1 #include "projectile.qh"
3 #include "../autocvars.qh"
6 #include <client/mutators/_mod.qh>
8 #include <common/constants.qh>
9 #include <common/effects/effect.qh>
10 #include <common/effects/all.qh>
11 #include <common/net_linked.qh>
12 #include <common/physics/movetypes/movetypes.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 boxparticles(particleeffectnum(Effects_from(this.traileffect)), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
53 bool Projectile_isnade(int proj); // TODO: remove
55 void Projectile_Draw(entity this)
66 if (this.count & 0x80)
68 // UNSET_ONGROUND(this);
69 if (this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FLY)
70 Movetype_Physics_NoMatchServer(this);
71 // the trivial movetypes do not have to match the
72 // server's ticrate as they are ticrate independent
73 // NOTE: this assumption is only true if MOVETYPE_FLY
74 // projectiles detonate on impact. If they continue
75 // moving, we might still be ticrate dependent.
77 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
78 if (!IS_ONGROUND(this))
79 if (this.velocity != '0 0 0')
80 this.angles = vectoangles(this.velocity);
84 InterpolateOrigin_Do(this);
87 if (this.count & 0x80)
89 drawn = (time >= this.spawntime - 0.02);
90 t = max(time, this.spawntime);
94 drawn = (this.iflags & IFLAG_VALID);
98 if (!(f & FL_ONGROUND))
104 case PROJECTILE_GRENADE:
105 rot = '-2000 0 0'; // forward
108 case PROJECTILE_GRENADE_BOUNCING:
109 rot = '0 -1000 0'; // sideways
111 case PROJECTILE_HOOKBOMB:
112 rot = '1000 0 0'; // forward
114 case PROJECTILE_ROCKET:
115 rot = '0 0 720'; // spinning
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, Sound samp, float vol, float attn)
178 sound(e, ch, samp, vol, attn);
182 void Ent_RemoveProjectile(entity this)
184 if (this.count & 0x80)
186 tracebox(this.origin, this.mins, this.maxs, this.origin + this.velocity * 0.05, MOVE_NORMAL, this);
187 Projectile_DrawTrail(this, trace_endpos);
191 NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
193 // projectile properties:
194 // kind (interpolated, or clientside)
202 // soundindex (hardcoded list)
205 // projectiles don't send angles, because they always follow the velocity
208 this.count = (f & 0x80);
209 this.flags |= FL_PROJECTILE;
210 this.iflags = (this.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES | IFLAG_ORIGIN;
211 this.solid = SOLID_TRIGGER;
212 // this.effects = EF_NOMODELFLAGS;
214 // this should make collisions with bmodels more exact, but it leads to
215 // projectiles no longer being able to lie on a bmodel
216 this.move_nomonsters = MOVE_WORLDONLY;
220 UNSET_ONGROUND(this);
224 // for some unknown reason, we don't need to care for
225 // sv_gameplayfix_delayprojectiles here.
226 this.move_time = time;
227 this.spawntime = time;
231 this.move_time = max(this.move_time, time);
234 if (!(this.count & 0x80))
235 InterpolateOrigin_Undo(this);
239 this.origin = ReadVector();
240 setorigin(this, this.origin);
241 if (this.count & 0x80)
243 this.velocity = ReadVector();
245 this.gravity = ReadCoord();
247 this.gravity = 0; // none
250 if (time == this.spawntime || (this.count & 0x80) || (f & 0x08))
252 this.trail_oldorigin = this.origin;
253 if (!(this.count & 0x80))
254 InterpolateOrigin_Reset(this);
259 this.fade_time = time + ReadByte() * ticrate;
260 this.fade_rate = 1 / (ReadByte() * ticrate);
268 int myteam = ReadByte();
269 this.team = myteam - 1;
274 this.colormap = (this.team) * 0x11; // note: team - 1 on server (client uses different numbers)
276 this.colormap = 0x00;
277 this.colormap |= BIT(10); // RENDER_COLORMAPPED
280 this.colormap = myteam;
281 // TODO: projectiles use glowmaps for their color, not teams
283 if(this.colormap > 0)
284 this.glowmod = colormapPaletteColor(this.colormap & 0x0F, true) * 2;
286 this.glowmod = '1 1 1';
292 this.cnt = ReadByte();
294 this.silent = (this.cnt & 0x80);
295 this.cnt = (this.cnt & 0x7F);
298 this.traileffect = 0;
301 #define HANDLE(id) case PROJECTILE_##id: setmodel(this, MDL_PROJECTILE_##id);
302 HANDLE(ELECTRO) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
303 HANDLE(ROCKET) this.traileffect = EFFECT_TR_ROCKET.m_id; this.scale = 2; break;
304 HANDLE(CRYLINK) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
305 HANDLE(CRYLINK_BOUNCING) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
306 HANDLE(ELECTRO_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
307 HANDLE(GRENADE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
308 HANDLE(GRENADE_BOUNCING) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
309 HANDLE(MINE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
310 HANDLE(BLASTER) this.traileffect = EFFECT_Null.m_id; break;
311 HANDLE(ARC_BOLT) this.traileffect = EFFECT_Null.m_id; break;
312 HANDLE(HLAC) this.traileffect = EFFECT_Null.m_id; break;
313 HANDLE(PORTO_RED) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
314 HANDLE(PORTO_BLUE) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
315 HANDLE(HOOKBOMB) this.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
316 HANDLE(HAGAR) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
317 HANDLE(HAGAR_BOUNCING) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
318 HANDLE(FIREBALL) this.modelindex = 0; this.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
319 HANDLE(FIREMINE) this.modelindex = 0; this.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
320 HANDLE(TAG) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
321 HANDLE(FLAC) this.scale = 0.4; this.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
322 HANDLE(SEEKER) this.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
324 HANDLE(MAGE_SPIKE) this.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
325 HANDLE(GOLEM_LIGHTNING) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
327 HANDLE(RAPTORBOMB) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
328 HANDLE(RAPTORBOMBLET) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
329 HANDLE(RAPTORCANNON) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
331 HANDLE(SPIDERROCKET) this.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
332 HANDLE(WAKIROCKET) this.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
333 HANDLE(WAKICANNON) this.traileffect = EFFECT_Null.m_id; break;
335 HANDLE(BUMBLE_GUN) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
336 HANDLE(BUMBLE_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
338 HANDLE(RPC) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
340 HANDLE(ROCKETMINSTA_LASER) this.traileffect = EFFECT_ROCKETMINSTA_LASER(this.team).m_id; break;
343 if (MUTATOR_CALLHOOK(Ent_Projectile, this))
346 error("Received invalid CSQC projectile, can't work with this!");
352 this.colormod = '0 0 0';
353 settouch(this, SUB_Stop);
354 set_movetype(this, MOVETYPE_TOSS);
359 case PROJECTILE_ELECTRO:
360 // only new engines support sound moving with object
361 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
362 this.mins = '-4 -4 -4';
364 set_movetype(this, MOVETYPE_BOUNCE);
365 settouch(this, func_null);
366 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
367 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
370 case PROJECTILE_ROCKET:
371 loopsound(this, CH_SHOTS_SINGLE, SND_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
372 this.mins = '-3 -3 -3';
375 case PROJECTILE_GRENADE:
376 this.mins = '-3 -3 -3';
379 case PROJECTILE_GRENADE_BOUNCING:
380 this.mins = '-3 -3 -3';
382 set_movetype(this, MOVETYPE_BOUNCE);
383 settouch(this, func_null);
384 this.bouncefactor = WEP_CVAR(mortar, bouncefactor);
385 this.bouncestop = WEP_CVAR(mortar, bouncestop);
387 case PROJECTILE_GOLEM_LIGHTNING:
388 this.mins = '-8 -8 -8';
391 this.avelocity = randomvec() * 720;
393 case PROJECTILE_MINE:
394 this.mins = '-4 -4 -4';
397 case PROJECTILE_PORTO_RED:
398 this.colormod = '2 1 1';
400 set_movetype(this, MOVETYPE_BOUNCE);
401 settouch(this, func_null);
403 case PROJECTILE_PORTO_BLUE:
404 this.colormod = '1 1 2';
406 set_movetype(this, MOVETYPE_BOUNCE);
407 settouch(this, func_null);
409 case PROJECTILE_HAGAR_BOUNCING:
410 set_movetype(this, MOVETYPE_BOUNCE);
411 settouch(this, func_null);
413 case PROJECTILE_CRYLINK_BOUNCING:
414 set_movetype(this, MOVETYPE_BOUNCE);
415 settouch(this, func_null);
417 case PROJECTILE_FIREBALL:
418 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
419 this.mins = '-16 -16 -16';
420 this.maxs = '16 16 16';
422 case PROJECTILE_FIREMINE:
423 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY, VOL_BASE, ATTEN_NORM);
424 set_movetype(this, MOVETYPE_BOUNCE);
425 settouch(this, func_null);
426 this.mins = '-4 -4 -4';
430 this.mins = '-2 -2 -2';
433 case PROJECTILE_FLAC:
434 this.mins = '-2 -2 -2';
437 case PROJECTILE_SEEKER:
438 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
439 this.mins = '-4 -4 -4';
442 case PROJECTILE_RAPTORBOMB:
443 this.mins = '-3 -3 -3';
446 case PROJECTILE_RAPTORBOMBLET:
448 case PROJECTILE_RAPTORCANNON:
450 case PROJECTILE_SPIDERROCKET:
451 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
453 case PROJECTILE_WAKIROCKET:
454 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
457 case PROJECTILE_WAKICANNON:
459 case PROJECTILE_BUMBLE_GUN:
460 // only new engines support sound moving with object
461 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
462 this.mins = '0 0 -4';
463 this.maxs = '0 0 -4';
464 this.move_movetype = MOVETYPE_BOUNCE;
465 settouch(this, func_null);
466 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
467 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
474 MUTATOR_CALLHOOK(EditProjectile, this);
476 setsize(this, this.mins, this.maxs);
483 if (this.move_movetype == MOVETYPE_FLY)
484 set_movetype(this, MOVETYPE_TOSS);
485 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
486 set_movetype(this, MOVETYPE_BOUNCE);
490 if (this.move_movetype == MOVETYPE_TOSS)
491 set_movetype(this, MOVETYPE_FLY);
492 if (this.move_movetype == MOVETYPE_BOUNCE)
493 set_movetype(this, MOVETYPE_BOUNCEMISSILE);
496 if (!(this.count & 0x80))
497 InterpolateOrigin_Note(this);
499 this.classname = "csqcprojectile";
500 this.draw = Projectile_Draw;
501 if (isnew) IL_PUSH(g_drawables, this);
502 this.entremove = Ent_RemoveProjectile;
505 PRECACHE(Projectiles)
507 MUTATOR_CALLHOOK(PrecacheProjectiles);