1 #include "projectile.qh"
3 #include "../autocvars.qh"
4 #include <client/mutators/_mod.qh>
6 #include <common/constants.qh>
7 #include <common/effects/effect.qh>
8 #include <common/effects/all.qh>
9 #include <common/net_linked.qh>
10 #include <common/physics/movetypes/movetypes.qh>
12 #include <common/mutators/mutator/nades/nades.qh>
14 #include <lib/csqcmodel/interpolate.qh>
16 #include <lib/warpzone/anglestransform.qh>
22 void SUB_Stop(entity this, entity toucher)
24 this.velocity = this.avelocity = '0 0 0';
25 set_movetype(this, MOVETYPE_NONE);
28 void Projectile_ResetTrail(entity this, vector to)
30 this.trail_oldorigin = to;
31 this.trail_oldtime = time;
34 void Projectile_DrawTrail(entity this, vector to)
36 vector from = this.trail_oldorigin;
37 // float t0 = this.trail_oldtime;
38 this.trail_oldorigin = to;
39 this.trail_oldtime = time;
41 // force the effect even for stationary firemine
42 if (this.cnt == PROJECTILE_FIREMINE)
48 particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha);
49 entity eff = REGISTRY_GET(Effects, this.traileffect);
50 boxparticles(particleeffectnum(eff), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
54 void Projectile_Draw(entity this)
65 if (this.count & 0x80)
67 // UNSET_ONGROUND(this);
68 if (this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FLY)
69 Movetype_Physics_NoMatchServer(this);
70 // the trivial movetypes do not have to match the
71 // server's ticrate as they are ticrate independent
72 // NOTE: this assumption is only true if MOVETYPE_FLY
73 // projectiles detonate on impact. If they continue
74 // moving, we might still be ticrate dependent.
76 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
77 if (!IS_ONGROUND(this))
78 if (this.velocity != '0 0 0')
79 this.angles = vectoangles(this.velocity);
83 InterpolateOrigin_Do(this);
86 if (this.count & 0x80)
88 drawn = (time >= this.spawntime - 0.02);
89 t = max(time, this.spawntime);
93 drawn = (this.iflags & IFLAG_VALID);
97 if (!(f & FL_ONGROUND))
103 case PROJECTILE_GRENADE:
104 rot = '-2000 0 0'; // forward
107 case PROJECTILE_GRENADE_BOUNCING:
108 rot = '0 -1000 0'; // sideways
110 case PROJECTILE_HOOKBOMB:
111 rot = '1000 0 0'; // forward
113 case PROJECTILE_ROCKET:
114 rot = '0 0 720'; // spinning
120 if (Projectile_isnade(this.cnt))
121 rot = this.avelocity;
123 this.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(this.angles), rot * (t - this.spawntime)));
131 a = 1 - (time - this.fade_time) * this.fade_rate;
132 this.alpha = bound(0, this.alphamod * a, 1);
135 this.renderflags = 0;
137 trailorigin = this.origin;
140 case PROJECTILE_GRENADE:
141 case PROJECTILE_GRENADE_BOUNCING:
142 trailorigin += v_right * 1 + v_forward * -10;
148 if (Projectile_isnade(this.cnt))
149 trailorigin += v_up * 4;
152 Projectile_DrawTrail(this, trailorigin);
154 Projectile_ResetTrail(this, trailorigin);
163 // Possibly add dlights here.
168 this.drawmask = MASK_NORMAL;
171 void loopsound(entity e, int ch, Sound 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;
219 UNSET_ONGROUND(this);
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 = ReadVector();
239 setorigin(this, this.origin);
240 if (this.count & 0x80)
242 this.velocity = ReadVector();
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 int proj_team = ReadByte();
268 this.team = proj_team - 1;
273 this.colormap = (this.team) * 0x11; // note: team - 1 on server (client uses different numbers)
275 this.colormap = 0x00;
276 this.colormap |= BIT(10); // RENDER_COLORMAPPED
279 this.colormap = proj_team;
280 // TODO: projectiles use glowmaps for their color, not teams
282 if(this.colormap > 0)
283 this.glowmod = colormapPaletteColor(this.colormap & 0x0F, true) * 2;
285 this.glowmod = '1 1 1';
291 this.cnt = ReadByte();
293 this.silent = (this.cnt & 0x80);
294 this.cnt = (this.cnt & 0x7F);
297 this.traileffect = 0;
300 #define HANDLE(id) case PROJECTILE_##id: setmodel(this, MDL_PROJECTILE_##id);
301 HANDLE(ELECTRO) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
302 HANDLE(ROCKET) this.traileffect = EFFECT_TR_ROCKET.m_id; this.scale = 2; break;
303 HANDLE(CRYLINK) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
304 HANDLE(CRYLINK_BOUNCING) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
305 HANDLE(ELECTRO_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
306 HANDLE(GRENADE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
307 HANDLE(GRENADE_BOUNCING) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
308 HANDLE(MINE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
309 HANDLE(BLASTER) this.traileffect = EFFECT_Null.m_id; break;
310 HANDLE(ARC_BOLT) this.traileffect = EFFECT_Null.m_id; break;
311 HANDLE(HLAC) this.traileffect = EFFECT_Null.m_id; break;
312 HANDLE(PORTO_RED) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
313 HANDLE(PORTO_BLUE) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
314 HANDLE(HOOKBOMB) this.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
315 HANDLE(HAGAR) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
316 HANDLE(HAGAR_BOUNCING) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
317 HANDLE(FIREBALL) this.modelindex = 0; this.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
318 HANDLE(FIREMINE) this.modelindex = 0; this.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
319 HANDLE(TAG) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
320 HANDLE(FLAC) this.scale = 0.4; this.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
321 HANDLE(SEEKER) this.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
323 HANDLE(MAGE_SPIKE) this.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
324 HANDLE(SHAMBLER_LIGHTNING) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
326 HANDLE(RAPTORBOMB) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
327 HANDLE(RAPTORBOMBLET) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
328 HANDLE(RAPTORCANNON) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
330 HANDLE(SPIDERROCKET) this.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
331 HANDLE(WAKIROCKET) this.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
332 HANDLE(WAKICANNON) this.traileffect = EFFECT_Null.m_id; break;
334 HANDLE(BUMBLE_GUN) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
335 HANDLE(BUMBLE_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
337 HANDLE(RPC) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
339 HANDLE(ROCKETMINSTA_LASER) this.traileffect = EFFECT_ROCKETMINSTA_LASER(this.team).m_id; break;
342 if (MUTATOR_CALLHOOK(Ent_Projectile, this))
345 error("Received invalid CSQC projectile, can't work with this!");
351 this.colormod = '0 0 0';
352 settouch(this, SUB_Stop);
353 set_movetype(this, MOVETYPE_TOSS);
358 case PROJECTILE_ELECTRO:
359 // only new engines support sound moving with object
360 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
361 this.mins = '-4 -4 -4';
363 set_movetype(this, MOVETYPE_BOUNCE);
364 settouch(this, func_null);
365 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
366 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
369 case PROJECTILE_ROCKET:
370 loopsound(this, CH_SHOTS_SINGLE, SND_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
371 this.mins = '-3 -3 -3';
374 case PROJECTILE_GRENADE:
375 this.mins = '-3 -3 -3';
378 case PROJECTILE_GRENADE_BOUNCING:
379 this.mins = '-3 -3 -3';
381 set_movetype(this, MOVETYPE_BOUNCE);
382 settouch(this, func_null);
383 this.bouncefactor = WEP_CVAR(mortar, bouncefactor);
384 this.bouncestop = WEP_CVAR(mortar, bouncestop);
386 case PROJECTILE_SHAMBLER_LIGHTNING:
387 this.mins = '-8 -8 -8';
390 this.avelocity = randomvec() * 720;
392 case PROJECTILE_MINE:
393 this.mins = '-4 -4 -4';
396 case PROJECTILE_PORTO_RED:
397 this.colormod = '2 1 1';
399 set_movetype(this, MOVETYPE_BOUNCE);
400 settouch(this, func_null);
402 case PROJECTILE_PORTO_BLUE:
403 this.colormod = '1 1 2';
405 set_movetype(this, MOVETYPE_BOUNCE);
406 settouch(this, func_null);
408 case PROJECTILE_HAGAR_BOUNCING:
409 set_movetype(this, MOVETYPE_BOUNCE);
410 settouch(this, func_null);
412 case PROJECTILE_CRYLINK_BOUNCING:
413 set_movetype(this, MOVETYPE_BOUNCE);
414 settouch(this, func_null);
416 case PROJECTILE_FIREBALL:
417 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
418 this.mins = '-16 -16 -16';
419 this.maxs = '16 16 16';
421 case PROJECTILE_FIREMINE:
422 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY, VOL_BASE, ATTEN_NORM);
423 set_movetype(this, MOVETYPE_BOUNCE);
424 settouch(this, func_null);
425 this.mins = '-4 -4 -4';
429 this.mins = '-2 -2 -2';
432 case PROJECTILE_FLAC:
433 this.mins = '-2 -2 -2';
436 case PROJECTILE_SEEKER:
437 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
438 this.mins = '-4 -4 -4';
441 case PROJECTILE_RAPTORBOMB:
442 this.mins = '-3 -3 -3';
445 case PROJECTILE_RAPTORBOMBLET:
447 case PROJECTILE_RAPTORCANNON:
449 case PROJECTILE_SPIDERROCKET:
450 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
452 case PROJECTILE_WAKIROCKET:
453 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
456 case PROJECTILE_WAKICANNON:
458 case PROJECTILE_BUMBLE_GUN:
459 // only new engines support sound moving with object
460 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
461 this.mins = '0 0 -4';
462 this.maxs = '0 0 -4';
463 this.move_movetype = MOVETYPE_BOUNCE;
464 settouch(this, func_null);
465 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
466 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
473 MUTATOR_CALLHOOK(EditProjectile, this);
475 setsize(this, this.mins, this.maxs);
482 if (this.move_movetype == MOVETYPE_FLY)
483 set_movetype(this, MOVETYPE_TOSS);
484 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
485 set_movetype(this, MOVETYPE_BOUNCE);
489 if (this.move_movetype == MOVETYPE_TOSS)
490 set_movetype(this, MOVETYPE_FLY);
491 if (this.move_movetype == MOVETYPE_BOUNCE)
492 set_movetype(this, MOVETYPE_BOUNCEMISSILE);
495 if (!(this.count & 0x80))
496 InterpolateOrigin_Note(this);
498 this.classname = "csqcprojectile";
499 this.draw = Projectile_Draw;
500 if (isnew) IL_PUSH(g_drawables, this);
501 this.entremove = Ent_RemoveProjectile;
504 PRECACHE(Projectiles)
506 MUTATOR_CALLHOOK(PrecacheProjectiles);