From 014a61aa8023ee78f09931dfe354d599e0e3d064 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Wed, 13 Dec 2023 12:08:23 -0500 Subject: [PATCH] Fix: mon_hates_material and player race mon_hates_material(mondata.c) was not evaluating the hero's race correctly due to upstream changes in 580c5a6, which removed the attempt to assess the hero's race from is_elf, is_dwarf, etc macros (for reasons described in that commit message). However, mon_hates_material was just passing gy.permonst.data to hates_material and relying on those macros to include the hero's race in the equation, so it was no longer working properly for an unpolymorphed hero after those changes. Make it explicitly check material hatred of the hero's race if not polymorphed. I had to remove the 'const' qualifier on raceptr to use it here, because keeping it would have led to a cascading requirement to add 'const' on all sorts of other functions (hates_material -> dmgtype -> dmgtype_fromattack...) -- and those really _should_ have const parameters, but I think that would have to be an upstream change to avoid risking a bunch of merge conflicts in subsequent merges. --- include/extern.h | 2 +- src/mondata.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/extern.h b/include/extern.h index e5787c77f..cdc6907a6 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1770,7 +1770,7 @@ extern const char *locomotion(const struct permonst *, const char *); extern const char *stagger(const struct permonst *, const char *); extern const char *on_fire(struct permonst *, struct attack *); extern const char *msummon_environ(struct permonst *, const char **); -extern const struct permonst *raceptr(struct monst *); +extern struct permonst *raceptr(struct monst *); extern boolean olfaction(struct permonst *); extern int monmaterial(int); extern int emits_light(struct permonst *); diff --git a/src/mondata.c b/src/mondata.c index c54f0e79c..cd818291c 100644 --- a/src/mondata.c +++ b/src/mondata.c @@ -458,7 +458,7 @@ mstrength_ranged_attk(register struct permonst* ptr) boolean mon_hates_material(struct monst *mon, int material) { - if (hates_material(mon->data, material)) + if (hates_material(raceptr(mon), material)) return TRUE; /* extra case: shapeshifted vampires still hate silver */ @@ -1367,8 +1367,8 @@ big_little_match(int montyp1, int montyp2) * Returns correct pointer for non-polymorphed and polymorphed * player. It does not return a pointer to player role character. */ -const struct permonst * -raceptr(struct monst* mtmp) +struct permonst * +raceptr(struct monst *mtmp) { if (mtmp == &gy.youmonst && !Upolyd) return &mons[gu.urace.mnum];