From 3e3fe6be6df324ed1aa3562d814afe2e19c857d6 Mon Sep 17 00:00:00 2001 From: Dirk D Date: Thu, 18 Nov 2021 01:34:04 +0100 Subject: [PATCH 1/2] Attribute infighting kills to a player in netgames --- src/doom/p_inter.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/doom/p_inter.c b/src/doom/p_inter.c index 15e0729827..801175db8b 100644 --- a/src/doom/p_inter.c +++ b/src/doom/p_inter.c @@ -742,11 +742,29 @@ P_KillMobj if (target->player) source->player->frags[target->player-players]++; } - else if (!netgame && (target->flags & MF_COUNTKILL) ) + else if (target->flags & MF_COUNTKILL) { // count all monster deaths, // even those caused by other monsters - players[0].killcount++; + if (!netgame) + { + players[0].killcount++; + } + else // netgame + { + if (!deathmatch) + { + // add kill to first player who is still ingame + for (unsigned int plridx = 0; plridx < MAXPLAYERS; plridx++) + { + if (playeringame[plridx]) + { + players[plridx].killcount++; + break; + } + } + } + } } if (target->player) From db100ff79d57c5871744b196e172e8a99acdab4f Mon Sep 17 00:00:00 2001 From: Dirk D Date: Thu, 18 Nov 2021 01:40:59 +0100 Subject: [PATCH 2/2] Align player kill count attribution with PrBoom+ This change breaks savegame compatibility by pulling in lastenemy field from Boom. --- src/doom/p_inter.c | 21 ++++++++++++++++----- src/doom/p_mobj.c | 2 ++ src/doom/p_mobj.h | 3 +++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/doom/p_inter.c b/src/doom/p_inter.c index 801175db8b..cbc1968a78 100644 --- a/src/doom/p_inter.c +++ b/src/doom/p_inter.c @@ -754,13 +754,20 @@ P_KillMobj { if (!deathmatch) { - // add kill to first player who is still ingame - for (unsigned int plridx = 0; plridx < MAXPLAYERS; plridx++) + if (target->lastenemy && target->lastenemy->health > 0 && target->lastenemy->player) { - if (playeringame[plridx]) + target->lastenemy->player->killcount++; + } + else + { + // add kill to first player who is still ingame + for (unsigned int plridx = 0; plridx < MAXPLAYERS; plridx++) { - players[plridx].killcount++; - break; + if (playeringame[plridx]) + { + players[plridx].killcount++; + break; + } } } } @@ -994,6 +1001,10 @@ P_DamageMobj { // if not intent on another player, // chase after this one + if ( !target->lastenemy || target->lastenemy->health <= 0 + || !target->lastenemy->player) + target->lastenemy = target->target; + target->target = source; target->threshold = BASETHRESHOLD; if (target->state == &states[target->info->spawnstate] diff --git a/src/doom/p_mobj.c b/src/doom/p_mobj.c index 53a1d600d6..f3cf95b653 100644 --- a/src/doom/p_mobj.c +++ b/src/doom/p_mobj.c @@ -680,6 +680,8 @@ P_SpawnMobjSafe mobj->oldz = mobj->z; mobj->oldangle = mobj->angle; + mobj->lastenemy = NULL; + // [crispy] height of the spawnstate's first sprite in pixels if (!info->actualheight) { diff --git a/src/doom/p_mobj.h b/src/doom/p_mobj.h index 87f1a25113..e00929829b 100644 --- a/src/doom/p_mobj.h +++ b/src/doom/p_mobj.h @@ -293,6 +293,9 @@ typedef struct mobj_s fixed_t oldz; angle_t oldangle; + // last known enemy + struct mobj_s* lastenemy; + } mobj_t;