]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/projectile.qc
Merge branch 'master' into Mario/monsters
[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                 self.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(self.angles), rot * (t - self.spawntime)));
111         }
112
113         vector ang;
114         ang = self.angles;
115         ang_x = -ang_x;
116         makevectors(ang);
117
118         a = 1 - (time - self.fade_time) * self.fade_rate;
119         self.alpha = bound(0, self.alphamod * a, 1);
120         if(self.alpha <= 0)
121                 drawn = 0;
122         self.renderflags = 0;
123
124         trailorigin = self.origin;
125         switch(self.cnt)
126         {
127                 case PROJECTILE_GRENADE:
128                 case PROJECTILE_GRENADE_BOUNCING:
129                         trailorigin += v_right * 1 + v_forward * -10;
130                         break;
131                 default:
132                         break;
133         }
134         if(drawn)
135                 Projectile_DrawTrail(trailorigin);
136         else
137                 Projectile_ResetTrail(trailorigin);
138
139         self.drawmask = 0;
140
141         if(!drawn)
142                 return;
143
144         switch(self.cnt)
145         {
146                 case PROJECTILE_BULLET_GLOWING:
147                 case PROJECTILE_BULLET_GLOWING_TRACER:
148                         adddynamiclight(self.origin, 50 * a, '1 1 0');
149                         break;
150                 default:
151                         break;
152         }
153
154         self.drawmask = MASK_NORMAL;
155 }
156
157 void loopsound(entity e, float ch, string samp, float vol, float attn)
158 {
159         if(self.silent)
160                 return;
161
162         sound(e, ch, samp, vol, attn);
163         e.snd_looping = ch;
164 }
165
166 void Ent_RemoveProjectile()
167 {
168         if(self.count & 0x80)
169         {
170                 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.05, MOVE_NORMAL, self);
171                 Projectile_DrawTrail(trace_endpos);
172         }
173 }
174
175 void Ent_Projectile()
176 {
177         float f;
178
179         // projectile properties:
180         //   kind (interpolated, or clientside)
181         //
182         //   modelindex
183         //   origin
184         //   scale
185         //   if clientside:
186         //     velocity
187         //     gravity
188         //   soundindex (hardcoded list)
189         //   effects
190         //
191         // projectiles don't send angles, because they always follow the velocity
192
193         f = ReadByte();
194         self.count = (f & 0x80);
195         self.iflags = (self.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES | IFLAG_ORIGIN;
196         self.solid = SOLID_TRIGGER;
197         //self.effects = EF_NOMODELFLAGS;
198
199         // this should make collisions with bmodels more exact, but it leads to
200         // projectiles no longer being able to lie on a bmodel
201         self.move_nomonsters = MOVE_WORLDONLY;
202         if(f & 0x40)
203                 self.move_flags |= FL_ONGROUND;
204         else
205                 self.move_flags &~= FL_ONGROUND;
206
207         if(!self.move_time)
208         {
209                 // for some unknown reason, we don't need to care for
210                 // sv_gameplayfix_delayprojectiles here.
211                 self.move_time = time;
212                 self.spawntime = time;
213         }
214         else
215                 self.move_time = max(self.move_time, time);
216
217         if(!(self.count & 0x80))
218                 InterpolateOrigin_Undo();
219
220         if(f & 1)
221         {
222                 self.origin_x = ReadCoord();
223                 self.origin_y = ReadCoord();
224                 self.origin_z = ReadCoord();
225                 setorigin(self, self.origin);
226                 if(self.count & 0x80)
227                 {
228                         self.velocity_x = ReadCoord();
229                         self.velocity_y = ReadCoord();
230                         self.velocity_z = ReadCoord();
231                         if(f & 0x10)
232                                 self.gravity = ReadCoord();
233                         else
234                                 self.gravity = 0; // none
235                         self.move_origin = self.origin;
236                         self.move_velocity = self.velocity;
237                 }
238
239                 if(time == self.spawntime || (self.count & 0x80) || (f & 0x08))
240                 {
241                         self.trail_oldorigin = self.origin;
242                         if(!(self.count & 0x80))
243                                 InterpolateOrigin_Reset();
244                 }
245
246                 if(f & 0x20)
247                 {
248                         self.fade_time = time + ReadByte() * ticrate;
249                         self.fade_rate = 1 / (ReadByte() * ticrate);
250                 }
251                 else
252                 {
253                         self.fade_time = 0;
254                         self.fade_rate = 0;
255                 }
256         }
257
258         if(f & 2)
259         {
260                 self.cnt = ReadByte();
261
262                 self.silent = (self.cnt & 0x80);
263                 self.cnt = (self.cnt & 0x7F);
264
265                 self.scale = 1;
266                 self.traileffect = 0;
267                 switch(self.cnt)
268                 {
269                         case PROJECTILE_ELECTRO: setmodel(self, "models/ebomb.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
270                         case PROJECTILE_ROCKET: setmodel(self, "models/rocket.md3");self.traileffect = particleeffectnum("TR_ROCKET"); self.scale = 2; break;
271                         case PROJECTILE_BULLET: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_bullet"); break;
272                         case PROJECTILE_BULLET_GLOWING: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_rifle_weak"); break;
273                         case PROJECTILE_BULLET_GLOWING_TRACER: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_rifle"); break;
274                         case PROJECTILE_CRYLINK: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
275                         case PROJECTILE_CRYLINK_BOUNCING: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
276                         case PROJECTILE_ELECTRO_BEAM: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
277                         case PROJECTILE_GRENADE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
278                         case PROJECTILE_GRENADE_BOUNCING: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
279                         case PROJECTILE_MINE: setmodel(self, "models/mine.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
280                         case PROJECTILE_LASER: setmodel(self, "models/laser.mdl");self.traileffect = particleeffectnum(""); break;
281                         case PROJECTILE_HLAC: setmodel(self, "models/hlac_bullet.md3");self.traileffect = particleeffectnum(""); break;
282                         case PROJECTILE_PORTO_RED: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
283                         case PROJECTILE_PORTO_BLUE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
284                         case PROJECTILE_HOOKBOMB: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_KNIGHTSPIKE"); break;
285                         case PROJECTILE_HAGAR: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("tr_hagar"); self.scale = 0.75; break;
286                         case PROJECTILE_HAGAR_BOUNCING: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("tr_hagar"); self.scale = 0.75; break;
287                         case PROJECTILE_FIREBALL: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("fireball"); break; // particle effect is good enough
288                         case PROJECTILE_FIREMINE: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("firemine"); break; // particle effect is good enough
289                         case PROJECTILE_TAG: setmodel(self, "models/laser.mdl"); self.traileffect = particleeffectnum("TR_ROCKET"); break;
290                         case PROJECTILE_FLAC: setmodel(self, "models/hagarmissile.mdl"); self.scale = 0.4; self.traileffect = particleeffectnum("TR_SEEKER"); break;
291                         case PROJECTILE_SEEKER: setmodel(self, "models/tagrocket.md3"); self.traileffect = particleeffectnum("TR_SEEKER"); break;
292                         
293                         case PROJECTILE_MAGE_SPIKE: setmodel(self, "models/ebomb.mdl"); self.traileffect = particleeffectnum("TR_VORESPIKE"); break;
294
295                         case PROJECTILE_RAPTORBOMB:    setmodel(self, "models/vehicles/clusterbomb.md3"); self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = particleeffectnum(""); break;
296                         case PROJECTILE_RAPTORBOMBLET: setmodel(self, "models/vehicles/bomblet.md3");     self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = particleeffectnum(""); break;
297                         case PROJECTILE_RAPTORCANNON:  setmodel(self, "models/plasmatrail.mdl"); self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
298
299                         case PROJECTILE_SPIDERROCKET: setmodel(self, "models/vehicles/rocket02.md3"); self.traileffect = particleeffectnum("spiderbot_rocket_thrust"); break;
300                         case PROJECTILE_WAKIROCKET:   setmodel(self, "models/vehicles/rocket01.md3");  self.traileffect = particleeffectnum("wakizashi_rocket_thrust"); break;
301                         case PROJECTILE_WAKICANNON:   setmodel(self, "models/laser.mdl");  self.traileffect = particleeffectnum(""); break;
302
303                         case PROJECTILE_BUMBLE_GUN: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
304                         case PROJECTILE_BUMBLE_BEAM: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
305
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 = func_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 = func_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 = func_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 = func_null;
362                                 break;
363                         case PROJECTILE_HAGAR_BOUNCING:
364                                 self.move_movetype = MOVETYPE_BOUNCE;
365                                 self.move_touch = func_null;
366                                 break;
367                         case PROJECTILE_CRYLINK_BOUNCING:
368                                 self.move_movetype = MOVETYPE_BOUNCE;
369                                 self.move_touch = func_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 = func_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             /*
411             case PROJECTILE_WAKICANNON:
412                                 break;
413                         case PROJECTILE_BUMBLE_GUN:
414                                 // only new engines support sound moving with object
415                                 loopsound(self, CH_SHOTS_SINGLE, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
416                                 self.mins = '0 0 -4';
417                                 self.maxs = '0 0 -4';
418                                 self.move_movetype = MOVETYPE_BOUNCE;
419                                 self.move_touch = func_null;
420                                 self.move_bounce_factor = g_balance_electro_secondary_bouncefactor;
421                                 self.move_bounce_stopspeed = g_balance_electro_secondary_bouncestop;
422                                 break;
423                         */
424                         default:
425                                 break;
426                 }
427                 setsize(self, self.mins, self.maxs);
428         }
429
430         if(self.gravity)
431         {
432                 if(self.move_movetype == MOVETYPE_FLY)
433                         self.move_movetype = MOVETYPE_TOSS;
434                 if(self.move_movetype == MOVETYPE_BOUNCEMISSILE)
435                         self.move_movetype = MOVETYPE_BOUNCE;
436         }
437         else
438         {
439                 if(self.move_movetype == MOVETYPE_TOSS)
440                         self.move_movetype = MOVETYPE_FLY;
441                 if(self.move_movetype == MOVETYPE_BOUNCE)
442                         self.move_movetype = MOVETYPE_BOUNCEMISSILE;
443         }
444
445         if(!(self.count & 0x80))
446                 InterpolateOrigin_Note();
447
448         self.draw = Projectile_Draw;
449         self.entremove = Ent_RemoveProjectile;
450 }
451
452 void Projectile_Precache()
453 {
454         precache_model("models/ebomb.mdl");
455         precache_model("models/elaser.mdl");
456         precache_model("models/grenademodel.md3");
457         precache_model("models/mine.md3");
458         precache_model("models/hagarmissile.mdl");
459         precache_model("models/hlac_bullet.md3");
460         precache_model("models/laser.mdl");
461         precache_model("models/plasmatrail.mdl");
462         precache_model("models/rocket.md3");
463         precache_model("models/tagrocket.md3");
464         precache_model("models/tracer.mdl");
465
466         precache_sound("weapons/electro_fly.wav");
467         precache_sound("weapons/rocket_fly.wav");
468         precache_sound("weapons/fireball_fly.wav");
469         precache_sound("weapons/fireball_fly2.wav");
470         precache_sound("weapons/tag_rocket_fly.wav");
471
472 }