]> granicus.if.org Git - nethack/commitdiff
Unify file removed -trickery
authorPasi Kallinen <paxed@alt.org>
Wed, 22 Apr 2015 05:45:03 +0000 (08:45 +0300)
committerPasi Kallinen <paxed@alt.org>
Wed, 22 Apr 2015 05:45:03 +0000 (08:45 +0300)
include/extern.h
src/do.c
src/save.c

index fe22f97e46782504400ebf3351f01228c3b1e3dc..406ae8c13e7d4222cd97d1db347cb75a2b017d33 100644 (file)
@@ -1981,6 +1981,7 @@ E void NDECL(rumor_check);
 
 E int NDECL(dosave);
 E int NDECL(dosave0);
+E boolean FDECL(tricked_fileremoved, (int, char *));
 #ifdef INSURANCE
 E void NDECL(savestateinlock);
 #endif
index ae941c065e04310e1719295555a9bb2bd5c71396..03edbb6f1e76ac8ecbcddac6d66d252e943bf4df 100644 (file)
--- a/src/do.c
+++ b/src/do.c
@@ -1225,11 +1225,7 @@ boolean at_stairs, falling, portal;
     } else {
         /* returning to previously visited level; reload it */
         fd = open_levelfile(new_ledger, whynot);
-        if (fd < 0) {
-            pline1(whynot);
-            pline("Probably someone removed it.");
-            Strcpy(killer.name, whynot);
-            done(TRICKED);
+        if (tricked_fileremoved(fd, whynot)) {
             /* we'll reach here if running in wizard mode */
             error("Cannot continue this game.");
         }
index ed00476987251885f545d13efd525705a2dc1bbb..fb695d1ed305bfe1c1e5091ffe7b84152ce9b97d 100644 (file)
@@ -360,6 +360,21 @@ register int fd, mode;
        bflush(fd);
 }
 
+boolean
+tricked_fileremoved(fd, whynot)
+int fd;
+char *whynot;
+{
+    if (fd < 0) {
+       pline1(whynot);
+       pline("Probably someone removed it.");
+       Strcpy(killer.name, whynot);
+       done(TRICKED);
+       return TRUE;
+    }
+    return FALSE;
+}
+
 #ifdef INSURANCE
 void
 savestateinlock()
@@ -387,13 +402,7 @@ savestateinlock()
                 * readable by an external utility
                 */
                fd = open_levelfile(0, whynot);
-               if (fd < 0) {
-                   pline1(whynot);
-                   pline("Probably someone removed it.");
-                   Strcpy(killer.name, whynot);
-                   done(TRICKED);
-                   return;
-               }
+               if (tricked_fileremoved(fd, whynot)) return;
 
                (void) read(fd, (genericptr_t) &hpid, sizeof(hpid));
                if (hackpid != hpid) {