]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/weapons/projectile.qc
Supposedly fix "lagging" rockets
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / weapons / 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_Stop()
8 {
9         self.move_velocity = self.move_avelocity = '0 0 0';
10         self.move_movetype = MOVETYPE_NONE;
11 }
12
13 .float alphamod;
14 .float count; // set if clientside projectile
15 .float cnt; // sound index
16 .float gravity;
17 .float snd_looping;
18 .float silent;
19
20 void Projectile_ResetTrail(vector to)
21 {
22         self.trail_oldorigin = to;
23         self.trail_oldtime = time;
24 }
25
26 void Projectile_DrawTrail(vector to)
27 {
28         vector from;
29         float t0;
30
31         from = self.trail_oldorigin;
32         t0 = self.trail_oldtime;
33         self.trail_oldorigin = to;
34         self.trail_oldtime = time;
35
36         // force the effect even for stationary firemine
37         if(self.cnt == PROJECTILE_FIREMINE)
38                 if(from == to)
39                         from_z += 1;
40
41         if (self.traileffect)
42         {
43                 particles_alphamin = particles_alphamax = particles_fade = sqrt(self.alpha);
44                 boxparticles(self.traileffect, self, from, to, self.velocity, self.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
45         }
46 }
47
48 .float proj_time;
49 void Projectile_Draw()
50 {
51         vector rot;
52         vector trailorigin;
53         float f;
54         float drawn;
55         float t;
56         float a;
57         float dt = time - self.proj_time;
58
59         self.proj_time = time;
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
115                 if(Nade_IDFromProjectile(self.cnt) != 0)
116                         rot = self.avelocity;
117
118                 self.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(self.angles), rot * (t - self.spawntime)));
119         }
120
121         vector ang;
122         ang = self.angles;
123         ang_x = -ang_x;
124         makevectors(ang);
125
126         a = 1 - (time - self.fade_time) * self.fade_rate;
127         self.alpha = bound(0, self.alphamod * a, 1);
128         if(self.alpha <= 0)
129                 drawn = 0;
130         self.renderflags = 0;
131
132         trailorigin = self.origin;
133         switch(self.cnt)
134         {
135                 case PROJECTILE_GRENADE:
136                 case PROJECTILE_GRENADE_BOUNCING:
137                         trailorigin += v_right * 1 + v_forward * -10;
138                         break;
139                 default:
140                         break;
141         }
142
143         if(Nade_IDFromProjectile(self.cnt) != 0)
144                 trailorigin += v_up * 4;
145
146         if(dt > 0)
147         if(drawn)
148                 Projectile_DrawTrail(trailorigin);
149         else
150                 Projectile_ResetTrail(trailorigin);
151
152         self.drawmask = 0;
153
154         if(!drawn)
155                 return;
156
157         switch(self.cnt)
158         {
159                 // Possibly add dlights here.
160                 default:
161                         break;
162         }
163
164         self.drawmask = MASK_NORMAL;
165 }
166
167 void loopsound(entity e, float ch, string samp, float vol, float attn)
168 {
169         if(self.silent)
170                 return;
171
172         sound(e, ch, samp, vol, attn);
173         e.snd_looping = ch;
174 }
175
176 void Ent_RemoveProjectile()
177 {
178         if(self.count & 0x80)
179         {
180                 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.05, MOVE_NORMAL, self);
181                 Projectile_DrawTrail(trace_endpos);
182         }
183 }
184
185 void Ent_Projectile()
186 {
187         float f;
188
189         // projectile properties:
190         //   kind (interpolated, or clientside)
191         //
192         //   modelindex
193         //   origin
194         //   scale
195         //   if clientside:
196         //     velocity
197         //     gravity
198         //   soundindex (hardcoded list)
199         //   effects
200         //
201         // projectiles don't send angles, because they always follow the velocity
202
203         f = ReadByte();
204         self.count = (f & 0x80);
205         self.iflags = (self.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES | IFLAG_ORIGIN;
206         self.solid = SOLID_TRIGGER;
207         self.proj_time = time;
208         //self.effects = EF_NOMODELFLAGS;
209
210         // this should make collisions with bmodels more exact, but it leads to
211         // projectiles no longer being able to lie on a bmodel
212         self.move_nomonsters = MOVE_WORLDONLY;
213         if(f & 0x40)
214                 self.move_flags |= FL_ONGROUND;
215         else
216                 self.move_flags &= ~FL_ONGROUND;
217
218         if(!self.move_time)
219         {
220                 // for some unknown reason, we don't need to care for
221                 // sv_gameplayfix_delayprojectiles here.
222                 self.move_time = time;
223                 self.spawntime = time;
224         }
225         else
226                 self.move_time = max(self.move_time, time);
227
228         if(!(self.count & 0x80))
229                 InterpolateOrigin_Undo();
230
231         if(f & 1)
232         {
233                 self.origin_x = ReadCoord();
234                 self.origin_y = ReadCoord();
235                 self.origin_z = ReadCoord();
236                 setorigin(self, self.origin);
237                 if(self.count & 0x80)
238                 {
239                         self.velocity_x = ReadCoord();
240                         self.velocity_y = ReadCoord();
241                         self.velocity_z = ReadCoord();
242                         if(f & 0x10)
243                                 self.gravity = ReadCoord();
244                         else
245                                 self.gravity = 0; // none
246                         self.move_origin = self.origin;
247                         self.move_velocity = self.velocity;
248                 }
249
250                 if(time == self.spawntime || (self.count & 0x80) || (f & 0x08))
251                 {
252                         self.trail_oldorigin = self.origin;
253                         if(!(self.count & 0x80))
254                                 InterpolateOrigin_Reset();
255                 }
256
257                 if(f & 0x20)
258                 {
259                         self.fade_time = time + ReadByte() * ticrate;
260                         self.fade_rate = 1 / (ReadByte() * ticrate);
261                 }
262                 else
263                 {
264                         self.fade_time = 0;
265                         self.fade_rate = 0;
266                 }
267
268                 self.team = ReadByte() - 1;
269         }
270
271         if(f & 2)
272         {
273                 self.cnt = ReadByte();
274
275                 self.silent = (self.cnt & 0x80);
276                 self.cnt = (self.cnt & 0x7F);
277
278                 self.scale = 1;
279                 self.traileffect = 0;
280                 switch(self.cnt)
281                 {
282                         case PROJECTILE_ELECTRO: setmodel(self, "models/ebomb.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
283                         case PROJECTILE_ROCKET: setmodel(self, "models/rocket.md3");self.traileffect = particleeffectnum("TR_ROCKET"); self.scale = 2; break;
284                         case PROJECTILE_CRYLINK: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
285                         case PROJECTILE_CRYLINK_BOUNCING: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
286                         case PROJECTILE_ELECTRO_BEAM: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
287                         case PROJECTILE_GRENADE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
288                         case PROJECTILE_GRENADE_BOUNCING: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
289                         case PROJECTILE_MINE: setmodel(self, "models/mine.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
290                         case PROJECTILE_BLASTER: setmodel(self, "models/laser.mdl");self.traileffect = particleeffectnum(""); break;
291                         case PROJECTILE_HLAC: setmodel(self, "models/hlac_bullet.md3");self.traileffect = particleeffectnum(""); break;
292                         case PROJECTILE_PORTO_RED: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
293                         case PROJECTILE_PORTO_BLUE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
294                         case PROJECTILE_HOOKBOMB: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_KNIGHTSPIKE"); break;
295                         case PROJECTILE_HAGAR: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("tr_hagar"); self.scale = 0.75; break;
296                         case PROJECTILE_HAGAR_BOUNCING: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("tr_hagar"); self.scale = 0.75; break;
297                         case PROJECTILE_NAPALM_FOUNTAIN: //self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("torch_small"); break;
298                         case PROJECTILE_FIREBALL: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("fireball"); break; // particle effect is good enough
299                         case PROJECTILE_FIREMINE: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("firemine"); break; // particle effect is good enough
300                         case PROJECTILE_TAG: setmodel(self, "models/laser.mdl"); self.traileffect = particleeffectnum("TR_ROCKET"); break;
301                         case PROJECTILE_FLAC: setmodel(self, "models/hagarmissile.mdl"); self.scale = 0.4; self.traileffect = particleeffectnum("TR_SEEKER"); break;
302                         case PROJECTILE_SEEKER: setmodel(self, "models/tagrocket.md3"); self.traileffect = particleeffectnum("TR_SEEKER"); break;
303
304                         case PROJECTILE_MAGE_SPIKE: setmodel(self, "models/ebomb.mdl"); self.traileffect = particleeffectnum("TR_VORESPIKE"); break;
305                         case PROJECTILE_SHAMBLER_LIGHTNING: setmodel(self, "models/ebomb.mdl"); self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
306
307                         case PROJECTILE_RAPTORBOMB:    setmodel(self, "models/vehicles/clusterbomb.md3"); self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = particleeffectnum(""); break;
308                         case PROJECTILE_RAPTORBOMBLET: setmodel(self, "models/vehicles/bomblet.md3");     self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = particleeffectnum(""); break;
309                         case PROJECTILE_RAPTORCANNON:  setmodel(self, "models/plasmatrail.mdl"); self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
310
311                         case PROJECTILE_SPIDERROCKET: setmodel(self, "models/vehicles/rocket02.md3"); self.traileffect = particleeffectnum("spiderbot_rocket_thrust"); break;
312                         case PROJECTILE_WAKIROCKET:   setmodel(self, "models/vehicles/rocket01.md3");  self.traileffect = particleeffectnum("wakizashi_rocket_thrust"); break;
313                         case PROJECTILE_WAKICANNON:   setmodel(self, "models/laser.mdl");  self.traileffect = particleeffectnum(""); break;
314
315                         case PROJECTILE_BUMBLE_GUN: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
316                         case PROJECTILE_BUMBLE_BEAM: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
317
318                         default:
319                                 if(Nade_IDFromProjectile(self.cnt) != 0) { setmodel(self, "models/weapons/v_ok_grenade.md3");self.traileffect = particleeffectnum(Nade_TrailEffect(self.cnt, self.team)); break; }
320                                 error("Received invalid CSQC projectile, can't work with this!");
321                                 break;
322                 }
323
324                 self.mins = '0 0 0';
325                 self.maxs = '0 0 0';
326                 self.colormod = '0 0 0';
327                 self.move_touch = SUB_Stop;
328                 self.move_movetype = MOVETYPE_TOSS;
329                 self.alphamod = 1;
330
331                 switch(self.cnt)
332                 {
333                         case PROJECTILE_ELECTRO:
334                                 // only new engines support sound moving with object
335                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/electro_fly.wav", VOL_BASE, ATTEN_NORM);
336                                 self.mins = '0 0 -4';
337                                 self.maxs = '0 0 -4';
338                                 self.move_movetype = MOVETYPE_BOUNCE;
339                                 self.move_touch = func_null;
340                                 self.move_bounce_factor = g_balance_electro_secondary_bouncefactor;
341                                 self.move_bounce_stopspeed = g_balance_electro_secondary_bouncestop;
342                                 break;
343                         case PROJECTILE_ROCKET:
344                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/rocket_fly.wav", VOL_BASE, ATTEN_NORM);
345                                 self.mins = '-3 -3 -3';
346                                 self.maxs = '3 3 3';
347                                 break;
348                         case PROJECTILE_GRENADE:
349                                 self.mins = '-3 -3 -3';
350                                 self.maxs = '3 3 3';
351                                 break;
352                         case PROJECTILE_GRENADE_BOUNCING:
353                                 self.mins = '-3 -3 -3';
354                                 self.maxs = '3 3 3';
355                                 self.move_movetype = MOVETYPE_BOUNCE;
356                                 self.move_touch = func_null;
357                                 self.move_bounce_factor = g_balance_mortar_bouncefactor;
358                                 self.move_bounce_stopspeed = g_balance_mortar_bouncestop;
359                                 break;
360                         case PROJECTILE_SHAMBLER_LIGHTNING:
361                                 self.mins = '-8 -8 -8';
362                                 self.maxs = '8 8 8';
363                                 self.scale = 2.5;
364                                 self.avelocity = randomvec() * 720;
365                                 break;
366                         case PROJECTILE_MINE:
367                                 self.mins = '-4 -4 -4';
368                                 self.maxs = '4 4 4';
369                                 break;
370                         case PROJECTILE_PORTO_RED:
371                                 self.colormod = '2 1 1';
372                                 self.alphamod = 0.5;
373                                 self.move_movetype = MOVETYPE_BOUNCE;
374                                 self.move_touch = func_null;
375                                 break;
376                         case PROJECTILE_PORTO_BLUE:
377                                 self.colormod = '1 1 2';
378                                 self.alphamod = 0.5;
379                                 self.move_movetype = MOVETYPE_BOUNCE;
380                                 self.move_touch = func_null;
381                                 break;
382                         case PROJECTILE_HAGAR_BOUNCING:
383                                 self.move_movetype = MOVETYPE_BOUNCE;
384                                 self.move_touch = func_null;
385                                 break;
386                         case PROJECTILE_CRYLINK_BOUNCING:
387                                 self.move_movetype = MOVETYPE_BOUNCE;
388                                 self.move_touch = func_null;
389                                 break;
390                         case PROJECTILE_NAPALM_FOUNTAIN:
391                         case PROJECTILE_FIREBALL:
392                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/fireball_fly2.wav", VOL_BASE, ATTEN_NORM);
393                                 self.mins = '-16 -16 -16';
394                                 self.maxs = '16 16 16';
395                                 break;
396                         case PROJECTILE_FIREMINE:
397                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/fireball_fly.wav", VOL_BASE, ATTEN_NORM);
398                                 self.move_movetype = MOVETYPE_BOUNCE;
399                                 self.move_touch = func_null;
400                                 self.mins = '-4 -4 -4';
401                                 self.maxs = '4 4 4';
402                                 break;
403                         case PROJECTILE_TAG:
404                                 self.mins = '-2 -2 -2';
405                                 self.maxs = '2 2 2';
406                                 break;
407                         case PROJECTILE_FLAC:
408                                 self.mins = '-2 -2 -2';
409                                 self.maxs = '2 2 2';
410                                 break;
411                         case PROJECTILE_SEEKER:
412                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTEN_NORM);
413                                 self.mins = '-4 -4 -4';
414                                 self.maxs = '4 4 4';
415                                 break;
416             case PROJECTILE_RAPTORBOMB:
417                                 self.mins = '-3 -3 -3';
418                                 self.maxs = '3 3 3';
419                                 break;
420             case PROJECTILE_RAPTORBOMBLET:
421                                 break;
422             case PROJECTILE_RAPTORCANNON:
423                                 break;
424             case PROJECTILE_SPIDERROCKET:
425                 loopsound(self, CH_SHOTS_SINGLE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTEN_NORM);
426                                 break;
427             case PROJECTILE_WAKIROCKET:
428                 loopsound(self, CH_SHOTS_SINGLE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTEN_NORM);
429                                 break;
430             /*
431             case PROJECTILE_WAKICANNON:
432                                 break;
433                         case PROJECTILE_BUMBLE_GUN:
434                                 // only new engines support sound moving with object
435                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/electro_fly.wav", VOL_BASE, ATTEN_NORM);
436                                 self.mins = '0 0 -4';
437                                 self.maxs = '0 0 -4';
438                                 self.move_movetype = MOVETYPE_BOUNCE;
439                                 self.move_touch = func_null;
440                                 self.move_bounce_factor = g_balance_electro_secondary_bouncefactor;
441                                 self.move_bounce_stopspeed = g_balance_electro_secondary_bouncestop;
442                                 break;
443                         */
444                         default:
445                                 break;
446                 }
447
448                 if(Nade_IDFromProjectile(self.cnt) != 0)
449                 {
450                         self.mins = '-16 -16 -16';
451                         self.maxs = '16 16 16';
452                         self.colormod = Nade_Color(Nade_IDFromProjectile(self.cnt));
453                         self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
454                         self.move_movetype = MOVETYPE_BOUNCE;
455                         self.move_touch = func_null;
456                         self.scale = 1.5;
457                         self.avelocity = randomvec() * 720;
458                         
459                         if(Nade_IDFromProjectile(self.cnt) == NADE_TYPE_TRANSLOCATE)
460                                 self.solid = SOLID_TRIGGER;
461                 }
462
463                 setsize(self, self.mins, self.maxs);
464         }
465
466         if(self.gravity)
467         {
468                 if(self.move_movetype == MOVETYPE_FLY)
469                         self.move_movetype = MOVETYPE_TOSS;
470                 if(self.move_movetype == MOVETYPE_BOUNCEMISSILE)
471                         self.move_movetype = MOVETYPE_BOUNCE;
472         }
473         else
474         {
475                 if(self.move_movetype == MOVETYPE_TOSS)
476                         self.move_movetype = MOVETYPE_FLY;
477                 if(self.move_movetype == MOVETYPE_BOUNCE)
478                         self.move_movetype = MOVETYPE_BOUNCEMISSILE;
479         }
480
481         if(!(self.count & 0x80))
482                 InterpolateOrigin_Note();
483
484         self.draw = Projectile_Draw;
485         self.entremove = Ent_RemoveProjectile;
486 }
487
488 void Projectile_Precache()
489 {
490         precache_model("models/ebomb.mdl");
491         precache_model("models/elaser.mdl");
492         precache_model("models/grenademodel.md3");
493         precache_model("models/mine.md3");
494         precache_model("models/hagarmissile.mdl");
495         precache_model("models/hlac_bullet.md3");
496         precache_model("models/laser.mdl");
497         precache_model("models/plasmatrail.mdl");
498         precache_model("models/rocket.md3");
499         precache_model("models/tagrocket.md3");
500         precache_model("models/tracer.mdl");
501         precache_model("models/sphere/sphere.md3");
502
503         precache_model("models/weapons/v_ok_grenade.md3");
504
505         precache_sound("weapons/electro_fly.wav");
506         precache_sound("weapons/rocket_fly.wav");
507         precache_sound("weapons/fireball_fly.wav");
508         precache_sound("weapons/fireball_fly2.wav");
509         precache_sound("weapons/tag_rocket_fly.wav");
510
511 }