]> granicus.if.org Git - nethack/commitdiff
Differentiate between monster anger from attacks and from other causes
authorAlex Smith <ais523@nethack4.org>
Mon, 17 Oct 2016 17:15:57 +0000 (18:15 +0100)
committerAlex Smith <ais523@nethack4.org>
Mon, 17 Oct 2016 17:19:22 +0000 (18:19 +0100)
setmangry() and wakeup() were being used for multiple purposes. Add an
extra parameter to track which. This fixes several minor bugs (e.g.
whether monsters with no eyes were angered by (useless) gaze attacks
against them previously depended on the state of a UI option, and
the Minetown guards would be annoyed if you used a cursed scroll of
tame monster on a shopkeeper). It's also a prerequisite for the
Elbereth changes I'm working on.

17 files changed:
include/extern.h
src/apply.c
src/dig.c
src/dokick.c
src/dothrow.c
src/explode.c
src/mon.c
src/music.c
src/polyself.c
src/potion.c
src/priest.c
src/read.c
src/region.c
src/trap.c
src/uhitm.c
src/vault.c
src/zap.c

index 0129b888f4d2f28edbb6486b8f32522cec2f82df..300af5e06e1196e2ca3be9cadae46e02a5eed38b 100644 (file)
@@ -1355,8 +1355,8 @@ E void FDECL(mnexto, (struct monst *));
 E void FDECL(maybe_mnexto, (struct monst *));
 E boolean FDECL(mnearto, (struct monst *, XCHAR_P, XCHAR_P, BOOLEAN_P));
 E void FDECL(m_respond, (struct monst *));
-E void FDECL(setmangry, (struct monst *));
-E void FDECL(wakeup, (struct monst *));
+E void FDECL(setmangry, (struct monst *, boolean));
+E void FDECL(wakeup, (struct monst *, boolean));
 E void NDECL(wake_nearby);
 E void FDECL(wake_nearto, (int, int, int));
 E void FDECL(seemimic, (struct monst *));
index 8d64620a85e1aa2c9a2b269b8e2ba98f0863aad8..2e1fb0cf1140ebaa3e7991c3ff2bee44bc2b3ea0 100644 (file)
@@ -2695,7 +2695,7 @@ struct obj *obj;
                 pline1(msg_slipsfree);
             }
             if (mtmp)
-                wakeup(mtmp);
+                wakeup(mtmp, TRUE);
         } else
             pline1(msg_snap);
 
@@ -2789,7 +2789,7 @@ struct obj *obj;
             } else {
                 pline1(msg_slipsfree);
             }
-            wakeup(mtmp);
+            wakeup(mtmp, TRUE);
         } else {
             if (mtmp->m_ap_type && !Protection_from_shape_changers
                 && !sensemon(mtmp))
index 5f45e117e2bd71b439540b252fcf8b304a4af4d5..4407c4c152dc749b2ee7945e61a0ecf910b46c40 100644 (file)
--- a/src/dig.c
+++ b/src/dig.c
@@ -2008,7 +2008,7 @@ struct monst *mtmp;
     }
 
     mtmp->mburied = TRUE;
-    wakeup(mtmp);       /* at least give it a chance :-) */
+    wakeup(mtmp, FALSE);       /* at least give it a chance :-) */
     newsym(mtmp->mx, mtmp->my);
 }
 
index f1e0dcddfdcaaa92f66d702383674caf82b30b47..2cb485472d4beaa98e865edbeffab19fe021f021 100644 (file)
@@ -156,7 +156,7 @@ xchar x, y;
     int i, j;
 
     /* anger target even if wild miss will occur */
