From 992f141ab764cf1bf074af9dfb12bd9792fb26f2 Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 14 Jan 2019 09:28:10 -0800 Subject: [PATCH] \#wizmakemap followup Both u_on_rndspot() and losedogs() might result in having a monster and the hero be at the same location. Have wiz_makemap() use the same fixup for that as goto_level(). --- include/extern.h | 3 ++- src/cmd.c | 7 ++++- src/do.c | 66 ++++++++++++++++++++++++++++-------------------- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/include/extern.h b/include/extern.h index 9a2be9e11..dd27db8aa 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 extern.h $NHDT-Date: 1546687295 2019/01/05 11:21:35 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.681 $ */ +/* NetHack 3.6 extern.h $NHDT-Date: 1547486885 2019/01/14 17:28:05 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.682 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -384,6 +384,7 @@ E int NDECL(doup); #ifdef INSURANCE E void NDECL(save_currentstate); #endif +E void FDECL(u_collide_m, (struct monst *)); E void FDECL(goto_level, (d_level *, BOOLEAN_P, BOOLEAN_P, BOOLEAN_P)); E void FDECL(schedule_goto, (d_level *, BOOLEAN_P, BOOLEAN_P, int, const char *, const char *)); diff --git a/src/cmd.c b/src/cmd.c index 39e34cc77..0d9e284b1 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 cmd.c $NHDT-Date: 1547421842 2019/01/13 23:24:02 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.326 $ */ +/* NetHack 3.6 cmd.c $NHDT-Date: 1547486885 2019/01/14 17:28:05 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.327 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2013. */ /* NetHack may be freely redistributed. See license for details. */ @@ -857,6 +857,11 @@ wiz_makemap(VOID_ARGS) u_on_rndspot((u.uhave.amulet ? 1 : 0) /* 'going up' flag */ | (In_W_tower(u.ux, u.uy, &u.uz) ? 2 : 0)); losedogs(); + /* u_on_rndspot() might pick a spot that has a monster, or losedogs() + might pick the hero's spot (only if there isn't already a monster + there), so we might have to move hero or the co-located monster */ + if ((mtmp = m_at(u.ux, u.uy)) != 0 && mtmp != u.usteed) + u_collide_m(mtmp); initrack(); if (Punished) { unplacebc(); diff --git a/src/do.c b/src/do.c index 53d0c60ae..346b77adb 100644 --- a/src/do.c +++ b/src/do.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do.c $NHDT-Date: 1547086513 2019/01/10 02:15:13 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.183 $ */ +/* NetHack 3.6 do.c $NHDT-Date: 1547486886 2019/01/14 17:28:06 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.184 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1157,6 +1157,39 @@ register xchar x, y; } */ +/* extracted from goto_level(); also used by wiz_makemap() */ +void +u_collide_m(mtmp) +struct monst *mtmp; +{ + coord cc; + + if (!mtmp || mtmp->mx != u.ux || mtmp->my != u.uy) + return; + + /* There's a monster at your target destination; it might be one + which accompanied you--see mon_arrive(dogmove.c)--or perhaps + it was already here. Randomly move you to an adjacent spot + or else the monster to any nearby location. Prior to 3.3.0 + the latter was done unconditionally. */ + if (!rn2(2) && enexto(&cc, u.ux, u.uy, youmonst.data) + && distu(cc.x, cc.y) <= 2) + u_on_newpos(cc.x, cc.y); /*[maybe give message here?]*/ + else + mnexto(mtmp); + + if ((mtmp = m_at(u.ux, u.uy)) != 0) { + /* there was an unconditional impossible("mnearto failed") + here, but it's not impossible and we're prepared to cope + with the situation, so only say something when debugging */ + if (wizard) + pline("(monster in hero's way)"); + if (!rloc(mtmp, TRUE) || (mtmp = m_at(u.ux, u.uy)) != 0) + /* no room to move it; send it away, to return later */ + m_into_limbo(mtmp); + } +} + void goto_level(newlevel, at_stairs, falling, portal) d_level *newlevel; @@ -1445,34 +1478,13 @@ boolean at_stairs, falling, portal; */ run_timers(); + /* hero might be arriving at a spot containing a monster; + if so, move one or the other to another location */ + if ((mtmp = m_at(u.ux, u.uy)) != 0 && mtmp != u.usteed) + u_collide_m(mtmp); + initrack(); - if ((mtmp = m_at(u.ux, u.uy)) != 0 && mtmp != u.usteed) { - /* There's a monster at your target destination; it might be one - which accompanied you--see mon_arrive(dogmove.c)--or perhaps - it was already here. Randomly move you to an adjacent spot - or else the monster to any nearby location. Prior to 3.3.0 - the latter was done unconditionally. */ - coord cc; - - if (!rn2(2) && enexto(&cc, u.ux, u.uy, youmonst.data) - && distu(cc.x, cc.y) <= 2) - u_on_newpos(cc.x, cc.y); /*[maybe give message here?]*/ - else - mnexto(mtmp); - - if ((mtmp = m_at(u.ux, u.uy)) != 0) { - /* there was an unconditional impossible("mnearto failed") - here, but it's not impossible and we're prepared to cope - with the situation, so only say something when debugging */ - if (wizard) - pline("(monster in hero's way)"); - if (!rloc(mtmp, TRUE) || (mtmp = m_at(u.ux, u.uy)) != 0) - /* no room to move it; send it away, to return later */ - m_into_limbo(mtmp); - } - } - /* initial movement of bubbles just before vision_recalc */ if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) movebubbles();