1 void DamageEffect(vector hitorg, float dmg, float type, float specnum1);
2 void Ent_DamageInfo(float isNew)
4 float dmg, rad, edge, thisdmg, forcemul, species;
5 vector force, thisforce;
10 w_deathtype = ReadShort();
11 w_issilent = (w_deathtype & 0x8000);
12 w_deathtype = (w_deathtype & 0x7FFF);
14 w_org_x = ReadCoord();
15 w_org_y = ReadCoord();
16 w_org_z = ReadCoord();
21 force = decompressShortVector(ReadShort());
35 for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
37 vector nearest = NearestPointOnBox(self, w_org);
40 thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
47 thisdmg = dmg + (edge - dmg) * thisdmg;
48 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
53 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
58 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
62 thisforce = forcemul * force;
65 if(self.damageforcescale)
68 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
69 self.move_flags &~= FL_ONGROUND;
76 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
78 DamageEffect(w_org, thisdmg, w_deathtype, species);
83 if(DEATH_ISVEHICLE(w_deathtype))
85 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
86 if(trace_plane_normal != '0 0 0')
87 w_backoff = trace_plane_normal;
89 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
91 setorigin(self, w_org + w_backoff * 2); // for sound() calls
100 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
101 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
102 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
105 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
106 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
109 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
110 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
114 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
115 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
117 case DEATH_WAKIROCKET:
118 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
119 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
121 case DEATH_WAKIBLOWUP:
122 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
123 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
126 case DEATH_RAPTOR_CANNON:
127 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
128 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
130 case DEATH_RAPTOR_BOMB_SPLIT:
133 for(i = 1; i < 4; ++i)
135 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
136 ang = vectoangles(vel);
137 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
141 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
142 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
144 case DEATH_RAPTOR_BOMB:
145 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
146 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
148 case DEATH_RAPTOR_DEATH:
149 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
150 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
156 if(DEATH_ISTURRET(w_deathtype))
159 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
160 if(trace_plane_normal != '0 0 0')
161 w_backoff = trace_plane_normal;
163 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
165 setorigin(self, w_org + w_backoff * 2); // for sound() calls
169 case DEATH_TURRET_EWHEEL:
170 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
171 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
174 case DEATH_TURRET_FLAC:
175 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
176 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
177 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
180 case DEATH_TURRET_MLRS:
181 case DEATH_TURRET_HK:
182 case DEATH_TURRET_WALKER_ROCKET:
183 case DEATH_TURRET_HELLION:
184 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
185 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
188 case DEATH_TURRET_MACHINEGUN:
189 case DEATH_TURRET_WALKER_GUN:
190 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
191 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
192 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
195 case DEATH_TURRET_PLASMA:
196 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
197 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
200 case DEATH_TURRET_WALKER_MEELE:
201 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
202 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
205 case DEATH_TURRET_PHASER:
208 case DEATH_TURRET_TESLA:
209 te_smallflash(self.origin);
215 // TODO spawn particle effects and sounds based on w_deathtype
216 if(!DEATH_ISSPECIAL(w_deathtype))
220 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
221 w_random = prandom();
223 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
224 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
225 w_backoff = trace_plane_normal;
227 w_backoff = -1 * normalize(force);
228 setorigin(self, w_org + w_backoff * 2); // for sound() calls
230 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
234 void DamageInfo_Precache()
237 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
238 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
241 void DamageEffect_Think()
243 if(time >= self.cnt || self.owner == world || self.owner.model == "" || !self.owner.drawmask)
245 // time is up or the player got gibbed / disconnected
249 if(self.owner.entnum == player_localentnum && !autocvar_chase_active)
250 return; // if we aren't using a third person view, hide our own effects
252 // now generate the particles
254 org = gettaginfo(self, 0); // origin at attached location
255 pointparticles(self.team, org, '0 0 0', 1);
256 self.nextthink = time + autocvar_cl_damageeffect_ticrate;
259 void DamageEffect(vector hitorg, float dmg, float type, float specnum)
261 // particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
264 string specstr, effectnum;
267 if(autocvar_cl_gentle || autocvar_cl_gentle_damage)
269 if(self == world || self.model == "" || !self.drawmask)
272 // return if we reached our damage effect limit
273 for(e = world; (e = find(e, classname, "damageeffect")); )
274 if(e.owner.entnum == self.entnum)
276 if(autocvar_cl_damageeffect < 1 || (self.isplayermodel && i >= autocvar_cl_damageeffect_limit))
277 return; // allow multiple damage effects on players
278 if(autocvar_cl_damageeffect < 2 || (!self.isplayermodel && i))
279 return; // allow a single damage effect on objects
281 specstr = species_prefix(specnum);
282 life = bound(autocvar_cl_damageeffect_lifetime_min, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
283 type = DEATH_WEAPONOF(type);
284 e = get_weaponinfo(type);
286 effectnum = strcat("weapondamage_", e.netname);
287 // if the weapon is a bullet weapon, its damage effect is blood
288 // since blood is species dependent, use the species tag for this effect
289 if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_RIFLE)
291 if(self.isplayermodel)
293 effectnum = strcat(effectnum, "_", specstr);
294 effectnum = substring(effectnum, 0, strlen(effectnum) - 1); // remove the _ symbol at the end of the species tag
297 return; // objects don't bleed
300 // if this is a player, damage effects will show on the limb where damage was dealt
301 // we do this by choosing the skeletal bone closest to the impact, and attaching the effect there
302 if(self.isplayermodel)
307 // go through all skeletal bones on the player, and choose the one closest to the damage origin
308 if(!closest || vlen(hitorg - gettaginfo(self, tagnum)) <= vlen(hitorg - gettaginfo(self, closest)))
311 gettaginfo(self, closest); // set gettaginfo_name to our bone
314 gettaginfo(self, 0); // set gettaginfo_name to entity origin
317 setmodel(e, "models/null.md3"); // necessary to attach and read origin
318 setattachment(e, self, gettaginfo_name); // attach to the given bone
321 e.classname = "damageeffect";
322 e.team = particleeffectnum(effectnum);
323 e.think = DamageEffect_Think;