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
112 case PROJECTILE_ROCKET:
113 rot = '0 0 720'; // spinning
119 if (Projectile_isnade(this.cnt))
120 rot = this.avelocity;
122 this.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(this.angles), rot * (t - this.spawntime)));
130 a = 1 - (time - this.fade_time) * this.fade_rate;
131 this.alpha = bound(0, this.alphamod * a, 1);
134 this.renderflags = 0;
136 trailorigin = this.origin;
139 case PROJECTILE_GRENADE:
140 case PROJECTILE_GRENADE_BOUNCING:
141 trailorigin += v_right * 1 + v_forward * -10;
147 if (Projectile_isnade(this.cnt))
148 trailorigin += v_up * 4;
151 Projectile_DrawTrail(this, trailorigin);
153 Projectile_ResetTrail(this, trailorigin);
162 // Possibly add dlights here.
167 this.drawmask = MASK_NORMAL;
170 void loopsound(entity e, int ch, Sound samp, float vol, float attn)
176 sound(e, ch, samp, vol, attn);
180 void Ent_RemoveProjectile(entity this)
182 if (this.count & 0x80)
184 tracebox(this.origin, this.mins, this.maxs, this.origin + this.velocity * 0.05, MOVE_NORMAL, this);
185 Projectile_DrawTrail(this, trace_endpos);
189 NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
191 // projectile properties:
192 // kind (interpolated, or clientside)
200 // soundindex (hardcoded list)
203 // projectiles don't send angles, because they always follow the velocity
206 this.count = (f & 0x80);
207 this.flags |= FL_PROJECTILE;
208 this.iflags = (this.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES | IFLAG_ORIGIN;
209 this.solid = SOLID_TRIGGER;
210 // this.effects = EF_NOMODELFLAGS;
212 // this should make collisions with bmodels more exact, but it leads to
213 // projectiles no longer being able to lie on a bmodel
214 this.move_nomonsters = MOVE_WORLDONLY;
218 UNSET_ONGROUND(this);
222 // for some unknown reason, we don't need to care for
223 // sv_gameplayfix_delayprojectiles here.
224 this.move_time = time;
225 this.spawntime = time;
229 this.move_time = max(this.move_time, time);
232 if (!(this.count & 0x80))
233 InterpolateOrigin_Undo(this);
237 this.origin_x = ReadCoord();
238 this.origin_y = ReadCoord();
239 this.origin_z = ReadCoord();
240 setorigin(this, this.origin);
241 if (this.count & 0x80)
243 this.velocity_x = ReadCoord();
244 this.velocity_y = ReadCoord();
245 this.velocity_z = ReadCoord();
247 this.gravity = ReadCoord();
249 this.gravity = 0; // none
252 if (time == this.spawntime || (this.count & 0x80) || (f & 0x08))
254 this.trail_oldorigin = this.origin;
255 if (!(this.count & 0x80))
256 InterpolateOrigin_Reset(this);
261 this.fade_time = time + ReadByte() * ticrate;
262 this.fade_rate = 1 / (ReadByte() * ticrate);
270 int myteam = ReadByte();
271 this.team = myteam - 1;
276 this.colormap = (this.team) * 0x11; // note: team - 1 on server (client uses different numbers)
278 this.colormap = 0x00;
279 this.colormap |= BIT(10); // RENDER_COLORMAPPED
282 this.colormap = myteam;
283 // TODO: projectiles use glowmaps for their color, not teams
285 if(this.colormap > 0)
286 this.glowmod = colormapPaletteColor(this.colormap & 0x0F, true) * 2;
288 this.glowmod = '1 1 1';
294 this.cnt = ReadByte();
296 this.silent = (this.cnt & 0x80);
297 this.cnt = (this.cnt & 0x7F);
300 this.traileffect = 0;
303 #define HANDLE(id) case PROJECTILE_##id: setmodel(this, MDL_PROJECTILE_##id);
304 HANDLE(ELECTRO) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
305 HANDLE(ROCKET) this.traileffect = EFFECT_TR_ROCKET.m_id; this.scale = 2; break;
306 HANDLE(CRYLINK) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
307 HANDLE(CRYLINK_BOUNCING) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
308 HANDLE(ELECTRO_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
309 HANDLE(GRENADE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
310 HANDLE(GRENADE_BOUNCING) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
311 HANDLE(MINE) this.traileffect = EFFECT_TR_GRENADE.m_id; break;
312 HANDLE(BLASTER) this.traileffect = EFFECT_Null.m_id; break;
313 HANDLE(ARC_BOLT) this.traileffect = EFFECT_Null.m_id; break;
314 HANDLE(HLAC) this.traileffect = EFFECT_Null.m_id; break;
315 HANDLE(PORTO_RED) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
316 HANDLE(PORTO_BLUE) this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
317 HANDLE(HOOKBOMB) this.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
318 HANDLE(HAGAR) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
319 HANDLE(HAGAR_BOUNCING) this.traileffect = EFFECT_HAGAR_ROCKET.m_id; this.scale = 0.75; break;
320 HANDLE(FIREBALL) this.modelindex = 0; this.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
321 HANDLE(FIREMINE) this.modelindex = 0; this.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
322 HANDLE(TAG) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
323 HANDLE(FLAC) this.scale = 0.4; this.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
324 HANDLE(SEEKER) this.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
326 HANDLE(MAGE_SPIKE) this.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
327 HANDLE(SHAMBLER_LIGHTNING) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
329 HANDLE(RAPTORBOMB) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
330 HANDLE(RAPTORBOMBLET) this.gravity = 1; this.avelocity = '0 0 180'; this.traileffect = EFFECT_Null.m_id; break;
331 HANDLE(RAPTORCANNON) this.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
333 HANDLE(SPIDERROCKET) this.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
334 HANDLE(WAKIROCKET) this.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
335 HANDLE(WAKICANNON) this.traileffect = EFFECT_Null.m_id; break;
337 HANDLE(BUMBLE_GUN) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
338 HANDLE(BUMBLE_BEAM) this.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
340 HANDLE(RPC) this.traileffect = EFFECT_TR_ROCKET.m_id; break;
342 HANDLE(ROCKETMINSTA_LASER) this.traileffect = EFFECT_ROCKETMINSTA_LASER(this.team).m_id; break;
345 if (MUTATOR_CALLHOOK(Ent_Projectile, this))
348 error("Received invalid CSQC projectile, can't work with this!");
354 this.colormod = '0 0 0';
355 settouch(this, SUB_Stop);
356 set_movetype(this, MOVETYPE_TOSS);
361 case PROJECTILE_ELECTRO:
362 // only new engines support sound moving with object
363 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
364 this.mins = '-4 -4 -4';
366 set_movetype(this, MOVETYPE_BOUNCE);
367 settouch(this, func_null);
368 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
369 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
372 case PROJECTILE_ROCKET:
373 loopsound(this, CH_SHOTS_SINGLE, SND_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
374 this.mins = '-3 -3 -3';
377 case PROJECTILE_GRENADE:
378 this.mins = '-3 -3 -3';
381 case PROJECTILE_GRENADE_BOUNCING:
382 this.mins = '-3 -3 -3';
384 set_movetype(this, MOVETYPE_BOUNCE);
385 settouch(this, func_null);
386 this.bouncefactor = WEP_CVAR(mortar, bouncefactor);
387 this.bouncestop = WEP_CVAR(mortar, bouncestop);
389 case PROJECTILE_SHAMBLER_LIGHTNING:
390 this.mins = '-8 -8 -8';
393 this.avelocity = randomvec() * 720;
395 case PROJECTILE_MINE:
396 this.mins = '-4 -4 -4';
399 case PROJECTILE_PORTO_RED:
400 this.colormod = '2 1 1';
402 set_movetype(this, MOVETYPE_BOUNCE);
403 settouch(this, func_null);
405 case PROJECTILE_PORTO_BLUE:
406 this.colormod = '1 1 2';
408 set_movetype(this, MOVETYPE_BOUNCE);
409 settouch(this, func_null);
411 case PROJECTILE_HAGAR_BOUNCING:
412 set_movetype(this, MOVETYPE_BOUNCE);
413 settouch(this, func_null);
415 case PROJECTILE_CRYLINK_BOUNCING:
416 set_movetype(this, MOVETYPE_BOUNCE);
417 settouch(this, func_null);
419 case PROJECTILE_FIREBALL:
420 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
421 this.mins = '-16 -16 -16';
422 this.maxs = '16 16 16';
424 case PROJECTILE_FIREMINE:
425 loopsound(this, CH_SHOTS_SINGLE, SND_FIREBALL_FLY, VOL_BASE, ATTEN_NORM);
426 set_movetype(this, MOVETYPE_BOUNCE);
427 settouch(this, func_null);
428 this.mins = '-4 -4 -4';
432 this.mins = '-2 -2 -2';
435 case PROJECTILE_FLAC:
436 this.mins = '-2 -2 -2';
439 case PROJECTILE_SEEKER:
440 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
441 this.mins = '-4 -4 -4';
444 case PROJECTILE_RAPTORBOMB:
445 this.mins = '-3 -3 -3';
448 case PROJECTILE_RAPTORBOMBLET:
450 case PROJECTILE_RAPTORCANNON:
452 case PROJECTILE_SPIDERROCKET:
453 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
455 case PROJECTILE_WAKIROCKET:
456 loopsound(this, CH_SHOTS_SINGLE, SND_TAG_ROCKET_FLY, VOL_BASE, ATTEN_NORM);
459 case PROJECTILE_WAKICANNON:
461 case PROJECTILE_BUMBLE_GUN:
462 // only new engines support sound moving with object
463 loopsound(this, CH_SHOTS_SINGLE, SND_ELECTRO_FLY, VOL_BASE, ATTEN_NORM);
464 this.mins = '0 0 -4';
465 this.maxs = '0 0 -4';
466 this.move_movetype = MOVETYPE_BOUNCE;
467 settouch(this, func_null);
468 this.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
469 this.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
476 MUTATOR_CALLHOOK(EditProjectile, this);
478 setsize(this, this.mins, this.maxs);
485 if (this.move_movetype == MOVETYPE_FLY)
486 set_movetype(this, MOVETYPE_TOSS);
487 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
488 set_movetype(this, MOVETYPE_BOUNCE);
492 if (this.move_movetype == MOVETYPE_TOSS)
493 set_movetype(this, MOVETYPE_FLY);
494 if (this.move_movetype == MOVETYPE_BOUNCE)
495 set_movetype(this, MOVETYPE_BOUNCEMISSILE);
498 if (!(this.count & 0x80))
499 InterpolateOrigin_Note(this);
501 this.classname = "csqcprojectile";
502 this.draw = Projectile_Draw;
503 if (isnew) IL_PUSH(g_drawables, this);
504 this.entremove = Ent_RemoveProjectile;
507 PRECACHE(Projectiles)
509 MUTATOR_CALLHOOK(PrecacheProjectiles);