From: Pasi Kallinen Date: Sat, 8 Feb 2020 15:35:52 +0000 (+0200) Subject: Unify finding a queen bee X-Git-Tag: NetHack-3.7.0_WIP-2020-02-14~48^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0323eecbfed0dfc1bfa888fd57ef891ad0c8fe54;p=nethack Unify finding a queen bee --- diff --git a/include/extern.h b/include/extern.h index 2e40f60e4..d3b7eab20 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1554,6 +1554,7 @@ E boolean FDECL(monhaskey, (struct monst *, BOOLEAN_P)); E void FDECL(mon_regen, (struct monst *, BOOLEAN_P)); E int FDECL(dochugw, (struct monst *)); E boolean FDECL(onscary, (int, int, struct monst *)); +E struct monst *FDECL(find_pmmonst, (int)); E int FDECL(bee_eat_jelly, (struct monst *, struct obj *)); E void FDECL(monflee, (struct monst *, int, BOOLEAN_P, BOOLEAN_P)); E void FDECL(mon_yells, (struct monst *, const char *)); diff --git a/src/dog.c b/src/dog.c index 5b9cfed69..05f693390 100644 --- a/src/dog.c +++ b/src/dog.c @@ -755,17 +755,10 @@ register struct obj *obj; return POISON; if (obj->otyp == LUMP_OF_ROYAL_JELLY && mon->data == &mons[PM_KILLER_BEE]) { - struct monst *mtmp = 0; + struct monst *mtmp = find_pmmonst(PM_QUEEN_BEE); /* if there's a queen bee on the level, don't eat royal jelly; if there isn't, do eat it and grow into a queen */ - if ((g.mvitals[PM_QUEEN_BEE].mvflags & G_GENOD) == 0) - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) - continue; - if (mtmp->data == &mons[PM_QUEEN_BEE]) - break; - } return !mtmp ? DOGFOOD : TABU; } if (!carni && !herbi) diff --git a/src/monmove.c b/src/monmove.c index 4d18d2850..b58d29303 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -252,6 +252,23 @@ struct monst *mon; } } +struct monst * +find_pmmonst(pm) +int pm; +{ + struct monst *mtmp = 0; + + if ((g.mvitals[pm].mvflags & G_GENOD) == 0) + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->data == &mons[pm]) + break; + } + + return mtmp; +} + /* killer bee 'mon' is on a spot containing lump of royal jelly 'obj' and will eat it if there is no queen bee on the level; return 1: mon died, 0: mon ate jelly and lived; -1: mon didn't eat jelly to use its move */ @@ -261,16 +278,8 @@ struct monst *mon; struct obj *obj; { int m_delay; - struct monst *mtmp = 0; + struct monst *mtmp = find_pmmonst(PM_QUEEN_BEE); - /* find a queen bee */ - if ((g.mvitals[PM_QUEEN_BEE].mvflags & G_GENOD) == 0) - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) - continue; - if (mtmp->data == &mons[PM_QUEEN_BEE]) - break; - } /* if there's no queen on the level, eat the royal jelly and become one */ if (!mtmp) { m_delay = obj->blessed ? 3 : !obj->cursed ? 5 : 7;