From 912886a73ff1ded760fccdf00b300d26ad9d79f0 Mon Sep 17 00:00:00 2001 From: Bart House Date: Fri, 23 Nov 2018 21:29:19 -0800 Subject: [PATCH] First set of changes to move globals to instance_globals. --- include/decl.h | 108 ++++++++++++++ include/extern.h | 4 +- include/global.h | 5 + include/hack.h | 9 ++ include/rm.h | 2 +- src/allmain.c | 2 - src/apply.c | 31 ++-- src/artifact.c | 43 +++--- src/botl.c | 5 +- src/cmd.c | 5 +- src/decl.c | 133 +++++++++++++---- src/detect.c | 20 ++- src/dog.c | 3 +- src/dogmove.c | 4 +- src/dokick.c | 4 +- src/dothrow.c | 6 +- src/eat.c | 2 +- src/end.c | 6 +- src/hack.c | 4 +- src/hacklib.c | 16 +-- src/mhitm.c | 8 +- src/mon.c | 4 +- src/monmove.c | 8 +- src/mthrowu.c | 5 +- src/muse.c | 18 ++- src/objects.c | 13 +- src/objnam.c | 37 +++-- src/pickup.c | 158 ++++++++++----------- src/pline.c | 38 +++-- src/polyself.c | 12 +- src/potion.c | 61 ++++---- src/questpgr.c | 10 +- src/read.c | 38 +++-- src/restore.c | 57 ++++---- src/role.c | 32 ++--- src/rumors.c | 125 ++++++++-------- src/save.c | 24 ++-- src/sys.c | 3 + src/trap.c | 25 ++-- src/u_init.c | 22 ++- src/uhitm.c | 17 +-- src/weapon.c | 36 +++-- src/zap.c | 38 ++--- sys/share/random.c | 2 +- sys/unix/NetHack.xcodeproj/project.pbxproj | 2 +- util/lev_main.c | 17 ++- util/makedefs.c | 5 +- win/share/tile2bmp.c | 9 ++ win/share/tilemap.c | 1 - win/tty/topl.c | 5 +- win/tty/wintty.c | 3 +- 51 files changed, 680 insertions(+), 565 deletions(-) diff --git a/include/decl.h b/include/decl.h index 077f82173..acea3152c 100644 --- a/include/decl.h +++ b/include/decl.h @@ -196,6 +196,7 @@ E NEARDATA char dogname[]; E NEARDATA char catname[]; E NEARDATA char horsename[]; E char preferred_pet; + E const char *occtxt; /* defined when occupation != NULL */ E const char *nomovemsg; E char lock[]; @@ -441,6 +442,113 @@ struct early_opt { boolean valallowed; }; +/* instance_globals holds engine state that does not need to be + * persisted upon game exit. The initialization state is well defined + * an set in decl.c during early early engine initialization. + * + * unlike instance_flags, values in the structure can be of any type. */ + +struct instance_globals { + /* apply.c */ + int jumping_is_magic; /* current jump result of magic */ + int polearm_range_min; + int polearm_range_max; + /* artifcat.c */ + int spec_dbon_applies; /* coordinate effects from spec_dbon() with + messages in artifact_hit() */ + /* botl.c */ + int mrank_sz; /* loaded by max_rank_sz */ + + /* dog.c */ + int petname_used; /* user preferred pet name has been used */ + + /* muse.c */ + boolean m_using; /* kludge to use mondided instead of killed */ + + /* objname.c */ + /* distantname used by distant_name() to pass extra information to + xname_flags(); it would be much cleaner if this were a parameter, + but that would require all of the xname() and doname() calls to be + modified */ + int distantname; + + /* 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; + char prevmsg[BUFSZ]; +#ifdef DUMPLOG + unsigned saved_pline_index; /* slot in saved_plines[] to use next */ + char *saved_plines[DUMPLOG_MSG_COUNT]; +#endif + + /* polyself.c */ + int sex_change_ok; /* controls whether taking on new form or becoming new + man can also change sex (ought to be an arg to + polymon() and newman() instead) */ + + /* potion.c */ + boolean notonhead; /* for long worms */ + int potion_nothing; + int potion_unkn; + + /* read.c */ + boolean known; + + /* restore.c */ + int n_ids_mapped; + struct bucket *id_map; + boolean restoring; + struct fruit *oldfruit; + long omoves; + + /* rumors.c */ + long true_rumor_size; /* rumor size variables are signed so that value -1 + can be used as a flag */ + long false_rumor_size; + unsigned long true_rumor_start; /* rumor start offsets are unsigned because + they're handled via %lx format */ + unsigned long false_rumor_start; + long true_rumor_end; /* rumor end offsets are signed because they're + compared with [dlb_]ftell() */ + long false_rumor_end; + int oracle_flg; /* -1=>don't use, 0=>need init, 1=>init done */ + unsigned oracle_cnt; /* oracles are handled differently from rumors... */ + unsigned long *oracle_loc; + + /* save.c */ + boolean havestate; + unsigned ustuck_id; /* need to preserve during save */ + unsigned usteed_id; /* need to preserve during save */ + + /* trap.c */ + int force_mintrap; /* mintrap() should take a flags argument, but for time + being we use this */ + /* u_init.c */ + short nocreate; + short nocreate2; + short nocreate3; + short nocreate4; + /* uhitm.c */ + boolean override_confirmation; /* Used to flag attacks caused by + Stormbringer's maliciousness. */ + /* weapon.c */ + struct obj *propellor; + /* zap.c */ + int poly_zapped; + boolean obj_zapped; + + unsigned long magic; /* validate that structure layout is preserved */ +}; + +E struct instance_globals g; + #undef E #endif /* DECL_H */ diff --git a/include/extern.h b/include/extern.h index bd0255c2a..3ecc08f09 100644 --- a/include/extern.h +++ b/include/extern.h @@ -253,7 +253,7 @@ E void FDECL(destroy_drawbridge, (int, int)); /* ### decl.c ### */ -E void NDECL(decl_init); +E void NDECL(decl_globals_init); /* ### detect.c ### */ @@ -1657,7 +1657,7 @@ E void NDECL(rename_disco); /* ### objects.c ### */ -E void NDECL(objects_init); +E void NDECL(objects_globals_init); /* ### objnam.c ### */ diff --git a/include/global.h b/include/global.h index c8d4e1e6f..7dfa0641f 100644 --- a/include/global.h +++ b/include/global.h @@ -365,5 +365,10 @@ struct savefile_info { #define nethack_enter(argc, argv) ((void) 0) #endif +/* Supply nhassert macro if not supplied by port */ +#ifndef nhassert +#define nhassert(e) ((void)0) +#endif + #endif /* GLOBAL_H */ diff --git a/include/hack.h b/include/hack.h index e59693d5f..9ba8b49fc 100644 --- a/include/hack.h +++ b/include/hack.h @@ -22,6 +22,15 @@ 0 \ } +/* The UNDEFINED macros are used to initialize variables whose + initialized value is not relied upon. + UNDEFINED_VALUE: used to initialize any scalar type except pointers. + UNDEFINED_VALUES: used to initialize any non scalar type without pointers. + UNDEFINED_PTR: can be used only on pointer types. */ +#define UNDEFINED_VALUE 0 +#define UNDEFINED_VALUES { 0 } +#define UNDEFINED_PTR NULL + /* symbolic names for capacity levels */ enum encumbrance_types { UNENCUMBERED = 0, diff --git a/include/rm.h b/include/rm.h index 080677e15..b0c0f9ad2 100644 --- a/include/rm.h +++ b/include/rm.h @@ -9,7 +9,7 @@ /* * The dungeon presentation graphics code and data structures were rewritten * and generalized for NetHack's release 2 by Eric S. Raymond (eric@snark) - * building on Don G. Kneller's MS-DOS implementation. See drawing.c for + * building on Don G Kneller's MS-DOS implementation. See drawing.c for * the code that permits the user to set the contents of the symbol structure. * * The door representation was changed by Ari diff --git a/src/allmain.c b/src/allmain.c index d3aad93f6..459ab1eca 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -33,9 +33,7 @@ boolean resuming; /* Note: these initializers don't do anything except guarantee that we're linked properly. */ - decl_init(); monst_init(); - objects_init(); /* if a save file created in normal mode is now being restored in explore mode, treat it as normal restore followed by 'X' command diff --git a/src/apply.c b/src/apply.c index edb3940e6..406a9d2ba 100644 --- a/src/apply.c +++ b/src/apply.c @@ -5,8 +5,6 @@ #include "hack.h" -extern boolean notonhead; /* for long worms */ - STATIC_DCL int FDECL(use_camera, (struct obj *)); STATIC_DCL int FDECL(use_towel, (struct obj *)); STATIC_DCL boolean FDECL(its_dead, (int, int, int *)); @@ -325,7 +323,7 @@ register struct obj *obj; context.stethoscope_movement = youmonst.movement; bhitpos.x = u.ux, bhitpos.y = u.uy; /* tentative, reset below */ - notonhead = u.uswallow; + g.notonhead = u.uswallow; if (u.usteed && u.dz > 0) { if (interference) { pline("%s interferes.", Monnam(u.ustuck)); @@ -374,7 +372,7 @@ register struct obj *obj; /* bhitpos needed by mstatusline() iff mtmp is a long worm */ bhitpos.x = rx, bhitpos.y = ry; - notonhead = (mtmp->mx != rx || mtmp->my != ry); + g.notonhead = (mtmp->mx != rx || mtmp->my != ry); if (mtmp->mundetected) { if (!canspotmon(mtmp)) @@ -884,7 +882,7 @@ struct obj *obj; mtmp = bhit(u.dx, u.dy, COLNO, INVIS_BEAM, (int FDECL((*), (MONST_P, OBJ_P))) 0, (int FDECL((*), (OBJ_P, OBJ_P))) 0, &obj); - if (!mtmp || !haseyes(mtmp->data) || notonhead) + if (!mtmp || !haseyes(mtmp->data) || g.notonhead) return 1; /* couldsee(mtmp->mx, mtmp->my) is implied by the fact that bhit() @@ -972,7 +970,7 @@ struct obj *obj; ; else if ((mtmp->minvis && !perceives(mtmp->data)) /* redundant: can't get here if these are true */ - || !haseyes(mtmp->data) || notonhead || !mtmp->mcansee) + || !haseyes(mtmp->data) || g.notonhead || !mtmp->mcansee) pline("%s doesn't seem to notice %s reflection.", Monnam(mtmp), mhis(mtmp)); else @@ -1600,15 +1598,13 @@ boolean showmsg; return TRUE; } -static int jumping_is_magic; - STATIC_OVL boolean get_valid_jump_position(x,y) int x,y; { return (isok(x, y) && (ACCESSIBLE(levl[x][y].typ) || Passes_walls) - && is_valid_jump_pos(x, y, jumping_is_magic, FALSE)); + && is_valid_jump_pos(x, y, g.jumping_is_magic, FALSE)); } void @@ -1722,7 +1718,7 @@ int magic; /* 0=Physical, otherwise skill level */ pline("Where do you want to jump?"); cc.x = u.ux; cc.y = u.uy; - jumping_is_magic = magic; + g.jumping_is_magic = magic; getpos_sethilite(display_jump_positions, get_valid_jump_position); if (getpos(&cc, TRUE, "the desired position") < 0) return 0; /* user pressed ESC */ @@ -2914,16 +2910,13 @@ int min_range, max_range; return TRUE; } -static int polearm_range_min = -1; -static int polearm_range_max = -1; - STATIC_OVL boolean get_valid_polearm_position(x, y) int x, y; { return (isok(x, y) && ACCESSIBLE(levl[x][y].typ) - && distu(x, y) >= polearm_range_min - && distu(x, y) <= polearm_range_max); + && distu(x, y) >= g.polearm_range_min + && distu(x, y) <= g.polearm_range_max); } void @@ -2995,8 +2988,8 @@ struct obj *obj; else max_range = 8; /* (P_SKILL(typ) >= P_EXPERT) */ - polearm_range_min = min_range; - polearm_range_max = max_range; + g.polearm_range_min = min_range; + g.polearm_range_max = max_range; /* Prompt for a location */ pline(where_to_hit); @@ -3039,7 +3032,7 @@ struct obj *obj; return 1; /* burn nutrition; maybe pass out */ context.polearm.hitmon = mtmp; check_caitiff(mtmp); - notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); + g.notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); (void) thitmonst(mtmp, uwep); } else if (glyph_is_statue(glyph) /* might be hallucinatory */ && sobj_at(STATUE, bhitpos.x, bhitpos.y)) { @@ -3207,7 +3200,7 @@ struct obj *obj; bhitpos = cc; if ((mtmp = m_at(cc.x, cc.y)) == (struct monst *) 0) break; - notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); + g.notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); save_confirm = flags.confirm; if (verysmall(mtmp->data) && !rn2(4) && enexto(&cc, u.ux, u.uy, (struct permonst *) 0)) { diff --git a/src/artifact.c b/src/artifact.c index 80332f325..72385ec1c 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -14,8 +14,6 @@ * the contents, just the total size. */ -extern boolean notonhead; /* for long worms */ - #define get_artifact(o) \ (((o) && (o)->oartifact) ? &artilist[(int) (o)->oartifact] : 0) @@ -41,9 +39,6 @@ STATIC_DCL int FDECL(count_surround_traps, (int, int)); of hit points that will fit in a 15 bit integer. */ #define FATAL_DAMAGE_MODIFIER 200 -/* coordinate effects from spec_dbon() with messages in artifact_hit() */ -STATIC_OVL int spec_dbon_applies = 0; - /* flags including which artifacts have already been created */ static boolean artiexist[1 + NROFARTIFACTS + 1]; /* and a discovery list for them (no dummy first entry here) */ @@ -540,7 +535,7 @@ long wp_mask; * that can print a message--need to guard against being printed * when restoring a game */ - (void) make_hallucinated((long) !on, restoring ? FALSE : TRUE, + (void) make_hallucinated((long) !on, g.restoring ? FALSE : TRUE, wp_mask); } if (spfx & SPFX_ESP) { @@ -848,15 +843,15 @@ int tmp; if (!weap || (weap->attk.adtyp == AD_PHYS /* check for `NO_ATTK' */ && weap->attk.damn == 0 && weap->attk.damd == 0)) - spec_dbon_applies = FALSE; + g.spec_dbon_applies = FALSE; else if (otmp->oartifact == ART_GRIMTOOTH) /* Grimtooth has SPFX settings to warn against elves but we want its damage bonus to apply to all targets, so bypass spec_applies() */ - spec_dbon_applies = TRUE; + g.spec_dbon_applies = TRUE; else - spec_dbon_applies = spec_applies(weap, mon); + g.spec_dbon_applies = spec_applies(weap, mon); - if (spec_dbon_applies) + if (g.spec_dbon_applies) return weap->attk.damd ? rnd((int) weap->attk.damd) : max(tmp, 1); return 0; } @@ -980,14 +975,14 @@ char *hittee; /* target's name: "you" or mon_nam(mdef) */ scare_dieroll /= (1 << (mb->spe / 3)); /* if target successfully resisted the artifact damage bonus, reduce overall likelihood of the assorted special effects */ - if (!spec_dbon_applies) + if (!g.spec_dbon_applies) dieroll += 1; /* might stun even when attempting a more severe effect, but in that case it will only happen if the other effect fails; extra damage will apply regardless; 3.4.1: sometimes might just probe even when it hasn't been enchanted */ - do_stun = (max(mb->spe, 0) < rn2(spec_dbon_applies ? 11 : 7)); + do_stun = (max(mb->spe, 0) < rn2(g.spec_dbon_applies ? 11 : 7)); /* the special effects also boost physical damage; increments are generally cumulative, but since the stun effect is based on a @@ -1186,12 +1181,12 @@ int dieroll; /* needed for Magicbane and vorpal blades */ if (attacks(AD_FIRE, otmp)) { if (realizes_damage) pline_The("fiery blade %s %s%c", - !spec_dbon_applies + !g.spec_dbon_applies ? "hits" : (mdef->data == &mons[PM_WATER_ELEMENTAL]) ? "vaporizes part of" : "burns", - hittee, !spec_dbon_applies ? '.' : '!'); + hittee, !g.spec_dbon_applies ? '.' : '!'); if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE); if (!rn2(4)) @@ -1205,8 +1200,8 @@ int dieroll; /* needed for Magicbane and vorpal blades */ if (attacks(AD_COLD, otmp)) { if (realizes_damage) pline_The("ice-cold blade %s %s%c", - !spec_dbon_applies ? "hits" : "freezes", hittee, - !spec_dbon_applies ? '.' : '!'); + !g.spec_dbon_applies ? "hits" : "freezes", hittee, + !g.spec_dbon_applies ? '.' : '!'); if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_COLD); return realizes_damage; @@ -1214,9 +1209,9 @@ int dieroll; /* needed for Magicbane and vorpal blades */ if (attacks(AD_ELEC, otmp)) { if (realizes_damage) pline_The("massive hammer hits%s %s%c", - !spec_dbon_applies ? "" : "! Lightning strikes", - hittee, !spec_dbon_applies ? '.' : '!'); - if (spec_dbon_applies) + !g.spec_dbon_applies ? "" : "! Lightning strikes", + hittee, !g.spec_dbon_applies ? '.' : '!'); + if (g.spec_dbon_applies) wake_nearto(mdef->mx, mdef->my, 4 * 4); if (!rn2(5)) (void) destroy_mitem(mdef, RING_CLASS, AD_ELEC); @@ -1227,10 +1222,10 @@ int dieroll; /* needed for Magicbane and vorpal blades */ if (attacks(AD_MAGM, otmp)) { if (realizes_damage) pline_The("imaginary widget hits%s %s%c", - !spec_dbon_applies + !g.spec_dbon_applies ? "" : "! A hail of magic missiles strikes", - hittee, !spec_dbon_applies ? '.' : '!'); + hittee, !g.spec_dbon_applies ? '.' : '!'); return realizes_damage; } @@ -1239,7 +1234,7 @@ int dieroll; /* needed for Magicbane and vorpal blades */ return Mb_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee); } - if (!spec_dbon_applies) { + if (!g.spec_dbon_applies) { /* since damage bonus didn't apply, nothing more to do; no further attacks have side-effects on inventory */ return FALSE; @@ -1258,7 +1253,7 @@ int dieroll; /* needed for Magicbane and vorpal blades */ } if (!youdefend) { /* allow normal cutworm() call to add extra damage */ - if (notonhead) + if (g.notonhead) return FALSE; if (bigmonst(mdef->data)) { @@ -1301,7 +1296,7 @@ int dieroll; /* needed for Magicbane and vorpal blades */ return FALSE; wepdesc = artilist[ART_VORPAL_BLADE].name; if (!youdefend) { - if (!has_head(mdef->data) || notonhead || u.uswallow) { + if (!has_head(mdef->data) || g.notonhead || u.uswallow) { if (youattack) pline("Somehow, you miss %s wildly.", mon_nam(mdef)); else if (vis) diff --git a/src/botl.c b/src/botl.c index 4fea3b64b..8510f3331 100644 --- a/src/botl.c +++ b/src/botl.c @@ -13,7 +13,6 @@ extern const char *hu_stat[]; /* defined in eat.c */ const char *const enc_stat[] = { "", "Burdened", "Stressed", "Strained", "Overtaxed", "Overloaded" }; -STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */ STATIC_DCL const char *NDECL(rank); #ifdef STATUS_HILITES STATIC_DCL void NDECL(bot_via_windowport); @@ -67,7 +66,7 @@ do_statusline1() Strcpy(nb = eos(nb), rank()); Sprintf(nb = eos(nb), " "); - i = mrank_sz + 15; + i = g.mrank_sz + 15; j = (int) ((nb + 2) - newbot1); /* strlen(newbot1) but less computation */ if ((i - j) > 0) Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */ @@ -349,7 +348,7 @@ max_rank_sz() if (urole.rank[i].f && (r = strlen(urole.rank[i].f)) > maxr) maxr = r; } - mrank_sz = maxr; + g.mrank_sz = maxr; return; } diff --git a/src/cmd.c b/src/cmd.c index f05787fe3..c7098c134 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -5785,8 +5785,7 @@ char def; { char res, qbuf[QBUFSZ]; #ifdef DUMPLOG - extern unsigned saved_pline_index; /* pline.c */ - unsigned idx = saved_pline_index; + unsigned idx = g.saved_pline_index; /* buffer to hold query+space+formatted_single_char_response */ char dumplog_buf[QBUFSZ + 1 + 15]; /* [QBUFSZ+1+7] should suffice */ #endif @@ -5803,7 +5802,7 @@ char def; } res = (*windowprocs.win_yn_function)(query, resp, def); #ifdef DUMPLOG - if (idx == saved_pline_index) { + if (idx == g.saved_pline_index) { /* when idx is still the same as saved_pline_index, the interface didn't put the prompt into saved_plines[]; we put a simplified version in there now (without response choices or default) */ diff --git a/src/decl.c b/src/decl.c index e9ab7fcb5..25e02a2ac 100644 --- a/src/decl.c +++ b/src/decl.c @@ -285,7 +285,7 @@ char *fqn_prefix_names[PREFIX_COUNT] = { }; #endif -NEARDATA struct savefile_info sfcap = { +const struct savefile_info default_sfinfo = { #ifdef NHSTDC 0x00000000UL #else @@ -308,28 +308,7 @@ NEARDATA struct savefile_info sfcap = { #endif }; -NEARDATA struct savefile_info sfrestinfo, sfsaveinfo = { -#ifdef NHSTDC - 0x00000000UL -#else - 0x00000000L -#endif -#if defined(COMPRESS) || defined(ZLIB_COMP) - | SFI1_EXTERNALCOMP -#endif -#if defined(ZEROCOMP) - | SFI1_ZEROCOMP -#endif -#if defined(RLECOMP) - | SFI1_RLECOMP -#endif - , -#ifdef NHSTDC - 0x00000000UL, 0x00000000UL -#else - 0x00000000L, 0x00000000L -#endif -}; +NEARDATA struct savefile_info sfcap, sfrestinfo, sfsaveinfo; struct plinemsg_type *plinemsg_types = (struct plinemsg_type *) 0; @@ -340,11 +319,111 @@ const char *ARGV0; /* support for lint.h */ unsigned nhUse_dummy = 0; -/* dummy routine used to force linkage */ -void -decl_init() +#define IVMAGIC 0xdeadbeef + +const struct instance_globals g_init = { + /* apply.c */ + 0, /* jumping_is_magic */ + -1, /* polearm_range_min */ + -1, /* polearm_range_max */ + + /* artifact.c */ + 0, /* spec_dbon_applies */ + + /* botl.c */ + 0, /* mrank_sz */ + + /* dog.c */ + 0, /* petname_used */ + + /* mused.c */ + FALSE, /* m_using */ + + /* objname.c */ + 0, /* distantname */ + + /* pickup.c */ + 0, /* oldcap */ + UNDEFINED_PTR, /* current_container */ + UNDEFINED_VALUE, /* abort_looting */ + + /* pline.c */ + 0, /* pline_flags */ + UNDEFINED_VALUES, /* prevmsg */ +#ifdef DUMPLOG + 0, /* saved_pline_index */ + UNDEFINED_VALUES, +#endif + + /* polyself.c */ + 0, /* sex_change_ok */ + + /* potion.c */ + FALSE, /* notonhead */ + UNDEFINED_VALUE, /* potion_nothing */ + UNDEFINED_VALUE, /* potion_unkn */ + + /* read.c */ + UNDEFINED_VALUE, /* known */ + + /* restore.c */ + 0, /* n_ids_mapped */ + 0, /* id_map */ + FALSE, /* restoring */ + UNDEFINED_PTR, /* oldfruit */ + UNDEFINED_VALUE, /* omoves */ + + /* rumors.c */ + 0, /* true_rumor_size */ + 0, /* false_rumor_size */ + UNDEFINED_VALUE, /* true_rumor_start*/ + UNDEFINED_VALUE, /* false_rumor_start*/ + UNDEFINED_VALUE, /* true_rumor_end */ + UNDEFINED_VALUE, /* false_rumor_end */ + 0, /* oracle_flag */ + 0, /* oracle_cnt */ + NULL, /* oracle_loc */ + + /* save.c */ + TRUE, /* havestate*/ + 0, /* ustuck_id */ + 0, /* usteed_id */ + + /* trap.c */ + 0, /* force_mintrap */ + + /* u_init.c */ + STRANGE_OBJECT, /* nocreate */ + STRANGE_OBJECT, /* nocreate2 */ + STRANGE_OBJECT, /* nocreate3 */ + STRANGE_OBJECT, /* nocreate4 */ + + /* uhitm.c */ + UNDEFINED_VALUE, /* override_confirmation */ + + /* weapon.c */ + UNDEFINED_PTR, /* propellor */ + + /* zap.c */ + UNDEFINED_VALUE, /* poly_zap */ + UNDEFINED_VALUE, /* obj_zapped */ + + IVMAGIC /* used to validate that structure layout has been preserved */ +}; + +struct instance_globals g; + +void +decl_globals_init() { - return; + g = g_init; + + nhassert(g_init.magic == IVMAGIC); + nhassert(g_init.havestate == TRUE); + + sfcap = default_sfinfo; + sfrestinfo = default_sfinfo; + sfsaveinfo = default_sfinfo; } /*decl.c*/ diff --git a/src/detect.c b/src/detect.c index e6c5778af..2c05cc937 100644 --- a/src/detect.c +++ b/src/detect.c @@ -11,8 +11,6 @@ #include "hack.h" #include "artifact.h" -extern boolean known; /* from read.c */ - STATIC_DCL boolean NDECL(unconstrain_map); STATIC_DCL void NDECL(reconstrain_map); STATIC_DCL void FDECL(browse_map, (int, const char *)); @@ -307,7 +305,7 @@ register struct obj *sobj; boolean stale, ugold = FALSE, steedgold = FALSE; int ter_typ = TER_DETECT | TER_OBJ; - known = stale = clear_stale_map(COIN_CLASS, + g.known = stale = clear_stale_map(COIN_CLASS, (unsigned) (sobj->blessed ? GOLD : 0)); /* look for gold carried by monsters (might be in a container) */ @@ -318,7 +316,7 @@ register struct obj *sobj; if (mtmp == u.usteed) { steedgold = TRUE; } else { - known = TRUE; + g.known = TRUE; goto outgoldmap; /* skip further searching */ } } else { @@ -328,7 +326,7 @@ register struct obj *sobj; if (mtmp == u.usteed) { steedgold = TRUE; } else { - known = TRUE; + g.known = TRUE; goto outgoldmap; /* skip further searching */ } } @@ -338,17 +336,17 @@ register struct obj *sobj; /* look for gold objects */ for (obj = fobj; obj; obj = obj->nobj) { if (sobj->blessed && o_material(obj, GOLD)) { - known = TRUE; + g.known = TRUE; if (obj->ox != u.ux || obj->oy != u.uy) goto outgoldmap; } else if (o_in(obj, COIN_CLASS)) { - known = TRUE; + g.known = TRUE; if (obj->ox != u.ux || obj->oy != u.uy) goto outgoldmap; } } - if (!known) { + if (!g.known) { /* no gold found on floor or monster's inventory. adjust message if you have gold in your inventory */ if (sobj) { @@ -484,7 +482,7 @@ register struct obj *sobj; } if (!ct && !ctu) { - known = stale && !confused; + g.known = stale && !confused; if (stale) { docrt(); You("sense a lack of %s nearby.", what); @@ -512,7 +510,7 @@ register struct obj *sobj; } return !stale; } else if (!ct) { - known = TRUE; + g.known = TRUE; You("%s %s nearby.", sobj ? "smell" : "sense", what); if (sobj && sobj->blessed) { if (!u.uedibility) @@ -523,7 +521,7 @@ register struct obj *sobj; struct obj *temp; int ter_typ = TER_DETECT | TER_OBJ; - known = TRUE; + g.known = TRUE; cls(); (void) unconstrain_map(); for (obj = fobj; obj; obj = obj->nobj) diff --git a/src/dog.c b/src/dog.c index 93a33716e..be4ab472c 100644 --- a/src/dog.c +++ b/src/dog.c @@ -160,7 +160,6 @@ makedog() register struct obj *otmp; const char *petname; int pettype; - static int petname_used = 0; if (preferred_pet == 'n') return ((struct monst *) 0); @@ -198,7 +197,7 @@ makedog() put_saddle_on_mon(otmp, mtmp); } - if (!petname_used++ && *petname) + if (!g.petname_used++ && *petname) mtmp = christen_monst(mtmp, petname); initedog(mtmp); diff --git a/src/dogmove.c b/src/dogmove.c index 1c8f4dd79..c67d61e23 100644 --- a/src/dogmove.c +++ b/src/dogmove.c @@ -7,8 +7,6 @@ #include "mfndpos.h" -extern boolean notonhead; - STATIC_DCL boolean FDECL(dog_hunger, (struct monst *, struct edog *)); STATIC_DCL int FDECL(dog_invent, (struct monst *, struct edog *, int)); STATIC_DCL int FDECL(dog_goal, (struct monst *, struct edog *, int, int, int)); @@ -1023,7 +1021,7 @@ int after; /* this is extra fast monster movement */ if (after) return 0; /* hit only once each move */ - notonhead = 0; + g.notonhead = 0; mstatus = mattackm(mtmp, mtmp2); /* aggressor (pet) died */ diff --git a/src/dokick.c b/src/dokick.c index 68eb49c24..62524a845 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -14,8 +14,6 @@ static NEARDATA const char *gate_str; /* kickedobj (decl.c) tracks a kicked object until placed or destroyed */ -extern boolean notonhead; /* for long worms */ - STATIC_DCL void FDECL(kickdmg, (struct monst *, BOOLEAN_P)); STATIC_DCL boolean FDECL(maybe_kick_monster, (struct monst *, XCHAR_P, XCHAR_P)); @@ -679,7 +677,7 @@ xchar x, y; if (mon->isshk && kickedobj->where == OBJ_MINVENT && kickedobj->ocarry == mon) return 1; /* alert shk caught it */ - notonhead = (mon->mx != bhitpos.x || mon->my != bhitpos.y); + g.notonhead = (mon->mx != bhitpos.x || mon->my != bhitpos.y); if (isgold ? ghitm(mon, kickedobj) /* caught? */ : thitmonst(mon, kickedobj)) /* hit && used up? */ return 1; diff --git a/src/dothrow.c b/src/dothrow.c index b3a2f8ba4..813c39edf 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -28,8 +28,6 @@ static NEARDATA const char bullets[] = { ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, /* thrownobj (decl.c) tracks an object until it lands */ -extern boolean notonhead; /* for long worms */ - /* Throw the selected object, asking for direction */ STATIC_OVL int throw_obj(obj, shotlimit) @@ -1100,7 +1098,7 @@ boolean twoweap; /* used to restore twoweapon mode if wielded weapon returns */ || Hallucination || Fumbling); boolean tethered_weapon = (obj->otyp == AKLYS && (wep_mask & W_WEP) != 0); - notonhead = FALSE; /* reset potentially stale value */ + g.notonhead = FALSE; /* reset potentially stale value */ if ((obj->cursed || obj->greased) && (u.dx || u.dy) && !rn2(7)) { boolean slipok = TRUE; @@ -1273,7 +1271,7 @@ boolean twoweap; /* used to restore twoweapon mode if wielded weapon returns */ return; /* alert shk caught it */ } (void) snuff_candle(obj); - notonhead = (bhitpos.x != mon->mx || bhitpos.y != mon->my); + g.notonhead = (bhitpos.x != mon->mx || bhitpos.y != mon->my); obj_gone = thitmonst(mon, obj); /* Monster may have been tamed; this frees old mon */ mon = m_at(bhitpos.x, bhitpos.y); diff --git a/src/eat.c b/src/eat.c index 94a86568a..69077934b 100644 --- a/src/eat.c +++ b/src/eat.c @@ -101,7 +101,7 @@ register struct obj *obj; || (obj->otyp == EGG)); if (u.umonnum == PM_GELATINOUS_CUBE && is_organic(obj) - /* [g.cubes can eat containers and retain all contents + /* [g-cubes can eat containers and retain all contents as engulfed items, but poly'd player can't do that] */ && !Has_contents(obj)) return TRUE; diff --git a/src/end.c b/src/end.c index b89eee7e9..33539c91a 100644 --- a/src/end.c +++ b/src/end.c @@ -684,14 +684,12 @@ dump_plines() { int i, j; char buf[BUFSZ], **strp; - extern char *saved_plines[]; - extern unsigned saved_pline_index; Strcpy(buf, " "); /* one space for indentation */ putstr(0, 0, "Latest messages:"); - for (i = 0, j = (int) saved_pline_index; i < DUMPLOG_MSG_COUNT; + for (i = 0, j = (int) g.saved_pline_index; i < DUMPLOG_MSG_COUNT; ++i, j = (j + 1) % DUMPLOG_MSG_COUNT) { - strp = &saved_plines[j]; + strp = &g.saved_plines[j]; if (*strp) { copynchars(&buf[1], *strp, BUFSZ - 1 - 1); putstr(0, 0, buf); diff --git a/src/hack.c b/src/hack.c index 362a4c78a..3e1ff2401 100644 --- a/src/hack.c +++ b/src/hack.c @@ -1155,10 +1155,10 @@ int x,y; int tx = u.tx; int ty = u.ty; boolean ret; - int g = glyph_at(x,y); + int glyph = glyph_at(x,y); if (x == u.ux && y == u.uy) return TRUE; - if (isok(x,y) && glyph_is_cmap(g) && S_stone == glyph_to_cmap(g) + if (isok(x,y) && glyph_is_cmap(glyph) && S_stone == glyph_to_cmap(glyph) && !levl[x][y].seenv) return FALSE; u.tx = x; diff --git a/src/hacklib.c b/src/hacklib.c index d0c6915f0..a6facde7b 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -1008,33 +1008,33 @@ char *buf; int k; time_t timeresult = (time_t) 0; struct tm t, *lt; - char *g, *p, y[5], mo[3], md[3], h[3], mi[3], s[3]; + char *d, *p, y[5], mo[3], md[3], h[3], mi[3], s[3]; if (buf && strlen(buf) == 14) { - g = buf; + d = buf; p = y; /* year */ for (k = 0; k < 4; ++k) - *p++ = *g++; + *p++ = *d++; *p = '\0'; p = mo; /* month */ for (k = 0; k < 2; ++k) - *p++ = *g++; + *p++ = *d++; *p = '\0'; p = md; /* day */ for (k = 0; k < 2; ++k) - *p++ = *g++; + *p++ = *d++; *p = '\0'; p = h; /* hour */ for (k = 0; k < 2; ++k) - *p++ = *g++; + *p++ = *d++; *p = '\0'; p = mi; /* minutes */ for (k = 0; k < 2; ++k) - *p++ = *g++; + *p++ = *d++; *p = '\0'; p = s; /* seconds */ for (k = 0; k < 2; ++k) - *p++ = *g++; + *p++ = *d++; *p = '\0'; lt = getlt(); if (lt) { diff --git a/src/mhitm.c b/src/mhitm.c index 3d516efe4..9be07a89a 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -6,8 +6,6 @@ #include "hack.h" #include "artifact.h" -extern boolean notonhead; - static NEARDATA boolean vis, far_noise; static NEARDATA long noisetime; static NEARDATA struct obj *otmp; @@ -161,7 +159,7 @@ register struct monst *mtmp; /* mtmp can be killed */ bhitpos.x = mon->mx; bhitpos.y = mon->my; - notonhead = 0; + g.notonhead = 0; result = mattackm(mtmp, mon); if (result & MM_AGR_DIED) @@ -179,7 +177,7 @@ register struct monst *mtmp; if ((result & MM_HIT) && !(result & MM_DEF_DIED) && rn2(4) && mon->movement >= NORMAL_SPEED) { mon->movement -= NORMAL_SPEED; - notonhead = 0; + g.notonhead = 0; (void) mattackm(mon, mtmp); /* return attack */ } @@ -1334,7 +1332,7 @@ register struct attack *mattk; } break; case AD_DRIN: - if (notonhead || !has_head(pd)) { + if (g.notonhead || !has_head(pd)) { if (vis && canspotmon(mdef)) pline("%s doesn't seem harmed.", Monnam(mdef)); /* Not clear what to do for green slimes */ diff --git a/src/mon.c b/src/mon.c index de037e42b..aea39c7a7 100644 --- a/src/mon.c +++ b/src/mon.c @@ -945,7 +945,7 @@ struct monst *mtmp; /* eat organic objects, including cloth and wood, if present; engulf others, except huge rocks and metal attached to player - [despite comment at top, doesn't assume that eater is a g.cube] */ + [despite comment at top, doesn't assume that eater is a g-cube] */ for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) { otmp2 = otmp->nexthere; @@ -1020,7 +1020,7 @@ struct monst *mtmp; register struct obj *otmp3; /* contents of eaten containers become engulfed; this - is arbitrary, but otherwise g.cubes are too powerful */ + is arbitrary, but otherwise g-cubes are too powerful */ while ((otmp3 = otmp->cobj) != 0) { obj_extract_self(otmp3); if (otmp->otyp == ICE_BOX && otmp3->otyp == CORPSE) { diff --git a/src/monmove.c b/src/monmove.c index fbc2d419d..5795c6ecb 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -7,8 +7,6 @@ #include "mfndpos.h" #include "artifact.h" -extern boolean notonhead; - STATIC_DCL void FDECL(watch_on_duty, (struct monst *)); STATIC_DCL int FDECL(disturb, (struct monst *)); STATIC_DCL void FDECL(release_hero, (struct monst *)); @@ -858,7 +856,7 @@ register int after; */ if ((dist2(mtmp->mx, mtmp->my, tx, ty) < 2) && intruder && (intruder != mtmp)) { - notonhead = (intruder->mx != tx || intruder->my != ty); + g.notonhead = (intruder->mx != tx || intruder->my != ty); if (mattackm(mtmp, intruder) == 2) return 2; mmoved = 1; @@ -1203,7 +1201,7 @@ not_special: int mstatus; mtmp2 = m_at(nix, niy); - notonhead = mtmp2 && (nix != mtmp2->mx || niy != mtmp2->my); + g.notonhead = mtmp2 && (nix != mtmp2->mx || niy != mtmp2->my); /* note: mstatus returns 0 if mtmp2 is nonexistent */ mstatus = mattackm(mtmp, mtmp2); @@ -1213,7 +1211,7 @@ not_special: if ((mstatus & MM_HIT) && !(mstatus & MM_DEF_DIED) && rn2(4) && mtmp2->movement >= NORMAL_SPEED) { mtmp2->movement -= NORMAL_SPEED; - notonhead = 0; + g.notonhead = 0; mstatus = mattackm(mtmp2, mtmp); /* return attack */ if (mstatus & MM_DEF_DIED) return 2; diff --git a/src/mthrowu.c b/src/mthrowu.c index 588a516c8..12b251b54 100644 --- a/src/mthrowu.c +++ b/src/mthrowu.c @@ -26,7 +26,6 @@ STATIC_OVL NEARDATA const char *breathwep[] = { "strange breath #9" }; -extern boolean notonhead; /* for long worms */ STATIC_VAR int mesg_given; /* for m_throw()/thitu() 'miss' message */ /* hero is hit by something other than a monster */ @@ -312,7 +311,7 @@ boolean verbose; /* give message(s) even when you can't see what happened */ int objgone = 1; struct obj *mon_launcher = archer ? MON_WEP(archer) : NULL; - notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); + g.notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); ismimic = mtmp->m_ap_type && mtmp->m_ap_type != M_AP_MONSTER; vis = cansee(bhitpos.x, bhitpos.y); @@ -477,7 +476,7 @@ struct obj *obj; /* missile (or stack providing it) */ bhitpos.x = x; bhitpos.y = y; - notonhead = FALSE; /* reset potentially stale value */ + g.notonhead = FALSE; /* reset potentially stale value */ if (obj->quan == 1L) { /* diff --git a/src/muse.c b/src/muse.c index 94b0350ad..394b6327e 100644 --- a/src/muse.c +++ b/src/muse.c @@ -8,8 +8,6 @@ #include "hack.h" -boolean m_using = FALSE; - /* Let monsters use magic items. Arbitrary assumptions: Monsters only use * scrolls when they can see, monsters know when wands have 0 charges, * monsters cannot recognize if items are cursed are not, monsters which @@ -670,12 +668,12 @@ struct monst *mtmp; zap_oseen = oseen; mzapmsg(mtmp, otmp, FALSE); otmp->spe--; - m_using = TRUE; + g.m_using = TRUE; mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp); /* monster learns that teleportation isn't useful here */ if (level.flags.noteleport) mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1)); - m_using = FALSE; + g.m_using = FALSE; return 2; case MUSE_SCR_TELEPORTATION: { int obj_is_cursed = otmp->cursed; @@ -1399,11 +1397,11 @@ struct monst *mtmp; otmp->spe--; if (oseen) makeknown(otmp->otyp); - m_using = TRUE; + g.m_using = TRUE; buzz((int) (-30 - (otmp->otyp - WAN_MAGIC_MISSILE)), (otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6, mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx), sgn(mtmp->muy - mtmp->my)); - m_using = FALSE; + g.m_using = FALSE; return (DEADMONSTER(mtmp)) ? 1 : 2; case MUSE_FIRE_HORN: case MUSE_FROST_HORN: @@ -1413,20 +1411,20 @@ struct monst *mtmp; } else You_hear("a horn being played."); otmp->spe--; - m_using = TRUE; + g.m_using = TRUE; buzz(-30 - ((otmp->otyp == FROST_HORN) ? AD_COLD - 1 : AD_FIRE - 1), rn1(6, 6), mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx), sgn(mtmp->muy - mtmp->my)); - m_using = FALSE; + g.m_using = FALSE; return (DEADMONSTER(mtmp)) ? 1 : 2; case MUSE_WAN_TELEPORTATION: case MUSE_WAN_STRIKING: zap_oseen = oseen; mzapmsg(mtmp, otmp, FALSE); otmp->spe--; - m_using = TRUE; + g.m_using = TRUE; mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp); - m_using = FALSE; + g.m_using = FALSE; return 2; case MUSE_SCR_EARTH: { /* TODO: handle steeds */ diff --git a/src/objects.c b/src/objects.c index fcca3b0f7..984a67e3e 100644 --- a/src/objects.c +++ b/src/objects.c @@ -61,7 +61,7 @@ struct monst { struct monst *dummy; }; /* lint: struct obj's union */ cost,sdam,ldam,oc1,oc2,nut,color) { obj } #define None (char *) 0 /* less visual distraction for 'no description' */ -NEARDATA struct objdescr obj_descr[] = +NEARDATA struct objdescr obj_descr_init[] = #else /* second pass -- object definitions */ #define BITS(nmkn,mrg,uskn,ctnr,mgc,chrg,uniq,nwsh,big,tuf,dir,sub,mtrl) \ @@ -75,7 +75,7 @@ NEARDATA struct objdescr obj_descr[] = #define HARDGEM(n) (0) #endif -NEARDATA struct objclass objects[] = +NEARDATA struct objclass obj_init[] = #endif { /* dummy object[0] -- description [2nd arg] *must* be NULL */ @@ -1169,13 +1169,14 @@ OBJECT(OBJ(None, None), /* clang-format on */ /* *INDENT-ON* */ -void NDECL(objects_init); +struct objdescr obj_descr[SIZE(obj_descr_init)]; +struct objclass objects[SIZE(obj_init)]; -/* dummy routine used to force linkage */ void -objects_init() +objects_globals_init() { - return; + memcpy(obj_descr, obj_descr_init, sizeof(obj_descr)); + memcpy(objects, obj_init, sizeof(objects)); } #endif /* !OBJECTS_PASS_2_ */ diff --git a/src/objnam.c b/src/objnam.c index 6a805852d..7d71725b7 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -211,11 +211,6 @@ struct obj *obj; return TRUE; } -/* used by distant_name() to pass extra information to xname_flags(); - it would be much cleaner if this were a parameter, but that would - require all of the xname() and doname() calls to be modified */ -static int distantname = 0; - /* Give the name of an object seen at a distance. Unlike xname/doname, * we don't want to set dknown if it's not set already. */ @@ -234,9 +229,9 @@ char *FDECL((*func), (OBJ_P)); * object is within X-ray radius and only treat it as distant when * beyond that radius. Logic is iffy but result might be interesting. */ - ++distantname; + ++g.distantname; str = (*func)(obj); - --distantname; + --g.distantname; return str; } @@ -426,7 +421,7 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ */ if (!nn && ocl->oc_uses_known && ocl->oc_unique) obj->known = 0; - if (!Blind && !distantname) + if (!Blind && !g.distantname) obj->dknown = TRUE; if (Role_if(PM_PRIEST)) obj->bknown = TRUE; @@ -1203,7 +1198,7 @@ unsigned doname_flags; } /* treat 'restoring' like suppress_price because shopkeeper and bill might not be available yet while restore is in progress */ - if (!iflags.suppress_price && !restoring && is_unpaid(obj)) { + if (!iflags.suppress_price && !g.restoring && is_unpaid(obj)) { long quotedprice = unpaid_cost(obj, TRUE); Sprintf(eos(bp), " (%s, %ld %s)", @@ -3385,21 +3380,21 @@ retry: } else if (!strcmpi(bp, "looking glass")) { ; /* avoid false hit on "* glass" */ } else if (!BSTRCMPI(bp, p - 6, " glass") || !strcmpi(bp, "glass")) { - register char *g = bp; + register char *s = bp; /* treat "broken glass" as a non-existent item; since "broken" is also a chest/box prefix it might have been stripped off above */ - if (broken || strstri(g, "broken")) + if (broken || strstri(s, "broken")) return (struct obj *) 0; - if (!strncmpi(g, "worthless ", 10)) - g += 10; - if (!strncmpi(g, "piece of ", 9)) - g += 9; - if (!strncmpi(g, "colored ", 8)) - g += 8; - else if (!strncmpi(g, "coloured ", 9)) - g += 9; - if (!strcmpi(g, "glass")) { /* choose random color */ + if (!strncmpi(s, "worthless ", 10)) + s += 10; + if (!strncmpi(s, "piece of ", 9)) + s += 9; + if (!strncmpi(s, "colored ", 8)) + s += 8; + else if (!strncmpi(s, "coloured ", 9)) + s += 9; + if (!strcmpi(s, "glass")) { /* choose random color */ /* 9 different kinds */ typ = LAST_GEM + rnd(9); if (objects[typ].oc_class == GEM_CLASS) @@ -3410,7 +3405,7 @@ retry: char tbuf[BUFSZ]; Strcpy(tbuf, "worthless piece of "); - Strcat(tbuf, g); /* assume it starts with the color */ + Strcat(tbuf, s); /* assume it starts with the color */ Strcpy(bp, tbuf); } } diff --git a/src/pickup.c b/src/pickup.c index 65a541d12..4127ade6b 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -54,12 +54,7 @@ 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) -/* 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) +#define Icebox (g.current_container->otyp == ICE_BOX) static const char moderateloadmsg[] = "You have a little trouble lifting", @@ -1573,10 +1568,9 @@ struct obj *otmp; int encumber_msg() { - static int oldcap = UNENCUMBERED; int newcap = near_capacity(); - if (oldcap < newcap) { + if (g.oldcap < newcap) { switch (newcap) { case 1: Your("movements are slowed slightly because of your load."); @@ -1594,7 +1588,7 @@ encumber_msg() break; } context.botl = 1; - } else if (oldcap > newcap) { + } else if (g.oldcap > newcap) { switch (newcap) { case 0: Your("movements are now unencumbered."); @@ -1613,7 +1607,7 @@ encumber_msg() context.botl = 1; } - oldcap = newcap; + g.oldcap = newcap; return newcap; } @@ -1713,7 +1707,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); - abort_looting = TRUE; + g.abort_looting = TRUE; return 1; } @@ -1738,7 +1732,7 @@ doloot() boolean prev_loot = FALSE; int num_conts = 0; - abort_looting = FALSE; + g.abort_looting = FALSE; if (check_capacity((char *) 0)) { /* "Can't do that while carrying so much stuff." */ @@ -1809,7 +1803,7 @@ doloot() for (i = 1; i <= n; i++) { cobj = pick_list[i - 1].item.a_obj; timepassed |= do_loot_cont(&cobj, i, n); - if (abort_looting) { + if (g.abort_looting) { /* chest trap or magic bag explosion or */ free((genericptr_t) pick_list); return timepassed; @@ -1834,7 +1828,7 @@ doloot() anyfound = TRUE; timepassed |= do_loot_cont(&cobj, 1, 1); - if (abort_looting) + if (g.abort_looting) /* chest trap or magic bag explosion or */ return timepassed; } @@ -2094,17 +2088,17 @@ STATIC_PTR int in_container(obj) register struct obj *obj; { - boolean floor_container = !carried(current_container); + boolean floor_container = !carried(g.current_container); boolean was_unpaid = FALSE; char buf[BUFSZ]; - if (!current_container) { + if (!g.current_container) { impossible(" no current_container?"); return 0; } else if (obj == uball || obj == uchain) { You("must be kidding."); return 0; - } else if (obj == current_container) { + } else if (obj == g.current_container) { pline("That would be an interesting topological exercise."); return 0; } else if (obj->owornmask & (W_ARMOR | W_ACCESSORY)) { @@ -2159,7 +2153,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(current_container))); + You("cannot fit %s into %s.", buf, the(xname(g.current_container))); return 0; } @@ -2175,7 +2169,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(current_container->no_charge + sellobj_state(g.current_container->no_charge ? SELL_DONTSELL : SELL_DELIBERATE); sellobj(obj, u.ux, u.uy); sellobj_state(SELL_NORMAL); @@ -2192,7 +2186,7 @@ register struct obj *obj; if (rot_alarm) obj->norevive = 1; } - } else if (Is_mbag(current_container) && mbag_explodes(obj, 0)) { + } else if (Is_mbag(g.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)); @@ -2200,34 +2194,34 @@ register struct obj *obj; if (was_unpaid) addtobill(obj, FALSE, FALSE, TRUE); obfree(obj, (struct obj *) 0); - delete_contents(current_container); + delete_contents(g.current_container); if (!floor_container) - useup(current_container); - else if (obj_here(current_container, u.ux, u.uy)) - useupf(current_container, current_container->quan); + useup(g.current_container); + else if (obj_here(g.current_container, u.ux, u.uy)) + useupf(g.current_container, g.current_container->quan); else panic("in_container: bag not found."); losehp(d(6, 6), "magical explosion", KILLED_BY_AN); - current_container = 0; /* baggone = TRUE; */ + g.current_container = 0; /* baggone = TRUE; */ } - if (current_container) { - Strcpy(buf, the(xname(current_container))); + if (g.current_container) { + Strcpy(buf, the(xname(g.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, current_container->ox, current_container->oy); - (void) add_to_container(current_container, obj); - current_container->owt = weight(current_container); + 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); } /* 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 (current_container ? 1 : -1); + return (g.current_container ? 1 : -1); } /* askchain() filter used by in_container(); @@ -2239,7 +2233,7 @@ int ck_bag(obj) struct obj *obj; { - return (current_container && obj != current_container); + return (g.current_container && obj != g.current_container); } /* Returns: -1 to stop, 1 item was removed, 0 item was not removed. */ @@ -2252,7 +2246,7 @@ register struct obj *obj; int res, loadlev; long count; - if (!current_container) { + if (!g.current_container) { impossible(" no current_container?"); return -1; } else if (is_gold) { @@ -2266,7 +2260,7 @@ register struct obj *obj; return -1; count = obj->quan; - if ((res = lift_object(obj, current_container, &count, FALSE)) <= 0) + if ((res = lift_object(obj, g.current_container, &count, FALSE)) <= 0) return res; if (obj->quan != count && obj->otyp != LOADSTONE) @@ -2274,15 +2268,15 @@ register struct obj *obj; /* Remove the object from the list. */ obj_extract_self(obj); - current_container->owt = weight(current_container); + g.current_container->owt = weight(g.current_container); if (Icebox) removed_from_icebox(obj); - if (!obj->unpaid && !carried(current_container) - && costly_spot(current_container->ox, current_container->oy)) { - obj->ox = current_container->ox; - obj->oy = current_container->oy; + 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; addtobill(obj, FALSE, FALSE, FALSE); } if (is_pick(obj)) @@ -2409,7 +2403,7 @@ int FDECL((*fn), (OBJ_P)); { /* result is only meaningful while use_container() is executing */ return ((fn == in_container || fn == out_container) - && !current_container); + && !g.current_container); } STATIC_OVL void @@ -2473,7 +2467,7 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ int used = 0; long loss; - abort_looting = FALSE; + g.abort_looting = FALSE; emptymsg[0] = '\0'; if (!u_handsy()) @@ -2496,37 +2490,37 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ multi_reason = "opening a container"; nomovemsg = ""; } - abort_looting = TRUE; + g.abort_looting = TRUE; return 1; } obj->lknown = 1; - current_container = obj; /* for use by in/out_container */ + g.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(current_container); + quantum_cat = SchroedingersBox(g.current_container); if (quantum_cat) { - observe_quantum_cat(current_container, TRUE, TRUE); + observe_quantum_cat(g.current_container, TRUE, TRUE); used = 1; } - cursed_mbag = Is_mbag(current_container) - && current_container->cursed - && Has_contents(current_container); + cursed_mbag = Is_mbag(g.current_container) + && g.current_container->cursed + && Has_contents(g.current_container); if (cursed_mbag - && (loss = boh_loss(current_container, held)) != 0) { + && (loss = boh_loss(g.current_container, held)) != 0) { used = 1; You("owe %ld %s for lost merchandise.", loss, currency(loss)); - current_container->owt = weight(current_container); + g.current_container->owt = weight(g.current_container); } inokay = (invent != 0 - && !(invent == current_container && !current_container->nobj)); - outokay = Has_contents(current_container); + && !(invent == g.current_container && !g.current_container->nobj)); + outokay = Has_contents(g.current_container); if (!outokay) /* preformat the empty-container message */ - Sprintf(emptymsg, "%s is %sempty.", Ysimple_name2(current_container), + Sprintf(emptymsg, "%s is %sempty.", Ysimple_name2(g.current_container), (quantum_cat || cursed_mbag) ? "now " : ""); /* @@ -2556,13 +2550,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 || !current_container->cknown); + outmaybe = (outokay || !g.current_container->cknown); if (!outmaybe) (void) safe_qbuf(qbuf, (char *) 0, " is empty. Do what with it?", - current_container, Yname2, Ysimple_name2, + g.current_container, Yname2, Ysimple_name2, "This"); else - (void) safe_qbuf(qbuf, "Do what with ", "?", current_container, + (void) safe_qbuf(qbuf, "Do what with ", "?", g.current_container, yname, ysimple_name, "it"); /* ask player about what to do with this container */ if (flags.menu_style == MENU_PARTIAL @@ -2572,7 +2566,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, current_container, outmaybe, inokay, + c = in_or_out_menu(qbuf, g.current_container, outmaybe, inokay, (boolean) (used != 0), more_containers); } } else { /* TRADITIONAL or COMBINATION */ @@ -2599,15 +2593,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 (!current_container->cknown) + if (!g.current_container->cknown) used = 1; /* gaining info */ - container_contents(current_container, FALSE, FALSE, TRUE); + container_contents(g.current_container, FALSE, FALSE, TRUE); } else break; } /* loop until something other than '?' or ':' is picked */ if (c == 'q') - abort_looting = TRUE; + g.abort_looting = TRUE; if (c == 'n' || c == 'q') /* [not strictly needed; falling thru works] */ goto containerdone; loot_out = (c == 'o' || c == 'b' || c == 'r'); @@ -2617,11 +2611,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(current_container)) { + if (!Has_contents(g.current_container)) { pline1(emptymsg); /* is empty. */ - if (!current_container->cknown) + if (!g.current_container->cknown) used = 1; - current_container->cknown = 1; + g.current_container->cknown = 1; } else { add_valid_menu_class(0); /* reset */ if (flags.menu_style == MENU_TRADITIONAL) @@ -2633,7 +2627,7 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ } if ((loot_in || stash_one) - && (!invent || (invent == current_container && !invent->nobj))) { + && (!invent || (invent == g.current_container && !invent->nobj))) { You("don't have anything%s to %s.", invent ? " else" : "", stash_one ? "stash" : "put in"); loot_in = stash_one = FALSE; @@ -2663,16 +2657,16 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ } } /* putting something in might have triggered magic bag explosion */ - if (!current_container) + if (!g.current_container) loot_out = FALSE; /* out after in */ if (loot_out && loot_in_first) { - if (!Has_contents(current_container)) { + if (!Has_contents(g.current_container)) { pline1(emptymsg); /* is empty. */ - if (!current_container->cknown) + if (!g.current_container->cknown) used = 1; - current_container->cknown = 1; + g.current_container->cknown = 1; } else { add_valid_menu_class(0); /* reset */ if (flags.menu_style == MENU_TRADITIONAL) @@ -2689,16 +2683,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 (current_container) - current_container->cknown = 1; + if (g.current_container) + g.current_container->cknown = 1; update_inventory(); } - *objp = current_container; /* might have become null */ - if (current_container) - current_container = 0; /* avoid hanging on to stale pointer */ + *objp = g.current_container; /* might have become null */ + if (g.current_container) + g.current_container = 0; /* avoid hanging on to stale pointer */ else - abort_looting = TRUE; + g.abort_looting = TRUE; return used; } @@ -2721,7 +2715,7 @@ boolean put_in; checkfunc = ck_bag; } else { action = "take out"; - objlist = &(current_container->cobj); + objlist = &(g.current_container->cobj); actionfunc = out_container; checkfunc = (int FDECL((*), (OBJ_P))) 0; } @@ -2758,7 +2752,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 : current_container->cobj, + n = query_category(buf, put_in ? invent : g.current_container->cobj, mflags, &pick_list, PICK_ANY); if (!n) return 0; @@ -2775,8 +2769,8 @@ boolean put_in; if (loot_everything) { if (!put_in) { - current_container->cknown = 1; - for (otmp = current_container->cobj; otmp; otmp = otmp2) { + g.current_container->cknown = 1; + for (otmp = g.current_container->cobj; otmp; otmp = otmp2) { otmp2 = otmp->nobj; res = out_container(otmp); if (res < 0) @@ -2784,7 +2778,7 @@ boolean put_in; n_looted += res; } } else { - for (otmp = invent; otmp && current_container; otmp = otmp2) { + for (otmp = invent; otmp && g.current_container; otmp = otmp2) { otmp2 = otmp->nobj; res = in_container(otmp); if (res < 0) @@ -2797,9 +2791,9 @@ boolean put_in; if (put_in && flags.invlet_constant) mflags |= USE_INVLET; if (!put_in) - current_container->cknown = 1; + g.current_container->cknown = 1; Sprintf(buf, "%s what?", action); - n = query_objlist(buf, put_in ? &invent : &(current_container->cobj), + n = query_objlist(buf, put_in ? &invent : &(g.current_container->cobj), mflags, &pick_list, PICK_ANY, all_categories ? allow_all : allow_category); if (n) { @@ -2813,7 +2807,7 @@ boolean put_in; } res = put_in ? in_container(otmp) : out_container(otmp); if (res < 0) { - if (!current_container) { + if (!g.current_container) { /* otmp caused current_container to explode; both are now gone */ otmp = 0; /* and break loop */ diff --git a/src/pline.c b/src/pline.c index ebde8b145..d7acef096 100644 --- a/src/pline.c +++ b/src/pline.c @@ -6,18 +6,12 @@ #define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers */ #include "hack.h" -static unsigned pline_flags = 0; -static char prevmsg[BUFSZ]; - static char *FDECL(You_buf, (int)); #if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__)) static void FDECL(execplinehandler, (const char *)); #endif #ifdef DUMPLOG -/* also used in end.c */ -unsigned saved_pline_index = 0; /* slot in saved_plines[] to use next */ -char *saved_plines[DUMPLOG_MSG_COUNT] = { (char *) 0 }; /* keep the most recent DUMPLOG_MSG_COUNT messages */ void @@ -31,8 +25,8 @@ const char *line; * The core should take responsibility for that and have * this share it. */ - unsigned indx = saved_pline_index; /* next slot to use */ - char *oldest = saved_plines[indx]; /* current content of that slot */ + unsigned indx = g.saved_pline_index; /* next slot to use */ + char *oldest = g.saved_plines[indx]; /* current content of that slot */ if (oldest && strlen(oldest) >= strlen(line)) { /* this buffer will gradually shrink until the 'else' is needed; @@ -41,9 +35,9 @@ const char *line; } else { if (oldest) free((genericptr_t) oldest); - saved_plines[indx] = dupstr(line); + g.saved_plines[indx] = dupstr(line); } - saved_pline_index = (indx + 1) % DUMPLOG_MSG_COUNT; + g.saved_pline_index = (indx + 1) % DUMPLOG_MSG_COUNT; } /* called during save (unlike the interface-specific message history, @@ -55,9 +49,9 @@ dumplogfreemessages() unsigned indx; for (indx = 0; indx < DUMPLOG_MSG_COUNT; ++indx) - if (saved_plines[indx]) - free((genericptr_t) saved_plines[indx]), saved_plines[indx] = 0; - saved_pline_index = 0; + if (g.saved_plines[indx]) + free((genericptr_t) g.saved_plines[indx]), g.saved_plines[indx] = 0; + g.saved_pline_index = 0; } #endif @@ -139,7 +133,7 @@ VA_DECL(const char *, line) * Unfortunately, that means Norep() isn't honored (general issue) and * that short lines aren't combined into one longer one (tty behavior). */ - if ((pline_flags & SUPPRESS_HISTORY) == 0) + if ((g.pline_flags & SUPPRESS_HISTORY) == 0) dumplogmsg(line); #endif /* use raw_print() if we're called too early (or perhaps too late @@ -153,11 +147,11 @@ VA_DECL(const char *, line) } msgtyp = MSGTYP_NORMAL; - no_repeat = (pline_flags & PLINE_NOREPEAT) ? TRUE : FALSE; - if ((pline_flags & OVERRIDE_MSGTYPE) == 0) { + no_repeat = (g.pline_flags & PLINE_NOREPEAT) ? TRUE : FALSE; + if ((g.pline_flags & OVERRIDE_MSGTYPE) == 0) { msgtyp = msgtype_type(line, no_repeat); if (msgtyp == MSGTYP_NOSHOW - || (msgtyp == MSGTYP_NOREP && !strcmp(line, prevmsg))) + || (msgtyp == MSGTYP_NOREP && !strcmp(line, g.prevmsg))) /* FIXME: we need a way to tell our caller that this message * was suppressed so that caller doesn't set iflags.last_msg * for something that hasn't been shown, otherwise a subsequent @@ -181,7 +175,7 @@ VA_DECL(const char *, line) /* this gets cleared after every pline message */ iflags.last_msg = PLNMSG_UNKNOWN; - (void) strncpy(prevmsg, line, BUFSZ), prevmsg[BUFSZ - 1] = '\0'; + (void) strncpy(g.prevmsg, line, BUFSZ), g.prevmsg[BUFSZ - 1] = '\0'; if (msgtyp == MSGTYP_STOP) display_nhwindow(WIN_MESSAGE, TRUE); /* --more-- */ @@ -205,9 +199,9 @@ VA_DECL2(unsigned, pflags, const char *, line) { VA_START(line); VA_INIT(line, const char *); - pline_flags = pflags; + g.pline_flags = pflags; vpline(line, VA_ARGS); - pline_flags = 0; + g.pline_flags = 0; VA_END(); return; } @@ -218,9 +212,9 @@ VA_DECL(const char *, line) { VA_START(line); VA_INIT(line, const char *); - pline_flags = PLINE_NOREPEAT; + g.pline_flags = PLINE_NOREPEAT; vpline(line, VA_ARGS); - pline_flags = 0; + g.pline_flags = 0; VA_END(); return; } diff --git a/src/polyself.c b/src/polyself.c index e136d1898..15fe3d3ce 100644 --- a/src/polyself.c +++ b/src/polyself.c @@ -33,10 +33,6 @@ STATIC_DCL void NDECL(polysense); STATIC_VAR const char no_longer_petrify_resistant[] = "No longer petrify-resistant, you"; -/* controls whether taking on new form or becoming new man can also - change sex (ought to be an arg to polymon() and newman() instead) */ -STATIC_VAR int sex_change_ok = 0; - /* update the youmonst.data structure pointer and intrinsics */ void set_uasmon() @@ -296,7 +292,7 @@ newman() u.ulevelmax = newlvl; u.ulevel = newlvl; - if (sex_change_ok && !rn2(10)) + if (g.sex_change_ok && !rn2(10)) change_sex(); adjabil(oldlvl, (int) u.ulevel); @@ -573,14 +569,14 @@ int psflags; /* The below polyok() fails either if everything is genocided, or if * we deliberately chose something illegal to force newman(). */ - sex_change_ok++; + g.sex_change_ok++; if (!polyok(&mons[mntmp]) || (!forcecontrol && !rn2(5)) || your_race(&mons[mntmp])) { newman(); } else { (void) polymon(mntmp); } - sex_change_ok--; /* reset */ + g.sex_change_ok--; /* reset */ made_change: new_light = emits_light(youmonst.data); @@ -650,7 +646,7 @@ int mntmp; if (!flags.female) dochange = TRUE; } else if (!is_neuter(&mons[mntmp]) && mntmp != u.ulycn) { - if (sex_change_ok && !rn2(10)) + if (g.sex_change_ok && !rn2(10)) dochange = TRUE; } diff --git a/src/potion.c b/src/potion.c index a6bf5f656..74a028322 100644 --- a/src/potion.c +++ b/src/potion.c @@ -5,9 +5,6 @@ #include "hack.h" -boolean notonhead = FALSE; - -static NEARDATA int nothing, unkn; static NEARDATA const char beverages[] = { POTION_CLASS, 0 }; STATIC_DCL long FDECL(itimeout, (long)); @@ -548,17 +545,17 @@ register struct obj *otmp; int retval; otmp->in_use = TRUE; - nothing = unkn = 0; + g.potion_nothing = g.potion_unkn = 0; if ((retval = peffects(otmp)) >= 0) return retval; - if (nothing) { - unkn++; + if (g.potion_nothing) { + g.potion_unkn++; You("have a %s feeling for a moment, then it passes.", Hallucination ? "normal" : "peculiar"); } if (otmp->dknown && !objects[otmp->otyp].oc_name_known) { - if (!unkn) { + if (!g.potion_unkn) { makeknown(otmp->otyp); more_experienced(0, 10); } else if (!objects[otmp->otyp].oc_uname) @@ -577,7 +574,7 @@ register struct obj *otmp; switch (otmp->otyp) { case POT_RESTORE_ABILITY: case SPE_RESTORE_ABILITY: - unkn++; + g.potion_unkn++; if (otmp->cursed) { pline("Ulch! This makes you feel mediocre!"); break; @@ -617,7 +614,7 @@ register struct obj *otmp; break; case POT_HALLUCINATION: if (Hallucination || Halluc_resistance) - nothing++; + g.potion_nothing++; (void) make_hallucinated(itimeout_incr(HHallucination, rn1(200, 600 - 300 * bcsign(otmp))), TRUE, 0L); @@ -629,7 +626,7 @@ register struct obj *otmp; newuhs(FALSE); break; } - unkn++; + g.potion_unkn++; if (is_undead(youmonst.data) || is_demon(youmonst.data) || u.ualign.type == A_CHAOTIC) { if (otmp->blessed) { @@ -674,7 +671,7 @@ register struct obj *otmp; } break; case POT_BOOZE: - unkn++; + g.potion_unkn++; pline("Ooph! This tastes like %s%s!", otmp->odiluted ? "watered down " : "", Hallucination ? "dandelion wine" : "liquid fire"); @@ -694,7 +691,7 @@ register struct obj *otmp; break; case POT_ENLIGHTENMENT: if (otmp->cursed) { - unkn++; + g.potion_unkn++; You("have an uneasy feeling..."); exercise(A_WIS, FALSE); } else { @@ -718,7 +715,7 @@ register struct obj *otmp; /* FALLTHRU */ case POT_INVISIBILITY: if (Invis || Blind || BInvis) { - nothing++; + g.potion_nothing++; } else { self_invis_message(); } @@ -736,7 +733,7 @@ register struct obj *otmp; case POT_FRUIT_JUICE: { int msg = Invisible && !Blind; - unkn++; + g.potion_unkn++; if (otmp->cursed) pline("Yecch! This tastes %s.", Hallucination ? "overripe" : "rotten"); @@ -766,7 +763,7 @@ register struct obj *otmp; newsym(u.ux, u.uy); /* see yourself! */ if (msg && !Blind) { /* Blind possible if polymorphed */ You("can see through yourself, but you are visible!"); - unkn--; + g.potion_unkn--; } break; } @@ -801,8 +798,8 @@ register struct obj *otmp; int x, y; if (Detect_monsters) - nothing++; - unkn++; + g.potion_nothing++; + g.potion_unkn++; /* after a while, repeated uses become less effective */ if ((HDetect_monsters & TIMEOUT) >= 300L) i = 1; @@ -816,11 +813,11 @@ register struct obj *otmp; newsym(x, y); } if (MON_AT(x, y)) - unkn = 0; + g.potion_unkn = 0; } } see_monsters(); - if (unkn) + if (g.potion_unkn) You_feel("lonely."); break; } @@ -885,11 +882,11 @@ register struct obj *otmp; if (!Confusion) { if (Hallucination) { pline("What a trippy feeling!"); - unkn++; + g.potion_unkn++; } else pline("Huh, What? Where am I?"); } else - nothing++; + g.potion_nothing++; make_confused(itimeout_incr(HConfusion, rn1(7, 16 - 8 * bcsign(otmp))), FALSE); @@ -897,9 +894,9 @@ register struct obj *otmp; case POT_GAIN_ABILITY: if (otmp->cursed) { pline("Ulch! That potion tasted foul!"); - unkn++; + g.potion_unkn++; } else if (Fixed_abil) { - nothing++; + g.potion_nothing++; } else { /* If blessed, increase all; if not, try up to */ int itmp; /* 6 times to find one which can be increased. */ @@ -918,7 +915,7 @@ register struct obj *otmp; /* skip when mounted; heal_legs() would heal steed's legs */ if (Wounded_legs && !otmp->cursed && !u.usteed) { heal_legs(0); - unkn++; + g.potion_unkn++; break; } /* FALLTHRU */ @@ -927,21 +924,21 @@ register struct obj *otmp; You("are suddenly moving %sfaster.", Fast ? "" : "much "); } else { Your("%s get new energy.", makeplural(body_part(LEG))); - unkn++; + g.potion_unkn++; } exercise(A_DEX, TRUE); incr_itimeout(&HFast, rn1(10, 100 + 60 * bcsign(otmp))); break; case POT_BLINDNESS: if (Blind) - nothing++; + g.potion_nothing++; make_blinded(itimeout_incr(Blinded, rn1(200, 250 - 125 * bcsign(otmp))), (boolean) !Blind); break; case POT_GAIN_LEVEL: if (otmp->cursed) { - unkn++; + g.potion_unkn++; /* they went up a level */ if ((ledger_no(&u.uz) == 1 && u.uhave.amulet) || Can_rise_up(u.ux, u.uy, &u.uz)) { @@ -1019,7 +1016,7 @@ register struct obj *otmp; that cursed effect yields "you float down" on next turn. Blessed and uncursed get one extra turn duration. */ } else /* already levitating, or can't levitate */ - nothing++; + g.potion_nothing++; if (otmp->cursed) { /* 'already levitating' used to block the cursed effect(s) @@ -1034,7 +1031,7 @@ register struct obj *otmp; (void) doup(); /* in case we're already Levitating, which would have resulted in incrementing 'nothing' */ - nothing = 0; /* not nothing after all */ + g.potion_nothing = 0; /* not nothing after all */ } else if (has_ceiling(&u.uz)) { int dmg = rnd(!uarmh ? 10 : !is_metallic(uarmh) ? 6 : 3); @@ -1042,7 +1039,7 @@ register struct obj *otmp; ceiling(u.ux, u.uy)); losehp(Maybe_Half_Phys(dmg), "colliding with the ceiling", KILLED_BY); - nothing = 0; /* not nothing after all */ + g.potion_nothing = 0; /* not nothing after all */ } } else if (otmp->blessed) { /* at this point, timeout is already at least 1 */ @@ -1126,7 +1123,7 @@ register struct obj *otmp; } if (Stoned) fix_petrification(); - unkn++; /* holy/unholy water can burn like acid too */ + g.potion_unkn++; /* holy/unholy water can burn like acid too */ break; case POT_POLYMORPH: You_feel("a little %s.", Hallucination ? "normal" : "strange"); @@ -1325,7 +1322,7 @@ int how; FALSE))); } else if (has_head(mon->data)) { Sprintf(buf, "%s %s", s_suffix(mnam), - (notonhead ? "body" : "head")); + (g.notonhead ? "body" : "head")); } else { Strcpy(buf, mnam); } diff --git a/src/questpgr.c b/src/questpgr.c index cf6fbdd38..ede98b1bc 100644 --- a/src/questpgr.c +++ b/src/questpgr.c @@ -282,7 +282,7 @@ char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */ which; /* 'h'|'H'|'i'|'I'|'j'|'J' */ { const char *pnoun; - int g; + int godgend; char lwhich = lowc(which); /* H,I,J -> h,i,j */ /* @@ -298,13 +298,13 @@ char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */ : (lwhich == 'i') ? "them" : (lwhich == 'j') ? "their" : "?"; } else { - g = (who == 'd') ? quest_status.godgend + godgend = (who == 'd') ? quest_status.godgend : (who == 'l') ? quest_status.ldrgend : (who == 'n') ? quest_status.nemgend : 2; /* default to neuter */ - pnoun = (lwhich == 'h') ? genders[g].he - : (lwhich == 'i') ? genders[g].him - : (lwhich == 'j') ? genders[g].his : "?"; + pnoun = (lwhich == 'h') ? genders[godgend].he + : (lwhich == 'i') ? genders[godgend].him + : (lwhich == 'j') ? genders[godgend].his : "?"; } Strcpy(cvt_buf, pnoun); /* capitalize for H,I,J */ diff --git a/src/read.c b/src/read.c index f6b2c3092..8db74ba52 100644 --- a/src/read.c +++ b/src/read.c @@ -12,8 +12,6 @@ ((mndx) == urace.malenum \ || (urace.femalenum != NON_PM && (mndx) == urace.femalenum)) -boolean known; - static NEARDATA const char readable[] = { ALL_CLASSES, SCROLL_CLASS, SPBOOK_CLASS, 0 }; static const char all_count[] = { ALLOW_COUNT, ALL_CLASSES, 0 }; @@ -189,7 +187,7 @@ doread() register struct obj *scroll; boolean confused, nodisappear; - known = FALSE; + g.known = FALSE; if (check_capacity((char *) 0)) return 0; scroll = getobj(readable, "read"); @@ -396,7 +394,7 @@ doread() } if (!seffects(scroll)) { if (!objects[scroll->otyp].oc_name_known) { - if (known) + if (g.known) learnscroll(scroll); else if (!objects[scroll->otyp].oc_uname) docall(scroll); @@ -801,7 +799,7 @@ int howmuch; if (Sokoban) return; - known = TRUE; + g.known = TRUE; for (zx = 0; zx < COLNO; zx++) for (zy = 0; zy < ROWNO; zy++) if (howmuch & ALL_MAP || rn2(7)) { @@ -1013,7 +1011,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ switch (otyp) { #ifdef MAIL case SCR_MAIL: - known = TRUE; + g.known = TRUE; if (sobj->spe == 2) /* "stamped scroll" created via magic marker--without a stamp */ pline("This scroll is marked \"postage due\"."); @@ -1142,7 +1140,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ if (s) { otmp->spe += s; adj_abon(otmp, s); - known = otmp->known; + g.known = otmp->known; /* update shop bill to reflect new higher price */ if (s > 0 && otmp->unpaid) alter_cost(otmp, 0L); @@ -1184,7 +1182,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ exercise(A_CON, FALSE); break; } else - known = TRUE; + g.known = TRUE; } else { /* armor and scroll both cursed */ pline("%s.", Yobjnam2(otmp, "vibrate")); if (otmp->spe >= -6) { @@ -1264,7 +1262,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ You("don't remember there being any magic words on this scroll."); else pline("This scroll seems to be blank."); - known = TRUE; + g.known = TRUE; break; case SCR_REMOVE_CURSE: case SPE_REMOVE_CURSE: { @@ -1350,7 +1348,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ confused ? &mons[PM_ACID_BLOB] : (struct permonst *) 0, FALSE)) - known = TRUE; + g.known = TRUE; /* no need to flush monsters; we ask for identification only if the * monsters are not visible */ @@ -1430,14 +1428,14 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ vis_results ? "is" : "seems", (results < 0) ? "un" : ""); if (vis_results > 0) - known = TRUE; + g.known = TRUE; } break; } case SCR_GENOCIDE: if (!already_known) You("have found a scroll of genocide!"); - known = TRUE; + g.known = TRUE; if (sblessed) do_class_genocide(); else @@ -1446,11 +1444,11 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ case SCR_LIGHT: if (!confused || rn2(5)) { if (!Blind) - known = TRUE; + g.known = TRUE; litroom(!confused && !scursed, sobj); if (!confused && !scursed) { if (lightdamage(sobj, TRUE, 5)) - known = TRUE; + g.known = TRUE; } } else { /* could be scroll of create monster, don't set known ...*/ @@ -1463,7 +1461,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ if (confused || scursed) { level_tele(); } else { - known = scrolltele(sobj); + g.known = scrolltele(sobj); } break; case SCR_GOLD_DETECTION: @@ -1556,7 +1554,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ cvt_sdoor_to_door(&levl[x][y]); /* do_mapping() already reveals secret passages */ } - known = TRUE; + g.known = TRUE; /*FALLTHRU*/ case SPE_MAGIC_MAPPING: if (level.flags.nommap) { @@ -1576,7 +1574,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ } break; case SCR_AMNESIA: - known = TRUE; + g.known = TRUE; forget((!sblessed ? ALL_SPELLS : 0) | (!confused || scursed ? ALL_MAP : 0)); if (Hallucination) /* Ommmmmm! */ @@ -1657,7 +1655,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ else pline_The("%s rumbles %s you!", ceiling(u.ux, u.uy), sblessed ? "around" : "above"); - known = 1; + g.known = 1; sokoban_guilt(); /* Loop through the surrounding squares */ @@ -1682,7 +1680,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ } break; case SCR_PUNISHMENT: - known = TRUE; + g.known = TRUE; if (confused || sblessed) { You_feel("guilty."); break; @@ -1694,7 +1692,7 @@ struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ if (!already_known) You("have found a scroll of stinking cloud!"); - known = TRUE; + g.known = TRUE; pline("Where do you want to center the %scloud?", already_known ? "stinking " : ""); cc.x = u.ux; diff --git a/src/restore.c b/src/restore.c index e9f25d72c..c8afe7b80 100644 --- a/src/restore.c +++ b/src/restore.c @@ -72,9 +72,6 @@ struct bucket { STATIC_DCL void NDECL(clear_id_mapping); STATIC_DCL void FDECL(add_id_mapping, (unsigned, unsigned)); -static int n_ids_mapped = 0; -static struct bucket *id_map = 0; - #ifdef AMII_GRAPHICS void FDECL(amii_setpens, (int)); /* use colors from save file */ extern int amii_numcolors; @@ -82,10 +79,6 @@ extern int amii_numcolors; #include "display.h" -boolean restoring = FALSE; -static NEARDATA struct fruit *oldfruit; -static NEARDATA long omoves; - #define Is_IceBox(o) ((o)->otyp == ICE_BOX ? TRUE : FALSE) /* Recalculate level.objects[x][y], since this info was not saved. */ @@ -179,7 +172,7 @@ boolean ghostly; mread(fd, (genericptr_t) tmp_dam, sizeof(*tmp_dam)); if (ghostly) - tmp_dam->when += (monstermoves - omoves); + tmp_dam->when += (monstermoves - g.omoves); Strcpy(damaged_shops, in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE)); if (u.uz.dlevel) { @@ -293,7 +286,7 @@ boolean ghostly, frozen; * immediately after old player died. */ if (ghostly && !frozen && !age_is_relative(otmp)) - otmp->age = monstermoves - omoves + otmp->age; + otmp->age = monstermoves - g.omoves + otmp->age; /* get contents of a container or statue */ if (Has_contents(otmp)) { @@ -513,7 +506,7 @@ register struct obj *otmp; { register struct fruit *oldf; - for (oldf = oldfruit; oldf; oldf = oldf->nextf) + for (oldf = g.oldfruit; oldf; oldf = oldf->nextf) if (oldf->fid == otmp->spe) break; @@ -805,7 +798,7 @@ register int fd; int rtmp; struct obj *otmp; - restoring = TRUE; + g.restoring = TRUE; get_plname_from_file(fd, plname); getlev(fd, 0, (xchar) 0, FALSE); if (!restgamestate(fd, &stuckid, &steedid)) { @@ -813,7 +806,7 @@ register int fd; savelev(-1, 0, FREE_SAVE); /* discard current level */ (void) nhclose(fd); (void) delete_savefile(); - restoring = FALSE; + g.restoring = FALSE; return 0; } restlevelstate(stuckid, steedid); @@ -907,7 +900,7 @@ register int fd; #ifdef MFLOPPY gameDiskPrompt(); #endif - max_rank_sz(); /* to recompute mrank_sz (botl.c) */ + max_rank_sz(); /* to recompute g.mrank_sz (botl.c) */ /* take care of iron ball & chain */ for (otmp = fobj; otmp; otmp = otmp->nobj) if (otmp->owornmask) @@ -929,7 +922,7 @@ register int fd; run_timers(); /* expire all timers that have gone off while away */ docrt(); - restoring = FALSE; + g.restoring = FALSE; clear_nhwindow(WIN_MESSAGE); /* Success! */ @@ -1036,7 +1029,7 @@ boolean ghostly; * information is available when restoring the objects. */ if (ghostly) - oldfruit = loadfruitchn(fd); + g.oldfruit = loadfruitchn(fd); /* First some sanity checks */ mread(fd, (genericptr_t) &hpid, sizeof(hpid)); @@ -1063,8 +1056,8 @@ boolean ghostly; rest_levl(fd, (boolean) ((sfrestinfo.sfi1 & SFI1_RLECOMP) == SFI1_RLECOMP)); mread(fd, (genericptr_t) lastseentyp, sizeof(lastseentyp)); - mread(fd, (genericptr_t) &omoves, sizeof(omoves)); - elapsed = monstermoves - omoves; + mread(fd, (genericptr_t) &g.omoves, sizeof(g.omoves)); + elapsed = monstermoves - g.omoves; mread(fd, (genericptr_t) &upstair, sizeof(stairway)); mread(fd, (genericptr_t) &dnstair, sizeof(stairway)); mread(fd, (genericptr_t) &upladder, sizeof(stairway)); @@ -1140,7 +1133,7 @@ boolean ghostly; rest_regions(fd, ghostly); if (ghostly) { /* Now get rid of all the temp fruits... */ - freefruitchn(oldfruit), oldfruit = 0; + freefruitchn(g.oldfruit), g.oldfruit = 0; if (lev > ledger_no(&medusa_level) && lev < ledger_no(&stronghold_level) && xdnstair == 0) { @@ -1237,11 +1230,11 @@ clear_id_mapping() { struct bucket *curr; - while ((curr = id_map) != 0) { - id_map = curr->next; + while ((curr = g.id_map) != 0) { + g.id_map = curr->next; free((genericptr_t) curr); } - n_ids_mapped = 0; + g.n_ids_mapped = 0; } /* Add a mapping to the ID map. */ @@ -1251,18 +1244,18 @@ unsigned gid, nid; { int idx; - idx = n_ids_mapped % N_PER_BUCKET; + idx = g.n_ids_mapped % N_PER_BUCKET; /* idx is zero on first time through, as well as when a new bucket is */ /* needed */ if (idx == 0) { struct bucket *gnu = (struct bucket *) alloc(sizeof(struct bucket)); - gnu->next = id_map; - id_map = gnu; + gnu->next = g.id_map; + g.id_map = gnu; } - id_map->map[idx].gid = gid; - id_map->map[idx].nid = nid; - n_ids_mapped++; + g.id_map->map[idx].gid = gid; + g.id_map->map[idx].nid = nid; + g.n_ids_mapped++; } /* @@ -1277,11 +1270,11 @@ unsigned gid, *nidp; int i; struct bucket *curr; - if (n_ids_mapped) - for (curr = id_map; curr; curr = curr->next) { + if (g.n_ids_mapped) + for (curr = g.id_map; curr; curr = curr->next) { /* first bucket might not be totally full */ - if (curr == id_map) { - i = n_ids_mapped % N_PER_BUCKET; + if (curr == g.id_map) { + i = g.n_ids_mapped % N_PER_BUCKET; if (i == 0) i = N_PER_BUCKET; } else @@ -1631,7 +1624,7 @@ register unsigned int len; return; } else { pline("Read %d instead of %u bytes.", rlen, len); - if (restoring) { + if (g.restoring) { (void) nhclose(fd); (void) delete_savefile(); error("Error restoring old game."); diff --git a/src/role.c b/src/role.c index 69adcab7b..31b512349 100644 --- a/src/role.c +++ b/src/role.c @@ -769,7 +769,7 @@ const struct Align aligns[] = { static struct { boolean roles[SIZE(roles)]; short mask; -} rfilter; +} rfilter = { UNDEFINED_VALUES, UNDEFINED_VALUE}; STATIC_DCL int NDECL(randrole_filtered); STATIC_DCL char *FDECL(promptsep, (char *, int)); @@ -1757,11 +1757,11 @@ winid where; not_yet[] = " not yet specified", rand_choice[] = " random"; char buf[BUFSZ]; - int r, c, g, a, allowmask; + int r, c, gend, a, allowmask; r = flags.initrole; c = flags.initrace; - g = flags.initgend; + gend = flags.initgend; a = flags.initalign; if (r >= 0) { allowmask = roles[r].allow; @@ -1770,9 +1770,9 @@ winid where; else if (c >= 0 && !(allowmask & ROLE_RACEMASK & races[c].allow)) c = ROLE_RANDOM; if ((allowmask & ROLE_GENDMASK) == ROLE_MALE) - g = 0; /* role forces male (hypothetical) */ + gend = 0; /* role forces male (hypothetical) */ else if ((allowmask & ROLE_GENDMASK) == ROLE_FEMALE) - g = 1; /* role forces female (valkyrie) */ + gend = 1; /* role forces female (valkyrie) */ if ((allowmask & ROLE_ALIGNMASK) == AM_LAWFUL) a = 0; /* aligns[lawful] */ else if ((allowmask & ROLE_ALIGNMASK) == AM_NEUTRAL) @@ -1804,10 +1804,10 @@ winid where; : roles[r].name.m); if (r >= 0 && roles[r].name.f) { /* distinct female name [caveman/cavewoman, priest/priestess] */ - if (g == 1) + if (gend == 1) /* female specified; replace male role name with female one */ Sprintf(index(buf, ':'), ": %s", roles[r].name.f); - else if (g < 0) + else if (gend < 0) /* gender unspecified; append slash and female role name */ Sprintf(eos(buf), "/%s", roles[r].name.f); } @@ -1820,11 +1820,11 @@ winid where; : races[c].noun); putstr(where, 0, buf); Sprintf(buf, "%12s ", "gender:"); - Strcat(buf, (which == RS_GENDER) ? choosing : (g == ROLE_NONE) + Strcat(buf, (which == RS_GENDER) ? choosing : (gend == ROLE_NONE) ? not_yet - : (g == ROLE_RANDOM) + : (gend == ROLE_RANDOM) ? rand_choice - : genders[g].adj); + : genders[gend].adj); putstr(where, 0, buf); Sprintf(buf, "%12s ", "alignment:"); Strcat(buf, (which == RS_ALGNMNT) ? choosing : (a == ROLE_NONE) @@ -1852,7 +1852,7 @@ boolean preselect; anything any; char buf[BUFSZ]; const char *what = 0, *constrainer = 0, *forcedvalue = 0; - int f = 0, r, c, g, a, i, allowmask; + int f = 0, r, c, gend, a, i, allowmask; r = flags.initrole; c = flags.initrace; @@ -1894,16 +1894,16 @@ boolean preselect; case RS_GENDER: what = "gender"; f = flags.initgend; - g = ROLE_NONE; + gend = ROLE_NONE; if (r >= 0) { allowmask = roles[r].allow & ROLE_GENDMASK; if (allowmask == ROLE_MALE) - g = 0; /* genders[male] */ + gend = 0; /* genders[male] */ else if (allowmask == ROLE_FEMALE) - g = 1; /* genders[female] */ - if (g >= 0) { + gend = 1; /* genders[female] */ + if (gend >= 0) { constrainer = "role"; - forcedvalue = genders[g].adj; + forcedvalue = genders[gend].adj; } else if (f >= 0 && (allowmask & ~rfilter.mask) == genders[f].allow) { /* if there is only one gender choice available due to user diff --git a/src/rumors.c b/src/rumors.c index 033a0126c..f4ef963d6 100644 --- a/src/rumors.c +++ b/src/rumors.c @@ -45,17 +45,6 @@ STATIC_DCL void FDECL(init_rumors, (dlb *)); STATIC_DCL void FDECL(init_oracles, (dlb *)); STATIC_DCL void FDECL(couldnt_open_file, (const char *)); -/* rumor size variables are signed so that value -1 can be used as a flag */ -static long true_rumor_size = 0L, false_rumor_size; -/* rumor start offsets are unsigned because they're handled via %lx format */ -static unsigned long true_rumor_start, false_rumor_start; -/* rumor end offsets are signed because they're compared with [dlb_]ftell() */ -static long true_rumor_end, false_rumor_end; -/* oracles are handled differently from rumors... */ -static int oracle_flg = 0; /* -1=>don't use, 0=>need init, 1=>init done */ -static unsigned oracle_cnt = 0; -static unsigned long *oracle_loc = 0; - STATIC_OVL void init_rumors(fp) dlb *fp; @@ -67,17 +56,17 @@ dlb *fp; (void) dlb_fgets(line, sizeof line, fp); /* skip "don't edit" comment */ (void) dlb_fgets(line, sizeof line, fp); - if (sscanf(line, rumors_header, &true_count, &true_rumor_size, - &true_rumor_start, &false_count, &false_rumor_size, - &false_rumor_start, &eof_offset) == 7 - && true_rumor_size > 0L - && false_rumor_size > 0L) { - true_rumor_end = (long) true_rumor_start + true_rumor_size; - /* assert( true_rumor_end == false_rumor_start ); */ - false_rumor_end = (long) false_rumor_start + false_rumor_size; - /* assert( false_rumor_end == eof_offset ); */ + if (sscanf(line, rumors_header, &true_count, &g.true_rumor_size, + &g.true_rumor_start, &false_count, &g.false_rumor_size, + &g.false_rumor_start, &eof_offset) == 7 + && g.true_rumor_size > 0L + && g.false_rumor_size > 0L) { + g.true_rumor_end = (long) g.true_rumor_start + g.true_rumor_size; + /* assert( g.true_rumor_end == false_rumor_start ); */ + g.false_rumor_end = (long) g.false_rumor_start + g.false_rumor_size; + /* assert( g.false_rumor_end == eof_offset ); */ } else { - true_rumor_size = -1L; /* init failed */ + g.true_rumor_size = -1L; /* init failed */ (void) dlb_fclose(fp); } } @@ -98,7 +87,7 @@ boolean exclude_cookie; char *endp, line[BUFSZ], xbuf[BUFSZ]; rumor_buf[0] = '\0'; - if (true_rumor_size < 0L) /* we couldn't open RUMORFILE */ + if (g.true_rumor_size < 0L) /* we couldn't open RUMORFILE */ return rumor_buf; rumors = dlb_fopen(RUMORFILE, "r"); @@ -109,9 +98,9 @@ boolean exclude_cookie; do { rumor_buf[0] = '\0'; - if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ + if (g.true_rumor_size == 0L) { /* if this is 1st outrumor() */ init_rumors(rumors); - if (true_rumor_size < 0L) { /* init failed */ + if (g.true_rumor_size < 0L) { /* init failed */ Sprintf(rumor_buf, "Error reading \"%.80s\".", RUMORFILE); return rumor_buf; } @@ -124,13 +113,13 @@ boolean exclude_cookie; switch (adjtruth = truth + rn2(2)) { case 2: /*(might let a bogus input arg sneak thru)*/ case 1: - beginning = (long) true_rumor_start; - tidbit = Rand() % true_rumor_size; + beginning = (long) g.true_rumor_start; + tidbit = Rand() % g.true_rumor_size; break; case 0: /* once here, 0 => false rather than "either"*/ case -1: - beginning = (long) false_rumor_start; - tidbit = Rand() % false_rumor_size; + beginning = (long) g.false_rumor_start; + tidbit = Rand() % g.false_rumor_size; break; default: impossible("strange truth value for rumor"); @@ -139,7 +128,7 @@ boolean exclude_cookie; (void) dlb_fseek(rumors, beginning + tidbit, SEEK_SET); (void) dlb_fgets(line, sizeof line, rumors); if (!dlb_fgets(line, sizeof line, rumors) - || (adjtruth > 0 && dlb_ftell(rumors) > true_rumor_end)) { + || (adjtruth > 0 && dlb_ftell(rumors) > g.true_rumor_end)) { /* reached end of rumors -- go back to beginning */ (void) dlb_fseek(rumors, beginning, SEEK_SET); (void) dlb_fgets(line, sizeof line, rumors); @@ -157,7 +146,7 @@ boolean exclude_cookie; exercise(A_WIS, (adjtruth > 0)); } else { couldnt_open_file(RUMORFILE); - true_rumor_size = -1; /* don't try to open it again */ + g.true_rumor_size = -1; /* don't try to open it again */ } /* this is safe either way, so do it always since we can't get the definition * out of makedefs.c @@ -187,7 +176,7 @@ rumor_check() winid tmpwin; char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ]; - if (true_rumor_size < 0L) { /* we couldn't open RUMORFILE */ + if (g.true_rumor_size < 0L) { /* we couldn't open RUMORFILE */ no_rumors: pline("rumors not accessible."); if (rumors) @@ -201,9 +190,9 @@ rumor_check() long ftell_rumor_start = 0L; rumor_buf[0] = '\0'; - if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ + if (g.true_rumor_size == 0L) { /* if this is 1st outrumor() */ init_rumors(rumors); - if (true_rumor_size < 0L) + if (g.true_rumor_size < 0L) goto no_rumors; /* init failed */ } tmpwin = create_nhwindow(NHW_TEXT); @@ -215,17 +204,17 @@ rumor_check() Sprintf( rumor_buf, "T start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)", - (long) true_rumor_start, true_rumor_start, true_rumor_end, - (unsigned long) true_rumor_end, true_rumor_size, - (unsigned long) true_rumor_size); + (long) g.true_rumor_start, g.true_rumor_start, g.true_rumor_end, + (unsigned long) g.true_rumor_end, g.true_rumor_size, + (unsigned long) g.true_rumor_size); putstr(tmpwin, 0, rumor_buf); Sprintf( rumor_buf, "F start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)", - (long) false_rumor_start, false_rumor_start, false_rumor_end, - (unsigned long) false_rumor_end, false_rumor_size, - (unsigned long) false_rumor_size); + (long) g.false_rumor_start, g.false_rumor_start, g.false_rumor_end, + (unsigned long) g.false_rumor_end, g.false_rumor_size, + (unsigned long) g.false_rumor_size); putstr(tmpwin, 0, rumor_buf); /* @@ -236,7 +225,7 @@ rumor_check() * the value read in rumors, and display it. */ rumor_buf[0] = '\0'; - (void) dlb_fseek(rumors, (long) true_rumor_start, SEEK_SET); + (void) dlb_fseek(rumors, (long) g.true_rumor_start, SEEK_SET); ftell_rumor_start = dlb_ftell(rumors); (void) dlb_fgets(line, sizeof line, rumors); if ((endp = index(line, '\n')) != 0) @@ -246,7 +235,7 @@ rumor_check() putstr(tmpwin, 0, rumor_buf); /* find last true rumor */ while (dlb_fgets(line, sizeof line, rumors) - && dlb_ftell(rumors) < true_rumor_end) + && dlb_ftell(rumors) < g.true_rumor_end) continue; if ((endp = index(line, '\n')) != 0) *endp = 0; @@ -254,7 +243,7 @@ rumor_check() putstr(tmpwin, 0, rumor_buf); rumor_buf[0] = '\0'; - (void) dlb_fseek(rumors, (long) false_rumor_start, SEEK_SET); + (void) dlb_fseek(rumors, (long) g.false_rumor_start, SEEK_SET); ftell_rumor_start = dlb_ftell(rumors); (void) dlb_fgets(line, sizeof line, rumors); if ((endp = index(line, '\n')) != 0) @@ -264,7 +253,7 @@ rumor_check() putstr(tmpwin, 0, rumor_buf); /* find last false rumor */ while (dlb_fgets(line, sizeof line, rumors) - && dlb_ftell(rumors) < false_rumor_end) + && dlb_ftell(rumors) < g.false_rumor_end) continue; if ((endp = index(line, '\n')) != 0) *endp = 0; @@ -276,7 +265,7 @@ rumor_check() destroy_nhwindow(tmpwin); } else { couldnt_open_file(RUMORFILE); - true_rumor_size = -1; /* don't try to open it again */ + g.true_rumor_size = -1; /* don't try to open it again */ } } @@ -381,11 +370,11 @@ dlb *fp; (void) dlb_fgets(line, sizeof line, fp); /* skip "don't edit" comment*/ (void) dlb_fgets(line, sizeof line, fp); if (sscanf(line, "%5d\n", &cnt) == 1 && cnt > 0) { - oracle_cnt = (unsigned) cnt; - oracle_loc = (unsigned long *) alloc((unsigned) cnt * sizeof(long)); + g.oracle_cnt = (unsigned) cnt; + g.oracle_loc = (unsigned long *) alloc((unsigned) cnt * sizeof(long)); for (i = 0; i < cnt; i++) { (void) dlb_fgets(line, sizeof line, fp); - (void) sscanf(line, "%5lx\n", &oracle_loc[i]); + (void) sscanf(line, "%5lx\n", &g.oracle_loc[i]); } } return; @@ -396,14 +385,14 @@ save_oracles(fd, mode) int fd, mode; { if (perform_bwrite(mode)) { - bwrite(fd, (genericptr_t) &oracle_cnt, sizeof oracle_cnt); - if (oracle_cnt) - bwrite(fd, (genericptr_t) oracle_loc, oracle_cnt * sizeof(long)); + bwrite(fd, (genericptr_t) &g.oracle_cnt, sizeof g.oracle_cnt); + if (g.oracle_cnt) + bwrite(fd, (genericptr_t) g.oracle_loc, g.oracle_cnt * sizeof(long)); } if (release_data(mode)) { - if (oracle_cnt) { - free((genericptr_t) oracle_loc); - oracle_loc = 0, oracle_cnt = 0, oracle_flg = 0; + if (g.oracle_cnt) { + free((genericptr_t) g.oracle_loc); + g.oracle_loc = 0, g.oracle_cnt = 0, g.oracle_flg = 0; } } } @@ -412,11 +401,11 @@ void restore_oracles(fd) int fd; { - mread(fd, (genericptr_t) &oracle_cnt, sizeof oracle_cnt); - if (oracle_cnt) { - oracle_loc = (unsigned long *) alloc(oracle_cnt * sizeof(long)); - mread(fd, (genericptr_t) oracle_loc, oracle_cnt * sizeof(long)); - oracle_flg = 1; /* no need to call init_oracles() */ + mread(fd, (genericptr_t) &g.oracle_cnt, sizeof g.oracle_cnt); + if (g.oracle_cnt) { + g.oracle_loc = (unsigned long *) alloc(g.oracle_cnt * sizeof(long)); + mread(fd, (genericptr_t) g.oracle_loc, g.oracle_cnt * sizeof(long)); + g.oracle_flg = 1; /* no need to call init_oracles() */ } } @@ -432,26 +421,26 @@ boolean delphi; /* early return if we couldn't open ORACLEFILE on previous attempt, or if all the oracularities are already exhausted */ - if (oracle_flg < 0 || (oracle_flg > 0 && oracle_cnt == 0)) + if (g.oracle_flg < 0 || (g.oracle_flg > 0 && g.oracle_cnt == 0)) return; oracles = dlb_fopen(ORACLEFILE, "r"); if (oracles) { - if (oracle_flg == 0) { /* if this is the first outoracle() */ + if (g.oracle_flg == 0) { /* if this is the first outoracle() */ init_oracles(oracles); - oracle_flg = 1; - if (oracle_cnt == 0) + g.oracle_flg = 1; + if (g.oracle_cnt == 0) goto close_oracles; } /* oracle_loc[0] is the special oracle; oracle_loc[1..oracle_cnt-1] are normal ones */ - if (oracle_cnt <= 1 && !special) + if (g.oracle_cnt <= 1 && !special) goto close_oracles; /*(shouldn't happen)*/ - oracle_idx = special ? 0 : rnd((int) oracle_cnt - 1); - (void) dlb_fseek(oracles, (long) oracle_loc[oracle_idx], SEEK_SET); + oracle_idx = special ? 0 : rnd((int) g.oracle_cnt - 1); + (void) dlb_fseek(oracles, (long) g.oracle_loc[oracle_idx], SEEK_SET); if (!special) /* move offset of very last one into this slot */ - oracle_loc[oracle_idx] = oracle_loc[--oracle_cnt]; + g.oracle_loc[oracle_idx] = g.oracle_loc[--g.oracle_cnt]; tmpwin = create_nhwindow(NHW_TEXT); if (delphi) @@ -474,7 +463,7 @@ boolean delphi; (void) dlb_fclose(oracles); } else { couldnt_open_file(ORACLEFILE); - oracle_flg = -1; /* don't try to open it again */ + g.oracle_flg = -1; /* don't try to open it again */ } } @@ -516,7 +505,7 @@ struct monst *oracl; break; case 'n': if (umoney <= (long) minor_cost /* don't even ask */ - || (oracle_cnt == 1 || oracle_flg < 0)) + || (g.oracle_cnt == 1 || g.oracle_flg < 0)) return 0; Sprintf(qbuf, "\"Then dost thou desire a major one?\" (%d %s)", major_cost, currency((long) major_cost)); diff --git a/src/save.c b/src/save.c index 18465966d..5a7449556 100644 --- a/src/save.c +++ b/src/save.c @@ -71,9 +71,6 @@ static struct save_procs { #define HUP #endif -/* need to preserve these during save to avoid accessing freed memory */ -static unsigned ustuck_id = 0, usteed_id = 0; - int dosave() { @@ -213,8 +210,8 @@ dosave0() store_version(fd); store_savefileinfo(fd); store_plname_in_file(fd); - ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); - usteed_id = (u.usteed ? u.usteed->m_id : 0); + g.ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); + g.usteed_id = (u.usteed ? u.usteed->m_id : 0); savelev(fd, ledger_no(&u.uz), WRITE_SAVE | FREE_SAVE); savegamestate(fd, WRITE_SAVE | FREE_SAVE); @@ -336,10 +333,10 @@ register int fd, mode; sizeof(struct spell) * (MAXSPELL + 1)); save_artifacts(fd); save_oracles(fd, mode); - if (ustuck_id) - bwrite(fd, (genericptr_t) &ustuck_id, sizeof ustuck_id); - if (usteed_id) - bwrite(fd, (genericptr_t) &usteed_id, sizeof usteed_id); + if (g.ustuck_id) + bwrite(fd, (genericptr_t) &g.ustuck_id, sizeof g.ustuck_id); + if (g.usteed_id) + bwrite(fd, (genericptr_t) &g.usteed_id, sizeof g.usteed_id); bwrite(fd, (genericptr_t) pl_character, sizeof pl_character); bwrite(fd, (genericptr_t) pl_fruit, sizeof pl_fruit); savefruitchn(fd, mode); @@ -369,7 +366,6 @@ void savestateinlock() { int fd, hpid; - static boolean havestate = TRUE; char whynot[BUFSZ]; /* When checkpointing is on, the full state needs to be written @@ -383,7 +379,7 @@ savestateinlock() * noop pid rewriting will take place on the first "checkpoint" after * the game is started or restored, if checkpointing is off. */ - if (flags.ins_chkpt || havestate) { + if (flags.ins_chkpt || g.havestate) { /* save the rest of the current game state in the lock file, * following the original int pid, the current level number, * and the current savefile name, which should not be subject @@ -421,13 +417,13 @@ savestateinlock() store_savefileinfo(fd); store_plname_in_file(fd); - ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); - usteed_id = (u.usteed ? u.usteed->m_id : 0); + g.ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); + g.usteed_id = (u.usteed ? u.usteed->m_id : 0); savegamestate(fd, WRITE_SAVE); } bclose(fd); } - havestate = flags.ins_chkpt; + g.havestate = flags.ins_chkpt; } #endif diff --git a/src/sys.c b/src/sys.c index 6adc8f71f..51b966ff2 100644 --- a/src/sys.c +++ b/src/sys.c @@ -20,6 +20,9 @@ struct sysopt sysopt; void sys_early_init() { + decl_globals_init(); + objects_globals_init(); + sysopt.support = (char *) 0; sysopt.recover = (char *) 0; #ifdef SYSCF diff --git a/src/trap.c b/src/trap.c index d8d4018e7..d3a219ce9 100644 --- a/src/trap.c +++ b/src/trap.c @@ -39,9 +39,6 @@ STATIC_DCL boolean FDECL(thitm, (int, struct monst *, struct obj *, int, BOOLEAN_P)); STATIC_DCL void NDECL(maybe_finish_sokoban); -/* mintrap() should take a flags argument, but for time being we use this */ -STATIC_VAR int force_mintrap = 0; - STATIC_VAR const char *const a_your[2] = { "a", "your" }; STATIC_VAR const char *const A_Your[2] = { "A", "Your" }; STATIC_VAR const char tower_of_flame[] = "tower of flame"; @@ -2165,7 +2162,7 @@ register struct monst *mtmp; } else { register int tt = trap->ttyp; boolean in_sight, tear_web, see_it, - inescapable = force_mintrap || ((tt == HOLE || tt == PIT) + inescapable = g.force_mintrap || ((tt == HOLE || tt == PIT) && Sokoban && !trap->madeby_u); const char *fallverb; @@ -2281,7 +2278,7 @@ register struct monst *mtmp; || mptr == &mons[PM_BUGBEAR]) You_hear("the roaring of an angry bear!"); } - } else if (force_mintrap) { + } else if (g.force_mintrap) { if (in_sight) { pline("%s evades %s bear trap!", Monnam(mtmp), a_your[trap->madeby_u]); @@ -2430,7 +2427,7 @@ register struct monst *mtmp; if (is_flyer(mptr) || is_floater(mptr) || (mtmp->wormno && count_wsegs(mtmp) > 5) || is_clinger(mptr)) { - if (force_mintrap && !Sokoban) { + if (g.force_mintrap && !Sokoban) { /* openfallingtrap; not inescapable here */ if (in_sight) { seetrap(trap); @@ -2467,7 +2464,7 @@ register struct monst *mtmp; if (is_flyer(mptr) || is_floater(mptr) || mptr == &mons[PM_WUMPUS] || (mtmp->wormno && count_wsegs(mtmp) > 5) || mptr->msize >= MZ_HUGE) { - if (force_mintrap && !Sokoban) { + if (g.force_mintrap && !Sokoban) { /* openfallingtrap; not inescapable here */ if (in_sight) { seetrap(trap); @@ -2556,7 +2553,7 @@ register struct monst *mtmp; a_your[trap->madeby_u]); deltrap(trap); newsym(mtmp->mx, mtmp->my); - } else if (force_mintrap && !mtmp->mtrapped) { + } else if (g.force_mintrap && !mtmp->mtrapped) { if (in_sight) { pline("%s avoids %s spider web!", Monnam(mtmp), a_your[trap->madeby_u]); @@ -4694,9 +4691,9 @@ boolean *noticed; /* set to true iff hero notices the effect; */ /* dotrap calls mintrap when mounted hero encounters a web */ if (u.usteed) dotrapflags |= NOWEBMSG; - ++force_mintrap; + ++g.force_mintrap; dotrap(t, dotrapflags); - --force_mintrap; + --g.force_mintrap; result = (u.utrap != 0); } else { if (mon->mtrapped) @@ -4704,9 +4701,9 @@ boolean *noticed; /* set to true iff hero notices the effect; */ /* you notice it if you see the trap close/tremble/whatever or if you sense the monster who becomes trapped */ *noticed = cansee(t->tx, t->ty) || canspotmon(mon); - ++force_mintrap; + ++g.force_mintrap; result = (mintrap(mon) != 0); - --force_mintrap; + --g.force_mintrap; } return result; } @@ -4747,9 +4744,9 @@ boolean *noticed; /* set to true iff hero notices the effect; */ *noticed = cansee(t->tx, t->ty) || canspotmon(mon); /* monster will be angered; mintrap doesn't handle that */ wakeup(mon, TRUE); - ++force_mintrap; + ++g.force_mintrap; result = (mintrap(mon) != 0); - --force_mintrap; + --g.force_mintrap; /* mon might now be on the migrating monsters list */ } return result; diff --git a/src/u_init.c b/src/u_init.c index 5b5c5113f..f18820d5a 100644 --- a/src/u_init.c +++ b/src/u_init.c @@ -974,15 +974,11 @@ register struct trobj *trop; struct obj *obj; int otyp, i; - while (trop->trclass) { + while (trop->trclass) { otyp = (int) trop->trotyp; if (otyp != UNDEF_TYP) { obj = mksobj(otyp, TRUE, FALSE); } else { /* UNDEF_TYP */ - static NEARDATA short nocreate = STRANGE_OBJECT; - static NEARDATA short nocreate2 = STRANGE_OBJECT; - static NEARDATA short nocreate3 = STRANGE_OBJECT; - static NEARDATA short nocreate4 = STRANGE_OBJECT; /* * For random objects, do not create certain overly powerful * items: wand of wishing, ring of levitation, or the @@ -995,9 +991,9 @@ register struct trobj *trop; */ obj = mkobj(trop->trclass, FALSE); otyp = obj->otyp; - while (otyp == WAN_WISHING || otyp == nocreate - || otyp == nocreate2 || otyp == nocreate3 - || otyp == nocreate4 || otyp == RIN_LEVITATION + while (otyp == WAN_WISHING || otyp == g.nocreate + || otyp == g.nocreate2 || otyp == g.nocreate3 + || otyp == g.nocreate4 || otyp == RIN_LEVITATION /* 'useless' items */ || otyp == POT_HALLUCINATION || otyp == POT_ACID @@ -1039,16 +1035,16 @@ register struct trobj *trop; case WAN_POLYMORPH: case RIN_POLYMORPH: case POT_POLYMORPH: - nocreate = RIN_POLYMORPH_CONTROL; + g.nocreate = RIN_POLYMORPH_CONTROL; break; case RIN_POLYMORPH_CONTROL: - nocreate = RIN_POLYMORPH; - nocreate2 = SPE_POLYMORPH; - nocreate3 = POT_POLYMORPH; + g.nocreate = RIN_POLYMORPH; + g.nocreate2 = SPE_POLYMORPH; + g.nocreate3 = POT_POLYMORPH; } /* Don't have 2 of the same ring or spellbook */ if (obj->oclass == RING_CLASS || obj->oclass == SPBOOK_CLASS) - nocreate4 = otyp; + g.nocreate4 = otyp; } if (urace.malenum != PM_HUMAN) { diff --git a/src/uhitm.c b/src/uhitm.c index 01c423593..1b061ba4e 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -24,11 +24,6 @@ STATIC_DCL boolean FDECL(hmonas, (struct monst *)); STATIC_DCL void FDECL(nohandglow, (struct monst *)); STATIC_DCL boolean FDECL(shade_aware, (struct obj *)); -extern boolean notonhead; /* for long worms */ - -/* Used to flag attacks caused by Stormbringer's maliciousness. */ -static boolean override_confirmation = FALSE; - #define PROJECTILE(obj) ((obj) && is_ammo(obj)) void @@ -213,7 +208,7 @@ struct obj *wep; /* uwep for attack(), null for kick_monster() */ && !Confusion && !Hallucination && !Stunned) { /* Intelligent chaotic weapons (Stormbringer) want blood */ if (wep && wep->oartifact == ART_STORMBRINGER) { - override_confirmation = TRUE; + g.override_confirmation = TRUE; return FALSE; } if (canspotmon(mtmp)) { @@ -387,7 +382,7 @@ register struct monst *mtmp; /* possibly set in attack_checks; examined in known_hitum, called via hitum or hmonas below */ - override_confirmation = FALSE; + g.override_confirmation = FALSE; /* attack_checks() used to use directly, now it uses bhitpos instead; it might map an invisible monster there */ bhitpos.x = u.ux + u.dx; @@ -470,7 +465,7 @@ int dieroll; /* hmon() might destroy weapon; remember aspect for cutworm */ slice_or_chop = (weapon && (is_blade(weapon) || is_axe(weapon))); - if (override_confirmation) { + if (g.override_confirmation) { /* this may need to be generalized if weapons other than Stormbringer acquire similar anti-social behavior... */ if (flags.verbose) @@ -489,7 +484,7 @@ int dieroll; /* we hit the monster; be careful: it might die or be knocked into a different location */ - notonhead = (mon->mx != x || mon->my != y); + g.notonhead = (mon->mx != x || mon->my != y); malive = hmon(mon, weapon, HMON_MELEE, dieroll); if (malive) { /* monster still alive */ @@ -623,7 +618,7 @@ struct attack *uattk; /* second attack for two-weapon combat; won't occur if Stormbringer overrode confirmation (assumes Stormbringer is primary weapon) or if the monster was killed or knocked to different location */ - if (u.twoweap && !override_confirmation && malive && m_at(x, y) == mon) { + if (u.twoweap && !g.override_confirmation && malive && m_at(x, y) == mon) { tmp = find_roll_to_hit(mon, uattk->aatyp, uswapwep, &attknum, &armorpenalty); dieroll = rnd(20); @@ -1830,7 +1825,7 @@ register struct attack *mattk; case AD_DRIN: { struct obj *helmet; - if (notonhead || !has_head(pd)) { + if (g.notonhead || !has_head(pd)) { pline("%s doesn't seem harmed.", Monnam(mdef)); tmp = 0; if (!Unchanging && pd == &mons[PM_GREEN_SLIME]) { diff --git a/src/weapon.c b/src/weapon.c index a590366bb..d72c18b9b 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -387,8 +387,6 @@ static NEARDATA const int pwep[] = { HALBERD, BARDICHE, SPETUM, BEC_DE_CORBIN, FAUCHARD, PARTISAN, LANCE }; -static struct obj *propellor; - /* select a ranged weapon for the monster */ struct obj * select_rwep(mtmp) @@ -401,7 +399,7 @@ register struct monst *mtmp; char mlet = mtmp->data->mlet; - propellor = &zeroobj; + g.propellor = &zeroobj; Oselect(EGG); /* cockatrice egg */ if (mlet == S_KOP) /* pies are first choice for Kops */ Oselect(CREAM_PIE); @@ -433,7 +431,7 @@ register struct monst *mtmp; || !mon_hates_silver(mtmp))) { if ((otmp = oselect(mtmp, pwep[i])) != 0 && (otmp == mwep || !mweponly)) { - propellor = otmp; /* force the monster to wield it */ + g.propellor = otmp; /* force the monster to wield it */ return otmp; } } @@ -454,41 +452,41 @@ register struct monst *mtmp; for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) if (otmp->oclass == GEM_CLASS && (otmp->otyp != LOADSTONE || !otmp->cursed)) { - propellor = m_carrying(mtmp, SLING); + g.propellor = m_carrying(mtmp, SLING); return otmp; } } /* KMH -- This belongs here so darts will work */ - propellor = &zeroobj; + g.propellor = &zeroobj; prop = (objects[rwep[i]]).oc_skill; if (prop < 0) { switch (-prop) { case P_BOW: - propellor = (oselect(mtmp, YUMI)); - if (!propellor) - propellor = (oselect(mtmp, ELVEN_BOW)); - if (!propellor) - propellor = (oselect(mtmp, BOW)); - if (!propellor) - propellor = (oselect(mtmp, ORCISH_BOW)); + g.propellor = (oselect(mtmp, YUMI)); + if (!g.propellor) + g.propellor = (oselect(mtmp, ELVEN_BOW)); + if (!g.propellor) + g.propellor = (oselect(mtmp, BOW)); + if (!g.propellor) + g.propellor = (oselect(mtmp, ORCISH_BOW)); break; case P_SLING: - propellor = (oselect(mtmp, SLING)); + g.propellor = (oselect(mtmp, SLING)); break; case P_CROSSBOW: - propellor = (oselect(mtmp, CROSSBOW)); + g.propellor = (oselect(mtmp, CROSSBOW)); } - if ((otmp = MON_WEP(mtmp)) && mwelded(otmp) && otmp != propellor + if ((otmp = MON_WEP(mtmp)) && mwelded(otmp) && otmp != g.propellor && mtmp->weapon_check == NO_WEAPON_WANTED) - propellor = 0; + g.propellor = 0; } /* propellor = obj, propellor to use * propellor = &zeroobj, doesn't need a propellor * propellor = 0, needed one and didn't have one */ - if (propellor != 0) { + if (g.propellor != 0) { /* Note: cannot use m_carrying for loadstones, since it will * always select the first object of a type, and maybe the * monster is carrying two but only the first is unthrowable. @@ -635,7 +633,7 @@ register struct monst *mon; break; case NEED_RANGED_WEAPON: (void) select_rwep(mon); - obj = propellor; + obj = g.propellor; break; case NEED_PICK_AXE: obj = m_carrying(mon, PICK_AXE); diff --git a/src/zap.c b/src/zap.c index 6907880e4..9ec946dfd 100644 --- a/src/zap.c +++ b/src/zap.c @@ -12,14 +12,6 @@ */ #define MAGIC_COOKIE 1000 -static NEARDATA boolean obj_zapped; -static NEARDATA int poly_zapped; - -extern boolean notonhead; /* for long worms */ - -/* kludge to use mondied instead of killed */ -extern boolean m_using; - STATIC_DCL void FDECL(polyuse, (struct obj *, int, int)); STATIC_DCL void FDECL(create_polymon, (struct obj *, int)); STATIC_DCL int FDECL(stone_to_flesh_obj, (struct obj *)); @@ -149,7 +141,7 @@ struct obj *otmp; if (u.uswallow && mtmp == u.ustuck) reveal_invis = FALSE; - notonhead = (mtmp->mx != bhitpos.x || mtmp->my != bhitpos.y); + g.notonhead = (mtmp->mx != bhitpos.x || mtmp->my != bhitpos.y); skilled_spell = (otmp && otmp->oclass == SPBOOK_CLASS && otmp->blessed); switch (otyp) { @@ -487,7 +479,7 @@ struct monst *mtmp; struct obj *otmp; mstatusline(mtmp); - if (notonhead) + if (g.notonhead) return; /* don't show minvent for long worm tail */ if (mtmp->minvent) { @@ -1368,13 +1360,13 @@ struct obj *obj; if (obj->otyp == SCR_MAIL) return; #endif - obj_zapped = TRUE; + g.obj_zapped = TRUE; - if (poly_zapped < 0) { + if (g.poly_zapped < 0) { /* some may metamorphosize */ for (i = obj->quan; i; i--) if (!rn2(Luck + 45)) { - poly_zapped = objects[obj->otyp].oc_material; + g.poly_zapped = objects[obj->otyp].oc_material; break; } } @@ -2076,7 +2068,7 @@ schar zz; learnwand(obj); } - poly_zapped = -1; + g.poly_zapped = -1; for (otmp = level.objects[tx][ty]; otmp; otmp = next_obj) { next_obj = otmp->nexthere; /* for zap downwards, don't hit object poly'd hero is hiding under */ @@ -2086,8 +2078,8 @@ schar zz; hitanything += (*fhito)(otmp, obj); } - if (poly_zapped >= 0) - create_polymon(level.objects[tx][ty], poly_zapped); + if (g.poly_zapped >= 0) + create_polymon(level.objects[tx][ty], g.poly_zapped); return hitanything; } @@ -2618,7 +2610,7 @@ struct obj *obj; /* wand or spell */ int steedhit = FALSE; bhitpos.x = u.usteed->mx, bhitpos.y = u.usteed->my; - notonhead = FALSE; + g.notonhead = FALSE; switch (obj->otyp) { /* * Wands that are allowed to hit the steed @@ -2961,16 +2953,16 @@ struct obj *obj; /* wand or spell */ void zapsetup() { - obj_zapped = FALSE; + g.obj_zapped = FALSE; } void zapwrapup() { /* if do_osshock() set obj_zapped while polying, give a message now */ - if (obj_zapped) + if (g.obj_zapped) You_feel("shuddering vibrations."); - obj_zapped = FALSE; + g.obj_zapped = FALSE; } /* called for various wand and spell effects - M. Stephenson */ @@ -3301,7 +3293,7 @@ struct obj **pobj; /* object tossed/used, set to NULL } if (mtmp && !(in_skip && M_IN_WATER(mtmp->data))) { - notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); + g.notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); if (weapon == FLASHED_LIGHT) { /* FLASHED_LIGHT hitting invisible monster should pass through instead of stop so we call @@ -4049,7 +4041,7 @@ boolean say; /* Announce out of sight hit/miss events if true */ if (type >= 0) mon->mstrategy &= ~STRAT_WAITMASK; buzzmonst: - notonhead = (mon->mx != bhitpos.x || mon->my != bhitpos.y); + g.notonhead = (mon->mx != bhitpos.x || mon->my != bhitpos.y); if (zap_hit(find_mac(mon), spell_type)) { if (mon_reflects(mon, (char *) 0)) { if (cansee(mon->mx, mon->my)) { @@ -5122,7 +5114,7 @@ int damage, tell; if (damage) { mtmp->mhp -= damage; if (DEADMONSTER(mtmp)) { - if (m_using) + if (g.m_using) monkilled(mtmp, "", AD_RBRE); else killed(mtmp); diff --git a/sys/share/random.c b/sys/share/random.c index 6d3d5e45c..3ec33b037 100644 --- a/sys/share/random.c +++ b/sys/share/random.c @@ -238,7 +238,7 @@ unsigned x; char * initstate(seed, arg_state, n) -unsigned seed; /* seed for R. N. G. */ +unsigned seed; /* seed for RNG */ char *arg_state; /* pointer to state array */ int n; /* # bytes of state info */ { diff --git a/sys/unix/NetHack.xcodeproj/project.pbxproj b/sys/unix/NetHack.xcodeproj/project.pbxproj index 4a0d53ae5..dcb402a98 100644 --- a/sys/unix/NetHack.xcodeproj/project.pbxproj +++ b/sys/unix/NetHack.xcodeproj/project.pbxproj @@ -810,6 +810,7 @@ 3186A3B121A4B0FD0052BF02 /* bitmfile.h */, 3186A36E21A4B0FA0052BF02 /* botl.h */, 3186A38721A4B0FB0052BF02 /* color.h */, + 31B8A30A21A20D730055BD01 /* config.h */, 3186A3C621A4B0FE0052BF02 /* config1.h */, 3186A37121A4B0FA0052BF02 /* context.h */, 3186A3C521A4B0FE0052BF02 /* coord.h */, @@ -901,7 +902,6 @@ 3186A36D21A4B0F90052BF02 /* xwindowp.h */, 3186A3BF21A4B0FD0052BF02 /* you.h */, 3186A3A721A4B0FD0052BF02 /* youprop.h */, - 31B8A30A21A20D730055BD01 /* config.h */, ); name = include; sourceTree = ""; diff --git a/util/lev_main.c b/util/lev_main.c index 8bcfc8365..670457b8e 100644 --- a/util/lev_main.c +++ b/util/lev_main.c @@ -109,8 +109,7 @@ struct lc_vardefs *FDECL(vardef_defined, (struct lc_vardefs *, char *, int)); void FDECL(splev_add_from, (sp_lev *, sp_lev *)); extern void NDECL(monst_init); -extern void NDECL(objects_init); -extern void NDECL(decl_init); +extern void NDECL(objects_globals_init); void FDECL(add_opcode, (sp_lev *, int, genericptr_t)); @@ -256,12 +255,15 @@ char **argv; argc = SIZE(mac_argv); argv = mac_argv; #endif + + decl_globals_init(); + objects_globals_init(); + /* Note: these initializers don't do anything except guarantee that * we're linked properly. */ monst_init(); - objects_init(); - decl_init(); + /* this one does something... */ init_obj_classes(); @@ -1646,4 +1648,11 @@ short ospeed; #endif #endif /* STRICT_REF_DEF */ +/* nhassert_failed is called when an nhassert's condition is false */ +void nhassert_failed(const char * exp, const char * file, int line) +{ + fprintf(stderr, "NHASSERT(%s) in '%s' at line %d\n", exp, file, line); + exit(EXIT_FAILURE); +} + /*lev_main.c*/ diff --git a/util/makedefs.c b/util/makedefs.c index 29a528f01..59a82f663 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -176,7 +176,7 @@ void NDECL(do_fix_sampleconfig); #endif extern void NDECL(monst_init); /* monst.c */ -extern void NDECL(objects_init); /* objects.c */ +extern void NDECL(objects_globals_init); /* objects.c */ static void NDECL(link_sanity_check); static char *FDECL(name_file, (const char *, const char *)); @@ -308,7 +308,6 @@ link_sanity_check() we're linked properly. */ monst_init(); - objects_init(); } @@ -318,6 +317,8 @@ char *options; { boolean more_than_one; + objects_globals_init(); + link_sanity_check(); /* construct the current version number */ diff --git a/win/share/tile2bmp.c b/win/share/tile2bmp.c index ca2c7dd73..8fb16e425 100644 --- a/win/share/tile2bmp.c +++ b/win/share/tile2bmp.c @@ -203,6 +203,8 @@ char *argv[]; } #endif + objects_globals_init(); + tilecount = 0; xoffset = yoffset = 0; initflag = 0; @@ -360,3 +362,10 @@ pixel (*pixels)[TILE_X]; } } } + +/* nhassert_failed is called when an nhassert's condition is false */ +void nhassert_failed(const char * exp, const char * file, int line) +{ + Fprintf(stderr, "NHASSERT(%s) in '%s' at line %d\n", exp, file, line); + exit(EXIT_FAILURE); +} diff --git a/win/share/tilemap.c b/win/share/tilemap.c index f859f44e8..1e59381b7 100644 --- a/win/share/tilemap.c +++ b/win/share/tilemap.c @@ -113,7 +113,6 @@ int set, entry; we're linked properly. */ monst_init(); - objects_init(); (void) def_char_to_objclass(']'); condnum = tilenum = 0; diff --git a/win/tty/topl.c b/win/tty/topl.c index 5233e1525..d0fadfb3e 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -648,9 +648,6 @@ boolean restoring_msghist; { static boolean initd = FALSE; int idx; -#ifdef DUMPLOG - extern unsigned saved_pline_index; /* pline.c */ -#endif if (restoring_msghist && !initd) { /* we're restoring history from the previous session, but new @@ -662,7 +659,7 @@ boolean restoring_msghist; initd = TRUE; #ifdef DUMPLOG /* this suffices; there's no need to scrub saved_pline[] pointers */ - saved_pline_index = 0; + g.saved_pline_index = 0; #endif } diff --git a/win/tty/wintty.c b/win/tty/wintty.c index ca9d60c1d..16a02762e 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -3217,7 +3217,6 @@ void tty_cliparound(x, y) int x, y; { - extern boolean restoring; int oldx = clipx, oldy = clipy; HUPSKIP(); @@ -3238,7 +3237,7 @@ int x, y; clipy = clipymax - (LI - 3); } if (clipx != oldx || clipy != oldy) { - if (on_level(&u.uz0, &u.uz) && !restoring) + if (on_level(&u.uz0, &u.uz) && !g.restoring) (void) doredraw(); } }