]> granicus.if.org Git - nethack/commitdiff
Detection map redisplay routine code deduplication
authorPasi Kallinen <paxed@alt.org>
Tue, 8 Dec 2020 15:08:57 +0000 (17:08 +0200)
committerPasi Kallinen <paxed@alt.org>
Tue, 8 Dec 2020 15:08:57 +0000 (17:08 +0200)
src/detect.c

index 575082e20eb51fb98eede951d36b60c16bc17dab..4bf7e0a0bb40a45da73e885f7500bb60ba11ad05 100644 (file)
@@ -13,6 +13,7 @@
 
 static boolean NDECL(unconstrain_map);
 static void NDECL(reconstrain_map);
+static void NDECL(map_redisplay);
 static void FDECL(browse_map, (int, const char *));
 static void FDECL(map_monst, (struct monst *, BOOLEAN_P));
 static void FDECL(do_dknown_of, (struct obj *));
@@ -52,6 +53,17 @@ reconstrain_map()
     u.uswallow = iflags.save_uswallow, iflags.save_uswallow = 0;
 }
 
+static void
+map_redisplay()
+{
+    reconstrain_map();
+    docrt(); /* redraw the screen to remove unseen traps from the map */
+    if (Underwater)
+        under_water(2);
+    if (u.uburied)
+        under_ground(2);
+}
+
 /* use getpos()'s 'autodescribe' to view whatever is currently shown on map */
 static void
 browse_map(ter_typ, ter_explain)
@@ -440,12 +452,7 @@ register struct obj *sobj;
 
     browse_map(ter_typ, "gold");
 
-    reconstrain_map();
-    docrt();
-    if (Underwater)
-        under_water(2);
-    if (u.uburied)
-        under_ground(2);
+    map_redisplay();
     return 0;
 }
 
@@ -564,12 +571,7 @@ register struct obj *sobj;
 
         browse_map(ter_typ, "food");
 
-        reconstrain_map();
-        docrt();
-        if (Underwater)
-            under_water(2);
-        if (u.uburied)
-            under_ground(2);
+        map_redisplay();
     }
     return 0;
 }
@@ -765,12 +767,7 @@ int class;            /* an object class, 0 for all */
     else
         browse_map(ter_typ, "object");
 
-    reconstrain_map();
-    docrt(); /* this will correctly reset vision */
-    if (Underwater)
-        under_water(2);
-    if (u.uburied)
-        under_ground(2);
+    map_redisplay();
     return 0;
 }
 
@@ -844,12 +841,7 @@ int mclass;                /* monster class, 0 for all */
             EDetect_monsters &= ~I_SPECIAL;
         }
 
-        reconstrain_map();
-        docrt(); /* redraw the screen to remove unseen monsters from map */
-        if (Underwater)
-            under_water(2);
-        if (u.uburied)
-            under_ground(2);
+        map_redisplay();
     }
     return 0;
 }
@@ -1032,12 +1024,7 @@ struct obj *sobj; /* null if crystal ball, *scroll if gold detection scroll */
 
     browse_map(ter_typ, "trap of interest");
 
-    reconstrain_map();
-    docrt(); /* redraw the screen to remove unseen traps from the map */
-    if (Underwater)
-        under_water(2);
-    if (u.uburied)
-        under_ground(2);
+    map_redisplay();
     return 0;
 }
 
@@ -1082,12 +1069,7 @@ furniture_detect()
         browse_map(TER_DETECT | TER_MAP | TER_TRP | TER_OBJ | TER_MON,
                    "location");
 
-    reconstrain_map();
-    docrt(); /* redraw everything */
-    if (Underwater)
-        under_water(2);
-    if (u.uburied)
-        under_ground(2);
+    map_redisplay();
     return 0;
 }
 
@@ -2108,12 +2090,7 @@ int which_subset; /* when not full, whether to suppress objs and/or traps */
         which_subset |= TER_MAP; /* guarantee non-zero */
         browse_map(which_subset, "anything of interest");
 
-        reconstrain_map();
-        docrt(); /* redraw the screen, restoring regular map */
-        if (Underwater)
-            under_water(2);
-        if (u.uburied)
-            under_ground(2);
+        map_redisplay();
     }
     return;
 }