From: PatR Date: Fri, 3 Feb 2023 18:45:59 +0000 (-0800) Subject: fix #K3857 - hiding while trapped in a non-pit X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e6ea3faed9adad387bc396850921a5a25971ef7;p=nethack fix #K3857 - hiding while trapped in a non-pit 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. --- diff --git a/src/mon.c b/src/mon.c index cd898fb8c..39e30fce7 100644 --- 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 */ diff --git a/src/trap.c b/src/trap.c index 0ebc18588..648e498b8 100644 --- a/src/trap.c +++ b/src/trap.c @@ -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; } diff --git a/src/uhitm.c b/src/uhitm.c index 7c3ef2f4c..d3c9ae26c 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -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;