diff --git a/doc/fixes34.1 b/doc/fixes34.1 index 314757db0..c7a87b5bd 100644 --- a/doc/fixes34.1 +++ b/doc/fixes34.1 @@ -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 diff --git a/src/apply.c b/src/apply.c index 39c8ce5b6..0a5ba9dfe 100644 --- a/src/apply.c +++ b/src/apply.c @@ -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 */