]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/projectile.qc
Merge remote-tracking branch 'origin/mrbougo/killspree_bugfix'
[xonotic/xonotic-data.pk3dir.git] / 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
24 void Projectile_ResetTrail(vector to)
25 {
26         self.trail_oldorigin = to;
27         self.trail_oldtime = time;
28 }
29
30 void Projectile_DrawTrail(vector to)
31 {
32         vector from;
33         float t0;
34
35         from = self.trail_oldorigin;
36         t0 = self.trail_oldtime;
37         self.trail_oldorigin = to;
38         self.trail_oldtime = time;
39
40         // force the effect even for stationary firemine
41         if(self.cnt == PROJECTILE_FIREMINE)
42                 if(from == to)
43                         from_z += 1;
44
45         if (self.traileffect)
46         {
47                 particles_alphamin = particles_alphamax = sqrt(self.alpha);
48                 boxparticles(self.traileffect, self, from, to, self.velocity, self.velocity, sqrt(self.alpha), PARTICLES_USEALPHA);
49         }
50 }
51
52 void Projectile_Draw()
53 {
54         vector rot;
55         vector trailorigin;
56         float f;
57         float drawn;
58         float t;
59         float a;
60
61         f = self.move_flags;
62
63         if(self.count & 0x80)
64         {
65                 //self.move_flags &~= FL_ONGROUND;
66                 if(self.move_movetype == MOVETYPE_NONE || self.move_movetype == MOVETYPE_FLY)
67                         Movetype_Physics_NoMatchServer();
68                         // the trivial movetypes do not have to match the
69                         // server's ticrate as they are ticrate independent
70                         // NOTE: this assumption is only true if MOVETYPE_FLY
71                         // projectiles detonate on impact. If they continue
72                         // moving, we might still be ticrate dependent.
73                 else
74                         Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
75                 if(!(self.move_flags & FL_ONGROUND))
76                         if(self.velocity != '0 0 0')
77                                 self.move_angles = self.angles = vectoangles(self.velocity);
78         }
79         else
80         {
81                 InterpolateOrigin_Do();
82         }
83
84         if(self.count & 0x80)
85         {
86                 drawn = (time >= self.spawntime - 0.02);
87                 t = max(time, self.spawntime);
88         }
89         else
90         {
91                 drawn = (self.iflags & IFLAG_VALID);
92                 t = time;
93         }
94
95         if(!(f & FL_ONGROUND))
96         {
97                 rot = '0 0 0';
98                 switch(self.cnt)
99                 {
100                         /*
101                         case PROJECTILE_GRENADE:
102                                 rot = '-2000 0 0'; // forward
103                                 break;
104                         */
105                         case PROJECTILE_GRENADE_BOUNCING:
106                                 rot = '0 -1000 0'; // sideways
107                                 break;
108                         case PROJECTILE_HOOKBOMB:
109                                 rot = '1000 0 0'; // forward
110                                 break;
111                         default:
112                                 break;
113                 }
114                 self.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(self.angles), rot * (t - self.spawntime)));
115         }
116
117         vector ang;
118         ang = self.angles;
119         ang_x = -ang_x;
120         makevectors(ang);
121
122         a = 1 - (time - self.fade_time) * self.fade_rate;
123         self.alpha = bound(0, self.alphamod * a, 1);
124         if(self.alpha <= 0)
125                 drawn = 0;
126         self.renderflags = 0;
127
128         trailorigin = self.origin;
129         switch(self.cnt)
130         {
131                 case PROJECTILE_GRENADE:
132                 case PROJECTILE_GRENADE_BOUNCING:
133                         trailorigin += v_right * 1 + v_forward * -10;
134                         break;
135                 default:
136                         break;
137         }
138         if(drawn)
139                 Projectile_DrawTrail(trailorigin);
140         else
141                 Projectile_ResetTrail(trailorigin);
142
143         self.drawmask = 0;
144
145         if(!drawn)
146                 return;
147
148         switch(self.cnt)
149         {
150                 case PROJECTILE_BULLET_GLOWING:
151                 case PROJECTILE_BULLET_GLOWING_TRACER:
152                         adddynamiclight(self.origin, 50 * a, '1 1 0');
153                         break;
154                 default:
155                         break;
156         }
157
158         self.drawmask = MASK_NORMAL;
159 }
160
161 void loopsound(entity e, float ch, string samp, float vol, float attn)
162 {
163         if(self.silent)
164                 return;
165
166         sound(e, ch, samp, vol, attn);
167         e.snd_looping = 1;
168 }
169
170 void Ent_RemoveProjectile()
171 {
172         if(self.snd_looping)
173                 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTN_NORM);
174
175         if(self.count & 0x80)
176         {
177                 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.05, MOVE_NORMAL, self);
178                 Projectile_DrawTrail(trace_endpos);
179         }
180 }
181
182 void Ent_Projectile()
183 {
184         float f;
185
186         // projectile properties:
187         //   kind (interpolated, or clientside)
188         //
189         //   modelindex
190         //   origin
191         //   scale
192         //   if clientside:
193         //     velocity
194         //     gravity
195         //   soundindex (hardcoded list)
196         //   effects
197         //
198         // projectiles don't send angles, because they always follow the velocity
199
200         f = ReadByte();
201         self.count = (f & 0x80);
202         self.iflags = (self.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES;
203         self.solid = SOLID_TRIGGER;
204         //self.effects = EF_NOMODELFLAGS;
205
206         // this should make collisions with bmodels more exact, but it leads to
207         // projectiles no longer being able to lie on a bmodel
208         self.move_nomonsters = MOVE_WORLDONLY;
209         if(f & 0x40)
210                 self.move_flags |= FL_ONGROUND;
211         else
212                 self.move_flags &~= FL_ONGROUND;
213
214         if(!self.move_time)
215         {
216                 // for some unknown reason, we don't need to care for
217                 // sv_gameplayfix_delayprojectiles here.
218                 self.move_time = time;
219                 self.spawntime = time;
220         }
221         else
222                 self.move_time = max(self.move_time, time);
223
224         if(!(self.count & 0x80))
225                 InterpolateOrigin_Undo();
226
227         if(f & 1)
228         {
229                 self.origin_x = ReadCoord();
230                 self.origin_y = ReadCoord();
231                 self.origin_z = ReadCoord();
232                 if(self.count & 0x80)
233                 {
234                         self.velocity_x = ReadCoord();
235                         self.velocity_y = ReadCoord();
236                         self.velocity_z = ReadCoord();
237                         if(f & 0x10)
238                                 self.gravity = ReadCoord();
239                         else
240                                 self.gravity = 0; // none
241                         self.move_origin = self.origin;
242                         self.move_velocity = self.velocity;
243                 }
244
245                 if(time == self.spawntime || (self.count & 0x80) || (f & 0x08))
246                 {
247                         self.trail_oldorigin = self.origin;
248                         if(!(self.count & 0x80))
249                                 InterpolateOrigin_Reset();
250                 }
251
252                 if(f & 0x20)
253                 {
254                         self.fade_time = time + ReadByte() * ticrate;
255                         self.fade_rate = 1 / (ReadByte() * ticrate);
256                 }
257                 else
258                 {
259                         self.fade_time = 0;
260                         self.fade_rate = 0;
261                 }
262         }
263
264         if(f & 2)
265         {
266                 self.cnt = ReadByte();
267
268                 self.silent = (self.cnt & 0x80);
269                 self.cnt = (self.cnt & 0x7F);
270
271                 self.scale = 1;
272                 self.traileffect = 0;
273                 switch(self.cnt)
274                 {
275                         case PROJECTILE_ELECTRO: setmodel(self, "models/ebomb.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
276                         case PROJECTILE_ROCKET: setmodel(self, "models/rocket.md3");self.traileffect = particleeffectnum("TR_ROCKET"); self.scale = 2; break;
277                         case PROJECTILE_BULLET: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_bullet"); break;
278                         case PROJECTILE_BULLET_GLOWING: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_rifle_weak"); break;
279                         case PROJECTILE_BULLET_GLOWING_TRACER: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_rifle"); break;
280                         case PROJECTILE_CRYLINK: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
281                         case PROJECTILE_CRYLINK_BOUNCING: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
282                         case PROJECTILE_ELECTRO_BEAM: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
283                         case PROJECTILE_GRENADE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
284                         case PROJECTILE_GRENADE_BOUNCING: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
285                         case PROJECTILE_MINE: setmodel(self, "models/mine.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
286                         case PROJECTILE_LASER: setmodel(self, "models/laser.mdl");self.traileffect = particleeffectnum(""); break;
287                         case PROJECTILE_HLAC: setmodel(self, "models/hlac_bullet.md3");self.traileffect = particleeffectnum(""); break;
288                         case PROJECTILE_PORTO_RED: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
289                         case PROJECTILE_PORTO_BLUE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
290                         case PROJECTILE_HOOKBOMB: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_KNIGHTSPIKE"); break;
291                         case PROJECTILE_HAGAR: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("tr_hagar"); self.scale = 0.75; break;
292                         case PROJECTILE_HAGAR_BOUNCING: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("tr_hagar"); self.scale = 0.75; break;
293                         case PROJECTILE_FIREBALL: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("fireball"); break; // particle effect is good enough
294                         case PROJECTILE_FIREMINE: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("firemine"); break; // particle effect is good enough
295                         case PROJECTILE_TAG: setmodel(self, "models/laser.mdl"); self.traileffect = particleeffectnum("TR_ROCKET"); break;
296                         case PROJECTILE_FLAC: setmodel(self, "models/hagarmissile.mdl"); self.scale = 0.4; self.traileffect = particleeffectnum("TR_SEEKER"); break;
297                         case PROJECTILE_SEEKER: setmodel(self, "models/tagrocket.md3"); self.traileffect = particleeffectnum("TR_SEEKER"); break;
298
299                         case PROJECTILE_RAPTORBOMB:    setmodel(self, "models/vehicles/clusterbomb.md3"); self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = particleeffectnum(""); break;
300                         case PROJECTILE_RAPTORBOMBLET: setmodel(self, "models/vehicles/bomblet.md3");     self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = particleeffectnum(""); break;
301                         case PROJECTILE_RAPTORCANNON:  setmodel(self, "models/plasmatrail.mdl"); self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
302
303                         case PROJECTILE_SPIDERROCKET: setmodel(self, "models/vehicles/rocket02.md3"); self.traileffect = particleeffectnum("spiderbot_rocket_thrust"); break;
304                         case PROJECTILE_WAKIROCKET:   setmodel(self, "models/vehicles/rocket01.md3");  self.traileffect = particleeffectnum("wakizashi_rocket_thrust"); break;
305                         case PROJECTILE_WAKICANNON:   setmodel(self, "models/laser.mdl");  self.traileffect = particleeffectnum(""); break;
306
307                         case PROJECTILE_BUMBLE_GUN: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
308                         case PROJECTILE_BUMBLE_BEAM: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
309
310                         default:
311                                 error("Received invalid CSQC projectile, can't work with this!");
312                                 break;
313                 }
314
315                 self.mins = '0 0 0';
316                 self.maxs = '0 0 0';
317                 self.colormod = '0 0 0';
318                 self.move_touch = SUB_Stop;
319                 self.move_movetype = MOVETYPE_TOSS;
320                 self.alphamod = 1;
321
322                 switch(self.cnt)
323                 {
324                         case PROJECTILE_ELECTRO:
325                                 // only new engines support sound moving with object
326                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
327                                 self.mins = '0 0 -4';
328                                 self.maxs = '0 0 -4';
329                                 self.move_movetype = MOVETYPE_BOUNCE;
330                                 self.move_touch = SUB_Null;
331                                 self.move_bounce_factor = g_balance_electro_secondary_bouncefactor;
332                                 self.move_bounce_stopspeed = g_balance_electro_secondary_bouncestop;
333                                 break;
334                         case PROJECTILE_ROCKET:
335                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/rocket_fly.wav", VOL_BASE, ATTN_NORM);
336                                 self.mins = '-3 -3 -3';
337                                 self.maxs = '3 3 3';
338                                 break;
339                         case PROJECTILE_GRENADE:
340                                 self.mins = '-3 -3 -3';
341                                 self.maxs = '3 3 3';
342                                 break;
343                         case PROJECTILE_GRENADE_BOUNCING:
344                                 self.mins = '-3 -3 -3';
345                                 self.maxs = '3 3 3';
346                                 self.move_movetype = MOVETYPE_BOUNCE;
347                                 self.move_touch = SUB_Null;
348                                 self.move_bounce_factor = g_balance_grenadelauncher_bouncefactor;
349                                 self.move_bounce_stopspeed = g_balance_grenadelauncher_bouncestop;
350                                 break;
351                         case PROJECTILE_MINE:
352                                 self.mins = '-4 -4 -4';
353                                 self.maxs = '4 4 4';
354                                 break;
355                         case PROJECTILE_PORTO_RED:
356                                 self.colormod = '2 1 1';
357                                 self.alphamod = 0.5;
358                                 self.move_movetype = MOVETYPE_BOUNCE;
359                                 self.move_touch = SUB_Null;
360                                 break;
361                         case PROJECTILE_PORTO_BLUE:
362                                 self.colormod = '1 1 2';
363                                 self.alphamod = 0.5;
364                                 self.move_movetype = MOVETYPE_BOUNCE;
365                                 self.move_touch = SUB_Null;
366                                 break;
367                         case PROJECTILE_HAGAR_BOUNCING:
368                                 self.move_movetype = MOVETYPE_BOUNCE;
369                                 self.move_touch = SUB_Null;
370                                 break;
371                         case PROJECTILE_CRYLINK_BOUNCING:
372                                 self.move_movetype = MOVETYPE_BOUNCE;
373                                 self.move_touch = SUB_Null;
374                                 break;
375                         case PROJECTILE_FIREBALL:
376                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/fireball_fly2.wav", VOL_BASE, ATTN_NORM);
377                                 self.mins = '-16 -16 -16';
378                                 self.maxs = '16 16 16';
379                                 break;
380                         case PROJECTILE_FIREMINE:
381                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/fireball_fly.wav", VOL_BASE, ATTN_NORM);
382                                 self.move_movetype = MOVETYPE_BOUNCE;
383                                 self.move_touch = SUB_Null;
384                                 self.mins = '-4 -4 -4';
385                                 self.maxs = '4 4 4';
386                                 break;
387                         case PROJECTILE_TAG:
388                                 self.mins = '-2 -2 -2';
389                                 self.maxs = '2 2 2';
390                                 break;
391                         case PROJECTILE_FLAC:
392                                 self.mins = '-2 -2 -2';
393                                 self.maxs = '2 2 2';
394                                 break;
395                         case PROJECTILE_SEEKER:
396                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
397                                 self.mins = '-4 -4 -4';
398                                 self.maxs = '4 4 4';
399                                 break;
400             case PROJECTILE_RAPTORBOMB:
401                                 self.mins = '-3 -3 -3';
402                                 self.maxs = '3 3 3';
403                                 break;
404             case PROJECTILE_RAPTORBOMBLET:
405                                 break;
406             case PROJECTILE_RAPTORCANNON:
407                                 break;
408             case PROJECTILE_SPIDERROCKET:
409                 loopsound(self, CH_SHOTS_SINGLE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
410                                 break;
411             case PROJECTILE_WAKIROCKET:
412                 loopsound(self, CH_SHOTS_SINGLE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
413                                 break;            
414             /*
415             case PROJECTILE_WAKICANNON:
416                                 break;
417                         case PROJECTILE_BUMBLE_GUN:
418                                 // only new engines support sound moving with object
419                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
420                                 self.mins = '0 0 -4';
421                                 self.maxs = '0 0 -4';
422                                 self.move_movetype = MOVETYPE_BOUNCE;
423                                 self.move_touch = SUB_Null;
424                                 self.move_bounce_factor = g_balance_electro_secondary_bouncefactor;
425                                 self.move_bounce_stopspeed = g_balance_electro_secondary_bouncestop;
426                                 break;
427                         */
428                         default:
429                                 break;
430                 }
431         }
432
433         if(self.gravity)
434         {
435                 if(self.move_movetype == MOVETYPE_FLY)
436                         self.move_movetype = MOVETYPE_TOSS;
437                 if(self.move_movetype == MOVETYPE_BOUNCEMISSILE)
438                         self.move_movetype = MOVETYPE_BOUNCE;
439         }
440         else
441         {
442                 if(self.move_movetype == MOVETYPE_TOSS)
443                         self.move_movetype = MOVETYPE_FLY;
444                 if(self.move_movetype == MOVETYPE_BOUNCE)
445                         self.move_movetype = MOVETYPE_BOUNCEMISSILE;
446         }
447
448         if(!(self.count & 0x80))
449                 InterpolateOrigin_Note();
450
451         self.draw = Projectile_Draw;
452         self.entremove = Ent_RemoveProjectile;
453 }
454
455 void Projectile_Precache()
456 {
457         precache_model("models/ebomb.mdl");
458         precache_model("models/elaser.mdl");
459         precache_model("models/grenademodel.md3");
460         precache_model("models/mine.md3");
461         precache_model("models/hagarmissile.mdl");
462         precache_model("models/hlac_bullet.md3");
463         precache_model("models/laser.mdl");
464         precache_model("models/plasmatrail.mdl");
465         precache_model("models/rocket.md3");
466         precache_model("models/tagrocket.md3");
467         precache_model("models/tracer.mdl");
468
469         precache_sound("weapons/electro_fly.wav");
470         precache_sound("weapons/rocket_fly.wav");
471         precache_sound("weapons/fireball_fly.wav");
472         precache_sound("weapons/fireball_fly2.wav");
473         precache_sound("weapons/tag_rocket_fly.wav");
474
475 }