]> granicus.if.org Git - nethack/commitdiff
split displaying trap map into separate function
authorSHIRAKATA Kentaro <argrath@ub32.org>
Sun, 8 May 2022 11:32:27 +0000 (20:32 +0900)
committerPatR <rankin@nethack.org>
Tue, 28 Jun 2022 19:39:38 +0000 (12:39 -0700)
src/detect.c

index 39a92b79e36860fc7a7b312f287d7a3131617102..cbd5f1dec32d1297f8b7806fbc209974916176e3 100644 (file)
@@ -21,6 +21,7 @@ static boolean check_map_spot(int, int, char, unsigned);
 static boolean clear_stale_map(char, unsigned);
 static void sense_trap(struct trap *, xchar, xchar, int);
 static int detect_obj_traps(struct obj *, boolean, int);
+static void display_trap_map(struct trap *, int);
 static int furniture_detect(void);
 static void show_map_spot(int, int);
 static void findone(int, int, genericptr_t);
@@ -908,6 +909,54 @@ detect_obj_traps(
     return result;
 }
 
+static void
+display_trap_map(struct trap *ttmp, int cursed_src)
+{
+    struct monst *mon;
+    int door, glyph, ter_typ = TER_DETECT | TER_TRP;
+    coord cc;
+
+    cls();
+
+    (void) unconstrain_map();
+    /* show chest traps first, so that subsequent floor trap display
+       will override if both types are present at the same location */
+    (void) detect_obj_traps(fobj, TRUE, cursed_src);
+    (void) detect_obj_traps(g.level.buriedobjlist, TRUE, cursed_src);
+    for (mon = fmon; mon; mon = mon->nmon) {
+        if (DEADMONSTER(mon) || (mon->isgd && !mon->mx))
+            continue;
+        (void) detect_obj_traps(mon->minvent, TRUE, cursed_src);
+    }
+    (void) detect_obj_traps(g.invent, TRUE, cursed_src);
+
+    for (ttmp = g.ftrap; ttmp; ttmp = ttmp->ntrap)
+        sense_trap(ttmp, 0, 0, cursed_src);
+
+    dummytrap.ttyp = TRAPPED_DOOR;
+    for (door = 0; door < g.doorindex; door++) {
+        cc = g.doors[door];
+        if (levl[cc.x][cc.y].typ == SDOOR) /* see above */
+            continue;
+        if (levl[cc.x][cc.y].doormask & D_TRAPPED) {
+            dummytrap.tx = cc.x, dummytrap.ty = cc.y;
+            sense_trap(&dummytrap, cc.x, cc.y, cursed_src);
+        }
+    }
+
+    /* redisplay hero unless sense_trap() revealed something at <ux,uy> */
+    glyph = glyph_at(u.ux, u.uy);
+    if (!(glyph_is_trap(glyph) || glyph_is_object(glyph))) {
+        newsym(u.ux, u.uy);
+        ter_typ |= TER_MON; /* for autodescribe at <u.ux,u.uy> */
+    }
+    You_feel("%s.", cursed_src ? "very greedy" : "entrapped");
+
+    browse_map(ter_typ, "trap of interest");
+
+    map_redisplay();
+}
+
 /* the detections are pulled out so they can
  * also be used in the crystal ball routine
  * returns 1 if nothing was detected
@@ -919,7 +968,7 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
 {
     register struct trap *ttmp;
     struct monst *mon;
-    int door, glyph, tr, ter_typ = TER_DETECT | TER_TRP;
+    int door, tr;
     int cursed_src = sobj && sobj->cursed;
     boolean found = FALSE;
     coord cc;
@@ -929,32 +978,36 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
 
     /* floor/ceiling traps */
     for (ttmp = g.ftrap; ttmp; ttmp = ttmp->ntrap) {
-        if (ttmp->tx != u.ux || ttmp->ty != u.uy)
-            goto outtrapmap;
-        else
+        if (ttmp->tx != u.ux || ttmp->ty != u.uy) {
+            display_trap_map(ttmp, cursed_src);
+            return 0;
+        } else
             found = TRUE;
     }
     /* chest traps (might be buried or carried) */
     if ((tr = detect_obj_traps(fobj, FALSE, 0)) != OTRAP_NONE) {
-        if (tr & OTRAP_THERE)
-            goto outtrapmap;
-        else
+        if (tr & OTRAP_THERE) {
+            display_trap_map(ttmp, cursed_src);
+            return 0;
+        } else
             found = TRUE;
     }
     if ((tr = detect_obj_traps(g.level.buriedobjlist, FALSE, 0))
         != OTRAP_NONE) {
-        if (tr & OTRAP_THERE)
-            goto outtrapmap;
-        else
+        if (tr & OTRAP_THERE) {
+            display_trap_map(ttmp, cursed_src);
+            return 0;
+        } else
             found = TRUE;
     }
     for (mon = fmon; mon; mon = mon->nmon) {
         if (DEADMONSTER(mon) || (mon->isgd && !mon->mx))
             continue;
         if ((tr = detect_obj_traps(mon->minvent, FALSE, 0)) != OTRAP_NONE) {
-            if (tr & OTRAP_THERE)
-                goto outtrapmap;
-            else
+            if (tr & OTRAP_THERE) {
+                display_trap_map(ttmp, cursed_src);
+                return 0;
+            } else
                 found = TRUE;
         }
     }
