3 #include "autocvars.qh"
6 #include "movetypes.qh"
8 #include "vehicles/vehicles.qh"
9 #include "../common/constants.qh"
10 #include "../common/deathtypes.qh"
11 #include "../common/util.qh"
12 #include "../common/weapons/weapons.qh"
13 #include "../dpdefs/csprogsdefs.qh"
21 void DamageEffect_Think()
23 // if particle distribution is enabled, slow ticrate by total number of damages
24 if(autocvar_cl_damageeffect_distribute)
25 self.nextthink = time + autocvar_cl_damageeffect_ticrate * self.owner.total_damages;
27 self.nextthink = time + autocvar_cl_damageeffect_ticrate;
29 if(time >= self.cnt || !self.owner || !self.owner.modelindex || !self.owner.drawmask)
31 // time is up or the player got gibbed / disconnected
32 self.owner.total_damages = max(0, self.owner.total_damages - 1);
36 if(self.state && !self.owner.csqcmodel_isdead)
38 // if the player was dead but is now alive, it means he respawned
39 // if so, clear his damage effects, or damages from his dead body will be copied back
40 self.owner.total_damages = max(0, self.owner.total_damages - 1);
44 self.state = self.owner.csqcmodel_isdead;
45 if(self.owner.isplayermodel && (self.owner.entnum == player_localentnum) && !autocvar_chase_active)
46 return; // if we aren't using a third person camera, hide our own effects
48 // now generate the particles
50 org = gettaginfo(self, 0); // origin at attached location
51 pointparticles(self.team, org, '0 0 0', 1);
54 void DamageEffect(vector hitorg, float dmg, int type, int specnum)
56 // particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
60 string specstr, effectname;
63 if(!autocvar_cl_damageeffect || autocvar_cl_gentle || autocvar_cl_gentle_damage)
65 if(!self || !self.modelindex || !self.drawmask)
68 // if this is a rigged mesh, the effect will show on the bone where damage was dealt
69 // we do this by choosing the skeletal bone closest to the impact, and attaching our entity to it
70 // if there's no skeleton, object origin will automatically be selected
74 continue; // skip empty bones
75 // blacklist bones positioned outside the mesh, or the effect will be floating
76 // TODO: Do we have to do it this way? Why do these bones exist at all?
77 if(gettaginfo_name == "master" || gettaginfo_name == "knee_L" || gettaginfo_name == "knee_R" || gettaginfo_name == "leg_L" || gettaginfo_name == "leg_R")
78 continue; // player model bone blacklist
80 // now choose the bone closest to impact origin
81 if(nearestbone == 0 || vlen(hitorg - gettaginfo(self, tagnum)) <= vlen(hitorg - gettaginfo(self, nearestbone)))
84 gettaginfo(self, nearestbone); // set gettaginfo_name
86 // return if we reached our damage effect limit or damages are disabled
87 // TODO: When the limit is reached, it would be better if the oldest damage was removed instead of not adding a new one
90 if(self.total_damages >= autocvar_cl_damageeffect_bones)
91 return; // allow multiple damages on skeletal models
95 if(autocvar_cl_damageeffect < 2 || self.total_damages)
96 return; // allow a single damage on non-skeletal models
99 life = bound(autocvar_cl_damageeffect_lifetime_min, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
101 effectname = get_weaponinfo(DEATH_WEAPONOF(type)).netname;
103 if(substring(effectname, strlen(effectname) - 5, 5) == "BLOOD")
105 if(self.isplayermodel)
107 specstr = species_prefix(specnum);
108 specstr = substring(specstr, 0, strlen(specstr) - 1);
109 effectname = strreplace("BLOOD", specstr, effectname);
111 else { return; } // objects don't bleed
115 setmodel(e, "null"); // necessary to attach and read origin
116 setattachment(e, self, gettaginfo_name); // attach to the given bone
117 e.classname = "damage";
120 e.team = particleeffectnum(effectname);
121 e.think = DamageEffect_Think;
123 self.total_damages += 1;
126 void Ent_DamageInfo(float isNew)
128 float dmg, rad, edge, thisdmg;
129 bool hitplayer = false;
130 int species, forcemul;
131 vector force, thisforce;
136 w_deathtype = ReadShort();
137 w_issilent = (w_deathtype & 0x8000);
138 w_deathtype = (w_deathtype & 0x7FFF);
140 w_org.x = ReadCoord();
141 w_org.y = ReadCoord();
142 w_org.z = ReadCoord();
147 force = decompressShortVector(ReadShort());
148 species = ReadByte();
161 for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
163 // attached ents suck
167 vector nearest = NearestPointOnBox(self, w_org);
170 thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
177 thisdmg = dmg + (edge - dmg) * thisdmg;
178 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
183 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
188 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
192 thisforce = forcemul * force;
195 if(self.damageforcescale)
198 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
199 self.move_flags &= ~FL_ONGROUND;
205 if(self.event_damage)
206 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
208 DamageEffect(w_org, thisdmg, w_deathtype, species);
210 if(self.isplayermodel)
211 hitplayer = true; // this impact damaged a player
216 if(DEATH_ISVEHICLE(w_deathtype))
218 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
219 if(trace_plane_normal != '0 0 0')
220 w_backoff = trace_plane_normal;
222 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
224 setorigin(self, w_org + w_backoff * 2); // for sound() calls
232 case DEATH_VH_SPID_MINIGUN:
234 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
235 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
236 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
238 case DEATH_VH_SPID_ROCKET:
239 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
240 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
242 case DEATH_VH_SPID_DEATH:
243 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
244 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
247 case DEATH_VH_WAKI_GUN:
248 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_NORM);
249 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
251 case DEATH_VH_WAKI_ROCKET:
252 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
253 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
255 case DEATH_VH_WAKI_DEATH:
256 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
257 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
260 case DEATH_VH_RAPT_CANNON:
261 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_NORM);
262 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
264 case DEATH_VH_RAPT_FRAGMENT:
267 for(i = 1; i < 4; ++i)
269 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
270 ang = vectoangles(vel);
271 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
273 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
274 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
276 case DEATH_VH_RAPT_BOMB:
277 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
278 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
280 case DEATH_VH_RAPT_DEATH:
281 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_MIN);
282 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
284 case DEATH_VH_BUMB_GUN:
285 sound(self, CH_SHOTS, "weapons/fireball_impact2.wav", VOL_BASE, ATTEN_NORM);
286 pointparticles(particleeffectnum("bigplasma_impact"), self.origin, w_backoff * 1000, 1);
292 if(DEATH_ISTURRET(w_deathtype))
295 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
296 if(trace_plane_normal != '0 0 0')
297 w_backoff = trace_plane_normal;
299 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
301 setorigin(self, w_org + w_backoff * 2); // for sound() calls
305 case DEATH_TURRET_EWHEEL:
306 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_MIN);
307 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
310 case DEATH_TURRET_FLAC:
311 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
312 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
313 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
316 case DEATH_TURRET_MLRS:
317 case DEATH_TURRET_HK:
318 case DEATH_TURRET_WALK_ROCKET:
319 case DEATH_TURRET_HELLION:
320 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
321 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
324 case DEATH_TURRET_MACHINEGUN:
325 case DEATH_TURRET_WALK_GUN:
326 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
327 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
328 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
331 case DEATH_TURRET_PLASMA:
332 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTEN_MIN);
333 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
336 case DEATH_TURRET_WALK_MEELE:
337 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_MIN);
338 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
341 case DEATH_TURRET_PHASER:
344 case DEATH_TURRET_TESLA:
345 te_smallflash(self.origin);
351 // TODO spawn particle effects and sounds based on w_deathtype
352 if(!DEATH_ISSPECIAL(w_deathtype))
353 if(!hitplayer || rad) // don't show ground impacts for hitscan weapons if a player was hit
355 int hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
356 w_random = prandom();
358 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
359 if(trace_fraction < 1 && hitwep != WEP_VORTEX && hitwep != WEP_VAPORIZER)
360 w_backoff = trace_plane_normal;
362 w_backoff = -1 * normalize(force);
363 setorigin(self, w_org + w_backoff * 2); // for sound() calls
365 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)) { WEP_ACTION(hitwep, WR_IMPACTEFFECT); }