]> granicus.if.org Git - nethack/commitdiff
more steadfast
authorPatR <rankin@nethack.org>
Wed, 26 Oct 2022 08:13:01 +0000 (01:13 -0700)
committerPatR <rankin@nethack.org>
Wed, 26 Oct 2022 08:13:01 +0000 (01:13 -0700)
Make changes similar to the suggested patch from entrez:  support
for 'youmonst' as the monster passed to m_carrying().  This doesn't
change carrying(otyp) to call m_carrying(&g.youmonst,otyp) though.

Also, treat being on the Plane of Air or in an air bubble on the
Plane of Water similar to flying or levitating:  wielded Giantslayer
(or carried loadstone) doesn't prevent knockback there.

src/invent.c
src/mthrowu.c
src/uhitm.c

index 01794c024bc0cc7d287a8b50430c78af32f25f2f..5b2b8638fb00673a508975bd20c18fd37088a806 100644 (file)
@@ -1285,15 +1285,17 @@ nxtobj(struct obj *obj, int type, boolean by_nexthere)
     return otmp;
 }
 
+/* return inventory object of type 'type' if hero has one, otherwise Null */
 struct obj *
 carrying(int type)
 {
     register struct obj *otmp;
 
+    /* this could be replaced by 'return m_carrying(&g.youmonst, type);' */
     for (otmp = g.invent; otmp; otmp = otmp->nobj)
         if (otmp->otyp == type)
-            return  otmp;
-    return (struct obj *) 0;
+            break;
+    return otmp;
 }
 
 /* Fictional and not-so-fictional currencies.
index d595e37edb28c187c04614eca31b0634e1ec27c7..7805095284a961ffaef4c630191c9607544c3bec 100644 (file)
@@ -1182,22 +1182,23 @@ lined_up(register struct monst* mtmp)
     return m_lined_up(&g.youmonst, mtmp) ? TRUE : FALSE;
 }
 
-/* check if a monster is carrying a particular item */
+/* check if a monster is carrying an item of a particular type */
 struct obj *
-m_carrying(struct monstmtmp, int type)
+m_carrying(struct monst *mtmp, int type)
 {
     register struct obj *otmp;
 
-    for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
+    for (otmp = (mtmp == &g.youmonst) ? g.invent : mtmp->minvent; otmp;
+         otmp = otmp->nobj)
         if (otmp->otyp == type)
-            return otmp;
-    return (struct obj *) 0;
+            break;
+    return otmp;
 }
 
 void
 hit_bars(
     struct obj **objp,    /* *objp will be set to NULL if object breaks */
-    coordxy objx, coordxy objy,   /* hero's spot (when wielded) or missile's spot */
+    coordxy objx, coordxy objy, /* hero's (when wielded) or missile's spot */
     coordxy barsx, coordxy barsy, /* adjacent spot where bars are located */
     unsigned breakflags)  /* breakage control */
 {
index b34797dbff75bbd9e8375b528c0c084b2dba9c33..f5db387c25e0177f31581b36b35d938f3fbdcf01 100644 (file)
@@ -4611,26 +4611,29 @@ missum(
         wakeup(mdef, TRUE);
 }
 
+/* check whether equipment protects against knockback */
 static boolean
 m_is_steadfast(struct monst *mtmp)
 {
     boolean is_u = (mtmp == &g.youmonst);
     struct obj *otmp = is_u ? uwep : MON_WEP(mtmp);
 
-    /* must be on the ground */
-    if (is_u ? (Flying || Levitation)
-             : (is_flyer(mtmp->data) || is_floater(mtmp->data)))
+    /* must be on the ground (or in water) */
+    if ((is_u ? (Flying || Levitation)
+              : (is_flyer(mtmp->data) || is_floater(mtmp->data)))
+        || Is_airlevel(&u.uz) /* air or cloud */
+        || (Is_waterlevel(&u.uz) && !is_pool(u.ux, u.uy))) /* air bubble */
         return FALSE;
 
     if (is_art(otmp, ART_GIANTSLAYER))
         return TRUE;
 
     /* steadfast if carrying any loadstone (and not floating or flying);
-       when mounted and steed is target of knockback, check the rider
-       for a loadstone too */
-    for (otmp = is_u ? g.invent : mtmp->minvent; otmp; otmp = otmp->nobj)
-        if (otmp->otyp == LOADSTONE)
-            return TRUE;
+       'is_u' test not needed here; m_carrying() is 'youmonst' aware */
+    if (m_carrying(mtmp, LOADSTONE))
+        return TRUE;
+    /* when mounted and steed is target of knockback, check the rider for
+       a loadstone too (Giantslayer's protection doesn't extend to steed) */
     if (u.usteed && mtmp == u.usteed && carrying(LOADSTONE))
         return TRUE;