1 #include "projectile.qh"
3 #include <client/mutators/_mod.qh>
4 #include <common/constants.qh>
5 #include <common/effects/all.qh>
6 #include <common/effects/effect.qh>
7 #include <common/mutators/mutator/nades/nades.qh>
8 #include <common/net_linked.qh>
9 #include <common/physics/movetypes/movetypes.qh>
10 #include <lib/csqcmodel/interpolate.qh>
11 #include <lib/warpzone/anglestransform.qh>
17 void SUB_Stop(entity this, entity toucher)
19 this.velocity = this.avelocity = '0 0 0';
20 set_movetype(this, MOVETYPE_NONE);
23 void Projectile_ResetTrail(entity this, vector to)
25 this.trail_oldorigin = to;
26 this.trail_oldtime = time;
29 void Projectile_DrawTrail(entity this, vector to)
31 vector from = this.trail_oldorigin;
32 // float t0 = this.trail_oldtime;
33 this.trail_oldorigin = to;
34 this.trail_oldtime = time;
36 // force the effect even for stationary firemine
37 if (this.cnt == PROJECTILE_FIREMINE)
43 particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha);
44 entity eff = REGISTRY_GET(Effects, this.traileffect);
45 boxparticles(particleeffectnum(eff), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
49 void Projectile_Draw(entity this)
60 if (this.count & 0x80)
62 // UNSET_ONGROUND(this);
63 if (this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FLY)
64 Movetype_Physics_NoMatchServer(this);
65 // the trivial movetypes do not have to match the
66 // server's ticrate as they are ticrate independent
67 // NOTE: this assumption is only true if MOVETYPE_FLY
68 // projectiles detonate on impact. If they continue
69 // moving, we might still be ticrate dependent.
71 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
72 if (!IS_ONGROUND(this))
73 if (this.velocity != '0 0 0')
74 this.angles = vectoangles(this.velocity);
78 InterpolateOrigin_Do(this);
81 if (this.count & 0x80)
83 drawn = (time >= this.spawntime - 0.02);
84 t = max(time, this.spawntime);
88 drawn = (this.iflags & IFLAG_VALID);
92 if (!(f & FL_ONGROUND))
98 case PROJECTILE_GRENADE:
99 rot = '-2000 0 0'; // forward
102 case PROJECTILE_GRENADE_BOUNCING:
103 rot = '0 -1000 0'; // sideways
105 case PROJECTILE_HOOKBOMB:
106 rot = '1000 0 0'; // forward
108 case PROJECTILE_ROCKET:
109 rot = '0 0 720'; // spinning
115 if (Projectile_isnade(this.cnt))
116 rot = this.avelocity;
118 this.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(this.angles), rot * (t - this.spawntime)));
126 a = 1 - (time - this.fade_time) * this.fade_rate;
127 this.alpha = bound(0, this.alphamod * a, 1);
130 this.renderflags = 0;
132 trailorigin = this.origin;
135 case PROJECTILE_GRENADE:
136 case PROJECTILE_GRENADE_BOUNCING:
137 trailorigin += v_right * 1 + v_forward * -10;
143 if (Projectile_isnade(this.cnt))
144 trailorigin += v_up * 4;
147 Projectile_DrawTrail(this, trailorigin);
149 Projectile_ResetTrail(this, trailorigin);
158 // Possibly add dlights here.
163 this.drawmask = MASK_NORMAL;
166 void loopsound(entity e, int ch, Sound samp, float vol, float attn)
172 sound(e, ch, samp, vol, attn);
176 void Ent_RemoveProjectile(entity this)
178 if (this.count & 0x80)
180 tracebox(this.origin, this.mins, this.maxs, this.origin + this.velocity * 0.05, MOVE_NORMAL, this);
181 Projectile_DrawTrail(this, trace_endpos);
185 NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
187 // projectile properties:
188 // kind (interpolated, or clientside)
196 // soundindex (hardcoded list)
199 // projectiles don't send angles, because they always follow the velocity
202 this.count = (f & 0x80);
203 this.flags |= FL_PROJECTILE;
204 this.iflags = (this.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES | IFLAG_ORIGIN;
205 this.solid = SOLID_TRIGGER;
206 // this.effects = EF_NOMODELFLAGS;
208 // this should make collisions with bmodels more exact, but it leads to
209 // projectiles no longer being able to lie on a bmodel
210 this.move_nomonsters = MOVE_WORLDONLY;
214 UNSET_ONGROUND(this);
218 // for some unknown reason, we don't need to care for
219 // sv_gameplayfix_delayprojectiles here.
220 this.move_time = time;
221 this.spawntime = time;
225 this.move_time = max(this.move_time, time);
228 if (!(this.count & 0x80))
229 InterpolateOrigin_Undo(this);
233 this.origin = ReadVector();
234 setorigin(this, this.origin);
235 if (this.count & 0x80)
237 this.velocity = ReadVector();
239 this.gravity = ReadCoord();
241 this.gravity = 0; // none
244 if (time == this.spawntime || (this.count & 0x80) || (f & 0x08))
246 this.trail_oldorigin = this.origin;
247 if (!(this.count & 0x80))
248 InterpolateOrigin_Reset(this);
253 this.fade_time = time + ReadByte() * ticrate;
254 this.fade_rate = 1 / (ReadByte() * ticrate);
262 int proj_team = ReadByte();
263 this.team = proj_team - 1;
268 this.colormap = (this.team) * 0x11; // note: team - 1 on server (client uses different numbers)
270 this.colormap = 0x00;
271 this.colormap |= BIT(10); // RENDER_COLORMAPPED
274 this.colormap = proj_team;
275 // TODO: projectiles use glowmaps for their color, not teams
277 if(this.colormap > 0)
278 this.glowmod = colormapPaletteColor(this.colormap & 0x0F, true) * 2;
280 this.glowmod = '1 1 1';
286 this.cnt = ReadByte();
288 this.silent = (this.cnt & 0x80);
289 this.cnt = (this.cnt & 0x7F);
292 this.traileffect = 0;
295 #define HANDLE(id) case PROJECTILE_##id: setmodel(this, MDL_PROJECTILE_##id);
296 HANDLE(ELECTRO) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
297 HANDLE(ROCKET) this.traileffect = EFFECT_TR_ROCKET.m_id; this.scale = 2; break;
298 HANDLE(CRYLINK) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
299 HANDLE(CRYLINK_BOUNCING) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
300 HANDLE(ELECTRO_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
301 HANDLE(GRENADE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
302 HANDLE(GRENADE_BOUNCING) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
303 HANDLE(MINE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
304 HANDLE(BLASTER) this.traileffect = EFFECT_Null.m_id; break;
305 HANDLE(ARC_BOLT) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; break;
306 HANDLE(HLAC) this.traileffect = EFFECT_Null.m_id; break;
307 HANDLE(PORTO_RED) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
308 HANDLE(PORTO_BLUE) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
309 HANDLE(HOOKBOMB) this.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
310 HANDLE(HAGAR) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
311 HANDLE(HAGAR_BOUNCING) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
312 HANDLE(FIREBALL) this.modelindex = 0; this.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
313 HANDLE(FIREMINE) this.modelindex = 0; this.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
314 HANDLE(TAG) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
315 HANDLE(FLAC) this.scale = 0.4; this.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
316 HANDLE(SEEKER) this.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
318 HANDLE(MAGE_SPIKE) this.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
319 HANDLE(SHAMBLER_LIGHTNING) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
321 HANDLE(RAPTORBOMB) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
322 HANDLE(RAPTORBOMBLET) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
323 HANDLE(RAPTORCANNON) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
325 HANDLE(SPIDERROCKET) this.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
326 HANDLE(WAKIROCKET) this.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
327 HANDLE(WAKICANNON) this.traileffect = EFFECT_Null.m_id; break;
329 HANDLE(BUMBLE_GUN) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
330 HANDLE(BUMBLE_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
332 HANDLE(RPC) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
334 HANDLE(ROCKETMINSTA_LASER) this.traileffect = EFFECT_ROCKETMINSTA_LASER(this.team).m_id; break;
337 if (MUTATOR_CALLHOOK(Ent_Projectile, this))
340 error("Received invalid CSQC projectile, can't work with this!");
346 this.colormod = '0 0 0';
347 settouch(this, SUB_Stop);
348 set_movetype(this, MOVETYPE_TOSS);
353 case PROJECTILE_ELECTRO:
354 // only new engines support sound moving with object
355 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
356 this.mins = '-4 -4 -4';
358 set_movetype(this, MOVETYPE_BOUNCE);
359 settouch(this, func_null);
360 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
361 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
364 case PROJECTILE_ROCKET:
365 loopsound(this, CH_SHOTS_SINGLE, SND_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
366 this.mins = '-3 -3 -3';
369 case PROJECTILE_GRENADE:
370 this.mins = '-3 -3 -3';
373 case PROJECTILE_GRENADE_BOUNCING:
374 this.mins = '-3 -3 -3';
376 set_movetype(this, MOVETYPE_BOUNCE);
377 settouch(this, func_null);
378 this.bouncefactor = WEP_CVAR(mortar, bouncefactor);
379 this.bouncestop = WEP_CVAR(mortar, bouncestop);
381 case PROJECTILE_SHAMBLER_LIGHTNING:
382 this.mins = '-8 -8 -8';
385 this.avelocity = randomvec() * 720;
387 case PROJECTILE_MINE:
388 this.mins = '-4 -4 -4';
391 case PROJECTILE_PORTO_RED:
392 this.colormod = '2 1 1';
394 set_movetype(this, MOVETYPE_BOUNCE);
395 settouch(this, func_null);
397 case PROJECTILE_PORTO_BLUE:
398 this.colormod = '1 1 2';
400 set_movetype(this, MOVETYPE_BOUNCE);
401 settouch(this, func_null);
403 case PROJECTILE_HAGAR_BOUNCING:
404 set_movetype(this, MOVETYPE_BOUNCE);
405 settouch(this, func_null);
407 case PROJECTILE_CRYLINK_BOUNCING:
408 set_movetype(this, MOVETYPE_BOUNCE);
409 settouch(this, func_null);
411 case PROJECTILE_FIREBALL:
412 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
413 this.mins = '-16 -16 -16';
414 this.maxs = '16 16 16';
416 case PROJECTILE_FIREMINE:
417 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY, VOL_BASE, ATTEN_NORM);
418 set_movetype(this, MOVETYPE_BOUNCE);
419 settouch(this, func_null);
420 this.mins = '-4 -4 -4';
424 this.mins = '-2 -2 -2';
427 case PROJECTILE_FLAC:
428 this.mins = '-2 -2 -2';
431 case PROJECTILE_SEEKER:
432 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
433 this.mins = '-4 -4 -4';
436 case PROJECTILE_ARC_BOLT:
437 set_movetype(this, MOVETYPE_BOUNCE);
438 settouch(this, func_null);
440 case PROJECTILE_RAPTORBOMB:
441 this.mins = '-3 -3 -3';
444 case PROJECTILE_RAPTORBOMBLET:
446 case PROJECTILE_RAPTORCANNON:
448 case PROJECTILE_SPIDERROCKET:
449 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
451 case PROJECTILE_WAKIROCKET:
452 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
455 case PROJECTILE_WAKICANNON:
457 case PROJECTILE_BUMBLE_GUN:
458 // only new engines support sound moving with object
459 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
460 this.mins = '0 0 -4';
461 this.maxs = '0 0 -4';
462 this.move_movetype = MOVETYPE_BOUNCE;
463 settouch(this, func_null);
464 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
465 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
472 MUTATOR_CALLHOOK(EditProjectile, this);
474 setsize(this, this.mins, this.maxs);
481 if (this.move_movetype == MOVETYPE_FLY)
482 set_movetype(this, MOVETYPE_TOSS);
483 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
484 set_movetype(this, MOVETYPE_BOUNCE);
488 if (this.move_movetype == MOVETYPE_TOSS)
489 set_movetype(this, MOVETYPE_FLY);
490 if (this.move_movetype == MOVETYPE_BOUNCE)
491 set_movetype(this, MOVETYPE_BOUNCEMISSILE);
494 if (!(this.count & 0x80))
495 InterpolateOrigin_Note(this);
497 this.draw = Projectile_Draw;
498 if (isnew) IL_PUSH(g_drawables, this);
499 this.entremove = Ent_RemoveProjectile;
502 PRECACHE(Projectiles)
504 MUTATOR_CALLHOOK(PrecacheProjectiles);