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