3 #include "autocvars.qh"
6 #include "movetypes.qh"
9 #include "vehicles/vehicles.qh"
11 #include "../common/constants.qh"
12 #include "../common/deathtypes.qh"
13 #include "../common/util.qh"
15 #include "../common/weapons/weapons.qh"
17 #include "../dpdefs/csprogsdefs.qh"
25 void DamageEffect_Think()
27 // if particle distribution is enabled, slow ticrate by total number of damages
28 if(autocvar_cl_damageeffect_distribute)
29 self.nextthink = time + autocvar_cl_damageeffect_ticrate * self.owner.total_damages;
31 self.nextthink = time + autocvar_cl_damageeffect_ticrate;
33 if(time >= self.cnt || !self.owner || !self.owner.modelindex || !self.owner.drawmask)
35 // time is up or the player got gibbed / disconnected
36 self.owner.total_damages = max(0, self.owner.total_damages - 1);
40 if(self.state && !self.owner.csqcmodel_isdead)
42 // if the player was dead but is now alive, it means he respawned
43 // if so, clear his damage effects, or damages from his dead body will be copied back
44 self.owner.total_damages = max(0, self.owner.total_damages - 1);
48 self.state = self.owner.csqcmodel_isdead;
49 if(self.owner.isplayermodel && (self.owner.entnum == player_localentnum) && !autocvar_chase_active)
50 return; // if we aren't using a third person camera, hide our own effects
52 // now generate the particles
54 org = gettaginfo(self, 0); // origin at attached location
55 pointparticles(self.team, org, '0 0 0', 1);
58 void DamageEffect(vector hitorg, float dmg, int type, int specnum)
60 // particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
64 string specstr, effectname;
67 if(!autocvar_cl_damageeffect || autocvar_cl_gentle || autocvar_cl_gentle_damage)
69 if(!self || !self.modelindex || !self.drawmask)
72 // if this is a rigged mesh, the effect will show on the bone where damage was dealt
73 // we do this by choosing the skeletal bone closest to the impact, and attaching our entity to it
74 // if there's no skeleton, object origin will automatically be selected
78 continue; // skip empty bones
79 // blacklist bones positioned outside the mesh, or the effect will be floating
80 // TODO: Do we have to do it this way? Why do these bones exist at all?
81 if(gettaginfo_name == "master" || gettaginfo_name == "knee_L" || gettaginfo_name == "knee_R" || gettaginfo_name == "leg_L" || gettaginfo_name == "leg_R")
82 continue; // player model bone blacklist
84 // now choose the bone closest to impact origin
85 if(nearestbone == 0 || vlen(hitorg - gettaginfo(self, tagnum)) <= vlen(hitorg - gettaginfo(self, nearestbone)))
88 gettaginfo(self, nearestbone); // set gettaginfo_name
90 // return if we reached our damage effect limit or damages are disabled
91 // TODO: When the limit is reached, it would be better if the oldest damage was removed instead of not adding a new one
94 if(self.total_damages >= autocvar_cl_damageeffect_bones)
95 return; // allow multiple damages on skeletal models
99 if(autocvar_cl_damageeffect < 2 || self.total_damages)
100 return; // allow a single damage on non-skeletal models
103 life = bound(autocvar_cl_damageeffect_lifetime_min, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
105 effectname = get_weaponinfo(DEATH_WEAPONOF(type)).netname;
107 if(substring(effectname, strlen(effectname) - 5, 5) == "BLOOD")
109 if(self.isplayermodel)
111 specstr = species_prefix(specnum);
112 specstr = substring(specstr, 0, strlen(specstr) - 1);
113 effectname = strreplace("BLOOD", specstr, effectname);
115 else { return; } // objects don't bleed
119 setmodel(e, "null"); // necessary to attach and read origin
120 setattachment(e, self, gettaginfo_name); // attach to the given bone
121 e.classname = "damage";
124 e.team = particleeffectnum(effectname);
125 e.think = DamageEffect_Think;
127 self.total_damages += 1;
130 void Ent_DamageInfo(float isNew)
132 float dmg, rad, edge, thisdmg;
133 bool hitplayer = false;
134 int species, forcemul;
135 vector force, thisforce;
140 w_deathtype = ReadShort();
141 w_issilent = (w_deathtype & 0x8000);
142 w_deathtype = (w_deathtype & 0x7FFF);
144 w_org.x = ReadCoord();
145 w_org.y = ReadCoord();
146 w_org.z = ReadCoord();
151 force = decompressShortVector(ReadShort());
152 species = ReadByte();
165 for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
167 // attached ents suck
171 vector nearest = NearestPointOnBox(self, w_org);
174 thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
181 thisdmg = dmg + (edge - dmg) * thisdmg;
182 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
187 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
192 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
196 thisforce = forcemul * force;
199 if(self.damageforcescale)
202 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
203 self.move_flags &= ~FL_ONGROUND;
209 if(self.event_damage)
210 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
212 DamageEffect(w_org, thisdmg, w_deathtype, species);
214 if(self.isplayermodel)
215 hitplayer = true; // this impact damaged a player
220 if(DEATH_ISVEHICLE(w_deathtype))
222 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
223 if(trace_plane_normal != '0 0 0')
224 w_backoff = trace_plane_normal;
226 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
228 setorigin(self, w_org + w_backoff * 2); // for sound() calls
236 case DEATH_VH_SPID_MINIGUN:
238 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
239 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
240 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
242 case DEATH_VH_SPID_ROCKET:
243 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
244 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
246 case DEATH_VH_SPID_DEATH:
247 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
248 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
251 case DEATH_VH_WAKI_GUN:
252 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_NORM);
253 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
255 case DEATH_VH_WAKI_ROCKET:
256 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
257 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
259 case DEATH_VH_WAKI_DEATH:
260 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
261 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
264 case DEATH_VH_RAPT_CANNON:
265 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_NORM);
266 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
268 case DEATH_VH_RAPT_FRAGMENT:
271 for(i = 1; i < 4; ++i)
273 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
274 ang = vectoangles(vel);
275 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
277 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
278 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
280 case DEATH_VH_RAPT_BOMB:
281 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
282 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
284 case DEATH_VH_RAPT_DEATH:
285 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_MIN);
286 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
288 case DEATH_VH_BUMB_GUN:
289 sound(self, CH_SHOTS, "weapons/fireball_impact2.wav", VOL_BASE, ATTEN_NORM);
290 pointparticles(particleeffectnum("bigplasma_impact"), self.origin, w_backoff * 1000, 1);
296 if(DEATH_ISTURRET(w_deathtype))
299 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
300 if(trace_plane_normal != '0 0 0')
301 w_backoff = trace_plane_normal;
303 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
305 setorigin(self, w_org + w_backoff * 2); // for sound() calls
309 case DEATH_TURRET_EWHEEL:
310 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_MIN);
311 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
314 case DEATH_TURRET_FLAC:
315 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
316 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
317 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
320 case DEATH_TURRET_MLRS:
321 case DEATH_TURRET_HK:
322 case DEATH_TURRET_WALK_ROCKET:
323 case DEATH_TURRET_HELLION:
324 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
325 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
328 case DEATH_TURRET_MACHINEGUN:
329 case DEATH_TURRET_WALK_GUN:
330 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
331 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
332 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
335 case DEATH_TURRET_PLASMA:
336 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTEN_MIN);
337 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
340 case DEATH_TURRET_WALK_MEELE:
341 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_MIN);
342 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
345 case DEATH_TURRET_PHASER:
348 case DEATH_TURRET_TESLA:
349 te_smallflash(self.origin);
355 // TODO spawn particle effects and sounds based on w_deathtype
356 if(!DEATH_ISSPECIAL(w_deathtype))
357 if(!hitplayer || rad) // don't show ground impacts for hitscan weapons if a player was hit
359 int hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
360 w_random = prandom();
362 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
363 if(trace_fraction < 1 && hitwep != WEP_VORTEX && hitwep != WEP_VAPORIZER)
364 w_backoff = trace_plane_normal;
366 w_backoff = -1 * normalize(force);
367 setorigin(self, w_org + w_backoff * 2); // for sound() calls
369 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)) { WEP_ACTION(hitwep, WR_IMPACTEFFECT); }