]> granicus.if.org Git - nethack/commitdiff
fix put request #377 - worm mismanagement
authorPatR <rankin@nethack.org>
Fri, 7 Aug 2020 23:05:11 +0000 (16:05 -0700)
committerPatR <rankin@nethack.org>
Fri, 7 Aug 2020 23:05:11 +0000 (16:05 -0700)
An earlier change resulted in place_worm_tail_randomly() sometimes
removing a long worm from the map unintentionally.  It was still on
the monster list so if wizard mode sanity_check option was On, there
would be warnings of a monster which isn't on the map.

The change which triggered this was necessary so I'm inclined to
blame place_worm_tail_randomly() laziness.

This is a superset of the pull request's fix.

Fixes #377

doc/fixes37.0
src/worm.c

index 857c26fcec0612c209e70e71f97d860a8371414b..b5f63675cc4aded8801f74222e8f361bd6858f68 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.276 $ $NHDT-Date: 1596785361 2020/08/07 07:29:21 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.277 $ $NHDT-Date: 1596841504 2020/08/07 23:05:04 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -313,6 +313,11 @@ some versions of tiles processing (not X11's) complained about the rename of
        "{acid,blinding} venom" to "splash of {acid,blinding} venom"
 wizard mode #timeout changed to show timed Displacement in 'can be timed in
        normal play' section instead of 'timed via #wizintrinsic only' section
+the fix to make worm visibility checks work as intended forced the coordinates
+       of the extra tail segment co-located with the worm monster to match
+       the worm instead of leaving it off the map; place_worm_tail_randomly()
+       reverses the segments and can throw some away if there isn't room,
+       but throwing away the extra segment removed the worm from the map
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index 7deb90cb6128286eebd983c05ce992216fb8fb35..c32c8c928ab3e4a04a14372341f8bd7bba893d35 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 worm.c  $NHDT-Date: 1596498230 2020/08/03 23:43:50 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.46 $ */
+/* NetHack 3.7 worm.c  $NHDT-Date: 1596841504 2020/08/07 23:05:04 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.47 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2009. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -727,6 +727,18 @@ xchar x, y;
         impossible("place_worm_tail_randomly: wormno is set without a tail!");
         return;
     }
+    if (wtails[wnum] == wheads[wnum]) {
+        /* single segment, co-located with worm so nothing to place */
+        if (curr->wx != worm->mx || curr->wy != worm->my)
+            impossible(
+        "place_worm_tail_randomly: tail segement at <%d,%d>, worm at <%d,%d>",
+                       curr->wx, curr->wy, worm->mx, worm->my);
+        return;
+    }
+    /* remove head segment from map in case we end up calling toss_wsegs();
+       if it doesn't get tossed, it will become the final tail segment and
+       get new coordinates */
+    wheads[wnum]->wx = wheads[wnum]->wy = 0;
 
     wheads[wnum] = new_tail = curr;
     curr = curr->nseg;
@@ -736,7 +748,7 @@ xchar x, y;
 
     while (curr) {
         xchar nx, ny;
-        char tryct = 0;
+        int tryct = 0;
 
         /* pick a random direction from x, y and search for goodpos() */
         do {