6 #include "../common/vehicles/all.qh"
8 #include "../common/constants.qh"
9 #include "../common/deathtypes.qh"
10 #include "../common/effects/effects.qh"
11 #include "../common/movetypes/movetypes.qh"
12 #include "../common/util.qh"
14 #include "../common/weapons/all.qh"
22 void DamageEffect_Think()
24 // if particle distribution is enabled, slow ticrate by total number of damages
25 if(autocvar_cl_damageeffect_distribute)
26 self.nextthink = time + autocvar_cl_damageeffect_ticrate * self.owner.total_damages;
28 self.nextthink = time + autocvar_cl_damageeffect_ticrate;
30 if(time >= self.cnt || !self.owner || !self.owner.modelindex || !self.owner.drawmask)
32 // time is up or the player got gibbed / disconnected
33 self.owner.total_damages = max(0, self.owner.total_damages - 1);
37 if(self.state && !self.owner.csqcmodel_isdead)
39 // if the player was dead but is now alive, it means he respawned
40 // if so, clear his damage effects, or damages from his dead body will be copied back
41 self.owner.total_damages = max(0, self.owner.total_damages - 1);
45 self.state = self.owner.csqcmodel_isdead;
46 if(self.owner.isplayermodel && (self.owner.entnum == player_localentnum) && !autocvar_chase_active)
47 return; // if we aren't using a third person camera, hide our own effects
49 // now generate the particles
51 org = gettaginfo(self, 0); // origin at attached location
52 pointparticles(self.team, org, '0 0 0', 1);
55 void DamageEffect(vector hitorg, float thedamage, int type, int specnum)
57 // particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
61 string specstr, effectname;
64 if(!autocvar_cl_damageeffect || autocvar_cl_gentle || autocvar_cl_gentle_damage)
66 if(!self || !self.modelindex || !self.drawmask)
69 // if this is a rigged mesh, the effect will show on the bone where damage was dealt
70 // we do this by choosing the skeletal bone closest to the impact, and attaching our entity to it
71 // if there's no skeleton, object origin will automatically be selected
75 continue; // skip empty bones
76 // blacklist bones positioned outside the mesh, or the effect will be floating
77 // TODO: Do we have to do it this way? Why do these bones exist at all?
78 if(gettaginfo_name == "master" || gettaginfo_name == "knee_L" || gettaginfo_name == "knee_R" || gettaginfo_name == "leg_L" || gettaginfo_name == "leg_R")
79 continue; // player model bone blacklist
81 // now choose the bone closest to impact origin
82 if(nearestbone == 0 || vlen(hitorg - gettaginfo(self, tagnum)) <= vlen(hitorg - gettaginfo(self, nearestbone)))
85 gettaginfo(self, nearestbone); // set gettaginfo_name
87 // return if we reached our damage effect limit or damages are disabled
88 // TODO: When the limit is reached, it would be better if the oldest damage was removed instead of not adding a new one
91 if(self.total_damages >= autocvar_cl_damageeffect_bones)
92 return; // allow multiple damages on skeletal models
96 if(autocvar_cl_damageeffect < 2 || self.total_damages)
97 return; // allow a single damage on non-skeletal models
100 life = bound(autocvar_cl_damageeffect_lifetime_min, thedamage * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
102 effectname = get_weaponinfo(DEATH_WEAPONOF(type)).netname;
104 if(substring(effectname, strlen(effectname) - 5, 5) == "BLOOD")
106 if(self.isplayermodel)
108 specstr = species_prefix(specnum);
109 specstr = substring(specstr, 0, strlen(specstr) - 1);
110 effectname = strreplace("BLOOD", specstr, effectname);
112 else { return; } // objects don't bleed
116 setmodel(e, MDL_Null); // necessary to attach and read origin
117 setattachment(e, self, gettaginfo_name); // attach to the given bone
118 e.classname = "damage";
121 e.team = _particleeffectnum(effectname);
122 e.think = DamageEffect_Think;
124 self.total_damages += 1;
127 void Ent_DamageInfo(float isNew)
129 float thedamage, rad, edge, thisdmg;
130 bool hitplayer = false;
131 int species, forcemul;
132 vector force, thisforce;
134 w_deathtype = ReadShort();
135 w_issilent = (w_deathtype & 0x8000);
136 w_deathtype = (w_deathtype & 0x7FFF);
138 w_org.x = ReadCoord();
139 w_org.y = ReadCoord();
140 w_org.z = ReadCoord();
142 thedamage = ReadByte();
145 force = decompressShortVector(ReadShort());
146 species = ReadByte();
159 for(entity e = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); e; e = e.chain)
162 // attached ents suck
166 vector nearest = NearestPointOnBox(self, w_org);
169 thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
176 thisdmg = thedamage + (edge - thedamage) * thisdmg;
177 thisforce = forcemul * vlen(force) * (thisdmg / thedamage) * normalize(self.origin - w_org);
182 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
187 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
191 thisforce = forcemul * force;
194 if(self.damageforcescale)
197 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
198 self.move_flags &= ~FL_ONGROUND;
204 if(self.event_damage)
205 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
207 DamageEffect(w_org, thisdmg, w_deathtype, species);
209 if(self.isplayermodel)
210 hitplayer = true; // this impact damaged a player
214 if(DEATH_ISVEHICLE(w_deathtype))
216 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
217 if(trace_plane_normal != '0 0 0')
218 w_backoff = trace_plane_normal;
220 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
222 setorigin(self, w_org + w_backoff * 2); // for sound() calls
230 case DEATH_VH_SPID_MINIGUN:
232 _snd = W_Sound(strcat("ric", ftos(1 + rint(random() * 2))));
233 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
234 pointparticles(particleeffectnum(EFFECT_SPIDERBOT_MINIGUN_IMPACT), self.origin, w_backoff * 1000, 1);
236 case DEATH_VH_SPID_ROCKET:
237 sound(self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
238 pointparticles(particleeffectnum(EFFECT_SPIDERBOT_ROCKET_EXPLODE), self.origin, w_backoff * 1000, 1);
240 case DEATH_VH_SPID_DEATH:
241 sound(self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_MIN);
242 pointparticles(particleeffectnum(EFFECT_EXPLOSION_BIG), self.origin, w_backoff * 1000, 1);
245 case DEATH_VH_WAKI_GUN:
246 sound(self, CH_SHOTS, W_Sound("laserimpact"), VOL_BASE, ATTEN_NORM);
247 pointparticles(particleeffectnum(EFFECT_RACER_IMPACT), self.origin, w_backoff * 1000, 1);
249 case DEATH_VH_WAKI_ROCKET:
250 sound(self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
251 pointparticles(particleeffectnum(EFFECT_RACER_ROCKET_EXPLODE), self.origin, w_backoff * 1000, 1);
253 case DEATH_VH_WAKI_DEATH:
254 sound(self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_MIN);
255 pointparticles(particleeffectnum(EFFECT_EXPLOSION_BIG), self.origin, w_backoff * 1000, 1);
258 case DEATH_VH_RAPT_CANNON:
259 sound(self, CH_SHOTS, W_Sound("laserimpact"), VOL_BASE, ATTEN_NORM);
260 pointparticles(particleeffectnum(EFFECT_RAPTOR_CANNON_IMPACT), self.origin, w_backoff * 1000, 1);
262 case DEATH_VH_RAPT_FRAGMENT:
265 for(i = 1; i < 4; ++i)
267 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
268 ang = vectoangles(vel);
269 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
271 sound(self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
272 pointparticles(particleeffectnum(EFFECT_RAPTOR_BOMB_SPREAD), self.origin, w_backoff * 1000, 1);
274 case DEATH_VH_RAPT_BOMB:
275 sound(self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
276 pointparticles(particleeffectnum(EFFECT_RAPTOR_BOMB_IMPACT), self.origin, w_backoff * 1000, 1);
278 case DEATH_VH_RAPT_DEATH:
279 sound(self, CH_SHOTS, W_Sound("laserimpact"), VOL_BASE, ATTEN_MIN);
280 pointparticles(particleeffectnum(EFFECT_EXPLOSION_BIG), self.origin, w_backoff * 1000, 1);
282 case DEATH_VH_BUMB_GUN:
283 sound(self, CH_SHOTS, W_Sound("fireball_impact2"), VOL_BASE, ATTEN_NORM);
284 pointparticles(particleeffectnum(EFFECT_BIGPLASMA_IMPACT), self.origin, w_backoff * 1000, 1);
290 if(DEATH_ISTURRET(w_deathtype))
293 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
294 if(trace_plane_normal != '0 0 0')
295 w_backoff = trace_plane_normal;
297 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
299 setorigin(self, w_org + w_backoff * 2); // for sound() calls
303 case DEATH_TURRET_EWHEEL:
304 sound(self, CH_SHOTS, W_Sound("laserimpact"), VOL_BASE, ATTEN_MIN);
305 pointparticles(particleeffectnum(EFFECT_BLASTER_IMPACT), self.origin, w_backoff * 1000, 1);
308 case DEATH_TURRET_FLAC:
309 pointparticles(particleeffectnum(EFFECT_HAGAR_EXPLODE), w_org, '0 0 0', 1);
310 _snd = W_Sound(strcat("hagexp", ftos(1 + rint(random() * 2))));
311 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
314 case DEATH_TURRET_MLRS:
315 case DEATH_TURRET_HK:
316 case DEATH_TURRET_WALK_ROCKET:
317 case DEATH_TURRET_HELLION:
318 sound(self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_MIN);
319 pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), self.origin, w_backoff * 1000, 1);
322 case DEATH_TURRET_MACHINEGUN:
323 case DEATH_TURRET_WALK_GUN:
324 _snd = W_Sound(strcat("ric", ftos(1 + rint(random() * 2))));
325 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
326 pointparticles(particleeffectnum(EFFECT_MACHINEGUN_IMPACT), self.origin, w_backoff * 1000, 1);
329 case DEATH_TURRET_PLASMA:
330 sound(self, CH_SHOTS, W_Sound("electro_impact"), VOL_BASE, ATTEN_MIN);
331 pointparticles(particleeffectnum(EFFECT_ELECTRO_IMPACT), self.origin, w_backoff * 1000, 1);
334 case DEATH_TURRET_WALK_MELEE:
335 sound(self, CH_SHOTS, W_Sound("ric1"), VOL_BASE, ATTEN_MIN);
336 pointparticles(particleeffectnum(EFFECT_TE_SPARK), self.origin, w_backoff * 1000, 1);
339 case DEATH_TURRET_PHASER:
342 case DEATH_TURRET_TESLA:
343 te_smallflash(self.origin);
349 // TODO spawn particle effects and sounds based on w_deathtype
350 if(!DEATH_ISSPECIAL(w_deathtype))
351 if(!hitplayer || rad) // don't show ground impacts for hitscan weapons if a player was hit
353 int hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
354 w_random = prandom();
356 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
357 if(trace_fraction < 1 && hitwep != WEP_VORTEX.m_id && hitwep != WEP_VAPORIZER.m_id)
358 w_backoff = trace_plane_normal;
360 w_backoff = -1 * normalize(force);
361 setorigin(self, w_org + w_backoff * 2); // for sound() calls
363 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)) { WEP_ACTION(hitwep, WR_IMPACTEFFECT); }