]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/projectile.qc
Merge remote-tracking branch 'origin/master' into tzork/gm_nexball
[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                         default:
307                                 error("Received invalid CSQC projectile, can't work with this!");
308                                 break;
309                 }
310
311                 self.mins = '0 0 0';
312                 self.maxs = '0 0 0';
313                 self.colormod = '0 0 0';
314                 self.move_touch = SUB_Stop;
315                 self.move_movetype = MOVETYPE_TOSS;
316                 self.alphamod = 1;
317
318                 switch(self.cnt)
319                 {
320                         case PROJECTILE_ELECTRO:
321                                 // only new engines support sound moving with object
322                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
323                                 self.mins = '0 0 -4';
324                                 self.maxs = '0 0 -4';
325                                 self.move_movetype = MOVETYPE_BOUNCE;
326                                 self.move_touch = SUB_Null;
327                                 self.move_bounce_factor = g_balance_electro_secondary_bouncefactor;
328                                 self.move_bounce_stopspeed = g_balance_electro_secondary_bouncestop;
329                                 break;
330                         case PROJECTILE_ROCKET:
331                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/rocket_fly.wav", VOL_BASE, ATTN_NORM);
332                                 self.mins = '-3 -3 -3';
333                                 self.maxs = '3 3 3';
334                                 break;
335                         case PROJECTILE_GRENADE:
336                                 self.mins = '-3 -3 -3';
337                                 self.maxs = '3 3 3';
338                                 break;
339                         case PROJECTILE_GRENADE_BOUNCING:
340                                 self.mins = '-3 -3 -3';
341                                 self.maxs = '3 3 3';
342                                 self.move_movetype = MOVETYPE_BOUNCE;
343                                 self.move_touch = SUB_Null;
344                                 self.move_bounce_factor = g_balance_grenadelauncher_bouncefactor;
345                                 self.move_bounce_stopspeed = g_balance_grenadelauncher_bouncestop;
346                                 break;
347                         case PROJECTILE_MINE:
348                                 self.mins = '-4 -4 -4';
349                                 self.maxs = '4 4 4';
350                                 break;
351                         case PROJECTILE_PORTO_RED:
352                                 self.colormod = '2 1 1';
353                                 self.alphamod = 0.5;
354                                 self.move_movetype = MOVETYPE_BOUNCE;
355                                 self.move_touch = SUB_Null;
356                                 break;
357                         case PROJECTILE_PORTO_BLUE:
358                                 self.colormod = '1 1 2';
359                                 self.alphamod = 0.5;
360                                 self.move_movetype = MOVETYPE_BOUNCE;
361                                 self.move_touch = SUB_Null;
362                                 break;
363                         case PROJECTILE_HAGAR_BOUNCING:
364                                 self.move_movetype = MOVETYPE_BOUNCE;
365                                 self.move_touch = SUB_Null;
366                                 break;
367                         case PROJECTILE_CRYLINK_BOUNCING:
368                                 self.move_movetype = MOVETYPE_BOUNCE;
369                                 self.move_touch = SUB_Null;
370                                 break;
371                         case PROJECTILE_FIREBALL:
372                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/fireball_fly2.wav", VOL_BASE, ATTN_NORM);
373                                 self.mins = '-16 -16 -16';
374                                 self.maxs = '16 16 16';
375                                 break;
376                         case PROJECTILE_FIREMINE:
377                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/fireball_fly.wav", VOL_BASE, ATTN_NORM);
378                                 self.move_movetype = MOVETYPE_BOUNCE;
379                                 self.move_touch = SUB_Null;
380                                 self.mins = '-4 -4 -4';
381                                 self.maxs = '4 4 4';
382                                 break;
383                         case PROJECTILE_TAG:
384                                 self.mins = '-2 -2 -2';
385                                 self.maxs = '2 2 2';
386                                 break;
387                         case PROJECTILE_FLAC:
388                                 self.mins = '-2 -2 -2';
389                                 self.maxs = '2 2 2';
390                                 break;
391                         case PROJECTILE_SEEKER:
392                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
393                                 self.mins = '-4 -4 -4';
394                                 self.maxs = '4 4 4';
395                                 break;
396             case PROJECTILE_RAPTORBOMB:
397                                 self.mins = '-3 -3 -3';
398                                 self.maxs = '3 3 3';
399                                 break;
400             case PROJECTILE_RAPTORBOMBLET:
401                                 break;
402             case PROJECTILE_RAPTORCANNON:
403                                 break;
404             case PROJECTILE_SPIDERROCKET:
405                 loopsound(self, CH_SHOTS_SINGLE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
406                                 break;
407             case PROJECTILE_WAKIROCKET:
408                 loopsound(self, CH_SHOTS_SINGLE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
409                                 break;
410             case PROJECTILE_WAKICANNON:
411                                 break;
412                         default:
413                                 break;
414                 }
415         }
416
417         if(self.gravity)
418         {
419                 if(self.move_movetype == MOVETYPE_FLY)
420                         self.move_movetype = MOVETYPE_TOSS;
421                 if(self.move_movetype == MOVETYPE_BOUNCEMISSILE)
422                         self.move_movetype = MOVETYPE_BOUNCE;
423         }
424         else
425         {
426                 if(self.move_movetype == MOVETYPE_TOSS)
427                         self.move_movetype = MOVETYPE_FLY;
428                 if(self.move_movetype == MOVETYPE_BOUNCE)
429                         self.move_movetype = MOVETYPE_BOUNCEMISSILE;
430         }
431
432         if(!(self.count & 0x80))
433                 InterpolateOrigin_Note();
434
435         self.draw = Projectile_Draw;
436         self.entremove = Ent_RemoveProjectile;
437 }
438
439 void Projectile_Precache()
440 {
441         precache_model("models/ebomb.mdl");
442         precache_model("models/elaser.mdl");
443         precache_model("models/grenademodel.md3");
444         precache_model("models/mine.md3");
445         precache_model("models/hagarmissile.mdl");
446         precache_model("models/hlac_bullet.md3");
447         precache_model("models/laser.mdl");
448         precache_model("models/plasmatrail.mdl");
449         precache_model("models/rocket.md3");
450         precache_model("models/tagrocket.md3");
451         precache_model("models/tracer.mdl");
452
453         precache_sound("weapons/electro_fly.wav");
454         precache_sound("weapons/rocket_fly.wav");
455         precache_sound("weapons/fireball_fly.wav");
456         precache_sound("weapons/fireball_fly2.wav");
457         precache_sound("weapons/tag_rocket_fly.wav");
458
459 }