4 #include "../common/deathtypes/all.qh"
5 #include "../common/movetypes/movetypes.qh"
6 #include "../common/vehicles/all.qh"
7 #include "../common/weapons/all.qh"
15 void DamageEffect_Think()
17 // if particle distribution is enabled, slow ticrate by total number of damages
18 if(autocvar_cl_damageeffect_distribute)
19 self.nextthink = time + autocvar_cl_damageeffect_ticrate * self.owner.total_damages;
21 self.nextthink = time + autocvar_cl_damageeffect_ticrate;
23 if(time >= self.cnt || !self.owner || !self.owner.modelindex || !self.owner.drawmask)
25 // time is up or the player got gibbed / disconnected
26 self.owner.total_damages = max(0, self.owner.total_damages - 1);
30 if(self.state && !self.owner.csqcmodel_isdead)
32 // if the player was dead but is now alive, it means he respawned
33 // if so, clear his damage effects, or damages from his dead body will be copied back
34 self.owner.total_damages = max(0, self.owner.total_damages - 1);
38 self.state = self.owner.csqcmodel_isdead;
39 if(self.owner.isplayermodel && (self.owner.entnum == player_localentnum) && !autocvar_chase_active)
40 return; // if we aren't using a third person camera, hide our own effects
42 // now generate the particles
44 org = gettaginfo(self, 0); // origin at attached location
45 pointparticles(self.team, org, '0 0 0', 1);
48 void DamageEffect(vector hitorg, float thedamage, int type, int specnum)
50 // particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
54 string specstr, effectname;
57 if(!autocvar_cl_damageeffect || autocvar_cl_gentle || autocvar_cl_gentle_damage)
59 if(!self || !self.modelindex || !self.drawmask)
62 // if this is a rigged mesh, the effect will show on the bone where damage was dealt
63 // we do this by choosing the skeletal bone closest to the impact, and attaching our entity to it
64 // if there's no skeleton, object origin will automatically be selected
68 continue; // skip empty bones
69 // blacklist bones positioned outside the mesh, or the effect will be floating
70 // TODO: Do we have to do it this way? Why do these bones exist at all?
71 if(gettaginfo_name == "master" || gettaginfo_name == "knee_L" || gettaginfo_name == "knee_R" || gettaginfo_name == "leg_L" || gettaginfo_name == "leg_R")
72 continue; // player model bone blacklist
74 // now choose the bone closest to impact origin
75 if(nearestbone == 0 || vlen(hitorg - gettaginfo(self, tagnum)) <= vlen(hitorg - gettaginfo(self, nearestbone)))
78 gettaginfo(self, nearestbone); // set gettaginfo_name
80 // return if we reached our damage effect limit or damages are disabled
81 // TODO: When the limit is reached, it would be better if the oldest damage was removed instead of not adding a new one
84 if(self.total_damages >= autocvar_cl_damageeffect_bones)
85 return; // allow multiple damages on skeletal models
89 if(autocvar_cl_damageeffect < 2 || self.total_damages)
90 return; // allow a single damage on non-skeletal models
93 life = bound(autocvar_cl_damageeffect_lifetime_min, thedamage * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
95 effectname = DEATH_WEAPONOF(type).netname;
97 if(substring(effectname, strlen(effectname) - 5, 5) == "BLOOD")
99 if(self.isplayermodel)
101 specstr = species_prefix(specnum);
102 specstr = substring(specstr, 0, strlen(specstr) - 1);
103 effectname = strreplace("BLOOD", specstr, effectname);
105 else { return; } // objects don't bleed
109 setmodel(e, MDL_Null); // necessary to attach and read origin
110 setattachment(e, self, gettaginfo_name); // attach to the given bone
111 e.classname = "damage";
114 e.team = _particleeffectnum(effectname);
115 e.think = DamageEffect_Think;
117 self.total_damages += 1;
120 void Ent_DamageInfo(float isNew)
122 float thedamage, rad, edge, thisdmg;
123 bool hitplayer = false;
124 int species, forcemul;
125 vector force, thisforce;
127 w_deathtype = ReadShort();
128 w_issilent = (w_deathtype & 0x8000);
129 w_deathtype = (w_deathtype & 0x7FFF);
131 w_org.x = ReadCoord();
132 w_org.y = ReadCoord();
133 w_org.z = ReadCoord();
135 thedamage = ReadByte();
138 force = decompressShortVector(ReadShort());
139 species = ReadByte();
152 for(entity e = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); e; e = e.chain)
155 // attached ents suck
159 vector nearest = NearestPointOnBox(self, w_org);
162 thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
169 thisdmg = thedamage + (edge - thedamage) * thisdmg;
170 thisforce = forcemul * vlen(force) * (thisdmg / thedamage) * normalize(self.origin - w_org);
175 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
180 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
184 thisforce = forcemul * force;
187 if(self.damageforcescale)
190 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
191 self.move_flags &= ~FL_ONGROUND;
197 if(self.event_damage)
198 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
200 DamageEffect(w_org, thisdmg, w_deathtype, species);
202 if(self.isplayermodel)
203 hitplayer = true; // this impact damaged a player
207 if(DEATH_ISVEHICLE(w_deathtype))
209 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
210 if(trace_plane_normal != '0 0 0')
211 w_backoff = trace_plane_normal;
213 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
215 setorigin(self, w_org + w_backoff * 2); // for sound() calls
217 switch(DEATH_ENT(w_deathtype))
223 case DEATH_VH_SPID_MINIGUN:
224 sound(self, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);
225 pointparticles(particleeffectnum(EFFECT_SPIDERBOT_MINIGUN_IMPACT), self.origin, w_backoff * 1000, 1);
227 case DEATH_VH_SPID_ROCKET:
228 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
229 pointparticles(particleeffectnum(EFFECT_SPIDERBOT_ROCKET_EXPLODE), self.origin, w_backoff * 1000, 1);
231 case DEATH_VH_SPID_DEATH:
232 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_MIN);
233 pointparticles(particleeffectnum(EFFECT_EXPLOSION_BIG), self.origin, w_backoff * 1000, 1);
236 case DEATH_VH_WAKI_GUN:
237 sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTEN_NORM);
238 pointparticles(particleeffectnum(EFFECT_RACER_IMPACT), self.origin, w_backoff * 1000, 1);
240 case DEATH_VH_WAKI_ROCKET:
241 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
242 pointparticles(particleeffectnum(EFFECT_RACER_ROCKET_EXPLODE), self.origin, w_backoff * 1000, 1);
244 case DEATH_VH_WAKI_DEATH:
245 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_MIN);
246 pointparticles(particleeffectnum(EFFECT_EXPLOSION_BIG), self.origin, w_backoff * 1000, 1);
249 case DEATH_VH_RAPT_CANNON:
250 sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTEN_NORM);
251 pointparticles(particleeffectnum(EFFECT_RAPTOR_CANNON_IMPACT), self.origin, w_backoff * 1000, 1);
253 case DEATH_VH_RAPT_FRAGMENT:
256 for(i = 1; i < 4; ++i)
258 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
259 ang = vectoangles(vel);
260 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
262 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
263 pointparticles(particleeffectnum(EFFECT_RAPTOR_BOMB_SPREAD), self.origin, w_backoff * 1000, 1);
265 case DEATH_VH_RAPT_BOMB:
266 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
267 pointparticles(particleeffectnum(EFFECT_RAPTOR_BOMB_IMPACT), self.origin, w_backoff * 1000, 1);
269 case DEATH_VH_RAPT_DEATH:
270 sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTEN_MIN);
271 pointparticles(particleeffectnum(EFFECT_EXPLOSION_BIG), self.origin, w_backoff * 1000, 1);
273 case DEATH_VH_BUMB_GUN:
274 sound(self, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM);
275 pointparticles(particleeffectnum(EFFECT_BIGPLASMA_IMPACT), self.origin, w_backoff * 1000, 1);
281 if(DEATH_ISTURRET(w_deathtype))
283 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
284 if(trace_plane_normal != '0 0 0')
285 w_backoff = trace_plane_normal;
287 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
289 setorigin(self, w_org + w_backoff * 2); // for sound() calls
291 switch(DEATH_ENT(w_deathtype))
293 case DEATH_TURRET_EWHEEL:
294 sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTEN_MIN);
295 pointparticles(particleeffectnum(EFFECT_BLASTER_IMPACT), self.origin, w_backoff * 1000, 1);
298 case DEATH_TURRET_FLAC:
299 pointparticles(particleeffectnum(EFFECT_HAGAR_EXPLODE), w_org, '0 0 0', 1);
300 sound(self, CH_SHOTS, SND_HAGEXP_RANDOM(), VOL_BASE, ATTEN_NORM);
303 case DEATH_TURRET_MLRS:
304 case DEATH_TURRET_HK:
305 case DEATH_TURRET_WALK_ROCKET:
306 case DEATH_TURRET_HELLION:
307 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_MIN);
308 pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), self.origin, w_backoff * 1000, 1);
311 case DEATH_TURRET_MACHINEGUN:
312 case DEATH_TURRET_WALK_GUN:
313 sound(self, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);
314 pointparticles(particleeffectnum(EFFECT_MACHINEGUN_IMPACT), self.origin, w_backoff * 1000, 1);
317 case DEATH_TURRET_PLASMA:
318 sound(self, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_MIN);
319 pointparticles(particleeffectnum(EFFECT_ELECTRO_IMPACT), self.origin, w_backoff * 1000, 1);
322 case DEATH_TURRET_WALK_MELEE:
323 sound(self, CH_SHOTS, SND_RIC1, VOL_BASE, ATTEN_MIN);
324 pointparticles(particleeffectnum(EFFECT_TE_SPARK), self.origin, w_backoff * 1000, 1);
327 case DEATH_TURRET_PHASER:
330 case DEATH_TURRET_TESLA:
331 te_smallflash(self.origin);
337 // TODO spawn particle effects and sounds based on w_deathtype
338 if(!DEATH_ISSPECIAL(w_deathtype))
339 if(!hitplayer || rad) // don't show ground impacts for hitscan weapons if a player was hit
341 Weapon hitwep = DEATH_WEAPONOF(w_deathtype);
342 w_random = prandom();
344 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
345 if(trace_fraction < 1 && hitwep != WEP_VORTEX && hitwep != WEP_VAPORIZER)
346 w_backoff = trace_plane_normal;
348 w_backoff = -1 * normalize(force);
349 setorigin(self, w_org + w_backoff * 2); // for sound() calls
351 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)) {
352 hitwep.wr_impacteffect(hitwep);