1 #include "projectile.qh"
3 #include "../autocvars.qh"
6 #include "../mutators/events.qh"
8 #include <common/constants.qh>
9 #include <common/net_linked.qh>
10 #include <common/physics/movetypes/movetypes.qh>
12 #include <lib/csqcmodel/interpolate.qh>
14 #include <lib/warpzone/anglestransform.qh>
20 void SUB_Stop(entity this, entity toucher)
22 this.velocity = this.avelocity = '0 0 0';
23 set_movetype(this, MOVETYPE_NONE);
26 void Projectile_ResetTrail(entity this, vector to)
28 this.trail_oldorigin = to;
29 this.trail_oldtime = time;
32 void Projectile_DrawTrail(entity this, vector to)
34 vector from = this.trail_oldorigin;
35 // float t0 = this.trail_oldtime;
36 this.trail_oldorigin = to;
37 this.trail_oldtime = time;
39 // force the effect even for stationary firemine
40 if (this.cnt == PROJECTILE_FIREMINE)
46 particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha);
47 boxparticles(particleeffectnum(Effects_from(this.traileffect)), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
51 bool Projectile_isnade(int proj); // TODO: remove
53 void Projectile_Draw(entity this)
64 if (this.count & 0x80)
66 // UNSET_ONGROUND(this);
67 if (this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FLY)
68 Movetype_Physics_NoMatchServer(this);
69 // the trivial movetypes do not have to match the
70 // server's ticrate as they are ticrate independent
71 // NOTE: this assumption is only true if MOVETYPE_FLY
72 // projectiles detonate on impact. If they continue
73 // moving, we might still be ticrate dependent.
75 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
76 if (!IS_ONGROUND(this))
77 if (this.velocity != '0 0 0')
78 this.angles = vectoangles(this.velocity);
82 InterpolateOrigin_Do(this);
85 if (this.count & 0x80)
87 drawn = (time >= this.spawntime - 0.02);
88 t = max(time, this.spawntime);
92 drawn = (this.iflags & IFLAG_VALID);
96 if (!(f & FL_ONGROUND))
102 case PROJECTILE_GRENADE:
103 rot = '-2000 0 0'; // forward
106 case PROJECTILE_GRENADE_BOUNCING:
107 rot = '0 -1000 0'; // sideways
109 case PROJECTILE_HOOKBOMB:
110 rot = '1000 0 0'; // forward
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, string 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_x = ReadCoord();
235 this.origin_y = ReadCoord();
236 this.origin_z = ReadCoord();
237 setorigin(this, this.origin);
238 if (this.count & 0x80)
240 this.velocity_x = ReadCoord();
241 this.velocity_y = ReadCoord();
242 this.velocity_z = ReadCoord();
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 myteam = ReadByte();
268 this.team = myteam - 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 = myteam;
280 if(this.colormap > 0)
281 this.glowmod = colormapPaletteColor(this.colormap & 0x0F, true) * 2;
283 this.glowmod = '1 1 1';
288 this.cnt = ReadByte();
290 this.silent = (this.cnt & 0x80);
291 this.cnt = (this.cnt & 0x7F);
294 this.traileffect = 0;
297 #define HANDLE(id) case PROJECTILE_##id: setmodel(this, MDL_PROJECTILE_##id);
298 HANDLE(ELECTRO) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
299 HANDLE(ROCKET) this.traileffect = EFFECT_TR_ROCKET.m_id; this.scale = 2; break;
300 HANDLE(CRYLINK) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
301 HANDLE(CRYLINK_BOUNCING) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
302 HANDLE(ELECTRO_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
303 HANDLE(GRENADE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
304 HANDLE(GRENADE_BOUNCING) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
305 HANDLE(MINE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
306 HANDLE(BLASTER) this.traileffect = EFFECT_Null.m_id; break;
307 HANDLE(ARC_BOLT) this.traileffect = EFFECT_Null.m_id; break;
308 HANDLE(HLAC) this.traileffect = EFFECT_Null.m_id; break;
309 HANDLE(PORTO_RED) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
310 HANDLE(PORTO_BLUE) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
311 HANDLE(HOOKBOMB) this.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
312 HANDLE(HAGAR) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
313 HANDLE(HAGAR_BOUNCING) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
314 HANDLE(FIREBALL) this.modelindex = 0; this.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
315 HANDLE(FIREMINE) this.modelindex = 0; this.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
316 HANDLE(TAG) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
317 HANDLE(FLAC) this.scale = 0.4; this.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
318 HANDLE(SEEKER) this.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
320 HANDLE(MAGE_SPIKE) this.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
321 HANDLE(SHAMBLER_LIGHTNING) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
323 HANDLE(RAPTORBOMB) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
324 HANDLE(RAPTORBOMBLET) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
325 HANDLE(RAPTORCANNON) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
327 HANDLE(SPIDERROCKET) this.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
328 HANDLE(WAKIROCKET) this.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
329 HANDLE(WAKICANNON) this.traileffect = EFFECT_Null.m_id; break;
331 HANDLE(BUMBLE_GUN) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
332 HANDLE(BUMBLE_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
334 HANDLE(RPC) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
336 HANDLE(ROCKETMINSTA_LASER) this.traileffect = EFFECT_ROCKETMINSTA_LASER(this.team).m_id; break;
339 if (MUTATOR_CALLHOOK(Ent_Projectile, this))
342 error("Received invalid CSQC projectile, can't work with this!");
348 this.colormod = '0 0 0';
349 settouch(this, SUB_Stop);
350 set_movetype(this, MOVETYPE_TOSS);
355 case PROJECTILE_ELECTRO:
356 // only new engines support sound moving with object
357 loopsound(this, CH_SHOTS_SINGLE, SND(ELECTRO_FLY), VOL_BASE, ATTEN_NORM);
358 this.mins = '-4 -4 -4';
360 set_movetype(this, MOVETYPE_BOUNCE);
361 settouch(this, func_null);
362 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
363 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
366 case PROJECTILE_ROCKET:
367 loopsound(this, CH_SHOTS_SINGLE, SND(ROCKET_FLY), VOL_BASE, ATTEN_NORM);
368 this.mins = '-3 -3 -3';
371 case PROJECTILE_GRENADE:
372 this.mins = '-3 -3 -3';
375 case PROJECTILE_GRENADE_BOUNCING:
376 this.mins = '-3 -3 -3';
378 set_movetype(this, MOVETYPE_BOUNCE);
379 settouch(this, func_null);
380 this.bouncefactor = WEP_CVAR(mortar, bouncefactor);
381 this.bouncestop = WEP_CVAR(mortar, bouncestop);
383 case PROJECTILE_SHAMBLER_LIGHTNING:
384 this.mins = '-8 -8 -8';
387 this.avelocity = randomvec() * 720;
389 case PROJECTILE_MINE:
390 this.mins = '-4 -4 -4';
393 case PROJECTILE_PORTO_RED:
394 this.colormod = '2 1 1';
396 set_movetype(this, MOVETYPE_BOUNCE);
397 settouch(this, func_null);
399 case PROJECTILE_PORTO_BLUE:
400 this.colormod = '1 1 2';
402 set_movetype(this, MOVETYPE_BOUNCE);
403 settouch(this, func_null);
405 case PROJECTILE_HAGAR_BOUNCING:
406 set_movetype(this, MOVETYPE_BOUNCE);
407 settouch(this, func_null);
409 case PROJECTILE_CRYLINK_BOUNCING:
410 set_movetype(this, MOVETYPE_BOUNCE);
411 settouch(this, func_null);
413 case PROJECTILE_FIREBALL:
414 loopsound(this, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
415 this.mins = '-16 -16 -16';
416 this.maxs = '16 16 16';
418 case PROJECTILE_FIREMINE:
419 loopsound(this, CH_SHOTS_SINGLE, SND(FIREBALL_FLY), VOL_BASE, ATTEN_NORM);
420 set_movetype(this, MOVETYPE_BOUNCE);
421 settouch(this, func_null);
422 this.mins = '-4 -4 -4';
426 this.mins = '-2 -2 -2';
429 case PROJECTILE_FLAC:
430 this.mins = '-2 -2 -2';
433 case PROJECTILE_SEEKER:
434 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
435 this.mins = '-4 -4 -4';
438 case PROJECTILE_RAPTORBOMB:
439 this.mins = '-3 -3 -3';
442 case PROJECTILE_RAPTORBOMBLET:
444 case PROJECTILE_RAPTORCANNON:
446 case PROJECTILE_SPIDERROCKET:
447 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
449 case PROJECTILE_WAKIROCKET:
450 loopsound(this, CH_SHOTS_SINGLE, SND(TAG_ROCKET_FLY), VOL_BASE, ATTEN_NORM);
453 case PROJECTILE_WAKICANNON:
455 case PROJECTILE_BUMBLE_GUN:
456 // only new engines support sound moving with object
457 loopsound(this, CH_SHOTS_SINGLE, SND(ELECTRO_FLY), VOL_BASE, ATTEN_NORM);
458 this.mins = '0 0 -4';
459 this.maxs = '0 0 -4';
460 this.move_movetype = MOVETYPE_BOUNCE;
461 settouch(this, func_null);
462 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
463 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
470 MUTATOR_CALLHOOK(EditProjectile, this);
472 setsize(this, this.mins, this.maxs);
479 if (this.move_movetype == MOVETYPE_FLY)
480 set_movetype(this, MOVETYPE_TOSS);
481 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
482 set_movetype(this, MOVETYPE_BOUNCE);
486 if (this.move_movetype == MOVETYPE_TOSS)
487 set_movetype(this, MOVETYPE_FLY);
488 if (this.move_movetype == MOVETYPE_BOUNCE)
489 set_movetype(this, MOVETYPE_BOUNCEMISSILE);
492 if (!(this.count & 0x80))
493 InterpolateOrigin_Note(this);
495 this.classname = "csqcprojectile";
496 this.draw = Projectile_Draw;
497 if (isnew) IL_PUSH(g_drawables, this);
498 this.entremove = Ent_RemoveProjectile;
501 PRECACHE(Projectiles)
503 MUTATOR_CALLHOOK(PrecacheProjectiles);