From 61a35d4ac0e3ef68e11e8caf9da9597d879e9902 Mon Sep 17 00:00:00 2001 From: nhmall Date: Fri, 23 Nov 2018 22:16:40 -0500 Subject: [PATCH] Revert "Moved pickup globals to instance_globals." This reverts commit 01596f166095f307eed6c705590cb7e0dd024f10. --- include/decl.h | 5 -- src/decl.c | 2 - src/pickup.c | 151 +++++++++++++++++++++++++------------------------ 3 files changed, 78 insertions(+), 80 deletions(-) diff --git a/include/decl.h b/include/decl.h index 3359542ef..ce9fe2d81 100644 --- a/include/decl.h +++ b/include/decl.h @@ -463,11 +463,6 @@ struct instance_globals { /* pickup.c */ int oldcap; /* last encumberance */ - /* current_container is set in use_container(), to be used by the - callback routines in_container() and out_container() from askchain() - and use_container(). Also used by menu_loot() and container_gone(). */ - struct obj *current_container; - boolean abort_looting; /* pline.c */ unsigned pline_flags; diff --git a/src/decl.c b/src/decl.c index 0fb2cd1d1..7a407a9e2 100644 --- a/src/decl.c +++ b/src/decl.c @@ -347,8 +347,6 @@ const struct instance_globals g_init = { /* pickup.c */ 0, /* oldcap */ - UNDEFINED_PTR, /* current_container */ - UNDEFINED_VALUE, /* abort_looting */ /* pline.c */ 0, /* pline_flags */ diff --git a/src/pickup.c b/src/pickup.c index 9b154ebc8..b008b0f8f 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -62,7 +62,12 @@ STATIC_DCL void FDECL(tipcontainer, (struct obj *)); /* if you can figure this out, give yourself a hearty pat on the back... */ #define GOLD_CAPACITY(w, n) (((w) * -100L) - ((n) + 50L) - 1L) -#define Icebox (g.current_container->otyp == ICE_BOX) +/* A variable set in use_container(), to be used by the callback routines + in_container() and out_container() from askchain() and use_container(). + Also used by menu_loot() and container_gone(). */ +static NEARDATA struct obj *current_container; +static NEARDATA boolean abort_looting; +#define Icebox (current_container->otyp == ICE_BOX) static const char moderateloadmsg[] = "You have a little trouble lifting", @@ -1690,7 +1695,7 @@ int cindex, ccount; /* index of this container (1..N), number of them (N) */ tmp = rnd(10); losehp(Maybe_Half_Phys(tmp), "carnivorous bag", KILLED_BY_AN); makeknown(BAG_OF_TRICKS); - g.abort_looting = TRUE; + abort_looting = TRUE; return 1; } @@ -1715,7 +1720,7 @@ doloot() boolean prev_loot = FALSE; int num_conts = 0; - g.abort_looting = FALSE; + abort_looting = FALSE; if (check_capacity((char *) 0)) { /* "Can't do that while carrying so much stuff." */ @@ -1786,7 +1791,7 @@ doloot() for (i = 1; i <= n; i++) { cobj = pick_list[i - 1].item.a_obj; timepassed |= do_loot_cont(&cobj, i, n); - if (g.abort_looting) { + if (abort_looting) { /* chest trap or magic bag explosion or */ free((genericptr_t) pick_list); return timepassed; @@ -1811,7 +1816,7 @@ doloot() anyfound = TRUE; timepassed |= do_loot_cont(&cobj, 1, 1); - if (g.abort_looting) + if (abort_looting) /* chest trap or magic bag explosion or */ return timepassed; } @@ -2071,17 +2076,17 @@ STATIC_PTR int in_container(obj) register struct obj *obj; { - boolean floor_container = !carried(g.current_container); + boolean floor_container = !carried(current_container); boolean was_unpaid = FALSE; char buf[BUFSZ]; - if (!g.current_container) { + if (!current_container) { impossible(" no current_container?"); return 0; } else if (obj == uball || obj == uchain) { You("must be kidding."); return 0; - } else if (obj == g.current_container) { + } else if (obj == current_container) { pline("That would be an interesting topological exercise."); return 0; } else if (obj->owornmask & (W_ARMOR | W_ACCESSORY)) { @@ -2136,7 +2141,7 @@ register struct obj *obj; * of evaluation of the parameters is undefined. */ Strcpy(buf, the(xname(obj))); - You("cannot fit %s into %s.", buf, the(xname(g.current_container))); + You("cannot fit %s into %s.", buf, the(xname(current_container))); return 0; } @@ -2152,7 +2157,7 @@ register struct obj *obj; was_unpaid = obj->unpaid ? TRUE : FALSE; /* don't sell when putting the item into your own container, * but handle billing correctly */ - sellobj_state(g.current_container->no_charge + sellobj_state(current_container->no_charge ? SELL_DONTSELL : SELL_DELIBERATE); sellobj(obj, u.ux, u.uy); sellobj_state(SELL_NORMAL); @@ -2169,7 +2174,7 @@ register struct obj *obj; if (rot_alarm) obj->norevive = 1; } - } else if (Is_mbag(g.current_container) && mbag_explodes(obj, 0)) { + } else if (Is_mbag(current_container) && mbag_explodes(obj, 0)) { /* explicitly mention what item is triggering the explosion */ pline("As you put %s inside, you are blasted by a magical explosion!", doname(obj)); @@ -2177,34 +2182,34 @@ register struct obj *obj; if (was_unpaid) addtobill(obj, FALSE, FALSE, TRUE); obfree(obj, (struct obj *) 0); - delete_contents(g.current_container); + delete_contents(current_container); if (!floor_container) - useup(g.current_container); - else if (obj_here(g.current_container, u.ux, u.uy)) - useupf(g.current_container, g.current_container->quan); + useup(current_container); + else if (obj_here(current_container, u.ux, u.uy)) + useupf(current_container, current_container->quan); else panic("in_container: bag not found."); losehp(d(6, 6), "magical explosion", KILLED_BY_AN); - g.current_container = 0; /* baggone = TRUE; */ + current_container = 0; /* baggone = TRUE; */ } - if (g.current_container) { - Strcpy(buf, the(xname(g.current_container))); + if (current_container) { + Strcpy(buf, the(xname(current_container))); You("put %s into %s.", doname(obj), buf); /* gold in container always needs to be added to credit */ if (floor_container && obj->oclass == COIN_CLASS) - sellobj(obj, g.current_container->ox, g.current_container->oy); - (void) add_to_container(g.current_container, obj); - g.current_container->owt = weight(g.current_container); + sellobj(obj, current_container->ox, current_container->oy); + (void) add_to_container(current_container, obj); + current_container->owt = weight(current_container); } /* gold needs this, and freeinv() many lines above may cause * the encumbrance to disappear from the status, so just always * update status immediately. */ bot(); - return (g.current_container ? 1 : -1); + return (current_container ? 1 : -1); } /* askchain() filter used by in_container(); @@ -2216,7 +2221,7 @@ int ck_bag(obj) struct obj *obj; { - return (g.current_container && obj != g.current_container); + return (current_container && obj != current_container); } /* Returns: -1 to stop, 1 item was removed, 0 item was not removed. */ @@ -2229,7 +2234,7 @@ register struct obj *obj; int res, loadlev; long count; - if (!g.current_container) { + if (!current_container) { impossible(" no current_container?"); return -1; } else if (is_gold) { @@ -2243,7 +2248,7 @@ register struct obj *obj; return -1; count = obj->quan; - if ((res = lift_object(obj, g.current_container, &count, FALSE)) <= 0) + if ((res = lift_object(obj, current_container, &count, FALSE)) <= 0) return res; if (obj->quan != count && obj->otyp != LOADSTONE) @@ -2251,15 +2256,15 @@ register struct obj *obj; /* Remove the object from the list. */ obj_extract_self(obj); - g.current_container->owt = weight(g.current_container); + current_container->owt = weight(current_container); if (Icebox) removed_from_icebox(obj); - if (!obj->unpaid && !carried(g.current_container) - && costly_spot(g.current_container->ox, g.current_container->oy)) { - obj->ox = g.current_container->ox; - obj->oy = g.current_container->oy; + if (!obj->unpaid && !carried(current_container) + && costly_spot(current_container->ox, current_container->oy)) { + obj->ox = current_container->ox; + obj->oy = current_container->oy; addtobill(obj, FALSE, FALSE, FALSE); } if (is_pick(obj)) @@ -2386,7 +2391,7 @@ int FDECL((*fn), (OBJ_P)); { /* result is only meaningful while use_container() is executing */ return ((fn == in_container || fn == out_container) - && !g.current_container); + && !current_container); } STATIC_OVL void @@ -2450,7 +2455,7 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ int used = 0; long loss; - g.abort_looting = FALSE; + abort_looting = FALSE; emptymsg[0] = '\0'; if (!u_handsy()) @@ -2473,37 +2478,37 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ multi_reason = "opening a container"; nomovemsg = ""; } - g.abort_looting = TRUE; + abort_looting = TRUE; return 1; } obj->lknown = 1; - g.current_container = obj; /* for use by in/out_container */ + current_container = obj; /* for use by in/out_container */ /* * From here on out, all early returns go through 'containerdone:'. */ /* check for Schroedinger's Cat */ - quantum_cat = SchroedingersBox(g.current_container); + quantum_cat = SchroedingersBox(current_container); if (quantum_cat) { - observe_quantum_cat(g.current_container, TRUE, TRUE); + observe_quantum_cat(current_container, TRUE, TRUE); used = 1; } - cursed_mbag = Is_mbag(g.current_container) - && g.current_container->cursed - && Has_contents(g.current_container); + cursed_mbag = Is_mbag(current_container) + && current_container->cursed + && Has_contents(current_container); if (cursed_mbag - && (loss = boh_loss(g.current_container, held)) != 0) { + && (loss = boh_loss(current_container, held)) != 0) { used = 1; You("owe %ld %s for lost merchandise.", loss, currency(loss)); - g.current_container->owt = weight(g.current_container); + current_container->owt = weight(current_container); } inokay = (invent != 0 - && !(invent == g.current_container && !g.current_container->nobj)); - outokay = Has_contents(g.current_container); + && !(invent == current_container && !current_container->nobj)); + outokay = Has_contents(current_container); if (!outokay) /* preformat the empty-container message */ - Sprintf(emptymsg, "%s is %sempty.", Ysimple_name2(g.current_container), + Sprintf(emptymsg, "%s is %sempty.", Ysimple_name2(current_container), (quantum_cat || cursed_mbag) ? "now " : ""); /* @@ -2533,13 +2538,13 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ * is empty. Do what with it? [:irs nq or ?] */ for (;;) { /* repeats iff '?' or ":' gets chosen */ - outmaybe = (outokay || !g.current_container->cknown); + outmaybe = (outokay || !current_container->cknown); if (!outmaybe) (void) safe_qbuf(qbuf, (char *) 0, " is empty. Do what with it?", - g.current_container, Yname2, Ysimple_name2, + current_container, Yname2, Ysimple_name2, "This"); else - (void) safe_qbuf(qbuf, "Do what with ", "?", g.current_container, + (void) safe_qbuf(qbuf, "Do what with ", "?", current_container, yname, ysimple_name, "it"); /* ask player about what to do with this container */ if (flags.menu_style == MENU_PARTIAL @@ -2549,7 +2554,7 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ trying to do both will yield proper feedback */ c = 'b'; } else { - c = in_or_out_menu(qbuf, g.current_container, outmaybe, inokay, + c = in_or_out_menu(qbuf, current_container, outmaybe, inokay, (boolean) (used != 0), more_containers); } } else { /* TRADITIONAL or COMBINATION */ @@ -2576,15 +2581,15 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ if (c == '?') { explain_container_prompt(more_containers); } else if (c == ':') { /* note: will set obj->cknown */ - if (!g.current_container->cknown) + if (!current_container->cknown) used = 1; /* gaining info */ - container_contents(g.current_container, FALSE, FALSE, TRUE); + container_contents(current_container, FALSE, FALSE, TRUE); } else break; } /* loop until something other than '?' or ':' is picked */ if (c == 'q') - g.abort_looting = TRUE; + abort_looting = TRUE; if (c == 'n' || c == 'q') /* [not strictly needed; falling thru works] */ goto containerdone; loot_out = (c == 'o' || c == 'b' || c == 'r'); @@ -2594,11 +2599,11 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ /* out-only or out before in */ if (loot_out && !loot_in_first) { - if (!Has_contents(g.current_container)) { + if (!Has_contents(current_container)) { pline1(emptymsg); /* is empty. */ - if (!g.current_container->cknown) + if (!current_container->cknown) used = 1; - g.current_container->cknown = 1; + current_container->cknown = 1; } else { add_valid_menu_class(0); /* reset */ if (flags.menu_style == MENU_TRADITIONAL) @@ -2610,7 +2615,7 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ } if ((loot_in || stash_one) - && (!invent || (invent == g.current_container && !invent->nobj))) { + && (!invent || (invent == current_container && !invent->nobj))) { You("don't have anything%s to %s.", invent ? " else" : "", stash_one ? "stash" : "put in"); loot_in = stash_one = FALSE; @@ -2640,16 +2645,16 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ } } /* putting something in might have triggered magic bag explosion */ - if (!g.current_container) + if (!current_container) loot_out = FALSE; /* out after in */ if (loot_out && loot_in_first) { - if (!Has_contents(g.current_container)) { + if (!Has_contents(current_container)) { pline1(emptymsg); /* is empty. */ - if (!g.current_container->cknown) + if (!current_container->cknown) used = 1; - g.current_container->cknown = 1; + current_container->cknown = 1; } else { add_valid_menu_class(0); /* reset */ if (flags.menu_style == MENU_TRADITIONAL) @@ -2666,16 +2671,16 @@ containerdone: whatever was already inside, now we suddenly do. That can't be helped unless we want to track things item by item and then deal with containers whose contents are "partly known". */ - if (g.current_container) - g.current_container->cknown = 1; + if (current_container) + current_container->cknown = 1; update_inventory(); } - *objp = g.current_container; /* might have become null */ - if (g.current_container) - g.current_container = 0; /* avoid hanging on to stale pointer */ + *objp = current_container; /* might have become null */ + if (current_container) + current_container = 0; /* avoid hanging on to stale pointer */ else - g.abort_looting = TRUE; + abort_looting = TRUE; return used; } @@ -2698,7 +2703,7 @@ boolean put_in; checkfunc = ck_bag; } else { action = "take out"; - objlist = &(g.current_container->cobj); + objlist = &(current_container->cobj); actionfunc = out_container; checkfunc = (int FDECL((*), (OBJ_P))) 0; } @@ -2735,7 +2740,7 @@ boolean put_in; all_categories = FALSE; Sprintf(buf, "%s what type of objects?", action); mflags = (ALL_TYPES | UNPAID_TYPES | BUCX_TYPES | CHOOSE_ALL); - n = query_category(buf, put_in ? invent : g.current_container->cobj, + n = query_category(buf, put_in ? invent : current_container->cobj, mflags, &pick_list, PICK_ANY); if (!n) return 0; @@ -2752,8 +2757,8 @@ boolean put_in; if (loot_everything) { if (!put_in) { - g.current_container->cknown = 1; - for (otmp = g.current_container->cobj; otmp; otmp = otmp2) { + current_container->cknown = 1; + for (otmp = current_container->cobj; otmp; otmp = otmp2) { otmp2 = otmp->nobj; res = out_container(otmp); if (res < 0) @@ -2761,7 +2766,7 @@ boolean put_in; n_looted += res; } } else { - for (otmp = invent; otmp && g.current_container; otmp = otmp2) { + for (otmp = invent; otmp && current_container; otmp = otmp2) { otmp2 = otmp->nobj; res = in_container(otmp); if (res < 0) @@ -2774,9 +2779,9 @@ boolean put_in; if (put_in && flags.invlet_constant) mflags |= USE_INVLET; if (!put_in) - g.current_container->cknown = 1; + current_container->cknown = 1; Sprintf(buf, "%s what?", action); - n = query_objlist(buf, put_in ? &invent : &(g.current_container->cobj), + n = query_objlist(buf, put_in ? &invent : &(current_container->cobj), mflags, &pick_list, PICK_ANY, all_categories ? allow_all : allow_category); if (n) { @@ -2790,7 +2795,7 @@ boolean put_in; } res = put_in ? in_container(otmp) : out_container(otmp); if (res < 0) { - if (!g.current_container) { + if (!current_container) { /* otmp caused current_container to explode; both are now gone */ otmp = 0; /* and break loop */ -- 2.40.0