]> granicus.if.org Git - nethack/commitdiff
Unify finding a queen bee
authorPasi Kallinen <paxed@alt.org>
Sat, 8 Feb 2020 15:35:52 +0000 (17:35 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 8 Feb 2020 15:35:52 +0000 (17:35 +0200)
include/extern.h
src/dog.c
src/monmove.c

index 2e40f60e4c1a9204ef380b090618460e5c21a12b..d3b7eab2026a1c4cf9db98c18e185df18abebd4b 100644 (file)
@@ -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 *));
index 5b9cfed69716c7922c7a0f6f562ec9217b35590b..05f69339010a7dbbab7f81ec33f1cf1fea36cd04 100644 (file)
--- 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)
index 4d18d2850451e42709c75ba6c19b0442f63ee1f2..b58d293035fd47540ae5ae3bea6ff1bc79061753 100644 (file)
@@ -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;