diff -uwr nethack-3.4.3/src/worm.c nethack-long-worm-fix-C343-324/src/worm.c --- nethack-3.4.3/src/worm.c 2003-12-08 00:39:13.000000000 +0100 +++ nethack-long-worm-fix-C343-324/src/worm.c 2008-10-26 15:24:55.000000000 +0100 @@ -303,6 +303,23 @@ (void) mattacku(worm); } +/* cutoff() + * + * Remove the tail of a worm and adjust the hp of the worm. + */ +void +cutoff(worm, tail) + struct monst *worm; + struct wseg *tail; +{ + if (flags.mon_moving) + pline("Part of the tail of %s is cut off.", mon_nam(worm)); + else + You("cut part of the tail off of %s.", mon_nam(worm)); + toss_wsegs(tail, TRUE); + if (worm->mhp > 1) worm->mhp /= 2; +} + /* cutworm() * * Check for mon->wormno before calling this function! @@ -368,17 +385,15 @@ /* Sometimes the tail end dies. */ if (rn2(3) || !(new_wnum = get_wormno())) { - if (flags.mon_moving) - pline("Part of the tail of %s is cut off.", mon_nam(worm)); - else - You("cut part of the tail off of %s.", mon_nam(worm)); - toss_wsegs(new_tail, TRUE); - if (worm->mhp > 1) worm->mhp /= 2; + cutoff(worm, new_tail); return; } remove_monster(x, y); /* clone_mon puts new head here */ - new_worm = clone_mon(worm, x, y); + if (!(new_worm = clone_mon(worm, x, y))) { + cutoff(worm, new_tail); + return; + } new_worm->wormno = new_wnum; /* affix new worm number */ /* Devalue the monster level of both halves of the worm. */