]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/player.qc
Some more defs.qh cleanup, update gameplay hash (again)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / player.qc
1 #include "player.qh"
2
3 #include <common/effects/all.qh>
4 #include "bot/api.qh"
5 #include "cheats.qh"
6 #include "client.qh"
7 #include "clientkill.qh"
8 #include "g_damage.qh"
9 #include "handicap.qh"
10 #include "miscfunctions.qh"
11 #include "portals.qh"
12 #include "teamplay.qh"
13 #include <server/sv_main.qh>
14 #include "weapons/throwing.qh"
15 #include "command/common.qh"
16 #include "command/vote.qh"
17 #include "../common/state.qh"
18 #include "../common/anim.qh"
19 #include "../common/animdecide.qh"
20 #include "../common/csqcmodel_settings.qh"
21 #include "../common/gamemodes/sv_rules.qh"
22 #include "../common/deathtypes/all.qh"
23 #include "../common/mapobjects/subs.qh"
24 #include <common/mapobjects/teleporters.qh>
25 #include "../common/playerstats.qh"
26 #include "../lib/csqcmodel/sv_model.qh"
27
28 #include "../common/minigames/sv_minigames.qh"
29
30 #include <common/gamemodes/_mod.qh>
31
32 #include "../common/physics/player.qh"
33 #include "../common/effects/qc/_mod.qh"
34 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
35 #include "../common/mapobjects/_mod.qh"
36 #include "../common/wepent.qh"
37
38 #include "weapons/weaponstats.qh"
39 #include <server/weapons/weaponsystem.qh>
40
41 #include "../common/animdecide.qh"
42
43 void Drop_Special_Items(entity player)
44 {
45         // called when the player has become stuck or frozen
46         // so objective items aren't stuck with the player
47
48         MUTATOR_CALLHOOK(DropSpecialItems, player);
49 }
50
51 void CopyBody_Think(entity this)
52 {
53         if(this.CopyBody_nextthink && time > this.CopyBody_nextthink)
54         {
55                 this.CopyBody_think(this);
56                 if(wasfreed(this))
57                         return;
58                 this.CopyBody_nextthink = this.nextthink;
59                 this.CopyBody_think = getthink(this);
60                 setthink(this, CopyBody_Think);
61         }
62         CSQCMODEL_AUTOUPDATE(this);
63         this.nextthink = time;
64 }
65 void CopyBody(entity this, float keepvelocity)
66 {
67         if (this.effects & EF_NODRAW)
68                 return;
69         entity clone = new(body);
70         clone.enemy = this;
71         clone.lip = this.lip;
72         clone.colormap = this.colormap;
73         clone.iscreature = this.iscreature;
74         clone.teleportable = this.teleportable;
75         clone.damagedbycontents = this.damagedbycontents;
76         if(clone.damagedbycontents)
77                 IL_PUSH(g_damagedbycontents, clone);
78         clone.angles = this.angles;
79         clone.v_angle = this.v_angle;
80         clone.avelocity = this.avelocity;
81         clone.damageforcescale = this.damageforcescale;
82         clone.effects = this.effects;
83         clone.glowmod = this.glowmod;
84         clone.event_damage = this.event_damage;
85         clone.event_heal = this.event_heal;
86         clone.anim_state = this.anim_state;
87         clone.anim_time = this.anim_time;
88         clone.anim_lower_action = this.anim_lower_action;
89         clone.anim_lower_time = this.anim_lower_time;
90         clone.anim_upper_action = this.anim_upper_action;
91         clone.anim_upper_time = this.anim_upper_time;
92         clone.anim_implicit_state = this.anim_implicit_state;
93         clone.anim_implicit_time = this.anim_implicit_time;
94         clone.anim_lower_implicit_action = this.anim_lower_implicit_action;
95         clone.anim_lower_implicit_time = this.anim_lower_implicit_time;
96         clone.anim_upper_implicit_action = this.anim_upper_implicit_action;
97         clone.anim_upper_implicit_time = this.anim_upper_implicit_time;
98         clone.dphitcontentsmask = this.dphitcontentsmask;
99         clone.death_time = this.death_time;
100         clone.pain_finished = this.pain_finished;
101         SetResourceExplicit(clone, RES_HEALTH, GetResource(this, RES_HEALTH));
102         SetResourceExplicit(clone, RES_ARMOR, GetResource(this, RES_ARMOR));
103         clone.armortype = this.armortype;
104         clone.model = this.model;
105         clone.modelindex = this.modelindex;
106         clone.skin = this.skin;
107         clone.species = this.species;
108         clone.move_qcphysics = false; // don't run gamecode logic on clones, too many
109         set_movetype(clone, this.move_movetype);
110         clone.solid = this.solid;
111         clone.takedamage = this.takedamage;
112         setcefc(clone, getcefc(this));
113         clone.uncustomizeentityforclient = this.uncustomizeentityforclient;
114         clone.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
115         if (keepvelocity == 1)
116                 clone.velocity = this.velocity;
117         clone.oldvelocity = clone.velocity;
118         clone.alpha = this.alpha;
119         clone.fade_time = this.fade_time;
120         clone.fade_rate = this.fade_rate;
121         //clone.weapon = this.weapon;
122         setorigin(clone, this.origin);
123         setsize(clone, this.mins, this.maxs);
124         clone.reset = SUB_Remove;
125         clone._ps = this._ps;
126
127         Drag_MoveDrag(this, clone);
128
129         if(clone.colormap <= maxclients && clone.colormap > 0)
130                 clone.colormap = 1024 + this.clientcolors;
131
132         CSQCMODEL_AUTOINIT(clone);
133         clone.CopyBody_nextthink = this.nextthink;
134         clone.CopyBody_think = getthink(this);
135         clone.nextthink = time;
136         setthink(clone, CopyBody_Think);
137         // "bake" the current animation frame for clones (they don't get clientside animation)
138         animdecide_load_if_needed(clone);
139         animdecide_setframes(clone, false, frame, frame1time, frame2, frame2time);
140
141         IL_PUSH(g_clones, clone);
142
143         MUTATOR_CALLHOOK(CopyBody, this, clone, keepvelocity);
144 }
145
146 void player_setupanimsformodel(entity this)
147 {
148         // load animation info
149         animdecide_load_if_needed(this);
150         animdecide_setstate(this, 0, false);
151 }
152
153 void player_anim(entity this)
154 {
155         int deadbits = (this.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
156         if(IS_DEAD(this)) {
157                 if (!deadbits) {
158                         // Decide on which death animation to use.
159                         if(random() < 0.5)
160                                 deadbits = ANIMSTATE_DEAD1;
161                         else
162                                 deadbits = ANIMSTATE_DEAD2;
163                 }
164         } else {
165                 // Clear a previous death animation.
166                 deadbits = 0;
167         }
168         int animbits = deadbits;
169         if(STAT(FROZEN, this))
170                 animbits |= ANIMSTATE_FROZEN;
171         if(this.move_movetype == MOVETYPE_FOLLOW)
172                 animbits |= ANIMSTATE_FOLLOW;
173         if(IS_DUCKED(this))
174                 animbits |= ANIMSTATE_DUCK;
175         animdecide_setstate(this, animbits, false);
176         animdecide_setimplicitstate(this, IS_ONGROUND(this));
177 }
178
179 void PlayerCorpseDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
180 {
181         float take, save;
182         vector v;
183         Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
184
185         v = healtharmor_applydamage(GetResource(this, RES_ARMOR), autocvar_g_balance_armor_blockpercent, deathtype, damage);
186         take = v.x;
187         save = v.y;
188
189         if(sound_allowed(MSG_BROADCAST, attacker))
190         {
191                 if (save > 10)
192                         sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
193                 else if (take > 30)
194                         sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
195                 else if (take > 10)
196                         sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
197         }
198
199         if (take > 50)
200                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
201         if (take > 100)
202                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
203
204         TakeResource(this, RES_ARMOR, save);
205         TakeResource(this, RES_HEALTH, take);
206         // pause regeneration for 5 seconds
207         this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
208
209         this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
210         this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
211         this.dmg_inflictor = inflictor;
212
213         if (GetResource(this, RES_HEALTH) <= -autocvar_sv_gibhealth && this.alpha >= 0)
214         {
215                 // don't use any animations as a gib
216                 this.frame = 0;
217                 // view just above the floor
218                 this.view_ofs = '0 0 4';
219
220                 Violence_GibSplash(this, 1, 1, attacker);
221                 this.alpha = -1;
222                 this.solid = SOLID_NOT; // restore later
223                 this.takedamage = DAMAGE_NO; // restore later
224                 if(this.damagedbycontents)
225                         IL_REMOVE(g_damagedbycontents, this);
226                 this.damagedbycontents = false;
227         }
228 }
229
230 void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
231 {
232         vector v;
233         float dh = max(GetResource(this, RES_HEALTH), 0);
234         float da = max(GetResource(this, RES_ARMOR), 0);
235         float take = 0, save = 0;
236
237         if (damage)
238         {
239                 if(!DEATH_ISSPECIAL(deathtype))
240                 {
241                         damage *= Handicap_GetTotalHandicap(this);
242                         if (this != attacker && IS_PLAYER(attacker))
243                         {
244                                 damage /= Handicap_GetTotalHandicap(attacker);
245                         }
246                 }
247
248                 if (time < this.spawnshieldtime && autocvar_g_spawnshield_blockdamage < 1)
249                         damage *= 1 - max(0, autocvar_g_spawnshield_blockdamage);
250
251                 if(deathtype & HITTYPE_SOUND) // sound based attacks cause bleeding from the ears
252                 {
253                         vector ear1, ear2;
254                         vector d;
255                         float f;
256                         ear1 = this.origin;
257                         ear1_z += 0.125 * this.view_ofs.z + 0.875 * this.maxs.z; // 7/8
258                         ear2 = ear1;
259                         makevectors(this.angles);
260                         ear1 += v_right * -10;
261                         ear2 += v_right * +10;
262                         d = inflictor.origin - this.origin;
263                         if (d)
264                                 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
265                         else
266                                 f = 0;  // Assum ecenter.
267                         force = v_right * vlen(force);
268                         Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), this, attacker);
269                         Violence_GibSplash_At(ear2, force,      2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), this, attacker);
270                         if(f > 0)
271                         {
272                                 hitloc = ear1;
273                                 force = force * -1;
274                         }
275                         else
276                         {
277                                 hitloc = ear2;
278                                 // force is already good
279                         }
280                 }
281                 else
282                         Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
283
284                 v = healtharmor_applydamage(GetResource(this, RES_ARMOR), autocvar_g_balance_armor_blockpercent, deathtype, damage);
285                 take = v.x;
286                 save = v.y;
287         }
288
289         if(attacker == this)
290         {
291                 // don't reset pushltime for self damage as it may be an attempt to
292                 // escape a lava pit or similar
293                 //this.pushltime = 0;
294                 this.istypefrag = 0;
295         }
296         else if(IS_PLAYER(attacker))
297         {
298                 this.pusher = attacker;
299                 this.pushltime = time + autocvar_g_maxpushtime;
300                 this.istypefrag = PHYS_INPUT_BUTTON_CHAT(this);
301         }
302         else if(time < this.pushltime)
303         {
304                 attacker = this.pusher;
305                 this.pushltime = max(this.pushltime, time + 0.6);
306         }
307         else
308         {
309                 this.pushltime = 0;
310                 this.istypefrag = 0;
311         }
312
313         MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, this, force, take, save, deathtype, damage);
314         take = bound(0, M_ARGV(4, float), GetResource(this, RES_HEALTH));
315         save = bound(0, M_ARGV(5, float), GetResource(this, RES_ARMOR));
316         float excess = max(0, damage - take - save);
317
318         if(sound_allowed(MSG_BROADCAST, attacker))
319         {
320                 if (save > 10 && (dh - take) > 0) // don't play armor sound if the attack is fatal
321                         sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
322                 else if (take > 30)
323                         sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
324                 else if (take > 10)
325                         sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
326         }
327
328         if (take > 50)
329                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
330         if (take > 100)
331                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
332
333         if (time >= this.spawnshieldtime || autocvar_g_spawnshield_blockdamage < 1)
334         {
335                 if (!(this.flags & FL_GODMODE))
336                 {
337                         TakeResource(this, RES_ARMOR, save);
338                         TakeResource(this, RES_HEALTH, take);
339                         // pause regeneration for 5 seconds
340                         if(take)
341                                 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
342
343                         if (time > this.pain_finished)          //Don't switch pain sequences like crazy
344                         {
345                                 this.pain_finished = time + 0.5;        //Supajoe
346
347                                 if(autocvar_sv_gentle < 1) {
348                                         if(this.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
349                                         {
350                                                 if (!this.animstate_override)
351                                                 {
352                                                         if (random() > 0.5)
353                                                                 animdecide_setaction(this, ANIMACTION_PAIN1, true);
354                                                         else
355                                                                 animdecide_setaction(this, ANIMACTION_PAIN2, true);
356                                                 }
357                                         }
358                                         float myhp = GetResource(this, RES_HEALTH);
359                                         if(myhp > 1)
360                                         if(myhp < 25 || !(DEATH_WEAPONOF(deathtype).spawnflags & WEP_FLAG_CANCLIMB) || take > 20 || attacker != this)
361                                         if(sound_allowed(MSG_BROADCAST, attacker))
362                                         // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
363                                         {
364                                                 if(deathtype == DEATH_FALL.m_id)
365                                                         PlayerSound(this, playersound_fall, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
366                                                 else if(myhp > 75)
367                                                         PlayerSound(this, playersound_pain100, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
368                                                 else if(myhp > 50)
369                                                         PlayerSound(this, playersound_pain75, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
370                                                 else if(myhp > 25)
371                                                         PlayerSound(this, playersound_pain50, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
372                                                 else
373                                                         PlayerSound(this, playersound_pain25, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
374                                         }
375                                 }
376                         }
377
378                         // throw off bot aim temporarily
379                         float shake;
380                         if(IS_BOT_CLIENT(this) && GetResource(this, RES_HEALTH) >= 1)
381                         {
382                                 shake = damage * 5 / (bound(0,skill,100) + 1);
383                                 this.v_angle_x = this.v_angle.x + (random() * 2 - 1) * shake;
384                                 this.v_angle_y = this.v_angle.y + (random() * 2 - 1) * shake;
385                                 this.v_angle_x = bound(-90, this.v_angle.x, 90);
386                         }
387
388                         float realdmg = damage - excess;
389                         if (this != attacker && realdmg)
390                         if (!(round_handler_IsActive() && !round_handler_IsRoundStarted()) && time >= game_starttime)
391                         {
392                                 if (IS_PLAYER(attacker) && DIFF_TEAM(attacker, this)) {
393                                         GameRules_scoring_add(attacker, DMG, realdmg);
394                                 }
395                                 if (IS_PLAYER(this)) {
396                                         GameRules_scoring_add(this, DMGTAKEN, realdmg);
397                                 }
398                         }
399                 }
400                 else
401                         this.max_armorvalue += (save + take);
402         }
403         this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
404         this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
405         this.dmg_inflictor = inflictor;
406
407         bool abot = (IS_BOT_CLIENT(attacker));
408         bool vbot = (IS_BOT_CLIENT(this));
409
410         bool valid_damage_for_weaponstats = false;
411         Weapon awep = WEP_Null;
412
413         if (!(round_handler_IsActive() && !round_handler_IsRoundStarted()) && time >= game_starttime)
414         if(vbot || IS_REAL_CLIENT(this))
415         if(abot || IS_REAL_CLIENT(attacker))
416         if(attacker && this != attacker)
417         if(DIFF_TEAM(this, attacker))
418         {
419                 if(DEATH_ISSPECIAL(deathtype))
420                         awep = attacker.(weaponentity).m_weapon;
421                 else
422                         awep = DEATH_WEAPONOF(deathtype);
423                 valid_damage_for_weaponstats = true;
424         }
425
426         dh = dh - max(GetResource(this, RES_HEALTH), 0);
427         da = da - max(GetResource(this, RES_ARMOR), 0);
428         if(valid_damage_for_weaponstats)
429         {
430                 WeaponStats_LogDamage(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot, dh + da);
431         }
432
433         MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype, damage);
434
435         if (GetResource(this, RES_HEALTH) < 1)
436         {
437                 float defer_ClientKill_Now_TeamChange;
438                 defer_ClientKill_Now_TeamChange = false;
439
440                 if(this.alivetime)
441                 {
442                         PlayerStats_GameReport_Event_Player(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
443                         this.alivetime = 0;
444                 }
445
446                 if(valid_damage_for_weaponstats)
447                         WeaponStats_LogKill(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot);
448
449                 if(autocvar_sv_gentle < 1)
450                 if(sound_allowed(MSG_BROADCAST, attacker))
451                 {
452                         if(deathtype == DEATH_DROWN.m_id)
453                                 PlayerSound(this, playersound_drown, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
454                         else
455                                 PlayerSound(this, playersound_death, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
456                 }
457
458                 // get rid of kill indicator
459                 if(this.killindicator)
460                 {
461                         delete(this.killindicator);
462                         this.killindicator = NULL;
463                         if(this.killindicator_teamchange)
464                                 defer_ClientKill_Now_TeamChange = true;
465
466                         if(this.classname == "body")
467                         if(deathtype == DEATH_KILL.m_id)
468                         {
469                                 // for the lemmings fans, a small harmless explosion
470                                 Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
471                         }
472                 }
473
474                 // print an obituary message
475                 if(this.classname != "body")
476                         Obituary(attacker, inflictor, this, deathtype, weaponentity);
477
478                 // increment frag counter for used weapon type
479                 Weapon w = DEATH_WEAPONOF(deathtype);
480                 if(w != WEP_Null && accuracy_isgooddamage(attacker, this))
481                         CS(attacker).accuracy.(accuracy_frags[w.m_id-1]) += 1;
482
483                 this.respawn_time = 0;
484                 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, this, deathtype, damage);
485                 damage = M_ARGV(4, float);
486                 excess = max(0, damage - take - save);
487
488                 //Weapon wep = this.(weaponentity).m_weapon;
489                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
490                 {
491                         .entity went = weaponentities[slot];
492                         if(!this.(went))
493                                 continue; // TODO: clones have no weapon, but we don't want to have to check this all the time
494                         Weapon wep = this.(went).m_weapon;
495                         wep.wr_playerdeath(wep, this, went);
496                 }
497
498                 RemoveGrapplingHooks(this);
499
500                 Portal_ClearAllLater(this);
501
502                 this.fixangle = true;
503
504                 if(defer_ClientKill_Now_TeamChange)
505                         ClientKill_Now_TeamChange(this); // can turn player into spectator
506
507                 // player could have been miraculously resuscitated ;)
508                 // e.g. players in freezetag get frozen, they don't really die
509                 if(GetResource(this, RES_HEALTH) >= 1 || !(IS_PLAYER(this) || this.classname == "body"))
510                         return;
511
512                 if (!this.respawn_time) // can be set in the mutator hook PlayerDies
513                         calculate_player_respawn_time(this);
514
515                 // when we get here, player actually dies
516
517                 Unfreeze(this, false); // remove any icy remains
518
519                 // clear waypoints
520                 WaypointSprite_PlayerDead(this);
521                 // throw a weapon
522                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
523                 {
524                         .entity went = weaponentities[slot];
525                         SpawnThrownWeapon(this, this.origin + (this.mins + this.maxs) * 0.5, this.(went).m_weapon, went);
526                 }
527
528                 // become fully visible
529                 this.alpha = default_player_alpha;
530                 // make the corpse upright (not tilted)
531                 this.angles_x = 0;
532                 this.angles_z = 0;
533                 // don't spin
534                 this.avelocity = '0 0 0';
535                 // view from the floor
536                 this.view_ofs = '0 0 -8';
537                 if(this.move_movetype == MOVETYPE_NOCLIP)
538                 {
539                         // don't toss the corpse in this case, it can get stuck in solid (causing low fps)
540                         // or fall indefinitely into the void if out of the map
541                         this.velocity = '0 0 0';
542                 }
543                 else
544                 {
545                         // toss the corpse
546                         set_movetype(this, MOVETYPE_TOSS);
547                 }
548                 // shootable corpse
549                 this.solid = SOLID_CORPSE;
550                 PS(this).ballistics_density = autocvar_g_ballistics_density_corpse;
551                 // don't stick to the floor
552                 UNSET_ONGROUND(this);
553                 // dying animation
554                 this.deadflag = DEAD_DYING;
555
556                 STAT(MOVEVARS_SPECIALCOMMAND, this) = false; // sweet release
557
558                 this.death_time = time;
559                 if (random() < 0.5)
560                         animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD1, true);
561                 else
562                         animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD2, true);
563
564                 // set damage function to corpse damage
565                 this.event_damage = PlayerCorpseDamage;
566                 this.event_heal = func_null;
567                 // call the corpse damage function just in case it wants to gib
568                 this.event_damage(this, inflictor, attacker, excess, deathtype, weaponentity, hitloc, force);
569
570                 // set up to fade out later
571                 SUB_SetFade (this, time + 6 + random (), 1);
572                 // reset body think wrapper broken by SUB_SetFade
573                 if(this.classname == "body" && getthink(this) != CopyBody_Think) {
574                         this.CopyBody_think = getthink(this);
575                         this.CopyBody_nextthink = this.nextthink;
576                         setthink(this, CopyBody_Think);
577                         this.nextthink = time;
578                 }
579
580                 if(autocvar_sv_gentle > 0 || autocvar_ekg || this.classname == "body") {
581                         // remove corpse
582                         // clones don't run any animation code any more, so we must gib them when they die :(
583                         this.event_damage(this, inflictor, attacker, autocvar_sv_gibhealth + 1, deathtype, weaponentity, hitloc, force);
584                 }
585
586                 // reset fields the weapons may use just in case
587                 if(this.classname != "body")
588                 {
589                         FOREACH(Weapons, it != WEP_Null,
590                         {
591                                 it.wr_resetplayer(it, this);
592                                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
593                                 {
594                                         ATTACK_FINISHED_FOR(this, it.m_id, slot) = 0;
595                                 }
596                         });
597                 }
598                 MUTATOR_CALLHOOK(PlayerDied, this);
599         }
600 }
601
602 bool PlayerHeal(entity targ, entity inflictor, float amount, float limit)
603 {
604         if(GetResource(targ, RES_HEALTH) <= 0 || GetResource(targ, RES_HEALTH) >= limit)
605                 return false;
606
607         GiveResourceWithLimit(targ, RES_HEALTH, amount, limit);
608         return true;
609 }