From 0c70b1bd0613a301223cc09fa4b6d21f7d30c2d6 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 28 May 2016 19:54:19 -0700 Subject: [PATCH] reset travel cache when changing levels When travel fails to reach its destination, it remembers the target spot to use as default next time. But that spot is only meaningful on the current level. Discard last travel destination when moving to a different level. Also, discard unlocking context when changing level unless the context is for a container being brought along (after having been picked up since you can't unlock a carried box). Previously, a door pointer on the new level could happen to match the last one being unlocked on the old level. Discard trap setting context when changing level even if the trap object is brought along. Somehow the code for applying a touchstone got inserted in between two sections of code for applying a trap (ages ago; probably since touchstone was first introduced however many versions back), so clean that up. --- doc/fixes36.1 | 1 + include/extern.h | 1 + src/apply.c | 28 ++++++++++++++-------------- src/do.c | 13 ++++++++++--- src/lock.c | 11 ++++++++++- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/doc/fixes36.1 b/doc/fixes36.1 index 9b40d87f..cdfdb46e 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -53,6 +53,7 @@ dipping fruit juice into enlightenment gave different result than the inverse make travel walk up to a trap and stop when the trap blocks the only way forward, instead of trying to go straight line travel will displace pets rather than stop +discard travel cache when moving to a different dungeon level do not autopickup unpaid items in shops death due an unseen gas spore's explosion resulted in "killed by a died" allow optional parameter "true", "yes", "false", or "no" for boolean options diff --git a/include/extern.h b/include/extern.h index 3d9c6c5f..1a20b24f 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1013,6 +1013,7 @@ E boolean FDECL(picking_lock, (int *, int *)); E boolean FDECL(picking_at, (int, int)); E void FDECL(breakchestlock, (struct obj *, BOOLEAN_P)); E void NDECL(reset_pick); +E void NDECL(maybe_reset_pick); E int FDECL(pick_lock, (struct obj *)); E int NDECL(doforce); E boolean FDECL(boxlock, (struct obj *, struct obj *)); diff --git a/src/apply.c b/src/apply.c index 24db211d..544619b9 100644 --- a/src/apply.c +++ b/src/apply.c @@ -2179,20 +2179,6 @@ struct obj *obj; update_inventory(); } -static struct trapinfo { - struct obj *tobj; - xchar tx, ty; - int time_needed; - boolean force_bungle; -} trapinfo; - -void -reset_trapset() -{ - trapinfo.tobj = 0; - trapinfo.force_bungle = 0; -} - /* touchstones - by Ken Arnold */ STATIC_OVL void use_stone(tstone) @@ -2322,6 +2308,20 @@ struct obj *tstone; return; } +static struct trapinfo { + struct obj *tobj; + xchar tx, ty; + int time_needed; + boolean force_bungle; +} trapinfo; + +void +reset_trapset() +{ + trapinfo.tobj = 0; + trapinfo.force_bungle = 0; +} + /* Place a landmine/bear trap. Helge Hafting */ STATIC_OVL void use_trap(otmp) diff --git a/src/do.c b/src/do.c index 5efa0da8..2cbfa366 100644 --- a/src/do.c +++ b/src/do.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do.c $NHDT-Date: 1454033599 2016/01/29 02:13:19 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.153 $ */ +/* NetHack 3.6 do.c $NHDT-Date: 1464487100 2016/05/29 01:58:20 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.156 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1523,13 +1523,20 @@ boolean at_stairs, falling, portal; save_currentstate(); #endif - if ((annotation = get_annotation(&u.uz))) + if ((annotation = get_annotation(&u.uz)) != 0) You("remember this level as %s.", annotation); /* assume this will always return TRUE when changing level */ (void) in_out_region(u.ux, u.uy); (void) pickup(1); - context.polearm.hitmon = NULL; + + /* discard context which applied to previous level */ + maybe_reset_pick(); /* for door or for box not accompanying hero */ + reset_trapset(); /* even if to-be-armed trap obj is accompanying hero */ + iflags.travelcc.x = iflags.travelcc.y = -1; /* travel destination cache */ + context.polearm.hitmon = (struct monst *) 0; /* polearm target */ + /* digging context is level-aware and can actually be resumed if + hero returns to the previous level without any intervening dig */ } STATIC_OVL void diff --git a/src/lock.c b/src/lock.c index 16f1c63b..f899f9a0 100644 --- a/src/lock.c +++ b/src/lock.c @@ -75,7 +75,8 @@ STATIC_PTR int picklock(VOID_ARGS) { if (xlock.box) { - if ((xlock.box->ox != u.ux) || (xlock.box->oy != u.uy)) { + if (xlock.box->where != OBJ_FLOOR + || xlock.box->ox != u.ux || xlock.box->oy != u.uy) { return ((xlock.usedtime = 0)); /* you or it moved */ } } else { /* door */ @@ -228,6 +229,14 @@ reset_pick() xlock.box = 0; } +/* level change; don't reset if hero is carrying xlock.box with him/her */ +void +maybe_reset_pick() +{ + if (!xlock.box || !carried(xlock.box)) + reset_pick(); +} + /* for doapply(); if player gives a direction or resumes an interrupted previous attempt then it costs hero a move even if nothing ultimately happens; when told "can't do that" before being asked for direction -- 2.11.4.GIT