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);
45 thisdmg = dmg + (edge - dmg) * thisdmg;
46 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
51 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
56 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
60 thisforce = forcemul * force;
63 if(self.damageforcescale)
66 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
67 self.move_flags &~= FL_ONGROUND;
74 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
76 DamageEffect(w_org, thisdmg, w_deathtype, species);
81 if(DEATH_ISVEHICLE(w_deathtype))
83 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
84 if(trace_plane_normal != '0 0 0')
85 w_backoff = trace_plane_normal;
87 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
89 setorigin(self, w_org + w_backoff * 2); // for sound() calls
98 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
99 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
100 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
103 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
104 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
107 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
108 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
112 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
113 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
115 case DEATH_WAKIROCKET:
116 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
117 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
119 case DEATH_WAKIBLOWUP:
120 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
121 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
124 case DEATH_RAPTOR_CANNON:
125 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
126 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
128 case DEATH_RAPTOR_BOMB_SPLIT:
131 for(i = 1; i < 4; ++i)
133 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
134 ang = vectoangles(vel);
135 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
139 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
140 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
142 case DEATH_RAPTOR_BOMB:
143 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
144 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
146 case DEATH_RAPTOR_DEATH:
147 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
148 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
154 if(DEATH_ISTURRET(w_deathtype))
157 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
158 if(trace_plane_normal != '0 0 0')
159 w_backoff = trace_plane_normal;
161 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
163 setorigin(self, w_org + w_backoff * 2); // for sound() calls
167 case DEATH_TURRET_EWHEEL:
168 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
169 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
172 case DEATH_TURRET_FLAC:
173 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
174 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
175 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
178 case DEATH_TURRET_MLRS:
179 case DEATH_TURRET_HK:
180 case DEATH_TURRET_WALKER_ROCKET:
181 case DEATH_TURRET_HELLION:
182 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
183 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
186 case DEATH_TURRET_MACHINEGUN:
187 case DEATH_TURRET_WALKER_GUN:
188 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
189 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
190 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
193 case DEATH_TURRET_PLASMA:
194 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
195 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
198 case DEATH_TURRET_WALKER_MEELE:
199 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
200 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
203 case DEATH_TURRET_PHASER:
206 case DEATH_TURRET_TESLA:
207 te_smallflash(self.origin);
213 // TODO spawn particle effects and sounds based on w_deathtype
214 if(!DEATH_ISSPECIAL(w_deathtype))
218 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
219 w_random = prandom();
221 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
222 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
223 w_backoff = trace_plane_normal;
225 w_backoff = -1 * normalize(force);
226 setorigin(self, w_org + w_backoff * 2); // for sound() calls
228 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
232 void DamageInfo_Precache()
235 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
236 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
239 void DamageEffect_Think()
241 if(time >= self.cnt || self.owner == world || self.owner.model == "" || !self.owner.drawmask)
243 // time is up or the player got gibbed / disconnected
247 if(self.owner.entnum == player_localentnum && !autocvar_chase_active)
248 return; // if we aren't using a third person view, hide our own effects
250 // now generate the particles
252 org = gettaginfo(self, 0); // origin at attached location
253 pointparticles(self.team, org, '0 0 0', 1);
254 self.nextthink = time + autocvar_cl_damageeffect_ticrate;
257 void DamageEffect(vector hitorg, float dmg, float type, float specnum)
259 // particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
262 string specstr, effectnum;
265 if(autocvar_cl_gentle || autocvar_cl_gentle_damage)
267 if(self == world || self.model == "" || !self.drawmask)
270 // return if we reached our damage effect limit
271 for(e = world; (e = find(e, classname, "damageeffect")); )
272 if(e.owner.entnum == self.entnum)
274 if(autocvar_cl_damageeffect < 1 || (self.isplayermodel && i >= autocvar_cl_damageeffect_limit))
275 return; // allow multiple damage effects on players
276 if(autocvar_cl_damageeffect < 2 || (!self.isplayermodel && i))
277 return; // allow a single damage effect on objects
279 specstr = species_prefix(specnum);
280 life = bound(autocvar_cl_damageeffect_lifetime_min, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
281 type = DEATH_WEAPONOF(type);
282 e = get_weaponinfo(type);
284 effectnum = strcat("weapondamage_", e.netname);
285 // if the weapon is a bullet weapon, its damage effect is blood
286 // since blood is species dependent, use the species tag for this effect
287 if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_RIFLE)
289 if(self.isplayermodel)
291 effectnum = strcat(effectnum, "_", specstr);
292 effectnum = substring(effectnum, 0, strlen(effectnum) - 1); // remove the _ symbol at the end of the species tag
295 return; // objects don't bleed
298 // if this is a player, damage effects will show on the limb where damage was dealt
299 // we do this by choosing the skeletal bone closest to the impact, and attaching the effect there
300 if(self.isplayermodel)
305 // go through all skeletal bones on the player, and choose the one closest to the damage origin
306 if(!closest || vlen(hitorg - gettaginfo(self, tagnum)) <= vlen(hitorg - gettaginfo(self, closest)))
309 gettaginfo(self, closest); // set gettaginfo_name to our bone
312 gettaginfo(self, 0); // set gettaginfo_name to entity origin
315 setmodel(e, "models/null.md3"); // necessary to attach and read origin
316 setattachment(e, self, gettaginfo_name); // attach to the given bone
319 e.classname = "damageeffect";
320 e.team = particleeffectnum(effectnum);
321 e.think = DamageEffect_Think;