]> granicus.if.org Git - nethack/commitdiff
check_leash's handling of 2nd leash
authornethack.rankin <nethack.rankin>
Tue, 24 Sep 2002 02:11:10 +0000 (02:11 +0000)
committernethack.rankin <nethack.rankin>
Tue, 24 Sep 2002 02:11:10 +0000 (02:11 +0000)
     Noticed by code inspection:  the inventory scan to find leashes
in use didn't reset the monster traversal loop for each leash, so
with more than one active it wouldn't necessarily find and check the
monster attached to the second one.

doc/fixes34.1
src/apply.c

index 314757db014fce5b50236f836bebacde6bc43bfa..c7a87b5bda41497b77b31c913cb875525700f45a 100644 (file)
@@ -254,6 +254,7 @@ show correct gender in ^X display when polymorphed into non-humanoid form
 for wizard and explore modes, skip second screen of ^X output when first
        screen is cancelled by ESC
 polyself into minotaur causes hard headgear to fall off
+with multiple leashes in use, 2nd had 50/50 chance of having unbounded length
 
 
 Platform- and/or Interface-Specific Fixes
index 39c8ce5b694243f82e39e91b768ba6f375eb3714..0a5ba9dfe2e18068010d8f6a89e4b810e03c889c 100644 (file)
@@ -530,44 +530,44 @@ check_leash(x, y)
 register xchar x, y;
 {
        register struct obj *otmp;
-       register struct monst *mtmp = fmon;
+       register struct monst *mtmp;
 
-       for(otmp = invent; otmp; otmp = otmp->nobj)
-           if(otmp->otyp == LEASH && otmp->leashmon != 0) {
-               while(mtmp) {
-                   if(!DEADMONSTER(mtmp) && ((int)mtmp->m_id == otmp->leashmon &&
-                           (dist2(u.ux,u.uy,mtmp->mx,mtmp->my) >
-                               dist2(x,y,mtmp->mx,mtmp->my)))
-                       ) {
-                       if(otmp->cursed && !breathless(mtmp->data)) {
-                           if(um_dist(mtmp->mx, mtmp->my, 5)) {
-                               pline("%s chokes to death!",Monnam(mtmp));
-                               mondied(mtmp);
-                           } else
-                               if(um_dist(mtmp->mx, mtmp->my, 3))
-                                       pline("%s chokes on the leash!",
-                                               Monnam(mtmp));
-                       } else {
-                           if(um_dist(mtmp->mx, mtmp->my, 5)) {
-                               pline("%s leash snaps loose!",
-                                       s_suffix(Monnam(mtmp)));
-                               m_unleash(mtmp, FALSE);
-                           } else {
-                               if(um_dist(mtmp->mx, mtmp->my, 3)) {
-                                   You("pull on the leash.");
-                                   if (mtmp->data->msound != MS_SILENT)
-                                       switch(rn2(3)) {
-                                           case 0:  growl(mtmp);       break;
-                                           case 1:  yelp(mtmp);        break;
-                                           default: whimper(mtmp); break;
-                                       }
-                               }
+       for (otmp = invent; otmp; otmp = otmp->nobj) {
+           if (otmp->otyp != LEASH || otmp->leashmon == 0) continue;
+           for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
+               if (DEADMONSTER(mtmp)) continue;
+               if ((int)mtmp->m_id == otmp->leashmon) break; 
+           }
+           if (!mtmp) {
+               impossible("leash in use isn't attached to anything?");
+               otmp->leashmon = 0;
+               continue;
+           }
+           if (dist2(u.ux,u.uy,mtmp->mx,mtmp->my) >
+                   dist2(x,y,mtmp->mx,mtmp->my)) {
+               if (otmp->cursed && !breathless(mtmp->data)) {
+                   if (um_dist(mtmp->mx, mtmp->my, 5)) {
+                       pline("%s chokes to death!", Monnam(mtmp));
+                       mondied(mtmp);
+                   } else if (um_dist(mtmp->mx, mtmp->my, 3)) {
+                       pline("%s chokes on the leash!", Monnam(mtmp));
+                   }
+               } else {
+                   if (um_dist(mtmp->mx, mtmp->my, 5)) {
+                       pline("%s leash snaps loose!", s_suffix(Monnam(mtmp)));
+                       m_unleash(mtmp, FALSE);
+                   } else if (um_dist(mtmp->mx, mtmp->my, 3)) {
+                       You("pull on the leash.");
+                       if (mtmp->data->msound != MS_SILENT)
+                           switch (rn2(3)) {
+                           case 0:  growl(mtmp);   break;
+                           case 1:  yelp(mtmp);    break;
+                           default: whimper(mtmp); break;
                            }
-                       }
                    }
-                   mtmp = mtmp->nmon;
                }
            }
+       }
 }
 
 #endif /* OVL0 */