]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'terencehill/damage_for_suicide' into 'master'
authorterencehill <piuntn@gmail.com>
Mon, 31 May 2021 12:21:37 +0000 (12:21 +0000)
committerterencehill <piuntn@gmail.com>
Mon, 31 May 2021 12:21:37 +0000 (12:21 +0000)
Count damage caused by suicide (with the kill command) as damage taken

See merge request xonotic/xonotic-data.pk3dir!911

qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc
qcsrc/common/gamemodes/gamemode/race/sv_race.qc
qcsrc/server/damage.qc
qcsrc/server/mutators/events.qh
qcsrc/server/player.qc

index 458465faaa260587a60563407fa72630d228c21e..45457d1a4d8adb895ea40b39e4ad89b458d2b495 100644 (file)
@@ -235,6 +235,13 @@ MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
        }
 }
 
+MUTATOR_HOOKFUNCTION(cts, PlayerDamaged)
+{
+       int frag_deathtype = M_ARGV(5, int);
+       if (frag_deathtype == DEATH_KILL.m_id)
+               return true; // forbid logging damage
+}
+
 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
 {
        entity frag_target = M_ARGV(2, entity);
index ecfd3660588cf91275a71f079d9994aa1bf1ab0f..0ffda17a96407171e9e1cbada4d045894a80ba3b 100644 (file)
@@ -285,6 +285,13 @@ MUTATOR_HOOKFUNCTION(rc, PutClientInServer)
        }
 }
 
+MUTATOR_HOOKFUNCTION(rc, PlayerDamaged)
+{
+       int frag_deathtype = M_ARGV(5, int);
+       if (frag_deathtype == DEATH_KILL.m_id)
+               return true; // forbid logging damage
+}
+
 MUTATOR_HOOKFUNCTION(rc, PlayerDies)
 {
        entity frag_target = M_ARGV(2, entity);
index 7e052de046ebbbd5f93dc6ef2f071b306f85623f..83252c00d86676ff4f9bf951e17c29e8d5da987d 100644 (file)
@@ -611,9 +611,12 @@ void Damage(entity targ, entity inflictor, entity attacker, float damage, int de
                // These are ALWAYS lethal
                // No damage modification here
                // Instead, prepare the victim for his death...
-               SetResourceExplicit(targ, RES_ARMOR, 0);
+               if(deathtype == DEATH_TEAMCHANGE.m_id || deathtype == DEATH_AUTOTEAMCHANGE.m_id)
+               {
+                       SetResourceExplicit(targ, RES_ARMOR, 0);
+                       SetResourceExplicit(targ, RES_HEALTH, 0.9); // this is < 1
+               }
                targ.spawnshieldtime = 0;
-               SetResourceExplicit(targ, RES_HEALTH, 0.9); // this is < 1
                targ.flags -= targ.flags & FL_GODMODE;
                damage = 100000;
        }
index 35a8f6fd93b7f31900f8d8eb8341815c99f69e65..c4521e824f3a7a9d57ce58df35494fcf3dbb8fa2 100644 (file)
@@ -449,6 +449,7 @@ MUTATOR_HOOKABLE(Damage_Calculate, EV_Damage_Calculate);
 
 /**
  * Called when a player is damaged
+ * Returns true if damage shouldn't be logged
  */
 #define EV_PlayerDamaged(i, o) \
     /** attacker  */ i(entity, MUTATOR_ARGV_0_entity) \
index 0a7dd86cb32aec451ec87a824473248507aff0f3..1d83be8d1b74288a2e2e6b2ee201262d617484c6 100644 (file)
@@ -387,18 +387,6 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage,
                                this.v_angle_y = this.v_angle.y + (random() * 2 - 1) * shake;
                                this.v_angle_x = bound(-90, this.v_angle.x, 90);
                        }
-
-                       float realdmg = damage - excess;
-                       if (this != attacker && realdmg && !STAT(FROZEN, this)
-                               && (!(round_handler_IsActive() && !round_handler_IsRoundStarted()) && time >= game_starttime))
-                       {
-                               if (IS_PLAYER(attacker) && DIFF_TEAM(attacker, this)) {
-                                       GameRules_scoring_add(attacker, DMG, realdmg);
-                               }
-                               if (IS_PLAYER(this)) {
-                                       GameRules_scoring_add(this, DMGTAKEN, realdmg);
-                               }
-                       }
                }
                else
                        this.max_armorvalue += (save + take);
@@ -433,7 +421,20 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage,
                WeaponStats_LogDamage(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot, dh + da);
        }
 
-       MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype, damage);
+       bool forbid_logging_damage = MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype, damage);
+
+       if ((dh || da) && !forbid_logging_damage)
+       {
+               float realdmg = damage - excess;
+               if ((this != attacker || deathtype == DEATH_KILL.m_id) && realdmg && !STAT(FROZEN, this)
+                       && (!(round_handler_IsActive() && !round_handler_IsRoundStarted()) && time >= game_starttime))
+               {
+                       if (IS_PLAYER(attacker) && DIFF_TEAM(attacker, this) && deathtype != DEATH_KILL.m_id)
+                               GameRules_scoring_add(attacker, DMG, realdmg);
+                       if (IS_PLAYER(this))
+                               GameRules_scoring_add(this, DMGTAKEN, realdmg);
+               }
+       }
 
        if (GetResource(this, RES_HEALTH) < 1)
        {