Skip to content

Commit

Permalink
Align player kill count attribution with PrBoom+
Browse files Browse the repository at this point in the history
This change breaks savegame compatibility by pulling in lastenemy field
from Boom.
  • Loading branch information
dirkd committed Nov 18, 2021
1 parent 3e3fe6b commit db100ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/doom/p_inter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions src/doom/p_mobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions src/doom/p_mobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ typedef struct mobj_s
fixed_t oldz;
angle_t oldangle;

// last known enemy
struct mobj_s* lastenemy;

} mobj_t;


Expand Down

0 comments on commit db100ff

Please sign in to comment.