From 54cfb8693699c968c9239e284ab6cc5dcb7c1a04 Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 27 Apr 2020 11:48:55 -0700 Subject: [PATCH] fix pull request #340 - untrap steed sanity When a failed #untrap attempt while mounted caused hero to be moved onto the trap, it neglected to set the steed's coordinates to match. If 'sanity_check' was On, that would trigger warnings about steed's anomalous position. Eventually a normal move would put steed's coordinates back in sync with the hero's. The pull request code set u.usteed->{mx,my} directly. I've used u_on_newpos() instead. I also replaced some direct manipulations of u.{ux,uy} with u_on_newpos() so that if clipping is in effect it will be updated. Fixes #340 --- doc/fixes37.0 | 2 ++ src/hack.c | 15 ++++++++++----- src/trap.c | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/fixes37.0 b/doc/fixes37.0 index c8260d6b8..b043ae707 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -164,6 +164,8 @@ some monster code was checking whether pets or engulfers were eating green slime by checking for green slime corpse instead of glob change light radius of stack of candles to square root could get redundate "mon hits other-mon" messages when mon wields an artifact +failed untrap while mounted that moved hero onto the trap would leave steed + with stale coordinates, triggering warnings if 'sanity_check' is On Fixes to 3.7.0-x Problems that Were Exposed Via git Repository diff --git a/src/hack.c b/src/hack.c index fa221844f..b5a92d4b2 100644 --- a/src/hack.c +++ b/src/hack.c @@ -1416,8 +1416,8 @@ domove_core() } if (u.uswallow) { u.dx = u.dy = 0; - u.ux = x = u.ustuck->mx; - u.uy = y = u.ustuck->my; + x = u.ustuck->mx, y = u.ustuck->my; + u_on_newpos(x, y); /* set u.ux,uy and handle CLIPPING */ mtmp = u.ustuck; } else { if (Is_airlevel(&u.uz) && rn2(4) && !Levitation && !Flying) { @@ -1777,15 +1777,15 @@ domove_core() if (!in_out_region(x, y)) return; - /* now move the hero */ mtmp = m_at(x, y); + /* tentaively move the hero plus steed; leave CLIPPING til later */ u.ux += u.dx; u.uy += u.dy; - /* Move your steed, too */ if (u.usteed) { u.usteed->mx = u.ux; u.usteed->my = u.uy; - exercise_steed(); + /* [if move attempt ends up being blocked, should training count?] */ + exercise_steed(); /* train riding skill */ } /* @@ -1911,10 +1911,15 @@ domove_core() if (didnt_move) { u.ux = u.ux0, u.uy = u.uy0; /* didn't move after all */ + /* could skip this bit since we're about to call u_on_newpos() */ if (u.usteed) u.usteed->mx = u.ux, u.usteed->my = u.uy; } } + /* tentative move above didn't handle CLIPPING, in case there was a + monster in the way and the move attempt ended up being blocked; + do a full re-position now, possibly back to where hero started */ + u_on_newpos(u.ux, u.uy); reset_occupations(); if (g.context.run) { diff --git a/src/trap.c b/src/trap.c index c810af652..b94f2c7cd 100644 --- a/src/trap.c +++ b/src/trap.c @@ -4035,7 +4035,8 @@ struct trap *ttmp; if (!Punished || drag_ball(x, y, &bc, &bx, &by, &cx, &cy, &unused, TRUE)) { u.ux0 = u.ux, u.uy0 = u.uy; - u.ux = x, u.uy = y; + /* set u.ux,u.uy and u.usteed->mx,my plus handle CLIPPING */ + u_on_newpos(x, y); u.umoved = TRUE; newsym(u.ux0, u.uy0); vision_recalc(1);