]> granicus.if.org Git - nethack/commitdiff
fix #K3857 - hiding while trapped in a non-pit
authorPatR <rankin@nethack.org>
Fri, 3 Feb 2023 18:45:59 +0000 (10:45 -0800)
committerPatR <rankin@nethack.org>
Fri, 3 Feb 2023 18:45:59 +0000 (10:45 -0800)
sanity_check feedback which occurred after using locking magic to
set off a bear trap at the location of a monster hiding under an
object.

Trivial bit: a recent change made stunning via knockback only occur
when not already stunned but was still adding the current stun time
to the new stun time even though current stun is now always zero.

Several formatting bits included.

src/mon.c
src/trap.c
src/uhitm.c

index cd898fb8cee6e7f8354354725aaf92bb714751cb..39e30fce7b0a5d8b2ab6a92d6dabd6e05b633325 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -161,8 +161,7 @@ sanity_check_single_mon(
                        !has_ceiling(&u.uz) ? "without ceiling"
                                            : "in solid stone",
                        msg);
-        if (mtmp->mtrapped && (t = t_at(mx, my)) != 0
-            && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))
+        if (mtmp->mtrapped && (t = t_at(mx, my)) != 0 && !is_pit(t->ttyp))
             impossible("hiding while trapped in a non-pit (%s)", msg);
     } else if (M_AP_TYPE(mtmp) != M_AP_NOTHING) {
         boolean is_mimic = (mptr->mlet == S_MIMIC);
@@ -4115,7 +4114,7 @@ maybe_unhide_at(coordxy x, coordxy y)
     if ((mtmp = m_at(x, y)) == 0 && u_at(x, y))
         mtmp = &gy.youmonst;
     if (mtmp && mtmp->mundetected
-        && ((hides_under(mtmp->data) && !OBJ_AT(x, y))
+        && ((hides_under(mtmp->data) && (!OBJ_AT(x, y) || mtmp->mtrapped))
             || (mtmp->data->mlet == S_EEL && !is_pool(x, y))))
         (void) hideunder(mtmp);
 }
@@ -4129,11 +4128,11 @@ hideunder(struct monst *mtmp)
     coordxy x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my;
 
     if (mtmp == u.ustuck) {
-        ; /* can't hide if holding you or held by you */
+        ; /* undetected==FALSE; can't hide if holding you or held by you */
     } else if (is_u ? (u.utrap && u.utraptype != TT_PIT)
-                    : (mtmp->mtrapped && (t = t_at(x, y)) != 0
-                       && !is_pit(t->ttyp))) {
-        ; /* can't hide while stuck in a non-pit trap */
+                    : (mtmp->mtrapped
+                       && (t = t_at(x, y)) != 0 && !is_pit(t->ttyp))) {
+        ; /* undetected==FALSE; can't hide while stuck in a non-pit trap */
     } else if (mtmp->data->mlet == S_EEL) {
         undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz));
     } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) {
@@ -4200,7 +4199,8 @@ mon_animal_list(boolean construct)
         /* if (n == 0) animal_temp[n++] = NON_PM; */
 
         ga.animal_list = (short *) alloc(n * sizeof *ga.animal_list);
-        (void) memcpy((genericptr_t) ga.animal_list, (genericptr_t) animal_temp,
+        (void) memcpy((genericptr_t) ga.animal_list,
+                      (genericptr_t) animal_temp,
                       n * sizeof *ga.animal_list);
         ga.animal_list_count = n;
     } else { /* release */
index 0ebc185881986c40b292544f8352251046ed93b0..648e498b88c2a8ce5c1a449db66be47bf8d84b29 100644 (file)
@@ -1097,7 +1097,8 @@ trapeffect_dart_trap(
             otmp->opoisoned = 1;
         if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) {
             ; /* nothing */
-        } else if (thitu(7, dmgval(otmp, &gy.youmonst), &otmp, "little dart")) {
+        } else if (thitu(7, dmgval(otmp, &gy.youmonst),
+                         &otmp, "little dart")) {
             if (otmp) {
                 if (otmp->opoisoned)
                     poisoned("dart", A_CON, "little dart",
@@ -1716,10 +1717,10 @@ trapeffect_pit(
                        plunged
                        ? "deliberately plunged into a pit of iron spikes"
                        : (conj_pit || deliberate)
-                       ? "stepped into a pit of iron spikes"
-                       : adj_pit
-                       ? "stumbled into a pit of iron spikes"
-                       : "fell into a pit of iron spikes",
+                         ? "stepped into a pit of iron spikes"
+                         : adj_pit
+                           ? "stumbled into a pit of iron spikes"
+                           : "fell into a pit of iron spikes",
                        NO_KILLER_PREFIX);
                 if (!rn2(6))
                     poisoned("spikes", A_STR,
@@ -2650,7 +2651,7 @@ choose_trapnote(struct trap *ttmp)
 }
 
 static int
-steedintrap(struct trap* trap, struct obj* otmp)
+steedintrap(struct trap *trap, struct obj *otmp)
 {
     struct monst *steed = u.usteed;
     int tt;
@@ -3306,9 +3307,9 @@ mintrap(struct monst *mtmp, unsigned mintrapflags)
                                 || (tt == HOLE && !mindless(mptr)));
 
         if (mtmp == u.usteed) {
-            /* true when called from dotrap, inescapable is not an option */
+            /* true when called from dotrap, inescapable is not an option */
         } else if (Sokoban && (is_pit(tt) || is_hole(tt)) && !trap->madeby_u) {
-            /* nothing here, the trap effects will handle messaging */
+            /* nothing here, the trap effects will handle messaging */
         } else if (!forcetrap) {
             if (floor_trigger(tt) && check_in_air(mtmp, mintrapflags)) {
                 return Trap_Effect_Finished;
@@ -3327,6 +3328,18 @@ mintrap(struct monst *mtmp, unsigned mintrapflags)
             setmangry(mtmp, FALSE);
 
         trap_result = trapeffect_selector(mtmp, trap, mintrapflags);
+
+        /* mtmp can't stay hiding under an object if trapped in non-pit
+           (mtmp hiding under object at armed bear trap loccation, hero
+           zaps wand of locking or spell of wizard lock at spot triggering
+           the trap and trapping mtmp there) */
+        if (!DEADMONSTER(mtmp) && mtmp->mtrapped) {
+            boolean alreadyspotted = canspotmon(mtmp);
+
+            maybe_unhide_at(mtmp->mx, mtmp->my);
+            if (!alreadyspotted && canseemon(mtmp))
+                pline("%s appears.", Amonnam(mtmp));
+        }
     }
     return trap_result;
 }
index 7c3ef2f4c3b9b0f176af31e49b7f7c8ae94ad077..d3c9ae26c56ed8ed396a02deb65fab8bd17639ed 100644 (file)
@@ -4884,7 +4884,7 @@ mhitm_knockback(
 
         set_apparxy(magr); /* update magr's idea of where you are */
         if (!Stunned && !rn2(4))
-            make_stunned((HStun & TIMEOUT) + (long) rnd(2) + 1L, TRUE);
+            make_stunned((long) rn1(2, 2), TRUE); /* 0..1 + 2 => 2..3 */
     } else {
         coordxy x = u_agr ? u.ux : magr->mx;
         coordxy y = u_agr ? u.uy : magr->my;