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