]> granicus.if.org Git - nethack/commitdiff
is_elf(), is_dwarf(), is_gnome(), is_orc(), is_human()
authornhmall <nhmall@nethack.org>
Thu, 6 Feb 2020 17:09:24 +0000 (12:09 -0500)
committernhmall <nhmall@nethack.org>
Thu, 6 Feb 2020 17:09:24 +0000 (12:09 -0500)
Those tests were only checking the permonst mflags2 field
so anytime those tests were used in the code, they came
up false for things like an elven ranger. An elven ranger
should return true for an is_elf() test, as an example.

That happens because the profession monsters in monst.c
are defined with M2_HUMAN.

This augments those is_*() race tests to also check for a
matching player race as well.

include/mondata.h

index e84a09272f71d297c51d52a89e4f1b0d5378413b..65ad58eca1a39dfc0c7e6eef6420a6e41dabf072 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)
-#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 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 your_race(ptr) (((ptr)->mflags2 & g.urace.selfmask) != 0L)
 #define is_bat(ptr)                                         \
     ((ptr) == &mons[PM_BAT] || (ptr) == &mons[PM_GIANT_BAT] \