Moved more globals to instance_globals.

This commit is contained in:
Bart House
2018-11-24 02:13:54 -08:00
parent f1e48cddfe
commit 3645e415e3
37 changed files with 987 additions and 869 deletions

View File

@@ -5,15 +5,6 @@
#include "hack.h"
/* at most one of `door' and `box' should be non-null at any given time */
STATIC_VAR NEARDATA struct xlock_s {
struct rm *door;
struct obj *box;
int picktyp, /* key|pick|card for unlock, sharp vs blunt for #force */
chance, usedtime;
boolean magic_key;
} xlock;
/* occupation callbacks */
STATIC_PTR int NDECL(picklock);
STATIC_PTR int NDECL(forcelock);
@@ -40,7 +31,7 @@ boolean
picking_at(x, y)
int x, y;
{
return (boolean) (occupation == picklock && xlock.door == &levl[x][y]);
return (boolean) (occupation == picklock && g.xlock.door == &levl[x][y]);
}
/* produce an occupation string appropriate for the current activity */
@@ -56,19 +47,19 @@ lock_action()
};
/* if the target is currently unlocked, we're trying to lock it now */
if (xlock.door && !(xlock.door->doormask & D_LOCKED))
if (g.xlock.door && !(g.xlock.door->doormask & D_LOCKED))
return actions[0] + 2; /* "locking the door" */
else if (xlock.box && !xlock.box->olocked)
return xlock.box->otyp == CHEST ? actions[1] + 2 : actions[2] + 2;
else if (g.xlock.box && !g.xlock.box->olocked)
return g.xlock.box->otyp == CHEST ? actions[1] + 2 : actions[2] + 2;
/* otherwise we're trying to unlock it */
else if (xlock.picktyp == LOCK_PICK)
else if (g.xlock.picktyp == LOCK_PICK)
return actions[3]; /* "picking the lock" */
else if (xlock.picktyp == CREDIT_CARD)
else if (g.xlock.picktyp == CREDIT_CARD)
return actions[3]; /* same as lock_pick */
else if (xlock.door)
else if (g.xlock.door)
return actions[0]; /* "unlocking the door" */
else if (xlock.box)
return xlock.box->otyp == CHEST ? actions[1] : actions[2];
else if (g.xlock.box)
return g.xlock.box->otyp == CHEST ? actions[1] : actions[2];
else
return actions[3];
}
@@ -77,44 +68,44 @@ lock_action()
STATIC_PTR int
picklock(VOID_ARGS)
{
if (xlock.box) {
if (xlock.box->where != OBJ_FLOOR
|| xlock.box->ox != u.ux || xlock.box->oy != u.uy) {
return ((xlock.usedtime = 0)); /* you or it moved */
if (g.xlock.box) {
if (g.xlock.box->where != OBJ_FLOOR
|| g.xlock.box->ox != u.ux || g.xlock.box->oy != u.uy) {
return ((g.xlock.usedtime = 0)); /* you or it moved */
}
} else { /* door */
if (xlock.door != &(levl[u.ux + u.dx][u.uy + u.dy])) {
return ((xlock.usedtime = 0)); /* you moved */
if (g.xlock.door != &(levl[u.ux + u.dx][u.uy + u.dy])) {
return ((g.xlock.usedtime = 0)); /* you moved */
}
switch (xlock.door->doormask) {
switch (g.xlock.door->doormask) {
case D_NODOOR:
pline("This doorway has no door.");
return ((xlock.usedtime = 0));
return ((g.xlock.usedtime = 0));
case D_ISOPEN:
You("cannot lock an open door.");
return ((xlock.usedtime = 0));
return ((g.xlock.usedtime = 0));
case D_BROKEN:
pline("This door is broken.");
return ((xlock.usedtime = 0));
return ((g.xlock.usedtime = 0));
}
}
if (xlock.usedtime++ >= 50 || nohands(youmonst.data)) {
if (g.xlock.usedtime++ >= 50 || nohands(youmonst.data)) {
You("give up your attempt at %s.", lock_action());
exercise(A_DEX, TRUE); /* even if you don't succeed */
return ((xlock.usedtime = 0));
return ((g.xlock.usedtime = 0));
}
if (rn2(100) >= xlock.chance)
if (rn2(100) >= g.xlock.chance)
return 1; /* still busy */
/* using the Master Key of Thievery finds traps if its bless/curse
state is adequate (non-cursed for rogues, blessed for others;
checked when setting up 'xlock') */
if ((!xlock.door ? (int) xlock.box->otrapped
: (xlock.door->doormask & D_TRAPPED) != 0)
&& xlock.magic_key) {
xlock.chance += 20; /* less effort needed next time */
if ((!g.xlock.door ? (int) g.xlock.box->otrapped
: (g.xlock.door->doormask & D_TRAPPED) != 0)
&& g.xlock.magic_key) {
g.xlock.chance += 20; /* less effort needed next time */
/* unfortunately we don't have a 'tknown' flag to record
"known to be trapped" so declining to disarm and then
retrying lock manipulation will find it all over again */
@@ -123,14 +114,14 @@ picklock(VOID_ARGS)
boolean alreadyunlocked;
/* disarming while using magic key always succeeds */
if (xlock.door) {
xlock.door->doormask &= ~D_TRAPPED;
if (g.xlock.door) {
g.xlock.door->doormask &= ~D_TRAPPED;
what = "door";
alreadyunlocked = !(xlock.door->doormask & D_LOCKED);
alreadyunlocked = !(g.xlock.door->doormask & D_LOCKED);
} else {
xlock.box->otrapped = 0;
what = (xlock.box->otyp == CHEST) ? "chest" : "box";
alreadyunlocked = !xlock.box->olocked;
g.xlock.box->otrapped = 0;
what = (g.xlock.box->otyp == CHEST) ? "chest" : "box";
alreadyunlocked = !g.xlock.box->olocked;
}
You("succeed in disarming the trap. The %s is still %slocked.",
what, alreadyunlocked ? "un" : "");
@@ -139,30 +130,30 @@ picklock(VOID_ARGS)
You("stop %s.", lock_action());
exercise(A_WIS, FALSE);
}
return ((xlock.usedtime = 0));
return ((g.xlock.usedtime = 0));
}
You("succeed in %s.", lock_action());
if (xlock.door) {
if (xlock.door->doormask & D_TRAPPED) {
if (g.xlock.door) {
if (g.xlock.door->doormask & D_TRAPPED) {
b_trapped("door", FINGER);
xlock.door->doormask = D_NODOOR;
g.xlock.door->doormask = D_NODOOR;
unblock_point(u.ux + u.dx, u.uy + u.dy);
if (*in_rooms(u.ux + u.dx, u.uy + u.dy, SHOPBASE))
add_damage(u.ux + u.dx, u.uy + u.dy, SHOP_DOOR_COST);
newsym(u.ux + u.dx, u.uy + u.dy);
} else if (xlock.door->doormask & D_LOCKED)
xlock.door->doormask = D_CLOSED;
} else if (g.xlock.door->doormask & D_LOCKED)
g.xlock.door->doormask = D_CLOSED;
else
xlock.door->doormask = D_LOCKED;
g.xlock.door->doormask = D_LOCKED;
} else {
xlock.box->olocked = !xlock.box->olocked;
xlock.box->lknown = 1;
if (xlock.box->otrapped)
(void) chest_trap(xlock.box, FINGER, FALSE);
g.xlock.box->olocked = !g.xlock.box->olocked;
g.xlock.box->lknown = 1;
if (g.xlock.box->otrapped)
(void) chest_trap(g.xlock.box, FINGER, FALSE);
}
exercise(A_DEX, TRUE);
return ((xlock.usedtime = 0));
return ((g.xlock.usedtime = 0));
}
void
@@ -222,17 +213,17 @@ boolean destroyit;
STATIC_PTR int
forcelock(VOID_ARGS)
{
if ((xlock.box->ox != u.ux) || (xlock.box->oy != u.uy))
return ((xlock.usedtime = 0)); /* you or it moved */
if ((g.xlock.box->ox != u.ux) || (g.xlock.box->oy != u.uy))
return ((g.xlock.usedtime = 0)); /* you or it moved */
if (xlock.usedtime++ >= 50 || !uwep || nohands(youmonst.data)) {
if (g.xlock.usedtime++ >= 50 || !uwep || nohands(youmonst.data)) {
You("give up your attempt to force the lock.");
if (xlock.usedtime >= 50) /* you made the effort */
exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE);
return ((xlock.usedtime = 0));
if (g.xlock.usedtime >= 50) /* you made the effort */
exercise((g.xlock.picktyp) ? A_DEX : A_STR, TRUE);
return ((g.xlock.usedtime = 0));
}
if (xlock.picktyp) { /* blade */
if (g.xlock.picktyp) { /* blade */
if (rn2(1000 - (int) uwep->spe) > (992 - greatest_erosion(uwep) * 10)
&& !uwep->cursed && !obj_resists(uwep, 0, 99)) {
/* for a +0 weapon, probability that it survives an unsuccessful
@@ -243,35 +234,35 @@ forcelock(VOID_ARGS)
useup(uwep);
You("give up your attempt to force the lock.");
exercise(A_DEX, TRUE);
return ((xlock.usedtime = 0));
return ((g.xlock.usedtime = 0));
}
} else /* blunt */
wake_nearby(); /* due to hammering on the container */
if (rn2(100) >= xlock.chance)
if (rn2(100) >= g.xlock.chance)
return 1; /* still busy */
You("succeed in forcing the lock.");
breakchestlock(xlock.box, (boolean) (!xlock.picktyp && !rn2(3)));
breakchestlock(g.xlock.box, (boolean) (!g.xlock.picktyp && !rn2(3)));
exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE);
return ((xlock.usedtime = 0));
exercise((g.xlock.picktyp) ? A_DEX : A_STR, TRUE);
return ((g.xlock.usedtime = 0));
}
void
reset_pick()
{
xlock.usedtime = xlock.chance = xlock.picktyp = 0;
xlock.magic_key = FALSE;
xlock.door = 0;
xlock.box = 0;
g.xlock.usedtime = g.xlock.chance = g.xlock.picktyp = 0;
g.xlock.magic_key = FALSE;
g.xlock.door = 0;
g.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))
if (!g.xlock.box || !carried(g.xlock.box))
reset_pick();
}
@@ -297,7 +288,7 @@ struct obj *pick;
picktyp = pick->otyp;
/* check whether we're resuming an interrupted previous attempt */
if (xlock.usedtime && picktyp == xlock.picktyp) {
if (g.xlock.usedtime && picktyp == g.xlock.picktyp) {
static char no_longer[] = "Unfortunately, you can no longer %s %s.";
if (nohands(youmonst.data)) {
@@ -308,7 +299,7 @@ struct obj *pick;
pline(no_longer, "hold the", what);
reset_pick();
return PICKLOCK_LEARNED_SOMETHING;
} else if (u.uswallow || (xlock.box && !can_reach_floor(TRUE))) {
} else if (u.uswallow || (g.xlock.box && !can_reach_floor(TRUE))) {
pline(no_longer, "reach the", "lock");
reset_pick();
return PICKLOCK_LEARNED_SOMETHING;
@@ -316,7 +307,7 @@ struct obj *pick;
const char *action = lock_action();
You("resume your attempt at %s.", action);
xlock.magic_key = is_magic_key(&youmonst, pick);
g.xlock.magic_key = is_magic_key(&youmonst, pick);
set_occupation(picklock, action, 0);
return PICKLOCK_DID_SOMETHING;
}
@@ -416,8 +407,8 @@ struct obj *pick;
if (otmp->cursed)
ch /= 2;
xlock.box = otmp;
xlock.door = 0;
g.xlock.box = otmp;
g.xlock.door = 0;
break;
}
if (c != 'y') {
@@ -495,15 +486,15 @@ struct obj *pick;
default:
ch = 0;
}
xlock.door = door;
xlock.box = 0;
g.xlock.door = door;
g.xlock.box = 0;
}
}
context.move = 0;
xlock.chance = ch;
xlock.picktyp = picktyp;
xlock.magic_key = is_magic_key(&youmonst, pick);
xlock.usedtime = 0;
g.xlock.chance = ch;
g.xlock.picktyp = picktyp;
g.xlock.magic_key = is_magic_key(&youmonst, pick);
g.xlock.usedtime = 0;
set_occupation(picklock, lock_action(), 0);
return PICKLOCK_DID_SOMETHING;
}
@@ -539,14 +530,14 @@ doforce()
}
picktyp = is_blade(uwep) && !is_pick(uwep);
if (xlock.usedtime && xlock.box && picktyp == xlock.picktyp) {
if (g.xlock.usedtime && g.xlock.box && picktyp == g.xlock.picktyp) {
You("resume your attempt to force the lock.");
set_occupation(forcelock, "forcing the lock", 0);
return 1;
}
/* A lock is made only for the honest man, the thief will break it. */
xlock.box = (struct obj *) 0;
g.xlock.box = (struct obj *) 0;
for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere)
if (Is_box(otmp)) {
if (otmp->obroken || !otmp->olocked) {
@@ -574,15 +565,15 @@ doforce()
You("force %s into a crack and pry.", yname(uwep));
else
You("start bashing it with %s.", yname(uwep));
xlock.box = otmp;
xlock.chance = objects[uwep->otyp].oc_wldam * 2;
xlock.picktyp = picktyp;
xlock.magic_key = FALSE;
xlock.usedtime = 0;
g.xlock.box = otmp;
g.xlock.chance = objects[uwep->otyp].oc_wldam * 2;
g.xlock.picktyp = picktyp;
g.xlock.magic_key = FALSE;
g.xlock.usedtime = 0;
break;
}
if (xlock.box)
if (g.xlock.box)
set_occupation(forcelock, "forcing the lock", 0);
else
You("decide not to force the issue.");
@@ -890,7 +881,7 @@ struct obj *obj, *otmp; /* obj *is* a box */
case SPE_POLYMORPH:
/* maybe start unlocking chest, get interrupted, then zap it;
we must avoid any attempt to resume unlocking it */
if (xlock.box == obj)
if (g.xlock.box == obj)
reset_pick();
break;
}