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
68 if(self.total_damages >= autocvar_cl_damageeffect_bones)
69 return; // allow multiple damages on skeletal models
73 if(autocvar_cl_damageeffect < 2 || self.total_damages)
74 return; // allow a single damage on non-skeletal models
77 life = bound(autocvar_cl_damageeffect_lifetime_min, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
78 specstr = species_prefix(specnum);
79 type = DEATH_WEAPONOF(type);
80 e = get_weaponinfo(type);
82 effectname = strcat("damage_", e.netname);
84 // if damage was dealt with a bullet weapon, our effect is blood
85 // since blood is species dependent, include the species tag
86 if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_RIFLE)
88 if(self.isplayermodel)
90 effectname = strcat(effectname, "_", specstr);
91 effectname = substring(effectname, 0, strlen(effectname) - 1); // remove the _ symbol at the end of the species tag
94 return; // objects don't bleed
98 setmodel(e, "null"); // necessary to attach and read origin // samual: FIXME: this is weird, is there some better way to do this?
99 setattachment(e, self, gettaginfo_name); // attach to the given bone
100 e.classname = "damage";
103 e.team = particleeffectnum(effectname);
104 e.think = DamageEffect_Think;
106 self.total_damages += 1;
109 void Ent_DamageInfo(float isNew)
111 float dmg, rad, edge, thisdmg, forcemul, species;
112 vector force, thisforce;
117 w_deathtype = ReadShort();
118 w_issilent = (w_deathtype & 0x8000);
119 w_deathtype = (w_deathtype & 0x7FFF);
121 w_org_x = ReadCoord();
122 w_org_y = ReadCoord();
123 w_org_z = ReadCoord();
128 force = decompressShortVector(ReadShort());
129 species = ReadByte();
142 for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
144 vector nearest = NearestPointOnBox(self, w_org);
147 thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
154 thisdmg = dmg + (edge - dmg) * thisdmg;
155 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
160 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
165 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
169 thisforce = forcemul * force;
172 if(self.damageforcescale)
175 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
176 self.move_flags &~= FL_ONGROUND;
182 if(self.event_damage)
183 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
185 DamageEffect(w_org, thisdmg, w_deathtype, species);
190 if(DEATH_ISVEHICLE(w_deathtype))
192 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
193 if(trace_plane_normal != '0 0 0')
194 w_backoff = trace_plane_normal;
196 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
198 setorigin(self, w_org + w_backoff * 2); // for sound() calls
206 case DEATH_SBMINIGUN:
208 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
209 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
210 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
213 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
214 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
217 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
218 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
222 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
223 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
225 case DEATH_WAKIROCKET:
226 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
227 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
229 case DEATH_WAKIBLOWUP:
230 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
231 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
234 case DEATH_RAPTOR_CANNON:
235 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
236 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
238 case DEATH_RAPTOR_BOMB_SPLIT:
241 for(i = 1; i < 4; ++i)
243 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
244 ang = vectoangles(vel);
245 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
247 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
248 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
250 case DEATH_RAPTOR_BOMB:
251 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
252 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
254 case DEATH_RAPTOR_DEATH:
255 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
256 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
262 if(DEATH_ISTURRET(w_deathtype))
265 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
266 if(trace_plane_normal != '0 0 0')
267 w_backoff = trace_plane_normal;
269 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
271 setorigin(self, w_org + w_backoff * 2); // for sound() calls
275 case DEATH_TURRET_EWHEEL:
276 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
277 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
280 case DEATH_TURRET_FLAC:
281 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
282 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
283 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
286 case DEATH_TURRET_MLRS:
287 case DEATH_TURRET_HK:
288 case DEATH_TURRET_WALKER_ROCKET:
289 case DEATH_TURRET_HELLION:
290 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
291 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
294 case DEATH_TURRET_MACHINEGUN:
295 case DEATH_TURRET_WALKER_GUN:
296 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
297 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
298 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
301 case DEATH_TURRET_PLASMA:
302 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
303 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
306 case DEATH_TURRET_WALKER_MEELE:
307 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
308 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
311 case DEATH_TURRET_PHASER:
314 case DEATH_TURRET_TESLA:
315 te_smallflash(self.origin);
321 // TODO spawn particle effects and sounds based on w_deathtype
322 if(!DEATH_ISSPECIAL(w_deathtype))
326 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
327 w_random = prandom();
329 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
330 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
331 w_backoff = trace_plane_normal;
333 w_backoff = -1 * normalize(force);
334 setorigin(self, w_org + w_backoff * 2); // for sound() calls
336 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
340 void DamageInfo_Precache()
343 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
344 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);