-    setmangry(mon);
+    setmangry(mon, TRUE);
 
     if (Levitation && !rn2(3) && verysmall(mon->data)
         && !is_flyer(mon->data)) {
@@ -298,7 +298,7 @@ register struct obj *gold;
 
     if (!likes_gold(mtmp->data) && !mtmp->isshk && !mtmp->ispriest
         && !mtmp->isgd && !is_mercenary(mtmp->data)) {
-        wakeup(mtmp);
+        wakeup(mtmp, TRUE);
     } else if (!mtmp->mcanmove) {
         /* too light to do real damage */
         if (canseemon(mtmp)) {
@@ -312,7 +312,7 @@ register struct obj *gold;
         mtmp->msleeping = 0;
         finish_meating(mtmp);
         if (!mtmp->isgd && !rn2(4)) /* not always pleasing */
-            setmangry(mtmp);
+            setmangry(mtmp, TRUE);
         /* greedy monsters catch gold */
         if (cansee(mtmp->mx, mtmp->my))
             pline("%s catches the gold.", Monnam(mtmp));
index 70496ef7a0369ebfa72985f7dedee3a1ce358fbf..98d41de9ef8e794f42aa567aa85d18c02d9d3253 100644 (file)
@@ -608,7 +608,8 @@ int x, y;
 
     if ((mon = m_at(x, y)) != 0) {
         You("bump into %s.", a_monnam(mon));
-        wakeup(mon);
+        wakeup(mon, FALSE);
+        setmangry(mon, FALSE);
         wake_nearto(x,y, 10);
         return FALSE;
     }
@@ -1346,7 +1347,7 @@ boolean maybe_wakeup;
     else
         miss(missile, mon);
     if (maybe_wakeup && !rn2(3))
-        wakeup(mon);
+        wakeup(mon, TRUE);
     return;
 }
 
@@ -1448,7 +1449,8 @@ register struct obj *obj; /* thrownobj or kickedobj or uwep */
        at leader... (kicked artifact is ok too; HMON_APPLIED could
        occur if quest artifact polearm or grapnel ever gets added) */
     if (hmode != HMON_APPLIED && quest_arti_hits_leader(obj, mon)) {
-        /* not wakeup(), which angers non-tame monsters */
+        /* AIS: changes to wakeup() means that it's now less inappropriate here
+           than it used to be, but the manual version works just as well */
         mon->msleeping = 0;
         mon->mstrategy &= ~STRAT_WAITMASK;
 
@@ -1562,7 +1564,7 @@ register struct obj *obj; /* thrownobj or kickedobj or uwep */
         } else {
             tmiss(obj, mon, TRUE);
             if (hmode == HMON_APPLIED)
-                wakeup(mon);
+                wakeup(mon, TRUE);
         }
 
     } else if (otyp == HEAVY_IRON_BALL) {
@@ -1610,7 +1612,7 @@ register struct obj *obj; /* thrownobj or kickedobj or uwep */
         }
     } else if (guaranteed_hit) {
         /* this assumes that guaranteed_hit is due to swallowing */
-        wakeup(mon);
+        wakeup(mon, TRUE);
         if (obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm])) {
             if (is_animal(u.ustuck->data)) {
                 minstapetrify(u.ustuck, TRUE);
index e6f85866bfe374a762c02f1c4356ee15af21a018..e26e58d8ab80b88f45b996be705d84c9c77d66fa 100644 (file)
@@ -433,7 +433,7 @@ int expltype;
                         monkilled(mtmp, "", (int) adtyp);
                 } else if (!context.mon_moving) {
                     /* all affected monsters, even if mdef is set */
-                    setmangry(mtmp);
+                    setmangry(mtmp, TRUE);
                 }
             }
 
index e31ecb27bb28b7cd7f1a3dc9d40e45726ab41ba2..d0586b200bb567650d712d4f6495959b02b8a1ef 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -2583,10 +2583,18 @@ struct monst *mtmp;
     }
 }
 
+/* Called whenever the player attacks mtmp; also called in other situations
+   where mtmp gets annoyed at the player. Handles mtmp getting annoyed at the
+   attack and any ramifications that might have. Useful also in situations where
+   mtmp was already hostile; it checks for situations where the player shouldn't
+   be attacking and any ramifications /that/ might have. */
 void
