1 #include "projectile.qh"
3 #include "../autocvars.qh"
6 #include "../mutators/events.qh"
8 #include <common/constants.qh>
9 #include <common/physics/movetypes/movetypes.qh>
11 #include <lib/csqcmodel/interpolate.qh>
13 #include <lib/warpzone/anglestransform.qh>
19 void SUB_Stop(entity this, entity toucher)
21 this.velocity = this.avelocity = '0 0 0';
22 this.move_movetype = MOVETYPE_NONE;
25 void Projectile_ResetTrail(entity this, vector to)
27 this.trail_oldorigin = to;
28 this.trail_oldtime = time;
31 void Projectile_DrawTrail(entity this, vector to)
33 vector from = this.trail_oldorigin;
34 // float t0 = this.trail_oldtime;
35 this.trail_oldorigin = to;
36 this.trail_oldtime = time;
38 // force the effect even for stationary firemine
39 if (this.cnt == PROJECTILE_FIREMINE)
45 particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha);
46 boxparticles(particleeffectnum(Effects_from(this.traileffect)), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
50 bool Projectile_isnade(int proj); // TODO: remove
52 void Projectile_Draw(entity this)
63 if (this.count & 0x80)
65 // UNSET_ONGROUND(this);
66 if (this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FLY)
67 Movetype_Physics_NoMatchServer(this);
68 // the trivial movetypes do not have to match the
69 // server's ticrate as they are ticrate independent
70 // NOTE: this assumption is only true if MOVETYPE_FLY
71 // projectiles detonate on impact. If they continue
72 // moving, we might still be ticrate dependent.
74 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
75 if (!IS_ONGROUND(this))
76 if (this.velocity != '0 0 0')
77 this.angles = vectoangles(this.velocity);
81 InterpolateOrigin_Do(this);
84 if (this.count & 0x80)
86 drawn = (time >= this.spawntime - 0.02);
87 t = max(time, this.spawntime);
91 drawn = (this.iflags & IFLAG_VALID);
95 if (!(f & FL_ONGROUND))
101 case PROJECTILE_GRENADE:
102 rot = '-2000 0 0'; // forward
105 case PROJECTILE_GRENADE_BOUNCING:
106 rot = '0 -1000 0'; // sideways
108 case PROJECTILE_HOOKBOMB:
109 rot = '1000 0 0'; // forward
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, string 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_x = ReadCoord();
234 this.origin_y = ReadCoord();
235 this.origin_z = ReadCoord();
236 setorigin(this, this.origin);
237 if (this.count & 0x80)
239 this.velocity_x = ReadCoord();
240 this.velocity_y = ReadCoord();
241 this.velocity_z = ReadCoord();
243 this.gravity = ReadCoord();
245 this.gravity = 0; // none
248 if (time == this.spawntime || (this.count & 0x80) || (f & 0x08))
250 this.trail_oldorigin = this.origin;
251 if (!(this.count & 0x80))
252 InterpolateOrigin_Reset(this);
257 this.fade_time = time + ReadByte() * ticrate;
258 this.fade_rate = 1 / (ReadByte() * ticrate);
266 this.team = ReadByte() - 1;
271 this.cnt = ReadByte();
273 this.silent = (this.cnt & 0x80);
274 this.cnt = (this.cnt & 0x7F);
277 this.traileffect = 0;
280 #define HANDLE(id) case PROJECTILE_##id: setmodel(this, MDL_PROJECTILE_##id);
281 HANDLE(ELECTRO) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
282 HANDLE(ROCKET) this.traileffect = EFFECT_TR_ROCKET.m_id; this.scale = 2; break;
283 HANDLE(CRYLINK) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
284 HANDLE(CRYLINK_BOUNCING) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
285 HANDLE(ELECTRO_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
286 HANDLE(GRENADE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
287 HANDLE(GRENADE_BOUNCING) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
288 HANDLE(MINE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
289 HANDLE(BLASTER) this.traileffect = EFFECT_Null.m_id; break;
290 HANDLE(ARC_BOLT) this.traileffect = EFFECT_Null.m_id; break;
291 HANDLE(HLAC) this.traileffect = EFFECT_Null.m_id; break;
292 HANDLE(PORTO_RED) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
293 HANDLE(PORTO_BLUE) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
294 HANDLE(HOOKBOMB) this.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
295 HANDLE(HAGAR) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
296 HANDLE(HAGAR_BOUNCING) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
297 HANDLE(FIREBALL) this.modelindex = 0; this.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
298 HANDLE(FIREMINE) this.modelindex = 0; this.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
299 HANDLE(TAG) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
300 HANDLE(FLAC) this.scale = 0.4; this.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
301 HANDLE(SEEKER) this.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
303 HANDLE(MAGE_SPIKE) this.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
304 HANDLE(SHAMBLER_LIGHTNING) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
306 HANDLE(RAPTORBOMB) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
307 HANDLE(RAPTORBOMBLET) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
308 HANDLE(RAPTORCANNON) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
310 HANDLE(SPIDERROCKET) this.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
311 HANDLE(WAKIROCKET) this.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
312 HANDLE(WAKICANNON) this.traileffect = EFFECT_Null.m_id; break;
314 HANDLE(BUMBLE_GUN) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
315 HANDLE(BUMBLE_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
317 HANDLE(RPC) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
319 HANDLE(ROCKETMINSTA_LASER) this.traileffect = EFFECT_ROCKETMINSTA_LASER(this.team).m_id; break;
322 if (MUTATOR_CALLHOOK(Ent_Projectile, this))
325 error("Received invalid CSQC projectile, can't work with this!");
331 this.colormod = '0 0 0';
332 settouch(this, SUB_Stop);
333 this.move_movetype = MOVETYPE_TOSS;
338 case PROJECTILE_ELECTRO:
339 // only new engines support sound moving with object
340 loopsound(this, CH_SHOTS_SINGLE, SND(ELECTRO_FLY), VOL_BASE, ATTEN_NORM);
341 this.mins = '-4 -4 -4';
343 this.move_movetype = MOVETYPE_BOUNCE;
344 settouch(this, func_null);
345 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
346 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
349 case PROJECTILE_ROCKET:
350 loopsound(this, CH_SHOTS_SINGLE, SND(ROCKET_FLY), VOL_BASE, ATTEN_NORM);
351 this.mins = '-3 -3 -3';
354 case PROJECTILE_GRENADE:
355 this.mins = '-3 -3 -3';
358 case PROJECTILE_GRENADE_BOUNCING:
359 this.mins = '-3 -3 -3';
361 this.move_movetype = MOVETYPE_BOUNCE;
362 settouch(this, func_null);
363 this.bouncefactor = WEP_CVAR(mortar, bouncefactor);
364 this.bouncestop = WEP_CVAR(mortar, bouncestop);
366 case PROJECTILE_SHAMBLER_LIGHTNING:
367 this.mins = '-8 -8 -8';
370 this.avelocity = randomvec() * 720;
372 case PROJECTILE_MINE:
373 this.mins = '-4 -4 -4';
376 case PROJECTILE_PORTO_RED:
377 this.colormod = '2 1 1';
379 this.move_movetype = MOVETYPE_BOUNCE;
380 settouch(this, func_null);
382 case PROJECTILE_PORTO_BLUE:
383 this.colormod = '1 1 2';
385 this.move_movetype = MOVETYPE_BOUNCE;
386 settouch(this, func_null);
388 case PROJECTILE_HAGAR_BOUNCING:
389 this.move_movetype = MOVETYPE_BOUNCE;
390 settouch(this, func_null);
392 case PROJECTILE_CRYLINK_BOUNCING:
393 this.move_movetype = MOVETYPE_BOUNCE;
394 settouch(this, func_null);
396 case PROJECTILE_FIREBALL:
397 loopsound(this, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
398 this.mins = '-16 -16 -16';
399 this.maxs = '16 16 16';
401 case PROJECTILE_FIREMINE:
402 loopsound(this, CH_SHOTS_SINGLE, SND(FIREBALL_FLY), VOL_BASE, ATTEN_NORM);
403 this.move_movetype = MOVETYPE_BOUNCE;
404 settouch(this, func_null);
405 this.mins = '-4 -4 -4';
409 this.mins = '-2 -2 -2';
412 case PROJECTILE_FLAC:
413 this.mins = '-2 -2 -2';
416 case PROJECTILE_SEEKER:
417 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
418 this.mins = '-4 -4 -4';
421 case PROJECTILE_RAPTORBOMB:
422 this.mins = '-3 -3 -3';
425 case PROJECTILE_RAPTORBOMBLET:
427 case PROJECTILE_RAPTORCANNON:
429 case PROJECTILE_SPIDERROCKET:
430 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
432 case PROJECTILE_WAKIROCKET:
433 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
436 case PROJECTILE_WAKICANNON:
438 case PROJECTILE_BUMBLE_GUN:
439 // only new engines support sound moving with object
440 loopsound(this, CH_SHOTS_SINGLE, SND(ELECTRO_FLY), VOL_BASE, ATTEN_NORM);
441 this.mins = '0 0 -4';
442 this.maxs = '0 0 -4';
443 this.move_movetype = MOVETYPE_BOUNCE;
444 settouch(this, func_null);
445 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
446 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
453 MUTATOR_CALLHOOK(EditProjectile, this);
455 setsize(this, this.mins, this.maxs);
462 if (this.move_movetype == MOVETYPE_FLY)
463 this.move_movetype = MOVETYPE_TOSS;
464 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
465 this.move_movetype = MOVETYPE_BOUNCE;
469 if (this.move_movetype == MOVETYPE_TOSS)
470 this.move_movetype = MOVETYPE_FLY;
471 if (this.move_movetype == MOVETYPE_BOUNCE)
472 this.move_movetype = MOVETYPE_BOUNCEMISSILE;
475 if (!(this.count & 0x80))
476 InterpolateOrigin_Note(this);
478 this.classname = "csqcprojectile";
479 this.draw = Projectile_Draw;
480 if (isnew) IL_PUSH(g_drawables, this);
481 this.entremove = Ent_RemoveProjectile;
484 PRECACHE(Projectiles)
486 MUTATOR_CALLHOOK(PrecacheProjectiles);