1 #include "projectile.qh"
3 #include <client/autocvars.qh>
4 #include <client/mutators/_mod.qh>
5 #include <common/constants.qh>
6 #include <common/effects/all.qh>
7 #include <common/effects/effect.qh>
8 #include <common/mutators/mutator/nades/nades.qh>
9 #include <common/net_linked.qh>
10 #include <common/physics/movetypes/movetypes.qh>
11 #include <lib/csqcmodel/interpolate.qh>
12 #include <lib/warpzone/anglestransform.qh>
18 void SUB_Stop(entity this, entity toucher)
20 this.velocity = this.avelocity = '0 0 0';
21 set_movetype(this, MOVETYPE_NONE);
24 void Projectile_ResetTrail(entity this, vector to)
26 this.trail_oldorigin = to;
27 this.trail_oldtime = time;
30 void Projectile_DrawTrail(entity this, vector to)
32 vector from = this.trail_oldorigin;
33 // float t0 = this.trail_oldtime;
34 this.trail_oldorigin = to;
35 this.trail_oldtime = time;
37 // force the effect even for stationary firemine
38 if (this.cnt == PROJECTILE_FIREMINE)
44 particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha);
45 entity eff = REGISTRY_GET(Effects, this.traileffect);
46 boxparticles(particleeffectnum(eff), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
50 void Projectile_Draw(entity this)
61 if (this.count & 0x80)
63 // UNSET_ONGROUND(this);
64 if (this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FLY)
65 Movetype_Physics_NoMatchServer(this);
66 // the trivial movetypes do not have to match the
67 // server's ticrate as they are ticrate independent
68 // NOTE: this assumption is only true if MOVETYPE_FLY
69 // projectiles detonate on impact. If they continue
70 // moving, we might still be ticrate dependent.
72 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
73 if (!IS_ONGROUND(this))
74 if (this.velocity != '0 0 0')
75 this.angles = vectoangles(this.velocity);
79 InterpolateOrigin_Do(this);
82 if (this.count & 0x80)
84 drawn = (time >= this.spawntime - 0.02);
85 t = max(time, this.spawntime);
89 drawn = (this.iflags & IFLAG_VALID);
93 if (!(f & FL_ONGROUND))
99 case PROJECTILE_GRENADE:
100 rot = '-2000 0 0'; // forward
103 case PROJECTILE_GRENADE_BOUNCING:
104 rot = '0 -1000 0'; // sideways
106 case PROJECTILE_HOOKBOMB:
107 rot = '1000 0 0'; // forward
109 case PROJECTILE_ROCKET:
110 rot = '0 0 720'; // spinning
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, Sound 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 = ReadVector();
235 setorigin(this, this.origin);
236 if (this.count & 0x80)
238 this.velocity = ReadVector();
240 this.gravity = ReadCoord();
242 this.gravity = 0; // none
245 if (time == this.spawntime || (this.count & 0x80) || (f & 0x08))
247 this.trail_oldorigin = this.origin;
248 if (!(this.count & 0x80))
249 InterpolateOrigin_Reset(this);
254 this.fade_time = time + ReadByte() * ticrate;
255 this.fade_rate = 1 / (ReadByte() * ticrate);
263 int proj_team = ReadByte();
264 this.team = proj_team - 1;
269 this.colormap = (this.team) * 0x11; // note: team - 1 on server (client uses different numbers)
271 this.colormap = 0x00;
272 this.colormap |= BIT(10); // RENDER_COLORMAPPED
275 this.colormap = proj_team;
276 // TODO: projectiles use glowmaps for their color, not teams
278 if(this.colormap > 0)
279 this.glowmod = colormapPaletteColor(this.colormap & 0x0F, true) * 2;
281 this.glowmod = '1 1 1';
287 this.cnt = ReadByte();
289 this.silent = (this.cnt & 0x80);
290 this.cnt = (this.cnt & 0x7F);
293 this.traileffect = 0;
296 #define HANDLE(id) case PROJECTILE_##id: setmodel(this, MDL_PROJECTILE_##id);
297 HANDLE(ELECTRO) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
298 HANDLE(ROCKET) this.traileffect = EFFECT_TR_ROCKET.m_id; this.scale = 2; break;
299 HANDLE(CRYLINK) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
300 HANDLE(CRYLINK_BOUNCING) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
301 HANDLE(ELECTRO_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
302 HANDLE(GRENADE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
303 HANDLE(GRENADE_BOUNCING) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
304 HANDLE(MINE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
305 HANDLE(BLASTER) this.traileffect = EFFECT_Null.m_id; break;
306 HANDLE(ARC_BOLT) this.traileffect = EFFECT_Null.m_id; break;
307 HANDLE(HLAC) this.traileffect = EFFECT_Null.m_id; break;
308 HANDLE(PORTO_RED) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
309 HANDLE(PORTO_BLUE) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
310 HANDLE(HOOKBOMB) this.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
311 HANDLE(HAGAR) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
312 HANDLE(HAGAR_BOUNCING) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
313 HANDLE(FIREBALL) this.modelindex = 0; this.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
314 HANDLE(FIREMINE) this.modelindex = 0; this.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
315 HANDLE(TAG) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
316 HANDLE(FLAC) this.scale = 0.4; this.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
317 HANDLE(SEEKER) this.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
319 HANDLE(MAGE_SPIKE) this.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
320 HANDLE(SHAMBLER_LIGHTNING) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
322 HANDLE(RAPTORBOMB) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
323 HANDLE(RAPTORBOMBLET) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
324 HANDLE(RAPTORCANNON) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
326 HANDLE(SPIDERROCKET) this.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
327 HANDLE(WAKIROCKET) this.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
328 HANDLE(WAKICANNON) this.traileffect = EFFECT_Null.m_id; break;
330 HANDLE(BUMBLE_GUN) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
331 HANDLE(BUMBLE_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
333 HANDLE(RPC) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
335 HANDLE(ROCKETMINSTA_LASER) this.traileffect = EFFECT_ROCKETMINSTA_LASER(this.team).m_id; break;
338 if (MUTATOR_CALLHOOK(Ent_Projectile, this))
341 error("Received invalid CSQC projectile, can't work with this!");
347 this.colormod = '0 0 0';
348 settouch(this, SUB_Stop);
349 set_movetype(this, MOVETYPE_TOSS);
354 case PROJECTILE_ELECTRO:
355 // only new engines support sound moving with object
356 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
357 this.mins = '-4 -4 -4';
359 set_movetype(this, MOVETYPE_BOUNCE);
360 settouch(this, func_null);
361 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
362 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
365 case PROJECTILE_ROCKET:
366 loopsound(this, CH_SHOTS_SINGLE, SND_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
367 this.mins = '-3 -3 -3';
370 case PROJECTILE_GRENADE:
371 this.mins = '-3 -3 -3';
374 case PROJECTILE_GRENADE_BOUNCING:
375 this.mins = '-3 -3 -3';
377 set_movetype(this, MOVETYPE_BOUNCE);
378 settouch(this, func_null);
379 this.bouncefactor = WEP_CVAR(mortar, bouncefactor);
380 this.bouncestop = WEP_CVAR(mortar, bouncestop);
382 case PROJECTILE_SHAMBLER_LIGHTNING:
383 this.mins = '-8 -8 -8';
386 this.avelocity = randomvec() * 720;
388 case PROJECTILE_MINE:
389 this.mins = '-4 -4 -4';
392 case PROJECTILE_PORTO_RED:
393 this.colormod = '2 1 1';
395 set_movetype(this, MOVETYPE_BOUNCE);
396 settouch(this, func_null);
398 case PROJECTILE_PORTO_BLUE:
399 this.colormod = '1 1 2';
401 set_movetype(this, MOVETYPE_BOUNCE);
402 settouch(this, func_null);
404 case PROJECTILE_HAGAR_BOUNCING:
405 set_movetype(this, MOVETYPE_BOUNCE);
406 settouch(this, func_null);
408 case PROJECTILE_CRYLINK_BOUNCING:
409 set_movetype(this, MOVETYPE_BOUNCE);
410 settouch(this, func_null);
412 case PROJECTILE_FIREBALL:
413 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
414 this.mins = '-16 -16 -16';
415 this.maxs = '16 16 16';
417 case PROJECTILE_FIREMINE:
418 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY, VOL_BASE, ATTEN_NORM);
419 set_movetype(this, MOVETYPE_BOUNCE);
420 settouch(this, func_null);
421 this.mins = '-4 -4 -4';
425 this.mins = '-2 -2 -2';
428 case PROJECTILE_FLAC:
429 this.mins = '-2 -2 -2';
432 case PROJECTILE_SEEKER:
433 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
434 this.mins = '-4 -4 -4';
437 case PROJECTILE_RAPTORBOMB:
438 this.mins = '-3 -3 -3';
441 case PROJECTILE_RAPTORBOMBLET:
443 case PROJECTILE_RAPTORCANNON:
445 case PROJECTILE_SPIDERROCKET:
446 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
448 case PROJECTILE_WAKIROCKET:
449 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
452 case PROJECTILE_WAKICANNON:
454 case PROJECTILE_BUMBLE_GUN:
455 // only new engines support sound moving with object
456 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
457 this.mins = '0 0 -4';
458 this.maxs = '0 0 -4';
459 this.move_movetype = MOVETYPE_BOUNCE;
460 settouch(this, func_null);
461 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
462 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
469 MUTATOR_CALLHOOK(EditProjectile, this);
471 setsize(this, this.mins, this.maxs);
478 if (this.move_movetype == MOVETYPE_FLY)
479 set_movetype(this, MOVETYPE_TOSS);
480 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
481 set_movetype(this, MOVETYPE_BOUNCE);
485 if (this.move_movetype == MOVETYPE_TOSS)
486 set_movetype(this, MOVETYPE_FLY);
487 if (this.move_movetype == MOVETYPE_BOUNCE)
488 set_movetype(this, MOVETYPE_BOUNCEMISSILE);
491 if (!(this.count & 0x80))
492 InterpolateOrigin_Note(this);
494 this.draw = Projectile_Draw;
495 if (isnew) IL_PUSH(g_drawables, this);
496 this.entremove = Ent_RemoveProjectile;
499 PRECACHE(Projectiles)
501 MUTATOR_CALLHOOK(PrecacheProjectiles);