From bd69677933012af28b2057e6fd9c83deceff573f Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Wed, 22 Apr 2015 09:23:54 +0300 Subject: [PATCH] Unify stumbling on door mimic --- include/extern.h | 1 + src/lock.c | 26 +++++++++++++++++--------- src/trap.c | 9 +-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/extern.h b/include/extern.h index b5648f0bf..1cb0d673d 100644 --- a/include/extern.h +++ b/include/extern.h @@ -984,6 +984,7 @@ E int NDECL(doforce); E boolean FDECL(boxlock, (struct obj *,struct obj *)); E boolean FDECL(doorlock, (struct obj *,int,int)); E int NDECL(doopen); +E boolean FDECL(stumble_on_door_mimic, (int,int)); E int FDECL(doopen_indir, (int,int)); E int NDECL(doclose); diff --git a/src/lock.c b/src/lock.c index 26abde26a..ed629e93c 100644 --- a/src/lock.c +++ b/src/lock.c @@ -526,6 +526,22 @@ doopen() /* try to open a door */ return doopen_indir(0, 0); } +boolean +stumble_on_door_mimic(x,y) +int x,y; +{ + struct monst *mtmp; + if ((mtmp = m_at(x,y)) && + mtmp->m_ap_type == M_AP_FURNITURE && + (mtmp->mappearance == S_hcdoor || + mtmp->mappearance == S_vcdoor) && + !Protection_from_shape_changers) { + stumble_onto_mimic(mtmp); + return TRUE; + } + return FALSE; +} + int doopen_indir(x, y) /* try to open a door in direction u.dx/u.dy */ int x, y; @@ -554,15 +570,7 @@ int x, y; if((cc.x == u.ux) && (cc.y == u.uy)) return(0); - if ((mtmp = m_at(cc.x,cc.y)) && - mtmp->m_ap_type == M_AP_FURNITURE && - (mtmp->mappearance == S_hcdoor || - mtmp->mappearance == S_vcdoor) && - !Protection_from_shape_changers) { - - stumble_onto_mimic(mtmp); - return(1); - } + if (stumble_on_door_mimic(cc.x, cc.y)) return 1; /* when choosing a direction is impaired, use a turn regardless of whether a door is successfully targetted */ diff --git a/src/trap.c b/src/trap.c index 037c73255..3efae477d 100644 --- a/src/trap.c +++ b/src/trap.c @@ -4108,14 +4108,7 @@ boolean force; return(0); } - if ((mtmp = m_at(x,y)) && - mtmp->m_ap_type == M_AP_FURNITURE && - (mtmp->mappearance == S_hcdoor || - mtmp->mappearance == S_vcdoor) && - !Protection_from_shape_changers) { - stumble_onto_mimic(mtmp); - return(1); - } + if (stumble_on_door_mimic(x,y)) return 1; } /* deal_with_floor_trap */ /* doors can be manipulated even while levitating/unskilled riding */