]> granicus.if.org Git - nethack/commitdiff
Remove urace test from is_elf, etc, macros
authorMichael Meyer <me@entrez.cc>
Thu, 27 Oct 2022 02:07:04 +0000 (22:07 -0400)
committerMichael Meyer <me@entrez.cc>
Thu, 27 Oct 2022 13:53:33 +0000 (09:53 -0400)
Reverts 690e072, which changed the various is_foo macros from this:

| #define is_elf(ptr) ((((ptr)->mflags2 & M2_ELF) != 0L)

to this:

| #define is_elf(ptr) ((((ptr)->mflags2 & M2_ELF) != 0L)     \
|                      || ((ptr) == g.youmonst.data &&       \
|                          !Upolyd && Race_if(PM_ELF)))

This is a problem because g.youmonst.data is not unique to the hero:
the '(ptr) == g.youmonst.data' test will also be true of all player
monsters of the same role.  For this reason, any of those player
monsters will be treated as sharing the hero's race, producing strange
results.  For example, if the player is an elven ranger, any ranger
player monster generated will be considered 'elven' too (so will get a
to-hit bonus when attacking orcs, etc) -- but only while the hero is
unpolymorphed.

There are already other ways of checking the hero's race in addition to
her current polyform, most notably the maybe_polyd() macro.  maybe_polyd
or something similar is already used in nearly all the cases where the
hero's race is being evaluated, meaning Race_if gets used instead when
the hero is in her natural form.  So I think the check of the hero's
race in is_foo had very little effect except for the unintended
side-effects on player monsters.

In reviewing all the uses of is_{elf,dwarf,gnome,orc,human}, I noticed
only one case that relied on the hero-race-checking behavior.  That has
been changed in this commit to use maybe_polyd (there's another 'raw'
is_human(g.youmonst.data) a few lines down, but it doesn't need
maybe_polyd since it already distinguishes between 'hero in nonhuman
polyform' vs 'nonpolyd or human polyform').  same_race(mondata.c) is
another case where &g.youmonst.data can be passed to is_foo, but
everywhere that calls it for the hero also calls your_race() or
same_race(&mons[Race_switch]) to handle the racial case.

include/mondata.h
src/shk.c

index 14825bc29f94eb20a7a8a82064420ce249c39ec8..8a6d564d4a70bad99689123b030c0c9987f7a4fd 100644 (file)
 #define is_shapeshifter(ptr) (((ptr)->mflags2 & M2_SHAPESHIFTER) != 0L)
 #define is_undead(ptr) (((ptr)->mflags2 & M2_UNDEAD) != 0L)
 #define is_were(ptr) (((ptr)->mflags2 & M2_WERE) != 0L)
-#define is_elf(ptr) ((((ptr)->mflags2 & M2_ELF) != 0L)     \
-                     || ((ptr) == g.youmonst.data &&       \
-                         !Upolyd && Race_if(PM_ELF)))
-#define is_dwarf(ptr) ((((ptr)->mflags2 & M2_DWARF) != 0L) \
-                     || ((ptr) == g.youmonst.data &&       \
-                         !Upolyd && Race_if(PM_DWARF)))
-#define is_gnome(ptr) ((((ptr)->mflags2 & M2_GNOME) != 0L) \
-                     || ((ptr) == g.youmonst.data &&       \
-                         !Upolyd && Race_if(PM_GNOME)))
-#define is_orc(ptr) ((((ptr)->mflags2 & M2_ORC) != 0L)     \
-                     || ((ptr) == g.youmonst.data &&       \
-                         !Upolyd && Race_if(PM_ORC)))
-#define is_human(ptr) ((((ptr)->mflags2 & M2_HUMAN) != 0L) \
-                     || ((ptr) == g.youmonst.data &&       \
-                         !Upolyd && Race_if(PM_HUMAN)))
+#define is_elf(ptr) (((ptr)->mflags2 & M2_ELF) != 0L)
+#define is_dwarf(ptr) (((ptr)->mflags2 & M2_DWARF) != 0L)
+#define is_gnome(ptr) (((ptr)->mflags2 & M2_GNOME) != 0L)
+#define is_orc(ptr) (((ptr)->mflags2 & M2_ORC) != 0L)
+#define is_human(ptr) (((ptr)->mflags2 & M2_HUMAN) != 0L)
 #define your_race(ptr) (((ptr)->mflags2 & g.urace.selfmask) != 0L)
 #define is_bat(ptr)                                         \
     ((ptr) == &mons[PM_BAT] || (ptr) == &mons[PM_GIANT_BAT] \
index 40d965e75d37965c2568c567e309e0a13727a2f2..c9000842ffd50d8f9cf319fdfcb819c83c3ca578 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -2761,12 +2761,12 @@ append_honorific(char *buf)
     Strcat(buf, honored[rn2(SIZE(honored) - 1) + u.uevent.udemigod]);
     if (is_vampire(g.youmonst.data))
         Strcat(buf, (flags.female) ? " dark lady" : " dark lord");
-    else if (is_elf(g.youmonst.data))
+    else if (maybe_polyd(is_elf(g.youmonst.data), Race_if(PM_ELF)))
         Strcat(buf, (flags.female) ? " hiril" : " hir");
     else
         Strcat(buf, !is_human(g.youmonst.data) ? " creature"
-                                             : (flags.female) ? " lady"
-                                                              : " sir");
+                      : (flags.female) ? " lady"
+                        : " sir");
 }
 
 void