@@ -969,9 +1022,10 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
         if (levl[cc.x][cc.y].typ == SDOOR)
             continue;
         if (levl[cc.x][cc.y].doormask & D_TRAPPED) {
-            if (cc.x != u.ux || cc.y != u.uy)
-                goto outtrapmap;
-            else
+            if (cc.x != u.ux || cc.y != u.uy) {
+                display_trap_map(ttmp, cursed_src);
+                return 0;
+            } else
                 found = TRUE;
         }
     }
@@ -985,48 +1039,6 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
     /* traps exist, but only under me - no separate display required */
     Your("%s itch.", makeplural(body_part(TOE)));
     return 0;
-
- outtrapmap:
-    cls();
-
-    (void) unconstrain_map();
-    /* show chest traps first, so that subsequent floor trap display
-       will override if both types are present at the same location */
-    (void) detect_obj_traps(fobj, TRUE, cursed_src);
-    (void) detect_obj_traps(g.level.buriedobjlist, TRUE, cursed_src);
-    for (mon = fmon; mon; mon = mon->nmon) {
-        if (DEADMONSTER(mon) || (mon->isgd && !mon->mx))
-            continue;
-        (void) detect_obj_traps(mon->minvent, TRUE, cursed_src);
-    }
-    (void) detect_obj_traps(g.invent, TRUE, cursed_src);
-
-    for (ttmp = g.ftrap; ttmp; ttmp = ttmp->ntrap)
-        sense_trap(ttmp, 0, 0, cursed_src);
-
-    dummytrap.ttyp = TRAPPED_DOOR;
-    for (door = 0; door < g.doorindex; door++) {
-        cc = g.doors[door];
-        if (levl[cc.x][cc.y].typ == SDOOR) /* see above */
-            continue;
-        if (levl[cc.x][cc.y].doormask & D_TRAPPED) {
-            dummytrap.tx = cc.x, dummytrap.ty = cc.y;
-            sense_trap(&dummytrap, cc.x, cc.y, cursed_src);
-        }
-    }
-
-    /* redisplay hero unless sense_trap() revealed something at <ux,uy> */
-    glyph = glyph_at(u.ux, u.uy);
-    if (!(glyph_is_trap(glyph) || glyph_is_object(glyph))) {
-        newsym(u.ux, u.uy);
-        ter_typ |= TER_MON; /* for autodescribe at <u.ux,u.uy> */
-    }
-    You_feel("%s.", cursed_src ? "very greedy" : "entrapped");
-
-    browse_map(ter_typ, "trap of interest");
-
-    map_redisplay();
-    return 0;
 }
 
 static int