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 -= 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 -= 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)
39 string specstr, effectnum;
42 if(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 // blacklist bones positioned outside the mesh, or the effect will be floating
54 // TODO: Do we have to do it this way? Why do these bones exist at all?
55 if(gettaginfo_name == "master" || gettaginfo_name == "knee_L" || gettaginfo_name == "knee_R" || gettaginfo_name == "leg_L" || gettaginfo_name == "leg_R")
56 continue; // player model bone blacklist
57 if(gettaginfo_name == "")
58 continue; // skip empty bones
60 // now choose the bone closest to impact origin
61 if(!closest || vlen(hitorg - gettaginfo(self, tagnum)) <= vlen(hitorg - gettaginfo(self, closest)))
64 skeletal = TRUE; // a bone was found, so this model is rigged
67 gettaginfo(self, closest); // set gettaginfo_name
69 // return if we reached our damage effect limit or damages are disabled
72 if(autocvar_cl_damageeffect < 1 || self.total_damages >= autocvar_cl_damageeffect_bones)
73 return; // allow multiple damages on skeletal models
77 if(autocvar_cl_damageeffect < 2 || self.total_damages)
78 return; // allow a single damage on non-skeletal models
81 life = bound(autocvar_cl_damageeffect_lifetime_min, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
82 specstr = species_prefix(specnum);
83 type = DEATH_WEAPONOF(type);
84 e = get_weaponinfo(type);
86 effectnum = strcat("damage_", e.netname);
88 // if damage was dealt with a bullet weapon, our effect is blood
89 // since blood is species dependent, include the species tag
90 if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_RIFLE)
92 if(self.isplayermodel)
94 effectnum = strcat(effectnum, "_", specstr);
95 effectnum = substring(effectnum, 0, strlen(effectnum) - 1); // remove the _ symbol at the end of the species tag
98 return; // objects don't bleed
102 setmodel(e, "null"); // necessary to attach and read origin // samual: FIXME: this is weird, is there some better way to do this?
103 setattachment(e, self, gettaginfo_name); // attach to the given bone
104 e.classname = "damage";
107 e.team = particleeffectnum(effectnum);
108 e.think = DamageEffect_Think;
110 self.total_damages += 1;
113 void Ent_DamageInfo(float isNew)
115 float dmg, rad, edge, thisdmg, forcemul, species;
116 vector force, thisforce;
121 w_deathtype = ReadShort();
122 w_issilent = (w_deathtype & 0x8000);
123 w_deathtype = (w_deathtype & 0x7FFF);
125 w_org_x = ReadCoord();
126 w_org_y = ReadCoord();
127 w_org_z = ReadCoord();
132 force = decompressShortVector(ReadShort());
133 species = ReadByte();
146 for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
148 vector nearest = NearestPointOnBox(self, w_org);
151 thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
158 thisdmg = dmg + (edge - dmg) * thisdmg;
159 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
164 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
169 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
173 thisforce = forcemul * force;
176 if(self.damageforcescale)
179 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
180 self.move_flags &~= FL_ONGROUND;
186 if(self.event_damage)
187 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
189 DamageEffect(w_org, thisdmg, w_deathtype, species);
194 if(DEATH_ISVEHICLE(w_deathtype))
196 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
197 if(trace_plane_normal != '0 0 0')
198 w_backoff = trace_plane_normal;
200 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
202 setorigin(self, w_org + w_backoff * 2); // for sound() calls
210 case DEATH_SBMINIGUN:
212 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
213 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
214 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
217 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
218 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
221 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
222 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
226 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
227 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
229 case DEATH_WAKIROCKET:
230 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
231 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
233 case DEATH_WAKIBLOWUP:
234 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
235 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
238 case DEATH_RAPTOR_CANNON:
239 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
240 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
242 case DEATH_RAPTOR_BOMB_SPLIT:
245 for(i = 1; i < 4; ++i)
247 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
248 ang = vectoangles(vel);
249 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
251 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
252 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
254 case DEATH_RAPTOR_BOMB:
255 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
256 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
258 case DEATH_RAPTOR_DEATH:
259 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
260 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
266 if(DEATH_ISTURRET(w_deathtype))
269 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
270 if(trace_plane_normal != '0 0 0')
271 w_backoff = trace_plane_normal;
273 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
275 setorigin(self, w_org + w_backoff * 2); // for sound() calls
279 case DEATH_TURRET_EWHEEL:
280 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
281 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
284 case DEATH_TURRET_FLAC:
285 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
286 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
287 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
290 case DEATH_TURRET_MLRS:
291 case DEATH_TURRET_HK:
292 case DEATH_TURRET_WALKER_ROCKET:
293 case DEATH_TURRET_HELLION:
294 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
295 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
298 case DEATH_TURRET_MACHINEGUN:
299 case DEATH_TURRET_WALKER_GUN:
300 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
301 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
302 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
305 case DEATH_TURRET_PLASMA:
306 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
307 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
310 case DEATH_TURRET_WALKER_MEELE:
311 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
312 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
315 case DEATH_TURRET_PHASER:
318 case DEATH_TURRET_TESLA:
319 te_smallflash(self.origin);
325 // TODO spawn particle effects and sounds based on w_deathtype
326 if(!DEATH_ISSPECIAL(w_deathtype))
330 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
331 w_random = prandom();
333 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
334 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
335 w_backoff = trace_plane_normal;
337 w_backoff = -1 * normalize(force);
338 setorigin(self, w_org + w_backoff * 2); // for sound() calls
340 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
344 void DamageInfo_Precache()
347 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
348 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);