-setmangry(mtmp)
+setmangry(mtmp, via_attack)
 struct monst *mtmp;
+boolean via_attack;
 {
+    (void) via_attack; /* AIS: not used yet */
+    /* AIS: Should this be in both places, or just in wakeup()? */
     mtmp->mstrategy &= ~STRAT_WAITMASK;
     if (!mtmp->mpeaceful)
         return;
@@ -2681,14 +2689,16 @@ struct monst *mtmp;
 
 }
 
-/* wake up a monster, usually making it angry in the process */
+/* wake up a monster, possibly making it angry in the process */
 void
-wakeup(mtmp)
+wakeup(mtmp, via_attack)
 register struct monst *mtmp;
+boolean via_attack;
 {
     mtmp->msleeping = 0;
     finish_meating(mtmp);
-    setmangry(mtmp);
+    if (via_attack)
+        setmangry(mtmp, TRUE);
     if (mtmp->m_ap_type) {
         seemimic(mtmp);
     } else if (context.forcefight && !context.mon_moving
index 58cc4b0f0d7a93860956a27592ad9348a0e1402b..75ab39d4d5abf155d5774e545ed7ff823d62e509 100644 (file)
@@ -263,7 +263,7 @@ int force;
     for (x = start_x; x <= end_x; x++)
         for (y = start_y; y <= end_y; y++) {
             if ((mtmp = m_at(x, y)) != 0) {
-                wakeup(mtmp); /* peaceful monster will become hostile */
+                wakeup(mtmp, TRUE); /* peaceful monster will become hostile */
                 if (mtmp->mundetected && is_hider(mtmp->data)) {
                     mtmp->mundetected = 0;
                     if (cansee(x, y))
index 71f9ce8ba2e912c44de6cf4e45fa1d2e54570550..869a37a075edfe4ef3c9d5ed2e8b60464af612ac 100644 (file)
@@ -1310,8 +1310,8 @@ dogaze()
                             mon_nam(mtmp));
                     if (yn(qbuf) != 'y')
                         continue;
-                    setmangry(mtmp);
                 }
+                setmangry(mtmp, TRUE);
                 if (!mtmp->mcanmove || mtmp->mstun || mtmp->msleeping
                     || !mtmp->mcansee || !haseyes(mtmp->data)) {
                     looked--;
index b5971dd79f76c3e9a69b90af05600b840ccbcc01..38f5c655370efe1786c666cf0b4f57abb976b055 100644 (file)
@@ -1488,7 +1488,7 @@ boolean your_fault;
         /* target might have been killed */
         if (mon->mhp > 0) {
             if (angermon)
-                wakeup(mon);
+                wakeup(mon, TRUE);
             else
                 mon->msleeping = 0;
         }
index ec76c91bbe42d043a184ab158a62f11e537a4374..0cce5cf36ffcd36a93d4f46498cd26dff7b520fc 100644 (file)
@@ -795,7 +795,8 @@ angry_priest()
     if ((priest = findpriest(temple_occupied(u.urooms))) != 0) {
         struct epri *eprip = EPRI(priest);
 
-        wakeup(priest);
+        wakeup(priest, FALSE);
+        setmangry(priest, FALSE);
         /*
          * If the altar has been destroyed or converted, let the
          * priest run loose.
index 12e3cc0027bbd394857a05e9cde6af541786e147..efc36e3cb8c7c8fc679422f8b9e7a2c74432bed2 100644 (file)
@@ -901,7 +901,7 @@ struct obj *sobj;
     unsigned was_peaceful = mtmp->mpeaceful;
 
     if (sobj->cursed) {
-        setmangry(mtmp);
+        setmangry(mtmp, FALSE);
         if (was_peaceful && !mtmp->mpeaceful)
             return -1;
     } else {
index 240f7270c92bf357d6c1be19eabf49af5168a102..3ab0317b22f550165b8d5d2d110538562801b83d 100644 (file)
@@ -974,7 +974,7 @@ genericptr_t p2;
             if (cansee(mtmp->mx, mtmp->my))
                 pline("%s coughs!", Monnam(mtmp));
             if (heros_fault(reg))
-                setmangry(mtmp);
+                setmangry(mtmp, TRUE);
             if (haseyes(mtmp->data) && mtmp->mcansee) {
                 mtmp->mblinded = 1;
                 mtmp->mcansee = 0;
index 9e5b2f500577ebeb4268242477fa1fa1093e2bc5..23e26dec3b121ce0074ac535e096c79738f0e0dd 100644 (file)
@@ -2119,7 +2119,7 @@ register struct monst *mtmp;
            Recognizing who made the trap isn't completely
            unreasonable; everybody has their own style. */
         if (trap->madeby_u && rnl(5))
-            setmangry(mtmp);
+            setmangry(mtmp, TRUE);
 
         in_sight = canseemon(mtmp);
         see_it = cansee(mtmp->mx, mtmp->my);
@@ -4541,7 +4541,7 @@ boolean *noticed; /* set to true iff hero notices the effect; */
            or if you sense the monster who becomes trapped */
         *noticed = cansee(t->tx, t->ty) || canspotmon(mon);
         /* monster will be angered; mintrap doesn't handle that */
-        wakeup(mon);
+        wakeup(mon, TRUE);
         ++force_mintrap;
         result = (mintrap(mon) != 0);
         --force_mintrap;
index 832390694d2c93706870f50c4f09519faa8ef08b..a4a31cde0c90b23588e7a43c7296c6c8a10b5b1b 100644 (file)
@@ -145,7 +145,7 @@ struct obj *wep; /* uwep for attack(), null for kick_monster() */
             if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK))
                 u.ustuck = mtmp;
         }
-        wakeup(mtmp); /* always necessary; also un-mimics mimics */
+        wakeup(mtmp, TRUE); /* always necessary; also un-mimics mimics */
         return TRUE;
     }
 
@@ -190,7 +190,7 @@ struct obj *wep; /* uwep for attack(), null for kick_monster() */
      */
     if ((mtmp->mundetected || mtmp->m_ap_type) && sensemon(mtmp)) {
         mtmp->mundetected = 0;
-        wakeup(mtmp);
+        wakeup(mtmp, TRUE);
     }
 
     if (flags.confirm && mtmp->mpeaceful && !Confusion && !Hallucination
@@ -573,7 +573,7 @@ int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */
     unconventional[0] = '\0';
     saved_oname[0] = '\0';
 
-    wakeup(mon);
+    wakeup(mon, TRUE);
     if (!obj) { /* attack with bare hands */
         if (mdat == &mons[PM_SHADE])
             tmp = 0;
@@ -894,7 +894,7 @@ int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */
                             pline("%s %s over %s!", what,
                                   vtense(what, "splash"), whom);
                         }
-                        setmangry(mon);
+                        setmangry(mon, TRUE);
                         mon->mcansee = 0;
                         tmp = rn1(25, 21);
                         if (((int) mon->mblinded + tmp) > 127)
@@ -903,7 +903,7 @@ int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */
                             mon->mblinded += tmp;
                     } else {
                         pline(obj->otyp == CREAM_PIE ? "Splat!" : "Splash!");
-                        setmangry(mon);
+                        setmangry(mon, TRUE);
                     }
                     if (thrown)
                         obfree(obj, (struct obj *) 0);
@@ -2097,7 +2097,7 @@ boolean wouldhavehit;
     else
         You("miss it.");
     if (!mdef->msleeping && mdef->mcanmove)
-        wakeup(mdef);
+        wakeup(mdef, TRUE);
 }
 
 /* attack monster as a monster. */
