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