1 void Ent_DamageInfo(float isNew)
3 float dmg, rad, edge, thisdmg, forcemul;
4 vector force, thisforce;
9 w_deathtype = ReadShort();
10 w_issilent = (w_deathtype & 0x8000);
11 w_deathtype = (w_deathtype & 0x7FFF);
13 w_org_x = ReadCoord();
14 w_org_y = ReadCoord();
15 w_org_z = ReadCoord();
20 force = decompressShortVector(ReadShort());
33 for(self = findradius(w_org, rad); self; self = self.chain)
37 thisdmg = vlen(self.origin - w_org) / rad;
42 thisdmg = dmg + (edge - dmg) * thisdmg;
43 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
48 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
54 thisforce = forcemul * force;
57 if(self.damageforcescale)
60 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
61 self.move_flags &~= FL_ONGROUND;
68 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
73 if(DEATH_ISVEHICLE(w_deathtype))
75 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
76 if(trace_plane_normal != '0 0 0')
77 w_backoff = trace_plane_normal;
79 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
81 setorigin(self, w_org + w_backoff * 2); // for sound() calls
90 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
91 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
92 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
95 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
96 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
99 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
100 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
104 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
105 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
107 case DEATH_WAKIROCKET:
108 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
109 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
111 case DEATH_WAKIBLOWUP:
112 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
113 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
116 case DEATH_RAPTOR_CANNON:
117 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
118 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
120 case DEATH_RAPTOR_BOMB_SPLIT:
123 for(i = 1; i < 4; ++i)
125 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
126 ang = vectoangles(vel);
127 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
131 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
132 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
134 case DEATH_RAPTOR_BOMB:
135 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
136 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
138 case DEATH_RAPTOR_DEATH:
139 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
140 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
146 if(DEATH_ISTURRET(w_deathtype))
148 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
149 if(trace_plane_normal != '0 0 0')
150 w_backoff = trace_plane_normal;
152 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
154 setorigin(self, w_org + w_backoff * 2); // for sound() calls
158 case DEATH_TURRET_EWHEEL:
159 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
160 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
163 case DEATH_TURRET_FLAC:
165 org2 = w_org + w_backoff * 6;
166 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
168 sound(self, CH_SHOTS, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
169 else if (w_random<0.7)
170 sound(self, CH_SHOTS, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
172 sound(self, CH_SHOTS, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
176 case DEATH_TURRET_MLRS:
177 case DEATH_TURRET_HK:
178 case DEATH_TURRET_WALKER_ROCKET:
179 case DEATH_TURRET_HELLION:
180 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
181 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
184 case DEATH_TURRET_MACHINEGUN:
185 case DEATH_TURRET_WALKER_GUN:
187 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
188 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
189 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
192 case DEATH_TURRET_PLASMA:
193 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
194 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
197 case DEATH_TURRET_WALKER_MEELE:
198 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
199 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
202 case DEATH_TURRET_PHASER:
205 case DEATH_TURRET_TESLA:
206 te_smallflash(self.origin);
212 // TODO spawn particle effects and sounds based on w_deathtype
213 if(!DEATH_ISSPECIAL(w_deathtype))
217 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
218 w_random = prandom();
220 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
221 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
222 w_backoff = trace_plane_normal;
224 w_backoff = -1 * normalize(force);
225 setorigin(self, w_org + w_backoff * 2); // for sound() calls
227 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
231 void DamageInfo_Precache()
234 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
235 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
241 .float dmgpartnum, dmgtime;
243 void Ent_DamageEffect_Think()
245 self.nextthink = time;
250 if(self.dmgtime > time)
252 entcs = entcs_receiver[self.team];
256 // Scan the owner of all gibs in the world. If a gib owner is the same as the player we're applying
257 // the effect to, it means our player is gibbed. Therefore, apply particles to the gibs instead.
259 for(head = world; (head = find(head, classname, "gib")); )
261 if(head.team == self.team)
263 if(autocvar_cl_damageeffect_gibs)
265 if(autocvar_cl_damageeffect_gibs_randomize < random())
266 pointparticles(self.dmgpartnum, head.origin, '0 0 0', 1);
267 self.dmgtime = time + autocvar_cl_damageeffect_gibs;
273 if(foundgib || !autocvar_cl_damageeffect_player)
274 return; // don't show effects on the invisible dead body if gibs exist
275 if(self.team == player_localentnum - 1 && !autocvar_chase_active)
276 return; // if we aren't in third person mode, hide own damage effect
278 // Now apply the effect to actual players
279 pointparticles(self.dmgpartnum, entcs.origin, '0 0 0', 1);
280 self.dmgtime = time + autocvar_cl_damageeffect_player;
283 void Ent_DamageEffect()
285 float dmg, type, specnum1, specnum2, entnumber;
287 string specstr, effectnum;
290 dmg = ReadByte(); // damage amount
291 type = ReadByte(); // damage weapon
292 specnum1 = ReadByte(); // player species
293 entnumber = ReadByte(); // player entnum
295 if(!autocvar_cl_damageeffect_player && !autocvar_cl_damageeffect_gibs)
297 if(autocvar_cl_gentle || autocvar_cl_gentle_damage)
300 specnum2 = (specnum1 & 0x78) / 8; // blood type: using four bits (0..7, bit indexes 3,4,5)
301 specstr = species_prefix(specnum2);
303 e = get_weaponinfo(type);
304 effectnum = strcat("weapondamage_", e.netname);
305 // If the weapon is a bullet weapon, its damage effect is blood.
306 // Since blood is species dependent, we make this effect per-species.
307 if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_RIFLE)
310 effectnum = strcat(effectnum, "_", specstr);
311 effectnum = substring(effectnum, 0, strlen(effectnum) - 1); // remove the _ symbol at the end of the species name
314 // if the player already has a damage effect, replace it with the new one
316 for(head = world; (head = find(head, classname, "dmgent")); )
318 if(head.team == entnumber - 1)
327 e.classname = "dmgent";
328 e.team = entnumber - 1;
329 e.dmgpartnum = particleeffectnum(effectnum);
330 e.think = Ent_DamageEffect_Think;