Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kill count in cooperative netgames #784

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/doom/p_inter.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,36 @@ 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)
{
if (target->lastenemy && target->lastenemy->health > 0 && target->lastenemy->player)
{
target->lastenemy->player->killcount++;
}
else
{
// 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)
Expand Down Expand Up @@ -976,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