@@ -2178,7 +2178,7 @@ register struct monst *mon;
                     sum[i] = damageum(mon, mattk);
                     break;
                 }
-                wakeup(mon);
+                wakeup(mon, TRUE);
                 /* maybe this check should be in damageum()? */
                 if (mon->data == &mons[PM_SHADE]
                     && !(mattk->aatyp == AT_KICK && uarmf
@@ -2212,7 +2212,7 @@ register struct monst *mon;
              * already grabbed in a previous attack
              */
             dhit = 1;
-            wakeup(mon);
+            wakeup(mon, TRUE);
             if (mon->data == &mons[PM_SHADE])
                 Your("hug passes harmlessly through %s.", mon_nam(mon));
             else if (!sticks(mon->data) && !u.uswallow) {
@@ -2230,7 +2230,7 @@ register struct monst *mon;
 
         case AT_EXPL: /* automatic hit if next to */
             dhit = -1;
-            wakeup(mon);
+            wakeup(mon, TRUE);
             sum[i] = explum(mon, mattk);
             break;
 
@@ -2238,7 +2238,7 @@ register struct monst *mon;
             tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0,
                                    &attknum, &armorpenalty);
             if ((dhit = (tmp > rnd(20 + i)))) {
-                wakeup(mon);
+                wakeup(mon, TRUE);
                 if (mon->data == &mons[PM_SHADE])
                     Your("attempt to surround %s is harmless.", mon_nam(mon));
                 else {
@@ -2637,7 +2637,7 @@ struct monst *mtmp;
     if (what)
         pline(fmt, what);
 
-    wakeup(mtmp); /* clears mimicking */
+    wakeup(mtmp, FALSE); /* clears mimicking */
     /* if hero is blind, wakeup() won't display the monster even though
        it's no longer concealed */
     if (!canspotmon(mtmp)
@@ -2695,7 +2695,7 @@ struct obj *otmp; /* source of flash */
             }
             if (mtmp->mhp > 0) {
                 if (!context.mon_moving)
-                    setmangry(mtmp);
+                    setmangry(mtmp, TRUE);
                 if (tmp < 9 && !mtmp->isshk && rn2(4))
                     monflee(mtmp, rn2(4) ? rnd(100) : 0, FALSE, TRUE);
                 mtmp->mcansee = 0;
index 909cc3872fcf33cd375e07c3e1d10d2df9feb62e..f076986f5b837340db078f79835956290545578e 100644 (file)
@@ -400,7 +400,7 @@ invault()
                 }
                 mongone(guard);
             } else {
-                setmangry(guard);
+                setmangry(guard, FALSE);
                 if (Deaf) {
                    if (!Blind)
                         pline("%s mouths something and looks very angry!",
index b2df5212f85827137e9d1e01dac38469cc2a32b8..9cf38e0302d9c96e223a483ac5e6498bbf4894a1 100644 (file)
--- a/src/zap.c
+++ b/src/zap.c
@@ -426,7 +426,7 @@ struct obj *otmp;
     }
     if (wake) {
         if (mtmp->mhp > 0) {
-            wakeup(mtmp);
+            wakeup(mtmp, TRUE);
             m_respond(mtmp);
             if (mtmp->isshk && !*u.ushops)
                 hot_pursuit(mtmp);
@@ -4535,12 +4535,9 @@ short exploding_wand_typ;
             You("%s of smoke.", !Blind ? "see a puff" : "smell a whiff");
         }
     if ((mon = m_at(x, y)) != 0) {
-        /* Cannot use wakeup() which also angers the monster */
-        mon->msleeping = 0;
-        if (mon->m_ap_type)
-            seemimic(mon);
+        wakeup(mon, FALSE);
         if (type >= 0) {
-            setmangry(mon);
+            setmangry(mon, TRUE);
             if (mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE))
                 ghod_hitsu(mon);
             if (mon->isshk && !*u.ushops)