From 2a439af3367fdddb096b085cd657ce1cca70dd3c Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 19 Nov 2018 21:49:49 +0200 Subject: [PATCH] More long worm checks when splitting When a long worm is split into two, perform more checks placing the segments on the map. --- include/extern.h | 2 +- src/mon.c | 2 +- src/restore.c | 2 +- src/worm.c | 19 +++++++++++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/extern.h b/include/extern.h index 8fd85e91e..ff0976e18 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2835,7 +2835,7 @@ E void FDECL(see_wsegs, (struct monst *)); E void FDECL(detect_wsegs, (struct monst *, BOOLEAN_P)); E void FDECL(save_worm, (int, int)); E void FDECL(rest_worm, (int)); -E void FDECL(place_wsegs, (struct monst *)); +E void FDECL(place_wsegs, (struct monst *, struct monst *)); E void FDECL(sanity_check_worm, (struct monst *)); E void FDECL(remove_worm, (struct monst *)); E void FDECL(place_worm_tail_randomly, (struct monst *, XCHAR_P, XCHAR_P)); diff --git a/src/mon.c b/src/mon.c index 232992d32..56c5da13f 100644 --- a/src/mon.c +++ b/src/mon.c @@ -1587,7 +1587,7 @@ struct monst *mtmp, *mtmp2; if (mtmp != u.usteed) /* don't place steed onto the map */ place_monster(mtmp2, mtmp2->mx, mtmp2->my); if (mtmp2->wormno) /* update level.monsters[wseg->wx][wseg->wy] */ - place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */ + place_wsegs(mtmp2, NULL); /* locations to mtmp2 not mtmp. */ if (emits_light(mtmp2->data)) { /* since this is so rare, we don't have any `mon_move_light_source' */ new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data), diff --git a/src/restore.c b/src/restore.c index f638875b8..f7a1e6a26 100644 --- a/src/restore.c +++ b/src/restore.c @@ -1080,7 +1080,7 @@ boolean ghostly; set_residency(mtmp, FALSE); place_monster(mtmp, mtmp->mx, mtmp->my); if (mtmp->wormno) - place_wsegs(mtmp); + place_wsegs(mtmp, NULL); /* regenerate monsters while on another level */ if (!u.uz.dlevel) diff --git a/src/worm.c b/src/worm.c index 2a19df288..427ccd04f 100644 --- a/src/worm.c +++ b/src/worm.c @@ -415,7 +415,7 @@ struct obj *weap; wgrowtime[new_wnum] = 0L; /* trying to call initworm(). */ /* Place the new monster at all the segment locations. */ - place_wsegs(new_worm); + place_wsegs(new_worm, worm); if (context.mon_moving) pline("%s is cut in half.", Monnam(worm)); @@ -556,17 +556,28 @@ int fd; * place_wsegs() * * Place the segments of the given worm. Called from restore.c + * If oldworm is not NULL, assumes the oldworm segments are on map + * in the same location as worm segments */ void -place_wsegs(worm) -struct monst *worm; +place_wsegs(worm, oldworm) +struct monst *worm, *oldworm; { struct wseg *curr = wtails[worm->wormno]; /* if (!mtmp->wormno) return; bullet proofing */ while (curr != wheads[worm->wormno]) { - place_worm_seg(worm, curr->wx, curr->wy); + xchar x = curr->wx; + xchar y = curr->wy; + + if (oldworm) { + if (m_at(x,y) == oldworm) + remove_monster(x, y); + else + impossible("placing worm seg <%i,%i> over another mon", x, y); + } + place_worm_seg(worm, x, y); curr = curr->nseg; } }