]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/projectile.qc
Scaled the weapon models down about 30% to match 2.5.2 sizes. Except the tuba, I...
[divverent/nexuiz.git] / data / qcsrc / client / projectile.qc
1 .vector iorigin1, iorigin2;
2 .float spawntime;
3 .vector trail_oldorigin;
4 .float trail_oldtime;
5 .float fade_time, fade_rate;
6
7 void SUB_Null()
8 {
9 }
10
11 void SUB_Stop()
12 {
13         self.move_velocity = self.move_avelocity = '0 0 0';
14         self.move_movetype = MOVETYPE_NONE;
15 }
16
17 .float alphamod;
18 .float count; // set if clientside projectile
19 .float cnt; // sound index
20 .float gravity;
21 .float snd_looping;
22 .float silent;
23 .float traileffect;
24
25 void Projectile_DrawTrail(vector to)
26 {
27         vector from;
28         float t0;
29         from = self.trail_oldorigin;
30         t0 = self.trail_oldtime;
31         self.trail_oldorigin = to;
32         self.trail_oldtime = time;
33
34         if (self.traileffect)
35                 trailparticles(self, self.traileffect, from, to);
36 }
37
38 void Projectile_Draw()
39 {
40         vector rot;
41         vector trailorigin;
42         float f;
43         float drawn;
44         float t;
45         float a;
46
47         f = self.move_flags;
48
49         if(self.count & 0x80)
50         {
51                 //self.move_flags &~= FL_ONGROUND;
52                 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
53                 if(!(self.move_flags & FL_ONGROUND))
54                         self.angles = vectoangles(self.velocity);
55         }
56         else
57         {
58                 InterpolateOrigin_Do();
59         }
60
61         if(self.count & 0x80)
62         {
63                 drawn = (time >= self.spawntime - 0.02);
64                 t = max(time, self.spawntime);
65         }
66         else
67         {
68                 drawn = (self.iflags & IFLAG_VALID);
69                 t = time;
70         }
71
72         if(!(f & FL_ONGROUND))
73         {
74                 rot = '0 0 0';
75                 switch(self.cnt)
76                 {
77                         /*
78                         case PROJECTILE_GRENADE:
79                                 rot = '-2000 0 0'; // forward
80                                 break;
81                         */
82                         case PROJECTILE_GRENADE_BOUNCING:
83                                 rot = '0 -1000 0'; // sideways
84                                 break;
85                         case PROJECTILE_HOOKBOMB:
86                                 rot = '1000 0 0'; // forward
87                                 break;
88                         default:
89                                 break;
90                 }
91                 self.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(self.angles), rot * (t - self.spawntime)));
92         }
93
94         vector ang;
95         ang = self.angles;
96         ang_x = -ang_x;
97         makevectors(ang);
98
99         a = 1 - (time - self.fade_time) * self.fade_rate;
100         if(a <= 0)
101                 drawn = 0;
102
103         trailorigin = self.origin;
104         switch(self.cnt)
105         {
106                 case PROJECTILE_GRENADE:
107                 case PROJECTILE_GRENADE_BOUNCING:
108                         trailorigin += v_right * 1 + v_forward * -10;
109                         break;
110                 default:
111                         break;
112         }
113         if(drawn)
114                 Projectile_DrawTrail(trailorigin);
115         else
116         {
117                 self.trail_oldorigin = trailorigin;
118                 self.trail_oldtime = time;
119         }
120
121         if(!drawn)
122                 return;
123
124         switch(self.cnt)
125         {
126                 case PROJECTILE_BULLET_GLOWING:
127                 case PROJECTILE_BULLET_GLOWING_TRACER:
128                         R_AddDynamicLight(self.origin, 50 * a, '1 1 0');
129                         break;
130                 default:
131                         break;
132         }
133
134         self.alpha = self.alphamod * a;
135         self.renderflags = 0;
136
137         R_AddEntity(self);
138 }
139
140 void loopsound(entity e, float ch, string samp, float vol, float attn)
141 {
142         if(self.silent)
143                 return;
144
145         sound(e, ch, samp, vol, attn);
146         e.snd_looping = 1;
147 }
148
149 void Ent_RemoveProjectile()
150 {
151         if(self.snd_looping)
152                 sound(self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
153
154         if(self.count & 0x80)
155         {
156                 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.05, MOVE_NORMAL, self);
157                 Projectile_DrawTrail(trace_endpos);
158         }
159 }
160
161 void Ent_Projectile()
162 {
163         float f;
164
165         // projectile properties:
166         //   kind (interpolated, or clientside)
167         //
168         //   modelindex
169         //   origin
170         //   scale
171         //   if clientside:
172         //     velocity
173         //     gravity
174         //   soundindex (hardcoded list)
175         //   effects
176         //
177         // projectiles don't send angles, because they always follow the velocity
178         
179         f = ReadByte();
180         self.count = (f & 0x80);
181         self.iflags = (self.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES;
182         self.solid = SOLID_TRIGGER;
183         //self.effects = EF_NOMODELFLAGS;
184
185         // this should make collisions with bmodels more exact, but it leads to
186         // projectiles no longer being able to lie on a bmodel
187         self.move_nomonsters = MOVE_WORLDONLY;
188         if(f & 0x40)
189                 self.move_flags |= FL_ONGROUND;
190         else
191                 self.move_flags &~= FL_ONGROUND;
192
193         if(!self.move_time)
194         {
195                 // for some unknown reason, we don't need to care for
196                 // sv_gameplayfix_delayprojectiles here.
197                 self.move_time = time;
198                 self.spawntime = time;
199         }
200         else
201                 self.move_time = max(self.move_time, time);
202
203         if(!(self.count & 0x80))
204                 InterpolateOrigin_Undo();
205
206         if(f & 1)
207         {
208                 self.origin_x = ReadCoord();
209                 self.origin_y = ReadCoord();
210                 self.origin_z = ReadCoord();
211                 if(self.count & 0x80)
212                 {
213                         self.velocity_x = ReadCoord();
214                         self.velocity_y = ReadCoord();
215                         self.velocity_z = ReadCoord();
216                         self.gravity = ReadCoord();
217
218                         self.move_origin = self.origin;
219                         self.move_velocity = self.velocity;
220                 }
221
222                 if(time == self.spawntime || (self.count & 0x80) || (f & 0x10))
223                 {
224                         self.trail_oldorigin = self.origin;
225                         if(!(self.count & 0x80))
226                                 InterpolateOrigin_Reset();
227                 }
228
229                 if(f & 0x20)
230                 {
231                         self.fade_time = time + ReadByte() * ticrate;
232                         self.fade_rate = 1 / (ReadByte() * ticrate);
233                 }
234                 else
235                 {
236                         self.fade_time = 0;
237                         self.fade_rate = 0;
238                 }
239         }
240
241         if(f & 2)
242         {
243                 self.cnt = ReadByte();
244
245                 self.silent = (self.cnt & 0x80);
246                 self.cnt = (self.cnt & 0x7F);
247
248                 self.scale = 1;
249                 self.traileffect = 0;
250                 switch(self.cnt)
251                 {
252                         case PROJECTILE_ELECTRO: setmodel(self, "models/ebomb.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
253                         case PROJECTILE_ROCKET: setmodel(self, "models/rocket.md3");self.traileffect = particleeffectnum("TR_ROCKET"); self.scale = 2; break;
254                         case PROJECTILE_BULLET: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_bullet"); break;
255                         case PROJECTILE_BULLET_GLOWING: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_bullet"); break;
256                         case PROJECTILE_BULLET_GLOWING_TRACER: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_rifle"); break;
257                         case PROJECTILE_CRYLINK: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
258                         case PROJECTILE_CRYLINK_BOUNCING: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
259                         case PROJECTILE_ELECTRO_BEAM: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
260                         case PROJECTILE_GRENADE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
261                         case PROJECTILE_GRENADE_BOUNCING: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
262                         case PROJECTILE_LASER: setmodel(self, "models/laser.mdl");self.traileffect = particleeffectnum(""); break;
263                         case PROJECTILE_HLAC: setmodel(self, "models/hlac_bullet.md3");self.traileffect = particleeffectnum(""); break;
264                         case PROJECTILE_PORTO_RED: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
265                         case PROJECTILE_PORTO_BLUE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
266                         case PROJECTILE_HOOKBOMB: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_KNIGHTSPIKE"); break;
267                         case PROJECTILE_HAGAR: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("TR_GRENADE"); self.scale = 0.4; break;
268                         case PROJECTILE_HAGAR_BOUNCING: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("TR_GRENADE"); self.scale = 0.4; break;
269                         case PROJECTILE_FIREBALL: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("fireball"); break; // particle effect is good enough
270                         case PROJECTILE_FIREMINE: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("firemine"); break; // particle effect is good enough
271                         default:
272                                 error("Received invalid CSQC projectile, can't work with this!");
273                                 break;
274                 }
275
276                 self.mins = '0 0 0';
277                 self.maxs = '0 0 0';
278                 self.colormod = '0 0 0';
279                 self.move_touch = SUB_Stop;
280                 self.move_movetype = MOVETYPE_TOSS;
281                 self.alphamod = 1;
282
283                 switch(self.cnt)
284                 {
285                         case PROJECTILE_ELECTRO:
286                                 // only new engines support sound moving with object
287                                 loopsound(self, CHAN_PROJECTILE, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
288                                 self.mins = '0 0 -3';
289                                 self.maxs = '0 0 -3';
290                                 self.move_movetype = MOVETYPE_BOUNCE;
291                                 self.move_touch = SUB_Null;
292                                 break;
293                         case PROJECTILE_ROCKET:
294                                 loopsound(self, CHAN_PROJECTILE, "weapons/rocket_fly.wav", VOL_BASE, ATTN_NORM);
295                                 self.mins = '-3 -3 -3';
296                                 self.maxs = '3 3 3';
297                                 break;
298                         case PROJECTILE_GRENADE:
299                                 self.mins = '0 0 -3';
300                                 self.maxs = '0 0 -3';
301                                 break;
302                         case PROJECTILE_GRENADE_BOUNCING:
303                                 self.mins = '0 0 -3';
304                                 self.maxs = '0 0 -3';
305                                 self.move_movetype = MOVETYPE_BOUNCE;
306                                 self.move_touch = SUB_Null;
307                                 break;
308                         case PROJECTILE_PORTO_RED:
309                                 self.colormod = '2 1 1';
310                                 self.alphamod = 0.5;
311                                 self.move_movetype = MOVETYPE_BOUNCE;
312                                 self.move_touch = SUB_Null;
313                                 break;
314                         case PROJECTILE_PORTO_BLUE:
315                                 self.colormod = '1 1 2';
316                                 self.alphamod = 0.5;
317                                 self.move_movetype = MOVETYPE_BOUNCE;
318                                 self.move_touch = SUB_Null;
319                                 break;
320                         case PROJECTILE_HAGAR_BOUNCING:
321                                 self.move_movetype = MOVETYPE_BOUNCE;
322                                 self.move_touch = SUB_Null;
323                                 break;
324                         case PROJECTILE_CRYLINK_BOUNCING:
325                                 self.move_movetype = MOVETYPE_BOUNCE;
326                                 self.move_touch = SUB_Null;
327                                 break;
328                         case PROJECTILE_FIREBALL:
329                                 loopsound(self, CHAN_PROJECTILE, "weapons/fireball_fly2.wav", VOL_BASE, ATTN_NORM);
330                                 self.mins = '-16 -16 -16';
331                                 self.maxs = '16 16 16';
332                                 break;
333                         case PROJECTILE_FIREMINE:
334                                 loopsound(self, CHAN_PROJECTILE, "weapons/fireball_fly.wav", VOL_BASE, ATTN_NORM);
335                                 self.move_movetype = MOVETYPE_BOUNCE;
336                                 self.move_touch = SUB_Null;
337                                 self.mins = '-4 -4 -4';
338                                 self.maxs = '4 4 4';
339                                 break;
340                         default:
341                                 break;
342                 }
343         }
344
345         if(self.gravity)
346         {
347                 if(self.move_movetype == MOVETYPE_FLY)
348                         self.move_movetype = MOVETYPE_TOSS;
349                 if(self.move_movetype == MOVETYPE_BOUNCEMISSILE)
350                         self.move_movetype = MOVETYPE_BOUNCE;
351         }
352         else
353         {
354                 if(self.move_movetype == MOVETYPE_TOSS)
355                         self.move_movetype = MOVETYPE_FLY;
356                 if(self.move_movetype == MOVETYPE_BOUNCE)
357                         self.move_movetype = MOVETYPE_BOUNCEMISSILE;
358         }
359
360         if(!(self.count & 0x80))
361                 InterpolateOrigin_Note();
362         
363         self.draw = Projectile_Draw;
364         self.entremove = Ent_RemoveProjectile;
365 }
366
367 void Projectile_Precache()
368 {
369         precache_model("models/ebomb.mdl");
370         precache_model("models/elaser.mdl");
371         precache_model("models/grenademodel.md3");
372         precache_model("models/hagarmissile.mdl");
373         precache_model("models/hlac_bullet.md3");
374         precache_model("models/laser.mdl");
375         precache_model("models/plasmatrail.mdl");
376         precache_model("models/rocket.md3");
377         precache_model("models/tracer.mdl");
378         precache_sound("weapons/electro_fly.wav");
379         precache_sound("weapons/rocket_fly.wav");
380         precache_sound("weapons/fireball_fly.wav");
381         precache_sound("weapons/fireball_fly2.wav");
382 }