1 #include "projectile.qh"
3 #include "../autocvars.qh"
6 #include "../mutators/events.qh"
8 #include <common/constants.qh>
9 #include <common/physics/movetypes/movetypes.qh>
11 #include <lib/csqcmodel/interpolate.qh>
13 #include <lib/warpzone/anglestransform.qh>
19 void SUB_Stop(entity this)
21 this.move_velocity = this.move_avelocity = '0 0 0';
22 this.move_movetype = MOVETYPE_NONE;
31 void Projectile_ResetTrail(entity this, vector to)
33 this.trail_oldorigin = to;
34 this.trail_oldtime = time;
37 void Projectile_DrawTrail(entity this, vector to)
39 vector from = this.trail_oldorigin;
40 // float t0 = this.trail_oldtime;
41 this.trail_oldorigin = to;
42 this.trail_oldtime = time;
44 // force the effect even for stationary firemine
45 if (this.cnt == PROJECTILE_FIREMINE)
51 particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha);
52 boxparticles(particleeffectnum(Effects_from(this.traileffect)), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
56 bool Projectile_isnade(int proj); // TODO: remove
58 void Projectile_Draw(entity this)
69 if (this.count & 0x80)
71 // this.move_flags &= ~FL_ONGROUND;
72 if (this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FLY)
73 Movetype_Physics_NoMatchServer(this);
74 // the trivial movetypes do not have to match the
75 // server's ticrate as they are ticrate independent
76 // NOTE: this assumption is only true if MOVETYPE_FLY
77 // projectiles detonate on impact. If they continue
78 // moving, we might still be ticrate dependent.
80 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
81 if (!(this.move_flags & FL_ONGROUND))
82 if (this.velocity != '0 0 0')
83 this.move_angles = this.angles = vectoangles(this.velocity);
87 InterpolateOrigin_Do(this);
90 if (this.count & 0x80)
92 drawn = (time >= this.spawntime - 0.02);
93 t = max(time, this.spawntime);
97 drawn = (this.iflags & IFLAG_VALID);
101 if (!(f & FL_ONGROUND))
107 case PROJECTILE_GRENADE:
108 rot = '-2000 0 0'; // forward
111 case PROJECTILE_GRENADE_BOUNCING:
112 rot = '0 -1000 0'; // sideways
114 case PROJECTILE_HOOKBOMB:
115 rot = '1000 0 0'; // forward
121 if (Projectile_isnade(this.cnt))
122 rot = this.avelocity;
124 this.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(this.angles), rot * (t - this.spawntime)));
132 a = 1 - (time - this.fade_time) * this.fade_rate;
133 this.alpha = bound(0, this.alphamod * a, 1);
136 this.renderflags = 0;
138 trailorigin = this.origin;
141 case PROJECTILE_GRENADE:
142 case PROJECTILE_GRENADE_BOUNCING:
143 trailorigin += v_right * 1 + v_forward * -10;
149 if (Projectile_isnade(this.cnt))
150 trailorigin += v_up * 4;
153 Projectile_DrawTrail(this, trailorigin);
155 Projectile_ResetTrail(this, trailorigin);
164 // Possibly add dlights here.
169 this.drawmask = MASK_NORMAL;
172 void loopsound(entity e, int ch, string samp, float vol, float attn)
177 _sound(e, ch, samp, vol, attn);
181 void Ent_RemoveProjectile(entity this)
183 if (this.count & 0x80)
185 tracebox(this.origin, this.mins, this.maxs, this.origin + this.velocity * 0.05, MOVE_NORMAL, this);
186 Projectile_DrawTrail(this, trace_endpos);
190 NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
192 // projectile properties:
193 // kind (interpolated, or clientside)
201 // soundindex (hardcoded list)
204 // projectiles don't send angles, because they always follow the velocity
207 this.count = (f & 0x80);
208 this.flags |= FL_PROJECTILE;
209 this.iflags = (this.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES | IFLAG_ORIGIN;
210 this.solid = SOLID_TRIGGER;
211 // this.effects = EF_NOMODELFLAGS;
213 // this should make collisions with bmodels more exact, but it leads to
214 // projectiles no longer being able to lie on a bmodel
215 this.move_nomonsters = MOVE_WORLDONLY;
217 this.move_flags |= FL_ONGROUND;
219 this.move_flags &= ~FL_ONGROUND;
223 // for some unknown reason, we don't need to care for
224 // sv_gameplayfix_delayprojectiles here.
225 this.move_time = time;
226 this.spawntime = time;
230 this.move_time = max(this.move_time, time);
233 if (!(this.count & 0x80))
234 InterpolateOrigin_Undo(this);
238 this.origin_x = ReadCoord();
239 this.origin_y = ReadCoord();
240 this.origin_z = ReadCoord();
241 setorigin(this, this.origin);
242 if (this.count & 0x80)
244 this.velocity_x = ReadCoord();
245 this.velocity_y = ReadCoord();
246 this.velocity_z = ReadCoord();
248 this.gravity = ReadCoord();
250 this.gravity = 0; // none
251 this.move_origin = this.origin;
252 this.move_velocity = this.velocity;
255 if (time == this.spawntime || (this.count & 0x80) || (f & 0x08))
257 this.trail_oldorigin = this.origin;
258 if (!(this.count & 0x80))
259 InterpolateOrigin_Reset(this);
264 this.fade_time = time + ReadByte() * ticrate;
265 this.fade_rate = 1 / (ReadByte() * ticrate);
273 this.team = ReadByte() - 1;
278 this.cnt = ReadByte();
280 this.silent = (this.cnt & 0x80);
281 this.cnt = (this.cnt & 0x7F);
284 this.traileffect = 0;
287 #define HANDLE(id) case PROJECTILE_##id: setmodel(this, MDL_PROJECTILE_##id);
288 HANDLE(ELECTRO) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
289 HANDLE(ROCKET) this.traileffect = EFFECT_TR_ROCKET.m_id; this.scale = 2; break;
290 HANDLE(CRYLINK) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
291 HANDLE(CRYLINK_BOUNCING) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
292 HANDLE(ELECTRO_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
293 HANDLE(GRENADE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
294 HANDLE(GRENADE_BOUNCING) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
295 HANDLE(MINE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
296 HANDLE(BLASTER) this.traileffect = EFFECT_Null.m_id; break;
297 HANDLE(HLAC) this.traileffect = EFFECT_Null.m_id; break;
298 HANDLE(PORTO_RED) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
299 HANDLE(PORTO_BLUE) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
300 HANDLE(HOOKBOMB) this.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
301 HANDLE(HAGAR) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
302 HANDLE(HAGAR_BOUNCING) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
303 HANDLE(FIREBALL) this.modelindex = 0; this.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
304 HANDLE(FIREMINE) this.modelindex = 0; this.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
305 HANDLE(TAG) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
306 HANDLE(FLAC) this.scale = 0.4; this.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
307 HANDLE(SEEKER) this.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
309 HANDLE(MAGE_SPIKE) this.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
310 HANDLE(SHAMBLER_LIGHTNING) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
312 HANDLE(RAPTORBOMB) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
313 HANDLE(RAPTORBOMBLET) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
314 HANDLE(RAPTORCANNON) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
316 HANDLE(SPIDERROCKET) this.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
317 HANDLE(WAKIROCKET) this.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
318 HANDLE(WAKICANNON) this.traileffect = EFFECT_Null.m_id; break;
320 HANDLE(BUMBLE_GUN) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
321 HANDLE(BUMBLE_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
323 HANDLE(RPC) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
325 HANDLE(ROCKETMINSTA_LASER) this.traileffect = EFFECT_ROCKETMINSTA_LASER(this.team).m_id; break;
328 if (MUTATOR_CALLHOOK(Ent_Projectile, this))
331 error("Received invalid CSQC projectile, can't work with this!");
337 this.colormod = '0 0 0';
338 this.move_touch = SUB_Stop_self;
339 this.move_movetype = MOVETYPE_TOSS;
344 case PROJECTILE_ELECTRO:
345 // only new engines support sound moving with object
346 loopsound(this, CH_SHOTS_SINGLE, SND(ELECTRO_FLY), VOL_BASE, ATTEN_NORM);
347 this.mins = '0 0 -4';
348 this.maxs = '0 0 -4';
349 this.move_movetype = MOVETYPE_BOUNCE;
350 this.move_touch = func_null;
351 this.move_bounce_factor = WEP_CVAR_SEC(electro, bouncefactor);
352 this.move_bounce_stopspeed = WEP_CVAR_SEC(electro, bouncestop);
355 case PROJECTILE_ROCKET:
356 loopsound(this, CH_SHOTS_SINGLE, SND(ROCKET_FLY), VOL_BASE, ATTEN_NORM);
357 this.mins = '-3 -3 -3';
360 case PROJECTILE_GRENADE:
361 this.mins = '-3 -3 -3';
364 case PROJECTILE_GRENADE_BOUNCING:
365 this.mins = '-3 -3 -3';
367 this.move_movetype = MOVETYPE_BOUNCE;
368 this.move_touch = func_null;
369 this.move_bounce_factor = WEP_CVAR(mortar, bouncefactor);
370 this.move_bounce_stopspeed = WEP_CVAR(mortar, bouncestop);
372 case PROJECTILE_SHAMBLER_LIGHTNING:
373 this.mins = '-8 -8 -8';
376 this.avelocity = randomvec() * 720;
378 case PROJECTILE_MINE:
379 this.mins = '-4 -4 -4';
382 case PROJECTILE_PORTO_RED:
383 this.colormod = '2 1 1';
385 this.move_movetype = MOVETYPE_BOUNCE;
386 this.move_touch = func_null;
388 case PROJECTILE_PORTO_BLUE:
389 this.colormod = '1 1 2';
391 this.move_movetype = MOVETYPE_BOUNCE;
392 this.move_touch = func_null;
394 case PROJECTILE_HAGAR_BOUNCING:
395 this.move_movetype = MOVETYPE_BOUNCE;
396 this.move_touch = func_null;
398 case PROJECTILE_CRYLINK_BOUNCING:
399 this.move_movetype = MOVETYPE_BOUNCE;
400 this.move_touch = func_null;
402 case PROJECTILE_FIREBALL:
403 loopsound(this, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
404 this.mins = '-16 -16 -16';
405 this.maxs = '16 16 16';
407 case PROJECTILE_FIREMINE:
408 loopsound(this, CH_SHOTS_SINGLE, SND(FIREBALL_FLY), VOL_BASE, ATTEN_NORM);
409 this.move_movetype = MOVETYPE_BOUNCE;
410 this.move_touch = func_null;
411 this.mins = '-4 -4 -4';
415 this.mins = '-2 -2 -2';
418 case PROJECTILE_FLAC:
419 this.mins = '-2 -2 -2';
422 case PROJECTILE_SEEKER:
423 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
424 this.mins = '-4 -4 -4';
427 case PROJECTILE_RAPTORBOMB:
428 this.mins = '-3 -3 -3';
431 case PROJECTILE_RAPTORBOMBLET:
433 case PROJECTILE_RAPTORCANNON:
435 case PROJECTILE_SPIDERROCKET:
436 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
438 case PROJECTILE_WAKIROCKET:
439 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
442 case PROJECTILE_WAKICANNON:
444 case PROJECTILE_BUMBLE_GUN:
445 // only new engines support sound moving with object
446 loopsound(this, CH_SHOTS_SINGLE, SND(ELECTRO_FLY), VOL_BASE, ATTEN_NORM);
447 this.mins = '0 0 -4';
448 this.maxs = '0 0 -4';
449 this.move_movetype = MOVETYPE_BOUNCE;
450 this.move_touch = func_null;
451 this.move_bounce_factor = WEP_CVAR_SEC(electro, bouncefactor);
452 this.move_bounce_stopspeed = WEP_CVAR_SEC(electro, bouncestop);
459 MUTATOR_CALLHOOK(EditProjectile, this);
461 setsize(this, this.mins, this.maxs);
468 if (this.move_movetype == MOVETYPE_FLY)
469 this.move_movetype = MOVETYPE_TOSS;
470 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
471 this.move_movetype = MOVETYPE_BOUNCE;
475 if (this.move_movetype == MOVETYPE_TOSS)
476 this.move_movetype = MOVETYPE_FLY;
477 if (this.move_movetype == MOVETYPE_BOUNCE)
478 this.move_movetype = MOVETYPE_BOUNCEMISSILE;
481 if (!(this.count & 0x80))
482 InterpolateOrigin_Note(this);
484 this.classname = "csqcprojectile";
485 this.draw = Projectile_Draw;
486 this.entremove = Ent_RemoveProjectile;
489 PRECACHE(Projectiles)
491 MUTATOR_CALLHOOK(PrecacheProjectiles);