1 void DamageEffect_Think()
3 // if particle distribution is enabled, slow ticrate by total number of damages
4 if(autocvar_cl_damageeffect_distribute)
5 self.nextthink = time + autocvar_cl_damageeffect_ticrate * self.owner.total_damages;
7 self.nextthink = time + autocvar_cl_damageeffect_ticrate;
9 if(time >= self.cnt || !self.owner || !self.owner.modelindex || !self.owner.drawmask)
11 // time is up or the player got gibbed / disconnected
12 self.owner.total_damages = max(0, self.owner.total_damages - 1);
16 if(self.state && !self.owner.csqcmodel_isdead)
18 // if the player was dead but is now alive, it means he respawned
19 // if so, clear his damage effects, or damages from his dead body will be copied back
20 self.owner.total_damages = max(0, self.owner.total_damages - 1);
24 self.state = self.owner.csqcmodel_isdead;
25 if(self.owner.isplayermodel && (self.owner.entnum == player_localentnum || self.owner.entnum == spectatee_status) && !autocvar_chase_active)
26 return; // if we aren't using a third person camera, hide our own effects
28 // now generate the particles
30 org = gettaginfo(self, 0); // origin at attached location
31 pointparticles(self.team, org, '0 0 0', 1);
34 void DamageEffect(vector hitorg, float dmg, float type, float specnum)
36 // particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
38 float life, nearestbone;
39 string specstr, effectname;
42 if(!autocvar_cl_damageeffect || autocvar_cl_gentle || autocvar_cl_gentle_damage)
44 if(!self || !self.modelindex || !self.drawmask)
47 // if this is a rigged mesh, the effect will show on the bone where damage was dealt
48 // we do this by choosing the skeletal bone closest to the impact, and attaching our entity to it
49 // if there's no skeleton, object origin will automatically be selected
53 continue; // skip empty bones
54 // blacklist bones positioned outside the mesh, or the effect will be floating
55 // TODO: Do we have to do it this way? Why do these bones exist at all?
56 if(gettaginfo_name == "master" || gettaginfo_name == "knee_L" || gettaginfo_name == "knee_R" || gettaginfo_name == "leg_L" || gettaginfo_name == "leg_R")
57 continue; // player model bone blacklist
59 // now choose the bone closest to impact origin
60 if(vlen(hitorg - gettaginfo(self, tagnum)) <= vlen(hitorg - gettaginfo(self, nearestbone)))
63 gettaginfo(self, nearestbone); // set gettaginfo_name
65 // return if we reached our damage effect limit or damages are disabled
66 // TODO: it would be better if the oldest damage was removed instead of not adding a new one
69 if(self.total_damages >= autocvar_cl_damageeffect_bones)
70 return; // allow multiple damages on skeletal models
74 if(autocvar_cl_damageeffect < 2 || self.total_damages)
75 return; // allow a single damage on non-skeletal models
78 life = bound(autocvar_cl_damageeffect_lifetime_min, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
79 specstr = species_prefix(specnum);
80 type = DEATH_WEAPONOF(type);
81 e = get_weaponinfo(type);
83 effectname = strcat("damage_", e.netname);
85 // if damage was dealt with a bullet weapon, our effect is blood
86 // since blood is species dependent, include the species tag
87 if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_RIFLE)
89 if(self.isplayermodel)
91 effectname = strcat(effectname, "_", specstr);
92 effectname = substring(effectname, 0, strlen(effectname) - 1); // remove the _ symbol at the end of the species tag
95 return; // objects don't bleed
99 setmodel(e, "null"); // necessary to attach and read origin // samual: FIXME: this is weird, is there some better way to do this?
100 setattachment(e, self, gettaginfo_name); // attach to the given bone
101 e.classname = "damage";
104 e.team = particleeffectnum(effectname);
105 e.think = DamageEffect_Think;
107 self.total_damages += 1;
110 void Ent_DamageInfo(float isNew)
112 float dmg, rad, edge, thisdmg, forcemul, species;
113 vector force, thisforce;
118 w_deathtype = ReadShort();
119 w_issilent = (w_deathtype & 0x8000);
120 w_deathtype = (w_deathtype & 0x7FFF);
122 w_org_x = ReadCoord();
123 w_org_y = ReadCoord();
124 w_org_z = ReadCoord();
129 force = decompressShortVector(ReadShort());
130 species = ReadByte();
143 for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
145 vector nearest = NearestPointOnBox(self, w_org);
148 thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
155 thisdmg = dmg + (edge - dmg) * thisdmg;
156 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
161 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
166 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
170 thisforce = forcemul * force;
173 if(self.damageforcescale)
176 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
177 self.move_flags &~= FL_ONGROUND;
183 if(self.event_damage)
184 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
186 DamageEffect(w_org, thisdmg, w_deathtype, species);
191 if(DEATH_ISVEHICLE(w_deathtype))
193 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
194 if(trace_plane_normal != '0 0 0')
195 w_backoff = trace_plane_normal;
197 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
199 setorigin(self, w_org + w_backoff * 2); // for sound() calls
207 case DEATH_SBMINIGUN:
209 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
210 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
211 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
214 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
215 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
218 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
219 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
223 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
224 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
226 case DEATH_WAKIROCKET:
227 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
228 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
230 case DEATH_WAKIBLOWUP:
231 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
232 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
235 case DEATH_RAPTOR_CANNON:
236 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
237 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
239 case DEATH_RAPTOR_BOMB_SPLIT:
242 for(i = 1; i < 4; ++i)
244 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
245 ang = vectoangles(vel);
246 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
248 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
249 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
251 case DEATH_RAPTOR_BOMB:
252 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
253 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
255 case DEATH_RAPTOR_DEATH:
256 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
257 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
263 if(DEATH_ISTURRET(w_deathtype))
266 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
267 if(trace_plane_normal != '0 0 0')
268 w_backoff = trace_plane_normal;
270 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
272 setorigin(self, w_org + w_backoff * 2); // for sound() calls
276 case DEATH_TURRET_EWHEEL:
277 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
278 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
281 case DEATH_TURRET_FLAC:
282 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
283 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
284 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
287 case DEATH_TURRET_MLRS:
288 case DEATH_TURRET_HK:
289 case DEATH_TURRET_WALKER_ROCKET:
290 case DEATH_TURRET_HELLION:
291 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
292 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
295 case DEATH_TURRET_MACHINEGUN:
296 case DEATH_TURRET_WALKER_GUN:
297 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
298 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
299 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
302 case DEATH_TURRET_PLASMA:
303 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
304 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
307 case DEATH_TURRET_WALKER_MEELE:
308 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
309 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
312 case DEATH_TURRET_PHASER:
315 case DEATH_TURRET_TESLA:
316 te_smallflash(self.origin);
322 // TODO spawn particle effects and sounds based on w_deathtype
323 if(!DEATH_ISSPECIAL(w_deathtype))
327 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
328 w_random = prandom();
330 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
331 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
332 w_backoff = trace_plane_normal;
334 w_backoff = -1 * normalize(force);
335 setorigin(self, w_org + w_backoff * 2); // for sound() calls
337 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
341 void DamageInfo_Precache()
344 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
345 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);