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