From bbfd597a80abe209e6fe8c186b9c55fc06a6331b Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Mon, 30 Dec 2002 01:42:36 +0000 Subject: [PATCH] raceptr() Add a routine for returning a ptr to the correct race of monst. Compensates for polyd and non-polyd player. --- include/extern.h | 1 + src/mondata.c | 13 +++++++++++++ src/worn.c | 5 +---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/extern.h b/include/extern.h index 6394878e9..1c2920417 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1167,6 +1167,7 @@ E int FDECL(big_to_little, (int)); E const char *FDECL(locomotion, (const struct permonst *,const char *)); E const char *FDECL(stagger, (const struct permonst *,const char *)); E const char *FDECL(on_fire, (struct permonst *,struct attack *)); +E const struct permonst *FDECL(raceptr, (struct monst *)); /* ### monmove.c ### */ diff --git a/src/mondata.c b/src/mondata.c index 81dbe913e..fd15557a2 100644 --- a/src/mondata.c +++ b/src/mondata.c @@ -616,6 +616,19 @@ int montype; return montype; } +/* + * Return the permonst ptr for the race of the monster. + * Returns correct pointer for non-polymorphed and polymorphed + * player. It does not return a pointer to player role character. + */ +const struct permonst * +raceptr(mtmp) +struct monst *mtmp; +{ + if (mtmp == &youmonst && !Upolyd) return(&mons[urace.malenum]); + else return(mtmp->data); +} + static const char *levitate[4] = { "float", "Float", "wobble", "Wobble" }; static const char *flys[4] = { "fly", "Fly", "flutter", "Flutter" }; static const char *flyl[4] = { "fly", "Fly", "stagger", "Stagger" }; diff --git a/src/worn.c b/src/worn.c index 40693d814..b89f0ddc6 100644 --- a/src/worn.c +++ b/src/worn.c @@ -761,10 +761,7 @@ racial_exception(mon, obj) struct monst *mon; struct obj *obj; { - struct permonst *ptr; - - if (mon == &youmonst && !Upolyd) ptr = &mons[urace.malenum]; - else ptr = mon->data; + const struct permonst *ptr = raceptr(mon); /* Acceptable Exceptions: */ /* Allow hobbits to wear elven armor - LoTR */ -- 2.40.0