]> granicus.if.org Git - nethack/commitdiff
Split stuck-cannot-go-up/down into separate function
authorPasi Kallinen <paxed@alt.org>
Sun, 5 Mar 2023 09:58:23 +0000 (11:58 +0200)
committerPasi Kallinen <paxed@alt.org>
Sun, 5 Mar 2023 09:58:23 +0000 (11:58 +0200)
src/do.c

index f668751cf5c330b8e5987a353b439e6b2c65b0ab..fc9e1b96702896f2ce5d852e389f82fc6d142482 100644 (file)
--- a/src/do.c
+++ b/src/do.c
@@ -16,6 +16,7 @@ static boolean engulfer_digests_food(struct obj *);
 static boolean danger_uprops(void);
 static int wipeoff(void);
 static int menu_drop(int);
+static boolean u_stuck_cannot_go(const char *);
 static NHFILE *currentlevel_rewrite(void);
 static void familiar_level_msg(void);
 static void final_level(void);
@@ -1019,6 +1020,26 @@ menu_drop(int retry)
     return (n_dropped ? ECMD_TIME : ECMD_OK);
 }
 
+static boolean
+u_stuck_cannot_go(const char *updn)
+{
+    if (u.ustuck) {
+        if (u.uswallow || !sticks(gy.youmonst.data)) {
+            You("are %s, and cannot go %s.",
+                !u.uswallow ? "being held"
+                : digests(u.ustuck->data) ? "swallowed"
+                : "engulfed", updn);
+            return TRUE;
+        } else {
+            struct monst *mtmp = u.ustuck;
+
+            set_ustuck((struct monst *) 0);
+            You("release %s.", mon_nam(mtmp));
+        }
+    }
+    return FALSE;
+}
+
 /* the #down command */
 int
 dodown(void)
@@ -1103,20 +1124,8 @@ dodown(void)
         return ECMD_TIME; /* came out of hiding; need '>' again to go down */
     }
 
-    if (u.ustuck) {
-        if (u.uswallow || !sticks(gy.youmonst.data)) {
-            You("are %s, and cannot go down.",
-                !u.uswallow ? "being held"
-                : digests(u.ustuck->data) ? "swallowed"
-                  : "engulfed");
-            return ECMD_TIME;
-        } else {
-            struct monst *mtmp = u.ustuck;
-
-            set_ustuck((struct monst *) 0);
-            You("release %s.", mon_nam(mtmp));
-        }
-    }
+    if (u_stuck_cannot_go("down"))
+        return ECMD_TIME;
 
     if (!stairs_down && !ladder_down) {
         trap = t_at(u.ux, u.uy);
@@ -1213,20 +1222,10 @@ doup(void)
     if (stucksteed(TRUE)) {
         return ECMD_OK;
     }
-    if (u.ustuck) {
-        if (u.uswallow || !sticks(gy.youmonst.data)) {
-            You("are %s, and cannot go up.",
-                !u.uswallow ? "being held"
-                : digests(u.ustuck->data) ? "swallowed"
-                  : "engulfed");
-            return ECMD_TIME;
-        } else {
-            struct monst *mtmp = u.ustuck;
 
-            set_ustuck((struct monst *) 0);
-            You("release %s.", mon_nam(mtmp));
-        }
-    }
+    if (u_stuck_cannot_go("up"))
+        return ECMD_TIME;
+
     if (near_capacity() > SLT_ENCUMBER) {
         /* No levitation check; inv_weight() already allows for it */
         Your("load is too heavy to climb the %s.",