From 6586cc84b2ee98c8f124a50b9ceb879b4d64e7b4 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 23 May 2023 15:34:58 -0700 Subject: [PATCH] trap setting bit Treat a trap object that has become the focus of trap setting occupation as if it had already been used up. (No discernable change in behavior unless someone adds an artifact bear trap or landmine that talks.) Shouldn't 'trapinfo' be part of 'context' and be saved and restored? (If so, it will need to include o_id and undergo pointer fixup during restore.) When trap arming is in progress hero will be too busy for player to issue S(ave) command but a hangup save could take place. --- src/allmain.c | 2 +- src/apply.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/allmain.c b/src/allmain.c index c593cdc72..22ce1d6f7 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -640,7 +640,7 @@ stop_occupation(void) if (go.occupation) { if (!maybe_finished_meal(TRUE)) You("stop %s.", go.occtxt); - go.occupation = 0; + go.occupation = (int (*)(void)) 0; gc.context.botl = TRUE; /* in case u.uhs changed */ nomul(0); } else if (gm.multi >= 0) { diff --git a/src/apply.c b/src/apply.c index cf5548baa..1b7a64659 100644 --- a/src/apply.c +++ b/src/apply.c @@ -2834,6 +2834,7 @@ use_trap(struct obj *otmp) return; } +/* occupation routine called each turn while arming a beartrap or landmine */ static int set_trap(void) { @@ -2841,9 +2842,8 @@ set_trap(void) struct trap *ttmp; int ttyp; - if (!otmp || !carried(otmp) || u.ux != gt.trapinfo.tx - || u.uy != gt.trapinfo.ty) { - /* ?? */ + if (!otmp || !carried(otmp) || !u_at(gt.trapinfo.tx, gt.trapinfo.ty)) { + /* trap object might have been stolen or hero teleported */ reset_trapset(); return 0; } @@ -4171,6 +4171,8 @@ doapply(void) case LAND_MINE: case BEARTRAP: use_trap(obj); + if (go.occupation == set_trap) + obj = (struct obj *) 0; /* not gone yet but behave as if it was */ break; case FLINT: case LUCKSTONE: @@ -4190,8 +4192,8 @@ doapply(void) pline("Sorry, I don't know how to use that."); return ECMD_FAIL; } - /* This assumes that anything that potentially destroyed obj has kept track - * of it and set obj to null before this point. */ + /* This assumes that anything that potentially destroyed obj has kept + * track of it and set obj to null before this point. */ if (obj && obj->oartifact) { res |= arti_speak(obj); /* sets ECMD_TIME bit if artifact speaks */ }