1 #include "projectile.qh"
3 #include "../autocvars.qh"
6 #include "../mutators/events.qh"
8 #include <common/constants.qh>
9 #include <common/net_linked.qh>
10 #include <common/physics/movetypes/movetypes.qh>
12 #include <lib/csqcmodel/interpolate.qh>
14 #include <lib/warpzone/anglestransform.qh>
20 void SUB_Stop(entity this, entity toucher)
22 this.velocity = this.avelocity = '0 0 0';
23 set_movetype(this, MOVETYPE_NONE);
26 void Projectile_ResetTrail(entity this, vector to)
28 this.trail_oldorigin = to;
29 this.trail_oldtime = time;
32 void Projectile_DrawTrail(entity this, vector to)
34 vector from = this.trail_oldorigin;
35 // float t0 = this.trail_oldtime;
36 this.trail_oldorigin = to;
37 this.trail_oldtime = time;
39 // force the effect even for stationary firemine
40 if (this.cnt == PROJECTILE_FIREMINE)
46 particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha);
47 boxparticles(particleeffectnum(Effects_from(this.traileffect)), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
51 bool Projectile_isnade(int proj); // TODO: remove
53 void Projectile_Draw(entity this)
64 if (this.count & 0x80)
66 // UNSET_ONGROUND(this);
67 if (this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FLY)
68 Movetype_Physics_NoMatchServer(this);
69 // the trivial movetypes do not have to match the
70 // server's ticrate as they are ticrate independent
71 // NOTE: this assumption is only true if MOVETYPE_FLY
72 // projectiles detonate on impact. If they continue
73 // moving, we might still be ticrate dependent.
75 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
76 if (!IS_ONGROUND(this))
77 if (this.velocity != '0 0 0')
78 this.angles = vectoangles(this.velocity);
82 InterpolateOrigin_Do(this);
85 if (this.count & 0x80)
87 drawn = (time >= this.spawntime - 0.02);
88 t = max(time, this.spawntime);
92 drawn = (this.iflags & IFLAG_VALID);
96 if (!(f & FL_ONGROUND))
102 case PROJECTILE_GRENADE:
103 rot = '-2000 0 0'; // forward
106 case PROJECTILE_GRENADE_BOUNCING:
107 rot = '0 -1000 0'; // sideways
109 case PROJECTILE_HOOKBOMB:
110 rot = '1000 0 0'; // forward
116 if (Projectile_isnade(this.cnt))
117 rot = this.avelocity;
119 this.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(this.angles), rot * (t - this.spawntime)));
127 a = 1 - (time - this.fade_time) * this.fade_rate;
128 this.alpha = bound(0, this.alphamod * a, 1);
131 this.renderflags = 0;
133 trailorigin = this.origin;
136 case PROJECTILE_GRENADE:
137 case PROJECTILE_GRENADE_BOUNCING:
138 trailorigin += v_right * 1 + v_forward * -10;
144 if (Projectile_isnade(this.cnt))
145 trailorigin += v_up * 4;
148 Projectile_DrawTrail(this, trailorigin);
150 Projectile_ResetTrail(this, trailorigin);
159 // Possibly add dlights here.
164 this.drawmask = MASK_NORMAL;
167 void loopsound(entity e, int ch, string samp, float vol, float attn)
173 _sound(e, ch, samp, vol, attn);
177 void Ent_RemoveProjectile(entity this)
179 if (this.count & 0x80)
181 tracebox(this.origin, this.mins, this.maxs, this.origin + this.velocity * 0.05, MOVE_NORMAL, this);
182 Projectile_DrawTrail(this, trace_endpos);
186 NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
188 // projectile properties:
189 // kind (interpolated, or clientside)
197 // soundindex (hardcoded list)
200 // projectiles don't send angles, because they always follow the velocity
203 this.count = (f & 0x80);
204 this.flags |= FL_PROJECTILE;
205 this.iflags = (this.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES | IFLAG_ORIGIN;
206 this.solid = SOLID_TRIGGER;
207 // this.effects = EF_NOMODELFLAGS;
209 // this should make collisions with bmodels more exact, but it leads to
210 // projectiles no longer being able to lie on a bmodel
211 this.move_nomonsters = MOVE_WORLDONLY;
215 UNSET_ONGROUND(this);
219 // for some unknown reason, we don't need to care for
220 // sv_gameplayfix_delayprojectiles here.
221 this.move_time = time;
222 this.spawntime = time;
226 this.move_time = max(this.move_time, time);
229 if (!(this.count & 0x80))
230 InterpolateOrigin_Undo(this);
234 this.origin_x = ReadCoord();
235 this.origin_y = ReadCoord();
236 this.origin_z = ReadCoord();
237 setorigin(this, this.origin);
238 if (this.count & 0x80)
240 this.velocity_x = ReadCoord();
241 this.velocity_y = ReadCoord();
242 this.velocity_z = ReadCoord();
244 this.gravity = ReadCoord();
246 this.gravity = 0; // none
249 if (time == this.spawntime || (this.count & 0x80) || (f & 0x08))
251 this.trail_oldorigin = this.origin;
252 if (!(this.count & 0x80))
253 InterpolateOrigin_Reset(this);
258 this.fade_time = time + ReadByte() * ticrate;
259 this.fade_rate = 1 / (ReadByte() * ticrate);
267 this.team = ReadByte() - 1;
272 this.cnt = ReadByte();
274 this.silent = (this.cnt & 0x80);
275 this.cnt = (this.cnt & 0x7F);
278 this.traileffect = 0;
281 #define HANDLE(id) case PROJECTILE_##id: setmodel(this, MDL_PROJECTILE_##id);
282 HANDLE(ELECTRO) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
283 HANDLE(ROCKET) this.traileffect = EFFECT_TR_ROCKET.m_id; this.scale = 2; break;
284 HANDLE(CRYLINK) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
285 HANDLE(CRYLINK_BOUNCING) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
286 HANDLE(ELECTRO_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
287 HANDLE(GRENADE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
288 HANDLE(GRENADE_BOUNCING) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
289 HANDLE(MINE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
290 HANDLE(BLASTER) this.traileffect = EFFECT_Null.m_id; break;
291 HANDLE(ARC_BOLT) this.traileffect = EFFECT_Null.m_id; break;
292 HANDLE(HLAC) this.traileffect = EFFECT_Null.m_id; break;
293 HANDLE(PORTO_RED) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
294 HANDLE(PORTO_BLUE) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
295 HANDLE(HOOKBOMB) this.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
296 HANDLE(HAGAR) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
297 HANDLE(HAGAR_BOUNCING) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
298 HANDLE(FIREBALL) this.modelindex = 0; this.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
299 HANDLE(FIREMINE) this.modelindex = 0; this.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
300 HANDLE(TAG) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
301 HANDLE(FLAC) this.scale = 0.4; this.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
302 HANDLE(SEEKER) this.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
304 HANDLE(MAGE_SPIKE) this.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
305 HANDLE(SHAMBLER_LIGHTNING) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
307 HANDLE(RAPTORBOMB) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
308 HANDLE(RAPTORBOMBLET) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
309 HANDLE(RAPTORCANNON) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
311 HANDLE(SPIDERROCKET) this.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
312 HANDLE(WAKIROCKET) this.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
313 HANDLE(WAKICANNON) this.traileffect = EFFECT_Null.m_id; break;
315 HANDLE(BUMBLE_GUN) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
316 HANDLE(BUMBLE_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
318 HANDLE(RPC) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
320 HANDLE(ROCKETMINSTA_LASER) this.traileffect = EFFECT_ROCKETMINSTA_LASER(this.team).m_id; break;
323 if (MUTATOR_CALLHOOK(Ent_Projectile, this))
326 error("Received invalid CSQC projectile, can't work with this!");
332 this.colormod = '0 0 0';
333 settouch(this, SUB_Stop);
334 set_movetype(this, MOVETYPE_TOSS);
339 case PROJECTILE_ELECTRO:
340 // only new engines support sound moving with object
341 loopsound(this, CH_SHOTS_SINGLE, SND(ELECTRO_FLY), VOL_BASE, ATTEN_NORM);
342 this.mins = '-4 -4 -4';
344 set_movetype(this, MOVETYPE_BOUNCE);
345 settouch(this, func_null);
346 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
347 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
350 case PROJECTILE_ROCKET:
351 loopsound(this, CH_SHOTS_SINGLE, SND(ROCKET_FLY), VOL_BASE, ATTEN_NORM);
352 this.mins = '-3 -3 -3';
355 case PROJECTILE_GRENADE:
356 this.mins = '-3 -3 -3';
359 case PROJECTILE_GRENADE_BOUNCING:
360 this.mins = '-3 -3 -3';
362 set_movetype(this, MOVETYPE_BOUNCE);
363 settouch(this, func_null);
364 this.bouncefactor = WEP_CVAR(mortar, bouncefactor);
365 this.bouncestop = WEP_CVAR(mortar, bouncestop);
367 case PROJECTILE_SHAMBLER_LIGHTNING:
368 this.mins = '-8 -8 -8';
371 this.avelocity = randomvec() * 720;
373 case PROJECTILE_MINE:
374 this.mins = '-4 -4 -4';
377 case PROJECTILE_PORTO_RED:
378 this.colormod = '2 1 1';
380 set_movetype(this, MOVETYPE_BOUNCE);
381 settouch(this, func_null);
383 case PROJECTILE_PORTO_BLUE:
384 this.colormod = '1 1 2';
386 set_movetype(this, MOVETYPE_BOUNCE);
387 settouch(this, func_null);
389 case PROJECTILE_HAGAR_BOUNCING:
390 set_movetype(this, MOVETYPE_BOUNCE);
391 settouch(this, func_null);
393 case PROJECTILE_CRYLINK_BOUNCING:
394 set_movetype(this, MOVETYPE_BOUNCE);
395 settouch(this, func_null);
397 case PROJECTILE_FIREBALL:
398 loopsound(this, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
399 this.mins = '-16 -16 -16';
400 this.maxs = '16 16 16';
402 case PROJECTILE_FIREMINE:
403 loopsound(this, CH_SHOTS_SINGLE, SND(FIREBALL_FLY), VOL_BASE, ATTEN_NORM);
404 set_movetype(this, MOVETYPE_BOUNCE);
405 settouch(this, func_null);
406 this.mins = '-4 -4 -4';
410 this.mins = '-2 -2 -2';
413 case PROJECTILE_FLAC:
414 this.mins = '-2 -2 -2';
417 case PROJECTILE_SEEKER:
418 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
419 this.mins = '-4 -4 -4';
422 case PROJECTILE_RAPTORBOMB:
423 this.mins = '-3 -3 -3';
426 case PROJECTILE_RAPTORBOMBLET:
428 case PROJECTILE_RAPTORCANNON:
430 case PROJECTILE_SPIDERROCKET:
431 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
433 case PROJECTILE_WAKIROCKET:
434 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
437 case PROJECTILE_WAKICANNON:
439 case PROJECTILE_BUMBLE_GUN:
440 // only new engines support sound moving with object
441 loopsound(this, CH_SHOTS_SINGLE, SND(ELECTRO_FLY), VOL_BASE, ATTEN_NORM);
442 this.mins = '0 0 -4';
443 this.maxs = '0 0 -4';
444 this.move_movetype = MOVETYPE_BOUNCE;
445 settouch(this, func_null);
446 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
447 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
454 MUTATOR_CALLHOOK(EditProjectile, this);
456 setsize(this, this.mins, this.maxs);
463 if (this.move_movetype == MOVETYPE_FLY)
464 set_movetype(this, MOVETYPE_TOSS);
465 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
466 set_movetype(this, MOVETYPE_BOUNCE);
470 if (this.move_movetype == MOVETYPE_TOSS)
471 set_movetype(this, MOVETYPE_FLY);
472 if (this.move_movetype == MOVETYPE_BOUNCE)
473 set_movetype(this, MOVETYPE_BOUNCEMISSILE);
476 if (!(this.count & 0x80))
477 InterpolateOrigin_Note(this);
479 this.classname = "csqcprojectile";
480 this.draw = Projectile_Draw;
481 if (isnew) IL_PUSH(g_drawables, this);
482 this.entremove = Ent_RemoveProjectile;
485 PRECACHE(Projectiles)
487 MUTATOR_CALLHOOK(PrecacheProjectiles);