Skip to content

Commit

Permalink
Fix: mon_hates_material and player race
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
entrez authored and copperwater committed Mar 21, 2024
1 parent b0884a0 commit 014a61a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
6 changes: 3 additions & 3 deletions src/mondata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 014a61a

Please sign in to comment.