Skip to content

Commit

Permalink
Fix: archfiends generated in bones weren't tracked properly
Browse files Browse the repository at this point in the history
From a github report, Geryon was loaded in a bones file, and
subsequently killing him did not get rid of his debuff during the
ascension run. The underlying cause is that the num_in_dgn counter did
not tick up when an archfiend was loaded from a bones file, which
subsequently caused the counter to underflow to UINT_MAX when they were
killed. Since that number is greater than 0, fiend_adversity concluded
they were still active in the dungeon.

Fix that problem, and also add a bounds check to guard against the
underflow by printing an impossible if for some reason num_in_dgn
attempts to decrement when already at 0.

Fixes #213
  • Loading branch information
copperwater committed Sep 14, 2024
1 parent 534d723 commit 920681a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2867,7 +2867,12 @@ m_detach(
}
if (is_archfiend(mtmp->data)) {
struct fiend_info *fiend = lookup_fiend(monsndx(mtmp->data));
fiend->num_in_dgn--;
if (fiend->num_in_dgn == 0) {
impossible("already 0 of this archfiend?");
}
else {
fiend->num_in_dgn--;
}
}

if (mtmp->m_id == gs.stealmid)
Expand Down
6 changes: 6 additions & 0 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,12 @@ getlev(NHFILE *nhfp, int pid, xint8 lev)
== sgn(mtmp->data->maligntyp))) ? 1
: peace_minded(mtmp->data);
set_malign(mtmp);
/* archfiends that newly exist in the game due to this bones file
* need to be counted */
if (is_archfiend(mtmp->data)) {
struct fiend_info *fnd = lookup_fiend(monsndx(mtmp->data));
fnd->num_in_dgn++;
}
} else if (elapsed > 0L) {
mon_catchup_elapsed_time(mtmp, elapsed);
}
Expand Down

0 comments on commit 920681a

Please sign in to comment.