From ed9082a99a34178b380ed5e6f0f50149e96e97e3 Mon Sep 17 00:00:00 2001 From: Bart House Date: Fri, 23 Nov 2018 21:29:19 -0800 Subject: [PATCH 01/11] 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 df9477b62..d7c920b77 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 0cbcaba66..0e0a56fb7 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -5788,8 +5788,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 @@ -5806,7 +5805,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 48220a4fb..b613a6a5b 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) @@ -1095,7 +1093,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; @@ -1268,7 +1266,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 353469a5d..9d76a3533 100644 --- a/src/end.c +++ b/src/end.c @@ -681,14 +681,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 dc96331e6..ca04d0ded 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 a0f367952..fb84a6126 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."); return; @@ -199,9 +188,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); @@ -213,17 +202,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); /* @@ -234,7 +223,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) @@ -244,7 +233,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; @@ -252,7 +241,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) @@ -262,7 +251,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; @@ -274,7 +263,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 */ } } @@ -379,11 +368,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; @@ -394,14 +383,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; } } } @@ -410,11 +399,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() */ } } @@ -431,27 +420,27 @@ 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) { winid tmpwin; - 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) return; } /* 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) return; /*(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) @@ -473,7 +462,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 */ } } @@ -515,7 +504,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(); } } From 0c71f0caacf249dffb5b0ea4708bf87a6c3d50bc Mon Sep 17 00:00:00 2001 From: Bart House Date: Fri, 23 Nov 2018 21:30:50 -0800 Subject: [PATCH 02/11] Removing spaces at end of lines. --- include/decl.h | 6 +++--- src/decl.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/decl.h b/include/decl.h index acea3152c..dec6c5c9a 100644 --- a/include/decl.h +++ b/include/decl.h @@ -445,7 +445,7 @@ struct early_opt { /* 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 { @@ -515,7 +515,7 @@ struct instance_globals { 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 + 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 */ @@ -535,7 +535,7 @@ struct instance_globals { short nocreate2; short nocreate3; short nocreate4; - /* uhitm.c */ + /* uhitm.c */ boolean override_confirmation; /* Used to flag attacks caused by Stormbringer's maliciousness. */ /* weapon.c */ diff --git a/src/decl.c b/src/decl.c index 25e02a2ac..ef5bd3a31 100644 --- a/src/decl.c +++ b/src/decl.c @@ -413,8 +413,8 @@ const struct instance_globals g_init = { struct instance_globals g; -void -decl_globals_init() +void +decl_globals_init() { g = g_init; From cc881d02b17856b7b86db52d4923fee8fe3ca434 Mon Sep 17 00:00:00 2001 From: Bart House Date: Fri, 23 Nov 2018 16:50:23 -0800 Subject: [PATCH 03/11] Moved pray.c globals to instance_globals. --- include/decl.h | 15 +++++++++++ include/extern.h | 3 +-- src/allmain.c | 5 ---- src/decl.c | 8 ++++++ src/monst.c | 10 +++++--- src/muse.c | 59 +++++++++++++++++++----------------------- src/pray.c | 61 ++++++++++++++++++++------------------------ util/lev_main.c | 9 +------ util/makedefs.c | 18 ++----------- win/share/tile2bmp.c | 1 + win/share/tilemap.c | 4 --- 11 files changed, 88 insertions(+), 105 deletions(-) diff --git a/include/decl.h b/include/decl.h index dec6c5c9a..8bad9caa9 100644 --- a/include/decl.h +++ b/include/decl.h @@ -464,6 +464,14 @@ struct instance_globals { /* muse.c */ boolean m_using; /* kludge to use mondided instead of killed */ + int trapx; + int trapy; + boolean zap_oseen; /* for wands which use mbhitm and are zapped at + * players. We usually want an oseen local to + * the function, but this is impossible since the + * function mbhitm has to be compatible with the + * normal zap routines, and those routines don't + * remember who zapped the wand. */ /* objname.c */ /* distantname used by distant_name() to pass extra information to @@ -498,6 +506,13 @@ struct instance_globals { int potion_nothing; int potion_unkn; + /* pray.c */ + /* values calculated when prayer starts, and used when completed */ + aligntyp p_aligntyp; + int p_trouble; + int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */ + + /* read.c */ boolean known; diff --git a/include/extern.h b/include/extern.h index d7c920b77..821cb040f 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1432,6 +1432,7 @@ E boolean FDECL(angry_guards, (BOOLEAN_P)); E void NDECL(pacify_guards); E void FDECL(decide_to_shapeshift, (struct monst *, int)); E boolean FDECL(vamp_stone, (struct monst *)); +E void NDECL(monst_globals_init); /* ### mondata.c ### */ @@ -1504,8 +1505,6 @@ E boolean FDECL(undesirable_disp, (struct monst *, XCHAR_P, XCHAR_P)); /* ### monst.c ### */ -E void NDECL(monst_init); - /* ### monstr.c ### */ E void NDECL(monstr_init); diff --git a/src/allmain.c b/src/allmain.c index 459ab1eca..891dbaafa 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -30,11 +30,6 @@ boolean resuming; int moveamt = 0, wtcap = 0, change = 0; boolean monscanmove = FALSE; - /* Note: these initializers don't do anything except guarantee that - we're linked properly. - */ - monst_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 to use up the save file and require confirmation for explore mode */ diff --git a/src/decl.c b/src/decl.c index ef5bd3a31..37fa05787 100644 --- a/src/decl.c +++ b/src/decl.c @@ -338,6 +338,9 @@ const struct instance_globals g_init = { /* mused.c */ FALSE, /* m_using */ + UNDEFINED_VALUE, /* trapx */ + UNDEFINED_VALUE, /* trapy */ + UNDEFINED_VALUE, /* zap_oseen */ /* objname.c */ 0, /* distantname */ @@ -363,6 +366,11 @@ const struct instance_globals g_init = { UNDEFINED_VALUE, /* potion_nothing */ UNDEFINED_VALUE, /* potion_unkn */ + /* pray.c */ + UNDEFINED_VALUE, /* p_aligntyp */ + UNDEFINED_VALUE, /* p_trouble */ + UNDEFINED_VALUE, /* p_type */ + /* read.c */ UNDEFINED_VALUE, /* known */ diff --git a/src/monst.c b/src/monst.c index c513f73b4..a1f216bb0 100644 --- a/src/monst.c +++ b/src/monst.c @@ -27,7 +27,6 @@ #define C(color) #endif -void NDECL(monst_init); /* * Entry Format: (from permonst.h) * @@ -101,7 +100,7 @@ void NDECL(monst_init); */ #ifndef SPLITMON_2 -NEARDATA struct permonst mons[] = { +NEARDATA struct permonst mons_init[] = { /* * ants */ @@ -3228,10 +3227,13 @@ struct permonst _mons2[] = { #endif /* !SPLITMON_1 */ #ifndef SPLITMON_1 -/* dummy routine used to force linkage */ + +struct permonst mons[SIZE(mons_init)]; + void -monst_init() +monst_globals_init() { + memcpy(mons, mons_init, sizeof(mons)); return; } diff --git a/src/muse.c b/src/muse.c index 394b6327e..b15aebb3b 100644 --- a/src/muse.c +++ b/src/muse.c @@ -44,13 +44,6 @@ static struct musable { * If it's an object, the object is also set (it's 0 otherwise). */ } m; -static int trapx, trapy; -static boolean zap_oseen; /* for wands which use mbhitm and are zapped at - * players. We usually want an oseen local to - * the function, but this is impossible since the - * function mbhitm has to be compatible with the - * normal zap routines, and those routines don't - * remember who zapped the wand. */ /* Any preliminary checks which may result in the monster being unable to use * the item. Returns 0 if nothing happened, 2 if the monster can't do @@ -439,13 +432,13 @@ struct monst *mtmp; && !is_floater(mtmp->data) && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest && Can_fall_thru(&u.uz)) { - trapx = xx; - trapy = yy; + g.trapx = xx; + g.trapy = yy; m.has_defense = MUSE_TRAPDOOR; break; /* no need to look at any other spots */ } else if (t->ttyp == TELEP_TRAP) { - trapx = xx; - trapy = yy; + g.trapx = xx; + g.trapy = yy; m.has_defense = MUSE_TELEPORT_TRAP; } } @@ -665,7 +658,7 @@ struct monst *mtmp; (void) rloc(mtmp, TRUE); return 2; case MUSE_WAN_TELEPORTATION: - zap_oseen = oseen; + g.zap_oseen = oseen; mzapmsg(mtmp, otmp, FALSE); otmp->spe--; g.m_using = TRUE; @@ -813,26 +806,26 @@ struct monst *mtmp; return 0; m_flee(mtmp); if (vis) { - struct trap *t = t_at(trapx, trapy); + struct trap *t = t_at(g.trapx, g.trapy); Mnam = Monnam(mtmp); pline("%s %s into a %s!", Mnam, vtense(Mnam, locomotion(mtmp->data, "jump")), (t->ttyp == TRAPDOOR) ? "trap door" : "hole"); - if (levl[trapx][trapy].typ == SCORR) { - levl[trapx][trapy].typ = CORR; - unblock_point(trapx, trapy); + if (levl[g.trapx][g.trapy].typ == SCORR) { + levl[g.trapx][g.trapy].typ = CORR; + unblock_point(g.trapx, g.trapy); } - seetrap(t_at(trapx, trapy)); + seetrap(t_at(g.trapx, g.trapy)); } /* don't use rloc_to() because worm tails must "move" */ remove_monster(mtmp->mx, mtmp->my); newsym(mtmp->mx, mtmp->my); /* update old location */ - place_monster(mtmp, trapx, trapy); + place_monster(mtmp, g.trapx, g.trapy); if (mtmp->wormno) worm_move(mtmp); - newsym(trapx, trapy); + newsym(g.trapx, g.trapy); migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM, (coord *) 0); @@ -915,15 +908,15 @@ struct monst *mtmp; Mnam = Monnam(mtmp); pline("%s %s onto a teleport trap!", Mnam, vtense(Mnam, locomotion(mtmp->data, "jump"))); - seetrap(t_at(trapx, trapy)); + seetrap(t_at(g.trapx, g.trapy)); } /* don't use rloc_to() because worm tails must "move" */ remove_monster(mtmp->mx, mtmp->my); newsym(mtmp->mx, mtmp->my); /* update old location */ - place_monster(mtmp, trapx, trapy); + place_monster(mtmp, g.trapx, g.trapy); if (mtmp->wormno) worm_move(mtmp); - newsym(trapx, trapy); + newsym(g.trapx, g.trapy); goto mon_tele; case MUSE_POT_HEALING: @@ -1217,7 +1210,7 @@ register struct obj *otmp; case WAN_STRIKING: reveal_invis = TRUE; if (mtmp == &youmonst) { - if (zap_oseen) + if (g.zap_oseen) makeknown(WAN_STRIKING); if (Antimagic) { shieldeff(u.ux, u.uy); @@ -1239,18 +1232,18 @@ register struct obj *otmp; tmp = d(2, 12); hit("wand", mtmp, exclam(tmp)); (void) resist(mtmp, otmp->oclass, tmp, TELL); - if (cansee(mtmp->mx, mtmp->my) && zap_oseen) + if (cansee(mtmp->mx, mtmp->my) && g.zap_oseen) makeknown(WAN_STRIKING); } else { miss("wand", mtmp); - if (cansee(mtmp->mx, mtmp->my) && zap_oseen) + if (cansee(mtmp->mx, mtmp->my) && g.zap_oseen) makeknown(WAN_STRIKING); } break; #if 0 /* disabled because find_offensive() never picks WAN_TELEPORTATION */ case WAN_TELEPORTATION: if (mtmp == &youmonst) { - if (zap_oseen) + if (g.zap_oseen) makeknown(WAN_TELEPORTATION); tele(); } else { @@ -1349,7 +1342,7 @@ struct obj *obj; /* 2nd arg to fhitm/fhito */ case WAN_LOCKING: case WAN_STRIKING: if (doorlock(obj, bhitpos.x, bhitpos.y)) { - if (zap_oseen) + if (g.zap_oseen) makeknown(obj->otyp); /* if a shop door gets broken, add it to the shk's fix list (no cost to player) */ @@ -1419,7 +1412,7 @@ struct monst *mtmp; return (DEADMONSTER(mtmp)) ? 1 : 2; case MUSE_WAN_TELEPORTATION: case MUSE_WAN_STRIKING: - zap_oseen = oseen; + g.zap_oseen = oseen; mzapmsg(mtmp, otmp, FALSE); otmp->spe--; g.m_using = TRUE; @@ -1647,8 +1640,8 @@ struct monst *mtmp; && !onscary(xx, yy, mtmp)) { /* use trap if it's the correct type */ if (t->ttyp == POLY_TRAP) { - trapx = xx; - trapy = yy; + g.trapx = xx; + g.trapy = yy; m.has_misc = MUSE_POLY_TRAP; return TRUE; } @@ -1876,15 +1869,15 @@ struct monst *mtmp; vtense(Mnam, locomotion(mtmp->data, "jump"))); } if (vis) - seetrap(t_at(trapx, trapy)); + seetrap(t_at(g.trapx, g.trapy)); /* don't use rloc() due to worms */ remove_monster(mtmp->mx, mtmp->my); newsym(mtmp->mx, mtmp->my); - place_monster(mtmp, trapx, trapy); + place_monster(mtmp, g.trapx, g.trapy); if (mtmp->wormno) worm_move(mtmp); - newsym(trapx, trapy); + newsym(g.trapx, g.trapy); (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE); return 2; diff --git a/src/pray.c b/src/pray.c index e1f55cb49..68e6d817f 100644 --- a/src/pray.c +++ b/src/pray.c @@ -47,11 +47,6 @@ static const char *godvoices[] = { "booms out", "thunders", "rings out", "booms", }; -/* values calculated when prayer starts, and used when completed */ -static aligntyp p_aligntyp; -static int p_trouble; -static int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */ - #define PIOUS 20 #define DEVOUT 14 #define FERVENT 9 @@ -907,7 +902,7 @@ aligntyp g_align; : Hallucination ? "full" : "satisfied"); /* not your deity */ - if (on_altar() && p_aligntyp != u.ualign.type) { + if (on_altar() && g.p_aligntyp != u.ualign.type) { adjalign(-1); return; } else if (u.ualign.record < 2 && trouble <= 0) @@ -929,7 +924,7 @@ aligntyp g_align; */ if (!trouble && u.ualign.record >= DEVOUT) { /* if hero was in trouble, but got better, no special favor */ - if (p_trouble == 0) + if (g.p_trouble == 0) pat_on_head = 1; } else { int action, prayer_luck; @@ -1768,47 +1763,47 @@ boolean praying; /* false means no messages should be given */ { int alignment; - p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type; - p_trouble = in_trouble(); + g.p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type; + g.p_trouble = in_trouble(); - if (is_demon(youmonst.data) && (p_aligntyp != A_CHAOTIC)) { + if (is_demon(youmonst.data) && (g.p_aligntyp != A_CHAOTIC)) { if (praying) pline_The("very idea of praying to a %s god is repugnant to you.", - p_aligntyp ? "lawful" : "neutral"); + g.p_aligntyp ? "lawful" : "neutral"); return FALSE; } if (praying) - You("begin praying to %s.", align_gname(p_aligntyp)); + You("begin praying to %s.", align_gname(g.p_aligntyp)); - if (u.ualign.type && u.ualign.type == -p_aligntyp) + if (u.ualign.type && u.ualign.type == -g.p_aligntyp) alignment = -u.ualign.record; /* Opposite alignment altar */ - else if (u.ualign.type != p_aligntyp) + else if (u.ualign.type != g.p_aligntyp) alignment = u.ualign.record / 2; /* Different alignment altar */ else alignment = u.ualign.record; - if ((p_trouble > 0) ? (u.ublesscnt > 200) /* big trouble */ - : (p_trouble < 0) ? (u.ublesscnt > 100) /* minor difficulties */ + if ((g.p_trouble > 0) ? (u.ublesscnt > 200) /* big trouble */ + : (g.p_trouble < 0) ? (u.ublesscnt > 100) /* minor difficulties */ : (u.ublesscnt > 0)) /* not in trouble */ - p_type = 0; /* too soon... */ + g.p_type = 0; /* too soon... */ else if ((int) Luck < 0 || u.ugangr || alignment < 0) - p_type = 1; /* too naughty... */ + g.p_type = 1; /* too naughty... */ else /* alignment >= 0 */ { - if (on_altar() && u.ualign.type != p_aligntyp) - p_type = 2; + if (on_altar() && u.ualign.type != g.p_aligntyp) + g.p_type = 2; else - p_type = 3; + g.p_type = 3; } if (is_undead(youmonst.data) && !Inhell - && (p_aligntyp == A_LAWFUL || (p_aligntyp == A_NEUTRAL && !rn2(10)))) - p_type = -1; + && (g.p_aligntyp == A_LAWFUL || (g.p_aligntyp == A_NEUTRAL && !rn2(10)))) + g.p_type = -1; /* Note: when !praying, the random factor for neutrals makes the return value a non-deterministic approximation for enlightenment. This case should be uncommon enough to live with... */ - return !praying ? (boolean) (p_type == 3 && !Inhell) : TRUE; + return !praying ? (boolean) (g.p_type == 3 && !Inhell) : TRUE; } /* #pray commmand */ @@ -1825,7 +1820,7 @@ dopray() if (!can_pray(TRUE)) return 0; - if (wizard && p_type >= 0) { + if (wizard && g.p_type >= 0) { if (yn("Force the gods to be pleased?") == 'y') { u.ublesscnt = 0; if (u.uluck < 0) @@ -1833,8 +1828,8 @@ dopray() if (u.ualign.record <= 0) u.ualign.record = 1; u.ugangr = 0; - if (p_type < 2) - p_type = 3; + if (g.p_type < 2) + g.p_type = 3; } } nomul(-3); @@ -1842,7 +1837,7 @@ dopray() nomovemsg = "You finish your prayer."; afternmv = prayer_done; - if (p_type == 3 && !Inhell) { + if (g.p_type == 3 && !Inhell) { /* if you've been true to your god you can't die while you pray */ if (!Blind) You("are surrounded by a shimmering light."); @@ -1855,10 +1850,10 @@ dopray() STATIC_PTR int prayer_done() /* M. Stephenson (1.0.3b) */ { - aligntyp alignment = p_aligntyp; + aligntyp alignment = g.p_aligntyp; u.uinvulnerable = FALSE; - if (p_type == -1) { + if (g.p_type == -1) { godvoice(alignment, (alignment == A_LAWFUL) ? "Vile creature, thou durst call upon me?" @@ -1880,17 +1875,17 @@ prayer_done() /* M. Stephenson (1.0.3b) */ return 0; } - if (p_type == 0) { + if (g.p_type == 0) { if (on_altar() && u.ualign.type != alignment) (void) water_prayer(FALSE); u.ublesscnt += rnz(250); change_luck(-3); gods_upset(u.ualign.type); - } else if (p_type == 1) { + } else if (g.p_type == 1) { if (on_altar() && u.ualign.type != alignment) (void) water_prayer(FALSE); angrygods(u.ualign.type); /* naughty */ - } else if (p_type == 2) { + } else if (g.p_type == 2) { if (water_prayer(FALSE)) { /* attempted water prayer on a non-coaligned altar */ u.ublesscnt += rnz(250); diff --git a/util/lev_main.c b/util/lev_main.c index 670457b8e..a68e7ee85 100644 --- a/util/lev_main.c +++ b/util/lev_main.c @@ -108,9 +108,6 @@ 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_globals_init); - void FDECL(add_opcode, (sp_lev *, int, genericptr_t)); static boolean FDECL(write_common_data, (int)); @@ -258,11 +255,7 @@ char **argv; decl_globals_init(); objects_globals_init(); - - /* Note: these initializers don't do anything except guarantee that - * we're linked properly. - */ - monst_init(); + monst_globals_init(); /* this one does something... */ init_obj_classes(); diff --git a/util/makedefs.c b/util/makedefs.c index 59a82f663..504a0d424 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -175,10 +175,9 @@ void NDECL(do_vision); void NDECL(do_fix_sampleconfig); #endif -extern void NDECL(monst_init); /* monst.c */ +extern void NDECL(monst_globals_init); /* monst.c */ extern void NDECL(objects_globals_init); /* objects.c */ -static void NDECL(link_sanity_check); static char *FDECL(name_file, (const char *, const char *)); static void FDECL(delete_file, (const char *template, const char *)); static FILE *FDECL(getfp, (const char *, const char *, const char *)); @@ -301,16 +300,6 @@ char *argv[]; #endif -static void -link_sanity_check() -{ - /* Note: these initializers don't do anything except guarantee that - we're linked properly. - */ - monst_init(); - -} - void do_makedefs(options) char *options; @@ -318,8 +307,7 @@ char *options; boolean more_than_one; objects_globals_init(); - - link_sanity_check(); + monst_globals_init(); /* construct the current version number */ make_version(); @@ -469,8 +457,6 @@ do_ext_makedefs(int argc, char **argv) { int todo = 0; - link_sanity_check(); - argc--; argv++; /* skip program name */ diff --git a/win/share/tile2bmp.c b/win/share/tile2bmp.c index 8fb16e425..522cee762 100644 --- a/win/share/tile2bmp.c +++ b/win/share/tile2bmp.c @@ -204,6 +204,7 @@ char *argv[]; #endif objects_globals_init(); + monst_globals_init(); tilecount = 0; xoffset = yoffset = 0; diff --git a/win/share/tilemap.c b/win/share/tilemap.c index 1e59381b7..39f3d4fc3 100644 --- a/win/share/tilemap.c +++ b/win/share/tilemap.c @@ -109,10 +109,6 @@ int set, entry; int i, j, condnum, tilenum; static char buf[BUFSZ]; - /* Note: these initializers don't do anything except guarantee that - we're linked properly. - */ - monst_init(); (void) def_char_to_objclass(']'); condnum = tilenum = 0; From 471224ea70e1b0295fa42f3796c2991bfbe8a61a Mon Sep 17 00:00:00 2001 From: Bart House Date: Fri, 23 Nov 2018 21:06:53 -0800 Subject: [PATCH 04/11] artifact.c, cmd.c and makemon.c globals moved to instance_globals. --- include/decl.h | 88 ++++++++++++++++ include/flag.h | 74 -------------- src/artifact.c | 41 ++++---- src/cmd.c | 272 ++++++++++++++++++++++++------------------------- src/decl.c | 9 ++ src/dig.c | 2 +- src/do_name.c | 92 ++++++++--------- src/makemon.c | 31 +++--- src/options.c | 8 +- 9 files changed, 314 insertions(+), 303 deletions(-) diff --git a/include/decl.h b/include/decl.h index 8bad9caa9..c9b2f5550 100644 --- a/include/decl.h +++ b/include/decl.h @@ -442,6 +442,78 @@ struct early_opt { boolean valallowed; }; +/* special key functions */ +enum nh_keyfunc { + NHKF_ESC = 0, + NHKF_DOAGAIN, + + NHKF_REQMENU, + + /* run ... clicklook need to be in a continuous block */ + NHKF_RUN, + NHKF_RUN2, + NHKF_RUSH, + NHKF_FIGHT, + NHKF_FIGHT2, + NHKF_NOPICKUP, + NHKF_RUN_NOPICKUP, + NHKF_DOINV, + NHKF_TRAVEL, + NHKF_CLICKLOOK, + + NHKF_REDRAW, + NHKF_REDRAW2, + NHKF_GETDIR_SELF, + NHKF_GETDIR_SELF2, + NHKF_GETDIR_HELP, + NHKF_COUNT, + NHKF_GETPOS_SELF, + NHKF_GETPOS_PICK, + NHKF_GETPOS_PICK_Q, /* quick */ + NHKF_GETPOS_PICK_O, /* once */ + NHKF_GETPOS_PICK_V, /* verbose */ + NHKF_GETPOS_SHOWVALID, + NHKF_GETPOS_AUTODESC, + NHKF_GETPOS_MON_NEXT, + NHKF_GETPOS_MON_PREV, + NHKF_GETPOS_OBJ_NEXT, + NHKF_GETPOS_OBJ_PREV, + NHKF_GETPOS_DOOR_NEXT, + NHKF_GETPOS_DOOR_PREV, + NHKF_GETPOS_UNEX_NEXT, + NHKF_GETPOS_UNEX_PREV, + NHKF_GETPOS_INTERESTING_NEXT, + NHKF_GETPOS_INTERESTING_PREV, + NHKF_GETPOS_VALID_NEXT, + NHKF_GETPOS_VALID_PREV, + NHKF_GETPOS_HELP, + NHKF_GETPOS_MENU, + NHKF_GETPOS_LIMITVIEW, + NHKF_GETPOS_MOVESKIP, + + NUM_NHKF +}; + +/* commands[] is used to directly access cmdlist[] instead of looping + through it to find the entry for a given input character; + move_X is the character used for moving one step in direction X; + alphadirchars corresponds to old sdir, + dirchars corresponds to ``iflags.num_pad ? ndir : sdir''; + pcHack_compat and phone_layout only matter when num_pad is on, + swap_yz only matters when it's off */ +struct cmd { + unsigned serialno; /* incremented after each update */ + boolean num_pad; /* same as iflags.num_pad except during updates */ + boolean pcHack_compat; /* for numpad: affects 5, M-5, and M-0 */ + boolean phone_layout; /* inverted keypad: 1,2,3 above, 7,8,9 below */ + boolean swap_yz; /* QWERTZ keyboards; use z to move NW, y to zap */ + char move_W, move_NW, move_N, move_NE, move_E, move_SE, move_S, move_SW; + const char *dirchars; /* current movement/direction characters */ + const char *alphadirchars; /* same as dirchars if !numpad */ + const struct ext_func_tab *commands[256]; /* indexed by input character */ + char spkeys[NUM_NHKF]; +}; + /* 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. @@ -449,19 +521,35 @@ struct early_opt { * 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() */ + /* flags including which artifacts have already been created */ + boolean artiexist[1 + NROFARTIFACTS + 1]; + /* and a discovery list for them (no dummy first entry here) */ + xchar artidisco[NROFARTIFACTS]; + /* botl.c */ int mrank_sz; /* loaded by max_rank_sz */ + /* cmd.c */ + struct cmd Cmd; /* flag.h */ + /* dog.c */ int petname_used; /* user preferred pet name has been used */ + /* makemon.c */ + struct { + int choice_count; + char mchoices[SPECIAL_PM]; /* value range is 0..127 */ + } rndmonst_state; + /* muse.c */ boolean m_using; /* kludge to use mondided instead of killed */ int trapx; diff --git a/include/flag.h b/include/flag.h index 1306356c4..812fb6191 100644 --- a/include/flag.h +++ b/include/flag.h @@ -529,58 +529,6 @@ enum runmode_types { struct ext_func_tab; /* from func_tab.h */ #endif -/* special key functions */ -enum nh_keyfunc { - NHKF_ESC = 0, - NHKF_DOAGAIN, - - NHKF_REQMENU, - - /* run ... clicklook need to be in a continuous block */ - NHKF_RUN, - NHKF_RUN2, - NHKF_RUSH, - NHKF_FIGHT, - NHKF_FIGHT2, - NHKF_NOPICKUP, - NHKF_RUN_NOPICKUP, - NHKF_DOINV, - NHKF_TRAVEL, - NHKF_CLICKLOOK, - - NHKF_REDRAW, - NHKF_REDRAW2, - NHKF_GETDIR_SELF, - NHKF_GETDIR_SELF2, - NHKF_GETDIR_HELP, - NHKF_COUNT, - NHKF_GETPOS_SELF, - NHKF_GETPOS_PICK, - NHKF_GETPOS_PICK_Q, /* quick */ - NHKF_GETPOS_PICK_O, /* once */ - NHKF_GETPOS_PICK_V, /* verbose */ - NHKF_GETPOS_SHOWVALID, - NHKF_GETPOS_AUTODESC, - NHKF_GETPOS_MON_NEXT, - NHKF_GETPOS_MON_PREV, - NHKF_GETPOS_OBJ_NEXT, - NHKF_GETPOS_OBJ_PREV, - NHKF_GETPOS_DOOR_NEXT, - NHKF_GETPOS_DOOR_PREV, - NHKF_GETPOS_UNEX_NEXT, - NHKF_GETPOS_UNEX_PREV, - NHKF_GETPOS_INTERESTING_NEXT, - NHKF_GETPOS_INTERESTING_PREV, - NHKF_GETPOS_VALID_NEXT, - NHKF_GETPOS_VALID_PREV, - NHKF_GETPOS_HELP, - NHKF_GETPOS_MENU, - NHKF_GETPOS_LIMITVIEW, - NHKF_GETPOS_MOVESKIP, - - NUM_NHKF -}; - enum gloctypes { GLOC_MONS = 0, GLOC_OBJS, @@ -592,26 +540,4 @@ enum gloctypes { NUM_GLOCS }; -/* commands[] is used to directly access cmdlist[] instead of looping - through it to find the entry for a given input character; - move_X is the character used for moving one step in direction X; - alphadirchars corresponds to old sdir, - dirchars corresponds to ``iflags.num_pad ? ndir : sdir''; - pcHack_compat and phone_layout only matter when num_pad is on, - swap_yz only matters when it's off */ -struct cmd { - unsigned serialno; /* incremented after each update */ - boolean num_pad; /* same as iflags.num_pad except during updates */ - boolean pcHack_compat; /* for numpad: affects 5, M-5, and M-0 */ - boolean phone_layout; /* inverted keypad: 1,2,3 above, 7,8,9 below */ - boolean swap_yz; /* QWERTZ keyboards; use z to move NW, y to zap */ - char move_W, move_NW, move_N, move_NE, move_E, move_SE, move_S, move_SW; - const char *dirchars; /* current movement/direction characters */ - const char *alphadirchars; /* same as dirchars if !numpad */ - const struct ext_func_tab *commands[256]; /* indexed by input character */ - char spkeys[NUM_NHKF]; -}; - -extern NEARDATA struct cmd Cmd; - #endif /* FLAG_H */ diff --git a/src/artifact.c b/src/artifact.c index 72385ec1c..80de4681a 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -39,11 +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 -/* 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) */ -STATIC_OVL xchar artidisco[NROFARTIFACTS]; - STATIC_DCL void NDECL(hack_artifacts); STATIC_DCL boolean FDECL(attacks, (int, struct obj *)); @@ -75,8 +70,8 @@ hack_artifacts() void init_artifacts() { - (void) memset((genericptr_t) artiexist, 0, sizeof artiexist); - (void) memset((genericptr_t) artidisco, 0, sizeof artidisco); + (void) memset((genericptr_t) g.artiexist, 0, sizeof g.artiexist); + (void) memset((genericptr_t) g.artidisco, 0, sizeof g.artidisco); hack_artifacts(); } @@ -84,16 +79,16 @@ void save_artifacts(fd) int fd; { - bwrite(fd, (genericptr_t) artiexist, sizeof artiexist); - bwrite(fd, (genericptr_t) artidisco, sizeof artidisco); + bwrite(fd, (genericptr_t) g.artiexist, sizeof g.artiexist); + bwrite(fd, (genericptr_t) g.artidisco, sizeof g.artidisco); } void restore_artifacts(fd) int fd; { - mread(fd, (genericptr_t) artiexist, sizeof artiexist); - mread(fd, (genericptr_t) artidisco, sizeof artidisco); + mread(fd, (genericptr_t) g.artiexist, sizeof g.artiexist); + mread(fd, (genericptr_t) g.artidisco, sizeof g.artidisco); hack_artifacts(); /* redo non-saved special cases */ } @@ -133,7 +128,7 @@ aligntyp alignment; /* target alignment, or A_NONE */ eligible[0] = 0; /* lint suppression */ /* gather eligible artifacts */ for (m = 1, a = &artilist[m]; a->otyp; a++, m++) { - if (artiexist[m]) + if (g.artiexist[m]) continue; if ((a->spfx & SPFX_NOGEN) || unique) continue; @@ -193,7 +188,7 @@ aligntyp alignment; /* target alignment, or A_NONE */ if (otmp) { otmp = oname(otmp, a->name); otmp->oartifact = m; - artiexist[m] = TRUE; + g.artiexist[m] = TRUE; } } else { /* nothing appropriate could be found; return original object */ @@ -243,7 +238,7 @@ const char *name; boolean *arex; if (otyp && *name) - for (a = artilist + 1, arex = artiexist + 1; a->otyp; a++, arex++) + for (a = artilist + 1, arex = g.artiexist + 1; a->otyp; a++, arex++) if ((int) a->otyp == otyp && !strcmp(a->name, name)) return *arex; return FALSE; @@ -265,7 +260,7 @@ boolean mod; otmp->age = 0; if (otmp->otyp == RIN_INCREASE_DAMAGE) otmp->spe = 0; - artiexist[m] = mod; + g.artiexist[m] = mod; break; } return; @@ -275,10 +270,10 @@ int nartifact_exist() { int a = 0; - int n = SIZE(artiexist); + int n = SIZE(g.artiexist); while (n > 1) - if (artiexist[--n]) + if (g.artiexist[--n]) a++; return a; @@ -866,8 +861,8 @@ xchar m; /* look for this artifact in the discoveries list; if we hit an empty slot then it's not present, so add it */ for (i = 0; i < NROFARTIFACTS; i++) - if (artidisco[i] == 0 || artidisco[i] == m) { - artidisco[i] = m; + if (g.artidisco[i] == 0 || g.artidisco[i] == m) { + g.artidisco[i] = m; return; } /* there is one slot per artifact, so we should never reach the @@ -885,9 +880,9 @@ xchar m; /* look for this artifact in the discoveries list; if we hit an empty slot then it's undiscovered */ for (i = 0; i < NROFARTIFACTS; i++) - if (artidisco[i] == m) + if (g.artidisco[i] == m) return FALSE; - else if (artidisco[i] == 0) + else if (g.artidisco[i] == 0) break; return TRUE; } @@ -901,14 +896,14 @@ winid tmpwin; /* supplied by dodiscover() */ char buf[BUFSZ]; for (i = 0; i < NROFARTIFACTS; i++) { - if (artidisco[i] == 0) + if (g.artidisco[i] == 0) break; /* empty slot implies end of list */ if (tmpwin == WIN_ERR) continue; /* for WIN_ERR, we just count */ if (i == 0) putstr(tmpwin, iflags.menu_headings, "Artifacts"); - m = artidisco[i]; + m = g.artidisco[i]; otyp = artilist[m].otyp; Sprintf(buf, " %s [%s %s]", artiname(m), align_str(artilist[m].alignment), simple_typename(otyp)); diff --git a/src/cmd.c b/src/cmd.c index 0e0a56fb7..d586a697a 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -27,8 +27,6 @@ STATIC_VAR boolean alt_esc = FALSE; #endif -struct cmd Cmd = { 0 }; /* flag.h */ - extern const char *hu_stat[]; /* hunger status from eat.c */ extern const char *enc_stat[]; /* encumbrance status from botl.c */ @@ -354,7 +352,7 @@ doextcmd(VOID_ARGS) } if (iflags.menu_requested && !accept_menu_prefix(func)) { pline("'%s' prefix has no effect for the %s command.", - visctrl(Cmd.spkeys[NHKF_REQMENU]), + visctrl(g.Cmd.spkeys[NHKF_REQMENU]), extcmdlist[idx].ef_txt); iflags.menu_requested = FALSE; } @@ -3412,8 +3410,8 @@ const char * key2extcmddesc(key) uchar key; { - if (Cmd.commands[key] && Cmd.commands[key]->ef_txt) - return Cmd.commands[key]->ef_desc; + if (g.Cmd.commands[key] && g.Cmd.commands[key]->ef_txt) + return g.Cmd.commands[key]->ef_desc; return (char *) 0; } @@ -3426,14 +3424,14 @@ const char *command; /* special case: "nothing" is reserved for unbinding */ if (!strcmp(command, "nothing")) { - Cmd.commands[key] = (struct ext_func_tab *) 0; + g.Cmd.commands[key] = (struct ext_func_tab *) 0; return TRUE; } for (extcmd = extcmdlist; extcmd->ef_txt; extcmd++) { if (strcmp(command, extcmd->ef_txt)) continue; - Cmd.commands[key] = extcmd; + g.Cmd.commands[key] = extcmd; #if 0 /* silently accept key binding for unavailable command (!SHELL,&c) */ if ((extcmd->flags & CMD_NOT_AVAILABLE) != 0) { char buf[BUFSZ]; @@ -3456,7 +3454,7 @@ commands_init() for (extcmd = extcmdlist; extcmd->ef_txt; extcmd++) if (extcmd->key) - Cmd.commands[extcmd->key] = extcmd; + g.Cmd.commands[extcmd->key] = extcmd; (void) bind_key(C('l'), "redraw"); /* if number_pad is set */ /* 'b', 'B' : go sw */ @@ -3501,7 +3499,7 @@ boolean *keys_used; /* boolean keys_used[256] */ continue; if (key == ' ' && !flags.rest_on_space) continue; - if ((extcmd = Cmd.commands[i]) != (struct ext_func_tab *) 0) { + if ((extcmd = g.Cmd.commands[i]) != (struct ext_func_tab *) 0) { if ((cmdflags && !(extcmd->flags & cmdflags)) || (exflags && (extcmd->flags & exflags))) continue; @@ -3565,29 +3563,29 @@ dokeylist(VOID_ARGS) putstr(datawin, 0, "Directional keys:"); show_direction_keys(datawin, '.', FALSE); /* '.'==self in direction grid */ - keys_used[(uchar) Cmd.move_NW] = keys_used[(uchar) Cmd.move_N] - = keys_used[(uchar) Cmd.move_NE] = keys_used[(uchar) Cmd.move_W] - = keys_used[(uchar) Cmd.move_E] = keys_used[(uchar) Cmd.move_SW] - = keys_used[(uchar) Cmd.move_S] = keys_used[(uchar) Cmd.move_SE] + keys_used[(uchar) g.Cmd.move_NW] = keys_used[(uchar) g.Cmd.move_N] + = keys_used[(uchar) g.Cmd.move_NE] = keys_used[(uchar) g.Cmd.move_W] + = keys_used[(uchar) g.Cmd.move_E] = keys_used[(uchar) g.Cmd.move_SW] + = keys_used[(uchar) g.Cmd.move_S] = keys_used[(uchar) g.Cmd.move_SE] = TRUE; if (!iflags.num_pad) { - keys_used[(uchar) highc(Cmd.move_NW)] - = keys_used[(uchar) highc(Cmd.move_N)] - = keys_used[(uchar) highc(Cmd.move_NE)] - = keys_used[(uchar) highc(Cmd.move_W)] - = keys_used[(uchar) highc(Cmd.move_E)] - = keys_used[(uchar) highc(Cmd.move_SW)] - = keys_used[(uchar) highc(Cmd.move_S)] - = keys_used[(uchar) highc(Cmd.move_SE)] = TRUE; - keys_used[(uchar) C(Cmd.move_NW)] - = keys_used[(uchar) C(Cmd.move_N)] - = keys_used[(uchar) C(Cmd.move_NE)] - = keys_used[(uchar) C(Cmd.move_W)] - = keys_used[(uchar) C(Cmd.move_E)] - = keys_used[(uchar) C(Cmd.move_SW)] - = keys_used[(uchar) C(Cmd.move_S)] - = keys_used[(uchar) C(Cmd.move_SE)] = TRUE; + keys_used[(uchar) highc(g.Cmd.move_NW)] + = keys_used[(uchar) highc(g.Cmd.move_N)] + = keys_used[(uchar) highc(g.Cmd.move_NE)] + = keys_used[(uchar) highc(g.Cmd.move_W)] + = keys_used[(uchar) highc(g.Cmd.move_E)] + = keys_used[(uchar) highc(g.Cmd.move_SW)] + = keys_used[(uchar) highc(g.Cmd.move_S)] + = keys_used[(uchar) highc(g.Cmd.move_SE)] = TRUE; + keys_used[(uchar) C(g.Cmd.move_NW)] + = keys_used[(uchar) C(g.Cmd.move_N)] + = keys_used[(uchar) C(g.Cmd.move_NE)] + = keys_used[(uchar) C(g.Cmd.move_W)] + = keys_used[(uchar) C(g.Cmd.move_E)] + = keys_used[(uchar) C(g.Cmd.move_SW)] + = keys_used[(uchar) C(g.Cmd.move_S)] + = keys_used[(uchar) C(g.Cmd.move_SE)] = TRUE; putstr(datawin, 0, ""); putstr(datawin, 0, "Shift- will move in specified direction until you hit"); @@ -3600,7 +3598,7 @@ dokeylist(VOID_ARGS) putstr(datawin, 0, ""); putstr(datawin, 0, "Miscellaneous keys:"); for (i = 0; misc_keys[i].desc; i++) { - key = Cmd.spkeys[misc_keys[i].nhkf]; + key = g.Cmd.spkeys[misc_keys[i].nhkf]; if (key && ((misc_keys[i].numpad && iflags.num_pad) || !misc_keys[i].numpad)) { keys_used[(uchar) key] = TRUE; @@ -3647,7 +3645,7 @@ int NDECL((*fn)); int i; for (i = 0; i < 256; ++i) - if (Cmd.commands[i] && Cmd.commands[i]->ef_funct == fn) + if (g.Cmd.commands[i] && g.Cmd.commands[i]->ef_funct == fn) return (char) i; return '\0'; } @@ -4144,7 +4142,7 @@ const char *command; for (i = 0; i < SIZE(spkeys_binds); i++) { if (!spkeys_binds[i].name || strcmp(command, spkeys_binds[i].name)) continue; - Cmd.spkeys[spkeys_binds[i].nhkf] = key; + g.Cmd.spkeys[spkeys_binds[i].nhkf] = key; return TRUE; } return FALSE; @@ -4299,97 +4297,97 @@ boolean initial; if (initial) { updated = 1; - Cmd.num_pad = FALSE; - Cmd.pcHack_compat = Cmd.phone_layout = Cmd.swap_yz = FALSE; + g.Cmd.num_pad = FALSE; + g.Cmd.pcHack_compat = g.Cmd.phone_layout = g.Cmd.swap_yz = FALSE; for (i = 0; i < SIZE(spkeys_binds); i++) - Cmd.spkeys[spkeys_binds[i].nhkf] = spkeys_binds[i].key; + g.Cmd.spkeys[spkeys_binds[i].nhkf] = spkeys_binds[i].key; commands_init(); } else { if (backed_dir_cmd) { for (i = 0; i < 8; i++) { - Cmd.commands[(uchar) Cmd.dirchars[i]] = back_dir_cmd[i]; + g.Cmd.commands[(uchar) g.Cmd.dirchars[i]] = back_dir_cmd[i]; } } /* basic num_pad */ flagtemp = iflags.num_pad; - if (flagtemp != Cmd.num_pad) { - Cmd.num_pad = flagtemp; + if (flagtemp != g.Cmd.num_pad) { + g.Cmd.num_pad = flagtemp; ++updated; } /* swap_yz mode (only applicable for !num_pad); intended for QWERTZ keyboard used in Central Europe, particularly Germany */ - flagtemp = (iflags.num_pad_mode & 1) ? !Cmd.num_pad : FALSE; - if (flagtemp != Cmd.swap_yz) { - Cmd.swap_yz = flagtemp; + flagtemp = (iflags.num_pad_mode & 1) ? !g.Cmd.num_pad : FALSE; + if (flagtemp != g.Cmd.swap_yz) { + g.Cmd.swap_yz = flagtemp; ++updated; - /* Cmd.swap_yz has been toggled; + /* g.Cmd.swap_yz has been toggled; perform the swap (or reverse previous one) */ for (i = 0; i < SIZE(ylist); i++) { c = ylist[i] & 0xff; - cmdtmp = Cmd.commands[c]; /* tmp = [y] */ - Cmd.commands[c] = Cmd.commands[c + 1]; /* [y] = [z] */ - Cmd.commands[c + 1] = cmdtmp; /* [z] = tmp */ + cmdtmp = g.Cmd.commands[c]; /* tmp = [y] */ + g.Cmd.commands[c] = g.Cmd.commands[c + 1]; /* [y] = [z] */ + g.Cmd.commands[c + 1] = cmdtmp; /* [z] = tmp */ } } /* MSDOS compatibility mode (only applicable for num_pad) */ - flagtemp = (iflags.num_pad_mode & 1) ? Cmd.num_pad : FALSE; - if (flagtemp != Cmd.pcHack_compat) { - Cmd.pcHack_compat = flagtemp; + flagtemp = (iflags.num_pad_mode & 1) ? g.Cmd.num_pad : FALSE; + if (flagtemp != g.Cmd.pcHack_compat) { + g.Cmd.pcHack_compat = flagtemp; ++updated; /* pcHack_compat has been toggled */ c = M('5') & 0xff; - cmdtmp = Cmd.commands['5']; - Cmd.commands['5'] = Cmd.commands[c]; - Cmd.commands[c] = cmdtmp; + cmdtmp = g.Cmd.commands['5']; + g.Cmd.commands['5'] = g.Cmd.commands[c]; + g.Cmd.commands[c] = cmdtmp; c = M('0') & 0xff; - Cmd.commands[c] = Cmd.pcHack_compat ? Cmd.commands['I'] : 0; + g.Cmd.commands[c] = g.Cmd.pcHack_compat ? g.Cmd.commands['I'] : 0; } /* phone keypad layout (only applicable for num_pad) */ - flagtemp = (iflags.num_pad_mode & 2) ? Cmd.num_pad : FALSE; - if (flagtemp != Cmd.phone_layout) { - Cmd.phone_layout = flagtemp; + flagtemp = (iflags.num_pad_mode & 2) ? g.Cmd.num_pad : FALSE; + if (flagtemp != g.Cmd.phone_layout) { + g.Cmd.phone_layout = flagtemp; ++updated; /* phone_layout has been toggled */ for (i = 0; i < 3; i++) { c = '1' + i; /* 1,2,3 <-> 7,8,9 */ - cmdtmp = Cmd.commands[c]; /* tmp = [1] */ - Cmd.commands[c] = Cmd.commands[c + 6]; /* [1] = [7] */ - Cmd.commands[c + 6] = cmdtmp; /* [7] = tmp */ + cmdtmp = g.Cmd.commands[c]; /* tmp = [1] */ + g.Cmd.commands[c] = g.Cmd.commands[c + 6]; /* [1] = [7] */ + g.Cmd.commands[c + 6] = cmdtmp; /* [7] = tmp */ c = (M('1') & 0xff) + i; /* M-1,M-2,M-3 <-> M-7,M-8,M-9 */ - cmdtmp = Cmd.commands[c]; /* tmp = [M-1] */ - Cmd.commands[c] = Cmd.commands[c + 6]; /* [M-1] = [M-7] */ - Cmd.commands[c + 6] = cmdtmp; /* [M-7] = tmp */ + cmdtmp = g.Cmd.commands[c]; /* tmp = [M-1] */ + g.Cmd.commands[c] = g.Cmd.commands[c + 6]; /* [M-1] = [M-7] */ + g.Cmd.commands[c + 6] = cmdtmp; /* [M-7] = tmp */ } } } /*?initial*/ if (updated) - Cmd.serialno++; - Cmd.dirchars = !Cmd.num_pad - ? (!Cmd.swap_yz ? sdir : sdir_swap_yz) - : (!Cmd.phone_layout ? ndir : ndir_phone_layout); - Cmd.alphadirchars = !Cmd.num_pad ? Cmd.dirchars : sdir; + g.Cmd.serialno++; + g.Cmd.dirchars = !g.Cmd.num_pad + ? (!g.Cmd.swap_yz ? sdir : sdir_swap_yz) + : (!g.Cmd.phone_layout ? ndir : ndir_phone_layout); + g.Cmd.alphadirchars = !g.Cmd.num_pad ? g.Cmd.dirchars : sdir; - Cmd.move_W = Cmd.dirchars[0]; - Cmd.move_NW = Cmd.dirchars[1]; - Cmd.move_N = Cmd.dirchars[2]; - Cmd.move_NE = Cmd.dirchars[3]; - Cmd.move_E = Cmd.dirchars[4]; - Cmd.move_SE = Cmd.dirchars[5]; - Cmd.move_S = Cmd.dirchars[6]; - Cmd.move_SW = Cmd.dirchars[7]; + g.Cmd.move_W = g.Cmd.dirchars[0]; + g.Cmd.move_NW = g.Cmd.dirchars[1]; + g.Cmd.move_N = g.Cmd.dirchars[2]; + g.Cmd.move_NE = g.Cmd.dirchars[3]; + g.Cmd.move_E = g.Cmd.dirchars[4]; + g.Cmd.move_SE = g.Cmd.dirchars[5]; + g.Cmd.move_S = g.Cmd.dirchars[6]; + g.Cmd.move_SW = g.Cmd.dirchars[7]; if (!initial) { for (i = 0; i < 8; i++) { back_dir_cmd[i] = - (struct ext_func_tab *) Cmd.commands[(uchar) Cmd.dirchars[i]]; - Cmd.commands[(uchar) Cmd.dirchars[i]] = (struct ext_func_tab *) 0; + (struct ext_func_tab *) g.Cmd.commands[(uchar) g.Cmd.dirchars[i]]; + g.Cmd.commands[(uchar) g.Cmd.dirchars[i]] = (struct ext_func_tab *) 0; } backed_dir_cmd = TRUE; for (i = 0; i < 8; i++) - (void) bind_key(Cmd.dirchars[i], "nothing"); + (void) bind_key(g.Cmd.dirchars[i], "nothing"); } } @@ -4475,7 +4473,7 @@ int start,end; int i; for (i = start; i <= end; i++) - if (Cmd.spkeys[i] == c) + if (g.Cmd.spkeys[i] == c) return i; return NHKF_ESC; } @@ -4497,7 +4495,7 @@ register char *cmd; context.nopick = 0; cmd = parse(); } - if (*cmd == Cmd.spkeys[NHKF_ESC]) { + if (*cmd == g.Cmd.spkeys[NHKF_ESC]) { context.move = FALSE; return; } @@ -4529,7 +4527,7 @@ register char *cmd; prefix_seen = TRUE; break; case NHKF_RUN2: - if (!Cmd.num_pad) + if (!g.Cmd.num_pad) break; /*FALLTHRU*/ case NHKF_RUN: @@ -4540,7 +4538,7 @@ register char *cmd; prefix_seen = TRUE; break; case NHKF_FIGHT2: - if (!Cmd.num_pad) + if (!g.Cmd.num_pad) break; /*FALLTHRU*/ /* Effects of movement commands and invisible monsters: @@ -4575,7 +4573,7 @@ register char *cmd; prefix_seen = TRUE; break; case NHKF_DOINV: - if (!Cmd.num_pad) + if (!g.Cmd.num_pad) break; (void) ddoinv(); /* a convenience borrowed from the PC */ context.move = FALSE; @@ -4601,7 +4599,7 @@ register char *cmd; if (movecmd(*cmd)) { /* ordinary movement */ context.run = 0; /* only matters here if it was 8 */ do_walk = TRUE; - } else if (movecmd(Cmd.num_pad ? unmeta(*cmd) : lowc(*cmd))) { + } else if (movecmd(g.Cmd.num_pad ? unmeta(*cmd) : lowc(*cmd))) { context.run = 1; do_rush = TRUE; } else if (movecmd(unctrl(*cmd))) { @@ -4613,9 +4611,9 @@ register char *cmd; /* some special prefix handling */ /* overload 'm' prefix to mean "request a menu" */ - if (prefix_seen && cmd[0] == Cmd.spkeys[NHKF_REQMENU]) { + if (prefix_seen && cmd[0] == g.Cmd.spkeys[NHKF_REQMENU]) { /* (for func_tab cast, see below) */ - const struct ext_func_tab *ft = Cmd.commands[cmd[1] & 0xff]; + const struct ext_func_tab *ft = g.Cmd.commands[cmd[1] & 0xff]; int NDECL((*func)) = ft ? ((struct ext_func_tab *) ft)->ef_funct : 0; if (func && accept_menu_prefix(func)) { @@ -4653,7 +4651,7 @@ register char *cmd; context.mv = TRUE; domove(); return; - } else if (prefix_seen && cmd[1] == Cmd.spkeys[NHKF_ESC]) { + } else if (prefix_seen && cmd[1] == g.Cmd.spkeys[NHKF_ESC]) { /* */ /* don't report "unknown command" for change of heart... */ bad_command = FALSE; @@ -4666,7 +4664,7 @@ register char *cmd; int res, NDECL((*func)); /* current - use *cmd to directly index cmdlist array */ - if ((tlist = Cmd.commands[*cmd & 0xff]) != 0) { + if ((tlist = g.Cmd.commands[*cmd & 0xff]) != 0) { if (!wizard && (tlist->flags & WIZMODECMD)) { You_cant("do that!"); res = 0; @@ -4737,14 +4735,14 @@ int movecmd(sym) char sym; { - register const char *dp = index(Cmd.dirchars, sym); + register const char *dp = index(g.Cmd.dirchars, sym); u.dz = 0; if (!dp || !*dp) return 0; - u.dx = xdir[dp - Cmd.dirchars]; - u.dy = ydir[dp - Cmd.dirchars]; - u.dz = zdir[dp - Cmd.dirchars]; + u.dx = xdir[dp - g.Cmd.dirchars]; + u.dy = ydir[dp - g.Cmd.dirchars]; + u.dz = zdir[dp - g.Cmd.dirchars]; #if 0 /* now handled elsewhere */ if (u.dx && u.dy && NODIAG(u.umonnum)) { u.dx = u.dy = 0; @@ -4768,21 +4766,21 @@ boolean redraw_cmd(c) char c; { - return (boolean) (c == Cmd.spkeys[NHKF_REDRAW] - || (Cmd.num_pad && c == Cmd.spkeys[NHKF_REDRAW2])); + return (boolean) (c == g.Cmd.spkeys[NHKF_REDRAW] + || (g.Cmd.num_pad && c == g.Cmd.spkeys[NHKF_REDRAW2])); } boolean prefix_cmd(c) char c; { - return (c == Cmd.spkeys[NHKF_RUSH] - || c == Cmd.spkeys[NHKF_RUN] - || c == Cmd.spkeys[NHKF_NOPICKUP] - || c == Cmd.spkeys[NHKF_RUN_NOPICKUP] - || c == Cmd.spkeys[NHKF_FIGHT] - || (Cmd.num_pad && (c == Cmd.spkeys[NHKF_RUN2] - || c == Cmd.spkeys[NHKF_FIGHT2]))); + return (c == g.Cmd.spkeys[NHKF_RUSH] + || c == g.Cmd.spkeys[NHKF_RUN] + || c == g.Cmd.spkeys[NHKF_NOPICKUP] + || c == g.Cmd.spkeys[NHKF_RUN_NOPICKUP] + || c == g.Cmd.spkeys[NHKF_FIGHT] + || (g.Cmd.num_pad && (c == g.Cmd.spkeys[NHKF_RUN2] + || c == g.Cmd.spkeys[NHKF_FIGHT2]))); } /* @@ -4841,14 +4839,14 @@ retry: } savech(dirsym); - if (dirsym == Cmd.spkeys[NHKF_GETDIR_SELF] - || dirsym == Cmd.spkeys[NHKF_GETDIR_SELF2]) { + if (dirsym == g.Cmd.spkeys[NHKF_GETDIR_SELF] + || dirsym == g.Cmd.spkeys[NHKF_GETDIR_SELF2]) { u.dx = u.dy = u.dz = 0; } else if (!(is_mov = movecmd(dirsym)) && !u.dz) { boolean did_help = FALSE, help_requested; if (!index(quitchars, dirsym)) { - help_requested = (dirsym == Cmd.spkeys[NHKF_GETDIR_HELP]); + help_requested = (dirsym == g.Cmd.spkeys[NHKF_GETDIR_HELP]); if (help_requested || iflags.cmdassist) { did_help = help_dir((s && *s == '^') ? dirsym : '\0', NHKF_ESC, @@ -4882,26 +4880,26 @@ boolean nodiag; centerchar = ' '; if (nodiag) { - Sprintf(buf, " %c ", Cmd.move_N); + Sprintf(buf, " %c ", g.Cmd.move_N); putstr(win, 0, buf); putstr(win, 0, " | "); Sprintf(buf, " %c- %c -%c", - Cmd.move_W, centerchar, Cmd.move_E); + g.Cmd.move_W, centerchar, g.Cmd.move_E); putstr(win, 0, buf); putstr(win, 0, " | "); - Sprintf(buf, " %c ", Cmd.move_S); + Sprintf(buf, " %c ", g.Cmd.move_S); putstr(win, 0, buf); } else { Sprintf(buf, " %c %c %c", - Cmd.move_NW, Cmd.move_N, Cmd.move_NE); + g.Cmd.move_NW, g.Cmd.move_N, g.Cmd.move_NE); putstr(win, 0, buf); putstr(win, 0, " \\ | / "); Sprintf(buf, " %c- %c -%c", - Cmd.move_W, centerchar, Cmd.move_E); + g.Cmd.move_W, centerchar, g.Cmd.move_E); putstr(win, 0, buf); putstr(win, 0, " / | \\ "); Sprintf(buf, " %c %c %c", - Cmd.move_SW, Cmd.move_S, Cmd.move_SE); + g.Cmd.move_SW, g.Cmd.move_S, g.Cmd.move_SE); putstr(win, 0, buf); }; } @@ -4940,7 +4938,7 @@ const char *msg; dothat = "rush"; break; case NHKF_RUN2: - if (!Cmd.num_pad) + if (!g.Cmd.num_pad) break; /*FALLTHRU*/ case NHKF_RUN: @@ -4948,7 +4946,7 @@ const char *msg; dothat = "run"; break; case NHKF_FIGHT2: - if (!Cmd.num_pad) + if (!g.Cmd.num_pad) break; /*FALLTHRU*/ case NHKF_FIGHT: @@ -4964,8 +4962,8 @@ const char *msg; /* for movement prefix followed by '.' or (numpad && 's') to mean 'self'; note: '-' for hands (inventory form of 'self') is not handled here */ if (prefixhandling - && (sym == Cmd.spkeys[NHKF_GETDIR_SELF] - || (Cmd.num_pad && sym == Cmd.spkeys[NHKF_GETDIR_SELF2]))) { + && (sym == g.Cmd.spkeys[NHKF_GETDIR_SELF] + || (g.Cmd.num_pad && sym == g.Cmd.spkeys[NHKF_GETDIR_SELF2]))) { Sprintf(buf, "You can't %s%s yourself.", dothat, how); /* for movement prefix followed by up or down */ } else if (prefixhandling && (sym == '<' || sym == '>')) { @@ -4981,7 +4979,7 @@ const char *msg; if (prefixhandling) { if (!*buf) Sprintf(buf, "Invalid direction for '%s' prefix.", - visctrl(Cmd.spkeys[spkey])); + visctrl(g.Cmd.spkeys[spkey])); pline("%s", buf); return TRUE; } @@ -5039,10 +5037,10 @@ const char *msg; putstr(win, 0, " < up"); putstr(win, 0, " > down"); if (!prefixhandling) { - int selfi = Cmd.num_pad ? NHKF_GETDIR_SELF2 : NHKF_GETDIR_SELF; + int selfi = g.Cmd.num_pad ? NHKF_GETDIR_SELF2 : NHKF_GETDIR_SELF; Sprintf(buf, " %4s direct at yourself", - visctrl(Cmd.spkeys[selfi])); + visctrl(g.Cmd.spkeys[selfi])); putstr(win, 0, buf); } } @@ -5351,7 +5349,7 @@ int x, y, mod; if (iflags.clicklook && mod == CLICK_2) { clicklook_cc.x = x; clicklook_cc.y = y; - cmd[0] = Cmd.spkeys[NHKF_CLICKLOOK]; + cmd[0] = g.Cmd.spkeys[NHKF_CLICKLOOK]; return cmd; } @@ -5364,7 +5362,7 @@ int x, y, mod; } else { u.tx = u.ux + x; u.ty = u.uy + y; - cmd[0] = Cmd.spkeys[NHKF_TRAVEL]; + cmd[0] = g.Cmd.spkeys[NHKF_TRAVEL]; return cmd; } @@ -5410,7 +5408,7 @@ int x, y, mod; if (!m_at(u.ux + x, u.uy + y) && !test_move(u.ux, u.uy, x, y, TEST_MOVE)) { - cmd[1] = Cmd.dirchars[dir]; + cmd[1] = g.Cmd.dirchars[dir]; cmd[2] = '\0'; if (iflags.herecmd_menu) { cmd[0] = there_cmd_menu(FALSE, u.ux + x, u.uy + y); @@ -5461,11 +5459,11 @@ int x, y, mod; /* move, attack, etc. */ cmd[1] = 0; if (mod == CLICK_1) { - cmd[0] = Cmd.dirchars[dir]; + cmd[0] = g.Cmd.dirchars[dir]; } else { - cmd[0] = (Cmd.num_pad - ? M(Cmd.dirchars[dir]) - : (Cmd.dirchars[dir] - 'a' + 'A')); /* run command */ + cmd[0] = (g.Cmd.num_pad + ? M(g.Cmd.dirchars[dir]) + : (g.Cmd.dirchars[dir] - 'a' + 'A')); /* run command */ } return cmd; @@ -5503,7 +5501,7 @@ boolean historical; /* whether to include in message history: True => yes */ } else if (cnt && (key == '\b' || key == STANDBY_erase_char)) { cnt = cnt / 10; backspaced = TRUE; - } else if (key == Cmd.spkeys[NHKF_ESC]) { + } else if (key == g.Cmd.spkeys[NHKF_ESC]) { break; } else if (!allowchars || index(allowchars, key)) { *count = cnt; @@ -5554,7 +5552,7 @@ parse() #ifdef ALTMETA alt_esc = iflags.altmeta; /* readchar() hack */ #endif - if (!Cmd.num_pad || (foo = readchar()) == Cmd.spkeys[NHKF_COUNT]) { + if (!g.Cmd.num_pad || (foo = readchar()) == g.Cmd.spkeys[NHKF_COUNT]) { long tmpmulti = multi; foo = get_count((char *) 0, '\0', LARGEST_INT, &tmpmulti, FALSE); @@ -5565,15 +5563,15 @@ parse() #endif if (iflags.debug_fuzzer /* if fuzzing, override '!' and ^Z */ - && (Cmd.commands[foo & 0x0ff] - && (Cmd.commands[foo & 0x0ff]->ef_funct == dosuspend_core - || Cmd.commands[foo & 0x0ff]->ef_funct == dosh_core))) - foo = Cmd.spkeys[NHKF_ESC]; + && (g.Cmd.commands[foo & 0x0ff] + && (g.Cmd.commands[foo & 0x0ff]->ef_funct == dosuspend_core + || g.Cmd.commands[foo & 0x0ff]->ef_funct == dosh_core))) + foo = g.Cmd.spkeys[NHKF_ESC]; - if (foo == Cmd.spkeys[NHKF_ESC]) { /* esc cancels count (TH) */ + if (foo == g.Cmd.spkeys[NHKF_ESC]) { /* esc cancels count (TH) */ clear_nhwindow(WIN_MESSAGE); multi = last_multi = 0; - } else if (foo == Cmd.spkeys[NHKF_DOAGAIN] || in_doagain) { + } else if (foo == g.Cmd.spkeys[NHKF_DOAGAIN] || in_doagain) { multi = last_multi; } else { last_multi = multi; @@ -5588,20 +5586,20 @@ parse() save_cm = (char *) 0; } /* in 3.4.3 this was in rhack(), where it was too late to handle M-5 */ - if (Cmd.pcHack_compat) { + if (g.Cmd.pcHack_compat) { /* This handles very old inconsistent DOS/Windows behaviour in a different way: earlier, the keyboard handler mapped these, which caused counts to be strange when entered from the number pad. Now do not map them until here. */ switch (foo) { case '5': - foo = Cmd.spkeys[NHKF_RUSH]; + foo = g.Cmd.spkeys[NHKF_RUSH]; break; case M('5'): - foo = Cmd.spkeys[NHKF_RUN]; + foo = g.Cmd.spkeys[NHKF_RUN]; break; case M('0'): - foo = Cmd.spkeys[NHKF_DOINV]; + foo = g.Cmd.spkeys[NHKF_DOINV]; break; default: break; /* as is */ @@ -5618,7 +5616,7 @@ parse() } clear_nhwindow(WIN_MESSAGE); if (prezero) - in_line[0] = Cmd.spkeys[NHKF_ESC]; + in_line[0] = g.Cmd.spkeys[NHKF_ESC]; iflags.in_parse = FALSE; return in_line; @@ -5771,7 +5769,7 @@ dotravel(VOID_ARGS) iflags.getloc_travelmode = FALSE; iflags.travelcc.x = u.tx = cc.x; iflags.travelcc.y = u.ty = cc.y; - cmd[0] = Cmd.spkeys[NHKF_TRAVEL]; + cmd[0] = g.Cmd.spkeys[NHKF_TRAVEL]; readchar_queue = cmd; return 0; } diff --git a/src/decl.c b/src/decl.c index 37fa05787..f1350b802 100644 --- a/src/decl.c +++ b/src/decl.c @@ -329,13 +329,22 @@ const struct instance_globals g_init = { /* artifact.c */ 0, /* spec_dbon_applies */ + UNDEFINED_VALUES, /* artiexist */ + UNDEFINED_VALUES, /* artdisco */ /* botl.c */ 0, /* mrank_sz */ + /* cmd.c */ + UNDEFINED_VALUES, /* Cmd */ + /* dog.c */ 0, /* petname_used */ + /* makemon.c */ + { -1, /* choice_count */ + { 0 } }, /* mchoices */ + /* mused.c */ FALSE, /* m_using */ UNDEFINED_VALUE, /* trapx */ diff --git a/src/dig.c b/src/dig.c index 29d0941d4..d8da7687f 100644 --- a/src/dig.c +++ b/src/dig.c @@ -972,7 +972,7 @@ struct obj *obj; /* construct list of directions to show player for likely choices */ downok = !!can_reach_floor(FALSE); dsp = dirsyms; - for (sdp = Cmd.dirchars; *sdp; ++sdp) { + for (sdp = g.Cmd.dirchars; *sdp; ++sdp) { /* filter out useless directions */ if (u.uswallow) { ; /* all directions are viable when swallowed */ diff --git a/src/do_name.c b/src/do_name.c index 01feca7e7..30044f207 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -100,7 +100,7 @@ const char *goal; Sprintf(sbuf, "Use '%c', '%c', '%c', '%c' to move the cursor to %s.", /* hjkl */ - Cmd.move_W, Cmd.move_S, Cmd.move_N, Cmd.move_E, goal); + g.Cmd.move_W, g.Cmd.move_S, g.Cmd.move_N, g.Cmd.move_E, goal); putstr(tmpwin, 0, sbuf); Sprintf(sbuf, "Use 'H', 'J', 'K', 'L' to fast-move the cursor, %s.", @@ -108,47 +108,47 @@ const char *goal; putstr(tmpwin, 0, sbuf); putstr(tmpwin, 0, "Or enter a background symbol (ex. '<')."); Sprintf(sbuf, "Use '%s' to move the cursor on yourself.", - visctrl(Cmd.spkeys[NHKF_GETPOS_SELF])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_SELF])); putstr(tmpwin, 0, sbuf); if (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0) { getpos_help_keyxhelp(tmpwin, - visctrl(Cmd.spkeys[NHKF_GETPOS_MON_NEXT]), - visctrl(Cmd.spkeys[NHKF_GETPOS_MON_PREV]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_MON_NEXT]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_MON_PREV]), GLOC_MONS); } if (!iflags.terrainmode || (iflags.terrainmode & TER_OBJ) != 0) { getpos_help_keyxhelp(tmpwin, - visctrl(Cmd.spkeys[NHKF_GETPOS_OBJ_NEXT]), - visctrl(Cmd.spkeys[NHKF_GETPOS_OBJ_PREV]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_OBJ_NEXT]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_OBJ_PREV]), GLOC_OBJS); } if (!iflags.terrainmode || (iflags.terrainmode & TER_MAP) != 0) { /* these are primarily useful when choosing a travel destination for the '_' command */ getpos_help_keyxhelp(tmpwin, - visctrl(Cmd.spkeys[NHKF_GETPOS_DOOR_NEXT]), - visctrl(Cmd.spkeys[NHKF_GETPOS_DOOR_PREV]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_DOOR_NEXT]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_DOOR_PREV]), GLOC_DOOR); getpos_help_keyxhelp(tmpwin, - visctrl(Cmd.spkeys[NHKF_GETPOS_UNEX_NEXT]), - visctrl(Cmd.spkeys[NHKF_GETPOS_UNEX_PREV]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_UNEX_NEXT]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_UNEX_PREV]), GLOC_EXPLORE); getpos_help_keyxhelp(tmpwin, - visctrl(Cmd.spkeys[NHKF_GETPOS_INTERESTING_NEXT]), - visctrl(Cmd.spkeys[NHKF_GETPOS_INTERESTING_PREV]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_INTERESTING_NEXT]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_INTERESTING_PREV]), GLOC_INTERESTING); } Sprintf(sbuf, "Use '%s' to change fast-move mode to %s.", - visctrl(Cmd.spkeys[NHKF_GETPOS_MOVESKIP]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_MOVESKIP]), fastmovemode[!iflags.getloc_moveskip]); putstr(tmpwin, 0, sbuf); if (!iflags.terrainmode || (iflags.terrainmode & TER_DETECT) == 0) { Sprintf(sbuf, "Use '%s' to toggle menu listing for possible targets.", - visctrl(Cmd.spkeys[NHKF_GETPOS_MENU])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_MENU])); putstr(tmpwin, 0, sbuf); Sprintf(sbuf, "Use '%s' to change the mode of limiting possible targets.", - visctrl(Cmd.spkeys[NHKF_GETPOS_LIMITVIEW])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_LIMITVIEW])); putstr(tmpwin, 0, sbuf); } if (!iflags.terrainmode) { @@ -156,56 +156,56 @@ const char *goal; if (getpos_getvalid) { Sprintf(sbuf, "Use '%s' or '%s' to move to valid locations.", - visctrl(Cmd.spkeys[NHKF_GETPOS_VALID_NEXT]), - visctrl(Cmd.spkeys[NHKF_GETPOS_VALID_PREV])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_VALID_NEXT]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_VALID_PREV])); putstr(tmpwin, 0, sbuf); } if (getpos_hilitefunc) { Sprintf(sbuf, "Use '%s' to display valid locations.", - visctrl(Cmd.spkeys[NHKF_GETPOS_SHOWVALID])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_SHOWVALID])); putstr(tmpwin, 0, sbuf); } Sprintf(sbuf, "Use '%s' to toggle automatic description.", - visctrl(Cmd.spkeys[NHKF_GETPOS_AUTODESC])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_AUTODESC])); putstr(tmpwin, 0, sbuf); if (iflags.cmdassist) { /* assisting the '/' command, I suppose... */ Sprintf(sbuf, (iflags.getpos_coords == GPCOORDS_NONE) ? "(Set 'whatis_coord' option to include coordinates with '%s' text.)" : "(Reset 'whatis_coord' option to omit coordinates from '%s' text.)", - visctrl(Cmd.spkeys[NHKF_GETPOS_AUTODESC])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_AUTODESC])); } /* disgusting hack; the alternate selection characters work for any getpos call, but only matter for dowhatis (and doquickwhatis) */ doing_what_is = (goal == what_is_an_unknown_object); if (doing_what_is) { Sprintf(kbuf, "'%s' or '%s' or '%s' or '%s'", - visctrl(Cmd.spkeys[NHKF_GETPOS_PICK]), - visctrl(Cmd.spkeys[NHKF_GETPOS_PICK_Q]), - visctrl(Cmd.spkeys[NHKF_GETPOS_PICK_O]), - visctrl(Cmd.spkeys[NHKF_GETPOS_PICK_V])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK_Q]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK_O]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK_V])); } else { - Sprintf(kbuf, "'%s'", visctrl(Cmd.spkeys[NHKF_GETPOS_PICK])); + Sprintf(kbuf, "'%s'", visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK])); } Sprintf(sbuf, "Type a %s when you are at the right place.", kbuf); putstr(tmpwin, 0, sbuf); if (doing_what_is) { Sprintf(sbuf, " '%s' describe current spot, show 'more info', move to another spot.", - visctrl(Cmd.spkeys[NHKF_GETPOS_PICK_V])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK_V])); putstr(tmpwin, 0, sbuf); Sprintf(sbuf, " '%s' describe current spot,%s move to another spot;", - visctrl(Cmd.spkeys[NHKF_GETPOS_PICK]), + visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK]), flags.help ? " prompt if 'more info'," : ""); putstr(tmpwin, 0, sbuf); Sprintf(sbuf, " '%s' describe current spot, move to another spot;", - visctrl(Cmd.spkeys[NHKF_GETPOS_PICK_Q])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK_Q])); putstr(tmpwin, 0, sbuf); Sprintf(sbuf, " '%s' describe current spot, stop looking at things;", - visctrl(Cmd.spkeys[NHKF_GETPOS_PICK_O])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK_O])); putstr(tmpwin, 0, sbuf); } } @@ -666,18 +666,18 @@ const char *goal; int gidx[NUM_GLOCS] = DUMMY; for (i = 0; i < SIZE(pick_chars_def); i++) - pick_chars[i] = Cmd.spkeys[pick_chars_def[i].nhkf]; + pick_chars[i] = g.Cmd.spkeys[pick_chars_def[i].nhkf]; pick_chars[SIZE(pick_chars_def)] = '\0'; for (i = 0; i < SIZE(mMoOdDxX_def); i++) - mMoOdDxX[i] = Cmd.spkeys[mMoOdDxX_def[i]]; + mMoOdDxX[i] = g.Cmd.spkeys[mMoOdDxX_def[i]]; mMoOdDxX[SIZE(mMoOdDxX_def)] = '\0'; if (!goal) goal = "desired location"; if (flags.verbose) { pline("(For instructions type a '%s')", - visctrl(Cmd.spkeys[NHKF_GETPOS_HELP])); + visctrl(g.Cmd.spkeys[NHKF_GETPOS_HELP])); msg_given = TRUE; } cx = ccp->x; @@ -712,7 +712,7 @@ const char *goal; if (iflags.autodescribe) msg_given = FALSE; - if (c == Cmd.spkeys[NHKF_ESC]) { + if (c == g.Cmd.spkeys[NHKF_ESC]) { cx = cy = -10; msg_given = TRUE; /* force clear */ result = -1; @@ -734,12 +734,12 @@ const char *goal; for (i = 0; i < 8; i++) { int dx, dy; - if (Cmd.dirchars[i] == c) { + if (g.Cmd.dirchars[i] == c) { /* a normal movement letter or digit */ dx = xdir[i]; dy = ydir[i]; - } else if (Cmd.alphadirchars[i] == lowc((char) c) - || (Cmd.num_pad && Cmd.dirchars[i] == (c & 0177))) { + } else if (g.Cmd.alphadirchars[i] == lowc((char) c) + || (g.Cmd.num_pad && g.Cmd.dirchars[i] == (c & 0177))) { /* a shifted movement letter or Meta-digit */ if (iflags.getloc_moveskip) { /* skip same glyphs */ @@ -782,15 +782,15 @@ const char *goal; goto nxtc; } - if (c == Cmd.spkeys[NHKF_GETPOS_HELP] || redraw_cmd(c)) { - if (c == Cmd.spkeys[NHKF_GETPOS_HELP]) + if (c == g.Cmd.spkeys[NHKF_GETPOS_HELP] || redraw_cmd(c)) { + if (c == g.Cmd.spkeys[NHKF_GETPOS_HELP]) getpos_help(force, goal); else /* ^R */ docrt(); /* redraw */ /* update message window to reflect that we're still targetting */ show_goal_msg = TRUE; msg_given = TRUE; - } else if (c == Cmd.spkeys[NHKF_GETPOS_SHOWVALID] + } else if (c == g.Cmd.spkeys[NHKF_GETPOS_SHOWVALID] && getpos_hilitefunc) { if (!hilite_state) { (*getpos_hilitefunc)(0); @@ -798,7 +798,7 @@ const char *goal; hilite_state = TRUE; } goto nxtc; - } else if (c == Cmd.spkeys[NHKF_GETPOS_AUTODESC]) { + } else if (c == g.Cmd.spkeys[NHKF_GETPOS_AUTODESC]) { iflags.autodescribe = !iflags.autodescribe; pline("Automatic description %sis %s.", flags.verbose ? "of features under cursor " : "", @@ -807,7 +807,7 @@ const char *goal; show_goal_msg = TRUE; msg_given = TRUE; goto nxtc; - } else if (c == Cmd.spkeys[NHKF_GETPOS_LIMITVIEW]) { + } else if (c == g.Cmd.spkeys[NHKF_GETPOS_LIMITVIEW]) { static const char *const view_filters[NUM_GFILTER] = { "Not limiting targets", "Limiting targets to in sight", @@ -825,13 +825,13 @@ const char *goal; pline("%s.", view_filters[iflags.getloc_filter]); msg_given = TRUE; goto nxtc; - } else if (c == Cmd.spkeys[NHKF_GETPOS_MENU]) { + } else if (c == g.Cmd.spkeys[NHKF_GETPOS_MENU]) { iflags.getloc_usemenu = !iflags.getloc_usemenu; pline("%s a menu to show possible targets.", iflags.getloc_usemenu ? "Using" : "Not using"); msg_given = TRUE; goto nxtc; - } else if (c == Cmd.spkeys[NHKF_GETPOS_SELF]) { + } else if (c == g.Cmd.spkeys[NHKF_GETPOS_SELF]) { /* reset 'm&M', 'o&O', &c; otherwise, there's no way for player to achieve that except by manually cycling through all spots */ for (i = 0; i < NUM_GLOCS; i++) @@ -839,7 +839,7 @@ const char *goal; cx = u.ux; cy = u.uy; goto nxtc; - } else if (c == Cmd.spkeys[NHKF_GETPOS_MOVESKIP]) { + } else if (c == g.Cmd.spkeys[NHKF_GETPOS_MOVESKIP]) { iflags.getloc_moveskip = !iflags.getloc_moveskip; pline("%skipping over similar terrain when fastmoving the cursor.", iflags.getloc_moveskip ? "S" : "Not s"); @@ -944,8 +944,8 @@ const char *goal; Strcpy(note, "aborted"); else /* hjkl */ Sprintf(note, "use '%c', '%c', '%c', '%c' or '%s'", - Cmd.move_W, Cmd.move_S, Cmd.move_N, Cmd.move_E, - visctrl(Cmd.spkeys[NHKF_GETPOS_PICK])); + g.Cmd.move_W, g.Cmd.move_S, g.Cmd.move_N, g.Cmd.move_E, + visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK])); pline("Unknown direction: '%s' (%s).", visctrl((char) c), note); msg_given = TRUE; diff --git a/src/makemon.c b/src/makemon.c index d78363130..4ecb2dc59 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -1509,11 +1509,6 @@ register struct permonst *ptr; return alshift; } -static NEARDATA struct { - int choice_count; - char mchoices[SPECIAL_PM]; /* value range is 0..127 */ -} rndmonst_state = { -1, { 0 } }; - /* select a random monster type */ struct permonst * rndmonst() @@ -1524,17 +1519,17 @@ rndmonst() if (u.uz.dnum == quest_dnum && rn2(7) && (ptr = qt_montype()) != 0) return ptr; - if (rndmonst_state.choice_count < 0) { /* need to recalculate */ + if (g.rndmonst_state.choice_count < 0) { /* need to recalculate */ int zlevel, minmlev, maxmlev; boolean elemlevel; boolean upper; - rndmonst_state.choice_count = 0; + g.rndmonst_state.choice_count = 0; /* look for first common monster */ for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) { if (!uncommon(mndx)) break; - rndmonst_state.mchoices[mndx] = 0; + g.rndmonst_state.mchoices[mndx] = 0; } if (mndx == SPECIAL_PM) { /* evidently they've all been exterminated */ @@ -1554,7 +1549,7 @@ rndmonst() */ for ( ; mndx < SPECIAL_PM; mndx++) { /* (`mndx' initialized above) */ ptr = &mons[mndx]; - rndmonst_state.mchoices[mndx] = 0; + g.rndmonst_state.mchoices[mndx] = 0; if (tooweak(mndx, minmlev) || toostrong(mndx, maxmlev)) continue; if (upper && !isupper((uchar) def_monsyms[(int) ptr->mlet].sym)) @@ -1568,8 +1563,8 @@ rndmonst() ct = (int) (ptr->geno & G_FREQ) + align_shift(ptr); if (ct < 0 || ct > 127) panic("rndmonst: bad count [#%d: %d]", mndx, ct); - rndmonst_state.choice_count += ct; - rndmonst_state.mchoices[mndx] = (char) ct; + g.rndmonst_state.choice_count += ct; + g.rndmonst_state.mchoices[mndx] = (char) ct; } /* * Possible modification: if choice_count is "too low", @@ -1577,18 +1572,18 @@ rndmonst() */ } /* choice_count+mchoices[] recalc */ - if (rndmonst_state.choice_count <= 0) { + if (g.rndmonst_state.choice_count <= 0) { /* maybe no common mons left, or all are too weak or too strong */ - debugpline1("rndmonst: choice_count=%d", rndmonst_state.choice_count); + debugpline1("rndmonst: choice_count=%d", g.rndmonst_state.choice_count); return (struct permonst *) 0; } /* * Now, select a monster at random. */ - ct = rnd(rndmonst_state.choice_count); + ct = rnd(g.rndmonst_state.choice_count); for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) - if ((ct -= (int) rndmonst_state.mchoices[mndx]) <= 0) + if ((ct -= (int) g.rndmonst_state.mchoices[mndx]) <= 0) break; if (mndx == SPECIAL_PM || uncommon(mndx)) { /* shouldn't happen */ @@ -1606,10 +1601,10 @@ int mndx; /* particular species that can no longer be created */ { /* cached selection info is out of date */ if (mndx == NON_PM) { - rndmonst_state.choice_count = -1; /* full recalc needed */ + g.rndmonst_state.choice_count = -1; /* full recalc needed */ } else if (mndx < SPECIAL_PM) { - rndmonst_state.choice_count -= rndmonst_state.mchoices[mndx]; - rndmonst_state.mchoices[mndx] = 0; + g.rndmonst_state.choice_count -= g.rndmonst_state.mchoices[mndx]; + g.rndmonst_state.mchoices[mndx] = 0; } /* note: safe to ignore extinction of unique monsters */ } diff --git a/src/options.c b/src/options.c index ead3a707a..ca511b665 100644 --- a/src/options.c +++ b/src/options.c @@ -5569,10 +5569,10 @@ char *buf; "4=on, phone layout, MSDOS compatible", "-1=off, y & z swapped", /*[5]*/ }; - int indx = Cmd.num_pad - ? (Cmd.phone_layout ? (Cmd.pcHack_compat ? 4 : 3) - : (Cmd.pcHack_compat ? 2 : 1)) - : Cmd.swap_yz ? 5 : 0; + int indx = g.Cmd.num_pad + ? (g.Cmd.phone_layout ? (g.Cmd.pcHack_compat ? 4 : 3) + : (g.Cmd.pcHack_compat ? 2 : 1)) + : g.Cmd.swap_yz ? 5 : 0; Strcpy(buf, numpadmodes[indx]); } else if (!strcmp(optname, "objects")) { From 40b682ecf60734c9c15bde5a0fcb9f5729cb13a0 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 24 Nov 2018 02:13:54 -0800 Subject: [PATCH 05/11] Moved more globals to instance_globals. --- include/decl.h | 150 +++++++++++++++++++++++++++++++- include/hack.h | 40 +++++++-- include/rm.h | 9 +- include/sp_lev.h | 18 ---- src/artifact.c | 3 +- src/bones.c | 5 +- src/botl.c | 4 +- src/cmd.c | 76 +++++++---------- src/dbridge.c | 44 ++++------ src/decl.c | 112 +++++++++++++++++++++++- src/dig.c | 10 +-- src/do.c | 58 ++++++------- src/do_name.c | 35 ++++---- src/dogmove.c | 67 ++++++++------- src/dokick.c | 145 ++++++++++++++++--------------- src/drawing.c | 93 +++++++++----------- src/dungeon.c | 123 +++++++++++++-------------- src/eat.c | 13 ++- src/end.c | 43 +++------- src/files.c | 30 +++---- src/hack.c | 38 ++++----- src/invent.c | 56 ++++++------ src/lock.c | 171 ++++++++++++++++++------------------- src/mapglyph.c | 18 ++-- src/mhitm.c | 193 ++++++++++++++++++++---------------------- src/mhitu.c | 8 +- src/mklev.c | 31 +++---- src/mkmap.c | 42 +++++---- src/mkmaze.c | 77 ++++++++--------- src/options.c | 64 +++++++------- src/pager.c | 14 +-- src/questpgr.c | 11 +-- src/sp_lev.c | 45 +++++----- sys/winnt/nttty.c | 4 +- win/curses/cursinit.c | 2 +- win/curses/cursmain.c | 2 +- win/curses/cursmisc.c | 2 +- 37 files changed, 987 insertions(+), 869 deletions(-) diff --git a/include/decl.h b/include/decl.h index c9b2f5550..beeaafa5c 100644 --- a/include/decl.h +++ b/include/decl.h @@ -37,8 +37,6 @@ E NEARDATA int nroom; E NEARDATA int nsubroom; E NEARDATA int occtime; -#define WARNCOUNT 6 /* number of different warning levels */ -E nhsym warnsyms[WARNCOUNT]; E NEARDATA int warn_obj_cnt; /* count of monsters meeting criteria */ E int x_maze_max, y_maze_max; @@ -514,12 +512,47 @@ struct cmd { char spkeys[NUM_NHKF]; }; + +#define ENTITIES 2 + +struct entity { + struct monst *emon; /* youmonst for the player */ + struct permonst *edata; /* must be non-zero for record to be valid */ + int ex, ey; +}; + +/* these probably ought to be generated by makedefs, like LAST_GEM */ +#define FIRST_GEM DILITHIUM_CRYSTAL +#define FIRST_AMULET AMULET_OF_ESP +#define LAST_AMULET AMULET_OF_YENDOR + +struct valuable_data { + long count; + int typ; +}; + +struct val_list { + struct valuable_data *list; + int size; +}; + +/* at most one of `door' and `box' should be non-null at any given time */ +struct xlock_s { + struct rm *door; + struct obj *box; + int picktyp, /* key|pick|card for unlock, sharp vs blunt for #force */ + chance, usedtime; + boolean magic_key; +}; + /* 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. */ +#define BSIZE 20 + struct instance_globals { /* apply.c */ @@ -540,9 +573,85 @@ struct instance_globals { /* cmd.c */ struct cmd Cmd; /* flag.h */ + /* Provide a means to redo the last command. The flag `in_doagain' is set + * to true while redoing the command. This flag is tested in commands that + * require additional input (like `throw' which requires a thing and a + * direction), and the input prompt is not shown. Also, while in_doagain is + * TRUE, no keystrokes can be saved into the saveq. + */ + char pushq[BSIZE]; + char saveq[BSIZE]; + int phead; + int ptail; + int shead; + int stail; + coord clicklook_cc; + winid en_win; + boolean en_via_menu; + + /* dbridge.c */ + struct entity occupants[ENTITIES]; + + /* dig.c */ + + boolean did_dig_msg; + + /* do.c */ + boolean at_ladder; + char *dfr_pre_msg; /* pline() before level change */ + char *dfr_post_msg; /* pline() after level change */ + d_level save_dlevel; + + /* do_name.c */ + struct opvar *gloc_filter_map; + int gloc_filter_floodfill_match_glyph; + int via_naming; /* dog.c */ int petname_used; /* user preferred pet name has been used */ + xchar gtyp; /* type of dog's current goal */ + xchar gx; /* x position of dog's current goal */ + char gy; /* y position of dog's current goal */ + + /* dokick.c */ + struct rm *maploc; + struct rm nowhere; + const char *gate_str; + + /* drawing */ + struct symsetentry symset[NUM_GRAPHICS]; + int currentgraphics; + nhsym showsyms[SYM_MAX]; /* symbols to be displayed */ + nhsym l_syms[SYM_MAX]; /* loaded symbols */ + nhsym r_syms[SYM_MAX]; /* rogue symbols */ + nhsym warnsyms[WARNCOUNT]; /* the current warning display symbols */ + + /* dungeon.c */ + int n_dgns; /* number of dungeons (also used in mklev.c and do.c) */ + branch *branches; /* dungeon branch list */ + mapseen *mapseenchn; /*DUNGEON_OVERVIEW*/ + + /* eat.c */ + boolean force_save_hs; + + /* end.c */ + struct valuable_data gems[LAST_GEM + 1 - FIRST_GEM + 1]; /* +1 for glass */ + struct valuable_data amulets[LAST_AMULET + 1 - FIRST_AMULET]; + struct val_list valuables[3]; + + /* hack.c */ + anything tmp_anything; + int wc; /* current weight_cap(); valid after call to inv_weight() */ + + /* invent.c */ + int lastinvnr; /* 0 ... 51 (never saved&restored) */ + unsigned sortlootmode; /* set by sortloot() for use by sortloot_cmp(); + * reset by sortloot when done */ + char *invbuf; + unsigned invbufsiz; + + /* lock.c */ + struct xlock_s xlock; /* makemon.c */ struct { @@ -550,6 +659,38 @@ struct instance_globals { char mchoices[SPECIAL_PM]; /* value range is 0..127 */ } rndmonst_state; + /* mhitm.c */ + boolean vis; + boolean far_noise; + long noisetime; + struct obj *otmp; + int dieroll; /* Needed for the special case of monsters wielding vorpal + * blades (rare). If we use this a lot it should probably + * be a parameter to mdamagem() instead of a global variable. + */ + + /* mhitu.c */ + int mhitu_dieroll; + + /* mklev.c */ + xchar vault_x; + xchar vault_y; + boolean made_branch; /* used only during level creation */ + + /* mkmap.c */ + char *new_locations; + int min_rx; /* rectangle bounds for regions */ + int max_rx; + int min_ry; + int max_ry; + int n_loc_filled; + + /* mkmaze.c */ + lev_region bughack; /* for preserving the insect legs when wallifying + * baalz level */ + boolean was_waterlevel; /* ugh... this shouldn't be needed */ + + /* muse.c */ boolean m_using; /* kludge to use mondided instead of killed */ int trapx; @@ -630,6 +771,11 @@ struct instance_globals { unsigned ustuck_id; /* need to preserve during save */ unsigned usteed_id; /* need to preserve during save */ + /* sp_lev.c */ + char *lev_message; + lev_region *lregions; + int num_lregions; + /* trap.c */ int force_mintrap; /* mintrap() should take a flags argument, but for time being we use this */ diff --git a/include/hack.h b/include/hack.h index 9ba8b49fc..46c104cf8 100644 --- a/include/hack.h +++ b/include/hack.h @@ -167,6 +167,27 @@ typedef struct strbuf { char buf[256]; } strbuf_t; +/* str_or_len from sp_lev.h */ +typedef union str_or_len { + char *str; + int len; +} Str_or_Len; + +/* values for rtype are defined in dungeon.h */ +/* lev_region from sp_lev.h */ +typedef struct { + struct { + xchar x1, y1, x2, y2; + } inarea; + struct { + xchar x1, y1, x2, y2; + } delarea; + boolean in_islev, del_islev; + xchar rtype, padding; + Str_or_Len rname; +} lev_region; + + #include "align.h" #include "dungeon.h" #include "monsym.h" @@ -175,6 +196,16 @@ typedef struct strbuf { #include "youprop.h" #include "wintype.h" #include "context.h" +#include "rm.h" + +/* Symbol offsets */ +#define SYM_OFF_P (0) +#define SYM_OFF_O (SYM_OFF_P + MAXPCHARS) /* MAXPCHARS from rm.h */ +#define SYM_OFF_M (SYM_OFF_O + MAXOCLASSES) /* MAXOCLASSES from objclass.h */ +#define SYM_OFF_W (SYM_OFF_M + MAXMCLASSES) /* MAXMCLASSES from monsym.h*/ +#define SYM_OFF_X (SYM_OFF_W + WARNCOUNT) +#define SYM_MAX (SYM_OFF_X + MAXOTHER) + #include "decl.h" #include "timeout.h" @@ -221,21 +252,12 @@ typedef struct sortloot_item Loot; #include "trap.h" #include "flag.h" -#include "rm.h" #include "vision.h" #include "display.h" #include "engrave.h" #include "rect.h" #include "region.h" -/* Symbol offsets */ -#define SYM_OFF_P (0) -#define SYM_OFF_O (SYM_OFF_P + MAXPCHARS) -#define SYM_OFF_M (SYM_OFF_O + MAXOCLASSES) -#define SYM_OFF_W (SYM_OFF_M + MAXMCLASSES) -#define SYM_OFF_X (SYM_OFF_W + WARNCOUNT) -#define SYM_MAX (SYM_OFF_X + MAXOTHER) - #ifdef USE_TRAMPOLI /* this doesn't belong here, but we have little choice */ #undef NDECL #define NDECL(f) f() diff --git a/include/rm.h b/include/rm.h index b0c0f9ad2..20b8550c9 100644 --- a/include/rm.h +++ b/include/rm.h @@ -300,14 +300,9 @@ struct symsetentry { #define H_CURS 3 extern const struct symdef defsyms[MAXPCHARS]; /* defaults */ +#define WARNCOUNT 6 /* number of different warning levels */ extern const struct symdef def_warnsyms[WARNCOUNT]; -extern int currentgraphics; /* from drawing.c */ -extern nhsym showsyms[]; -extern nhsym l_syms[]; -extern nhsym r_syms[]; - -extern struct symsetentry symset[NUM_GRAPHICS]; /* from drawing.c */ -#define SYMHANDLING(ht) (symset[currentgraphics].handling == (ht)) +#define SYMHANDLING(ht) (g.symset[g.currentgraphics].handling == (ht)) /* * The 5 possible states of doors diff --git a/include/sp_lev.h b/include/sp_lev.h index e38244b34..24b1ba169 100644 --- a/include/sp_lev.h +++ b/include/sp_lev.h @@ -327,11 +327,6 @@ typedef struct { long jmp_target; } opjmp; -typedef union str_or_len { - char *str; - int len; -} Str_or_Len; - typedef struct { xchar init_style; /* one of LVLINIT_foo */ long flags; @@ -400,19 +395,6 @@ typedef struct { xchar fromter, toter, tolit; } replaceterrain; -/* values for rtype are defined in dungeon.h */ -typedef struct { - struct { - xchar x1, y1, x2, y2; - } inarea; - struct { - xchar x1, y1, x2, y2; - } delarea; - boolean in_islev, del_islev; - xchar rtype, padding; - Str_or_Len rname; -} lev_region; - typedef struct { struct { xchar room; diff --git a/src/artifact.c b/src/artifact.c index 80de4681a..465d6a387 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -1508,14 +1508,13 @@ struct obj *obj; case CREATE_PORTAL: { int i, num_ok_dungeons, last_ok_dungeon = 0; d_level newlev; - extern int n_dgns; /* from dungeon.c */ winid tmpwin = create_nhwindow(NHW_MENU); anything any; any = zeroany; /* set all bits to zero */ start_menu(tmpwin); /* use index+1 (cant use 0) as identifier */ - for (i = num_ok_dungeons = 0; i < n_dgns; i++) { + for (i = num_ok_dungeons = 0; i < g.n_dgns; i++) { if (!dungeons[i].dunlev_ureached) continue; any.a_int = i + 1; diff --git a/src/bones.c b/src/bones.c index 7aadc3967..02e9f5650 100644 --- a/src/bones.c +++ b/src/bones.c @@ -20,11 +20,10 @@ STATIC_OVL boolean no_bones_level(lev) d_level *lev; { - extern d_level save_dlevel; /* in do.c */ s_level *sptr; - if (ledger_no(&save_dlevel)) - assign_level(lev, &save_dlevel); + if (ledger_no(&g.save_dlevel)) + assign_level(lev, &g.save_dlevel); return (boolean) (((sptr = Is_special(lev)) != 0 && !sptr->boneid) || !dungeons[lev->dnum].boneid diff --git a/src/botl.c b/src/botl.c index 8510f3331..4ff49358f 100644 --- a/src/botl.c +++ b/src/botl.c @@ -739,10 +739,10 @@ boolean *valsetlist; */ if (fld == BL_GOLD && (context.rndencode != oldrndencode - || showsyms[COIN_CLASS + SYM_OFF_O] != oldgoldsym)) { + || g.showsyms[COIN_CLASS + SYM_OFF_O] != oldgoldsym)) { update_all = TRUE; /* chg = 2; */ oldrndencode = context.rndencode; - oldgoldsym = showsyms[COIN_CLASS + SYM_OFF_O]; + oldgoldsym = g.showsyms[COIN_CLASS + SYM_OFF_O]; } reset = FALSE; diff --git a/src/cmd.c b/src/cmd.c index d586a697a..fe4a61437 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -266,16 +266,6 @@ int xtime; STATIC_DCL char NDECL(popch); -/* Provide a means to redo the last command. The flag `in_doagain' is set - * to true while redoing the command. This flag is tested in commands that - * require additional input (like `throw' which requires a thing and a - * direction), and the input prompt is not shown. Also, while in_doagain is - * TRUE, no keystrokes can be saved into the saveq. - */ -#define BSIZE 20 -static char pushq[BSIZE], saveq[BSIZE]; -static NEARDATA int phead, ptail, shead, stail; - STATIC_OVL char popch() { @@ -287,9 +277,9 @@ popch() if (occupation) return '\0'; if (in_doagain) - return (char) ((shead != stail) ? saveq[stail++] : '\0'); + return (char) ((g.shead != g.stail) ? g.saveq[g.stail++] : '\0'); else - return (char) ((phead != ptail) ? pushq[ptail++] : '\0'); + return (char) ((g.phead != g.ptail) ? g.pushq[g.ptail++] : '\0'); } char @@ -310,9 +300,9 @@ pushch(ch) char ch; { if (!ch) - phead = ptail = 0; - if (phead < BSIZE) - pushq[phead++] = ch; + g.phead = g.ptail = 0; + if (g.phead < BSIZE) + g.pushq[g.phead++] = ch; return; } @@ -325,9 +315,9 @@ char ch; { if (!in_doagain) { if (!ch) - phead = ptail = shead = stail = 0; - else if (shead < BSIZE) - saveq[shead++] = ch; + g.phead = g.ptail = g.shead = g.stail = 0; + else if (g.shead < BSIZE) + g.saveq[g.shead++] = ch; } return; } @@ -1547,8 +1537,6 @@ doterrain(VOID_ARGS) } /* -enlightenment and conduct- */ -static winid en_win = WIN_ERR; -static boolean en_via_menu = FALSE; static const char You_[] = "You ", are[] = "are ", were[] = "were ", have[] = "have ", had[] = "had ", can[] = "can ", could[] = "could "; @@ -1570,13 +1558,13 @@ static void enlght_out(buf) const char *buf; { - if (en_via_menu) { + if (g.en_via_menu) { anything any; any = zeroany; - add_menu(en_win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); + add_menu(g.en_win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); } else - putstr(en_win, 0, buf); + putstr(g.en_win, 0, buf); } static void @@ -1708,10 +1696,10 @@ int final; /* ENL_GAMEINPROGRESS:0, ENL_GAMEOVERALIVE, ENL_GAMEOVERDEAD */ { char buf[BUFSZ], tmpbuf[BUFSZ]; - en_win = create_nhwindow(NHW_MENU); - en_via_menu = !final; - if (en_via_menu) - start_menu(en_win); + g.en_win = create_nhwindow(NHW_MENU); + g.en_via_menu = !final; + if (g.en_via_menu) + start_menu(g.en_win); Strcpy(tmpbuf, plname); *tmpbuf = highc(*tmpbuf); /* same adjustment as bottom line */ @@ -1746,18 +1734,18 @@ int final; /* ENL_GAMEINPROGRESS:0, ENL_GAMEOVERALIVE, ENL_GAMEOVERDEAD */ attributes_enlightenment(mode, final); } - if (!en_via_menu) { - display_nhwindow(en_win, TRUE); + if (!g.en_via_menu) { + display_nhwindow(g.en_win, TRUE); } else { menu_item *selected = 0; - end_menu(en_win, (char *) 0); - if (select_menu(en_win, PICK_NONE, &selected) > 0) + end_menu(g.en_win, (char *) 0); + if (select_menu(g.en_win, PICK_NONE, &selected) > 0) free((genericptr_t) selected); - en_via_menu = FALSE; + g.en_via_menu = FALSE; } - destroy_nhwindow(en_win); - en_win = WIN_ERR; + destroy_nhwindow(g.en_win); + g.en_win = WIN_ERR; } /*ARGSUSED*/ @@ -3108,8 +3096,8 @@ int final; int ngenocided; /* Create the conduct window */ - en_win = create_nhwindow(NHW_MENU); - putstr(en_win, 0, "Voluntary challenges:"); + g.en_win = create_nhwindow(NHW_MENU); + putstr(g.en_win, 0, "Voluntary challenges:"); if (u.uroleplay.blind) you_have_been("blind from birth"); @@ -3203,9 +3191,9 @@ int final; } /* Pop up the window and wait for a key */ - display_nhwindow(en_win, TRUE); - destroy_nhwindow(en_win); - en_win = WIN_ERR; + display_nhwindow(g.en_win, TRUE); + destroy_nhwindow(g.en_win); + g.en_win = WIN_ERR; } /* ordered by command name */ @@ -4499,9 +4487,9 @@ register char *cmd; context.move = FALSE; return; } - if (*cmd == DOAGAIN && !in_doagain && saveq[0]) { + if (*cmd == DOAGAIN && !in_doagain && g.saveq[0]) { in_doagain = TRUE; - stail = 0; + g.stail = 0; rhack((char *) 0); /* read and execute command */ in_doagain = FALSE; return; @@ -4582,7 +4570,7 @@ register char *cmd; case NHKF_CLICKLOOK: if (iflags.clicklook) { context.move = FALSE; - do_look(2, &clicklook_cc); + do_look(2, &g.clicklook_cc); } return; case NHKF_TRAVEL: @@ -5347,8 +5335,8 @@ int x, y, mod; cmd[1] = 0; if (iflags.clicklook && mod == CLICK_2) { - clicklook_cc.x = x; - clicklook_cc.y = y; + g.clicklook_cc.x = x; + g.clicklook_cc.y = y; cmd[0] = g.Cmd.spkeys[NHKF_CLICKLOOK]; return cmd; } diff --git a/src/dbridge.c b/src/dbridge.c index bf03f8d4a..e3b03e824 100644 --- a/src/dbridge.c +++ b/src/dbridge.c @@ -282,16 +282,6 @@ boolean flag; return TRUE; } -struct entity { - struct monst *emon; /* youmonst for the player */ - struct permonst *edata; /* must be non-zero for record to be valid */ - int ex, ey; -}; - -#define ENTITIES 2 - -static NEARDATA struct entity occupants[ENTITIES]; - STATIC_OVL struct entity * e_at(x, y) @@ -300,15 +290,15 @@ int x, y; int entitycnt; for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++) - if ((occupants[entitycnt].edata) && (occupants[entitycnt].ex == x) - && (occupants[entitycnt].ey == y)) + if ((g.occupants[entitycnt].edata) && (g.occupants[entitycnt].ex == x) + && (g.occupants[entitycnt].ey == y)) break; debugpline1("entitycnt = %d", entitycnt); #ifdef D_DEBUG wait_synch(); #endif return (entitycnt == ENTITIES) ? (struct entity *) 0 - : &(occupants[entitycnt]); + : &(g.occupants[entitycnt]); } STATIC_OVL void @@ -471,9 +461,9 @@ int xkill_flags, how; /* dead long worm handling */ for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++) { - if (etmp != &(occupants[entitycnt]) - && etmp->emon == occupants[entitycnt].emon) - occupants[entitycnt].edata = (struct permonst *) 0; + if (etmp != &(g.occupants[entitycnt]) + && etmp->emon == g.occupants[entitycnt].emon) + g.occupants[entitycnt].edata = (struct permonst *) 0; } #undef mk_message #undef mk_corpse @@ -801,11 +791,11 @@ int x, y; break; } lev2->wall_info = W_NONDIGGABLE; - set_entity(x, y, &(occupants[0])); - set_entity(x2, y2, &(occupants[1])); - do_entity(&(occupants[0])); /* Do set_entity after first */ - set_entity(x2, y2, &(occupants[1])); /* do_entity for worm tail */ - do_entity(&(occupants[1])); + set_entity(x, y, &(g.occupants[0])); + set_entity(x2, y2, &(g.occupants[1])); + do_entity(&(g.occupants[0])); /* Do set_entity after first */ + set_entity(x2, y2, &(g.occupants[1])); /* do_entity for worm tail */ + do_entity(&(g.occupants[1])); if (OBJ_AT(x, y) && !Deaf) You_hear("smashing and crushing."); (void) revive_nasty(x, y, (char *) 0); @@ -850,11 +840,11 @@ int x, y; lev2 = &levl[x2][y2]; lev2->typ = DOOR; lev2->doormask = D_NODOOR; - set_entity(x, y, &(occupants[0])); - set_entity(x2, y2, &(occupants[1])); - do_entity(&(occupants[0])); /* do set_entity after first */ - set_entity(x2, y2, &(occupants[1])); /* do_entity for worm tails */ - do_entity(&(occupants[1])); + set_entity(x, y, &(g.occupants[0])); + set_entity(x2, y2, &(g.occupants[1])); + do_entity(&(g.occupants[0])); /* do set_entity after first */ + set_entity(x2, y2, &(g.occupants[1])); /* do_entity for worm tails */ + do_entity(&(g.occupants[1])); (void) revive_nasty(x, y, (char *) 0); delallobj(x, y); if ((t = t_at(x, y)) != 0) @@ -883,7 +873,7 @@ int x, y; struct obj *otmp; int x2, y2, i; boolean e_inview; - struct entity *etmp1 = &(occupants[0]), *etmp2 = &(occupants[1]); + struct entity *etmp1 = &(g.occupants[0]), *etmp2 = &(g.occupants[1]); lev1 = &levl[x][y]; if (!IS_DRAWBRIDGE(lev1->typ)) diff --git a/src/decl.c b/src/decl.c index f1350b802..4bd1d434e 100644 --- a/src/decl.c +++ b/src/decl.c @@ -337,13 +337,109 @@ const struct instance_globals g_init = { /* cmd.c */ UNDEFINED_VALUES, /* Cmd */ + UNDEFINED_VALUES, /* pushq */ + UNDEFINED_VALUES, /* saveq */ + UNDEFINED_VALUE, /* phead */ + UNDEFINED_VALUE, /* ptail */ + UNDEFINED_VALUE, /* shead */ + UNDEFINED_VALUE, /* stail */ + UNDEFINED_VALUES, /* clicklook_cc */ + WIN_ERR, /* en_win */ + FALSE, /* en_via_menu */ + + /* dbridge.c */ + UNDEFINED_VALUES, + + /* dig.c */ + UNDEFINED_VALUE, /* did_dig_msg */ + + /* do.c */ + FALSE, /* at_ladder */ + NULL, /* dfr_pre_msg */ + NULL, /* dfr_post_msg */ + { 0, 0 }, /* save_dlevel */ + + /* do_name.c */ + NULL, /* gloc_filter_map */ + UNDEFINED_VALUE, /* gloc_filter_floodfill_match_glyph */ + 0, /* via_naming */ /* dog.c */ 0, /* petname_used */ + UNDEFINED_VALUE, /* gtyp */ + UNDEFINED_VALUE, /* gx */ + UNDEFINED_VALUE, /* gy */ + + /* dokick.c */ + UNDEFINED_PTR, /* maploc */ + UNDEFINED_VALUES, /* nowhere */ + UNDEFINED_PTR, /* gate_str */ + + /* drawing.c */ + DUMMY, /* symset */ + 0, /* currentgraphics */ + DUMMY, /* showsyms */ + DUMMY, /* l_syms */ + DUMMY, /* r_syms */ + DUMMY, /* warnsyms */ + + /* dungeon.c */ + UNDEFINED_VALUE, /* n_dgns */ + NULL, /* branches */ + NULL, /* mapseenchn */ + + /* eat.c */ + FALSE, /* force_save_hs */ + + /* end.c */ + UNDEFINED_VALUES, + UNDEFINED_VALUES, + UNDEFINED_VALUES, + + /* hack.c */ + UNDEFINED_VALUES, + UNDEFINED_VALUE, + + /* invent.c */ + 51, /* lastinvr */ + 0, /* sortloogmode */ + NULL, /* invbuf */ + 0, /* inbufsize */ + + /* lock.c */ + UNDEFINED_VALUES, /* makemon.c */ - { -1, /* choice_count */ - { 0 } }, /* mchoices */ + { -1, /* choice_count */ + { 0 } }, /* mchoices */ + + /* mhitm.c */ + UNDEFINED_VALUE, /* vis */ + UNDEFINED_VALUE, /* far_noise */ + UNDEFINED_VALUE, /* noisetime */ + UNDEFINED_PTR, /* otmp */ + UNDEFINED_VALUE, /* dieroll */ + + /* mhitu.c */ + UNDEFINED_VALUE, /* mhitu_dieroll */ + + /* mklev.c */ + UNDEFINED_VALUE, /* vault_x */ + UNDEFINED_VALUE, /* vault_y */ + UNDEFINED_VALUE, /* made_branch */ + + /* mkmap.c */ + UNDEFINED_PTR, /* new_locations */ + UNDEFINED_VALUE, /* min_rx */ + UNDEFINED_VALUE, /* max_rx */ + UNDEFINED_VALUE, /* min_ry */ + UNDEFINED_VALUE, /* max_ry */ + UNDEFINED_VALUE, /* n_loc_filled */ + + /* mkmaze.c */ + { {COLNO, ROWNO, 0, 0}, {COLNO, ROWNO, 0, 0} }, /* bughack */ + UNDEFINED_VALUE, /* was_waterlevel */ + /* mused.c */ FALSE, /* m_using */ @@ -406,6 +502,11 @@ const struct instance_globals g_init = { 0, /* ustuck_id */ 0, /* usteed_id */ + /* sp_lev.c */ + NULL, /* lev_message */ + NULL, /* lregions */ + 0, /* num_lregions */ + /* trap.c */ 0, /* force_mintrap */ @@ -435,6 +536,13 @@ decl_globals_init() { g = g_init; + g.valuables[0].list = g.gems; + g.valuables[0].size = SIZE(g.gems); + g.valuables[1].list = g.amulets; + g.valuables[1].size = SIZE(g.amulets); + g.valuables[2].list = NULL; + g.valuables[2].size = 0; + nhassert(g_init.magic == IVMAGIC); nhassert(g_init.havestate == TRUE); diff --git a/src/dig.c b/src/dig.c index d8da7687f..9c50cc1e6 100644 --- a/src/dig.c +++ b/src/dig.c @@ -482,9 +482,9 @@ dig(VOID_ARGS) || (dig_target == DIGTYP_ROCK && !IS_ROCK(lev->typ))) return 0; /* statue or boulder got taken */ - if (!did_dig_msg) { + if (!g.did_dig_msg) { You("hit the %s with all your might.", d_target[dig_target]); - did_dig_msg = TRUE; + g.did_dig_msg = TRUE; } } return 1; @@ -1116,7 +1116,7 @@ struct obj *obj; "chopping at the door", "cutting the tree" }; - did_dig_msg = FALSE; + g.did_dig_msg = FALSE; context.digging.quiet = FALSE; if (context.digging.pos.x != rx || context.digging.pos.y != ry || !on_level(&context.digging.level, &u.uz) @@ -1128,7 +1128,7 @@ struct obj *obj; && (moves <= context.digging.lastdigtime + 2 && moves >= context.digging.lastdigtime)) { /* avoid messages if repeated autodigging */ - did_dig_msg = TRUE; + g.did_dig_msg = TRUE; context.digging.quiet = TRUE; } context.digging.down = context.digging.chew = FALSE; @@ -1185,7 +1185,7 @@ struct obj *obj; shopdig(0); } else You("continue %s downward.", verbing); - did_dig_msg = FALSE; + g.did_dig_msg = FALSE; set_occupation(dig, verbing, 0); } return 1; diff --git a/src/do.c b/src/do.c index 87cbe86c4..1435ac9d3 100644 --- a/src/do.c +++ b/src/do.c @@ -19,8 +19,6 @@ STATIC_DCL int NDECL(currentlevel_rewrite); STATIC_DCL void NDECL(final_level); /* static boolean FDECL(badspot, (XCHAR_P,XCHAR_P)); */ -extern int n_dgns; /* number of dungeons, from dungeon.c */ - static NEARDATA const char drop_types[] = { ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, 0 }; @@ -891,9 +889,6 @@ drop_done: return n_dropped; } -/* on a ladder, used in goto_level */ -static NEARDATA boolean at_ladder = FALSE; - /* the '>' command */ int dodown() @@ -1024,9 +1019,9 @@ dodown() if (trap && Is_stronghold(&u.uz)) { goto_hell(FALSE, TRUE); } else { - at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER); + g.at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER); next_level(!trap); - at_ladder = FALSE; + g.at_ladder = FALSE; } return 1; } @@ -1077,14 +1072,12 @@ doup() You("are held back by your pet!"); return 0; } - at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER); + g.at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER); prev_level(TRUE); - at_ladder = FALSE; + g.at_ladder = FALSE; return 1; } -d_level save_dlevel = { 0, 0 }; - /* check that we can write out the current level */ STATIC_OVL int currentlevel_rewrite() @@ -1221,7 +1214,7 @@ boolean at_stairs, falling, portal; (void) next_to_u(); return; } else - at_stairs = at_ladder = FALSE; + at_stairs = g.at_ladder = FALSE; } } @@ -1297,7 +1290,7 @@ boolean at_stairs, falling, portal; for (l_idx = maxledgerno(); l_idx > 0; --l_idx) delete_levelfile(l_idx); /* mark #overview data for all dungeon branches as uninteresting */ - for (l_idx = 0; l_idx < n_dgns; ++l_idx) + for (l_idx = 0; l_idx < g.n_dgns; ++l_idx) remdun_mapseen(l_idx); } @@ -1371,7 +1364,7 @@ boolean at_stairs, falling, portal; u_on_newpos(ttrap->tx, ttrap->ty); } else if (at_stairs && !In_endgame(&u.uz)) { if (up) { - if (at_ladder) + if (g.at_ladder) u_on_newpos(xdnladder, ydnladder); else if (newdungeon) u_on_sstairs(1); @@ -1384,10 +1377,10 @@ boolean at_stairs, falling, portal; pline("%s %s up%s the %s.", great_effort ? "With great effort, you" : "You", Levitation ? "float" : Flying ? "fly" : "climb", - (Flying && at_ladder) ? " along" : "", - at_ladder ? "ladder" : "stairs"); + (Flying && g.at_ladder) ? " along" : "", + g.at_ladder ? "ladder" : "stairs"); } else { /* down */ - if (at_ladder) + if (g.at_ladder) u_on_newpos(xupladder, yupladder); else if (newdungeon) u_on_sstairs(0); @@ -1398,10 +1391,10 @@ boolean at_stairs, falling, portal; } else if (Flying) { if (flags.verbose) You("fly down %s.", - at_ladder ? "along the ladder" : "the stairs"); + g.at_ladder ? "along the ladder" : "the stairs"); } else if (near_capacity() > UNENCUMBERED || Punished || Fumbling) { - You("fall down the %s.", at_ladder ? "ladder" : "stairs"); + You("fall down the %s.", g.at_ladder ? "ladder" : "stairs"); if (Punished) { drag_down(); ballrelease(FALSE); @@ -1411,13 +1404,13 @@ boolean at_stairs, falling, portal; dismount_steed(DISMOUNT_FELL); else losehp(Maybe_Half_Phys(rnd(3)), - at_ladder ? "falling off a ladder" + g.at_ladder ? "falling off a ladder" : "tumbling down a flight of stairs", KILLED_BY); selftouch("Falling, you"); } else { /* ordinary descent */ if (flags.verbose) - You("%s.", at_ladder ? "climb down the ladder" + You("%s.", g.at_ladder ? "climb down the ladder" : "descend the stairs"); } } @@ -1615,9 +1608,6 @@ final_level() gain_guardian_angel(); } -static char *dfr_pre_msg = 0, /* pline() before level change */ - *dfr_post_msg = 0; /* pline() after level change */ - /* change levels at the end of this turn, after monsters finish moving */ void schedule_goto(tolev, at_stairs, falling, portal_flag, pre_msg, post_msg) @@ -1642,9 +1632,9 @@ const char *pre_msg, *post_msg; assign_level(&u.utolev, tolev); if (pre_msg) - dfr_pre_msg = dupstr(pre_msg); + g.dfr_pre_msg = dupstr(pre_msg); if (post_msg) - dfr_post_msg = dupstr(post_msg); + g.dfr_post_msg = dupstr(post_msg); } /* handle something like portal ejection */ @@ -1656,8 +1646,8 @@ deferred_goto() int typmask = u.utotype; /* save it; goto_level zeroes u.utotype */ assign_level(&dest, &u.utolev); - if (dfr_pre_msg) - pline1(dfr_pre_msg); + if (g.dfr_pre_msg) + pline1(g.dfr_pre_msg); goto_level(&dest, !!(typmask & 1), !!(typmask & 2), !!(typmask & 4)); if (typmask & 0200) { /* remove portal */ struct trap *t = t_at(u.ux, u.uy); @@ -1667,14 +1657,14 @@ deferred_goto() newsym(u.ux, u.uy); } } - if (dfr_post_msg) - pline1(dfr_post_msg); + if (g.dfr_post_msg) + pline1(g.dfr_post_msg); } u.utotype = 0; /* our caller keys off of this */ - if (dfr_pre_msg) - free((genericptr_t) dfr_pre_msg), dfr_pre_msg = 0; - if (dfr_post_msg) - free((genericptr_t) dfr_post_msg), dfr_post_msg = 0; + if (g.dfr_pre_msg) + free((genericptr_t) g.dfr_pre_msg), g.dfr_pre_msg = 0; + if (g.dfr_post_msg) + free((genericptr_t) g.dfr_post_msg), g.dfr_post_msg = 0; } /* diff --git a/src/do_name.c b/src/do_name.c index 30044f207..be5c55137 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -244,13 +244,9 @@ const void *b; && glyph_to_cmap(levl[(x)][(y)].glyph) == S_stone \ && !levl[(x)][(y)].seenv) -static struct opvar *gloc_filter_map = (struct opvar *) 0; - #define GLOC_SAME_AREA(x,y) \ (isok((x), (y)) \ - && (selection_getpoint((x),(y), gloc_filter_map))) - -static int gloc_filter_floodfill_match_glyph; + && (selection_getpoint((x),(y), g.gloc_filter_map))) int gloc_filter_classify_glyph(glyph) @@ -285,11 +281,11 @@ int x, y; if (!levl[x][y].seenv) return FALSE; - if (glyph == gloc_filter_floodfill_match_glyph) + if (glyph == g.gloc_filter_floodfill_match_glyph) return TRUE; if (gloc_filter_classify_glyph(glyph) - == gloc_filter_classify_glyph(gloc_filter_floodfill_match_glyph)) + == gloc_filter_classify_glyph(g.gloc_filter_floodfill_match_glyph)) return TRUE; return FALSE; @@ -299,18 +295,18 @@ void gloc_filter_floodfill(x, y) int x, y; { - gloc_filter_floodfill_match_glyph = back_to_glyph(x, y); + g.gloc_filter_floodfill_match_glyph = back_to_glyph(x, y); set_selection_floodfillchk(gloc_filter_floodfill_matcharea); - selection_floodfill(gloc_filter_map, x, y, FALSE); + selection_floodfill(g.gloc_filter_map, x, y, FALSE); } void gloc_filter_init() { if (iflags.getloc_filter == GFILTER_AREA) { - if (!gloc_filter_map) { - gloc_filter_map = selection_opvar((char *) 0); + if (!g.gloc_filter_map) { + g.gloc_filter_map = selection_opvar((char *) 0); } /* special case: if we're in a doorway, try to figure out which direction we're moving, and use that side of the doorway */ @@ -329,9 +325,10 @@ gloc_filter_init() void gloc_filter_done() { - if (gloc_filter_map) { - opvar_free_x(gloc_filter_map); - gloc_filter_map = (struct opvar *) 0; + if (g.gloc_filter_map) { + opvar_free_x(g.gloc_filter_map); + g.gloc_filter_map = (struct opvar *) 0; + } } @@ -885,7 +882,7 @@ const char *goal; || glyph_to_cmap(k) == S_corr || glyph_to_cmap(k) == S_litcorr) continue; - if (c == defsyms[sidx].sym || c == (int) showsyms[sidx]) + if (c == defsyms[sidx].sym || c == (int) g.showsyms[sidx]) matching[sidx] = (char) ++k; } if (k) { @@ -1184,8 +1181,6 @@ do_mname() (void) christen_monst(mtmp, buf); } -STATIC_VAR int via_naming = 0; - /* * This routine used to change the address of 'obj' so be unsafe if not * used with extreme care. Applying a name to an object no longer @@ -1257,9 +1252,9 @@ register struct obj *obj; a valid artifact name */ u.uconduct.literate++; } - ++via_naming; /* This ought to be an argument rather than a static... */ + ++g.via_naming; /* This ought to be an argument rather than a static... */ obj = oname(obj, buf); - --via_naming; /* ...but oname() is used in a lot of places, so defer. */ + --g.via_naming; /* ...but oname() is used in a lot of places, so defer. */ } struct obj * @@ -1299,7 +1294,7 @@ const char *name; /* if obj is owned by a shop, increase your bill */ if (obj->unpaid) alter_cost(obj, 0L); - if (via_naming) { + if (g.via_naming) { /* violate illiteracy conduct since successfully wrote arti-name */ u.uconduct.literate++; } diff --git a/src/dogmove.c b/src/dogmove.c index c67d61e23..2003bc77a 100644 --- a/src/dogmove.c +++ b/src/dogmove.c @@ -120,7 +120,6 @@ struct monst *mon; static NEARDATA const char nofetch[] = { BALL_CLASS, CHAIN_CLASS, ROCK_CLASS, 0 }; -STATIC_VAR xchar gtyp, gx, gy; /* type and position of dog's current goal */ STATIC_PTR void FDECL(wantdoor, (int, int, genericptr_t)); @@ -492,17 +491,17 @@ int after, udist, whappr; dog_has_minvent = (droppables(mtmp) != 0); if (!edog || mtmp->mleashed) { /* he's not going anywhere... */ - gtyp = APPORT; - gx = u.ux; - gy = u.uy; + g.gtyp = APPORT; + g.gx = u.ux; + g.gy = u.uy; } else { #define DDIST(x, y) (dist2(x, y, omx, omy)) #define SQSRCHRADIUS 5 int min_x, max_x, min_y, max_y; register int nx, ny; - gtyp = UNDEF; /* no goal as yet */ - gx = gy = 0; /* suppress 'used before set' message */ + g.gtyp = UNDEF; /* no goal as yet */ + g.gx = g.gy = 0; /* suppress 'used before set' message */ if ((min_x = omx - SQSRCHRADIUS) < 1) min_x = 1; @@ -520,7 +519,7 @@ int after, udist, whappr; if (nx >= min_x && nx <= max_x && ny >= min_y && ny <= max_y) { otyp = dogfood(mtmp, obj); /* skip inferior goals */ - if (otyp > gtyp || otyp == UNDEF) + if (otyp > g.gtyp || otyp == UNDEF) continue; /* avoid cursed items unless starving */ if (cursed_object_at(nx, ny) @@ -531,31 +530,31 @@ int after, udist, whappr; || !can_reach_location(mtmp, mtmp->mx, mtmp->my, nx, ny)) continue; if (otyp < MANFOOD) { - if (otyp < gtyp || DDIST(nx, ny) < DDIST(gx, gy)) { - gx = nx; - gy = ny; - gtyp = otyp; + if (otyp < g.gtyp || DDIST(nx, ny) < DDIST(g.gx, g.gy)) { + g.gx = nx; + g.gy = ny; + g.gtyp = otyp; } - } else if (gtyp == UNDEF && in_masters_sight + } else if (g.gtyp == UNDEF && in_masters_sight && !dog_has_minvent && (!levl[omx][omy].lit || levl[u.ux][u.uy].lit) && (otyp == MANFOOD || m_cansee(mtmp, nx, ny)) && edog->apport > rn2(8) && can_carry(mtmp, obj) > 0) { - gx = nx; - gy = ny; - gtyp = APPORT; + g.gx = nx; + g.gy = ny; + g.gtyp = APPORT; } } } } /* follow player if appropriate */ - if (gtyp == UNDEF || (gtyp != DOGFOOD && gtyp != APPORT + if (g.gtyp == UNDEF || (g.gtyp != DOGFOOD && g.gtyp != APPORT && monstermoves < edog->hungrytime)) { - gx = u.ux; - gy = u.uy; - if (after && udist <= 4 && gx == u.ux && gy == u.uy) + g.gx = u.ux; + g.gy = u.uy; + if (after && udist <= 4 && g.gx == u.ux && g.gy == u.uy) return -2; appr = (udist >= 9) ? 1 : (mtmp->mflee) ? -1 : 0; if (udist > 1) { @@ -576,34 +575,34 @@ int after, udist, whappr; appr = 0; #define FARAWAY (COLNO + 2) /* position outside screen */ - if (gx == u.ux && gy == u.uy && !in_masters_sight) { + if (g.gx == u.ux && g.gy == u.uy && !in_masters_sight) { register coord *cp; cp = gettrack(omx, omy); if (cp) { - gx = cp->x; - gy = cp->y; + g.gx = cp->x; + g.gy = cp->y; if (edog) edog->ogoal.x = 0; } else { /* assume master hasn't moved far, and reuse previous goal */ if (edog && edog->ogoal.x && (edog->ogoal.x != omx || edog->ogoal.y != omy)) { - gx = edog->ogoal.x; - gy = edog->ogoal.y; + g.gx = edog->ogoal.x; + g.gy = edog->ogoal.y; edog->ogoal.x = 0; } else { int fardist = FARAWAY * FARAWAY; - gx = gy = FARAWAY; /* random */ + g.gx = g.gy = FARAWAY; /* random */ do_clear_area(omx, omy, 9, wantdoor, (genericptr_t) &fardist); /* here gx == FARAWAY e.g. when dog is in a vault */ - if (gx == FARAWAY || (gx == omx && gy == omy)) { - gx = u.ux; - gy = u.uy; + if (g.gx == FARAWAY || (g.gx == omx && g.gy == omy)) { + g.gx = u.ux; + g.gy = u.uy; } else if (edog) { - edog->ogoal.x = gx; - edog->ogoal.y = gy; + edog->ogoal.x = g.gx; + edog->ogoal.y = g.gy; } } } @@ -878,7 +877,7 @@ int after; /* this is extra fast monster movement */ int chi = -1, nidist, ndist; coord poss[9]; long info[9], allowflags; -#define GDIST(x, y) (dist2(x, y, gx, gy)) +#define GDIST(x, y) (dist2(x, y, g.gx, g.gy)) /* * Tame Angels have isminion set and an ispriest structure instead of @@ -982,7 +981,7 @@ int after; /* this is extra fast monster movement */ uncursedcnt++; } - better_with_displacing = should_displace(mtmp, poss, info, cnt, gx, gy); + better_with_displacing = should_displace(mtmp, poss, info, cnt, g.gx, g.gy); chcnt = 0; chi = -1; @@ -1329,8 +1328,8 @@ genericptr_t distance; int ndist, *dist_ptr = (int *) distance; if (*dist_ptr > (ndist = distu(x, y))) { - gx = x; - gy = y; + g.gx = x; + g.gy = y; *dist_ptr = ndist; } } diff --git a/src/dokick.c b/src/dokick.c index 62524a845..0ddd54b0f 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -9,9 +9,6 @@ (martial_bonus() || is_bigfoot(youmonst.data) \ || (uarmf && uarmf->otyp == KICKING_BOOTS)) -static NEARDATA struct rm *maploc, nowhere; -static NEARDATA const char *gate_str; - /* kickedobj (decl.c) tracks a kicked object until placed or destroyed */ STATIC_DCL void FDECL(kickdmg, (struct monst *, BOOLEAN_P)); @@ -718,33 +715,33 @@ const char *kickobjnam; if (*kickobjnam) what = kickobjnam; - else if (maploc == &nowhere) + else if (g.maploc == &g.nowhere) what = "nothing"; - else if (IS_DOOR(maploc->typ)) + else if (IS_DOOR(g.maploc->typ)) what = "a door"; - else if (IS_TREE(maploc->typ)) + else if (IS_TREE(g.maploc->typ)) what = "a tree"; - else if (IS_STWALL(maploc->typ)) + else if (IS_STWALL(g.maploc->typ)) what = "a wall"; - else if (IS_ROCK(maploc->typ)) + else if (IS_ROCK(g.maploc->typ)) what = "a rock"; - else if (IS_THRONE(maploc->typ)) + else if (IS_THRONE(g.maploc->typ)) what = "a throne"; - else if (IS_FOUNTAIN(maploc->typ)) + else if (IS_FOUNTAIN(g.maploc->typ)) what = "a fountain"; - else if (IS_GRAVE(maploc->typ)) + else if (IS_GRAVE(g.maploc->typ)) what = "a headstone"; - else if (IS_SINK(maploc->typ)) + else if (IS_SINK(g.maploc->typ)) what = "a sink"; - else if (IS_ALTAR(maploc->typ)) + else if (IS_ALTAR(g.maploc->typ)) what = "an altar"; - else if (IS_DRAWBRIDGE(maploc->typ)) + else if (IS_DRAWBRIDGE(g.maploc->typ)) what = "a drawbridge"; - else if (maploc->typ == STAIRS) + else if (g.maploc->typ == STAIRS) what = "the stairs"; - else if (maploc->typ == LADDER) + else if (g.maploc->typ == LADDER) what = "a ladder"; - else if (maploc->typ == IRONBARS) + else if (g.maploc->typ == IRONBARS) what = "an iron bar"; else what = "something weird"; @@ -887,10 +884,10 @@ dokick() u_wipe_engr(2); if (!isok(x, y)) { - maploc = &nowhere; + g.maploc = &g.nowhere; goto ouch; } - maploc = &levl[x][y]; + g.maploc = &levl[x][y]; /* * The next five tests should stay in their present order: @@ -959,49 +956,49 @@ dokick() goto ouch; } - if (!IS_DOOR(maploc->typ)) { - if (maploc->typ == SDOOR) { + if (!IS_DOOR(g.maploc->typ)) { + if (g.maploc->typ == SDOOR) { if (!Levitation && rn2(30) < avrg_attrib) { - cvt_sdoor_to_door(maploc); /* ->typ = DOOR */ + cvt_sdoor_to_door(g.maploc); /* ->typ = DOOR */ pline("Crash! %s a secret door!", /* don't "kick open" when it's locked unless it also happens to be trapped */ - (maploc->doormask & (D_LOCKED | D_TRAPPED)) == D_LOCKED + (g.maploc->doormask & (D_LOCKED | D_TRAPPED)) == D_LOCKED ? "Your kick uncovers" : "You kick open"); exercise(A_DEX, TRUE); - if (maploc->doormask & D_TRAPPED) { - maploc->doormask = D_NODOOR; + if (g.maploc->doormask & D_TRAPPED) { + g.maploc->doormask = D_NODOOR; b_trapped("door", FOOT); - } else if (maploc->doormask != D_NODOOR - && !(maploc->doormask & D_LOCKED)) - maploc->doormask = D_ISOPEN; + } else if (g.maploc->doormask != D_NODOOR + && !(g.maploc->doormask & D_LOCKED)) + g.maploc->doormask = D_ISOPEN; feel_newsym(x, y); /* we know it's gone */ - if (maploc->doormask == D_ISOPEN - || maploc->doormask == D_NODOOR) + if (g.maploc->doormask == D_ISOPEN + || g.maploc->doormask == D_NODOOR) unblock_point(x, y); /* vision */ return 1; } else goto ouch; } - if (maploc->typ == SCORR) { + if (g.maploc->typ == SCORR) { if (!Levitation && rn2(30) < avrg_attrib) { pline("Crash! You kick open a secret passage!"); exercise(A_DEX, TRUE); - maploc->typ = CORR; + g.maploc->typ = CORR; feel_newsym(x, y); /* we know it's gone */ unblock_point(x, y); /* vision */ return 1; } else goto ouch; } - if (IS_THRONE(maploc->typ)) { + if (IS_THRONE(g.maploc->typ)) { register int i; if (Levitation) goto dumb; - if ((Luck < 0 || maploc->doormask) && !rn2(3)) { - maploc->typ = ROOM; - maploc->doormask = 0; /* don't leave loose ends.. */ + if ((Luck < 0 || g.maploc->doormask) && !rn2(3)) { + g.maploc->typ = ROOM; + g.maploc->doormask = 0; /* don't leave loose ends.. */ (void) mkgold((long) rnd(200), x, y); if (Blind) pline("CRASH! You destroy it."); @@ -1011,7 +1008,7 @@ dokick() } exercise(A_DEX, TRUE); return 1; - } else if (Luck > 0 && !rn2(3) && !maploc->looted) { + } else if (Luck > 0 && !rn2(3) && !g.maploc->looted) { (void) mkgold((long) rn1(201, 300), x, y); i = Luck + 1; if (i > 6) @@ -1027,7 +1024,7 @@ dokick() newsym(x, y); } /* prevent endless milking */ - maploc->looted = T_LOOTED; + g.maploc->looted = T_LOOTED; return 1; } else if (!rn2(4)) { if (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz)) { @@ -1038,7 +1035,7 @@ dokick() } goto ouch; } - if (IS_ALTAR(maploc->typ)) { + if (IS_ALTAR(g.maploc->typ)) { if (Levitation) goto dumb; You("kick %s.", (Blind ? something : "the altar")); @@ -1048,7 +1045,7 @@ dokick() exercise(A_DEX, TRUE); return 1; } - if (IS_FOUNTAIN(maploc->typ)) { + if (IS_FOUNTAIN(g.maploc->typ)) { if (Levitation) goto dumb; You("kick %s.", (Blind ? something : "the fountain")); @@ -1063,7 +1060,7 @@ dokick() exercise(A_DEX, TRUE); return 1; } - if (IS_GRAVE(maploc->typ)) { + if (IS_GRAVE(g.maploc->typ)) { if (Levitation) goto dumb; if (rn2(4)) @@ -1073,8 +1070,8 @@ dokick() || ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10))) { adjalign(-sgn(u.ualign.type)); } - maploc->typ = ROOM; - maploc->doormask = 0; + g.maploc->typ = ROOM; + g.maploc->doormask = 0; (void) mksobj_at(ROCK, x, y, TRUE, FALSE); del_engr_at(x, y); if (Blind) @@ -1085,9 +1082,9 @@ dokick() } return 1; } - if (maploc->typ == IRONBARS) + if (g.maploc->typ == IRONBARS) goto ouch; - if (IS_TREE(maploc->typ)) { + if (IS_TREE(g.maploc->typ)) { struct obj *treefruit; /* nothing, fruit or trouble? 75:23.5:1.5% */ @@ -1096,7 +1093,7 @@ dokick() You_hear("a low buzzing."); /* a warning */ goto ouch; } - if (rn2(15) && !(maploc->looted & TREE_LOOTED) + if (rn2(15) && !(g.maploc->looted & TREE_LOOTED) && (treefruit = rnd_treefruit_at(x, y))) { long nfruit = 8L - rnl(7), nfall; short frtype = treefruit->otyp; @@ -1120,9 +1117,9 @@ dokick() exercise(A_DEX, TRUE); exercise(A_WIS, TRUE); /* discovered a new food source! */ newsym(x, y); - maploc->looted |= TREE_LOOTED; + g.maploc->looted |= TREE_LOOTED; return 1; - } else if (!(maploc->looted & TREE_SWARM)) { + } else if (!(g.maploc->looted & TREE_SWARM)) { int cnt = rnl(4) + 2; int made = 0; coord mm; @@ -1139,12 +1136,12 @@ dokick() pline("You've attracted the tree's former occupants!"); else You("smell stale honey."); - maploc->looted |= TREE_SWARM; + g.maploc->looted |= TREE_SWARM; return 1; } goto ouch; } - if (IS_SINK(maploc->typ)) { + if (IS_SINK(g.maploc->typ)) { int gend = poly_gender(); short washerndx = (gend == 1 || (gend == 2 && rn2(2))) ? PM_INCUBUS @@ -1159,7 +1156,7 @@ dokick() pline("Klunk!"); exercise(A_DEX, TRUE); return 1; - } else if (!(maploc->looted & S_LPUDDING) && !rn2(3) + } else if (!(g.maploc->looted & S_LPUDDING) && !rn2(3) && !(mvitals[PM_BLACK_PUDDING].mvflags & G_GONE)) { if (Blind) You_hear("a gushing sound."); @@ -1169,37 +1166,37 @@ dokick() (void) makemon(&mons[PM_BLACK_PUDDING], x, y, NO_MM_FLAGS); exercise(A_DEX, TRUE); newsym(x, y); - maploc->looted |= S_LPUDDING; + g.maploc->looted |= S_LPUDDING; return 1; - } else if (!(maploc->looted & S_LDWASHER) && !rn2(3) + } else if (!(g.maploc->looted & S_LDWASHER) && !rn2(3) && !(mvitals[washerndx].mvflags & G_GONE)) { /* can't resist... */ pline("%s returns!", (Blind ? Something : "The dish washer")); if (makemon(&mons[washerndx], x, y, NO_MM_FLAGS)) newsym(x, y); - maploc->looted |= S_LDWASHER; + g.maploc->looted |= S_LDWASHER; exercise(A_DEX, TRUE); return 1; } else if (!rn2(3)) { pline("Flupp! %s.", (Blind ? "You hear a sloshing sound" : "Muddy waste pops up from the drain")); - if (!(maploc->looted & S_LRING)) { /* once per sink */ + if (!(g.maploc->looted & S_LRING)) { /* once per sink */ if (!Blind) You_see("a ring shining in its midst."); (void) mkobj_at(RING_CLASS, x, y, TRUE); newsym(x, y); exercise(A_DEX, TRUE); exercise(A_WIS, TRUE); /* a discovery! */ - maploc->looted |= S_LRING; + g.maploc->looted |= S_LRING; } return 1; } goto ouch; } - if (maploc->typ == STAIRS || maploc->typ == LADDER - || IS_STWALL(maploc->typ)) { - if (!IS_STWALL(maploc->typ) && maploc->ladder == LA_DOWN) + if (g.maploc->typ == STAIRS || g.maploc->typ == LADDER + || IS_STWALL(g.maploc->typ)) { + if (!IS_STWALL(g.maploc->typ) && g.maploc->ladder == LA_DOWN) goto dumb; ouch: pline("Ouch! That hurts!"); @@ -1212,7 +1209,7 @@ dokick() pline_The("drawbridge is unaffected."); /* update maploc to refer to the drawbridge */ (void) find_drawbridge(&x, &y); - maploc = &levl[x][y]; + g.maploc = &levl[x][y]; } } if (!rn2(3)) @@ -1226,8 +1223,8 @@ dokick() goto dumb; } - if (maploc->doormask == D_ISOPEN || maploc->doormask == D_BROKEN - || maploc->doormask == D_NODOOR) { + if (g.maploc->doormask == D_ISOPEN || g.maploc->doormask == D_BROKEN + || g.maploc->doormask == D_NODOOR) { dumb: exercise(A_DEX, FALSE); if (martial() || ACURR(A_DEX) >= 16 || rn2(3)) { @@ -1253,20 +1250,20 @@ dokick() if (rnl(35) < avrg_attrib + (!martial() ? 0 : ACURR(A_DEX))) { boolean shopdoor = *in_rooms(x, y, SHOPBASE) ? TRUE : FALSE; /* break the door */ - if (maploc->doormask & D_TRAPPED) { + if (g.maploc->doormask & D_TRAPPED) { if (flags.verbose) You("kick the door."); exercise(A_STR, FALSE); - maploc->doormask = D_NODOOR; + g.maploc->doormask = D_NODOOR; b_trapped("door", FOOT); } else if (ACURR(A_STR) > 18 && !rn2(5) && !shopdoor) { pline("As you kick the door, it shatters to pieces!"); exercise(A_STR, TRUE); - maploc->doormask = D_NODOOR; + g.maploc->doormask = D_NODOOR; } else { pline("As you kick the door, it crashes open!"); exercise(A_STR, TRUE); - maploc->doormask = D_BROKEN; + g.maploc->doormask = D_BROKEN; } feel_newsym(x, y); /* we know we broke it */ unblock_point(x, y); /* vision */ @@ -1438,11 +1435,11 @@ xchar dlev; /* if !0 send to dlev near player */ dct == oct ? "the " : dct == 1L ? "an" : "", what); else if (oct == dct) pline("%s adjacent %s %s.", dct == 1L ? "The" : "All the", what, - gate_str); + g.gate_str); else pline("%s adjacent %s %s.", dct == 1L ? "One of the" : "Some of the", - dct == 1L ? "objects falls" : what, gate_str); + dct == 1L ? "objects falls" : what, g.gate_str); } if (costly && shkp && price) { @@ -1746,10 +1743,10 @@ long num; if (nodrop) Sprintf(eos(xbuf), "."); else - Sprintf(eos(xbuf), " and %s %s.", otense(otmp, "fall"), gate_str); + Sprintf(eos(xbuf), " and %s %s.", otense(otmp, "fall"), g.gate_str); pline("%s%s", obuf, xbuf); } else if (!nodrop) - pline("%s %s %s.", obuf, otense(otmp, "fall"), gate_str); + pline("%s %s %s.", obuf, otense(otmp, "fall"), g.gate_str); } /* migration destination for objects which fall down to next level */ @@ -1759,25 +1756,25 @@ xchar x, y; { struct trap *ttmp; - gate_str = 0; + g.gate_str = 0; /* this matches the player restriction in goto_level() */ if (on_level(&u.uz, &qstart_level) && !ok_to_quest()) return MIGR_NOWHERE; if ((xdnstair == x && ydnstair == y) || (sstairs.sx == x && sstairs.sy == y && !sstairs.up)) { - gate_str = "down the stairs"; + g.gate_str = "down the stairs"; return (xdnstair == x && ydnstair == y) ? MIGR_STAIRS_UP : MIGR_SSTAIRS; } if (xdnladder == x && ydnladder == y) { - gate_str = "down the ladder"; + g.gate_str = "down the ladder"; return MIGR_LADDER_UP; } if (((ttmp = t_at(x, y)) != 0 && ttmp->tseen) && is_hole(ttmp->ttyp)) { - gate_str = (ttmp->ttyp == TRAPDOOR) ? "through the trap door" + g.gate_str = (ttmp->ttyp == TRAPDOOR) ? "through the trap door" : "through the hole"; return MIGR_RANDOM; } diff --git a/src/drawing.c b/src/drawing.c index 5a73d4c3f..8867ab74c 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -17,15 +17,6 @@ #define C(n) #endif -struct symsetentry symset[NUM_GRAPHICS]; - -int currentgraphics = 0; - -nhsym showsyms[SYM_MAX] = DUMMY; /* symbols to be displayed */ -nhsym l_syms[SYM_MAX] = DUMMY; /* loaded symbols */ -nhsym r_syms[SYM_MAX] = DUMMY; /* rogue symbols */ - -nhsym warnsyms[WARNCOUNT] = DUMMY; /* the current warning display symbols */ const char invisexplain[] = "remembered, unseen, creature", altinvisexplain[] = "unseen creature"; /* for clairvoyance */ @@ -357,9 +348,9 @@ init_symbols() void update_bouldersym() { - showsyms[SYM_BOULDER + SYM_OFF_X] = iflags.bouldersym; - l_syms[SYM_BOULDER + SYM_OFF_X] = iflags.bouldersym; - r_syms[SYM_BOULDER + SYM_OFF_X] = iflags.bouldersym; + g.showsyms[SYM_BOULDER + SYM_OFF_X] = iflags.bouldersym; + g.l_syms[SYM_BOULDER + SYM_OFF_X] = iflags.bouldersym; + g.r_syms[SYM_BOULDER + SYM_OFF_X] = iflags.bouldersym; } void @@ -368,20 +359,20 @@ init_showsyms() register int i; for (i = 0; i < MAXPCHARS; i++) - showsyms[i + SYM_OFF_P] = defsyms[i].sym; + g.showsyms[i + SYM_OFF_P] = defsyms[i].sym; for (i = 0; i < MAXOCLASSES; i++) - showsyms[i + SYM_OFF_O] = def_oc_syms[i].sym; + g.showsyms[i + SYM_OFF_O] = def_oc_syms[i].sym; for (i = 0; i < MAXMCLASSES; i++) - showsyms[i + SYM_OFF_M] = def_monsyms[i].sym; + g.showsyms[i + SYM_OFF_M] = def_monsyms[i].sym; for (i = 0; i < WARNCOUNT; i++) - showsyms[i + SYM_OFF_W] = def_warnsyms[i].sym; + g.showsyms[i + SYM_OFF_W] = def_warnsyms[i].sym; for (i = 0; i < MAXOTHER; i++) { if (i == SYM_BOULDER) - showsyms[i + SYM_OFF_X] = iflags.bouldersym + g.showsyms[i + SYM_OFF_X] = iflags.bouldersym ? iflags.bouldersym : def_oc_syms[ROCK_CLASS].sym; else if (i == SYM_INVISIBLE) - showsyms[i + SYM_OFF_X] = DEF_INVISIBLE; + g.showsyms[i + SYM_OFF_X] = DEF_INVISIBLE; } } @@ -392,20 +383,20 @@ init_l_symbols() register int i; for (i = 0; i < MAXPCHARS; i++) - l_syms[i + SYM_OFF_P] = defsyms[i].sym; + g.l_syms[i + SYM_OFF_P] = defsyms[i].sym; for (i = 0; i < MAXOCLASSES; i++) - l_syms[i + SYM_OFF_O] = def_oc_syms[i].sym; + g.l_syms[i + SYM_OFF_O] = def_oc_syms[i].sym; for (i = 0; i < MAXMCLASSES; i++) - l_syms[i + SYM_OFF_M] = def_monsyms[i].sym; + g.l_syms[i + SYM_OFF_M] = def_monsyms[i].sym; for (i = 0; i < WARNCOUNT; i++) - l_syms[i + SYM_OFF_W] = def_warnsyms[i].sym; + g.l_syms[i + SYM_OFF_W] = def_warnsyms[i].sym; for (i = 0; i < MAXOTHER; i++) { if (i == SYM_BOULDER) - l_syms[i + SYM_OFF_X] = iflags.bouldersym + g.l_syms[i + SYM_OFF_X] = iflags.bouldersym ? iflags.bouldersym : def_oc_syms[ROCK_CLASS].sym; else if (i == SYM_INVISIBLE) - l_syms[i + SYM_OFF_X] = DEF_INVISIBLE; + g.l_syms[i + SYM_OFF_X] = DEF_INVISIBLE; } clear_symsetentry(PRIMARY, FALSE); @@ -420,30 +411,30 @@ init_r_symbols() later by the roguesymbols option */ for (i = 0; i < MAXPCHARS; i++) - r_syms[i + SYM_OFF_P] = defsyms[i].sym; - r_syms[S_vodoor] = r_syms[S_hodoor] = r_syms[S_ndoor] = '+'; - r_syms[S_upstair] = r_syms[S_dnstair] = '%'; + g.r_syms[i + SYM_OFF_P] = defsyms[i].sym; + g.r_syms[S_vodoor] = g.r_syms[S_hodoor] = g.r_syms[S_ndoor] = '+'; + g.r_syms[S_upstair] = g.r_syms[S_dnstair] = '%'; for (i = 0; i < MAXOCLASSES; i++) - r_syms[i + SYM_OFF_O] = def_r_oc_syms[i]; + g.r_syms[i + SYM_OFF_O] = def_r_oc_syms[i]; for (i = 0; i < MAXMCLASSES; i++) - r_syms[i + SYM_OFF_M] = def_monsyms[i].sym; + g.r_syms[i + SYM_OFF_M] = def_monsyms[i].sym; for (i = 0; i < WARNCOUNT; i++) - r_syms[i + SYM_OFF_W] = def_warnsyms[i].sym; + g.r_syms[i + SYM_OFF_W] = def_warnsyms[i].sym; for (i = 0; i < MAXOTHER; i++) { if (i == SYM_BOULDER) - r_syms[i + SYM_OFF_X] = iflags.bouldersym + g.r_syms[i + SYM_OFF_X] = iflags.bouldersym ? iflags.bouldersym : def_oc_syms[ROCK_CLASS].sym; else if (i == SYM_INVISIBLE) - r_syms[i + SYM_OFF_X] = DEF_INVISIBLE; + g.r_syms[i + SYM_OFF_X] = DEF_INVISIBLE; } clear_symsetentry(ROGUESET, FALSE); /* default on Rogue level is no color * but some symbol sets can override that */ - symset[ROGUESET].nocolor = 1; + g.symset[ROGUESET].nocolor = 1; } void @@ -457,25 +448,25 @@ int whichset; /* Adjust graphics display characters on Rogue levels */ for (i = 0; i < SYM_MAX; i++) - showsyms[i] = r_syms[i]; + g.showsyms[i] = g.r_syms[i]; #if defined(MSDOS) && defined(USE_TILES) if (iflags.grmode) tileview(FALSE); #endif - currentgraphics = ROGUESET; + g.currentgraphics = ROGUESET; break; case PRIMARY: default: for (i = 0; i < SYM_MAX; i++) - showsyms[i] = l_syms[i]; + g.showsyms[i] = g.l_syms[i]; #if defined(MSDOS) && defined(USE_TILES) if (iflags.grmode) tileview(TRUE); #endif - currentgraphics = PRIMARY; + g.currentgraphics = PRIMARY; break; } } @@ -488,11 +479,11 @@ int nondefault; if (nondefault) { for (i = 0; i < SYM_MAX; i++) - showsyms[i] = l_syms[i]; + g.showsyms[i] = g.l_syms[i]; #ifdef PC9800 if (SYMHANDLING(H_IBM) && ibmgraphics_mode_callback) (*ibmgraphics_mode_callback)(); - else if (!symset[currentgraphics].name && ascgraphics_mode_callback) + else if (!g.symset[g.currentgraphics].name && ascgraphics_mode_callback) (*ascgraphics_mode_callback)(); #endif #ifdef TERMLIB @@ -512,7 +503,7 @@ update_l_symset(symp, val) struct symparse *symp; int val; { - l_syms[symp->idx] = val; + g.l_syms[symp->idx] = val; } void @@ -520,7 +511,7 @@ update_r_symset(symp, val) struct symparse *symp; int val; { - r_syms[symp->idx] = val; + g.r_syms[symp->idx] = val; } void @@ -528,20 +519,20 @@ clear_symsetentry(which_set, name_too) int which_set; boolean name_too; { - if (symset[which_set].desc) - free((genericptr_t) symset[which_set].desc); - symset[which_set].desc = (char *) 0; + if (g.symset[which_set].desc) + free((genericptr_t) g.symset[which_set].desc); + g.symset[which_set].desc = (char *) 0; - symset[which_set].handling = H_UNK; - symset[which_set].nocolor = 0; + g.symset[which_set].handling = H_UNK; + g.symset[which_set].nocolor = 0; /* initialize restriction bits */ - symset[which_set].primary = 0; - symset[which_set].rogue = 0; + g.symset[which_set].primary = 0; + g.symset[which_set].rogue = 0; if (name_too) { - if (symset[which_set].name) - free((genericptr_t) symset[which_set].name); - symset[which_set].name = (char *) 0; + if (g.symset[which_set].name) + free((genericptr_t) g.symset[which_set].name); + g.symset[which_set].name = (char *) 0; } } diff --git a/src/dungeon.c b/src/dungeon.c index 335ca15da..913fe0c9d 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -25,11 +25,6 @@ struct proto_dungeon { int n_brs; /* number of tmpbranch entries */ }; -int n_dgns; /* number of dungeons (also used in mklev.c and do.c) */ -static branch *branches = (branch *) 0; /* dungeon branch list */ - -mapseen *mapseenchn = (struct mapseen *) 0; /*DUNGEON_OVERVIEW*/ - struct lchoice { int idx; schar lev[MAXLINFO]; @@ -88,7 +83,7 @@ dumpit() if (!explicitdebug(__FILE__)) return; - for (i = 0; i < n_dgns; i++) { + for (i = 0; i < g.n_dgns; i++) { fprintf(stderr, "\n#%d \"%s\" (%s):\n", i, DD.dname, DD.proto); fprintf(stderr, " num_dunlevs %d, dunlev_ureached %d\n", DD.num_dunlevs, DD.dunlev_ureached); @@ -112,7 +107,7 @@ dumpit() getchar(); } fprintf(stderr, "\nBranches:\n"); - for (br = branches; br; br = br->next) { + for (br = g.branches; br; br = br->next) { fprintf(stderr, "%d: %s, end1 %d %d, end2 %d %d, %s\n", br->id, br->type == BR_STAIR ? "stair" @@ -143,17 +138,17 @@ boolean perform_write, free_data; int count; if (perform_write) { - bwrite(fd, (genericptr_t) &n_dgns, sizeof n_dgns); + bwrite(fd, (genericptr_t) &g.n_dgns, sizeof g.n_dgns); bwrite(fd, (genericptr_t) dungeons, - sizeof(dungeon) * (unsigned) n_dgns); + sizeof(dungeon) * (unsigned) g.n_dgns); bwrite(fd, (genericptr_t) &dungeon_topology, sizeof dungeon_topology); bwrite(fd, (genericptr_t) tune, sizeof tune); - for (count = 0, curr = branches; curr; curr = curr->next) + for (count = 0, curr = g.branches; curr; curr = curr->next) count++; bwrite(fd, (genericptr_t) &count, sizeof(count)); - for (curr = branches; curr; curr = curr->next) + for (curr = g.branches; curr; curr = curr->next) bwrite(fd, (genericptr_t) curr, sizeof(branch)); count = maxledgerno(); @@ -162,28 +157,28 @@ boolean perform_write, free_data; (unsigned) count * sizeof(struct linfo)); bwrite(fd, (genericptr_t) &inv_pos, sizeof inv_pos); - for (count = 0, curr_ms = mapseenchn; curr_ms; + for (count = 0, curr_ms = g.mapseenchn; curr_ms; curr_ms = curr_ms->next) count++; bwrite(fd, (genericptr_t) &count, sizeof(count)); - for (curr_ms = mapseenchn; curr_ms; curr_ms = curr_ms->next) + for (curr_ms = g.mapseenchn; curr_ms; curr_ms = curr_ms->next) save_mapseen(fd, curr_ms); } if (free_data) { - for (curr = branches; curr; curr = next) { + for (curr = g.branches; curr; curr = next) { next = curr->next; free((genericptr_t) curr); } - branches = 0; - for (curr_ms = mapseenchn; curr_ms; curr_ms = next_ms) { + g.branches = 0; + for (curr_ms = g.mapseenchn; curr_ms; curr_ms = next_ms) { next_ms = curr_ms->next; if (curr_ms->custom) free((genericptr_t) curr_ms->custom); free((genericptr_t) curr_ms); } - mapseenchn = 0; + g.mapseenchn = 0; } } @@ -196,12 +191,12 @@ int fd; int count, i; mapseen *curr_ms, *last_ms; - mread(fd, (genericptr_t) &n_dgns, sizeof(n_dgns)); - mread(fd, (genericptr_t) dungeons, sizeof(dungeon) * (unsigned) n_dgns); + mread(fd, (genericptr_t) &g.n_dgns, sizeof(g.n_dgns)); + mread(fd, (genericptr_t) dungeons, sizeof(dungeon) * (unsigned) g.n_dgns); mread(fd, (genericptr_t) &dungeon_topology, sizeof dungeon_topology); mread(fd, (genericptr_t) tune, sizeof tune); - last = branches = (branch *) 0; + last = g.branches = (branch *) 0; mread(fd, (genericptr_t) &count, sizeof(count)); for (i = 0; i < count; i++) { @@ -211,7 +206,7 @@ int fd; if (last) last->next = curr; else - branches = curr; + g.branches = curr; last = curr; } @@ -231,7 +226,7 @@ int fd; if (last_ms) last_ms->next = curr_ms; else - mapseenchn = curr_ms; + g.mapseenchn = curr_ms; last_ms = curr_ms; } } @@ -258,7 +253,7 @@ const char *s; { xchar i; - for (i = 0; i < n_dgns; i++) + for (i = 0; i < g.n_dgns; i++) if (!strcmp(dungeons[i].dname, s)) return i; @@ -297,7 +292,7 @@ struct proto_dungeon *pd; branch *br; const char *dnam; - for (br = branches; br; br = br->next) { + for (br = g.branches; br; br = br->next) { dnam = dungeons[br->end2.dnum].dname; if (!strcmpi(dnam, s) || (!strncmpi(dnam, "The ", 4) && !strcmpi(dnam + 4, s))) @@ -397,7 +392,7 @@ struct proto_dungeon *pd; do { if (++i >= num) i = 0; - for (curr = branches; curr; curr = curr->next) + for (curr = g.branches; curr; curr = curr->next) if ((curr->end1.dnum == dnum && curr->end1.dlevel == base + i) || (curr->end2.dnum == dnum && curr->end2.dlevel == base + i)) break; @@ -439,7 +434,7 @@ boolean extract_first; long new_val, curr_val, prev_val; if (extract_first) { - for (prev = 0, curr = branches; curr; prev = curr, curr = curr->next) + for (prev = 0, curr = g.branches; curr; prev = curr, curr = curr->next) if (curr == new_branch) break; @@ -448,7 +443,7 @@ boolean extract_first; if (prev) prev->next = curr->next; else - branches = curr->next; + g.branches = curr->next; } new_branch->next = (branch *) 0; @@ -464,7 +459,7 @@ boolean extract_first; prev = (branch *) 0; prev_val = -1; new_val = branch_val(new_branch); - for (curr = branches; curr; + for (curr = g.branches; curr; prev_val = curr_val, prev = curr, curr = curr->next) { curr_val = branch_val(curr); if (prev_val < new_val && new_val <= curr_val) @@ -474,8 +469,8 @@ boolean extract_first; new_branch->next = curr; prev->next = new_branch; } else { - new_branch->next = branches; - branches = new_branch; + new_branch->next = g.branches; + g.branches = new_branch; } } @@ -763,11 +758,11 @@ init_dungeons() * dungeon arrays. */ sp_levchn = (s_level *) 0; - Fread((genericptr_t) &n_dgns, sizeof(int), 1, dgn_file); - if (n_dgns >= MAXDUNGEON) + Fread((genericptr_t) &g.n_dgns, sizeof(int), 1, dgn_file); + if (g.n_dgns >= MAXDUNGEON) panic("init_dungeons: too many dungeons"); - for (i = 0; i < n_dgns; i++) { + for (i = 0; i < g.n_dgns; i++) { Fread((genericptr_t) &pd.tmpdungeon[i], sizeof(struct tmpdungeon), 1, dgn_file); if (!wizard && pd.tmpdungeon[i].chance @@ -782,7 +777,7 @@ init_dungeons() for (j = 0; j < pd.tmpdungeon[i].branches; j++) Fread((genericptr_t) &pd.tmpbranch[cb], sizeof(struct tmpbranch), 1, dgn_file); - n_dgns--; + g.n_dgns--; i--; continue; } @@ -938,12 +933,12 @@ init_dungeons() * its entrance (end1) has a bogus dnum, namely * n_dgns. */ - for (br = branches; br; br = br->next) + for (br = g.branches; br; br = br->next) if (on_level(&br->end2, &knox_level)) break; if (br) - br->end1.dnum = n_dgns; + br->end1.dnum = g.n_dgns; /* adjust the branch's position on the list */ insert_branch(br, TRUE); } @@ -1015,7 +1010,7 @@ boolean noquest; d_level tmp; register schar ret = 0; - for (i = 0; i < n_dgns; i++) { + for (i = 0; i < g.n_dgns; i++) { if (noquest && i == quest_dnum) continue; tmp.dlevel = dungeons[i].dunlev_ureached; @@ -1050,8 +1045,8 @@ d_level *lev; xchar maxledgerno() { - return (xchar) (dungeons[n_dgns - 1].ledger_start - + dungeons[n_dgns - 1].num_dunlevs); + return (xchar) (dungeons[g.n_dgns - 1].ledger_start + + dungeons[g.n_dgns - 1].num_dunlevs); } /* return the dungeon that this ledgerno exists in */ @@ -1062,7 +1057,7 @@ xchar ledgerno; register int i; /* find i such that (i->base + 1) <= ledgerno <= (i->base + i->count) */ - for (i = 0; i < n_dgns; i++) + for (i = 0; i < g.n_dgns; i++) if (dungeons[i].ledger_start < ledgerno && ledgerno <= dungeons[i].ledger_start + dungeons[i].num_dunlevs) return (xchar) i; @@ -1123,7 +1118,7 @@ d_level *lev; { branch *curr; - for (curr = branches; curr; curr = curr->next) { + for (curr = g.branches; curr; curr = curr->next) { if (on_level(lev, &curr->end1) || on_level(lev, &curr->end2)) return curr; } @@ -1373,7 +1368,7 @@ int levnum; * This assumes that end2 is always the "child" and it is * unique. */ - for (br = branches; br; br = br->next) + for (br = g.branches; br; br = br->next) if (br->end2.dnum == dgn) break; if (!br) @@ -1425,7 +1420,7 @@ const char *s; dnum = dname_to_dnum(s); /* Find the branch that connects to dungeon i's branch. */ - for (br = branches; br; br = br->next) + for (br = g.branches; br; br = br->next) if (br->end2.dnum == dnum) break; @@ -1721,8 +1716,8 @@ struct dungeon *dptr; /* if other floating branches are added, this will need to change */ if (idx != knox_level.dnum) return FALSE; - for (br = branches; br; br = br->next) - if (br->end1.dnum == n_dgns && br->end2.dnum == idx) + for (br = g.branches; br; br = br->next) + if (br->end1.dnum == g.n_dgns && br->end2.dnum == idx) return TRUE; return FALSE; } @@ -1816,7 +1811,7 @@ struct lchoice *lchoices_p; char buf[BUFSZ]; /* This assumes that end1 is the "parent". */ - for (br = branches; br; br = br->next) { + for (br = g.branches; br; br = br->next) { if (br->end1.dnum == dnum && lower_bound < br->end1.dlevel && br->end1.dlevel <= upper_bound) { Sprintf(buf, "%c %s to %s: %d", @@ -1856,7 +1851,7 @@ xchar *rdgn; lchoices.menuletter = 'a'; } - for (i = 0, dptr = dungeons; i < n_dgns; i++, dptr++) { + for (i = 0, dptr = dungeons; i < g.n_dgns; i++, dptr++) { if (bymenu && In_endgame(&u.uz) && i != astral_level.dnum) continue; unplaced = unplaced_floater(dptr); @@ -1933,8 +1928,8 @@ xchar *rdgn; } /* Print out floating branches (if any). */ - for (first = TRUE, br = branches; br; br = br->next) { - if (br->end1.dnum == n_dgns) { + for (first = TRUE, br = g.branches; br; br = br->next) { + if (br->end1.dnum == g.n_dgns) { if (first) { putstr(win, 0, ""); putstr(win, 0, "Floating branches"); @@ -2006,7 +2001,7 @@ d_level *dest; return; /* we only care about forward branches */ - for (br = branches; br; br = br->next) { + for (br = g.branches; br; br = br->next) { if (on_level(source, &br->end1) && on_level(dest, &br->end2)) break; if (on_level(source, &br->end2) && on_level(dest, &br->end1)) @@ -2094,7 +2089,7 @@ d_level *lev; { mapseen *mptr; - for (mptr = mapseenchn; mptr; mptr = mptr->next) + for (mptr = g.mapseenchn; mptr; mptr = mptr->next) if (on_level(&(mptr->lev), lev)) break; @@ -2107,7 +2102,7 @@ const char *s; { mapseen *mptr; - for (mptr = mapseenchn; mptr; mptr = mptr->next) + for (mptr = g.mapseenchn; mptr; mptr = mptr->next) if (mptr->custom && !strcmpi(s, mptr->custom)) break; @@ -2122,7 +2117,7 @@ int ledger_num; mapseen *mptr; struct cemetery *bp; - for (mptr = mapseenchn; mptr; mptr = mptr->next) + for (mptr = g.mapseenchn; mptr; mptr = mptr->next) if (dungeons[mptr->lev.dnum].ledger_start + mptr->lev.dlevel == ledger_num) break; @@ -2151,7 +2146,7 @@ int ledger_num; mapseen *mptr, *mprev = (mapseen *)0; struct cemetery *bp, *bpnext; - for (mptr = mapseenchn; mptr; mprev = mptr, mptr = mptr->next) + for (mptr = g.mapseenchn; mptr; mprev = mptr, mptr = mptr->next) if (dungeons[mptr->lev.dnum].ledger_start + mptr->lev.dlevel == ledger_num) break; @@ -2172,7 +2167,7 @@ int ledger_num; mprev->next = mptr->next; free(mptr); } else { - mapseenchn = mptr->next; + g.mapseenchn = mptr->next; free(mptr); } } @@ -2185,7 +2180,7 @@ mapseen *mptr; branch *curr; int brindx; - for (brindx = 0, curr = branches; curr; curr = curr->next, ++brindx) + for (brindx = 0, curr = g.branches; curr; curr = curr->next, ++brindx) if (curr == mptr->br) break; bwrite(fd, (genericptr_t) &brindx, sizeof brindx); @@ -2211,7 +2206,7 @@ int fd; load = (mapseen *) alloc(sizeof *load); mread(fd, (genericptr_t) &branchnum, sizeof branchnum); - for (brindx = 0, curr = branches; curr; curr = curr->next, ++brindx) + for (brindx = 0, curr = g.branches; curr; curr = curr->next, ++brindx) if (brindx == branchnum) break; load->br = curr; @@ -2246,7 +2241,7 @@ long *total_count, *total_size; mapseen *mptr = find_mapseen(&u.uz); ocount = bcount = acount = osize = bsize = asize = 0L; - for (mptr = mapseenchn; mptr; mptr = mptr->next) { + for (mptr = g.mapseenchn; mptr; mptr = mptr->next) { ++ocount; osize += (long) sizeof *mptr; for (ce = mptr->final_resting_place; ce; ce = ce->next) { @@ -2288,7 +2283,7 @@ int dnum; { mapseen *mptr, **mptraddr; - mptraddr = &mapseenchn; + mptraddr = &g.mapseenchn; while ((mptr = *mptraddr) != 0) { if (mptr->lev.dnum == dnum) { #if 1 /* use this... */ @@ -2330,14 +2325,14 @@ d_level *lev; init->lev.dlevel = lev->dlevel; /* walk until we get to the place where we should insert init */ - for (mptr = mapseenchn, prev = 0; mptr; prev = mptr, mptr = mptr->next) + for (mptr = g.mapseenchn, prev = 0; mptr; prev = mptr, mptr = mptr->next) if (mptr->lev.dnum > init->lev.dnum || (mptr->lev.dnum == init->lev.dnum && mptr->lev.dlevel > init->lev.dlevel)) break; if (!prev) { - init->next = mapseenchn; - mapseenchn = init; + init->next = g.mapseenchn; + g.mapseenchn = init; } else { mptr = prev->next; prev->next = init; @@ -2413,7 +2408,7 @@ recalc_mapseen() if (mptr->flags.unreachable) { mptr->flags.unreachable = 0; /* reached it; Eye of the Aethiopica? */ if (In_quest(&u.uz)) { - mapseen *mptrtmp = mapseenchn; + mapseen *mptrtmp = g.mapseenchn; /* when quest was unreachable due to ejection and portal removal, getting back to it via arti-invoke should revive annotation @@ -2716,7 +2711,7 @@ int why, reason, *lastdun_p; mapseen *mptr; boolean showheader; - for (mptr = mapseenchn; mptr; mptr = mptr->next) { + for (mptr = g.mapseenchn; mptr; mptr = mptr->next) { if (viewendgame ^ In_endgame(&mptr->lev)) continue; diff --git a/src/eat.c b/src/eat.c index 69077934b..555fa82fe 100644 --- a/src/eat.c +++ b/src/eat.c @@ -39,8 +39,6 @@ STATIC_DCL const char *FDECL(foodword, (struct obj *)); STATIC_DCL int FDECL(tin_variety, (struct obj *, BOOLEAN_P)); STATIC_DCL boolean FDECL(maybe_cannibal, (int, BOOLEAN_P)); -char msgbuf[BUFSZ]; - /* also used to see if you're allowed to eat cats and dogs */ #define CANNIBAL_ALLOWED() (Role_if(PM_CAVEMAN) || Race_if(PM_ORC)) @@ -69,8 +67,6 @@ STATIC_OVL NEARDATA const char allobj[] = { BALL_CLASS, CHAIN_CLASS, SPBOOK_CLASS, 0 }; -STATIC_OVL boolean force_save_hs = FALSE; - /* see hunger states in hack.h - texts used on bottom line */ const char *hu_stat[] = { "Satiated", " ", "Hungry ", "Weak ", "Fainting", "Fainted ", "Starved " }; @@ -1733,6 +1729,7 @@ start_eating(otmp) struct obj *otmp; { const char *old_nomovemsg, *save_nomovemsg; + static char msgbuf[BUFSZ]; debugpline2("start_eating: %s (victual = %s)", /* note: fmt_ptr() returns a static buffer but supports @@ -2758,7 +2755,7 @@ bite() do_reset_eat(); return 0; } - force_save_hs = TRUE; + g.force_save_hs = TRUE; if (context.victual.nmod < 0) { lesshungry(-context.victual.nmod); consume_oeaten(context.victual.piece, @@ -2768,7 +2765,7 @@ bite() lesshungry(1); consume_oeaten(context.victual.piece, -1); /* -= 1 */ } - force_save_hs = FALSE; + g.force_save_hs = FALSE; recalc_wt(); return 0; } @@ -2845,7 +2842,7 @@ lesshungry(num) int num; { /* See comments in newuhs() for discussion on force_save_hs */ - boolean iseating = (occupation == eatfood) || force_save_hs; + boolean iseating = (occupation == eatfood) || g.force_save_hs; debugpline1("lesshungry(%d)", num); u.uhunger += num; @@ -2951,7 +2948,7 @@ boolean incr; * were added or if HUNGRY and WEAK were separated by a big enough * gap to fit two bites. */ - if (occupation == eatfood || force_save_hs) { + if (occupation == eatfood || g.force_save_hs) { if (!saved_hs) { save_hs = u.uhs; saved_hs = TRUE; diff --git a/src/end.c b/src/end.c index 9d76a3533..cb27f2922 100644 --- a/src/end.c +++ b/src/end.c @@ -19,27 +19,6 @@ /* add b to long a, convert wraparound to max value */ #define nowrap_add(a, b) (a = ((a + b) < 0 ? LONG_MAX : (a + b))) -/* these probably ought to be generated by makedefs, like LAST_GEM */ -#define FIRST_GEM DILITHIUM_CRYSTAL -#define FIRST_AMULET AMULET_OF_ESP -#define LAST_AMULET AMULET_OF_YENDOR - -struct valuable_data { - long count; - int typ; -}; - -static struct valuable_data - gems[LAST_GEM + 1 - FIRST_GEM + 1], /* 1 extra for glass */ - amulets[LAST_AMULET + 1 - FIRST_AMULET]; - -static struct val_list { - struct valuable_data *list; - int size; -} valuables[] = { { gems, sizeof gems / sizeof *gems }, - { amulets, sizeof amulets / sizeof *amulets }, - { 0, 0 } }; - #ifndef NO_SIGNAL STATIC_PTR void FDECL(done_intr, (int)); #if defined(UNIX) || defined(VMS) || defined(__EMX__) @@ -909,18 +888,18 @@ struct obj *list; /* inventory or container contents */ continue; } else if (obj->oclass == AMULET_CLASS) { i = obj->otyp - FIRST_AMULET; - if (!amulets[i].count) { - amulets[i].count = obj->quan; - amulets[i].typ = obj->otyp; + if (!g.amulets[i].count) { + g.amulets[i].count = obj->quan; + g.amulets[i].typ = obj->otyp; } else - amulets[i].count += obj->quan; /* always adds one */ + g.amulets[i].count += obj->quan; /* always adds one */ } else if (obj->oclass == GEM_CLASS && obj->otyp < LUCKSTONE) { i = min(obj->otyp, LAST_GEM + 1) - FIRST_GEM; - if (!gems[i].count) { - gems[i].count = obj->quan; - gems[i].typ = obj->otyp; + if (!g.gems[i].count) { + g.gems[i].count = obj->quan; + g.gems[i].typ = obj->otyp; } else - gems[i].count += obj->quan; + g.gems[i].count += obj->quan; } return; } @@ -1407,14 +1386,14 @@ int how; register struct val_list *val; register int i; - for (val = valuables; val->list; val++) + for (val = g.valuables; val->list; val++) for (i = 0; i < val->size; i++) { val->list[i].count = 0L; } get_valuables(invent); /* add points for collected valuables */ - for (val = valuables; val->list; val++) + for (val = g.valuables; val->list; val++) for (i = 0; i < val->size; i++) if (val->list[i].count != 0L) { tmp = val->list[i].count @@ -1465,7 +1444,7 @@ int how; #endif /* list valuables here */ - for (val = valuables; val->list; val++) { + for (val = g.valuables; val->list; val++) { sort_valuables(val->list, val->size); for (i = 0; i < val->size && !done_stopprint; i++) { int typ = val->list[i].typ; diff --git a/src/files.c b/src/files.c index 3dd137743..57b2c65df 100644 --- a/src/files.c +++ b/src/files.c @@ -167,8 +167,6 @@ static int lockptr; extern char *sounddir; #endif -extern int n_dgns; /* from dungeon.c */ - #if defined(UNIX) && defined(QT_GRAPHICS) #define SELECTSAVED #endif @@ -604,7 +602,7 @@ clearlocks() sethanguphandler((void FDECL((*), (int) )) SIG_IGN); #endif /* can't access maxledgerno() before dungeons are created -dlc */ - for (x = (n_dgns ? maxledgerno() : 0); x >= 0; x--) + for (x = (g.n_dgns ? maxledgerno() : 0); x >= 0; x--) delete_levelfile(x); /* not all levels need be present */ } #endif /* ?PC_LOCKING,&c */ @@ -3182,17 +3180,17 @@ int which_set; /* name caller put in symset[which_set].name was not found; if it looks like "Default symbols", null it out and return success to use the default; otherwise, return failure */ - if (symset[which_set].name - && (fuzzymatch(symset[which_set].name, "Default symbols", + if (g.symset[which_set].name + && (fuzzymatch(g.symset[which_set].name, "Default symbols", " -_", TRUE) - || !strcmpi(symset[which_set].name, "default"))) + || !strcmpi(g.symset[which_set].name, "default"))) clear_symsetentry(which_set, TRUE); config_error_done(); - return (symset[which_set].name == 0) ? 1 : 0; + return (g.symset[which_set].name == 0) ? 1 : 0; } if (!chosen_symset_end) config_error_add("Missing finish for symset \"%s\"", - symset[which_set].name ? symset[which_set].name + g.symset[which_set].name ? g.symset[which_set].name : "unknown"); config_error_done(); @@ -3256,7 +3254,7 @@ int which_set; return 0; } - if (!symset[which_set].name) { + if (!g.symset[which_set].name) { /* A null symset name indicates that we're just building a pick-list of possible symset values from the file, so only do that */ @@ -3328,7 +3326,7 @@ int which_set; switch (symp->idx) { case 0: /* start of symset */ - if (!strcmpi(bufp, symset[which_set].name)) { + if (!strcmpi(bufp, g.symset[which_set].name)) { /* matches desired one */ chosen_symset_start = TRUE; /* these init_*() functions clear symset fields too */ @@ -3355,11 +3353,11 @@ int which_set; if (bufp) { if (!strcmpi(bufp, "true") || !strcmpi(bufp, "yes") || !strcmpi(bufp, "on")) - symset[which_set].nocolor = 0; + g.symset[which_set].nocolor = 0; else if (!strcmpi(bufp, "false") || !strcmpi(bufp, "no") || !strcmpi(bufp, "off")) - symset[which_set].nocolor = 1; + g.symset[which_set].nocolor = 1; } } break; @@ -3371,10 +3369,10 @@ int which_set; if (!strcmpi(known_restrictions[n], bufp)) { switch (n) { case 0: - symset[which_set].primary = 1; + g.symset[which_set].primary = 1; break; case 1: - symset[which_set].rogue = 1; + g.symset[which_set].rogue = 1; break; } break; /* while loop */ @@ -3405,10 +3403,10 @@ int which_set; { int i = 0; - symset[which_set].handling = H_UNK; + g.symset[which_set].handling = H_UNK; while (known_handling[i]) { if (!strcmpi(known_handling[i], handling)) { - symset[which_set].handling = i; + g.symset[which_set].handling = i; return; } i++; diff --git a/src/hack.c b/src/hack.c index 3e1ff2401..5a2d2eec4 100644 --- a/src/hack.c +++ b/src/hack.c @@ -24,42 +24,40 @@ STATIC_DCL void FDECL(move_update, (BOOLEAN_P)); #define TRAVP_GUESS 1 #define TRAVP_VALID 2 -static anything tmp_anything; - anything * uint_to_any(ui) unsigned ui; { - tmp_anything = zeroany; - tmp_anything.a_uint = ui; - return &tmp_anything; + g.tmp_anything = zeroany; + g.tmp_anything.a_uint = ui; + return &g.tmp_anything; } anything * long_to_any(lng) long lng; { - tmp_anything = zeroany; - tmp_anything.a_long = lng; - return &tmp_anything; + g.tmp_anything = zeroany; + g.tmp_anything.a_long = lng; + return &g.tmp_anything; } anything * monst_to_any(mtmp) struct monst *mtmp; { - tmp_anything = zeroany; - tmp_anything.a_monst = mtmp; - return &tmp_anything; + g.tmp_anything = zeroany; + g.tmp_anything.a_monst = mtmp; + return &g.tmp_anything; } anything * obj_to_any(obj) struct obj *obj; { - tmp_anything = zeroany; - tmp_anything.a_obj = obj; - return &tmp_anything; + g.tmp_anything = zeroany; + g.tmp_anything.a_obj = obj; + return &g.tmp_anything; } boolean @@ -2968,8 +2966,6 @@ weight_cap() return (int) carrcap; } -static int wc; /* current weight_cap(); valid after call to inv_weight() */ - /* returns how far beyond the normal capacity the player is currently. */ /* inv_weight() is negative if the player is below normal capacity. */ int @@ -2985,8 +2981,8 @@ inv_weight() wt += otmp->owt; otmp = otmp->nobj; } - wc = weight_cap(); - return (wt - wc); + g.wc = weight_cap(); + return (wt - g.wc); } /* @@ -3001,9 +2997,9 @@ int xtra_wt; if (wt <= 0) return UNENCUMBERED; - if (wc <= 1) + if (g.wc <= 1) return OVERLOADED; - cap = (wt * 2 / wc) + 1; + cap = (wt * 2 / g.wc) + 1; return min(cap, OVERLOADED); } @@ -3018,7 +3014,7 @@ max_capacity() { int wt = inv_weight(); - return (wt - (2 * wc)); + return (wt - (2 * g.wc)); } boolean diff --git a/src/invent.c b/src/invent.c index 718e1feb5..3da2ab31d 100644 --- a/src/invent.c +++ b/src/invent.c @@ -39,8 +39,6 @@ STATIC_DCL void FDECL(menu_identify, (int)); STATIC_DCL boolean FDECL(tool_in_use, (struct obj *)); STATIC_DCL char FDECL(obj_to_let, (struct obj *)); -static int lastinvnr = 51; /* 0 ... 51 (never saved&restored) */ - /* wizards can wish for venom, which will become an invisible inventory * item without this. putting it in inv_order would mean venom would * suddenly become a choice for all the inventory-class commands, which @@ -263,9 +261,6 @@ struct obj *obj; return res; } -/* set by sortloot() for use by sortloot_cmp(); reset by sortloot when done */ -static unsigned sortlootmode = 0; - /* qsort comparison routine for sortloot() */ STATIC_OVL int CFDECLSPEC sortloot_cmp(vptr1, vptr2) @@ -280,7 +275,7 @@ const genericptr vptr2; int val1, val2, c, namcmp; /* order by object class unless we're doing by-invlet without sortpack */ - if ((sortlootmode & (SORTLOOT_PACK | SORTLOOT_INVLET)) + if ((g.sortlootmode & (SORTLOOT_PACK | SORTLOOT_INVLET)) != SORTLOOT_INVLET) { /* Classify each object at most once no matter how many comparisons it is involved in. */ @@ -296,7 +291,7 @@ const genericptr vptr2; return (int) (val1 - val2); /* skip sub-classes when ordering by sortpack+invlet */ - if ((sortlootmode & SORTLOOT_INVLET) == 0) { + if ((g.sortlootmode & SORTLOOT_INVLET) == 0) { /* Class matches; sort by subclass. */ val1 = sli1->subclass; val2 = sli2->subclass; @@ -321,7 +316,7 @@ const genericptr vptr2; } /* order by assigned inventory letter */ - if ((sortlootmode & SORTLOOT_INVLET) != 0) { + if ((g.sortlootmode & SORTLOOT_INVLET) != 0) { c = obj1->invlet; val1 = ('a' <= c && c <= 'z') ? (c - 'a' + 2) : ('A' <= c && c <= 'Z') ? (c - 'A' + 2 + 26) @@ -338,7 +333,7 @@ const genericptr vptr2; return val1 - val2; } - if ((sortlootmode & SORTLOOT_LOOT) == 0) + if ((g.sortlootmode & SORTLOOT_LOOT) == 0) goto tiebreak; /* @@ -488,9 +483,9 @@ boolean FDECL((*filterfunc), (OBJ_P)); /* do the sort; if no sorting is requested, we'll just return a sortloot_item array reflecting the current ordering */ if (mode && n > 1) { - sortlootmode = mode; /* extra input for sortloot_cmp() */ + g.sortlootmode = mode; /* extra input for sortloot_cmp() */ qsort((genericptr_t) sliarray, n, sizeof *sliarray, sortloot_cmp); - sortlootmode = 0; /* reset static mode flags */ + g.sortlootmode = 0; /* reset static mode flags */ /* if sortloot_cmp formatted any objects, discard their strings now */ for (i = 0; i < n; ++i) if (sliarray[i].str) @@ -520,7 +515,7 @@ boolean by_nexthere; /* T: traverse via obj->nexthere, F: via obj->nobj */ unsigned n, i; boolean already_sorted = TRUE; - sortlootmode = mode; /* extra input for sortloot_cmp() */ + g.sortlootmode = mode; /* extra input for sortloot_cmp() */ for (n = osli.indx = 0, osli.obj = *olist; (o = osli.obj) != 0; osli = nsli) { nsli.obj = by_nexthere ? o->nexthere : o->nobj; @@ -544,7 +539,7 @@ boolean by_nexthere; /* T: traverse via obj->nexthere, F: via obj->nobj */ *olist = sliarray[0].obj; free((genericptr_t) sliarray); } - sortlootmode = 0; + g.sortlootmode = 0; } #endif /*0*/ @@ -577,7 +572,7 @@ register struct obj *otmp; if ((i = otmp->invlet) && (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z'))) return; - for (i = lastinvnr + 1; i != lastinvnr; i++) { + for (i = g.lastinvnr + 1; i != g.lastinvnr; i++) { if (i == 52) { i = -1; continue; @@ -587,7 +582,7 @@ register struct obj *otmp; } otmp->invlet = (inuse[i] ? NOINVSYM : (i < 26) ? ('a' + i) : ('A' + i - 26)); - lastinvnr = i; + g.lastinvnr = i; } /* note: assumes ASCII; toggling a bit puts lowercase in front of uppercase */ @@ -3809,9 +3804,6 @@ STATIC_VAR NEARDATA const char *names[] = { STATIC_VAR NEARDATA const char oth_symbols[] = { CONTAINED_SYM, '\0' }; STATIC_VAR NEARDATA const char *oth_names[] = { "Bagged/Boxed items" }; -STATIC_VAR NEARDATA char *invbuf = (char *) 0; -STATIC_VAR NEARDATA unsigned invbufsiz = 0; - char * let_to_name(let, unpaid, showsym) char let; @@ -3833,36 +3825,36 @@ boolean unpaid, showsym; len = strlen(class_name) + (unpaid ? sizeof "unpaid_" : sizeof "") + (oclass ? (strlen(ocsymfmt) + invbuf_sympadding) : 0); - if (len > invbufsiz) { - if (invbuf) - free((genericptr_t) invbuf); - invbufsiz = len + 10; /* add slop to reduce incremental realloc */ - invbuf = (char *) alloc(invbufsiz); + if (len > g.invbufsiz) { + if (g.invbuf) + free((genericptr_t) g.invbuf); + g.invbufsiz = len + 10; /* add slop to reduce incremental realloc */ + g.invbuf = (char *) alloc(g.invbufsiz); } if (unpaid) - Strcat(strcpy(invbuf, "Unpaid "), class_name); + Strcat(strcpy(g.invbuf, "Unpaid "), class_name); else - Strcpy(invbuf, class_name); + Strcpy(g.invbuf, class_name); if ((oclass != 0) && showsym) { - char *bp = eos(invbuf); + char *bp = eos(g.invbuf); int mlen = invbuf_sympadding - strlen(class_name); while (--mlen > 0) { *bp = ' '; bp++; } *bp = '\0'; - Sprintf(eos(invbuf), ocsymfmt, def_oc_syms[oclass].sym); + Sprintf(eos(g.invbuf), ocsymfmt, def_oc_syms[oclass].sym); } - return invbuf; + return g.invbuf; } /* release the static buffer used by let_to_name() */ void free_invbuf() { - if (invbuf) - free((genericptr_t) invbuf), invbuf = (char *) 0; - invbufsiz = 0; + if (g.invbuf) + free((genericptr_t) g.invbuf), g.invbuf = (char *) 0; + g.invbufsiz = 0; } /* give consecutive letters to every item in inventory (for !fixinv mode); @@ -3896,7 +3888,7 @@ reassign() } if (i >= 52) i = 52 - 1; - lastinvnr = i; + g.lastinvnr = i; } /* #adjust command diff --git a/src/lock.c b/src/lock.c index 5c52532b9..62ebde0f0 100644 --- a/src/lock.c +++ b/src/lock.c @@ -5,15 +5,6 @@ #include "hack.h" -/* at most one of `door' and `box' should be non-null at any given time */ -STATIC_VAR NEARDATA struct xlock_s { - struct rm *door; - struct obj *box; - int picktyp, /* key|pick|card for unlock, sharp vs blunt for #force */ - chance, usedtime; - boolean magic_key; -} xlock; - /* occupation callbacks */ STATIC_PTR int NDECL(picklock); STATIC_PTR int NDECL(forcelock); @@ -40,7 +31,7 @@ boolean picking_at(x, y) int x, y; { - return (boolean) (occupation == picklock && xlock.door == &levl[x][y]); + return (boolean) (occupation == picklock && g.xlock.door == &levl[x][y]); } /* produce an occupation string appropriate for the current activity */ @@ -56,19 +47,19 @@ lock_action() }; /* if the target is currently unlocked, we're trying to lock it now */ - if (xlock.door && !(xlock.door->doormask & D_LOCKED)) + if (g.xlock.door && !(g.xlock.door->doormask & D_LOCKED)) return actions[0] + 2; /* "locking the door" */ - else if (xlock.box && !xlock.box->olocked) - return xlock.box->otyp == CHEST ? actions[1] + 2 : actions[2] + 2; + else if (g.xlock.box && !g.xlock.box->olocked) + return g.xlock.box->otyp == CHEST ? actions[1] + 2 : actions[2] + 2; /* otherwise we're trying to unlock it */ - else if (xlock.picktyp == LOCK_PICK) + else if (g.xlock.picktyp == LOCK_PICK) return actions[3]; /* "picking the lock" */ - else if (xlock.picktyp == CREDIT_CARD) + else if (g.xlock.picktyp == CREDIT_CARD) return actions[3]; /* same as lock_pick */ - else if (xlock.door) + else if (g.xlock.door) return actions[0]; /* "unlocking the door" */ - else if (xlock.box) - return xlock.box->otyp == CHEST ? actions[1] : actions[2]; + else if (g.xlock.box) + return g.xlock.box->otyp == CHEST ? actions[1] : actions[2]; else return actions[3]; } @@ -77,44 +68,44 @@ lock_action() STATIC_PTR int picklock(VOID_ARGS) { - if (xlock.box) { - if (xlock.box->where != OBJ_FLOOR - || xlock.box->ox != u.ux || xlock.box->oy != u.uy) { - return ((xlock.usedtime = 0)); /* you or it moved */ + if (g.xlock.box) { + if (g.xlock.box->where != OBJ_FLOOR + || g.xlock.box->ox != u.ux || g.xlock.box->oy != u.uy) { + return ((g.xlock.usedtime = 0)); /* you or it moved */ } } else { /* door */ - if (xlock.door != &(levl[u.ux + u.dx][u.uy + u.dy])) { - return ((xlock.usedtime = 0)); /* you moved */ + if (g.xlock.door != &(levl[u.ux + u.dx][u.uy + u.dy])) { + return ((g.xlock.usedtime = 0)); /* you moved */ } - switch (xlock.door->doormask) { + switch (g.xlock.door->doormask) { case D_NODOOR: pline("This doorway has no door."); - return ((xlock.usedtime = 0)); + return ((g.xlock.usedtime = 0)); case D_ISOPEN: You("cannot lock an open door."); - return ((xlock.usedtime = 0)); + return ((g.xlock.usedtime = 0)); case D_BROKEN: pline("This door is broken."); - return ((xlock.usedtime = 0)); + return ((g.xlock.usedtime = 0)); } } - if (xlock.usedtime++ >= 50 || nohands(youmonst.data)) { + if (g.xlock.usedtime++ >= 50 || nohands(youmonst.data)) { You("give up your attempt at %s.", lock_action()); exercise(A_DEX, TRUE); /* even if you don't succeed */ - return ((xlock.usedtime = 0)); + return ((g.xlock.usedtime = 0)); } - if (rn2(100) >= xlock.chance) + if (rn2(100) >= g.xlock.chance) return 1; /* still busy */ /* using the Master Key of Thievery finds traps if its bless/curse state is adequate (non-cursed for rogues, blessed for others; checked when setting up 'xlock') */ - if ((!xlock.door ? (int) xlock.box->otrapped - : (xlock.door->doormask & D_TRAPPED) != 0) - && xlock.magic_key) { - xlock.chance += 20; /* less effort needed next time */ + if ((!g.xlock.door ? (int) g.xlock.box->otrapped + : (g.xlock.door->doormask & D_TRAPPED) != 0) + && g.xlock.magic_key) { + g.xlock.chance += 20; /* less effort needed next time */ /* unfortunately we don't have a 'tknown' flag to record "known to be trapped" so declining to disarm and then retrying lock manipulation will find it all over again */ @@ -123,14 +114,14 @@ picklock(VOID_ARGS) boolean alreadyunlocked; /* disarming while using magic key always succeeds */ - if (xlock.door) { - xlock.door->doormask &= ~D_TRAPPED; + if (g.xlock.door) { + g.xlock.door->doormask &= ~D_TRAPPED; what = "door"; - alreadyunlocked = !(xlock.door->doormask & D_LOCKED); + alreadyunlocked = !(g.xlock.door->doormask & D_LOCKED); } else { - xlock.box->otrapped = 0; - what = (xlock.box->otyp == CHEST) ? "chest" : "box"; - alreadyunlocked = !xlock.box->olocked; + g.xlock.box->otrapped = 0; + what = (g.xlock.box->otyp == CHEST) ? "chest" : "box"; + alreadyunlocked = !g.xlock.box->olocked; } You("succeed in disarming the trap. The %s is still %slocked.", what, alreadyunlocked ? "un" : ""); @@ -139,30 +130,30 @@ picklock(VOID_ARGS) You("stop %s.", lock_action()); exercise(A_WIS, FALSE); } - return ((xlock.usedtime = 0)); + return ((g.xlock.usedtime = 0)); } You("succeed in %s.", lock_action()); - if (xlock.door) { - if (xlock.door->doormask & D_TRAPPED) { + if (g.xlock.door) { + if (g.xlock.door->doormask & D_TRAPPED) { b_trapped("door", FINGER); - xlock.door->doormask = D_NODOOR; + g.xlock.door->doormask = D_NODOOR; unblock_point(u.ux + u.dx, u.uy + u.dy); if (*in_rooms(u.ux + u.dx, u.uy + u.dy, SHOPBASE)) add_damage(u.ux + u.dx, u.uy + u.dy, SHOP_DOOR_COST); newsym(u.ux + u.dx, u.uy + u.dy); - } else if (xlock.door->doormask & D_LOCKED) - xlock.door->doormask = D_CLOSED; + } else if (g.xlock.door->doormask & D_LOCKED) + g.xlock.door->doormask = D_CLOSED; else - xlock.door->doormask = D_LOCKED; + g.xlock.door->doormask = D_LOCKED; } else { - xlock.box->olocked = !xlock.box->olocked; - xlock.box->lknown = 1; - if (xlock.box->otrapped) - (void) chest_trap(xlock.box, FINGER, FALSE); + g.xlock.box->olocked = !g.xlock.box->olocked; + g.xlock.box->lknown = 1; + if (g.xlock.box->otrapped) + (void) chest_trap(g.xlock.box, FINGER, FALSE); } exercise(A_DEX, TRUE); - return ((xlock.usedtime = 0)); + return ((g.xlock.usedtime = 0)); } void @@ -222,17 +213,17 @@ boolean destroyit; STATIC_PTR int forcelock(VOID_ARGS) { - if ((xlock.box->ox != u.ux) || (xlock.box->oy != u.uy)) - return ((xlock.usedtime = 0)); /* you or it moved */ + if ((g.xlock.box->ox != u.ux) || (g.xlock.box->oy != u.uy)) + return ((g.xlock.usedtime = 0)); /* you or it moved */ - if (xlock.usedtime++ >= 50 || !uwep || nohands(youmonst.data)) { + if (g.xlock.usedtime++ >= 50 || !uwep || nohands(youmonst.data)) { You("give up your attempt to force the lock."); - if (xlock.usedtime >= 50) /* you made the effort */ - exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE); - return ((xlock.usedtime = 0)); + if (g.xlock.usedtime >= 50) /* you made the effort */ + exercise((g.xlock.picktyp) ? A_DEX : A_STR, TRUE); + return ((g.xlock.usedtime = 0)); } - if (xlock.picktyp) { /* blade */ + if (g.xlock.picktyp) { /* blade */ if (rn2(1000 - (int) uwep->spe) > (992 - greatest_erosion(uwep) * 10) && !uwep->cursed && !obj_resists(uwep, 0, 99)) { /* for a +0 weapon, probability that it survives an unsuccessful @@ -243,35 +234,35 @@ forcelock(VOID_ARGS) useup(uwep); You("give up your attempt to force the lock."); exercise(A_DEX, TRUE); - return ((xlock.usedtime = 0)); + return ((g.xlock.usedtime = 0)); } } else /* blunt */ wake_nearby(); /* due to hammering on the container */ - if (rn2(100) >= xlock.chance) + if (rn2(100) >= g.xlock.chance) return 1; /* still busy */ You("succeed in forcing the lock."); - breakchestlock(xlock.box, (boolean) (!xlock.picktyp && !rn2(3))); + breakchestlock(g.xlock.box, (boolean) (!g.xlock.picktyp && !rn2(3))); - exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE); - return ((xlock.usedtime = 0)); + exercise((g.xlock.picktyp) ? A_DEX : A_STR, TRUE); + return ((g.xlock.usedtime = 0)); } void reset_pick() { - xlock.usedtime = xlock.chance = xlock.picktyp = 0; - xlock.magic_key = FALSE; - xlock.door = 0; - xlock.box = 0; + g.xlock.usedtime = g.xlock.chance = g.xlock.picktyp = 0; + g.xlock.magic_key = FALSE; + g.xlock.door = 0; + g.xlock.box = 0; } /* level change; don't reset if hero is carrying xlock.box with him/her */ void maybe_reset_pick() { - if (!xlock.box || !carried(xlock.box)) + if (!g.xlock.box || !carried(g.xlock.box)) reset_pick(); } @@ -297,7 +288,7 @@ struct obj *pick; picktyp = pick->otyp; /* check whether we're resuming an interrupted previous attempt */ - if (xlock.usedtime && picktyp == xlock.picktyp) { + if (g.xlock.usedtime && picktyp == g.xlock.picktyp) { static char no_longer[] = "Unfortunately, you can no longer %s %s."; if (nohands(youmonst.data)) { @@ -308,7 +299,7 @@ struct obj *pick; pline(no_longer, "hold the", what); reset_pick(); return PICKLOCK_LEARNED_SOMETHING; - } else if (u.uswallow || (xlock.box && !can_reach_floor(TRUE))) { + } else if (u.uswallow || (g.xlock.box && !can_reach_floor(TRUE))) { pline(no_longer, "reach the", "lock"); reset_pick(); return PICKLOCK_LEARNED_SOMETHING; @@ -316,7 +307,7 @@ struct obj *pick; const char *action = lock_action(); You("resume your attempt at %s.", action); - xlock.magic_key = is_magic_key(&youmonst, pick); + g.xlock.magic_key = is_magic_key(&youmonst, pick); set_occupation(picklock, action, 0); return PICKLOCK_DID_SOMETHING; } @@ -416,8 +407,8 @@ struct obj *pick; if (otmp->cursed) ch /= 2; - xlock.box = otmp; - xlock.door = 0; + g.xlock.box = otmp; + g.xlock.door = 0; break; } if (c != 'y') { @@ -495,15 +486,15 @@ struct obj *pick; default: ch = 0; } - xlock.door = door; - xlock.box = 0; + g.xlock.door = door; + g.xlock.box = 0; } } context.move = 0; - xlock.chance = ch; - xlock.picktyp = picktyp; - xlock.magic_key = is_magic_key(&youmonst, pick); - xlock.usedtime = 0; + g.xlock.chance = ch; + g.xlock.picktyp = picktyp; + g.xlock.magic_key = is_magic_key(&youmonst, pick); + g.xlock.usedtime = 0; set_occupation(picklock, lock_action(), 0); return PICKLOCK_DID_SOMETHING; } @@ -539,14 +530,14 @@ doforce() } picktyp = is_blade(uwep) && !is_pick(uwep); - if (xlock.usedtime && xlock.box && picktyp == xlock.picktyp) { + if (g.xlock.usedtime && g.xlock.box && picktyp == g.xlock.picktyp) { You("resume your attempt to force the lock."); set_occupation(forcelock, "forcing the lock", 0); return 1; } /* A lock is made only for the honest man, the thief will break it. */ - xlock.box = (struct obj *) 0; + g.xlock.box = (struct obj *) 0; for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) if (Is_box(otmp)) { if (otmp->obroken || !otmp->olocked) { @@ -574,15 +565,15 @@ doforce() You("force %s into a crack and pry.", yname(uwep)); else You("start bashing it with %s.", yname(uwep)); - xlock.box = otmp; - xlock.chance = objects[uwep->otyp].oc_wldam * 2; - xlock.picktyp = picktyp; - xlock.magic_key = FALSE; - xlock.usedtime = 0; + g.xlock.box = otmp; + g.xlock.chance = objects[uwep->otyp].oc_wldam * 2; + g.xlock.picktyp = picktyp; + g.xlock.magic_key = FALSE; + g.xlock.usedtime = 0; break; } - if (xlock.box) + if (g.xlock.box) set_occupation(forcelock, "forcing the lock", 0); else You("decide not to force the issue."); @@ -890,7 +881,7 @@ struct obj *obj, *otmp; /* obj *is* a box */ case SPE_POLYMORPH: /* maybe start unlocking chest, get interrupted, then zap it; we must avoid any attempt to resume unlocking it */ - if (xlock.box == obj) + if (g.xlock.box == obj) reset_pick(); break; } diff --git a/src/mapglyph.c b/src/mapglyph.c index 719c8e175..0ad22344d 100644 --- a/src/mapglyph.c +++ b/src/mapglyph.c @@ -48,10 +48,10 @@ static const int explcolors[] = { #if defined(USE_TILES) && defined(MSDOS) #define HAS_ROGUE_IBM_GRAPHICS \ - (currentgraphics == ROGUESET && SYMHANDLING(H_IBM) && !iflags.grmode) + (g.currentgraphics == ROGUESET && SYMHANDLING(H_IBM) && !iflags.grmode) #else #define HAS_ROGUE_IBM_GRAPHICS \ - (currentgraphics == ROGUESET && SYMHANDLING(H_IBM)) + (g.currentgraphics == ROGUESET && SYMHANDLING(H_IBM)) #endif #define is_objpile(x,y) (!Hallucination && level.objects[(x)][(y)] \ @@ -71,7 +71,7 @@ unsigned *ospecial; /* condense multiple tests in macro version down to single */ boolean has_rogue_ibm_graphics = HAS_ROGUE_IBM_GRAPHICS; boolean has_rogue_color = (has_rogue_ibm_graphics - && symset[currentgraphics].nocolor == 0); + && g.symset[g.currentgraphics].nocolor == 0); /* * Map the glyph back to a character and color. @@ -129,14 +129,14 @@ unsigned *ospecial; /* provide a visible difference if normal and lit corridor use the same symbol */ } else if (iflags.use_color && offset == S_litcorr - && showsyms[idx] == showsyms[S_corr + SYM_OFF_P]) { + && g.showsyms[idx] == g.showsyms[S_corr + SYM_OFF_P]) { color = CLR_WHITE; #endif /* try to provide a visible difference between water and lava if they use the same symbol and color is disabled */ } else if (!iflags.use_color && offset == S_lava - && (showsyms[idx] == showsyms[S_pool + SYM_OFF_P] - || showsyms[idx] == showsyms[S_water + SYM_OFF_P])) { + && (g.showsyms[idx] == g.showsyms[S_pool + SYM_OFF_P] + || g.showsyms[idx] == g.showsyms[S_water + SYM_OFF_P])) { special |= MG_BW_LAVA; } else { cmap_color(offset); @@ -222,7 +222,7 @@ unsigned *ospecial; } } - ch = showsyms[idx]; + ch = g.showsyms[idx]; #ifdef TEXTCOLOR /* Turn off color if no color defined, or rogue level w/o PC graphics. */ if (!has_color(color) || (Is_rogue_level(&u.uz) && !has_rogue_color)) @@ -283,7 +283,7 @@ const char *str; else break; so = mapglyph(gv, &ch, &oc, &os, 0, 0); - *put++ = showsyms[so]; + *put++ = g.showsyms[so]; /* 'str' is ready for the next loop iteration and '*str' should not be copied at the end of this iteration */ continue; @@ -308,7 +308,7 @@ const char *str; else break; } - *put++ = showsyms[so]; + *put++ = g.showsyms[so]; break; #endif case '\\': diff --git a/src/mhitm.c b/src/mhitm.c index 9be07a89a..31c7f0f2b 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -6,10 +6,6 @@ #include "hack.h" #include "artifact.h" -static NEARDATA boolean vis, far_noise; -static NEARDATA long noisetime; -static NEARDATA struct obj *otmp; - static const char brief_feeling[] = "have a %s feeling for a moment, then it passes."; @@ -32,11 +28,6 @@ STATIC_DCL void FDECL(missmm, (struct monst *, struct monst *, STATIC_DCL int FDECL(passivemm, (struct monst *, struct monst *, BOOLEAN_P, int)); -/* Needed for the special case of monsters wielding vorpal blades (rare). - * If we use this a lot it should probably be a parameter to mdamagem() - * instead of a global variable. - */ -static int dieroll; /* returns mon_nam(mon) relative to other_mon; normal name unless they're the same, in which case the reference is to {him|her|it} self */ @@ -69,9 +60,9 @@ register struct attack *mattk; { boolean farq = (distu(magr->mx, magr->my) > 15); - if (!Deaf && (farq != far_noise || moves - noisetime > 10)) { - far_noise = farq; - noisetime = moves; + if (!Deaf && (farq != g.far_noise || moves - g.noisetime > 10)) { + g.far_noise = farq; + g.noisetime = moves; You_hear("%s%s.", (mattk->aatyp == AT_EXPL) ? "an explosion" : "some noises", farq ? " in the distance" : ""); @@ -87,7 +78,7 @@ struct attack *mattk; const char *fmt; char buf[BUFSZ], mdef_name[BUFSZ]; - if (vis) { + if (g.vis) { if (!canspotmon(magr)) map_invisible(magr->mx, magr->my); if (!canspotmon(mdef)) @@ -235,7 +226,7 @@ boolean quietly; * You can observe monster displacement if you can see both of * the monsters involved. */ - vis = (canspotmon(magr) && canspotmon(mdef)); + g.vis = (canspotmon(magr) && canspotmon(mdef)); if (touch_petrifies(pd) && !resists_ston(magr)) { if (which_armor(magr, W_ARMG) != 0) { @@ -248,7 +239,7 @@ boolean quietly; monstone(magr); if (!DEADMONSTER(magr)) return MM_HIT; /* lifesaved */ - else if (magr->mtame && !vis) + else if (magr->mtame && !g.vis) You(brief_feeling, "peculiarly sad"); return MM_AGR_DIED; } @@ -258,7 +249,7 @@ boolean quietly; remove_monster(tx, ty); place_monster(magr, tx, ty); /* put down at target spot */ place_monster(mdef, fx, fy); - if (vis && !quietly) + if (g.vis && !quietly) pline("%s moves %s out of %s way!", Monnam(magr), mon_nam(mdef), is_rider(pa) ? "the" : mhis(magr)); newsym(fx, fy); /* see it */ @@ -343,7 +334,7 @@ register struct monst *magr, *mdef; tmp++; /* Set up the visibility of action */ - vis = (cansee(magr->mx, magr->my) && cansee(mdef->mx, mdef->my) + g.vis = (cansee(magr->mx, magr->my) && cansee(mdef->mx, mdef->my) && (canspotmon(magr) || canspotmon(mdef))); /* Set flag indicating monster has moved this turn. Necessary since a @@ -357,7 +348,7 @@ register struct monst *magr, *mdef; for (i = 0; i < NATTK; i++) { res[i] = MM_MISS; mattk = getmattk(magr, mdef, i, res, &alt_attk); - otmp = (struct obj *) 0; + g.otmp = (struct obj *) 0; attk = 1; switch (mattk->aatyp) { case AT_WEAP: /* "hand to hand" attacks */ @@ -376,12 +367,12 @@ register struct monst *magr, *mdef; return 0; } possibly_unwield(magr, FALSE); - otmp = MON_WEP(magr); + g.otmp = MON_WEP(magr); - if (otmp) { - if (vis) - mswingsm(magr, mdef, otmp); - tmp += hitval(otmp, mdef); + if (g.otmp) { + if (g.vis) + mswingsm(magr, mdef, g.otmp); + tmp += hitval(g.otmp, mdef); } /*FALLTHRU*/ case AT_CLAW: @@ -399,26 +390,26 @@ register struct monst *magr, *mdef; * have a weapon instead. This instinct doesn't work for * players, or under conflict or confusion. */ - if (!magr->mconf && !Conflict && otmp && mattk->aatyp != AT_WEAP + if (!magr->mconf && !Conflict && g.otmp && mattk->aatyp != AT_WEAP && touch_petrifies(mdef->data)) { strike = 0; break; } - dieroll = rnd(20 + i); - strike = (tmp > dieroll); + g.dieroll = rnd(20 + i); + strike = (tmp > g.dieroll); /* KMH -- don't accumulate to-hit bonuses */ - if (otmp) - tmp -= hitval(otmp, mdef); + if (g.otmp) + tmp -= hitval(g.otmp, mdef); if (strike) { res[i] = hitmm(magr, mdef, mattk); if ((mdef->data == &mons[PM_BLACK_PUDDING] || mdef->data == &mons[PM_BROWN_PUDDING]) - && (otmp && (objects[otmp->otyp].oc_material == IRON - || objects[otmp->otyp].oc_material == METAL)) + && (g.otmp && (objects[g.otmp->otyp].oc_material == IRON + || objects[g.otmp->otyp].oc_material == METAL)) && mdef->mhp > 1 && !mdef->mcan) { if (clone_mon(mdef, 0, 0)) { - if (vis && canspotmon(mdef)) { + if (g.vis && canspotmon(mdef)) { char buf[BUFSZ]; Strcpy(buf, Monnam(mdef)); @@ -533,7 +524,7 @@ hitmm(magr, mdef, mattk) register struct monst *magr, *mdef; struct attack *mattk; { - if (vis) { + if (g.vis) { int compat; char buf[BUFSZ], mdef_name[BUFSZ]; @@ -595,7 +586,7 @@ struct attack *mattk; { char buf[BUFSZ]; - if (vis) { + if (g.vis) { if (mdef->data->mlet == S_MIMIC && mdef->m_ap_type != M_AP_NOTHING) seemimic(mdef); @@ -606,7 +597,7 @@ struct attack *mattk; if (magr->mcan || !magr->mcansee || !mdef->mcansee || (magr->minvis && !perceives(mdef->data)) || mdef->msleeping) { - if (vis && canspotmon(mdef)) + if (g.vis && canspotmon(mdef)) pline("but nothing happens."); return MM_MISS; } @@ -687,7 +678,7 @@ register struct attack *mattk; if (!engulf_target(magr, mdef)) return MM_MISS; - if (vis) { + if (g.vis) { /* [this two-part formatting dates back to when only one x_monnam result could be included in an expression because the next one would overwrite first's result -- that's no longer the case] */ @@ -699,7 +690,7 @@ register struct attack *mattk; if (is_vampshifter(mdef) && newcham(mdef, &mons[mdef->cham], FALSE, FALSE)) { - if (vis) { + if (g.vis) { /* 'it' -- previous form is no longer available and using that would be excessively verbose */ pline("%s expels %s.", Monnam(magr), @@ -821,7 +812,7 @@ register struct attack *mattk; wornitems = magr->misc_worn_check; /* wielded weapon gives same protection as gloves here */ - if (otmp != 0) + if (g.otmp != 0) wornitems |= W_ARMG; if (protector == 0L @@ -830,12 +821,12 @@ register struct attack *mattk; mon_to_stone(magr); return MM_HIT; /* no damage during the polymorph */ } - if (vis && canspotmon(magr)) + if (g.vis && canspotmon(magr)) pline("%s turns to stone!", Monnam(magr)); monstone(magr); if (!DEADMONSTER(magr)) return MM_HIT; /* lifesaved */ - else if (magr->mtame && !vis) + else if (magr->mtame && !g.vis) You(brief_feeling, "peculiarly sad"); return MM_AGR_DIED; } @@ -849,7 +840,7 @@ register struct attack *mattk; case AD_DGST: /* eating a Rider or its corpse is fatal */ if (is_rider(pd)) { - if (vis && canseemon(magr)) + if (g.vis && canseemon(magr)) pline("%s %s!", Monnam(magr), (pd == &mons[PM_FAMINE]) ? "belches feebly, shrivels up and dies" @@ -859,7 +850,7 @@ register struct attack *mattk; mondied(magr); if (!DEADMONSTER(magr)) return 0; /* lifesaved */ - else if (magr->mtame && !vis) + else if (magr->mtame && !g.vis) You(brief_feeling, "queasy"); return MM_AGR_DIED; } @@ -917,26 +908,26 @@ register struct attack *mattk; if (mattk->aatyp == AT_KICK && thick_skinned(pd)) { tmp = 0; } else if (mattk->aatyp == AT_WEAP) { - if (otmp) { + if (g.otmp) { struct obj *marmg; - if (otmp->otyp == CORPSE - && touch_petrifies(&mons[otmp->corpsenm])) + if (g.otmp->otyp == CORPSE + && touch_petrifies(&mons[g.otmp->corpsenm])) goto do_stone; - tmp += dmgval(otmp, mdef); + tmp += dmgval(g.otmp, mdef); if ((marmg = which_armor(magr, W_ARMG)) != 0 && marmg->otyp == GAUNTLETS_OF_POWER) tmp += rn1(4, 3); /* 3..6 */ if (tmp < 1) /* is this necessary? mhitu.c has it... */ tmp = 1; - if (otmp->oartifact) { - (void) artifact_hit(magr, mdef, otmp, &tmp, dieroll); + if (g.otmp->oartifact) { + (void) artifact_hit(magr, mdef, g.otmp, &tmp, g.dieroll); if (DEADMONSTER(mdef)) return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); } if (tmp) - rustm(mdef, otmp); + rustm(mdef, g.otmp); } } else if (pa == &mons[PM_PURPLE_WORM] && pd == &mons[PM_SHRIEKER]) { /* hack to enhance mm_aggression(); we don't want purple @@ -952,22 +943,22 @@ register struct attack *mattk; tmp = 0; break; } - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk)); if (completelyburns(pd)) { /* paper golem or straw golem */ - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s burns completely!", Monnam(mdef)); mondead(mdef); /* was mondied() but that dropped paper scrolls */ if (!DEADMONSTER(mdef)) return 0; - else if (mdef->mtame && !vis) + else if (mdef->mtame && !g.vis) pline("May %s roast in peace.", mon_nam(mdef)); return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); } tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); if (resists_fire(mdef)) { - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline_The("fire doesn't seem to burn %s!", mon_nam(mdef)); shieldeff(mdef->mx, mdef->my); golemeffects(mdef, AD_FIRE, tmp); @@ -981,10 +972,10 @@ register struct attack *mattk; tmp = 0; break; } - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s is covered in frost!", Monnam(mdef)); if (resists_cold(mdef)) { - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline_The("frost doesn't seem to chill %s!", mon_nam(mdef)); shieldeff(mdef->mx, mdef->my); golemeffects(mdef, AD_COLD, tmp); @@ -997,11 +988,11 @@ register struct attack *mattk; tmp = 0; break; } - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s gets zapped!", Monnam(mdef)); tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); if (resists_elec(mdef)) { - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline_The("zap doesn't shock %s!", mon_nam(mdef)); shieldeff(mdef->mx, mdef->my); golemeffects(mdef, AD_ELEC, tmp); @@ -1016,11 +1007,11 @@ register struct attack *mattk; break; } if (resists_acid(mdef)) { - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s is covered in %s, but it seems harmless.", Monnam(mdef), hliquid("acid")); tmp = 0; - } else if (vis && canseemon(mdef)) { + } else if (g.vis && canseemon(mdef)) { pline("%s is covered in %s!", Monnam(mdef), hliquid("acid")); pline("It burns %s!", mon_nam(mdef)); } @@ -1033,12 +1024,12 @@ register struct attack *mattk; if (magr->mcan) break; if (pd == &mons[PM_IRON_GOLEM]) { - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s falls to pieces!", Monnam(mdef)); mondied(mdef); if (!DEADMONSTER(mdef)) return 0; - else if (mdef->mtame && !vis) + else if (mdef->mtame && !g.vis) pline("May %s rust in peace.", mon_nam(mdef)); return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); } @@ -1057,12 +1048,12 @@ register struct attack *mattk; if (magr->mcan) break; if (pd == &mons[PM_WOOD_GOLEM] || pd == &mons[PM_LEATHER_GOLEM]) { - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s falls to pieces!", Monnam(mdef)); mondied(mdef); if (!DEADMONSTER(mdef)) return 0; - else if (mdef->mtame && !vis) + else if (mdef->mtame && !g.vis) pline("May %s rot in peace.", mon_nam(mdef)); return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); } @@ -1083,13 +1074,13 @@ register struct attack *mattk; break; } if (!resists_ston(mdef)) { - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s turns to stone!", Monnam(mdef)); monstone(mdef); post_stone: if (!DEADMONSTER(mdef)) return 0; - else if (mdef->mtame && !vis) + else if (mdef->mtame && !g.vis) You(brief_feeling, "peculiarly sad"); return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); } @@ -1101,18 +1092,18 @@ register struct attack *mattk; boolean wasseen = canspotmon(mdef); /* save the name before monster teleports, otherwise we'll get "it" in the suddenly disappears message */ - if (vis && wasseen) + if (g.vis && wasseen) Strcpy(mdef_Monnam, Monnam(mdef)); mdef->mstrategy &= ~STRAT_WAITFORU; (void) rloc(mdef, TRUE); - if (vis && wasseen && !canspotmon(mdef) && mdef != u.usteed) + if (g.vis && wasseen && !canspotmon(mdef) && mdef != u.usteed) pline("%s suddenly disappears!", mdef_Monnam); } break; case AD_SLEE: if (!cancelled && !mdef->msleeping && sleep_monst(mdef, rnd(10), -1)) { - if (vis && canspotmon(mdef)) { + if (g.vis && canspotmon(mdef)) { Strcpy(buf, Monnam(mdef)); pline("%s is put to sleep by %s.", buf, mon_nam(magr)); } @@ -1122,7 +1113,7 @@ register struct attack *mattk; break; case AD_PLYS: if (!cancelled && mdef->mcanmove) { - if (vis && canspotmon(mdef)) { + if (g.vis && canspotmon(mdef)) { Strcpy(buf, Monnam(mdef)); pline("%s is frozen by %s.", buf, mon_nam(magr)); } @@ -1135,7 +1126,7 @@ register struct attack *mattk; mon_adjust_speed(mdef, -1, (struct obj *) 0); mdef->mstrategy &= ~STRAT_WAITFORU; - if (mdef->mspeed != oldspeed && vis && canspotmon(mdef)) + if (mdef->mspeed != oldspeed && g.vis && canspotmon(mdef)) pline("%s slows down.", Monnam(mdef)); } break; @@ -1145,7 +1136,7 @@ register struct attack *mattk; * we still should check for it). */ if (!magr->mcan && !mdef->mconf && !magr->mspec_used) { - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s looks confused.", Monnam(mdef)); mdef->mconf = 1; mdef->mstrategy &= ~STRAT_WAITFORU; @@ -1155,7 +1146,7 @@ register struct attack *mattk; if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) { register unsigned rnd_tmp; - if (vis && mdef->mcansee && canspotmon(mdef)) + if (g.vis && mdef->mcansee && canspotmon(mdef)) pline("%s is blinded.", Monnam(mdef)); rnd_tmp = d((int) mattk->damn, (int) mattk->damd); if ((rnd_tmp += mdef->mblinded) > 127) @@ -1168,7 +1159,7 @@ register struct attack *mattk; break; case AD_HALU: if (!magr->mcan && haseyes(pd) && mdef->mcansee) { - if (vis && canseemon(mdef)) + if (g.vis && canseemon(mdef)) pline("%s looks %sconfused.", Monnam(mdef), mdef->mconf ? "more " : ""); mdef->mconf = 1; @@ -1185,7 +1176,7 @@ register struct attack *mattk; if (is_were(pd) && pd->mlet != S_HUMAN) were_change(mdef); if (pd == &mons[PM_CLAY_GOLEM]) { - if (vis && canseemon(mdef)) { + if (g.vis && canseemon(mdef)) { pline("Some writing vanishes from %s head!", s_suffix(mon_nam(mdef))); pline("%s is destroyed!", Monnam(mdef)); @@ -1193,13 +1184,13 @@ register struct attack *mattk; mondied(mdef); if (!DEADMONSTER(mdef)) return 0; - else if (mdef->mtame && !vis) + else if (mdef->mtame && !g.vis) You(brief_feeling, "strangely sad"); return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); } if (!Deaf) { - if (!vis) + if (!g.vis) You_hear("laughter."); else if (canseemon(magr)) pline("%s chuckles.", Monnam(magr)); @@ -1222,21 +1213,21 @@ register struct attack *mattk; add_to_minv(magr, gold); } mdef->mstrategy &= ~STRAT_WAITFORU; - if (vis && canseemon(mdef)) { + if (g.vis && canseemon(mdef)) { Strcpy(buf, Monnam(magr)); pline("%s steals some gold from %s.", buf, mon_nam(mdef)); } if (!tele_restrict(magr)) { boolean couldspot = canspotmon(magr); (void) rloc(magr, TRUE); - if (vis && couldspot && !canspotmon(magr)) + if (g.vis && couldspot && !canspotmon(magr)) pline("%s suddenly disappears!", buf); } break; case AD_DRLI: if (!cancelled && !rn2(3) && !resists_drli(mdef)) { tmp = d(2, 6); - if (vis && canspotmon(mdef)) + if (g.vis && canspotmon(mdef)) pline("%s suddenly seems weaker!", Monnam(mdef)); mdef->mhpmax -= tmp; if (mdef->m_lev == 0) @@ -1264,26 +1255,26 @@ register struct attack *mattk; Strcpy(mdefnambuf, x_monnam(mdef, ARTICLE_THE, (char *) 0, 0, FALSE)); - otmp = obj; - if (u.usteed == mdef && otmp == which_armor(mdef, W_SADDLE)) + g.otmp = obj; + if (u.usteed == mdef && g.otmp == which_armor(mdef, W_SADDLE)) /* "You can no longer ride ." */ dismount_steed(DISMOUNT_POLY); - obj_extract_self(otmp); - if (otmp->owornmask) { - mdef->misc_worn_check &= ~otmp->owornmask; - if (otmp->owornmask & W_WEP) + obj_extract_self(g.otmp); + if (g.otmp->owornmask) { + mdef->misc_worn_check &= ~g.otmp->owornmask; + if (g.otmp->owornmask & W_WEP) mwepgone(mdef); - otmp->owornmask = 0L; - update_mon_intrinsics(mdef, otmp, FALSE, FALSE); + g.otmp->owornmask = 0L; + update_mon_intrinsics(mdef, g.otmp, FALSE, FALSE); /* give monster a chance to wear other equipment on its next move instead of waiting until it picks something up */ mdef->misc_worn_check |= I_SPECIAL; } /* add_to_minv() might free otmp [if it merges] */ - if (vis) - Strcpy(onambuf, doname(otmp)); - (void) add_to_minv(magr, otmp); - if (vis && canseemon(mdef)) { + if (g.vis) + Strcpy(onambuf, doname(g.otmp)); + (void) add_to_minv(magr, g.otmp); + if (g.vis && canseemon(mdef)) { Strcpy(buf, Monnam(magr)); pline("%s steals %s from %s!", buf, onambuf, mdefnambuf); } @@ -1297,7 +1288,7 @@ register struct attack *mattk; boolean couldspot = canspotmon(magr); (void) rloc(magr, TRUE); - if (vis && couldspot && !canspotmon(magr)) + if (g.vis && couldspot && !canspotmon(magr)) pline("%s suddenly disappears!", buf); } } @@ -1305,7 +1296,7 @@ register struct attack *mattk; break; case AD_DREN: if (!cancelled && !rn2(4)) - xdrainenergym(mdef, (boolean) (vis && canspotmon(mdef) + xdrainenergym(mdef, (boolean) (g.vis && canspotmon(mdef) && mattk->aatyp != AT_ENGL)); tmp = 0; break; @@ -1313,18 +1304,18 @@ register struct attack *mattk; case AD_DRDX: case AD_DRCO: if (!cancelled && !rn2(8)) { - if (vis && canspotmon(magr)) + if (g.vis && canspotmon(magr)) pline("%s %s was poisoned!", s_suffix(Monnam(magr)), mpoisons_subj(magr, mattk)); if (resists_poison(mdef)) { - if (vis && canspotmon(mdef) && canspotmon(magr)) + if (g.vis && canspotmon(mdef) && canspotmon(magr)) pline_The("poison doesn't seem to affect %s.", mon_nam(mdef)); } else { if (rn2(10)) tmp += rn1(10, 6); else { - if (vis && canspotmon(mdef)) + if (g.vis && canspotmon(mdef)) pline_The("poison was deadly..."); tmp = mdef->mhp; } @@ -1333,28 +1324,28 @@ register struct attack *mattk; break; case AD_DRIN: if (g.notonhead || !has_head(pd)) { - if (vis && canspotmon(mdef)) + if (g.vis && canspotmon(mdef)) pline("%s doesn't seem harmed.", Monnam(mdef)); /* Not clear what to do for green slimes */ tmp = 0; break; } if ((mdef->misc_worn_check & W_ARMH) && rn2(8)) { - if (vis && canspotmon(magr) && canseemon(mdef)) { + if (g.vis && canspotmon(magr) && canseemon(mdef)) { Strcpy(buf, s_suffix(Monnam(mdef))); pline("%s helmet blocks %s attack to %s head.", buf, s_suffix(mon_nam(magr)), mhis(mdef)); } break; } - res = eat_brains(magr, mdef, vis, &tmp); + res = eat_brains(magr, mdef, g.vis, &tmp); break; case AD_SLIM: if (cancelled) break; /* physical damage only */ if (!rn2(4) && !slimeproof(pd)) { if (!munslime(mdef, FALSE) && !DEADMONSTER(mdef)) { - if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, vis && canseemon(mdef))) + if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, g.vis && canseemon(mdef))) pd = mdef->data; mdef->mstrategy &= ~STRAT_WAITFORU; res = MM_HIT; @@ -1558,8 +1549,8 @@ int mdead; acid_damage(MON_WEP(magr)); goto assess_dmg; case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ - if (mhit && !mdef->mcan && otmp) { - (void) drain_item(otmp, FALSE); + if (mhit && !mdef->mcan && g.otmp) { + (void) drain_item(g.otmp, FALSE); /* No message */ } break; diff --git a/src/mhitu.c b/src/mhitu.c index 85293d57b..e7d9eb52d 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -22,10 +22,6 @@ STATIC_DCL void FDECL(mswings, (struct monst *, struct obj *)); STATIC_DCL void FDECL(wildmiss, (struct monst *, struct attack *)); STATIC_DCL void FDECL(hitmsg, (struct monst *, struct attack *)); -/* See comment in mhitm.c. If we use this a lot it probably should be */ -/* changed to a parameter to mhitu. */ -static int dieroll; - STATIC_OVL void hitmsg(mtmp, mattk) struct monst *mtmp; @@ -755,7 +751,7 @@ register struct monst *mtmp; tmp += hittmp; mswings(mtmp, mon_currwep); } - if (tmp > (j = dieroll = rnd(20 + i))) + if (tmp > (j = g.mhitu_dieroll = rnd(20 + i))) sum[i] = hitmu(mtmp, mattk); else missmu(mtmp, (tmp == j), mattk); @@ -991,7 +987,7 @@ register struct attack *mattk; if (dmg <= 0) dmg = 1; if (!(otmp->oartifact - && artifact_hit(mtmp, &youmonst, otmp, &dmg, dieroll))) + && artifact_hit(mtmp, &youmonst, otmp, &dmg, g.mhitu_dieroll))) hitmsg(mtmp, mattk); if (!dmg) break; diff --git a/src/mklev.c b/src/mklev.c index 35b0d9378..9eb55f7e0 100644 --- a/src/mklev.c +++ b/src/mklev.c @@ -36,10 +36,8 @@ STATIC_DCL void FDECL(mkinvpos, (XCHAR_P, XCHAR_P, int)); STATIC_DCL void FDECL(mk_knox_portal, (XCHAR_P, XCHAR_P)); #define create_vault() create_room(-1, -1, 2, 2, -1, -1, VAULT, TRUE) -#define init_vault() vault_x = -1 -#define do_vault() (vault_x != -1) -static xchar vault_x, vault_y; -static boolean made_branch; /* used only during level creation */ +#define init_vault() g.vault_x = -1 +#define do_vault() (g.vault_x != -1) /* Args must be (const genericptr) so that qsort will always be happy. */ @@ -229,8 +227,8 @@ makerooms() if (nroom >= (MAXNROFROOMS / 6) && rn2(2) && !tried_vault) { tried_vault = TRUE; if (create_vault()) { - vault_x = rooms[nroom].lx; - vault_y = rooms[nroom].ly; + g.vault_x = rooms[nroom].lx; + g.vault_y = rooms[nroom].ly; rooms[nroom].hx = -1; } } else if (!create_room(-1, -1, -1, -1, -1, -1, OROOM, -1)) @@ -636,7 +634,7 @@ clear_level_structures() xdnstair = ydnstair = xupstair = yupstair = 0; sstairs.sx = sstairs.sy = 0; xdnladder = ydnladder = xupladder = yupladder = 0; - made_branch = FALSE; + g.made_branch = FALSE; clear_regions(); } @@ -731,20 +729,20 @@ makelevel() debugpline0("trying to make a vault..."); w = 1; h = 1; - if (check_room(&vault_x, &w, &vault_y, &h, TRUE)) { + if (check_room(&g.vault_x, &w, &g.vault_y, &h, TRUE)) { fill_vault: - add_room(vault_x, vault_y, vault_x + w, vault_y + h, TRUE, VAULT, + add_room(g.vault_x, g.vault_y, g.vault_x + w, g.vault_y + h, TRUE, VAULT, FALSE); level.flags.has_vault = 1; ++room_threshold; fill_room(&rooms[nroom - 1], FALSE); - mk_knox_portal(vault_x + w, vault_y + h); + mk_knox_portal(g.vault_x + w, g.vault_y + h); if (!level.flags.noteleport && !rn2(3)) makevtele(); } else if (rnd_rect() && create_vault()) { - vault_x = rooms[nroom].lx; - vault_y = rooms[nroom].ly; - if (check_room(&vault_x, &w, &vault_y, &h, TRUE)) + g.vault_x = rooms[nroom].lx; + g.vault_y = rooms[nroom].ly; + if (check_room(&g.vault_x, &w, &g.vault_y, &h, TRUE)) goto fill_vault; else rooms[nroom].hx = -1; @@ -1139,7 +1137,7 @@ xchar x, y; /* location */ * a special level is loaded that specifies an SSTAIR location * as a favored spot for a branch. */ - if (!br || made_branch) + if (!br || g.made_branch) return; if (!x) { /* find random coordinates for branch */ @@ -1179,7 +1177,7 @@ xchar x, y; /* location */ * per level, if we failed once, we're going to fail again on the * next call. */ - made_branch = TRUE; + g.made_branch = TRUE; } STATIC_OVL boolean @@ -1824,7 +1822,6 @@ STATIC_OVL void mk_knox_portal(x, y) xchar x, y; { - extern int n_dgns; /* from dungeon.c */ d_level *source; branch *br; schar u_depth; @@ -1840,7 +1837,7 @@ xchar x, y; } /* Already set or 2/3 chance of deferring until a later level. */ - if (source->dnum < n_dgns || (rn2(3) && !wizard)) + if (source->dnum < g.n_dgns || (rn2(3) && !wizard)) return; if (!(u.uz.dnum == oracle_level.dnum /* in main dungeon */ diff --git a/src/mkmap.c b/src/mkmap.c index df2e37122..b953a3d47 100644 --- a/src/mkmap.c +++ b/src/mkmap.c @@ -21,10 +21,6 @@ STATIC_DCL void FDECL(finish_map, STATIC_DCL void FDECL(remove_room, (unsigned)); void FDECL(mkmap, (lev_init *)); -static char *new_locations; -int min_rx, max_rx, min_ry, max_ry; /* rectangle bounds for regions */ -static int n_loc_filled; - STATIC_OVL void init_map(bg_typ) schar bg_typ; @@ -100,7 +96,7 @@ schar bg_typ, fg_typ; } } -#define new_loc(i, j) *(new_locations + ((j) * (WIDTH + 1)) + (i)) +#define new_loc(i, j) *(g.new_locations + ((j) * (WIDTH + 1)) + (i)) STATIC_OVL void pass_two(bg_typ, fg_typ) @@ -176,10 +172,10 @@ boolean anyroom; sx++; /* compensate for extra decrement */ /* assume sx,sy is valid */ - if (sx < min_rx) - min_rx = sx; - if (sy < min_ry) - min_ry = sy; + if (sx < g.min_rx) + g.min_rx = sx; + if (sy < g.min_ry) + g.min_ry = sy; for (i = sx; i <= WIDTH && levl[i][sy].typ == fg_typ; i++) { levl[i][sy].roomno = rmno; @@ -199,7 +195,7 @@ boolean anyroom; levl[ii][jj].roomno = SHARED; } } - n_loc_filled++; + g.n_loc_filled++; } nx = i; @@ -240,10 +236,10 @@ boolean anyroom; } } - if (nx > max_rx) - max_rx = nx - 1; /* nx is just past valid region */ - if (sy > max_ry) - max_ry = sy; + if (nx > g.max_rx) + g.max_rx = nx - 1; /* nx is just past valid region */ + if (sy > g.max_ry) + g.max_ry = sy; } /* @@ -284,12 +280,12 @@ schar bg_typ, fg_typ; for (i = 2; i <= WIDTH; i++) for (j = 1; j < HEIGHT; j++) { if (levl[i][j].typ == fg_typ && levl[i][j].roomno == NO_ROOM) { - min_rx = max_rx = i; - min_ry = max_ry = j; - n_loc_filled = 0; + g.min_rx = g.max_rx = i; + g.min_ry = g.max_ry = j; + g.n_loc_filled = 0; flood_fill_rm(i, j, nroom + ROOMOFFSET, FALSE, FALSE); - if (n_loc_filled > 3) { - add_room(min_rx, min_ry, max_rx, max_ry, FALSE, OROOM, + if (g.n_loc_filled > 3) { + add_room(g.min_rx, g.min_ry, g.max_rx, g.max_ry, FALSE, OROOM, TRUE); rooms[nroom - 1].irregular = TRUE; if (nroom >= (MAXNROFROOMS * 2)) @@ -299,8 +295,8 @@ schar bg_typ, fg_typ; * it's a tiny hole; erase it from the map to avoid * having the player end up here with no way out. */ - for (sx = min_rx; sx <= max_rx; sx++) - for (sy = min_ry; sy <= max_ry; sy++) + for (sx = g.min_rx; sx <= g.max_rx; sx++) + for (sy = g.min_ry; sy <= g.max_ry; sy++) if ((int) levl[sx][sy].roomno == nroom + ROOMOFFSET) { levl[sx][sy].typ = bg_typ; @@ -460,7 +456,7 @@ lev_init *init_lev; if (lit < 0) lit = (rnd(1 + abs(depth(&u.uz))) < 11 && rn2(77)) ? 1 : 0; - new_locations = (char *) alloc((WIDTH + 1) * HEIGHT); + g.new_locations = (char *) alloc((WIDTH + 1) * HEIGHT); init_map(bg_typ); init_fill(bg_typ, fg_typ); @@ -485,7 +481,7 @@ lev_init *init_lev; level.flags.is_maze_lev = FALSE; level.flags.is_cavernous_lev = TRUE; } - free(new_locations); + free(g.new_locations); } /*mkmap.c*/ diff --git a/src/mkmaze.c b/src/mkmaze.c index 863502baf..efaad38b2 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -7,12 +7,6 @@ #include "sp_lev.h" #include "lev.h" /* save & restore info */ -/* from sp_lev.c, for fixup_special() */ -extern lev_region *lregions; -extern int num_lregions; -/* for preserving the insect legs when wallifying baalz level */ -static lev_region bughack = { {COLNO, ROWNO, 0, 0}, {COLNO, ROWNO, 0, 0} }; - STATIC_DCL int FDECL(iswall, (int, int)); STATIC_DCL int FDECL(iswall_or_stone, (int, int)); STATIC_DCL boolean FDECL(is_solid, (int, int)); @@ -30,6 +24,9 @@ STATIC_DCL void FDECL(migr_booty_item, (int, const char *)); STATIC_DCL void FDECL(migrate_orc, (struct monst *, unsigned long)); STATIC_DCL void NDECL(stolen_booty); +lev_region bughack; /* for preserving the insect legs when wallifying + * baalz level */ + /* adjust a coordinate one step in the specified direction */ #define mz_move(X, Y, dir) \ do { \ @@ -142,8 +139,8 @@ int x1, y1, x2, y2; for (x = x1; x <= x2; x++) for (y = y1; y <= y2; y++) { if (within_bounded_area(x, y, - bughack.inarea.x1, bughack.inarea.y1, - bughack.inarea.x2, bughack.inarea.y2)) + g.bughack.inarea.x1, g.bughack.inarea.y1, + g.bughack.inarea.x2, g.bughack.inarea.y2)) continue; lev = &levl[x][y]; type = lev->typ; @@ -193,8 +190,8 @@ int x1, y1, x2, y2; /* set the locations TRUE if rock or wall or out of bounds */ loc_f = within_bounded_area(x, y, /* for baalz insect */ - bughack.inarea.x1, bughack.inarea.y1, - bughack.inarea.x2, bughack.inarea.y2) + g.bughack.inarea.x1, g.bughack.inarea.y1, + g.bughack.inarea.x2, g.bughack.inarea.y2) ? iswall : iswall_or_stone; locale[0][0] = (*loc_f)(x - 1, y - 1); @@ -394,28 +391,28 @@ baalz_fixup() for (lastx = x = 0; x < COLNO; ++x) if ((levl[x][y].wall_info & W_NONDIGGABLE) != 0) { if (!lastx) - bughack.inarea.x1 = x + 1; + g.bughack.inarea.x1 = x + 1; lastx = x; } - bughack.inarea.x2 = ((lastx > bughack.inarea.x1) ? lastx : x) - 1; + g.bughack.inarea.x2 = ((lastx > g.bughack.inarea.x1) ? lastx : x) - 1; /* find low and high y for to-be-wallified portion of level */ - x = bughack.inarea.x1; + x = g.bughack.inarea.x1; for (lasty = y = 0; y < ROWNO; ++y) if ((levl[x][y].wall_info & W_NONDIGGABLE) != 0) { if (!lasty) - bughack.inarea.y1 = y + 1; + g.bughack.inarea.y1 = y + 1; lasty = y; } - bughack.inarea.y2 = ((lasty > bughack.inarea.y1) ? lasty : y) - 1; + g.bughack.inarea.y2 = ((lasty > g.bughack.inarea.y1) ? lasty : y) - 1; /* two pools mark where special post-wallify fix-ups are needed */ - for (x = bughack.inarea.x1; x <= bughack.inarea.x2; ++x) - for (y = bughack.inarea.y1; y <= bughack.inarea.y2; ++y) + for (x = g.bughack.inarea.x1; x <= g.bughack.inarea.x2; ++x) + for (y = g.bughack.inarea.y1; y <= g.bughack.inarea.y2; ++y) if (levl[x][y].typ == POOL) { levl[x][y].typ = HWALL; - if (bughack.delarea.x1 == COLNO) - bughack.delarea.x1 = x, bughack.delarea.y1 = y; + if (g.bughack.delarea.x1 == COLNO) + g.bughack.delarea.x1 = x, g.bughack.delarea.y1 = y; else - bughack.delarea.x2 = x, bughack.delarea.y2 = y; + g.bughack.delarea.x2 = x, g.bughack.delarea.y2 = y; } else if (levl[x][y].typ == IRONBARS) { /* novelty effect; allowing digging in front of 'eyes' */ levl[x - 1][y].wall_info &= ~W_NONDIGGABLE; @@ -423,15 +420,15 @@ baalz_fixup() levl[x - 2][y].wall_info &= ~W_NONDIGGABLE; } - wallification(max(bughack.inarea.x1 - 2, 1), - max(bughack.inarea.y1 - 2, 0), - min(bughack.inarea.x2 + 2, COLNO - 1), - min(bughack.inarea.y2 + 2, ROWNO - 1)); + wallification(max(g.bughack.inarea.x1 - 2, 1), + max(g.bughack.inarea.y1 - 2, 0), + min(g.bughack.inarea.x2 + 2, COLNO - 1), + min(g.bughack.inarea.y2 + 2, ROWNO - 1)); /* bughack hack for rear-most legs on baalz level; first joint on both top and bottom gets a bogus extra connection to room area, producing unwanted rectangles; change back to separated legs */ - x = bughack.delarea.x1, y = bughack.delarea.y1; + x = g.bughack.delarea.x1, y = g.bughack.delarea.y1; if (isok(x, y) && levl[x][y].typ == TLWALL && isok(x, y + 1) && levl[x][y + 1].typ == TUWALL) { levl[x][y].typ = BRCORNER; @@ -439,7 +436,7 @@ baalz_fixup() if ((mtmp = m_at(x, y)) != 0) /* something at temporary pool... */ (void) rloc(mtmp, FALSE); } - x = bughack.delarea.x2, y = bughack.delarea.y2; + x = g.bughack.delarea.x2, y = g.bughack.delarea.y2; if (isok(x, y) && levl[x][y].typ == TLWALL && isok(x, y - 1) && levl[x][y - 1].typ == TDWALL) { levl[x][y].typ = TRCORNER; @@ -451,37 +448,35 @@ baalz_fixup() /* reset bughack region; set low end to so that within_bounded_region() in fix_wall_spines() will fail most quickly--on its first test--when loading other levels */ - bughack.inarea.x1 = bughack.delarea.x1 = COLNO; - bughack.inarea.y1 = bughack.delarea.y1 = ROWNO; - bughack.inarea.x2 = bughack.delarea.x2 = 0; - bughack.inarea.y2 = bughack.delarea.y2 = 0; + g.bughack.inarea.x1 = g.bughack.delarea.x1 = COLNO; + g.bughack.inarea.y1 = g.bughack.delarea.y1 = ROWNO; + g.bughack.inarea.x2 = g.bughack.delarea.x2 = 0; + g.bughack.inarea.y2 = g.bughack.delarea.y2 = 0; } -static boolean was_waterlevel; /* ugh... this shouldn't be needed */ - /* this is special stuff that the level compiler cannot (yet) handle */ void fixup_special() { - lev_region *r = lregions; + lev_region *r = g.lregions; struct d_level lev; int x, y; struct mkroom *croom; boolean added_branch = FALSE; - if (was_waterlevel) { - was_waterlevel = FALSE; + if (g.was_waterlevel) { + g.was_waterlevel = FALSE; u.uinwater = 0; unsetup_waterlevel(); } if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) { level.flags.hero_memory = 0; - was_waterlevel = TRUE; + g.was_waterlevel = TRUE; /* water level is an odd beast - it has to be set up before calling place_lregions etc. */ setup_waterlevel(); } - for (x = 0; x < num_lregions; x++, r++) { + for (x = 0; x < g.num_lregions; x++, r++) { switch (r->rtype) { case LR_BRANCH: added_branch = TRUE; @@ -618,9 +613,9 @@ fixup_special() stolen_booty(); } - if (lregions) - free((genericptr_t) lregions), lregions = 0; - num_lregions = 0; + if (g.lregions) + free((genericptr_t) g.lregions), g.lregions = 0; + g.num_lregions = 0; } void @@ -1623,7 +1618,7 @@ int fd; } ebubbles = b; b->next = (struct bubble *) 0; - was_waterlevel = TRUE; + g.was_waterlevel = TRUE; } const char * diff --git a/src/options.c b/src/options.c index ca511b665..b5f08cdee 100644 --- a/src/options.c +++ b/src/options.c @@ -599,9 +599,9 @@ reglyph_darkroom() } } if (flags.dark_room && iflags.use_color) - showsyms[S_darkroom] = showsyms[S_room]; + g.showsyms[S_darkroom] = g.showsyms[S_room]; else - showsyms[S_darkroom] = showsyms[S_stone]; + g.showsyms[S_darkroom] = g.showsyms[S_stone]; } /* check whether a user-supplied option string is a proper leading @@ -742,7 +742,7 @@ initoptions_init() /* Set the default monster and object class symbols. */ init_symbols(); for (i = 0; i < WARNCOUNT; i++) - warnsyms[i] = def_warnsyms[i].sym; + g.warnsyms[i] = def_warnsyms[i].sym; iflags.bouldersym = 0; /* for "special achievement" tracking (see obj.h, @@ -771,9 +771,9 @@ initoptions_init() */ /* this detects the IBM-compatible console on most 386 boxes */ if ((opts = nh_getenv("TERM")) && !strncmp(opts, "AT", 2)) { - if (!symset[PRIMARY].name) + if (!g.symset[PRIMARY].name) load_symset("IBMGraphics", PRIMARY); - if (!symset[ROGUESET].name) + if (!g.symset[ROGUESET].name) load_symset("RogueIBM", ROGUESET); switch_symbols(TRUE); #ifdef TEXTCOLOR @@ -788,7 +788,7 @@ initoptions_init() /* [could also check "xterm" which emulates vtXXX by default] */ && !strncmpi(opts, "vt", 2) && AS && AE && index(AS, '\016') && index(AE, '\017')) { - if (!symset[PRIMARY].name) + if (!g.symset[PRIMARY].name) load_symset("DECGraphics", PRIMARY); switch_symbols(TRUE); } @@ -797,10 +797,10 @@ initoptions_init() #if defined(MSDOS) || defined(WIN32) /* Use IBM defaults. Can be overridden via config file */ - if (!symset[PRIMARY].name) { + if (!g.symset[PRIMARY].name) { load_symset("IBMGraphics_2", PRIMARY); } - if (!symset[ROGUESET].name) { + if (!g.symset[ROGUESET].name) { load_symset("RogueEpyx", ROGUESET); } #endif @@ -1157,7 +1157,7 @@ register uchar *graph_chars; for (i = 0; i < WARNCOUNT; i++) if (graph_chars[i]) - warnsyms[i] = graph_chars[i]; + g.warnsyms[i] = graph_chars[i]; } STATIC_OVL int @@ -2288,7 +2288,7 @@ boolean tinitial, tfrom_file; bad_negation(fullname, FALSE); return FALSE; } else if ((op = string_for_opt(opts, FALSE)) != 0) { - symset[ROGUESET].name = dupstr(op); + g.symset[ROGUESET].name = dupstr(op); if (!read_sym_file(ROGUESET)) { clear_symsetentry(ROGUESET, TRUE); config_error_add( @@ -2313,7 +2313,7 @@ boolean tinitial, tfrom_file; bad_negation(fullname, FALSE); return FALSE; } else if ((op = string_for_opt(opts, FALSE)) != 0) { - symset[PRIMARY].name = dupstr(op); + g.symset[PRIMARY].name = dupstr(op); if (!read_sym_file(PRIMARY)) { clear_symsetentry(PRIMARY, TRUE); config_error_add( @@ -2321,7 +2321,7 @@ boolean tinitial, tfrom_file; op, SYMBOLS); return FALSE; } else { - switch_symbols(symset[PRIMARY].name != (char *) 0); + switch_symbols(g.symset[PRIMARY].name != (char *) 0); need_redraw = TRUE; } } else @@ -3779,10 +3779,10 @@ boolean tinitial, tfrom_file; complain_about_duplicate(opts, 1); if (!negated) { /* There is no rogue level DECgraphics-specific set */ - if (symset[PRIMARY].name) { + if (g.symset[PRIMARY].name) { badflag = TRUE; } else { - symset[PRIMARY].name = dupstr(fullname); + g.symset[PRIMARY].name = dupstr(fullname); if (!read_sym_file(PRIMARY)) { badflag = TRUE; clear_symsetentry(PRIMARY, TRUE); @@ -3812,12 +3812,12 @@ boolean tinitial, tfrom_file; complain_about_duplicate(opts, 1); if (!negated) { for (i = 0; i < NUM_GRAPHICS; ++i) { - if (symset[i].name) { + if (g.symset[i].name) { badflag = TRUE; } else { if (i == ROGUESET) sym_name = "RogueIBM"; - symset[i].name = dupstr(sym_name); + g.symset[i].name = dupstr(sym_name); if (!read_sym_file(i)) { badflag = TRUE; clear_symsetentry(i, TRUE); @@ -3850,10 +3850,10 @@ boolean tinitial, tfrom_file; if (duplicate) complain_about_duplicate(opts, 1); if (!negated) { - if (symset[PRIMARY].name) { + if (g.symset[PRIMARY].name) { badflag = TRUE; } else { - symset[PRIMARY].name = dupstr(fullname); + g.symset[PRIMARY].name = dupstr(fullname); if (!read_sym_file(PRIMARY)) { badflag = TRUE; clear_symsetentry(PRIMARY, TRUE); @@ -5211,8 +5211,8 @@ boolean setinitial, setfromfile; which_set = rogueflag ? ROGUESET : PRIMARY; /* clear symset[].name as a flag to read_sym_file() to build list */ - symset_name = symset[which_set].name; - symset[which_set].name = (char *) 0; + symset_name = g.symset[which_set].name; + g.symset[which_set].name = (char *) 0; symset_list = (struct symsetentry *) 0; res = read_sym_file(which_set); @@ -5294,7 +5294,7 @@ boolean setinitial, setfromfile; clear_symsetentry(which_set, TRUE); /* transfer only the name of the symbol set */ - symset[which_set].name = dupstr(sl->name); + g.symset[which_set].name = dupstr(sl->name); ready_to_switch = TRUE; break; } @@ -5338,8 +5338,8 @@ boolean setinitial, setfromfile; if (nothing_to_do) return TRUE; - if (!symset[which_set].name && symset_name) - symset[which_set].name = symset_name; /* not dupstr() here */ + if (!g.symset[which_set].name && symset_name) + g.symset[which_set].name = symset_name; /* not dupstr() here */ /* Set default symbols and clear the handling value */ if (rogueflag) @@ -5347,7 +5347,7 @@ boolean setinitial, setfromfile; else init_l_symbols(); - if (symset[which_set].name) { + if (g.symset[which_set].name) { if (read_sym_file(which_set)) { ready_to_switch = TRUE; } else { @@ -5426,7 +5426,7 @@ char *buf; Sprintf(buf, "%c", iflags.bouldersym ? iflags.bouldersym - : showsyms[(int) objects[BOULDER].oc_class + SYM_OFF_O]); + : g.showsyms[(int) objects[BOULDER].oc_class + SYM_OFF_O]); #endif else if (!strcmp(optname, "catname")) Sprintf(buf, "%s", catname[0] ? catname : none); @@ -5611,8 +5611,8 @@ char *buf; Sprintf(buf, "%s", rolestring(flags.initrace, races, noun)); } else if (!strcmp(optname, "roguesymset")) { Sprintf(buf, "%s", - symset[ROGUESET].name ? symset[ROGUESET].name : "default"); - if (currentgraphics == ROGUESET && symset[ROGUESET].name) + g.symset[ROGUESET].name ? g.symset[ROGUESET].name : "default"); + if (g.currentgraphics == ROGUESET && g.symset[ROGUESET].name) Strcat(buf, ", active"); } else if (!strcmp(optname, "role")) { Sprintf(buf, "%s", rolestring(flags.initrole, roles, name.m)); @@ -5671,8 +5671,8 @@ char *buf; FEATURE_NOTICE_VER_MIN, FEATURE_NOTICE_VER_PATCH); } else if (!strcmp(optname, "symset")) { Sprintf(buf, "%s", - symset[PRIMARY].name ? symset[PRIMARY].name : "default"); - if (currentgraphics == PRIMARY && symset[PRIMARY].name) + g.symset[PRIMARY].name ? g.symset[PRIMARY].name : "default"); + if (g.currentgraphics == PRIMARY && g.symset[PRIMARY].name) Strcat(buf, ", active"); #ifdef CURSES_GRAPHICS } else if (!strcmp(optname, "term_cols")) { @@ -5903,9 +5903,9 @@ int which_set; { clear_symsetentry(which_set, TRUE); - if (symset[which_set].name) - free((genericptr_t) symset[which_set].name); - symset[which_set].name = dupstr(s); + if (g.symset[which_set].name) + free((genericptr_t) g.symset[which_set].name); + g.symset[which_set].name = dupstr(s); if (read_sym_file(which_set)) { switch_symbols(TRUE); diff --git a/src/pager.c b/src/pager.c index 22df977e4..219a92878 100644 --- a/src/pager.c +++ b/src/pager.c @@ -44,7 +44,7 @@ int c; int i; for (i = S_sw_tl; i <= S_sw_br; i++) - if ((int) showsyms[i] == c) + if ((int) g.showsyms[i] == c) return TRUE; return FALSE; } @@ -851,7 +851,7 @@ struct permonst **for_supplement; /* Check for monsters */ if (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0) { for (i = 0; i < MAXMCLASSES; i++) { - if (sym == (looked ? showsyms[i + SYM_OFF_M] : def_monsyms[i].sym) + if (sym == (looked ? g.showsyms[i + SYM_OFF_M] : def_monsyms[i].sym) && def_monsyms[i].explain) { need_to_look = TRUE; if (!found) { @@ -867,7 +867,7 @@ struct permonst **for_supplement; /* handle '@' as a special case if it refers to you and you're playing a character which isn't normally displayed by that symbol; firstmatch is assumed to already be set for '@' */ - if ((looked ? (sym == showsyms[S_HUMAN + SYM_OFF_M] + if ((looked ? (sym == g.showsyms[S_HUMAN + SYM_OFF_M] && cc.x == u.ux && cc.y == u.uy) : (sym == def_monsyms[S_HUMAN].sym && !flags.showrace)) && !(Race_if(PM_HUMAN) || Race_if(PM_ELF)) && !Upolyd) @@ -877,7 +877,7 @@ struct permonst **for_supplement; /* Now check for objects */ if (!iflags.terrainmode || (iflags.terrainmode & TER_OBJ) != 0) { for (i = 1; i < MAXOCLASSES; i++) { - if (sym == (looked ? showsyms[i + SYM_OFF_O] + if (sym == (looked ? g.showsyms[i + SYM_OFF_O] : def_oc_syms[i].sym) || (looked && i == ROCK_CLASS && glyph_is_statue(glyph))) { need_to_look = TRUE; @@ -913,7 +913,7 @@ struct permonst **for_supplement; } /* Now check for graphics symbols */ - alt_i = (sym == (looked ? showsyms[0] : defsyms[0].sym)) ? 0 : (2 + 1); + alt_i = (sym == (looked ? g.showsyms[0] : defsyms[0].sym)) ? 0 : (2 + 1); for (hit_trap = FALSE, i = 0; i < MAXPCHARS; i++) { /* when sym is the default background character, we process i == 0 three times: unexplored, stone, dark part of a room */ @@ -929,7 +929,7 @@ struct permonst **for_supplement; x_str = "land"; /* replace "dark part of a room" */ /* alt_i is now 3 or more and no longer of interest */ } - if (sym == (looked ? showsyms[i] : defsyms[i].sym) && *x_str) { + if (sym == (looked ? g.showsyms[i] : defsyms[i].sym) && *x_str) { /* avoid "an unexplored", "an stone", "an air", "a water", "a floor of a room", "a dark part of a room"; article==2 => "the", 1 => "an", 0 => (none) */ @@ -972,7 +972,7 @@ struct permonst **for_supplement; /* Now check for warning symbols */ for (i = 1; i < WARNCOUNT; i++) { x_str = def_warnsyms[i].explanation; - if (sym == (looked ? warnsyms[i] : def_warnsyms[i].sym)) { + if (sym == (looked ? g.warnsyms[i] : def_warnsyms[i].sym)) { if (!found) { Sprintf(out_str, "%s%s", prefix, def_warnsyms[i].explanation); *firstmatch = def_warnsyms[i].explanation; diff --git a/src/questpgr.c b/src/questpgr.c index ede98b1bc..e3ec48dfc 100644 --- a/src/questpgr.c +++ b/src/questpgr.c @@ -15,9 +15,6 @@ #include "wintty.h" #endif -/* from sp_lev.c, for deliver_splev_message() */ -extern char *lev_message; - static void NDECL(dump_qtlist); static void FDECL(Fread, (genericptr_t, int, int, dlb *)); STATIC_DCL struct qtmsg *FDECL(construct_qtlist, (long)); @@ -676,10 +673,10 @@ deliver_splev_message() char *str, *nl, in_line[BUFSZ], out_line[BUFSZ]; /* there's no provision for delivering via window instead of pline */ - if (lev_message) { + if (g.lev_message) { /* lev_message can span multiple lines using embedded newline chars; any segments too long to fit within in_line[] will be truncated */ - for (str = lev_message; *str; str = nl + 1) { + for (str = g.lev_message; *str; str = nl + 1) { /* copying will stop at newline if one is present */ copynchars(in_line, str, (int) (sizeof in_line) - 1); @@ -692,8 +689,8 @@ deliver_splev_message() break; /* done if no newline */ } - free((genericptr_t) lev_message); - lev_message = 0; + free((genericptr_t) g.lev_message); + g.lev_message = NULL; } } diff --git a/src/sp_lev.c b/src/sp_lev.c index 6ebf7e9df..59e76bac8 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -18,6 +18,8 @@ #pragma warning(disable : 4244) #endif +lev_region *lregions; + typedef void FDECL((*select_iter_func), (int, int, genericptr)); extern void FDECL(mkmap, (lev_init *)); @@ -189,8 +191,6 @@ STATIC_DCL boolean FDECL(sp_level_coder, (sp_lev *)); extern struct engr *head_engr; -extern int min_rx, max_rx, min_ry, max_ry; /* from mkmap.c */ - /* positions touched by level elements explicitly defined in the des-file */ static char SpLev_Map[COLNO][ROWNO]; @@ -198,10 +198,6 @@ static aligntyp ralign[3] = { AM_CHAOTIC, AM_NEUTRAL, AM_LAWFUL }; static NEARDATA xchar xstart, ystart; static NEARDATA char xsize, ysize; -char *lev_message = 0; -lev_region *lregions = 0; -int num_lregions = 0; - static boolean splev_init_present = FALSE; static boolean icedpools = FALSE; static int mines_prize_count = 0, soko_prize_count = 0; /* achievements */ @@ -2966,19 +2962,19 @@ struct sp_coder *coder; if (!msg) return; - old_n = lev_message ? (strlen(lev_message) + 1) : 0; + old_n = g.lev_message ? (strlen(g.lev_message) + 1) : 0; n = strlen(msg); levmsg = (char *) alloc(old_n + n + 1); if (old_n) levmsg[old_n - 1] = '\n'; - if (lev_message) - (void) memcpy((genericptr_t) levmsg, (genericptr_t) lev_message, + if (g.lev_message) + (void) memcpy((genericptr_t) levmsg, (genericptr_t) g.lev_message, old_n - 1); (void) memcpy((genericptr_t) &levmsg[old_n], msg, n); levmsg[old_n + n] = '\0'; - Free(lev_message); - lev_message = levmsg; + Free(g.lev_message); + g.lev_message = levmsg; opvar_free(op); } @@ -4566,21 +4562,21 @@ struct sp_coder *coder; get_location(&tmplregion->delarea.x2, &tmplregion->delarea.y2, ANY_LOC, (struct mkroom *) 0); } - if (num_lregions) { + if (g.num_lregions) { /* realloc the lregion space to add the new one */ lev_region *newl = (lev_region *) alloc( - sizeof(lev_region) * (unsigned) (1 + num_lregions)); + sizeof(lev_region) * (unsigned) (1 + g.num_lregions)); - (void) memcpy((genericptr_t) (newl), (genericptr_t) lregions, - sizeof(lev_region) * num_lregions); - Free(lregions); - num_lregions++; - lregions = newl; + (void) memcpy((genericptr_t) (newl), (genericptr_t) g.lregions, + sizeof(lev_region) * g.num_lregions); + Free(g.lregions); + g.num_lregions++; + g.lregions = newl; } else { - num_lregions = 1; - lregions = (lev_region *) alloc(sizeof(lev_region)); + g.num_lregions = 1; + g.lregions = (lev_region *) alloc(sizeof(lev_region)); } - (void) memcpy(&lregions[num_lregions - 1], tmplregion, + (void) memcpy(&g.lregions[g.num_lregions - 1], tmplregion, sizeof(lev_region)); free(tmplregion); @@ -4669,11 +4665,12 @@ struct sp_coder *coder; troom->needjoining = joined; if (irregular) { - min_rx = max_rx = dx1; - min_ry = max_ry = dy1; + g.min_rx = g.max_rx = dx1; + g.min_ry = g.max_ry = dy1; smeq[nroom] = nroom; flood_fill_rm(dx1, dy1, nroom + ROOMOFFSET, OV_i(rlit), TRUE); - add_room(min_rx, min_ry, max_rx, max_ry, FALSE, OV_i(rtype), TRUE); + add_room(g.min_rx, g.min_ry, g.max_rx, g.max_ry, FALSE, OV_i(rtype), + TRUE); troom->rlit = OV_i(rlit); troom->irregular = TRUE; } else { diff --git a/sys/winnt/nttty.c b/sys/winnt/nttty.c index b71133af2..47d1af63f 100644 --- a/sys/winnt/nttty.c +++ b/sys/winnt/nttty.c @@ -1583,8 +1583,8 @@ check_font_widths() boolean used[256]; memset(used, 0, sizeof(used)); for (int i = 0; i < SYM_MAX; i++) { - used[l_syms[i]] = TRUE; - used[r_syms[i]] = TRUE; + used[g.l_syms[i]] = TRUE; + used[g.r_syms[i]] = TRUE; } int wcUsedCount = 0; diff --git a/win/curses/cursinit.c b/win/curses/cursinit.c index 04adbb853..44edaa927 100644 --- a/win/curses/cursinit.c +++ b/win/curses/cursinit.c @@ -791,7 +791,7 @@ curses_init_options() /* Make sure that DECgraphics is not set to true via the config file, as this will cause display issues. We can't disable it in options.c in case the game is compiled with both tty and curses. */ - if (!symset[PRIMARY].name || !strcmpi(symset[PRIMARY].name, "DECgraphics")) { + if (!g.symset[PRIMARY].name || !strcmpi(g.symset[PRIMARY].name, "DECgraphics")) { load_symset("curses",PRIMARY); load_symset("default",ROGUESET); } diff --git a/win/curses/cursmain.c b/win/curses/cursmain.c index f2ab82542..7721d6421 100644 --- a/win/curses/cursmain.c +++ b/win/curses/cursmain.c @@ -590,7 +590,7 @@ curses_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph, int bkglyph) if ((special & MG_DETECT) && iflags.use_inverse) { attr = A_REVERSE; } - if (!symset[PRIMARY].name || !strcmpi(symset[PRIMARY].name, "curses")) { + if (!g.symset[PRIMARY].name || !strcmpi(g.symset[PRIMARY].name, "curses")) { ch = curses_convert_glyph(ch, glyph); } if (wid == NHW_MAP) { diff --git a/win/curses/cursmisc.c b/win/curses/cursmisc.c index 0c47d775d..8d942630b 100644 --- a/win/curses/cursmisc.c +++ b/win/curses/cursmisc.c @@ -454,7 +454,7 @@ curses_convert_glyph(int ch, int glyph) /* If user selected a custom character for this object, don't override this. */ - if (((glyph_is_cmap(glyph)) && (ch != showsyms[symbol]))) { + if (((glyph_is_cmap(glyph)) && (ch != g.showsyms[symbol]))) { return ch; } From 1d70c4a1bf76268cf4a00228c4c1695634fb8c8d Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 24 Nov 2018 17:59:16 -0800 Subject: [PATCH 06/11] More globals moved to instance_globals. --- include/botl.h | 31 ++++- include/decl.h | 18 +++ include/hack.h | 1 + src/allmain.c | 2 +- src/apply.c | 42 +++---- src/artifact.c | 8 +- src/botl.c | 324 ++++++++++++++++++++++--------------------------- src/decl.c | 11 ++ src/mkmaze.c | 3 - src/mon.c | 18 ++- src/sp_lev.c | 2 - 11 files changed, 233 insertions(+), 227 deletions(-) diff --git a/include/botl.h b/include/botl.h index 6c3ddb8c6..df9d1a97b 100644 --- a/include/botl.h +++ b/include/botl.h @@ -96,7 +96,36 @@ enum hlattribs { HL_UNDEF = 0x00, HL_ULINE = 0x08, HL_BLINK = 0x10, HL_DIM = 0x20 }; -/* #endif STATUS_HILITES */ + +#ifdef STATUS_HILITES +struct hilite_s { + enum statusfields fld; + boolean set; + unsigned anytype; + anything value; + int behavior; + char textmatch[QBUFSZ]; + enum relationships rel; + int coloridx; + struct hilite_s *next; +}; +#endif + +struct istat_s { + const char *fldname; + const char *fldfmt; + long time; /* moves when this field hilite times out */ + boolean chg; /* need to recalc time? */ + unsigned anytype; + anything a; + char *val; + int valwidth; + enum statusfields idxmax; + enum statusfields fld; +#ifdef STATUS_HILITES + struct hilite_s *thresholds; +#endif +}; extern const char *status_fieldnames[]; /* in botl.c */ diff --git a/include/decl.h b/include/decl.h index beeaafa5c..a23c7088b 100644 --- a/include/decl.h +++ b/include/decl.h @@ -545,6 +545,13 @@ struct xlock_s { boolean magic_key; }; +struct trapinfo { + struct obj *tobj; + xchar tx, ty; + int time_needed; + boolean force_bungle; +}; + /* 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. @@ -559,6 +566,7 @@ struct instance_globals { int jumping_is_magic; /* current jump result of magic */ int polearm_range_min; int polearm_range_max; + struct trapinfo trapinfo; /* artifcat.c */ int spec_dbon_applies; /* coordinate effects from spec_dbon() with @@ -567,9 +575,16 @@ struct instance_globals { boolean artiexist[1 + NROFARTIFACTS + 1]; /* and a discovery list for them (no dummy first entry here) */ xchar artidisco[NROFARTIFACTS]; + int mkot_trap_warn_count; /* botl.c */ int mrank_sz; /* loaded by max_rank_sz */ + struct istat_s blstats[2][MAXBLSTATS]; + boolean blinit; + boolean update_all; + boolean valset[MAXBLSTATS]; + long bl_hilite_moves; + unsigned long cond_hilites[BL_ATTCLR_MAX]; /* cmd.c */ struct cmd Cmd; /* flag.h */ @@ -690,6 +705,9 @@ struct instance_globals { * baalz level */ boolean was_waterlevel; /* ugh... this shouldn't be needed */ + /* mon.c */ + boolean vamp_rise_msg; + boolean disintegested; /* muse.c */ boolean m_using; /* kludge to use mondided instead of killed */ diff --git a/include/hack.h b/include/hack.h index 46c104cf8..c82334a91 100644 --- a/include/hack.h +++ b/include/hack.h @@ -197,6 +197,7 @@ typedef struct { #include "wintype.h" #include "context.h" #include "rm.h" +#include "botl.h" /* Symbol offsets */ #define SYM_OFF_P (0) diff --git a/src/allmain.c b/src/allmain.c index 891dbaafa..e25d8b849 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -748,7 +748,7 @@ const char *msg; * */ -static struct early_opt earlyopts[] = { +static const struct early_opt earlyopts[] = { {ARG_DEBUG, "debug", 5, TRUE}, {ARG_VERSION, "version", 4, TRUE}, #ifdef WIN32 diff --git a/src/apply.c b/src/apply.c index 406a9d2ba..2107b6704 100644 --- a/src/apply.c +++ b/src/apply.c @@ -2437,18 +2437,11 @@ struct obj *tstone; return; } -static struct trapinfo { - struct obj *tobj; - xchar tx, ty; - int time_needed; - boolean force_bungle; -} trapinfo; - void reset_trapset() { - trapinfo.tobj = 0; - trapinfo.force_bungle = 0; + g.trapinfo.tobj = 0; + g.trapinfo.force_bungle = 0; } /* Place a landmine/bear trap. Helge Hafting */ @@ -2495,22 +2488,23 @@ struct obj *otmp; return; } ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP; - if (otmp == trapinfo.tobj && u.ux == trapinfo.tx && u.uy == trapinfo.ty) { + if (otmp == g.trapinfo.tobj && u.ux == g.trapinfo.tx + && u.uy == g.trapinfo.ty) { You("resume setting %s%s.", shk_your(buf, otmp), defsyms[trap_to_defsym(what_trap(ttyp))].explanation); set_occupation(set_trap, occutext, 0); return; } - trapinfo.tobj = otmp; - trapinfo.tx = u.ux, trapinfo.ty = u.uy; + g.trapinfo.tobj = otmp; + g.trapinfo.tx = u.ux, g.trapinfo.ty = u.uy; tmp = ACURR(A_DEX); - trapinfo.time_needed = + g.trapinfo.time_needed = (tmp > 17) ? 2 : (tmp > 12) ? 3 : (tmp > 7) ? 4 : 5; if (Blind) - trapinfo.time_needed *= 2; + g.trapinfo.time_needed *= 2; tmp = ACURR(A_STR); if (ttyp == BEAR_TRAP && tmp < 18) - trapinfo.time_needed += (tmp > 12) ? 1 : (tmp > 7) ? 2 : 4; + g.trapinfo.time_needed += (tmp > 12) ? 1 : (tmp > 7) ? 2 : 4; /*[fumbling and/or confusion and/or cursed object check(s) should be incorporated here instead of in set_trap]*/ if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) { @@ -2527,8 +2521,8 @@ struct obj *otmp; if (chance) { switch (ttyp) { case LANDMINE: /* set it off */ - trapinfo.time_needed = 0; - trapinfo.force_bungle = TRUE; + g.trapinfo.time_needed = 0; + g.trapinfo.force_bungle = TRUE; break; case BEAR_TRAP: /* drop it without arming it */ reset_trapset(); @@ -2554,18 +2548,18 @@ STATIC_PTR int set_trap() { - struct obj *otmp = trapinfo.tobj; + struct obj *otmp = g.trapinfo.tobj; struct trap *ttmp; int ttyp; - if (!otmp || !carried(otmp) || u.ux != trapinfo.tx - || u.uy != trapinfo.ty) { + if (!otmp || !carried(otmp) || u.ux != g.trapinfo.tx + || u.uy != g.trapinfo.ty) { /* ?? */ reset_trapset(); return 0; } - if (--trapinfo.time_needed > 0) + if (--g.trapinfo.time_needed > 0) return 1; /* still busy */ ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP; @@ -2576,13 +2570,13 @@ set_trap() if (*in_rooms(u.ux, u.uy, SHOPBASE)) { add_damage(u.ux, u.uy, 0L); /* schedule removal */ } - if (!trapinfo.force_bungle) + if (!g.trapinfo.force_bungle) You("finish arming %s.", the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation)); if (((otmp->cursed || Fumbling) && (rnl(10) > 5)) - || trapinfo.force_bungle) + || g.trapinfo.force_bungle) dotrap(ttmp, - (unsigned) (trapinfo.force_bungle ? FORCEBUNGLE : 0)); + (unsigned) (g.trapinfo.force_bungle ? FORCEBUNGLE : 0)); } else { /* this shouldn't happen */ Your("trap setting attempt fails."); diff --git a/src/artifact.c b/src/artifact.c index 465d6a387..ff13c0e7c 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -2088,8 +2088,6 @@ int dropflag; /* 0==don't drop, 1==drop all, 2==drop weapon */ clear_bypasses(); /* reset upon final exit */ } -static int mkot_trap_warn_count = 0; - STATIC_OVL int count_surround_traps(x, y) int x, y; @@ -2147,13 +2145,13 @@ mkot_trap_warn() if (!uarmg && uwep && uwep->oartifact == ART_MASTER_KEY_OF_THIEVERY) { int idx, ntraps = count_surround_traps(u.ux, u.uy); - if (ntraps != mkot_trap_warn_count) { + if (ntraps != g.mkot_trap_warn_count) { idx = min(ntraps, SIZE(heat) - 1); pline_The("Key feels %s%c", heat[idx], (ntraps > 3) ? '!' : '.'); } - mkot_trap_warn_count = ntraps; + g.mkot_trap_warn_count = ntraps; } else - mkot_trap_warn_count = 0; + g.mkot_trap_warn_count = 0; } /* Master Key is magic key if its bless/curse state meets our criteria: diff --git a/src/botl.c b/src/botl.c index 4ff49358f..698bf8bd1 100644 --- a/src/botl.c +++ b/src/botl.c @@ -399,41 +399,12 @@ char *buf; /* structure that tracks the status details in the core */ #ifdef STATUS_HILITES -struct hilite_s { - enum statusfields fld; - boolean set; - unsigned anytype; - anything value; - int behavior; - char textmatch[QBUFSZ]; - enum relationships rel; - int coloridx; - struct hilite_s *next; -}; - struct condmap { const char *id; unsigned long bitmask; }; #endif /* STATUS_HILITES */ -struct istat_s { - const char *fldname; - const char *fldfmt; - long time; /* moves when this field hilite times out */ - boolean chg; /* need to recalc time? */ - unsigned anytype; - anything a; - char *val; - int valwidth; - enum statusfields idxmax; - enum statusfields fld; -#ifdef STATUS_HILITES - struct hilite_s *thresholds; -#endif -}; - - STATIC_DCL void NDECL(init_blstats); STATIC_DCL char *FDECL(anything_to_s, (char *, anything *, int)); STATIC_OVL int FDECL(percentage, (struct istat_s *, struct istat_s *)); @@ -469,7 +440,7 @@ STATIC_DCL int FDECL(status_hilite_menu_choose_behavior, (int)); STATIC_DCL int FDECL(status_hilite_menu_choose_updownboth, (int, const char *, BOOLEAN_P, BOOLEAN_P)); STATIC_DCL boolean FDECL(status_hilite_menu_add, (int)); -#define has_hilite(i) (blstats[0][(i)].thresholds) +#define has_hilite(i) (g.blstats[0][(i)].thresholds) #endif #define INIT_BLSTAT(name, fmtstr, anytyp, wid, fld) \ @@ -510,12 +481,6 @@ STATIC_DCL struct istat_s initblstats[MAXBLSTATS] = { #undef INIT_BLSTATP #undef INIT_BLSTAT -struct istat_s blstats[2][MAXBLSTATS]; -static boolean blinit = FALSE, update_all = FALSE; -static boolean valset[MAXBLSTATS]; -unsigned long blcolormasks[CLR_MAX]; -static long bl_hilite_moves = 0L; - /* we don't put this next declaration in #ifdef STATUS_HILITES. * In the absence of STATUS_HILITES, each array * element will be 0 however, and quite meaningless, @@ -523,7 +488,6 @@ static long bl_hilite_moves = 0L; * the final argument of status_update, with or * without STATUS_HILITES. */ -unsigned long cond_hilites[BL_ATTCLR_MAX]; void bot_via_windowport() @@ -533,14 +497,14 @@ bot_via_windowport() static int i, idx = 0, idx_p, cap; long money; - if (!blinit) + if (!g.blinit) panic("bot before init."); idx_p = idx; idx = 1 - idx; /* 0 -> 1, 1 -> 0 */ /* clear the "value set" indicators */ - (void) memset((genericptr_t) valset, 0, MAXBLSTATS * sizeof (boolean)); + (void) memset((genericptr_t) g.valset, 0, MAXBLSTATS * sizeof (boolean)); /* * Note: min(x,9999) - we enforce the same maximum on hp, maxhp, @@ -561,30 +525,30 @@ bot_via_windowport() nb[i] = highc(nb[i]); } else Strcpy(nb = eos(nb), rank()); - Sprintf(blstats[idx][BL_TITLE].val, "%-29s", buf); - valset[BL_TITLE] = TRUE; /* indicate val already set */ + Sprintf(g.blstats[idx][BL_TITLE].val, "%-29s", buf); + g.valset[BL_TITLE] = TRUE; /* indicate val already set */ /* Strength */ - blstats[idx][BL_STR].a.a_int = ACURR(A_STR); - Strcpy(blstats[idx][BL_STR].val, get_strength_str()); - valset[BL_STR] = TRUE; /* indicate val already set */ + g.blstats[idx][BL_STR].a.a_int = ACURR(A_STR); + Strcpy(g.blstats[idx][BL_STR].val, get_strength_str()); + g.valset[BL_STR] = TRUE; /* indicate val already set */ /* Dexterity, constitution, intelligence, wisdom, charisma. */ - blstats[idx][BL_DX].a.a_int = ACURR(A_DEX); - blstats[idx][BL_CO].a.a_int = ACURR(A_CON); - blstats[idx][BL_IN].a.a_int = ACURR(A_INT); - blstats[idx][BL_WI].a.a_int = ACURR(A_WIS); - blstats[idx][BL_CH].a.a_int = ACURR(A_CHA); + g.blstats[idx][BL_DX].a.a_int = ACURR(A_DEX); + g.blstats[idx][BL_CO].a.a_int = ACURR(A_CON); + g.blstats[idx][BL_IN].a.a_int = ACURR(A_INT); + g.blstats[idx][BL_WI].a.a_int = ACURR(A_WIS); + g.blstats[idx][BL_CH].a.a_int = ACURR(A_CHA); /* Alignment */ - Strcpy(blstats[idx][BL_ALIGN].val, (u.ualign.type == A_CHAOTIC) + Strcpy(g.blstats[idx][BL_ALIGN].val, (u.ualign.type == A_CHAOTIC) ? "Chaotic" : (u.ualign.type == A_NEUTRAL) ? "Neutral" : "Lawful"); /* Score */ - blstats[idx][BL_SCORE].a.a_long = + g.blstats[idx][BL_SCORE].a.a_long = #ifdef SCORE_ON_BOTL flags.showscore ? botl_score() : #endif @@ -594,18 +558,18 @@ bot_via_windowport() i = Upolyd ? u.mh : u.uhp; if (i < 0) i = 0; - blstats[idx][BL_HP].a.a_int = min(i, 9999); + g.blstats[idx][BL_HP].a.a_int = min(i, 9999); i = Upolyd ? u.mhmax : u.uhpmax; - blstats[idx][BL_HPMAX].a.a_int = min(i, 9999); + g.blstats[idx][BL_HPMAX].a.a_int = min(i, 9999); /* Dungeon level. */ - (void) describe_level(blstats[idx][BL_LEVELDESC].val); - valset[BL_LEVELDESC] = TRUE; /* indicate val already set */ + (void) describe_level(g.blstats[idx][BL_LEVELDESC].val); + g.valset[BL_LEVELDESC] = TRUE; /* indicate val already set */ /* Gold */ if ((money = money_cnt(invent)) < 0L) money = 0L; /* ought to issue impossible() and then discard gold */ - blstats[idx][BL_GOLD].a.a_long = min(money, 999999L); + g.blstats[idx][BL_GOLD].a.a_long = min(money, 999999L); /* * The tty port needs to display the current symbol for gold * as a field header, so to accommodate that we pass gold with @@ -621,78 +585,78 @@ bot_via_windowport() * The currency prefix is encoded as ten character \GXXXXNNNN * sequence. */ - Sprintf(blstats[idx][BL_GOLD].val, "%s:%ld", + Sprintf(g.blstats[idx][BL_GOLD].val, "%s:%ld", encglyph(objnum_to_glyph(GOLD_PIECE)), - blstats[idx][BL_GOLD].a.a_long); - valset[BL_GOLD] = TRUE; /* indicate val already set */ + g.blstats[idx][BL_GOLD].a.a_long); + g.valset[BL_GOLD] = TRUE; /* indicate val already set */ /* Power (magical energy) */ - blstats[idx][BL_ENE].a.a_int = min(u.uen, 9999); - blstats[idx][BL_ENEMAX].a.a_int = min(u.uenmax, 9999); + g.blstats[idx][BL_ENE].a.a_int = min(u.uen, 9999); + g.blstats[idx][BL_ENEMAX].a.a_int = min(u.uenmax, 9999); /* Armor class */ - blstats[idx][BL_AC].a.a_int = u.uac; + g.blstats[idx][BL_AC].a.a_int = u.uac; /* Monster level (if Upolyd) */ - blstats[idx][BL_HD].a.a_int = Upolyd ? (int) mons[u.umonnum].mlevel : 0; + g.blstats[idx][BL_HD].a.a_int = Upolyd ? (int) mons[u.umonnum].mlevel : 0; /* Experience */ - blstats[idx][BL_XP].a.a_int = u.ulevel; - blstats[idx][BL_EXP].a.a_long = u.uexp; + g.blstats[idx][BL_XP].a.a_int = u.ulevel; + g.blstats[idx][BL_EXP].a.a_long = u.uexp; /* Time (moves) */ - blstats[idx][BL_TIME].a.a_long = moves; + g.blstats[idx][BL_TIME].a.a_long = moves; /* Hunger */ /* note: u.uhs is unsigned, and 3.6.1's STATUS_HILITE defined BL_HUNGER to be ANY_UINT, but that was the only non-int/non-long numeric field so it's far simpler to treat it as plain int and not need ANY_UINT handling at all */ - blstats[idx][BL_HUNGER].a.a_int = (int) u.uhs; - Strcpy(blstats[idx][BL_HUNGER].val, + g.blstats[idx][BL_HUNGER].a.a_int = (int) u.uhs; + Strcpy(g.blstats[idx][BL_HUNGER].val, (u.uhs != NOT_HUNGRY) ? hu_stat[u.uhs] : ""); - valset[BL_HUNGER] = TRUE; + g.valset[BL_HUNGER] = TRUE; /* Carrying capacity */ cap = near_capacity(); - blstats[idx][BL_CAP].a.a_int = cap; - Strcpy(blstats[idx][BL_CAP].val, + g.blstats[idx][BL_CAP].a.a_int = cap; + Strcpy(g.blstats[idx][BL_CAP].val, (cap > UNENCUMBERED) ? enc_stat[cap] : ""); - valset[BL_CAP] = TRUE; + g.valset[BL_CAP] = TRUE; /* Conditions */ - blstats[idx][BL_CONDITION].a.a_ulong = 0L; + g.blstats[idx][BL_CONDITION].a.a_ulong = 0L; if (Stoned) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STONE; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STONE; if (Slimed) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_SLIME; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_SLIME; if (Strangled) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STRNGL; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STRNGL; if (Sick && (u.usick_type & SICK_VOMITABLE) != 0) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FOODPOIS; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FOODPOIS; if (Sick && (u.usick_type & SICK_NONVOMITABLE) != 0) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_TERMILL; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_TERMILL; /* * basic formatting puts hunger status and encumbrance here */ if (Blind) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_BLIND; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_BLIND; if (Deaf) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_DEAF; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_DEAF; if (Stunned) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STUN; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STUN; if (Confusion) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_CONF; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_CONF; if (Hallucination) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_HALLU; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_HALLU; /* levitation and flying are mututally exclusive */ if (Levitation) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_LEV; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_LEV; if (Flying) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FLY; + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FLY; if (u.usteed) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_RIDE; - evaluate_and_notify_windowport(valset, idx, idx_p); + g.blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_RIDE; + evaluate_and_notify_windowport(g.valset, idx, idx_p); } STATIC_OVL boolean @@ -711,18 +675,18 @@ boolean *valsetlist; /* * Now pass the changed values to window port. */ - anytype = blstats[idx][fld].anytype; - curr = &blstats[idx][fld]; - prev = &blstats[idx_p][fld]; + anytype = g.blstats[idx][fld].anytype; + curr = &g.blstats[idx][fld]; + prev = &g.blstats[idx_p][fld]; color = NO_COLOR; - chg = update_all ? 0 : compare_blstats(prev, curr); + chg = g.update_all ? 0 : compare_blstats(prev, curr); /* Temporary? hack: moveloop()'s prolog for a new game sets * context.rndencode after the status window has been init'd, * so $:0 has already been encoded and cached by the window * port. Without this hack, gold's \G sequence won't be - * recognized and ends up being displayed as-is for 'update_all'. + * recognized and ends up being displayed as-is for 'g.update_all'. * * Also, even if context.rndencode hasn't changed and the * gold amount itself hasn't changed, the glyph portion of the @@ -747,16 +711,16 @@ boolean *valsetlist; reset = FALSE; #ifdef STATUS_HILITES - if (!update_all && !chg) { - reset = hilite_reset_needed(prev, bl_hilite_moves); + if (!g.update_all && !chg) { + reset = hilite_reset_needed(prev, g.bl_hilite_moves); if (reset) curr->time = prev->time = 0L; } #endif - if (update_all || chg || reset) { + if (g.update_all || chg || reset) { idxmax = curr->idxmax; - pc = (idxmax >= 0) ? percentage(curr, &blstats[idx][idxmax]) : 0; + pc = (idxmax >= 0) ? percentage(curr, &g.blstats[idx][idxmax]) : 0; if (!valsetlist[fld]) (void) anything_to_s(curr->val, &curr->a, anytype); @@ -773,11 +737,11 @@ boolean *valsetlist; } #endif /* STATUS_HILITES */ status_update(fld, (genericptr_t) curr->val, - chg, pc, color, &cond_hilites[0]); + chg, pc, color, &g.cond_hilites[0]); } else { - /* Color for conditions is done through cond_hilites[] */ + /* Color for conditions is done through g.cond_hilites[] */ status_update(fld, (genericptr_t) &curr->a.a_ulong, chg, pc, - color, &cond_hilites[0]); + color, &g.cond_hilites[0]); } curr->chg = prev->chg = TRUE; updated = TRUE; @@ -832,13 +796,13 @@ boolean *valsetlist; */ if (context.botlx && (windowprocs.wincap2 & WC2_RESET_STATUS) != 0L) status_update(BL_RESET, (genericptr_t) 0, 0, 0, - NO_COLOR, &cond_hilites[0]); + NO_COLOR, &g.cond_hilites[0]); else if ((windowprocs.wincap2 & WC2_FLUSH_STATUS) != 0L) status_update(BL_FLUSH, (genericptr_t) 0, 0, 0, - NO_COLOR, &cond_hilites[0]); + NO_COLOR, &g.cond_hilites[0]); context.botl = context.botlx = 0; - update_all = FALSE; + g.update_all = FALSE; } void @@ -848,17 +812,17 @@ status_eval_next_unhilite() struct istat_s *curr = NULL; long next_unhilite, this_unhilite; - bl_hilite_moves = moves; + g.bl_hilite_moves = moves; /* figure out when the next unhilight needs to be performed */ next_unhilite = 0L; for (i = 0; i < MAXBLSTATS; ++i) { - curr = &blstats[0][i]; /* blstats[0][*].time == blstats[1][*].time */ + curr = &g.blstats[0][i]; /* g.blstats[0][*].time == g.blstats[1][*].time */ if (curr->chg) { - struct istat_s *prev = &blstats[1][i]; + struct istat_s *prev = &g.blstats[1][i]; #ifdef STATUS_HILITES - curr->time = prev->time = (bl_hilite_moves + iflags.hilite_delta); + curr->time = prev->time = (g.bl_hilite_moves + iflags.hilite_delta); #endif curr->chg = prev->chg = FALSE; } @@ -872,7 +836,7 @@ status_eval_next_unhilite() ) next_unhilite = this_unhilite; } - if (next_unhilite > 0L && next_unhilite < bl_hilite_moves) + if (next_unhilite > 0L && next_unhilite < g.bl_hilite_moves) context.botl = TRUE; } @@ -886,11 +850,11 @@ boolean const char *fieldname = (const char *) 0; if (!reassessment) { - if (blinit) + if (g.blinit) impossible("2nd status_initialize with full init."); init_blstats(); (*windowprocs.win_status_init)(); - blinit = TRUE; + g.blinit = TRUE; } for (i = 0; i < MAXBLSTATS; ++i) { enum statusfields fld = initblstats[i].fld; @@ -908,7 +872,7 @@ boolean fieldfmt = initblstats[i].fldfmt; status_enablefield(fld, fieldname, fieldfmt, fldenabled); } - update_all = TRUE; + g.update_all = TRUE; } void @@ -922,19 +886,19 @@ status_finish() /* free memory that we alloc'd now */ for (i = 0; i < MAXBLSTATS; ++i) { - if (blstats[0][i].val) - free((genericptr_t) blstats[0][i].val), blstats[0][i].val = 0; - if (blstats[1][i].val) - free((genericptr_t) blstats[1][i].val), blstats[1][i].val = 0; + if (g.blstats[0][i].val) + free((genericptr_t) g.blstats[0][i].val), g.blstats[0][i].val = 0; + if (g.blstats[1][i].val) + free((genericptr_t) g.blstats[1][i].val), g.blstats[1][i].val = 0; #ifdef STATUS_HILITES - if (blstats[0][i].thresholds) { - struct hilite_s *temp = blstats[0][i].thresholds, + if (g.blstats[0][i].thresholds) { + struct hilite_s *temp = g.blstats[0][i].thresholds, *next = (struct hilite_s *)0; while (temp) { next = temp->next; free(temp); - blstats[0][i].thresholds = (struct hilite_s *)0; - blstats[1][i].thresholds = blstats[0][i].thresholds; + g.blstats[0][i].thresholds = (struct hilite_s *)0; + g.blstats[1][i].thresholds = g.blstats[0][i].thresholds; temp = next; } } @@ -957,18 +921,18 @@ init_blstats() for (i = BEFORE; i <= NOW; ++i) { for (j = 0; j < MAXBLSTATS; ++j) { #ifdef STATUS_HILITES - struct hilite_s *keep_hilite_chain = blstats[i][j].thresholds; + struct hilite_s *keep_hilite_chain = g.blstats[i][j].thresholds; #endif - blstats[i][j] = initblstats[j]; - blstats[i][j].a = zeroany; - if (blstats[i][j].valwidth) { - blstats[i][j].val = (char *) alloc(blstats[i][j].valwidth); - blstats[i][j].val[0] = '\0'; + g.blstats[i][j] = initblstats[j]; + g.blstats[i][j].a = zeroany; + if (g.blstats[i][j].valwidth) { + g.blstats[i][j].val = (char *) alloc(g.blstats[i][j].valwidth); + g.blstats[i][j].val[0] = '\0'; } else - blstats[i][j].val = (char *) 0; + g.blstats[i][j].val = (char *) 0; #ifdef STATUS_HILITES - blstats[i][j].thresholds = keep_hilite_chain; + g.blstats[i][j].thresholds = keep_hilite_chain; #endif } } @@ -1233,9 +1197,7 @@ struct istat_s *bl, *maxbl; /* Core status hiliting support */ /****************************************************************************/ -struct hilite_s status_hilites[MAXBLSTATS]; - -static struct fieldid_t { +static const struct fieldid_t { const char *fieldname; enum statusfields fldid; } fieldids_alias[] = { @@ -1352,8 +1314,8 @@ reset_status_hilites() int i; for (i = 0; i < MAXBLSTATS; ++i) - blstats[0][i].time = blstats[1][i].time = 0L; - update_all = TRUE; + g.blstats[0][i].time = g.blstats[1][i].time = 0L; + g.update_all = TRUE; } context.botlx = TRUE; } @@ -1428,7 +1390,7 @@ int *colorptr; if (!colorptr || fldidx < 0 || fldidx >= MAXBLSTATS) return; - if (blstats[idx][fldidx].thresholds) { + if (g.blstats[idx][fldidx].thresholds) { int dt; /* there are hilites set here */ int max_pc = -1, min_pc = 101; @@ -1442,7 +1404,7 @@ int *colorptr; perc_or_abs = FALSE; /* min_/max_ are used to track best fit */ - for (hl = blstats[idx][fldidx].thresholds; hl; hl = hl->next) { + for (hl = g.blstats[idx][fldidx].thresholds; hl; hl = hl->next) { dt = initblstats[fldidx].anytype; /* only needed for 'absolute' */ /* if we've already matched a temporary highlight, it takes precedence over all persistent ones; we still process @@ -1577,7 +1539,7 @@ int *colorptr; } break; case BL_TH_TEXTMATCH: /* ANY_STR */ - txtstr = blstats[idx][fldidx].val; + txtstr = g.blstats[idx][fldidx].val; if (fldidx == BL_TITLE) /* " the ", skip past " the " */ txtstr += (strlen(plname) + sizeof " the " - sizeof ""); @@ -1834,12 +1796,12 @@ struct hilite_s *hilite; new_hilite->set = TRUE; new_hilite->fld = fld; - new_hilite->next = blstats[0][fld].thresholds; - blstats[0][fld].thresholds = new_hilite; + new_hilite->next = g.blstats[0][fld].thresholds; + g.blstats[0][fld].thresholds = new_hilite; /* sort_hilites(fld) */ /* current and prev must both point at the same hilites */ - blstats[1][fld].thresholds = blstats[0][fld].thresholds; + g.blstats[1][fld].thresholds = g.blstats[0][fld].thresholds; } @@ -2365,21 +2327,21 @@ int sidx; for (i = 0; i < sf; ++i) { int a = match_str2attr(subfields[i], FALSE); if (a == ATR_DIM) - cond_hilites[HL_ATTCLR_DIM] |= conditions_bitmask; + g.cond_hilites[HL_ATTCLR_DIM] |= conditions_bitmask; else if (a == ATR_BLINK) - cond_hilites[HL_ATTCLR_BLINK] |= conditions_bitmask; + g.cond_hilites[HL_ATTCLR_BLINK] |= conditions_bitmask; else if (a == ATR_ULINE) - cond_hilites[HL_ATTCLR_ULINE] |= conditions_bitmask; + g.cond_hilites[HL_ATTCLR_ULINE] |= conditions_bitmask; else if (a == ATR_INVERSE) - cond_hilites[HL_ATTCLR_INVERSE] |= conditions_bitmask; + g.cond_hilites[HL_ATTCLR_INVERSE] |= conditions_bitmask; else if (a == ATR_BOLD) - cond_hilites[HL_ATTCLR_BOLD] |= conditions_bitmask; + g.cond_hilites[HL_ATTCLR_BOLD] |= conditions_bitmask; else if (a == ATR_NONE) { - cond_hilites[HL_ATTCLR_DIM] &= ~conditions_bitmask; - cond_hilites[HL_ATTCLR_BLINK] &= ~conditions_bitmask; - cond_hilites[HL_ATTCLR_ULINE] &= ~conditions_bitmask; - cond_hilites[HL_ATTCLR_INVERSE] &= ~conditions_bitmask; - cond_hilites[HL_ATTCLR_BOLD] &= ~conditions_bitmask; + g.cond_hilites[HL_ATTCLR_DIM] &= ~conditions_bitmask; + g.cond_hilites[HL_ATTCLR_BLINK] &= ~conditions_bitmask; + g.cond_hilites[HL_ATTCLR_ULINE] &= ~conditions_bitmask; + g.cond_hilites[HL_ATTCLR_INVERSE] &= ~conditions_bitmask; + g.cond_hilites[HL_ATTCLR_BOLD] &= ~conditions_bitmask; } else { int k = match_str2clr(subfields[i]); @@ -2391,7 +2353,7 @@ int sidx; /* set the bits in the appropriate member of the condition array according to color chosen as index */ - cond_hilites[coloridx] |= conditions_bitmask; + g.cond_hilites[coloridx] |= conditions_bitmask; success = TRUE; sidx++; } @@ -2404,14 +2366,14 @@ clear_status_hilites() int i; for (i = 0; i < MAXBLSTATS; ++i) { - if (blstats[0][i].thresholds) { - struct hilite_s *temp = blstats[0][i].thresholds, + if (g.blstats[0][i].thresholds) { + struct hilite_s *temp = g.blstats[0][i].thresholds, *next = (struct hilite_s *)0; while (temp) { next = temp->next; free(temp); - blstats[0][i].thresholds = (struct hilite_s *)0; - blstats[1][i].thresholds = blstats[0][i].thresholds; + g.blstats[0][i].thresholds = (struct hilite_s *)0; + g.blstats[1][i].thresholds = g.blstats[0][i].thresholds; temp = next; } } @@ -2555,19 +2517,19 @@ status_hilite_linestr_gather_conditions() int j; for (j = 0; j < CLR_MAX; j++) - if (cond_hilites[j] & valid_conditions[i].bitmask) { + if (g.cond_hilites[j] & valid_conditions[i].bitmask) { clr = j; break; } - if (cond_hilites[HL_ATTCLR_DIM] & valid_conditions[i].bitmask) + if (g.cond_hilites[HL_ATTCLR_DIM] & valid_conditions[i].bitmask) atr |= HL_DIM; - if (cond_hilites[HL_ATTCLR_BOLD] & valid_conditions[i].bitmask) + if (g.cond_hilites[HL_ATTCLR_BOLD] & valid_conditions[i].bitmask) atr |= HL_BOLD; - if (cond_hilites[HL_ATTCLR_BLINK] & valid_conditions[i].bitmask) + if (g.cond_hilites[HL_ATTCLR_BLINK] & valid_conditions[i].bitmask) atr |= HL_BLINK; - if (cond_hilites[HL_ATTCLR_ULINE] & valid_conditions[i].bitmask) + if (g.cond_hilites[HL_ATTCLR_ULINE] & valid_conditions[i].bitmask) atr |= HL_ULINE; - if (cond_hilites[HL_ATTCLR_INVERSE] & valid_conditions[i].bitmask) + if (g.cond_hilites[HL_ATTCLR_INVERSE] & valid_conditions[i].bitmask) atr |= HL_INVERSE; if (atr != HL_NONE) atr &= ~HL_NONE; @@ -2626,7 +2588,7 @@ status_hilite_linestr_gather() status_hilite_linestr_done(); for (i = 0; i < MAXBLSTATS; i++) { - hl = blstats[0][i].thresholds; + hl = g.blstats[0][i].thresholds; while (hl) { status_hilite_linestr_add(i, hl, 0UL, status_hilite2str(hl)); hl = hl->next; @@ -2730,7 +2692,7 @@ status_hilite_menu_choose_field() for (i = 0; i < MAXBLSTATS; i++) { #ifndef SCORE_ON_BOTL if (initblstats[i].fld == BL_SCORE - && !blstats[0][BL_SCORE].thresholds) + && !g.blstats[0][BL_SCORE].thresholds) continue; #endif any = zeroany; @@ -3275,23 +3237,23 @@ choose_color: char *tmpattr; if (atr & HL_DIM) - cond_hilites[HL_ATTCLR_DIM] |= cond; + g.cond_hilites[HL_ATTCLR_DIM] |= cond; else if (atr & HL_BLINK) - cond_hilites[HL_ATTCLR_BLINK] |= cond; + g.cond_hilites[HL_ATTCLR_BLINK] |= cond; else if (atr & HL_ULINE) - cond_hilites[HL_ATTCLR_ULINE] |= cond; + g.cond_hilites[HL_ATTCLR_ULINE] |= cond; else if (atr & HL_INVERSE) - cond_hilites[HL_ATTCLR_INVERSE] |= cond; + g.cond_hilites[HL_ATTCLR_INVERSE] |= cond; else if (atr & HL_BOLD) - cond_hilites[HL_ATTCLR_BOLD] |= cond; + g.cond_hilites[HL_ATTCLR_BOLD] |= cond; else if (atr == HL_NONE) { - cond_hilites[HL_ATTCLR_DIM] &= ~cond; - cond_hilites[HL_ATTCLR_BLINK] &= ~cond; - cond_hilites[HL_ATTCLR_ULINE] &= ~cond; - cond_hilites[HL_ATTCLR_INVERSE] &= ~cond; - cond_hilites[HL_ATTCLR_BOLD] &= ~cond; + g.cond_hilites[HL_ATTCLR_DIM] &= ~cond; + g.cond_hilites[HL_ATTCLR_BLINK] &= ~cond; + g.cond_hilites[HL_ATTCLR_ULINE] &= ~cond; + g.cond_hilites[HL_ATTCLR_INVERSE] &= ~cond; + g.cond_hilites[HL_ATTCLR_BOLD] &= ~cond; } - cond_hilites[clr] |= cond; + g.cond_hilites[clr] |= cond; (void) strNsubst(strcpy(clrbuf, clr2colorname(clr)), " ", "-", 0); tmpattr = hlattr2attrname(atr, attrbuf, BUFSZ); if (tmpattr) @@ -3342,16 +3304,16 @@ int id; int i; for (i = 0; i < CLR_MAX; i++) - cond_hilites[i] &= ~hlstr->mask; - cond_hilites[HL_ATTCLR_DIM] &= ~hlstr->mask; - cond_hilites[HL_ATTCLR_BOLD] &= ~hlstr->mask; - cond_hilites[HL_ATTCLR_BLINK] &= ~hlstr->mask; - cond_hilites[HL_ATTCLR_ULINE] &= ~hlstr->mask; - cond_hilites[HL_ATTCLR_INVERSE] &= ~hlstr->mask; + g.cond_hilites[i] &= ~hlstr->mask; + g.cond_hilites[HL_ATTCLR_DIM] &= ~hlstr->mask; + g.cond_hilites[HL_ATTCLR_BOLD] &= ~hlstr->mask; + g.cond_hilites[HL_ATTCLR_BLINK] &= ~hlstr->mask; + g.cond_hilites[HL_ATTCLR_ULINE] &= ~hlstr->mask; + g.cond_hilites[HL_ATTCLR_INVERSE] &= ~hlstr->mask; return TRUE; } else { int fld = hlstr->fld; - struct hilite_s *hl = blstats[0][fld].thresholds; + struct hilite_s *hl = g.blstats[0][fld].thresholds; struct hilite_s *hlprev = (struct hilite_s *) 0; if (hl) { @@ -3360,9 +3322,9 @@ int id; if (hlprev) { hlprev->next = hl->next; } else { - blstats[0][fld].thresholds = hl->next; - blstats[1][fld].thresholds = - blstats[0][fld].thresholds; + g.blstats[0][fld].thresholds = hl->next; + g.blstats[1][fld].thresholds = + g.blstats[0][fld].thresholds; } free((genericptr_t) hl); return TRUE; diff --git a/src/decl.c b/src/decl.c index 4bd1d434e..b030b054d 100644 --- a/src/decl.c +++ b/src/decl.c @@ -326,14 +326,22 @@ const struct instance_globals g_init = { 0, /* jumping_is_magic */ -1, /* polearm_range_min */ -1, /* polearm_range_max */ + UNDEFINED_VALUES, /* trapinfo */ /* artifact.c */ 0, /* spec_dbon_applies */ UNDEFINED_VALUES, /* artiexist */ UNDEFINED_VALUES, /* artdisco */ + 0, /* mkot_trap_warn_count */ /* botl.c */ 0, /* mrank_sz */ + UNDEFINED_VALUES, /* blstats */ + FALSE, /* blinit */ + FALSE, /* update_all */ + UNDEFINED_VALUES, /* valset */ + 0, /* bl_hilite_moves */ + UNDEFINED_VALUES, /* cond_hilites */ /* cmd.c */ UNDEFINED_VALUES, /* Cmd */ @@ -440,6 +448,9 @@ const struct instance_globals g_init = { { {COLNO, ROWNO, 0, 0}, {COLNO, ROWNO, 0, 0} }, /* bughack */ UNDEFINED_VALUE, /* was_waterlevel */ + /* mon.c */ + UNDEFINED_VALUE, /* vamp_rise_msg */ + UNDEFINED_VALUE, /* disintegested */ /* mused.c */ FALSE, /* m_using */ diff --git a/src/mkmaze.c b/src/mkmaze.c index efaad38b2..a2a072487 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -24,9 +24,6 @@ STATIC_DCL void FDECL(migr_booty_item, (int, const char *)); STATIC_DCL void FDECL(migrate_orc, (struct monst *, unsigned long)); STATIC_DCL void NDECL(stolen_booty); -lev_region bughack; /* for preserving the insect legs when wallifying - * baalz level */ - /* adjust a coordinate one step in the specified direction */ #define mz_move(X, Y, dir) \ do { \ diff --git a/src/mon.c b/src/mon.c index aea39c7a7..4b512d000 100644 --- a/src/mon.c +++ b/src/mon.c @@ -12,8 +12,6 @@ #include "mfndpos.h" #include -STATIC_VAR boolean vamp_rise_msg, disintegested; - STATIC_DCL void FDECL(sanity_check_single_mon, (struct monst *, BOOLEAN_P, const char *)); STATIC_DCL boolean FDECL(restrap, (struct monst *)); @@ -1898,7 +1896,7 @@ register struct monst *mtmp; spec_mon = (nonliving(mtmp->data) || noncorporeal(mtmp->data) || amorphous(mtmp->data)), - spec_death = (disintegested /* disintegrated or digested */ + spec_death = (g.disintegested /* disintegrated or digested */ || noncorporeal(mtmp->data) || amorphous(mtmp->data)); @@ -1939,7 +1937,7 @@ register struct monst *mtmp; if (!type_is_pname(mtmp->data)) whom = an(whom); pline(upstart(buf), whom); - vamp_rise_msg = TRUE; + g.vamp_rise_msg = TRUE; } newsym(x, y); return; @@ -2226,8 +2224,8 @@ int how; be_sad = (mdef->mtame != 0); /* no corpses if digested or disintegrated */ - disintegested = (how == AD_DGST || how == -AD_RBRE); - if (disintegested) + g.disintegested = (how == AD_DGST || how == -AD_RBRE); + if (g.disintegested) mondead(mdef); else mondied(mdef); @@ -2323,14 +2321,14 @@ int xkill_flags; /* 1: suppress message, 2: suppress corpse, 4: pacifist */ thrownobj = 0; } - vamp_rise_msg = FALSE; /* might get set in mondead(); only checked below */ - disintegested = nocorpse; /* alternate vamp_rise message needed if true */ + g.vamp_rise_msg = FALSE; /* might get set in mondead(); only checked below */ + g.disintegested = nocorpse; /* alternate vamp_rise message needed if true */ /* dispose of monster and make cadaver */ if (stoned) monstone(mtmp); else mondead(mtmp); - disintegested = FALSE; /* reset */ + g.disintegested = FALSE; /* reset */ if (!DEADMONSTER(mtmp)) { /* monster lifesaved */ /* Cannot put the non-visible lifesaving message in @@ -2338,7 +2336,7 @@ int xkill_flags; /* 1: suppress message, 2: suppress corpse, 4: pacifist */ * kill it (as opposed to visible lifesaving which always appears). */ stoned = FALSE; - if (!cansee(x, y) && !vamp_rise_msg) + if (!cansee(x, y) && !g.vamp_rise_msg) pline("Maybe not..."); return; } diff --git a/src/sp_lev.c b/src/sp_lev.c index 59e76bac8..c450109b2 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -18,8 +18,6 @@ #pragma warning(disable : 4244) #endif -lev_region *lregions; - typedef void FDECL((*select_iter_func), (int, int, genericptr)); extern void FDECL(mkmap, (lev_init *)); From 5807fb50623f204e98b90fddc91aaf1f71a24965 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 24 Nov 2018 18:46:36 -0800 Subject: [PATCH 07/11] Even more globals moved to instance_globals.c --- include/decl.h | 62 +++++++++++++++++- src/cmd.c | 11 ++-- src/decl.c | 28 ++++++++ src/dig.c | 2 - src/display.c | 57 +++++++--------- src/do_wear.c | 12 ++-- src/dogmove.c | 2 +- src/drawing.c | 2 +- src/eat.c | 24 ++++--- src/end.c | 34 +++------- src/explode.c | 2 +- src/extralev.c | 78 ++++++++++------------ src/files.c | 173 +++++++++++++++++++++++-------------------------- src/options.c | 21 +++--- 14 files changed, 269 insertions(+), 239 deletions(-) diff --git a/include/decl.h b/include/decl.h index a23c7088b..16195e1ab 100644 --- a/include/decl.h +++ b/include/decl.h @@ -552,6 +552,32 @@ struct trapinfo { boolean force_bungle; }; +typedef struct { + xchar gnew; /* perhaps move this bit into the rm structure. */ + int glyph; +} gbuf_entry; + +enum vanq_order_modes { + VANQ_MLVL_MNDX = 0, + VANQ_MSTR_MNDX, + VANQ_ALPHA_SEP, + VANQ_ALPHA_MIX, + VANQ_MCLS_HTOL, + VANQ_MCLS_LTOH, + VANQ_COUNT_H_L, + VANQ_COUNT_L_H, + + NUM_VANQ_ORDER_MODES +}; + +struct rogueroom { + xchar rlx, rly; + xchar dx, dy; + boolean real; + uchar doortable; + int nroom; /* Only meaningful for "real" rooms */ +}; + /* 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. @@ -559,6 +585,7 @@ struct trapinfo { * unlike instance_flags, values in the structure can be of any type. */ #define BSIZE 20 +#define WIZKIT_MAX 128 struct instance_globals { @@ -603,6 +630,7 @@ struct instance_globals { coord clicklook_cc; winid en_win; boolean en_via_menu; + int last_multi; /* dbridge.c */ struct entity occupants[ENTITIES]; @@ -611,6 +639,12 @@ struct instance_globals { boolean did_dig_msg; + /* display.c */ + gbuf_entry gbuf[ROWNO][COLNO]; + char gbuf_start[ROWNO]; + char gbuf_stop[ROWNO]; + + /* do.c */ boolean at_ladder; char *dfr_pre_msg; /* pline() before level change */ @@ -622,6 +656,11 @@ struct instance_globals { int gloc_filter_floodfill_match_glyph; int via_naming; + /* do_wear.c */ + /* starting equipment gets auto-worn at beginning of new game, + and we don't want stealth or displacement feedback then */ + boolean initial_don; /* manipulated in set_wear() */ + /* dog.c */ int petname_used; /* user preferred pet name has been used */ xchar gtyp; /* type of dog's current goal */ @@ -648,12 +687,29 @@ struct instance_globals { /* eat.c */ boolean force_save_hs; + char *eatmbuf; /* set by cpostfx() */ + /* end.c */ struct valuable_data gems[LAST_GEM + 1 - FIRST_GEM + 1]; /* +1 for glass */ struct valuable_data amulets[LAST_AMULET + 1 - FIRST_AMULET]; struct val_list valuables[3]; - + int vanq_sortmode; + + /* extralev.c */ + struct rogueroom r[3][3]; + + /* files.c */ + char wizkit[WIZKIT_MAX]; + int lockptr; + char *config_section_chosen; + char *config_section_current; + int nesting; + int symset_count; /* for pick-list building only */ + boolean chosen_symset_start; + boolean chosen_symset_end; + int symset_which_set; + /* hack.c */ anything tmp_anything; int wc; /* current weight_cap(); valid after call to inv_weight() */ @@ -727,6 +783,10 @@ struct instance_globals { modified */ int distantname; + /* options.c */ + struct symsetentry *symset_list; /* files.c will populate this with + list of available sets */ + /* pickup.c */ int oldcap; /* last encumberance */ /* current_container is set in use_container(), to be used by the diff --git a/src/cmd.c b/src/cmd.c index fe4a61437..70a811e66 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -5320,9 +5320,6 @@ boolean doit; return ch; } - -static NEARDATA int last_multi; - /* * convert a MAP window position into a movecmd */ @@ -5544,7 +5541,7 @@ parse() long tmpmulti = multi; foo = get_count((char *) 0, '\0', LARGEST_INT, &tmpmulti, FALSE); - last_multi = multi = tmpmulti; + g.last_multi = multi = tmpmulti; } #ifdef ALTMETA alt_esc = FALSE; /* readchar() reset */ @@ -5558,11 +5555,11 @@ parse() if (foo == g.Cmd.spkeys[NHKF_ESC]) { /* esc cancels count (TH) */ clear_nhwindow(WIN_MESSAGE); - multi = last_multi = 0; + multi = g.last_multi = 0; } else if (foo == g.Cmd.spkeys[NHKF_DOAGAIN] || in_doagain) { - multi = last_multi; + multi = g.last_multi; } else { - last_multi = multi; + g.last_multi = multi; savech(0); /* reset input queue */ savech((char) foo); } diff --git a/src/decl.c b/src/decl.c index b030b054d..0f18aacba 100644 --- a/src/decl.c +++ b/src/decl.c @@ -354,6 +354,7 @@ const struct instance_globals g_init = { UNDEFINED_VALUES, /* clicklook_cc */ WIN_ERR, /* en_win */ FALSE, /* en_via_menu */ + UNDEFINED_VALUE, /* last_multi */ /* dbridge.c */ UNDEFINED_VALUES, @@ -361,6 +362,11 @@ const struct instance_globals g_init = { /* dig.c */ UNDEFINED_VALUE, /* did_dig_msg */ + /* display.c */ + UNDEFINED_VALUES, + UNDEFINED_VALUES, + UNDEFINED_VALUES, + /* do.c */ FALSE, /* at_ladder */ NULL, /* dfr_pre_msg */ @@ -372,6 +378,9 @@ const struct instance_globals g_init = { UNDEFINED_VALUE, /* gloc_filter_floodfill_match_glyph */ 0, /* via_naming */ + /* do_wear.c */ + FALSE, /* initial_don */ + /* dog.c */ 0, /* petname_used */ UNDEFINED_VALUE, /* gtyp */ @@ -398,11 +407,27 @@ const struct instance_globals g_init = { /* eat.c */ FALSE, /* force_save_hs */ + NULL, /* eatmbuf */ /* end.c */ UNDEFINED_VALUES, UNDEFINED_VALUES, UNDEFINED_VALUES, + VANQ_MLVL_MNDX, + + /* extralev.c */ + UNDEFINED_VALUES, + + /* files.c */ + UNDEFINED_VALUES, /* wizkit */ + UNDEFINED_VALUE, /* lockptr */ + NULL, /* config_section_chosen */ + NULL, /* config_section_current */ + 0, /* nesting */ + 0, /* symset_count */ + FALSE, /* chosen_symset_start */ + FALSE, /* chosen_symset_end */ + 0, /* symset_which_set */ /* hack.c */ UNDEFINED_VALUES, @@ -461,6 +486,9 @@ const struct instance_globals g_init = { /* objname.c */ 0, /* distantname */ + /* options.c */ + NULL, /* symset_list */ + /* pickup.c */ 0, /* oldcap */ UNDEFINED_PTR, /* current_container */ diff --git a/src/dig.c b/src/dig.c index 9c50cc1e6..b689e6133 100644 --- a/src/dig.c +++ b/src/dig.c @@ -5,8 +5,6 @@ #include "hack.h" -static NEARDATA boolean did_dig_msg; - STATIC_DCL boolean NDECL(rm_waslit); STATIC_DCL void FDECL(mkcavepos, (XCHAR_P, XCHAR_P, int, BOOLEAN_P, BOOLEAN_P)); diff --git a/src/display.c b/src/display.c index 129b63fd3..e27fc7f2f 100644 --- a/src/display.c +++ b/src/display.c @@ -1378,15 +1378,6 @@ docrt() /* Glyph Buffering (3rd screen) ============================================ */ -typedef struct { - xchar new; /* perhaps move this bit into the rm structure. */ - int glyph; -} gbuf_entry; - -static gbuf_entry gbuf[ROWNO][COLNO]; -static char gbuf_start[ROWNO]; -static char gbuf_stop[ROWNO]; - /* FIXME: This is a dirty hack, because newsym() doesn't distinguish * between object piles and single objects, it doesn't mark the location * for update. */ @@ -1395,11 +1386,11 @@ newsym_force(x, y) register int x, y; { newsym(x,y); - gbuf[y][x].new = 1; - if (gbuf_start[y] > x) - gbuf_start[y] = x; - if (gbuf_stop[y] < x) - gbuf_stop[y] = x; + g.gbuf[y][x].gnew = 1; + if (g.gbuf_start[y] > x) + g.gbuf_start[y] = x; + if (g.gbuf_stop[y] < x) + g.gbuf_stop[y] = x; } /* @@ -1475,13 +1466,13 @@ int x, y, glyph; return; } - if (gbuf[y][x].glyph != glyph || iflags.use_background_glyph) { - gbuf[y][x].glyph = glyph; - gbuf[y][x].new = 1; - if (gbuf_start[y] > x) - gbuf_start[y] = x; - if (gbuf_stop[y] < x) - gbuf_stop[y] = x; + if (g.gbuf[y][x].glyph != glyph || iflags.use_background_glyph) { + g.gbuf[y][x].glyph = glyph; + g.gbuf[y][x].gnew = 1; + if (g.gbuf_start[y] > x) + g.gbuf_start[y] = x; + if (g.gbuf_stop[y] < x) + g.gbuf_stop[y] = x; } } @@ -1494,12 +1485,12 @@ int x, y, glyph; int i; \ \ for (i = 0; i < ROWNO; i++) { \ - gbuf_start[i] = COLNO - 1; \ - gbuf_stop[i] = 0; \ + g.gbuf_start[i] = COLNO - 1; \ + g.gbuf_stop[i] = 0; \ } \ } -static gbuf_entry nul_gbuf = { 0, cmap_to_glyph(S_stone) }; +static const gbuf_entry nul_gbuf = { 0, cmap_to_glyph(S_stone) }; /* * Turn the 3rd screen into stone. */ @@ -1510,7 +1501,7 @@ clear_glyph_buffer() register gbuf_entry *gptr; for (y = 0; y < ROWNO; y++) { - gptr = &gbuf[y][0]; + gptr = &g.gbuf[y][0]; for (x = COLNO; x; x--) { *gptr++ = nul_gbuf; } @@ -1528,8 +1519,8 @@ int start, stop, y; register int x; for (x = start; x <= stop; x++) - if (gbuf[y][x].glyph != cmap_to_glyph(S_stone)) - print_glyph(WIN_MAP, x, y, gbuf[y][x].glyph, get_bk_glyph(x,y)); + if (g.gbuf[y][x].glyph != cmap_to_glyph(S_stone)) + print_glyph(WIN_MAP, x, y, g.gbuf[y][x].glyph, get_bk_glyph(x,y)); } void @@ -1575,11 +1566,11 @@ int cursor_on_u; #endif for (y = 0; y < ROWNO; y++) { - register gbuf_entry *gptr = &gbuf[y][x = gbuf_start[y]]; - for (; x <= gbuf_stop[y]; gptr++, x++) - if (gptr->new) { + register gbuf_entry *gptr = &g.gbuf[y][x = g.gbuf_start[y]]; + for (; x <= g.gbuf_stop[y]; gptr++, x++) + if (gptr->gnew) { print_glyph(WIN_MAP, x, y, gptr->glyph, get_bk_glyph(x, y)); - gptr->new = 0; + gptr->gnew = 0; } } @@ -1791,7 +1782,7 @@ xchar x, y; { if (x < 0 || y < 0 || x >= COLNO || y >= ROWNO) return cmap_to_glyph(S_room); /* XXX */ - return gbuf[y][x].glyph; + return g.gbuf[y][x].glyph; } /* @@ -1812,7 +1803,7 @@ xchar x, y; struct rm *lev = &levl[x][y]; if (iflags.use_background_glyph && lev->seenv != 0 - && gbuf[y][x].glyph != cmap_to_glyph(S_stone)) { + && g.gbuf[y][x].glyph != cmap_to_glyph(S_stone)) { switch (lev->typ) { case SCORR: case STONE: diff --git a/src/do_wear.c b/src/do_wear.c index 8300bd0c2..b67ee8c37 100644 --- a/src/do_wear.c +++ b/src/do_wear.c @@ -71,10 +71,6 @@ struct obj *otmp; } } -/* starting equipment gets auto-worn at beginning of new game, - and we don't want stealth or displacement feedback then */ -static boolean initial_don = FALSE; /* manipulated in set_wear() */ - /* putting on or taking off an item which confers stealth; give feedback and discover it iff stealth state is changing */ STATIC_OVL @@ -84,7 +80,7 @@ struct obj *obj; long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */ boolean on; { - if (on ? initial_don : context.takeoff.cancelled_don) + if (on ? g.initial_don : context.takeoff.cancelled_don) return; if (!oldprop /* extrinsic stealth from something else */ @@ -118,7 +114,7 @@ struct obj *obj; long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */ boolean on; { - if (on ? initial_don : context.takeoff.cancelled_don) + if (on ? g.initial_don : context.takeoff.cancelled_don) return; if (!oldprop /* extrinsic displacement from something else */ @@ -1161,7 +1157,7 @@ void set_wear(obj) struct obj *obj; /* if null, do all worn items; otherwise just obj itself */ { - initial_don = !obj; + g.initial_don = !obj; if (!obj ? ublindf != 0 : (obj == ublindf)) (void) Blindf_on(ublindf); @@ -1187,7 +1183,7 @@ struct obj *obj; /* if null, do all worn items; otherwise just obj itself */ if (!obj ? uarms != 0 : (obj == uarms)) (void) Shield_on(); - initial_don = FALSE; + g.initial_don = FALSE; } /* check whether the target object is currently being put on (or taken off-- diff --git a/src/dogmove.c b/src/dogmove.c index 2003bc77a..3fe8737e6 100644 --- a/src/dogmove.c +++ b/src/dogmove.c @@ -1334,7 +1334,7 @@ genericptr_t distance; } } -static struct qmchoices { +static const struct qmchoices { int mndx; /* type of pet, 0 means any */ char mlet; /* symbol of pet, 0 means any */ unsigned mappearance; /* mimic this */ diff --git a/src/drawing.c b/src/drawing.c index 8867ab74c..de35f90ab 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -567,7 +567,7 @@ const char *known_restrictions[] = { "primary", "rogue", (const char *) 0, }; -struct symparse loadsyms[] = { +const struct symparse loadsyms[] = { { SYM_CONTROL, 0, "start" }, { SYM_CONTROL, 0, "begin" }, { SYM_CONTROL, 1, "finish" }, diff --git a/src/eat.c b/src/eat.c index 555fa82fe..54f18fc79 100644 --- a/src/eat.c +++ b/src/eat.c @@ -144,17 +144,15 @@ static const struct { { "", 0, 0, 0 } }; #define TTSZ SIZE(tintxts) -static char *eatmbuf = 0; /* set by cpostfx() */ - /* called after mimicing is over */ STATIC_PTR int eatmdone(VOID_ARGS) { /* release `eatmbuf' */ - if (eatmbuf) { - if (nomovemsg == eatmbuf) + if (g.eatmbuf) { + if (nomovemsg == g.eatmbuf) nomovemsg = 0; - free((genericptr_t) eatmbuf), eatmbuf = 0; + free((genericptr_t) g.eatmbuf), g.eatmbuf = 0; } /* update display */ if (youmonst.m_ap_type) { @@ -171,7 +169,7 @@ eatmupdate() const char *altmsg = 0; int altapp = 0; /* lint suppression */ - if (!eatmbuf || nomovemsg != eatmbuf) + if (!g.eatmbuf || nomovemsg != g.eatmbuf) return; if (is_obj_mappear(&youmonst,ORANGE) && !Hallucination) { @@ -188,11 +186,11 @@ eatmupdate() if (altmsg) { /* replace end-of-mimicking message */ - if (strlen(altmsg) > strlen(eatmbuf)) { - free((genericptr_t) eatmbuf); - eatmbuf = (char *) alloc(strlen(altmsg) + 1); + if (strlen(altmsg) > strlen(g.eatmbuf)) { + free((genericptr_t) g.eatmbuf); + g.eatmbuf = (char *) alloc(strlen(altmsg) + 1); } - nomovemsg = strcpy(eatmbuf, altmsg); + nomovemsg = strcpy(g.eatmbuf, altmsg); /* update current image */ youmonst.mappearance = altapp; newsym(u.ux, u.uy); @@ -947,7 +945,7 @@ int pm; /* in case `afternmv' didn't get called for previously mimicking gold, clean up now to avoid `eatmbuf' memory leak */ - if (eatmbuf) + if (g.eatmbuf) (void) eatmdone(); switch (pm) { @@ -1033,8 +1031,8 @@ int pm; ? "You suddenly dread being peeled and mimic %s again!" : "You now prefer mimicking %s again.", an(Upolyd ? youmonst.data->mname : urace.noun)); - eatmbuf = dupstr(buf); - nomovemsg = eatmbuf; + g.eatmbuf = dupstr(buf); + nomovemsg = g.eatmbuf; afternmv = eatmdone; /* ??? what if this was set before? */ youmonst.m_ap_type = M_AP_OBJECT; diff --git a/src/end.c b/src/end.c index cb27f2922..5d12b3800 100644 --- a/src/end.c +++ b/src/end.c @@ -1634,19 +1634,6 @@ int status; nethack_exit(status); } -enum vanq_order_modes { - VANQ_MLVL_MNDX = 0, - VANQ_MSTR_MNDX, - VANQ_ALPHA_SEP, - VANQ_ALPHA_MIX, - VANQ_MCLS_HTOL, - VANQ_MCLS_LTOH, - VANQ_COUNT_H_L, - VANQ_COUNT_L_H, - - NUM_VANQ_ORDER_MODES -}; - static const char *vanqorders[NUM_VANQ_ORDER_MODES] = { "traditional: by monster level, by internal monster index", "by monster toughness, by internal monster index", @@ -1657,7 +1644,6 @@ static const char *vanqorders[NUM_VANQ_ORDER_MODES] = { "by count, high to low, by internal index within tied count", "by count, low to high, by internal index within tied count", }; -static int vanq_sortmode = VANQ_MLVL_MNDX; STATIC_PTR int CFDECLSPEC vanqsort_cmp(vptr1, vptr2) @@ -1669,7 +1655,7 @@ const genericptr vptr2; const char *name1, *name2, *punct; schar mcls1, mcls2; - switch (vanq_sortmode) { + switch (g.vanq_sortmode) { default: case VANQ_MLVL_MNDX: /* sort by monster level */ @@ -1721,7 +1707,7 @@ const genericptr vptr2; if (res == 0) { mlev1 = mons[indx1].mlevel, mlev2 = mons[indx2].mlevel; res = mlev1 - mlev2; /* mlevel low to high */ - if (vanq_sortmode == VANQ_MCLS_HTOL) + if (g.vanq_sortmode == VANQ_MCLS_HTOL) res = -res; /* mlevel high to low */ } break; @@ -1729,7 +1715,7 @@ const genericptr vptr2; case VANQ_COUNT_L_H: died1 = mvitals[indx1].died, died2 = mvitals[indx2].died; res = died2 - died1; /* dead count high to low */ - if (vanq_sortmode == VANQ_COUNT_L_H) + if (g.vanq_sortmode == VANQ_COUNT_L_H) res = -res; /* dead count low to high */ break; } @@ -1756,7 +1742,7 @@ set_vanq_order() continue; any.a_int = i + 1; add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, vanqorders[i], - (i == vanq_sortmode) ? MENU_SELECTED : MENU_UNSELECTED); + (i == g.vanq_sortmode) ? MENU_SELECTED : MENU_UNSELECTED); } end_menu(tmpwin, "Sort order for vanquished monster counts"); @@ -1765,12 +1751,12 @@ set_vanq_order() if (n > 0) { choice = selected[0].item.a_int - 1; /* skip preselected entry if we have more than one item chosen */ - if (n > 1 && choice == vanq_sortmode) + if (n > 1 && choice == g.vanq_sortmode) choice = selected[1].item.a_int - 1; free((genericptr_t) selected); - vanq_sortmode = choice; + g.vanq_sortmode = choice; } - return (n < 0) ? -1 : vanq_sortmode; + return (n < 0) ? -1 : g.vanq_sortmode; } /* #vanquished command */ @@ -1832,9 +1818,9 @@ boolean ask; if (set_vanq_order() < 0) return; } - uniq_header = (vanq_sortmode == VANQ_ALPHA_SEP); - class_header = (vanq_sortmode == VANQ_MCLS_LTOH - || vanq_sortmode == VANQ_MCLS_HTOL); + uniq_header = (g.vanq_sortmode == VANQ_ALPHA_SEP); + class_header = (g.vanq_sortmode == VANQ_MCLS_LTOH + || g.vanq_sortmode == VANQ_MCLS_HTOL); klwin = create_nhwindow(NHW_MENU); putstr(klwin, 0, "Vanquished creatures:"); diff --git a/src/explode.c b/src/explode.c index 46d3b327f..1f3b78939 100644 --- a/src/explode.c +++ b/src/explode.c @@ -5,7 +5,7 @@ #include "hack.h" /* Note: Arrays are column first, while the screen is row first */ -static int explosion[3][3] = { { S_explode1, S_explode4, S_explode7 }, +static const int explosion[3][3] = { { S_explode1, S_explode4, S_explode7 }, { S_explode2, S_explode5, S_explode8 }, { S_explode3, S_explode6, S_explode9 } }; diff --git a/src/extralev.c b/src/extralev.c index 54e935e08..50b2f81a1 100644 --- a/src/extralev.c +++ b/src/extralev.c @@ -8,19 +8,11 @@ #include "hack.h" -struct rogueroom { - xchar rlx, rly; - xchar dx, dy; - boolean real; - uchar doortable; - int nroom; /* Only meaningful for "real" rooms */ -}; #define UP 1 #define DOWN 2 #define LEFT 4 #define RIGHT 8 -static NEARDATA struct rogueroom r[3][3]; STATIC_DCL void FDECL(roguejoin, (int, int, int, int, int)); STATIC_DCL void FDECL(roguecorr, (int, int, int)); STATIC_DCL void FDECL(miniwalk, (int, int)); @@ -59,20 +51,20 @@ int x, y, dir; register int fromx, fromy, tox, toy; if (dir == DOWN) { - r[x][y].doortable &= ~DOWN; - if (!r[x][y].real) { - fromx = r[x][y].rlx; - fromy = r[x][y].rly; + g.r[x][y].doortable &= ~DOWN; + if (!g.r[x][y].real) { + fromx = g.r[x][y].rlx; + fromy = g.r[x][y].rly; fromx += 1 + 26 * x; fromy += 7 * y; } else { - fromx = r[x][y].rlx + rn2(r[x][y].dx); - fromy = r[x][y].rly + r[x][y].dy; + fromx = g.r[x][y].rlx + rn2(g.r[x][y].dx); + fromy = g.r[x][y].rly + g.r[x][y].dy; fromx += 1 + 26 * x; fromy += 7 * y; if (!IS_WALL(levl[fromx][fromy].typ)) impossible("down: no wall at %d,%d?", fromx, fromy); - dodoor(fromx, fromy, &rooms[r[x][y].nroom]); + dodoor(fromx, fromy, &rooms[g.r[x][y].nroom]); levl[fromx][fromy].doormask = D_NODOOR; fromy++; } @@ -81,40 +73,40 @@ int x, y, dir; return; } y++; - r[x][y].doortable &= ~UP; - if (!r[x][y].real) { - tox = r[x][y].rlx; - toy = r[x][y].rly; + g.r[x][y].doortable &= ~UP; + if (!g.r[x][y].real) { + tox = g.r[x][y].rlx; + toy = g.r[x][y].rly; tox += 1 + 26 * x; toy += 7 * y; } else { - tox = r[x][y].rlx + rn2(r[x][y].dx); - toy = r[x][y].rly - 1; + tox = g.r[x][y].rlx + rn2(g.r[x][y].dx); + toy = g.r[x][y].rly - 1; tox += 1 + 26 * x; toy += 7 * y; if (!IS_WALL(levl[tox][toy].typ)) impossible("up: no wall at %d,%d?", tox, toy); - dodoor(tox, toy, &rooms[r[x][y].nroom]); + dodoor(tox, toy, &rooms[g.r[x][y].nroom]); levl[tox][toy].doormask = D_NODOOR; toy--; } roguejoin(fromx, fromy, tox, toy, FALSE); return; } else if (dir == RIGHT) { - r[x][y].doortable &= ~RIGHT; - if (!r[x][y].real) { - fromx = r[x][y].rlx; - fromy = r[x][y].rly; + g.r[x][y].doortable &= ~RIGHT; + if (!g.r[x][y].real) { + fromx = g.r[x][y].rlx; + fromy = g.r[x][y].rly; fromx += 1 + 26 * x; fromy += 7 * y; } else { - fromx = r[x][y].rlx + r[x][y].dx; - fromy = r[x][y].rly + rn2(r[x][y].dy); + fromx = g.r[x][y].rlx + g.r[x][y].dx; + fromy = g.r[x][y].rly + rn2(g.r[x][y].dy); fromx += 1 + 26 * x; fromy += 7 * y; if (!IS_WALL(levl[fromx][fromy].typ)) impossible("down: no wall at %d,%d?", fromx, fromy); - dodoor(fromx, fromy, &rooms[r[x][y].nroom]); + dodoor(fromx, fromy, &rooms[g.r[x][y].nroom]); levl[fromx][fromy].doormask = D_NODOOR; fromx++; } @@ -123,20 +115,20 @@ int x, y, dir; return; } x++; - r[x][y].doortable &= ~LEFT; - if (!r[x][y].real) { - tox = r[x][y].rlx; - toy = r[x][y].rly; + g.r[x][y].doortable &= ~LEFT; + if (!g.r[x][y].real) { + tox = g.r[x][y].rlx; + toy = g.r[x][y].rly; tox += 1 + 26 * x; toy += 7 * y; } else { - tox = r[x][y].rlx - 1; - toy = r[x][y].rly + rn2(r[x][y].dy); + tox = g.r[x][y].rlx - 1; + toy = g.r[x][y].rly + rn2(g.r[x][y].dy); tox += 1 + 26 * x; toy += 7 * y; if (!IS_WALL(levl[tox][toy].typ)) impossible("left: no wall at %d,%d?", tox, toy); - dodoor(tox, toy, &rooms[r[x][y].nroom]); + dodoor(tox, toy, &rooms[g.r[x][y].nroom]); levl[tox][toy].doormask = D_NODOOR; tox--; } @@ -157,18 +149,18 @@ int x, y; while (1) { q = 0; -#define doorhere (r[x][y].doortable) +#define doorhere (g.r[x][y].doortable) if (x > 0 && (!(doorhere & LEFT)) - && (!r[x - 1][y].doortable || !rn2(10))) + && (!g.r[x - 1][y].doortable || !rn2(10))) dirs[q++] = 0; if (x < 2 && (!(doorhere & RIGHT)) - && (!r[x + 1][y].doortable || !rn2(10))) + && (!g.r[x + 1][y].doortable || !rn2(10))) dirs[q++] = 1; if (y > 0 && (!(doorhere & UP)) - && (!r[x][y - 1].doortable || !rn2(10))) + && (!g.r[x][y - 1].doortable || !rn2(10))) dirs[q++] = 2; if (y < 2 && (!(doorhere & DOWN)) - && (!r[x][y + 1].doortable || !rn2(10))) + && (!g.r[x][y + 1].doortable || !rn2(10))) dirs[q++] = 3; /* Rogue levels aren't just 3 by 3 mazes; they have some extra * connections, thus that 1/10 chance @@ -222,7 +214,7 @@ makeroguerooms() * Room height may be 2-4 (2-5 on last row), length 2-23 (not * counting walls). */ -#define here r[x][y] +#define here g.r[x][y] nroom = 0; for (y = 0; y < 3; y++) @@ -256,7 +248,7 @@ makeroguerooms() if (here.real) { /* Make a room */ int lowx, lowy, hix, hiy; - r[x][y].nroom = nroom; + g.r[x][y].nroom = nroom; smeq[nroom] = nroom; lowx = 1 + 26 * x + here.rlx; diff --git a/src/files.c b/src/files.c index 57b2c65df..d80ee27cc 100644 --- a/src/files.c +++ b/src/files.c @@ -125,15 +125,12 @@ struct level_ftrack { #endif #endif /*HOLD_LOCKFILE_OPEN*/ -#define WIZKIT_MAX 128 -static char wizkit[WIZKIT_MAX]; STATIC_DCL FILE *NDECL(fopen_wizkit_file); STATIC_DCL void FDECL(wizkit_addinv, (struct obj *)); #ifdef AMIGA extern char PATH[]; /* see sys/amiga/amidos.c */ extern char bbs_id[]; -static int lockptr; #ifdef __SASC_60 #include #endif @@ -143,7 +140,6 @@ extern void FDECL(amii_set_text_font, (char *, int)); #endif #if defined(WIN32) || defined(MSDOS) -static int lockptr; #ifdef MSDOS #define Delay(a) msleep(a) #endif @@ -215,9 +211,6 @@ STATIC_DCL int FDECL(open_levelfile_exclusively, (const char *, int, int)); #endif -static char *config_section_chosen = (char *) 0; -static char *config_section_current = (char *) 0; - /* * fname_encode() * @@ -1611,8 +1604,6 @@ boolean uncomp; /* ---------- BEGIN FILE LOCKING HANDLING ----------- */ -static int nesting = 0; - #if defined(NO_FILE_LINKS) || defined(USE_FCNTL) /* implies UNIX */ static int lockfd; /* for lock_file() to pass to unlock_file() */ #endif @@ -1674,8 +1665,8 @@ int retryct; const char *lockname; #endif - nesting++; - if (nesting > 1) { + g.nesting++; + if (g.nesting > 1) { impossible("TRIED TO NEST LOCKS"); return TRUE; } @@ -1692,7 +1683,7 @@ int retryct; if (lockfd == -1) { HUP raw_printf("Cannot open file %s. Is NetHack installed correctly?", filename); - nesting--; + g.nesting--; return FALSE; } sflock.l_type = F_WRLCK; @@ -1722,7 +1713,7 @@ int retryct; HUP(void) raw_print("I give up. Sorry."); HUP raw_printf("Some other process has an unnatural grip on %s.", filename); - nesting--; + g.nesting--; return FALSE; } #else @@ -1742,25 +1733,25 @@ int retryct; HUP(void) raw_print("I give up. Sorry."); HUP raw_printf("Perhaps there is an old %s around?", lockname); - nesting--; + g.nesting--; return FALSE; } break; case ENOENT: HUP raw_printf("Can't find file %s to lock!", filename); - nesting--; + g.nesting--; return FALSE; case EACCES: HUP raw_printf("No write permission to lock %s!", filename); - nesting--; + g.nesting--; return FALSE; #ifdef VMS /* c__translate(vmsfiles.c) */ case EPERM: /* could be misleading, but usually right */ HUP raw_printf("Can't lock %s due to directory protection.", filename); - nesting--; + g.nesting--; return FALSE; #endif case EROFS: @@ -1769,13 +1760,13 @@ int retryct; HUP raw_printf("Cannot lock %s.", filename); HUP raw_printf( "(Perhaps you are running NetHack from inside the distribution package?)."); - nesting--; + g.nesting--; return FALSE; default: HUP perror(lockname); HUP raw_printf("Cannot lock %s for unknown reason (%d).", filename, errnosv); - nesting--; + g.nesting--; return FALSE; } #endif /* USE_FCNTL */ @@ -1786,23 +1777,23 @@ int retryct; && !defined(USE_FCNTL) #ifdef AMIGA #define OPENFAILURE(fd) (!fd) - lockptr = 0; + g.lockptr = 0; #else #define OPENFAILURE(fd) (fd < 0) - lockptr = -1; + g.lockptr = -1; #endif - while (--retryct && OPENFAILURE(lockptr)) { + while (--retryct && OPENFAILURE(g.lockptr)) { #if defined(WIN32) && !defined(WIN_CE) - lockptr = sopen(lockname, O_RDWR | O_CREAT, SH_DENYRW, S_IWRITE); + g.lockptr = sopen(lockname, O_RDWR | O_CREAT, SH_DENYRW, S_IWRITE); #else (void) DeleteFile(lockname); /* in case dead process was here first */ #ifdef AMIGA - lockptr = Open(lockname, MODE_NEWFILE); + g.lockptr = Open(lockname, MODE_NEWFILE); #else - lockptr = open(lockname, O_RDWR | O_CREAT | O_EXCL, S_IWRITE); + g.lockptr = open(lockname, O_RDWR | O_CREAT | O_EXCL, S_IWRITE); #endif #endif - if (OPENFAILURE(lockptr)) { + if (OPENFAILURE(g.lockptr)) { raw_printf("Waiting for access to %s. (%d retries left).", filename, retryct); Delay(50); @@ -1810,7 +1801,7 @@ int retryct; } if (!retryct) { raw_printf("I give up. Sorry."); - nesting--; + g.nesting--; return FALSE; } #endif /* AMIGA || WIN32 || MSDOS */ @@ -1834,7 +1825,7 @@ const char *filename; const char *lockname; #endif - if (nesting == 1) { + if (g.nesting == 1) { #ifdef USE_FCNTL sflock.l_type = F_UNLCK; if (fcntl(lockfd, F_SETLK, &sflock) == -1) { @@ -1857,15 +1848,15 @@ const char *filename; #endif /* UNIX || VMS */ #if defined(AMIGA) || defined(WIN32) || defined(MSDOS) - if (lockptr) - Close(lockptr); + if (g.lockptr) + Close(g.lockptr); DeleteFile(lockname); - lockptr = 0; + g.lockptr = 0; #endif /* AMIGA || WIN32 || MSDOS */ #endif /* USE_FCNTL */ } - nesting--; + g.nesting--; } /* ---------- END FILE LOCKING HANDLING ----------- */ @@ -2183,13 +2174,13 @@ char sep; STATIC_OVL void free_config_sections() { - if (config_section_chosen) { - free(config_section_chosen); - config_section_chosen = NULL; + if (g.config_section_chosen) { + free(g.config_section_chosen); + g.config_section_chosen = NULL; } - if (config_section_current) { - free(config_section_current); - config_section_current = NULL; + if (g.config_section_current) { + free(g.config_section_current); + g.config_section_current = NULL; } } @@ -2208,20 +2199,20 @@ char *buf; { if (is_config_section(buf)) { char *send; - if (config_section_current) { - free(config_section_current); + if (g.config_section_current) { + free(g.config_section_current); } - config_section_current = dupstr(&buf[1]); - send = rindex(config_section_current, ']'); + g.config_section_current = dupstr(&buf[1]); + send = rindex(g.config_section_current, ']'); *send = '\0'; - debugpline1("set config section: '%s'", config_section_current); + debugpline1("set config section: '%s'", g.config_section_current); return TRUE; } - if (config_section_current) { - if (!config_section_chosen) + if (g.config_section_current) { + if (!g.config_section_chosen) return TRUE; - if (strcmp(config_section_current, config_section_chosen)) + if (strcmp(g.config_section_current, g.config_section_chosen)) return TRUE; } return FALSE; @@ -2562,7 +2553,7 @@ char *origbuf; } switch_symbols(TRUE); } else if (match_varname(buf, "WIZKIT", 6)) { - (void) strncpy(wizkit, bufp, WIZKIT_MAX - 1); + (void) strncpy(g.wizkit, bufp, WIZKIT_MAX - 1); #ifdef AMIGA } else if (match_varname(buf, "FONT", 4)) { char *t; @@ -2873,58 +2864,58 @@ fopen_wizkit_file() envp = nh_getenv("WIZKIT"); if (envp && *envp) - (void) strncpy(wizkit, envp, WIZKIT_MAX - 1); - if (!wizkit[0]) + (void) strncpy(g.wizkit, envp, WIZKIT_MAX - 1); + if (!g.wizkit[0]) return (FILE *) 0; #ifdef UNIX - if (access(wizkit, 4) == -1) { + if (access(g.wizkit, 4) == -1) { /* 4 is R_OK on newer systems */ /* nasty sneaky attempt to read file through * NetHack's setuid permissions -- this is a * place a file name may be wholly under the player's * control */ - raw_printf("Access to %s denied (%d).", wizkit, errno); + raw_printf("Access to %s denied (%d).", g.wizkit, errno); wait_synch(); /* fall through to standard names */ } else #endif - if ((fp = fopenp(wizkit, "r")) != (FILE *) 0) { + if ((fp = fopenp(g.wizkit, "r")) != (FILE *) 0) { return fp; #if defined(UNIX) || defined(VMS) } else { /* access() above probably caught most problems for UNIX */ - raw_printf("Couldn't open requested config file %s (%d).", wizkit, + raw_printf("Couldn't open requested config file %s (%d).", g.wizkit, errno); wait_synch(); #endif } #if defined(MICRO) || defined(MAC) || defined(__BEOS__) || defined(WIN32) - if ((fp = fopenp(fqname(wizkit, CONFIGPREFIX, 0), "r")) != (FILE *) 0) + if ((fp = fopenp(fqname(g.wizkit, CONFIGPREFIX, 0), "r")) != (FILE *) 0) return fp; #else #ifdef VMS envp = nh_getenv("HOME"); if (envp) - Sprintf(tmp_wizkit, "%s%s", envp, wizkit); + Sprintf(tmp_wizkit, "%s%s", envp, g.wizkit); else - Sprintf(tmp_wizkit, "%s%s", "sys$login:", wizkit); + Sprintf(tmp_wizkit, "%s%s", "sys$login:", g.wizkit); if ((fp = fopenp(tmp_wizkit, "r")) != (FILE *) 0) return fp; #else /* should be only UNIX left */ envp = nh_getenv("HOME"); if (envp) - Sprintf(tmp_wizkit, "%s/%s", envp, wizkit); + Sprintf(tmp_wizkit, "%s/%s", envp, g.wizkit); else - Strcpy(tmp_wizkit, wizkit); + Strcpy(tmp_wizkit, g.wizkit); if ((fp = fopenp(tmp_wizkit, "r")) != (FILE *) 0) return fp; else if (errno != ENOENT) { /* e.g., problems when setuid NetHack can't search home * directory restricted to user */ - raw_printf("Couldn't open default wizkit file %s (%d).", tmp_wizkit, + raw_printf("Couldn't open default g.wizkit file %s (%d).", tmp_wizkit, errno); wait_synch(); } @@ -3106,11 +3097,11 @@ boolean FDECL((*proc), (char *)); continue; } bufp++; - if (config_section_chosen) - free(config_section_chosen); + if (g.config_section_chosen) + free(g.config_section_chosen); section = choose_random_part(bufp, ','); if (section) - config_section_chosen = dupstr(section); + g.config_section_chosen = dupstr(section); else { config_error_add("No config section to choose"); rv = FALSE; @@ -3136,13 +3127,9 @@ boolean FDECL((*proc), (char *)); return rv; } -extern struct symsetentry *symset_list; /* options.c */ extern struct symparse loadsyms[]; /* drawing.c */ extern const char *known_handling[]; /* drawing.c */ extern const char *known_restrictions[]; /* drawing.c */ -static int symset_count = 0; /* for pick-list building only */ -static boolean chosen_symset_start = FALSE, chosen_symset_end = FALSE; -static int symset_which_set = 0; STATIC_OVL FILE * @@ -3167,16 +3154,16 @@ int which_set; if (!(fp = fopen_sym_file())) return 0; - symset_count = 0; - chosen_symset_start = chosen_symset_end = FALSE; - symset_which_set = which_set; + g.symset_count = 0; + g.chosen_symset_start = g.chosen_symset_end = FALSE; + g.symset_which_set = which_set; config_error_init(TRUE, "symbols", FALSE); parse_conf_file(fp, proc_symset_line); (void) fclose(fp); - if (!chosen_symset_start && !chosen_symset_end) { + if (!g.chosen_symset_start && !g.chosen_symset_end) { /* name caller put in symset[which_set].name was not found; if it looks like "Default symbols", null it out and return success to use the default; otherwise, return failure */ @@ -3188,7 +3175,7 @@ int which_set; config_error_done(); return (g.symset[which_set].name == 0) ? 1 : 0; } - if (!chosen_symset_end) + if (!g.chosen_symset_end) config_error_add("Missing finish for symset \"%s\"", g.symset[which_set].name ? g.symset[which_set].name : "unknown"); @@ -3202,7 +3189,7 @@ boolean proc_symset_line(buf) char *buf; { - return !((boolean) parse_sym_line(buf, symset_which_set)); + return !((boolean) parse_sym_line(buf, g.symset_which_set)); } /* returns 0 on error */ @@ -3235,9 +3222,9 @@ int which_set; if (!bufp) { if (strncmpi(buf, "finish", 6) == 0) { /* end current graphics set */ - if (chosen_symset_start) - chosen_symset_end = TRUE; - chosen_symset_start = FALSE; + if (g.chosen_symset_start) + g.chosen_symset_end = TRUE; + g.chosen_symset_start = FALSE; return 1; } config_error_add("No \"finish\""); @@ -3266,15 +3253,15 @@ int which_set; tmpsp = (struct symsetentry *) alloc(sizeof (struct symsetentry)); tmpsp->next = (struct symsetentry *) 0; - if (!symset_list) { - symset_list = tmpsp; - symset_count = 0; + if (!g.symset_list) { + g.symset_list = tmpsp; + g.symset_count = 0; } else { - symset_count++; - tmpsp->next = symset_list; - symset_list = tmpsp; + g.symset_count++; + tmpsp->next = g.symset_list; + g.symset_list = tmpsp; } - tmpsp->idx = symset_count; + tmpsp->idx = g.symset_count; tmpsp->name = dupstr(bufp); tmpsp->desc = (char *) 0; tmpsp->nocolor = 0; @@ -3284,7 +3271,7 @@ int which_set; break; case 2: /* handler type identified */ - tmpsp = symset_list; /* most recent symset */ + tmpsp = g.symset_list; /* most recent symset */ tmpsp->handling = H_UNK; i = 0; while (known_handling[i]) { @@ -3296,13 +3283,13 @@ int which_set; } break; case 3: /* description:something */ - tmpsp = symset_list; /* most recent symset */ + tmpsp = g.symset_list; /* most recent symset */ if (tmpsp && !tmpsp->desc) tmpsp->desc = dupstr(bufp); break; case 5: /* restrictions: xxxx*/ - tmpsp = symset_list; /* most recent symset */ + tmpsp = g.symset_list; /* most recent symset */ for (i = 0; known_restrictions[i]; ++i) { if (!strcmpi(known_restrictions[i], bufp)) { switch (i) { @@ -3328,7 +3315,7 @@ int which_set; /* start of symset */ if (!strcmpi(bufp, g.symset[which_set].name)) { /* matches desired one */ - chosen_symset_start = TRUE; + g.chosen_symset_start = TRUE; /* these init_*() functions clear symset fields too */ if (which_set == ROGUESET) init_r_symbols(); @@ -3338,18 +3325,18 @@ int which_set; break; case 1: /* finish symset */ - if (chosen_symset_start) - chosen_symset_end = TRUE; - chosen_symset_start = FALSE; + if (g.chosen_symset_start) + g.chosen_symset_end = TRUE; + g.chosen_symset_start = FALSE; break; case 2: /* handler type identified */ - if (chosen_symset_start) + if (g.chosen_symset_start) set_symhandling(bufp, which_set); break; /* case 3: (description) is ignored here */ case 4: /* color:off */ - if (chosen_symset_start) { + if (g.chosen_symset_start) { if (bufp) { if (!strcmpi(bufp, "true") || !strcmpi(bufp, "yes") || !strcmpi(bufp, "on")) @@ -3362,7 +3349,7 @@ int which_set; } break; case 5: /* restrictions: xxxx*/ - if (chosen_symset_start) { + if (g.chosen_symset_start) { int n = 0; while (known_restrictions[n]) { @@ -3384,7 +3371,7 @@ int which_set; } } else { /* !SYM_CONTROL */ val = sym_val(bufp); - if (chosen_symset_start) { + if (g.chosen_symset_start) { if (which_set == PRIMARY) { update_l_symset(symp, val); } else if (which_set == ROGUESET) { diff --git a/src/options.c b/src/options.c index b5f08cdee..b9fda55da 100644 --- a/src/options.c +++ b/src/options.c @@ -4566,9 +4566,6 @@ int numtotal; return opt_idx; } -struct symsetentry *symset_list = 0; /* files.c will populate this with - list of available sets */ - STATIC_OVL boolean special_handling(optname, setinitial, setfromfile) const char *optname; @@ -5213,14 +5210,14 @@ boolean setinitial, setfromfile; /* clear symset[].name as a flag to read_sym_file() to build list */ symset_name = g.symset[which_set].name; g.symset[which_set].name = (char *) 0; - symset_list = (struct symsetentry *) 0; + g.symset_list = (struct symsetentry *) 0; res = read_sym_file(which_set); - if (res && symset_list) { + if (res && g.symset_list) { char symsetchoice[BUFSZ]; int let = 'a', biggest = 0, thissize = 0; - sl = symset_list; + sl = g.symset_list; while (sl) { /* check restrictions */ if ((!rogueflag && sl->rogue) @@ -5251,7 +5248,7 @@ boolean setinitial, setfromfile; add_menu(tmpwin, NO_GLYPH, &any, let++, 0, ATR_NONE, "Default Symbols", MENU_UNSELECTED); - sl = symset_list; + sl = g.symset_list; while (sl) { /* check restrictions */ if ((!rogueflag && sl->rogue) @@ -5283,7 +5280,7 @@ boolean setinitial, setfromfile; if (chosen > -1) { /* chose an actual symset name from file */ - sl = symset_list; + sl = g.symset_list; while (sl) { if (sl->idx == chosen) { if (symset_name) { @@ -5314,15 +5311,15 @@ boolean setinitial, setfromfile; /* The symbols file could not be accessed */ pline("Unable to access \"%s\" file.", SYMBOLS); return TRUE; - } else if (!symset_list) { + } else if (!g.symset_list) { /* The symbols file was empty */ pline("There were no symbol sets found in \"%s\".", SYMBOLS); return TRUE; } /* clean up */ - while (symset_list) { - sl = symset_list; + while (g.symset_list) { + sl = g.symset_list; if (sl->name) free((genericptr_t) sl->name); sl->name = (char *) 0; @@ -5331,7 +5328,7 @@ boolean setinitial, setfromfile; free((genericptr_t) sl->desc); sl->desc = (char *) 0; - symset_list = sl->next; + g.symset_list = sl->next; free((genericptr_t) sl); } From 6d6623cf578353dc66637040ca953c30bdbf2fdb Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 24 Nov 2018 19:27:56 -0800 Subject: [PATCH 08/11] Even more globals moved to instance_globals. --- include/decl.h | 62 +++++++++++++ include/lev.h | 35 ------- src/decl.c | 18 +++- src/files.c | 1 - src/invent.c | 45 ++++----- src/light.c | 46 +++++---- src/makemon.c | 2 +- src/mkmap.c | 4 +- src/mkmaze.c | 130 +++++++++++++------------- src/mkobj.c | 2 +- src/mkroom.c | 2 +- src/mon.c | 23 ++--- src/muse.c | 246 ++++++++++++++++++++++++------------------------- 13 files changed, 315 insertions(+), 301 deletions(-) diff --git a/include/decl.h b/include/decl.h index 16195e1ab..517abe793 100644 --- a/include/decl.h +++ b/include/decl.h @@ -578,6 +578,49 @@ struct rogueroom { int nroom; /* Only meaningful for "real" rooms */ }; +typedef struct ls_t { + struct ls_t *next; + xchar x, y; /* source's position */ + short range; /* source's current range */ + short flags; + short type; /* type of light source */ + anything id; /* source's identifier */ +} light_source; + +struct container { + struct container *next; + xchar x, y; + short what; + genericptr_t list; +}; + +enum bubble_contains_types { + CONS_OBJ = 0, + CONS_MON, + CONS_HERO, + CONS_TRAP +}; + +#define MAX_BMASK 4 + +struct bubble { + xchar x, y; /* coordinates of the upper left corner */ + schar dx, dy; /* the general direction of the bubble's movement */ + uchar bm[MAX_BMASK + 2]; /* bubble bit mask */ + struct bubble *prev, *next; /* need to traverse the list up and down */ + struct container *cons; +}; + +struct musable { + struct obj *offensive; + struct obj *defensive; + struct obj *misc; + int has_offense, has_defense, has_misc; + /* =0, no capability; otherwise, different numbers. + * If it's an object, the object is also set (it's 0 otherwise). + */ +}; + /* 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. @@ -720,6 +763,18 @@ struct instance_globals { * reset by sortloot when done */ char *invbuf; unsigned invbufsiz; + /* for perm_invent when operating on a partial inventory display, so that + the persistent one doesn't get shrunk during filtering for item selection + then regrown to full inventory, possibly being resized in the process */ + winid cached_pickinv_win; + /* query objlist callback: return TRUE if obj type matches "this_type" */ + int this_type; + /* query objlist callback: return TRUE if obj is at given location */ + coord only; + + /* light.c */ + light_source *light_base; + /* lock.c */ struct xlock_s xlock; @@ -760,10 +815,16 @@ struct instance_globals { lev_region bughack; /* for preserving the insect legs when wallifying * baalz level */ boolean was_waterlevel; /* ugh... this shouldn't be needed */ + struct bubble *bbubbles; + struct bubble *ebubbles; + struct trap *wportal; + int xmin, ymin, xmax, ymax; /* level boundaries */ /* mon.c */ boolean vamp_rise_msg; boolean disintegested; + short *animal_list; /* list of PM values for animal monsters */ + int animal_list_count; /* muse.c */ boolean m_using; /* kludge to use mondided instead of killed */ @@ -775,6 +836,7 @@ struct instance_globals { * function mbhitm has to be compatible with the * normal zap routines, and those routines don't * remember who zapped the wand. */ + struct musable m; /* objname.c */ /* distantname used by distant_name() to pass extra information to diff --git a/include/lev.h b/include/lev.h index 17fd8dddd..97fe8d660 100644 --- a/include/lev.h +++ b/include/lev.h @@ -12,43 +12,8 @@ #define WRITE_SAVE 0x2 #define FREE_SAVE 0x4 -#define MAX_BMASK 4 - /* operations of the various saveXXXchn & co. routines */ #define perform_bwrite(mode) ((mode) & (COUNT_SAVE | WRITE_SAVE)) #define release_data(mode) ((mode) &FREE_SAVE) -/* The following are used in mkmaze.c */ -struct container { - struct container *next; - xchar x, y; - short what; - genericptr_t list; -}; - -enum bubble_contains_types { - CONS_OBJ = 0, - CONS_MON, - CONS_HERO, - CONS_TRAP -}; - -struct bubble { - xchar x, y; /* coordinates of the upper left corner */ - schar dx, dy; /* the general direction of the bubble's movement */ - uchar bm[MAX_BMASK + 2]; /* bubble bit mask */ - struct bubble *prev, *next; /* need to traverse the list up and down */ - struct container *cons; -}; - -/* used in light.c */ -typedef struct ls_t { - struct ls_t *next; - xchar x, y; /* source's position */ - short range; /* source's current range */ - short flags; - short type; /* type of light source */ - anything id; /* source's identifier */ -} light_source; - #endif /* LEV_H */ diff --git a/src/decl.c b/src/decl.c index 0f18aacba..267d038e7 100644 --- a/src/decl.c +++ b/src/decl.c @@ -438,6 +438,12 @@ const struct instance_globals g_init = { 0, /* sortloogmode */ NULL, /* invbuf */ 0, /* inbufsize */ + WIN_ERR, /* cached_pickinv_win */ + UNDEFINED_VALUE, + UNDEFINED_VALUES, + + /* light.c */ + NULL, /* light_source */ /* lock.c */ UNDEFINED_VALUES, @@ -472,16 +478,26 @@ const struct instance_globals g_init = { /* mkmaze.c */ { {COLNO, ROWNO, 0, 0}, {COLNO, ROWNO, 0, 0} }, /* bughack */ UNDEFINED_VALUE, /* was_waterlevel */ + UNDEFINED_PTR, /* bbubbles */ + UNDEFINED_PTR, /* ebubbles */ + UNDEFINED_PTR, /* wportal */ + UNDEFINED_VALUE, /* xmin */ + UNDEFINED_VALUE, /* ymin */ + UNDEFINED_VALUE, /* xmax */ + UNDEFINED_VALUE, /* ymax */ /* mon.c */ UNDEFINED_VALUE, /* vamp_rise_msg */ UNDEFINED_VALUE, /* disintegested */ + NULL, /* animal_list */ + UNDEFINED_VALUE, /* animal_list_count */ - /* mused.c */ + /* muse.c */ FALSE, /* m_using */ UNDEFINED_VALUE, /* trapx */ UNDEFINED_VALUE, /* trapy */ UNDEFINED_VALUE, /* zap_oseen */ + UNDEFINED_VALUES, /* m */ /* objname.c */ 0, /* distantname */ diff --git a/src/files.c b/src/files.c index d80ee27cc..28e805971 100644 --- a/src/files.c +++ b/src/files.c @@ -3127,7 +3127,6 @@ boolean FDECL((*proc), (char *)); return rv; } -extern struct symparse loadsyms[]; /* drawing.c */ extern const char *known_handling[]; /* drawing.c */ extern const char *known_restrictions[]; /* drawing.c */ diff --git a/src/invent.c b/src/invent.c index 3da2ab31d..2f00b222e 100644 --- a/src/invent.c +++ b/src/invent.c @@ -48,7 +48,7 @@ STATIC_DCL char FDECL(obj_to_let, (struct obj *)); * confused: 'WIZARD' used to be a compile-time conditional so this was * guarded by #ifdef WIZARD/.../#endif.] */ -static char venom_inv[] = { VENOM_CLASS, 0 }; /* (constant) */ +static const char venom_inv[] = { VENOM_CLASS, 0 }; /* (constant) */ /* sortloot() classification; called at most once for each object sorted */ STATIC_OVL void @@ -2464,17 +2464,12 @@ struct obj *list, **last_found; return (struct obj *) 0; } -/* for perm_invent when operating on a partial inventory display, so that - the persistent one doesn't get shrunk during filtering for item selection - then regrown to full inventory, possibly being resized in the process */ -static winid cached_pickinv_win = WIN_ERR; - void free_pickinv_cache() { - if (cached_pickinv_win != WIN_ERR) { - destroy_nhwindow(cached_pickinv_win); - cached_pickinv_win = WIN_ERR; + if (g.cached_pickinv_win != WIN_ERR) { + destroy_nhwindow(g.cached_pickinv_win); + g.cached_pickinv_win = WIN_ERR; } } @@ -2494,7 +2489,7 @@ long *out_cnt; static const char not_carrying_anything[] = "Not carrying anything"; struct obj *otmp, wizid_fakeobj; char ilet, ret; - char *invlet = flags.inv_order; + const char *invlet = flags.inv_order; int n, classcount; winid win; /* windows being used */ anything any; @@ -2510,9 +2505,9 @@ long *out_cnt; /* partial inventory in perm_invent setting; don't operate on full inventory window, use an alternate one instead; create the first time needed and keep it for re-use as needed later */ - if (cached_pickinv_win == WIN_ERR) - cached_pickinv_win = create_nhwindow(NHW_MENU); - win = cached_pickinv_win; + if (g.cached_pickinv_win == WIN_ERR) + g.cached_pickinv_win = create_nhwindow(NHW_MENU); + win = g.cached_pickinv_win; } else win = WIN_INVEN; @@ -2997,22 +2992,20 @@ dounpaid() destroy_nhwindow(win); } -/* query objlist callback: return TRUE if obj type matches "this_type" */ -static int this_type; STATIC_OVL boolean this_type_only(obj) struct obj *obj; { - boolean res = (obj->oclass == this_type); + boolean res = (obj->oclass == g.this_type); if (obj->oclass == COIN_CLASS) { /* if filtering by bless/curse state, gold is classified as either unknown or uncursed based on user option setting */ - if (this_type && index("BUCX", this_type)) - res = (this_type == (iflags.goldX ? 'X' : 'U')); + if (g.this_type && index("BUCX", g.this_type)) + res = (g.this_type == (iflags.goldX ? 'X' : 'U')); } else { - switch (this_type) { + switch (g.this_type) { case 'B': res = (obj->bknown && obj->blessed); break; @@ -3071,7 +3064,7 @@ dotypeinv() n = query_category(prompt, invent, i, &pick_list, PICK_ONE); if (!n) return 0; - this_type = c = pick_list[0].item.a_int; + g.this_type = c = pick_list[0].item.a_int; free((genericptr_t) pick_list); } } @@ -3189,7 +3182,7 @@ dotypeinv() You("have no %sobjects%s.", before, after); return 0; } - this_type = oclass; + g.this_type = oclass; } if (query_objlist((char *) 0, &invent, ((flags.invlet_constant ? USE_INVLET : 0) @@ -4289,14 +4282,12 @@ register struct obj *obj; return ret; } -/* query objlist callback: return TRUE if obj is at given location */ -static coord only; STATIC_OVL boolean only_here(obj) struct obj *obj; { - return (obj->ox == only.x && obj->oy == only.y); + return (obj->ox == g.only.x && obj->oy == g.only.y); } /* @@ -4323,13 +4314,13 @@ boolean as_if_seen; } if (n) { - only.x = x; - only.y = y; + g.only.x = x; + g.only.y = y; if (query_objlist("Things that are buried here:", &level.buriedobjlist, INVORDER_SORT, &selected, PICK_NONE, only_here) > 0) free((genericptr_t) selected); - only.x = only.y = 0; + g.only.x = g.only.y = 0; } return n; } diff --git a/src/light.c b/src/light.c index 446dc390e..c9e4dba24 100644 --- a/src/light.c +++ b/src/light.c @@ -42,8 +42,6 @@ #define LSF_SHOW 0x1 /* display the light source */ #define LSF_NEEDS_FIXUP 0x2 /* need oid fixup */ -static light_source *light_base = 0; - STATIC_DCL void FDECL(write_ls, (int, light_source *)); STATIC_DCL int FDECL(maybe_write_ls, (int, int, BOOLEAN_P)); @@ -67,14 +65,14 @@ anything *id; ls = (light_source *) alloc(sizeof(light_source)); - ls->next = light_base; + ls->next = g.light_base; ls->x = x; ls->y = y; ls->range = range; ls->type = type; ls->id = *id; ls->flags = 0; - light_base = ls; + g.light_base = ls; vision_full_recalc = 1; /* make the source show up */ } @@ -107,7 +105,7 @@ anything *id; break; } - for (prev = 0, curr = light_base; curr; prev = curr, curr = curr->next) { + for (prev = 0, curr = g.light_base; curr; prev = curr, curr = curr->next) { if (curr->type != type) continue; if (curr->id.a_obj @@ -115,7 +113,7 @@ anything *id; if (prev) prev->next = curr->next; else - light_base = curr->next; + g.light_base = curr->next; free((genericptr_t) curr); vision_full_recalc = 1; @@ -137,7 +135,7 @@ char **cs_rows; light_source *ls; char *row; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { ls->flags &= ~LSF_SHOW; /* @@ -255,7 +253,7 @@ int fd, mode, range; } if (release_data(mode)) { - for (prev = &light_base; (curr = *prev) != 0;) { + for (prev = &g.light_base; (curr = *prev) != 0;) { if (!curr->id.a_monst) { impossible("save_light_sources: no id! [range=%d]", range); is_global = 0; @@ -301,8 +299,8 @@ int fd; while (count-- > 0) { ls = (light_source *) alloc(sizeof(light_source)); mread(fd, (genericptr_t) ls, sizeof(light_source)); - ls->next = light_base; - light_base = ls; + ls->next = g.light_base; + g.light_base = ls; } } @@ -317,7 +315,7 @@ long *count, *size; Sprintf(hdrbuf, hdrfmt, (long) sizeof (light_source)); *count = *size = 0L; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { ++*count; *size += (long) sizeof *ls; } @@ -332,7 +330,7 @@ boolean ghostly; unsigned nid; light_source *ls; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { if (ls->flags & LSF_NEEDS_FIXUP) { if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) { if (ghostly) { @@ -371,7 +369,7 @@ boolean write_it; int count = 0, is_global; light_source *ls; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { if (!ls->id.a_monst) { impossible("maybe_write_ls: no id! [range=%d]", range); continue; @@ -408,7 +406,7 @@ light_sources_sanity_check() struct obj *otmp; unsigned int auint; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { if (!ls->id.a_monst) panic("insane light source: no id!"); if (ls->type == LS_OBJECT) { @@ -475,7 +473,7 @@ struct obj *src, *dest; { light_source *ls; - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) if (ls->type == LS_OBJECT && ls->id.a_obj == src) ls->id.a_obj = dest; src->lamplit = 0; @@ -486,7 +484,7 @@ struct obj *src, *dest; boolean any_light_source() { - return (boolean) (light_base != (light_source *) 0); + return (boolean) (g.light_base != (light_source *) 0); } /* @@ -500,7 +498,7 @@ int x, y; light_source *ls; struct obj *obj; - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) /* * Is this position check valid??? Can I assume that the positions * will always be correct because the objects would have been @@ -553,7 +551,7 @@ struct obj *src, *dest; { light_source *ls, *new_ls; - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) if (ls->type == LS_OBJECT && ls->id.a_obj == src) { /* * Insert the new source at beginning of list. This will @@ -569,8 +567,8 @@ struct obj *src, *dest; vision_full_recalc = 1; /* in case range changed */ } new_ls->id.a_obj = dest; - new_ls->next = light_base; - light_base = new_ls; + new_ls->next = g.light_base; + g.light_base = new_ls; dest->lamplit = 1; /* now an active light source */ } } @@ -587,7 +585,7 @@ struct obj *src, *dest; if (src != dest) end_burn(src, TRUE); /* extinguish candles */ - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) if (ls->type == LS_OBJECT && ls->id.a_obj == dest) { ls->range = candle_light_range(dest); vision_full_recalc = 1; /* in case range changed */ @@ -603,7 +601,7 @@ int new_radius; { light_source *ls; - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) if (ls->type == LS_OBJECT && ls->id.a_obj == obj) { if (new_radius != ls->range) vision_full_recalc = 1; @@ -709,10 +707,10 @@ wiz_light_sources() putstr(win, 0, buf); putstr(win, 0, ""); - if (light_base) { + if (g.light_base) { putstr(win, 0, "location range flags type id"); putstr(win, 0, "-------- ----- ------ ---- -------"); - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { Sprintf(buf, " %2d,%2d %2d 0x%04x %s %s", ls->x, ls->y, ls->range, ls->flags, (ls->type == LS_OBJECT diff --git a/src/makemon.c b/src/makemon.c index 4ecb2dc59..e4d40e887 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -2112,7 +2112,7 @@ struct monst *mtmp; MCORPSENM(mtmp) = NON_PM; } -static NEARDATA char syms[] = { +static const NEARDATA char syms[] = { MAXOCLASSES, MAXOCLASSES + 1, RING_CLASS, WAND_CLASS, WEAPON_CLASS, FOOD_CLASS, COIN_CLASS, SCROLL_CLASS, POTION_CLASS, ARMOR_CLASS, AMULET_CLASS, TOOL_CLASS, ROCK_CLASS, GEM_CLASS, SPBOOK_CLASS, diff --git a/src/mkmap.c b/src/mkmap.c index b953a3d47..26c534cd6 100644 --- a/src/mkmap.c +++ b/src/mkmap.c @@ -61,8 +61,8 @@ schar bg_typ; return levl[col][row].typ; } -static int dirs[16] = { -1, -1 /**/, -1, 0 /**/, -1, 1 /**/, 0, -1 /**/, - 0, 1 /**/, 1, -1 /**/, 1, 0 /**/, 1, 1 }; +static const int dirs[16] = { -1, -1 /**/, -1, 0 /**/, -1, 1 /**/, 0, -1 /**/, + 0, 1 /**/, 1, -1 /**/, 1, 0 /**/, 1, 1 }; STATIC_OVL void pass_one(bg_typ, fg_typ) diff --git a/src/mkmaze.c b/src/mkmaze.c index a2a072487..18622609a 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -1371,15 +1371,11 @@ fumaroles() * other source files, but they are all so nicely encapsulated here. */ -static struct bubble *bbubbles, *ebubbles; - -static struct trap *wportal; -static int xmin, ymin, xmax, ymax; /* level boundaries */ /* bubble movement boundaries */ -#define bxmin (xmin + 1) -#define bymin (ymin + 1) -#define bxmax (xmax - 1) -#define bymax (ymax - 1) +#define gbxmin (g.xmin + 1) +#define gbymin (g.ymin + 1) +#define gbxmax (g.xmax - 1) +#define gbymax (g.ymax - 1) STATIC_DCL void NDECL(set_wportal); STATIC_DCL void FDECL(mk_bubble, (int, int, int)); @@ -1398,7 +1394,7 @@ movebubbles() 1, 0, 0, 0, 0 }; /* set up the portal the first time bubbles are moved */ - if (!wportal) + if (!g.wportal) set_wportal(); vision_recalc(2); @@ -1412,7 +1408,7 @@ movebubbles() * Pick up everything inside of a bubble then fill all bubble * locations. */ - for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { + for (b = up ? g.bbubbles : g.ebubbles; b; b = up ? b->next : b->prev) { if (b->cons) panic("movebubbles: cons != null"); for (i = 0, x = b->x; i < (int) b->bm[0]; i++, x++) @@ -1511,7 +1507,7 @@ movebubbles() * would eventually end up in the last bubble in the chain. */ up = !up; - for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { + for (b = up ? g.bbubbles : g.ebubbles; b; b = up ? b->next : b->prev) { int rx = rn2(3), ry = rn2(3); mv_bubble(b, b->dx + 1 - (!b->dx ? rx : (rx ? 1 : 0)), @@ -1570,14 +1566,14 @@ int fd, mode; if (perform_bwrite(mode)) { int n = 0; - for (b = bbubbles; b; b = b->next) + for (b = g.bbubbles; b; b = b->next) ++n; bwrite(fd, (genericptr_t) &n, sizeof(int)); - bwrite(fd, (genericptr_t) &xmin, sizeof(int)); - bwrite(fd, (genericptr_t) &ymin, sizeof(int)); - bwrite(fd, (genericptr_t) &xmax, sizeof(int)); - bwrite(fd, (genericptr_t) &ymax, sizeof(int)); - for (b = bbubbles; b; b = b->next) + bwrite(fd, (genericptr_t) &g.xmin, sizeof(int)); + bwrite(fd, (genericptr_t) &g.ymin, sizeof(int)); + bwrite(fd, (genericptr_t) &g.xmax, sizeof(int)); + bwrite(fd, (genericptr_t) &g.ymax, sizeof(int)); + for (b = g.bbubbles; b; b = b->next) bwrite(fd, (genericptr_t) b, sizeof(struct bubble)); } if (release_data(mode)) @@ -1596,24 +1592,24 @@ int fd; set_wportal(); mread(fd, (genericptr_t) &n, sizeof(int)); - mread(fd, (genericptr_t) &xmin, sizeof(int)); - mread(fd, (genericptr_t) &ymin, sizeof(int)); - mread(fd, (genericptr_t) &xmax, sizeof(int)); - mread(fd, (genericptr_t) &ymax, sizeof(int)); + mread(fd, (genericptr_t) &g.xmin, sizeof(int)); + mread(fd, (genericptr_t) &g.ymin, sizeof(int)); + mread(fd, (genericptr_t) &g.xmax, sizeof(int)); + mread(fd, (genericptr_t) &g.ymax, sizeof(int)); for (i = 0; i < n; i++) { btmp = b; b = (struct bubble *) alloc(sizeof(struct bubble)); mread(fd, (genericptr_t) b, sizeof(struct bubble)); - if (bbubbles) { + if (g.bbubbles) { btmp->next = b; b->prev = btmp; } else { - bbubbles = b; + g.bbubbles = b; b->prev = (struct bubble *) 0; } mv_bubble(b, 0, 0, TRUE); } - ebubbles = b; + g.ebubbles = b; b->next = (struct bubble *) 0; g.was_waterlevel = TRUE; } @@ -1652,8 +1648,8 @@ STATIC_OVL void set_wportal() { /* there better be only one magic portal on water level... */ - for (wportal = ftrap; wportal; wportal = wportal->ntrap) - if (wportal->ttyp == MAGIC_PORTAL) + for (g.wportal = ftrap; g.wportal; g.wportal = g.wportal->ntrap) + if (g.wportal->ttyp == MAGIC_PORTAL) return; impossible("set_wportal(): no portal!"); } @@ -1668,15 +1664,15 @@ setup_waterlevel() /* ouch, hardcoded... */ - xmin = 3; - ymin = 1; - xmax = 78; - ymax = 20; + g.xmin = 3; + g.ymin = 1; + g.xmax = 78; + g.ymax = 20; /* set hero's memory to water */ - for (x = xmin; x <= xmax; x++) - for (y = ymin; y <= ymax; y++) + for (x = g.xmin; x <= g.xmax; x++) + for (y = g.ymin; y <= g.ymax; y++) levl[x][y].glyph = Is_waterlevel(&u.uz) ? water_glyph : air_glyph; /* make bubbles */ @@ -1689,8 +1685,8 @@ setup_waterlevel() yskip = 3 + rn2(3); } - for (x = bxmin; x <= bxmax; x += xskip) - for (y = bymin; y <= bymax; y += yskip) + for (x = gbxmin; x <= gbxmax; x += xskip) + for (y = gbymin; y <= gbymax; y += yskip) mk_bubble(x, y, rn2(7)); } @@ -1701,11 +1697,11 @@ unsetup_waterlevel() /* free bubbles */ - for (b = bbubbles; b; b = bb) { + for (b = g.bbubbles; b; b = bb) { bb = b->next; free((genericptr_t) b); } - bbubbles = ebubbles = (struct bubble *) 0; + g.bbubbles = g.ebubbles = (struct bubble *) 0; } STATIC_OVL void @@ -1729,7 +1725,7 @@ int x, y, n; *bmask[] = { bm2, bm3, bm4, bm5, bm6, bm7, bm8 }; struct bubble *b; - if (x >= bxmax || y >= bymax) + if (x >= gbxmax || y >= gbymax) return; if (n >= SIZE(bmask)) { impossible("n too large (mk_bubble)"); @@ -1739,10 +1735,10 @@ int x, y, n; panic("bmask size is larger than MAX_BMASK"); } b = (struct bubble *) alloc(sizeof(struct bubble)); - if ((x + (int) bmask[n][0] - 1) > bxmax) - x = bxmax - bmask[n][0] + 1; - if ((y + (int) bmask[n][1] - 1) > bymax) - y = bymax - bmask[n][1] + 1; + if ((x + (int) bmask[n][0] - 1) > gbxmax) + x = gbxmax - bmask[n][0] + 1; + if ((y + (int) bmask[n][1] - 1) > gbymax) + y = gbymax - bmask[n][1] + 1; b->x = x; b->y = y; b->dx = 1 - rn2(3); @@ -1751,15 +1747,15 @@ int x, y, n; (void) memcpy((genericptr_t) b->bm, (genericptr_t) bmask[n], (bmask[n][1] + 2) * sizeof(b->bm[0])); b->cons = 0; - if (!bbubbles) - bbubbles = b; - if (ebubbles) { - ebubbles->next = b; - b->prev = ebubbles; + if (!g.bbubbles) + g.bbubbles = b; + if (g.ebubbles) { + g.ebubbles->next = b; + b->prev = g.ebubbles; } else b->prev = (struct bubble *) 0; b->next = (struct bubble *) 0; - ebubbles = b; + g.ebubbles = b; mv_bubble(b, 0, 0, TRUE); } @@ -1793,42 +1789,42 @@ boolean ini; * collision with level borders? * 1 = horizontal border, 2 = vertical, 3 = corner */ - if (b->x <= bxmin) + if (b->x <= gbxmin) colli |= 2; - if (b->y <= bymin) + if (b->y <= gbymin) colli |= 1; - if ((int) (b->x + b->bm[0] - 1) >= bxmax) + if ((int) (b->x + b->bm[0] - 1) >= gbxmax) colli |= 2; - if ((int) (b->y + b->bm[1] - 1) >= bymax) + if ((int) (b->y + b->bm[1] - 1) >= gbymax) colli |= 1; - if (b->x < bxmin) { - pline("bubble xmin: x = %d, xmin = %d", b->x, bxmin); - b->x = bxmin; + if (b->x < gbxmin) { + pline("bubble xmin: x = %d, xmin = %d", b->x, gbxmin); + b->x = gbxmin; } - if (b->y < bymin) { - pline("bubble ymin: y = %d, ymin = %d", b->y, bymin); - b->y = bymin; + if (b->y < gbymin) { + pline("bubble ymin: y = %d, ymin = %d", b->y, gbymin); + b->y = gbymin; } - if ((int) (b->x + b->bm[0] - 1) > bxmax) { + if ((int) (b->x + b->bm[0] - 1) > gbxmax) { pline("bubble xmax: x = %d, xmax = %d", b->x + b->bm[0] - 1, - bxmax); - b->x = bxmax - b->bm[0] + 1; + gbxmax); + b->x = gbxmax - b->bm[0] + 1; } - if ((int) (b->y + b->bm[1] - 1) > bymax) { + if ((int) (b->y + b->bm[1] - 1) > gbymax) { pline("bubble ymax: y = %d, ymax = %d", b->y + b->bm[1] - 1, - bymax); - b->y = bymax - b->bm[1] + 1; + gbymax); + b->y = gbymax - b->bm[1] + 1; } /* bounce if we're trying to move off the border */ - if (b->x == bxmin && dx < 0) + if (b->x == gbxmin && dx < 0) dx = -dx; - if (b->x + b->bm[0] - 1 == bxmax && dx > 0) + if (b->x + b->bm[0] - 1 == gbxmax && dx > 0) dx = -dx; - if (b->y == bymin && dy < 0) + if (b->y == gbymin && dy < 0) dy = -dy; - if (b->y + b->bm[1] - 1 == bymax && dy > 0) + if (b->y + b->bm[1] - 1 == gbymax && dy > 0) dy = -dy; b->x += dx; diff --git a/src/mkobj.c b/src/mkobj.c index 9a0ec48f2..31deb2087 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -1436,7 +1436,7 @@ register struct obj *obj; return (wt ? wt * (int) obj->quan : ((int) obj->quan + 1) >> 1); } -static int treefruits[] = { APPLE, ORANGE, PEAR, BANANA, EUCALYPTUS_LEAF }; +static const int treefruits[] = { APPLE, ORANGE, PEAR, BANANA, EUCALYPTUS_LEAF }; struct obj * rnd_treefruit_at(x, y) diff --git a/src/mkroom.c b/src/mkroom.c index d0995c7f1..51b5020e2 100644 --- a/src/mkroom.c +++ b/src/mkroom.c @@ -759,7 +759,7 @@ courtmon() #define NSTYPES (PM_CAPTAIN - PM_SOLDIER + 1) -static struct { +static const struct { unsigned pm; unsigned prob; } squadprob[NSTYPES] = { { PM_SOLDIER, 80 }, diff --git a/src/mon.c b/src/mon.c index 4b512d000..10803e874 100644 --- a/src/mon.c +++ b/src/mon.c @@ -3056,9 +3056,6 @@ struct monst *mon; } } -static short *animal_list = 0; /* list of PM values for animal monsters */ -static int animal_list_count; - void mon_animal_list(construct) boolean construct; @@ -3074,14 +3071,14 @@ boolean construct; animal_temp[n++] = i; /* if (n == 0) animal_temp[n++] = NON_PM; */ - animal_list = (short *) alloc(n * sizeof *animal_list); - (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp, - n * sizeof *animal_list); - animal_list_count = n; + g.animal_list = (short *) alloc(n * sizeof *g.animal_list); + (void) memcpy((genericptr_t) g.animal_list, (genericptr_t) animal_temp, + n * sizeof *g.animal_list); + g.animal_list_count = n; } else { /* release */ - if (animal_list) - free((genericptr_t) animal_list), animal_list = 0; - animal_list_count = 0; + if (g.animal_list) + free((genericptr_t) g.animal_list), g.animal_list = 0; + g.animal_list_count = 0; } } @@ -3090,15 +3087,15 @@ pick_animal() { int res; - if (!animal_list) + if (!g.animal_list) mon_animal_list(TRUE); - res = animal_list[rn2(animal_list_count)]; + res = g.animal_list[rn2(g.animal_list_count)]; /* rogue level should use monsters represented by uppercase letters only, but since chameleons aren't generated there (not uppercase!) we don't perform a lot of retries */ if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet)) - res = animal_list[rn2(animal_list_count)]; + res = g.animal_list[rn2(g.animal_list_count)]; return res; } diff --git a/src/muse.c b/src/muse.c index b15aebb3b..58a02bbde 100644 --- a/src/muse.c +++ b/src/muse.c @@ -35,16 +35,6 @@ STATIC_DCL boolean FDECL(muse_unslime, (struct monst *, struct obj *, STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *)); STATIC_DCL boolean FDECL(green_mon, (struct monst *)); -static struct musable { - struct obj *offensive; - struct obj *defensive; - struct obj *misc; - int has_offense, has_defense, has_misc; - /* =0, no capability; otherwise, different numbers. - * If it's an object, the object is also set (it's 0 otherwise). - */ -} m; - /* Any preliminary checks which may result in the monster being unable to use * the item. Returns 0 if nothing happened, 2 if the monster can't do * anything (i.e. it teleported) and 1 if it's dead. @@ -148,7 +138,7 @@ struct obj *obj; monkilled(mon, "", AD_RBRE); return 1; } - m.has_defense = m.has_offense = m.has_misc = 0; + g.m.has_defense = g.m.has_offense = g.m.has_misc = 0; /* Only one needed to be set to 0 but the others are harmless */ } return 0; @@ -265,18 +255,18 @@ struct monst *mtmp; { struct obj *obj = 0; if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_FULL_HEALING; return TRUE; } if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_EXTRA_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_EXTRA_HEALING; return TRUE; } if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_HEALING; return TRUE; } return FALSE; @@ -302,8 +292,8 @@ struct monst *mtmp; if (u.uswallow && stuck) return FALSE; - m.defensive = (struct obj *) 0; - m.has_defense = 0; + g.m.defensive = (struct obj *) 0; + g.m.has_defense = 0; /* since unicorn horns don't get used up, the monster would look * silly trying to use the same cursed horn round after round @@ -315,8 +305,8 @@ struct monst *mtmp; break; } if (obj || is_unicorn(mtmp->data)) { - m.defensive = obj; - m.has_defense = MUSE_UNICORN_HORN; + g.m.defensive = obj; + g.m.has_defense = MUSE_UNICORN_HORN; return TRUE; } } @@ -326,8 +316,8 @@ struct monst *mtmp; for (obj = mtmp->minvent; obj; obj = obj->nobj) { if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) { - m.defensive = obj; - m.has_defense = MUSE_LIZARD_CORPSE; + g.m.defensive = obj; + g.m.has_defense = MUSE_LIZARD_CORPSE; return TRUE; } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) { liztin = obj; @@ -335,9 +325,9 @@ struct monst *mtmp; } /* confused or stunned monster might not be able to open tin */ if (liztin && mcould_eat_tin(mtmp) && rn2(3)) { - m.defensive = liztin; + g.m.defensive = liztin; /* tin and corpse ultimately end up being handled the same */ - m.has_defense = MUSE_LIZARD_CORPSE; + g.m.has_defense = MUSE_LIZARD_CORPSE; return TRUE; } } @@ -374,22 +364,22 @@ struct monst *mtmp; } else if (levl[x][y].typ == STAIRS) { if (x == xdnstair && y == ydnstair) { if (!is_floater(mtmp->data)) - m.has_defense = MUSE_DOWNSTAIRS; + g.m.has_defense = MUSE_DOWNSTAIRS; } else if (x == xupstair && y == yupstair) { - m.has_defense = MUSE_UPSTAIRS; + g.m.has_defense = MUSE_UPSTAIRS; } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) { if (sstairs.up || !is_floater(mtmp->data)) - m.has_defense = MUSE_SSTAIRS; + g.m.has_defense = MUSE_SSTAIRS; } } else if (levl[x][y].typ == LADDER) { if (x == xupladder && y == yupladder) { - m.has_defense = MUSE_UP_LADDER; + g.m.has_defense = MUSE_UP_LADDER; } else if (x == xdnladder && y == ydnladder) { if (!is_floater(mtmp->data)) - m.has_defense = MUSE_DN_LADDER; + g.m.has_defense = MUSE_DN_LADDER; } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) { if (sstairs.up || !is_floater(mtmp->data)) - m.has_defense = MUSE_SSTAIRS; + g.m.has_defense = MUSE_SSTAIRS; } } else { /* Note: trap doors take precedence over teleport traps. */ @@ -434,12 +424,12 @@ struct monst *mtmp; && Can_fall_thru(&u.uz)) { g.trapx = xx; g.trapy = yy; - m.has_defense = MUSE_TRAPDOOR; + g.m.has_defense = MUSE_TRAPDOOR; break; /* no need to look at any other spots */ } else if (t->ttyp == TELEP_TRAP) { g.trapx = xx; g.trapy = yy; - m.has_defense = MUSE_TELEPORT_TRAP; + g.m.has_defense = MUSE_TELEPORT_TRAP; } } } @@ -462,8 +452,8 @@ struct monst *mtmp; if ((mon = m_at(xx, yy)) != 0 && is_mercenary(mon->data) && mon->data != &mons[PM_GUARD] && (mon->msleeping || !mon->mcanmove)) { - m.defensive = obj; - m.has_defense = MUSE_BUGLE; + g.m.defensive = obj; + g.m.has_defense = MUSE_BUGLE; goto toot; /* double break */ } } @@ -473,7 +463,7 @@ struct monst *mtmp; } /* use immediate physical escape prior to attempting magic */ - if (m.has_defense) /* stairs, trap door or tele-trap, bugle alert */ + if (g.m.has_defense) /* stairs, trap door or tele-trap, bugle alert */ goto botm; /* kludge to cut down on trap destruction (particularly portals) */ @@ -482,16 +472,16 @@ struct monst *mtmp; || t->ttyp == BEAR_TRAP)) t = 0; /* ok for monster to dig here */ -#define nomore(x) if (m.has_defense == x) continue; +#define nomore(x) if (g.m.has_defense == x) continue; /* selection could be improved by collecting all possibilities into an array and then picking one at random */ for (obj = mtmp->minvent; obj; obj = obj->nobj) { /* don't always use the same selection pattern */ - if (m.has_defense && !rn2(3)) + if (g.m.has_defense && !rn2(3)) break; /* nomore(MUSE_WAN_DIGGING); */ - if (m.has_defense == MUSE_WAN_DIGGING) + if (g.m.has_defense == MUSE_WAN_DIGGING) break; if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest @@ -504,8 +494,8 @@ struct monst *mtmp; && !(is_ice(x, y) || is_pool(x, y) || is_lava(x, y)) && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER] && In_V_tower(&u.uz))) { - m.defensive = obj; - m.has_defense = MUSE_WAN_DIGGING; + g.m.defensive = obj; + g.m.has_defense = MUSE_WAN_DIGGING; } nomore(MUSE_WAN_TELEPORTATION_SELF); nomore(MUSE_WAN_TELEPORTATION); @@ -518,8 +508,8 @@ struct monst *mtmp; */ if (!level.flags.noteleport || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) { - m.defensive = obj; - m.has_defense = (mon_has_amulet(mtmp)) + g.m.defensive = obj; + g.m.has_defense = (mon_has_amulet(mtmp)) ? MUSE_WAN_TELEPORTATION : MUSE_WAN_TELEPORTATION_SELF; } @@ -532,52 +522,52 @@ struct monst *mtmp; /* see WAN_TELEPORTATION case above */ if (!level.flags.noteleport || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) { - m.defensive = obj; - m.has_defense = MUSE_SCR_TELEPORTATION; + g.m.defensive = obj; + g.m.has_defense = MUSE_SCR_TELEPORTATION; } } if (mtmp->data != &mons[PM_PESTILENCE]) { nomore(MUSE_POT_FULL_HEALING); if (obj->otyp == POT_FULL_HEALING) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_FULL_HEALING; } nomore(MUSE_POT_EXTRA_HEALING); if (obj->otyp == POT_EXTRA_HEALING) { - m.defensive = obj; - m.has_defense = MUSE_POT_EXTRA_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_EXTRA_HEALING; } nomore(MUSE_WAN_CREATE_MONSTER); if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { - m.defensive = obj; - m.has_defense = MUSE_WAN_CREATE_MONSTER; + g.m.defensive = obj; + g.m.has_defense = MUSE_WAN_CREATE_MONSTER; } nomore(MUSE_POT_HEALING); if (obj->otyp == POT_HEALING) { - m.defensive = obj; - m.has_defense = MUSE_POT_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_HEALING; } } else { /* Pestilence */ nomore(MUSE_POT_FULL_HEALING); if (obj->otyp == POT_SICKNESS) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_FULL_HEALING; } nomore(MUSE_WAN_CREATE_MONSTER); if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { - m.defensive = obj; - m.has_defense = MUSE_WAN_CREATE_MONSTER; + g.m.defensive = obj; + g.m.has_defense = MUSE_WAN_CREATE_MONSTER; } } nomore(MUSE_SCR_CREATE_MONSTER); if (obj->otyp == SCR_CREATE_MONSTER) { - m.defensive = obj; - m.has_defense = MUSE_SCR_CREATE_MONSTER; + g.m.defensive = obj; + g.m.has_defense = MUSE_SCR_CREATE_MONSTER; } } botm: - return (boolean) !!m.has_defense; + return (boolean) !!g.m.has_defense; #undef nomore } @@ -590,7 +580,7 @@ use_defensive(mtmp) struct monst *mtmp; { int i, fleetim, how = 0; - struct obj *otmp = m.defensive; + struct obj *otmp = g.m.defensive; boolean vis, vismon, oseen; const char *Mnam; @@ -608,7 +598,7 @@ struct monst *mtmp; monflee(m, fleetim, FALSE, FALSE); \ } - switch (m.has_defense) { + switch (g.m.has_defense) { case MUSE_UNICORN_HORN: if (vismon) { if (otmp) @@ -968,7 +958,7 @@ struct monst *mtmp; return 0; /* i.e. an exploded wand */ default: impossible("%s wanted to perform action %d?", Monnam(mtmp), - m.has_defense); + g.m.has_defense); break; } return 0; @@ -1051,8 +1041,8 @@ struct monst *mtmp; boolean reflection_skip = (Reflecting && rn2(2)); struct obj *helmet = which_armor(mtmp, W_ARMH); - m.offensive = (struct obj *) 0; - m.has_offense = 0; + g.m.offensive = (struct obj *) 0; + g.m.has_offense = 0; if (mtmp->mpeaceful || is_animal(mtmp->data) || mindless(mtmp->data) || nohands(mtmp->data)) return FALSE; @@ -1068,55 +1058,55 @@ struct monst *mtmp; if (!lined_up(mtmp)) return FALSE; -#define nomore(x) if (m.has_offense == x) continue; +#define nomore(x) if (g.m.has_offense == x) continue; /* this picks the last viable item rather than prioritizing choices */ for (obj = mtmp->minvent; obj; obj = obj->nobj) { if (!reflection_skip) { nomore(MUSE_WAN_DEATH); if (obj->otyp == WAN_DEATH && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_DEATH; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_DEATH; } nomore(MUSE_WAN_SLEEP); if (obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_SLEEP; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_SLEEP; } nomore(MUSE_WAN_FIRE); if (obj->otyp == WAN_FIRE && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_FIRE; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_FIRE; } nomore(MUSE_FIRE_HORN); if (obj->otyp == FIRE_HORN && obj->spe > 0 && can_blow(mtmp)) { - m.offensive = obj; - m.has_offense = MUSE_FIRE_HORN; + g.m.offensive = obj; + g.m.has_offense = MUSE_FIRE_HORN; } nomore(MUSE_WAN_COLD); if (obj->otyp == WAN_COLD && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_COLD; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_COLD; } nomore(MUSE_FROST_HORN); if (obj->otyp == FROST_HORN && obj->spe > 0 && can_blow(mtmp)) { - m.offensive = obj; - m.has_offense = MUSE_FROST_HORN; + g.m.offensive = obj; + g.m.has_offense = MUSE_FROST_HORN; } nomore(MUSE_WAN_LIGHTNING); if (obj->otyp == WAN_LIGHTNING && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_LIGHTNING; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_LIGHTNING; } nomore(MUSE_WAN_MAGIC_MISSILE); if (obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_MAGIC_MISSILE; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_MAGIC_MISSILE; } } nomore(MUSE_WAN_STRIKING); if (obj->otyp == WAN_STRIKING && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_STRIKING; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_STRIKING; } #if 0 /* use_offensive() has had some code to support wand of teleportation * for a long time, but find_offensive() never selected one; @@ -1132,34 +1122,34 @@ struct monst *mtmp; || (u.ux == sstairs.sx && u.uy == sstairs.sy) || (u.ux == xupladder && u.uy == yupladder) || (u.ux == xdnladder && u.uy == ydnladder))) { - m.offensive = obj; - m.has_offense = MUSE_WAN_TELEPORTATION; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_TELEPORTATION; } #endif nomore(MUSE_POT_PARALYSIS); if (obj->otyp == POT_PARALYSIS && multi >= 0) { - m.offensive = obj; - m.has_offense = MUSE_POT_PARALYSIS; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_PARALYSIS; } nomore(MUSE_POT_BLINDNESS); if (obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) { - m.offensive = obj; - m.has_offense = MUSE_POT_BLINDNESS; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_BLINDNESS; } nomore(MUSE_POT_CONFUSION); if (obj->otyp == POT_CONFUSION) { - m.offensive = obj; - m.has_offense = MUSE_POT_CONFUSION; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_CONFUSION; } nomore(MUSE_POT_SLEEPING); if (obj->otyp == POT_SLEEPING) { - m.offensive = obj; - m.has_offense = MUSE_POT_SLEEPING; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_SLEEPING; } nomore(MUSE_POT_ACID); if (obj->otyp == POT_ACID) { - m.offensive = obj; - m.has_offense = MUSE_POT_ACID; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_ACID; } /* we can safely put this scroll here since the locations that * are in a 1 square radius are a subset of the locations that @@ -1175,20 +1165,20 @@ struct monst *mtmp; && mtmp->mcansee && haseyes(mtmp->data) && !Is_rogue_level(&u.uz) && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) { - m.offensive = obj; - m.has_offense = MUSE_SCR_EARTH; + g.m.offensive = obj; + g.m.has_offense = MUSE_SCR_EARTH; } #if 0 nomore(MUSE_SCR_FIRE); if (obj->otyp == SCR_FIRE && resists_fire(mtmp) && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2 && mtmp->mcansee && haseyes(mtmp->data)) { - m.offensive = obj; - m.has_offense = MUSE_SCR_FIRE; + g.m.offensive = obj; + g.m.has_offense = MUSE_SCR_FIRE; } #endif /* 0 */ } - return (boolean) !!m.has_offense; + return (boolean) !!g.m.has_offense; #undef nomore } @@ -1371,7 +1361,7 @@ use_offensive(mtmp) struct monst *mtmp; { int i; - struct obj *otmp = m.offensive; + struct obj *otmp = g.m.offensive; boolean oseen; /* offensive potions are not drunk, they're thrown */ @@ -1379,7 +1369,7 @@ struct monst *mtmp; return i; oseen = otmp && canseemon(mtmp); - switch (m.has_offense) { + switch (g.m.has_offense) { case MUSE_WAN_DEATH: case MUSE_WAN_SLEEP: case MUSE_WAN_FIRE: @@ -1534,7 +1524,7 @@ struct monst *mtmp; return 0; /* i.e. an exploded wand */ default: impossible("%s wanted to perform action %d?", Monnam(mtmp), - m.has_offense); + g.m.has_offense); break; } return 0; @@ -1610,8 +1600,8 @@ struct monst *mtmp; boolean immobile = (mdat->mmove == 0); boolean stuck = (mtmp == u.ustuck); - m.misc = (struct obj *) 0; - m.has_misc = 0; + g.m.misc = (struct obj *) 0; + g.m.has_misc = 0; if (is_animal(mdat) || mindless(mdat)) return 0; if (u.uswallow && stuck) @@ -1642,7 +1632,7 @@ struct monst *mtmp; if (t->ttyp == POLY_TRAP) { g.trapx = xx; g.trapy = yy; - m.has_misc = MUSE_POLY_TRAP; + g.m.has_misc = MUSE_POLY_TRAP; return TRUE; } } @@ -1650,7 +1640,7 @@ struct monst *mtmp; if (nohands(mdat)) return 0; -#define nomore(x) if (m.has_misc == x) continue +#define nomore(x) if (g.m.has_misc == x) continue /* * [bug?] Choice of item is not prioritized; the last viable one * in the monster's inventory will be chosen. @@ -1663,8 +1653,8 @@ struct monst *mtmp; if (obj->otyp == POT_GAIN_LEVEL && (!obj->cursed || (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) { - m.misc = obj; - m.has_misc = MUSE_POT_GAIN_LEVEL; + g.m.misc = obj; + g.m.has_misc = MUSE_POT_GAIN_LEVEL; } nomore(MUSE_BULLWHIP); if (obj->otyp == BULLWHIP && !mtmp->mpeaceful @@ -1678,8 +1668,8 @@ struct monst *mtmp; prevent cursed weapons from being targetted) */ && (canletgo(uwep, "") || (u.twoweap && canletgo(uswapwep, "")))) { - m.misc = obj; - m.has_misc = MUSE_BULLWHIP; + g.m.misc = obj; + g.m.has_misc = MUSE_BULLWHIP; } /* Note: peaceful/tame monsters won't make themselves * invisible unless you can see them. Not really right, but... @@ -1688,41 +1678,41 @@ struct monst *mtmp; if (obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && !mtmp->minvis && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible) && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { - m.misc = obj; - m.has_misc = MUSE_WAN_MAKE_INVISIBLE; + g.m.misc = obj; + g.m.has_misc = MUSE_WAN_MAKE_INVISIBLE; } nomore(MUSE_POT_INVISIBILITY); if (obj->otyp == POT_INVISIBILITY && !mtmp->minvis && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible) && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { - m.misc = obj; - m.has_misc = MUSE_POT_INVISIBILITY; + g.m.misc = obj; + g.m.has_misc = MUSE_POT_INVISIBILITY; } nomore(MUSE_WAN_SPEED_MONSTER); if (obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0 && mtmp->mspeed != MFAST && !mtmp->isgd) { - m.misc = obj; - m.has_misc = MUSE_WAN_SPEED_MONSTER; + g.m.misc = obj; + g.m.has_misc = MUSE_WAN_SPEED_MONSTER; } nomore(MUSE_POT_SPEED); if (obj->otyp == POT_SPEED && mtmp->mspeed != MFAST && !mtmp->isgd) { - m.misc = obj; - m.has_misc = MUSE_POT_SPEED; + g.m.misc = obj; + g.m.has_misc = MUSE_POT_SPEED; } nomore(MUSE_WAN_POLYMORPH); if (obj->otyp == WAN_POLYMORPH && obj->spe > 0 && (mtmp->cham == NON_PM) && mons[monsndx(mdat)].difficulty < 6) { - m.misc = obj; - m.has_misc = MUSE_WAN_POLYMORPH; + g.m.misc = obj; + g.m.has_misc = MUSE_WAN_POLYMORPH; } nomore(MUSE_POT_POLYMORPH); if (obj->otyp == POT_POLYMORPH && (mtmp->cham == NON_PM) && mons[monsndx(mdat)].difficulty < 6) { - m.misc = obj; - m.has_misc = MUSE_POT_POLYMORPH; + g.m.misc = obj; + g.m.has_misc = MUSE_POT_POLYMORPH; } } - return (boolean) !!m.has_misc; + return (boolean) !!g.m.has_misc; #undef nomore } @@ -1748,7 +1738,7 @@ use_misc(mtmp) struct monst *mtmp; { int i; - struct obj *otmp = m.misc; + struct obj *otmp = g.m.misc; boolean vis, vismon, oseen; char nambuf[BUFSZ]; @@ -1758,7 +1748,7 @@ struct monst *mtmp; vismon = canseemon(mtmp); oseen = otmp && vismon; - switch (m.has_misc) { + switch (g.m.has_misc) { case MUSE_POT_GAIN_LEVEL: mquaffmsg(mtmp, otmp); if (otmp->cursed) { @@ -1951,7 +1941,7 @@ struct monst *mtmp; return 0; /* i.e. an exploded wand */ default: impossible("%s wanted to perform action %d?", Monnam(mtmp), - m.has_misc); + g.m.has_misc); break; } return 0; From 06201ef83322ad20fda99b885cc62861ce06222e Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 24 Nov 2018 21:08:17 -0800 Subject: [PATCH 09/11] Moving globals to instance_globals part 10ish. --- include/decl.h | 3 +++ src/decl.c | 3 +++ src/o_init.c | 32 +++++++++++++++----------------- src/objnam.c | 2 +- src/options.c | 9 +++++++-- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/include/decl.h b/include/decl.h index 517abe793..1f49decbd 100644 --- a/include/decl.h +++ b/include/decl.h @@ -838,6 +838,9 @@ struct instance_globals { * remember who zapped the wand. */ struct musable m; + /* o_init.c */ + short disco[NUM_OBJECTS]; + /* objname.c */ /* distantname used by distant_name() to pass extra information to xname_flags(); it would be much cleaner if this were a parameter, diff --git a/src/decl.c b/src/decl.c index 267d038e7..3882fb8ae 100644 --- a/src/decl.c +++ b/src/decl.c @@ -499,6 +499,9 @@ const struct instance_globals g_init = { UNDEFINED_VALUE, /* zap_oseen */ UNDEFINED_VALUES, /* m */ + /* o_init.c */ + DUMMY, /* disco */ + /* objname.c */ 0, /* distantname */ diff --git a/src/o_init.c b/src/o_init.c index b4fc440ee..77cd02229 100644 --- a/src/o_init.c +++ b/src/o_init.c @@ -12,8 +12,6 @@ STATIC_DCL void NDECL(shuffle_all); STATIC_DCL boolean FDECL(interesting_to_discover, (int)); STATIC_DCL char *FDECL(oclass_to_name, (CHAR_P, char *)); -static NEARDATA short disco[NUM_OBJECTS] = DUMMY; - #ifdef USE_TILES STATIC_DCL void NDECL(shuffle_tiles); extern short glyph2tile[]; /* from tile.c */ @@ -296,7 +294,7 @@ int fd, mode; if (perform_bwrite(mode)) { bwrite(fd, (genericptr_t) bases, sizeof bases); - bwrite(fd, (genericptr_t) disco, sizeof disco); + bwrite(fd, (genericptr_t) g.disco, sizeof g.disco); bwrite(fd, (genericptr_t) objects, sizeof(struct objclass) * NUM_OBJECTS); } @@ -325,7 +323,7 @@ register int fd; unsigned int len; mread(fd, (genericptr_t) bases, sizeof bases); - mread(fd, (genericptr_t) disco, sizeof disco); + mread(fd, (genericptr_t) g.disco, sizeof g.disco); mread(fd, (genericptr_t) objects, sizeof(struct objclass) * NUM_OBJECTS); for (i = 0; i < NUM_OBJECTS; i++) if (objects[i].oc_uname) { @@ -351,10 +349,10 @@ boolean credit_hero; uname'd) or the next open slot; one or the other will be found before we reach the next class... */ - for (dindx = bases[acls]; disco[dindx] != 0; dindx++) - if (disco[dindx] == oindx) + for (dindx = bases[acls]; g.disco[dindx] != 0; dindx++) + if (g.disco[dindx] == oindx) break; - disco[dindx] = oindx; + g.disco[dindx] = oindx; if (mark_as_known) { objects[oindx].oc_name_known = 1; @@ -377,19 +375,19 @@ register int oindx; register boolean found = FALSE; /* find the object; shift those behind it forward one slot */ - for (dindx = bases[acls]; dindx < NUM_OBJECTS && disco[dindx] != 0 + for (dindx = bases[acls]; dindx < NUM_OBJECTS && g.disco[dindx] != 0 && objects[dindx].oc_class == acls; dindx++) if (found) - disco[dindx - 1] = disco[dindx]; - else if (disco[dindx] == oindx) + g.disco[dindx - 1] = g.disco[dindx]; + else if (g.disco[dindx] == oindx) found = TRUE; /* clear last slot */ if (found) - disco[dindx - 1] = 0; + g.disco[dindx - 1] = 0; else - impossible("named object not in disco"); + impossible("named object not in g.disco"); update_inventory(); } } @@ -405,7 +403,7 @@ register int i; } /* items that should stand out once they're known */ -static short uniq_objs[] = { +static const short uniq_objs[] = { AMULET_OF_YENDOR, SPE_BOOK_OF_THE_DEAD, CANDELABRUM_OF_INVOCATION, BELL_OF_OPENING, }; @@ -446,7 +444,7 @@ dodiscovered() /* free after Robert Viduya */ prev_class = oclass + 1; /* forced different from oclass */ for (i = bases[(int) oclass]; i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { - if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { + if ((dis = g.disco[i]) != 0 && interesting_to_discover(dis)) { ct++; if (oclass != prev_class) { putstr(tmpwin, iflags.menu_headings, @@ -543,7 +541,7 @@ doclassdisco() c = def_oc_syms[(int) oclass].sym; for (i = bases[(int) oclass]; i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) - if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { + if ((dis = g.disco[i]) != 0 && interesting_to_discover(dis)) { if (!index(discosyms, c)) { Sprintf(eos(discosyms), "%c", c); if (!traditional) { @@ -634,7 +632,7 @@ doclassdisco() putstr(tmpwin, iflags.menu_headings, buf); for (i = bases[(int) oclass]; i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) { - if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { + if ((dis = g.disco[i]) != 0 && interesting_to_discover(dis)) { Sprintf(buf, "%s %s", objects[dis].oc_pre_discovered ? "*" : " ", obj_typename(dis)); @@ -680,7 +678,7 @@ rename_disco() prev_class = oclass + 1; /* forced different from oclass */ for (i = bases[(int) oclass]; i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { - dis = disco[i]; + dis = g.disco[i]; if (!dis || !interesting_to_discover(dis)) continue; ct++; diff --git a/src/objnam.c b/src/objnam.c index 7d71725b7..3a40978a1 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -2055,7 +2055,7 @@ struct sing_plur { /* word pairs that don't fit into formula-based transformations; also some suffices which have very few--often one--matches or which aren't systematically reversible (knives, staves) */ -static struct sing_plur one_off[] = { +static const struct sing_plur one_off[] = { { "child", "children" }, /* (for wise guys who give their food funny names) */ { "cubus", "cubi" }, /* in-/suc-cubus */ diff --git a/src/options.c b/src/options.c index b9fda55da..041ab42ff 100644 --- a/src/options.c +++ b/src/options.c @@ -51,11 +51,11 @@ enum window_option_types { * option (e.g. time and timed_delay) the shorter one must come first. */ -static struct Bool_Opt { +static const struct Bool_Opt { const char *name; boolean *addr, initvalue; int optflags; -} boolopt[] = { +} boolopt_init[] = { { "acoustics", &flags.acoustics, TRUE, SET_IN_GAME }, #if defined(SYSFLAGS) && defined(AMIGA) /* Amiga altmeta causes Alt+key to be converted into Meta+key by @@ -449,6 +449,8 @@ static struct Comp_Opt { { (char *) 0, (char *) 0, 0, 0 } }; +static struct Bool_Opt boolopt[SIZE(boolopt_init)]; + #ifdef OPTION_LISTS_ONLY #undef static @@ -688,6 +690,8 @@ initoptions_init() #endif int i; + memcpy(boolopt, boolopt_init, sizeof(boolopt)); + /* set up the command parsing */ reset_commands(TRUE); /* init */ @@ -6719,4 +6723,5 @@ set_playmode() #endif /* OPTION_LISTS_ONLY */ + /*options.c*/ From 8950d01b1ad2f5ae0ab1d8e3c213b75c6e271927 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 24 Nov 2018 22:33:37 -0800 Subject: [PATCH 10/11] Last big push for moving globals to instance_globals. --- include/decl.h | 86 +++++++++++++++ include/hack.h | 4 + include/sp_lev.h | 3 - src/decl.c | 48 +++++++++ src/pager.c | 2 +- src/pickup.c | 47 ++++----- src/pline.c | 22 ++-- src/questpgr.c | 106 +++++++++---------- src/region.c | 2 +- src/shk.c | 60 +++++------ src/sp_lev.c | 255 +++++++++++++++++++++------------------------ src/spell.c | 42 ++++---- src/timeout.c | 52 +++++---- src/topten.c | 18 ++-- src/trap.c | 58 ++++------- src/windows.c | 10 +- sys/share/random.c | 4 +- 17 files changed, 441 insertions(+), 378 deletions(-) diff --git a/include/decl.h b/include/decl.h index 1f49decbd..250182289 100644 --- a/include/decl.h +++ b/include/decl.h @@ -621,6 +621,23 @@ struct musable { */ }; +struct h2o_ctx { + int dkn_boom, unk_boom; /* track dknown, !dknown separately */ + boolean ctx_valid; +}; + +struct launchplace { + struct obj *obj; + xchar x, y; +}; + +struct repo { /* repossession context */ + struct monst *shopkeeper; + coord location; +}; + + + /* 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. @@ -629,6 +646,7 @@ struct musable { #define BSIZE 20 #define WIZKIT_MAX 128 +#define CVT_BUF_SIZE 64 struct instance_globals { @@ -859,6 +877,14 @@ struct instance_globals { and use_container(). Also used by menu_loot() and container_gone(). */ struct obj *current_container; boolean abort_looting; + /* Value set by query_objlist() for n_or_more(). */ + long val_for_n_or_more; + /* list of valid menu classes for query_objlist() and allow_category callback + (with room for all object classes, 'u'npaid, BUCX, and terminator) */ + char valid_menu_classes[MAXOCLASSES + 1 + 4 + 1]; + boolean class_filter; + boolean bucx_filter; + boolean shop_filter; /* pline.c */ unsigned pline_flags; @@ -867,6 +893,9 @@ struct instance_globals { unsigned saved_pline_index; /* slot in saved_plines[] to use next */ char *saved_plines[DUMPLOG_MSG_COUNT]; #endif + /* work buffer for You(), &c and verbalize() */ + char *you_buf; + int you_buf_siz; /* polyself.c */ int sex_change_ok; /* controls whether taking on new form or becoming new @@ -884,6 +913,12 @@ struct instance_globals { int p_trouble; int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */ + /* questpgr.c */ + char cvt_buf[CVT_BUF_SIZE]; + struct qtlists qt_list; + struct dlb_handle *msg_file; + /* used by ldrname() and neminame(), then copied into cvt_buf */ + char nambuf[CVT_BUF_SIZE]; /* read.c */ boolean known; @@ -914,14 +949,60 @@ struct instance_globals { unsigned ustuck_id; /* need to preserve during save */ unsigned usteed_id; /* need to preserve during save */ + /* shk.c */ + /* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */ + char sell_response; + int sell_how; + /* can't just use sell_response='y' for auto_credit because the 'a' response + shouldn't carry over from ordinary selling to credit selling */ + boolean auto_credit; + struct repo repo; + /* sp_lev.c */ char *lev_message; lev_region *lregions; int num_lregions; + /* positions touched by level elements explicitly defined in the des-file */ + char SpLev_Map[COLNO][ROWNO]; + xchar xstart, ystart; + char xsize, ysize; + boolean splev_init_present; + boolean icedpools; + int mines_prize_count; + int soko_prize_count; /* achievements */ + struct obj *container_obj[MAX_CONTAINMENT]; + int container_idx; + struct monst *invent_carrying_monster; + aligntyp ralign[3]; + + /* spells.c */ + int spl_sortmode; /* index into spl_sortchoices[] */ + int *spl_orderindx; /* array of spl_book[] indices */ + + /* timeout.c */ + /* ordered timer list */ + struct fe *timer_base; /* "active" */ + unsigned long timer_id; + + /* topten.c */ + winid toptenwin; + /* trap.c */ int force_mintrap; /* mintrap() should take a flags argument, but for time being we use this */ + /* context for water_damage(), managed by water_damage_chain(); + when more than one stack of potions of acid explode while processing + a chain of objects, use alternate phrasing after the first message */ + struct h2o_ctx acid_ctx; + /* + * The following are used to track launched objects to + * prevent them from vanishing if you are killed. They + * will reappear at the launchplace in bones files. + */ + struct launchplace launchplace; + + /* u_init.c */ short nocreate; short nocreate2; @@ -930,8 +1011,13 @@ struct instance_globals { /* uhitm.c */ boolean override_confirmation; /* Used to flag attacks caused by Stormbringer's maliciousness. */ + /* weapon.c */ struct obj *propellor; + + /* windows.c */ + struct win_choices *last_winchoice; + /* zap.c */ int poly_zapped; boolean obj_zapped; diff --git a/include/hack.h b/include/hack.h index c82334a91..e551df36a 100644 --- a/include/hack.h +++ b/include/hack.h @@ -167,6 +167,9 @@ typedef struct strbuf { char buf[256]; } strbuf_t; +/* max. layers of object containment from sp_lev.h */ +#define MAX_CONTAINMENT 10 + /* str_or_len from sp_lev.h */ typedef union str_or_len { char *str; @@ -198,6 +201,7 @@ typedef struct { #include "context.h" #include "rm.h" #include "botl.h" +#include "qtext.h" /* Symbol offsets */ #define SYM_OFF_P (0) diff --git a/include/sp_lev.h b/include/sp_lev.h index 24b1ba169..f3ffe6a94 100644 --- a/include/sp_lev.h +++ b/include/sp_lev.h @@ -42,9 +42,6 @@ enum lvlinit_types { LVLINIT_ROGUE }; -/* max. layers of object containment */ -#define MAX_CONTAINMENT 10 - /* max. # of random registers */ #define MAX_REGISTERS 10 diff --git a/src/decl.c b/src/decl.c index 3882fb8ae..0540014e0 100644 --- a/src/decl.c +++ b/src/decl.c @@ -512,6 +512,11 @@ const struct instance_globals g_init = { 0, /* oldcap */ UNDEFINED_PTR, /* current_container */ UNDEFINED_VALUE, /* abort_looting */ + UNDEFINED_VALUE, /* val_for_n_or_more */ + UNDEFINED_VALUES, /* valid_menu_classes */ + UNDEFINED_VALUE, /* class_filter */ + UNDEFINED_VALUE, /* bucx_filter */ + UNDEFINED_VALUE, /* shop_filter */ /* pline.c */ 0, /* pline_flags */ @@ -520,6 +525,8 @@ const struct instance_globals g_init = { 0, /* saved_pline_index */ UNDEFINED_VALUES, #endif + NULL, /* you_buf */ + 0, /* you_buf_siz */ /* polyself.c */ 0, /* sex_change_ok */ @@ -534,6 +541,12 @@ const struct instance_globals g_init = { UNDEFINED_VALUE, /* p_trouble */ UNDEFINED_VALUE, /* p_type */ + /* questpgr.c */ + UNDEFINED_VALUES, /* cvt_buf */ + UNDEFINED_VALUES, /* qt_list */ + UNDEFINED_PTR, /* msg_file */ + UNDEFINED_VALUES, /* nambuf */ + /* read.c */ UNDEFINED_VALUE, /* known */ @@ -560,13 +573,45 @@ const struct instance_globals g_init = { 0, /* ustuck_id */ 0, /* usteed_id */ + /* shk.c */ + 'a', /* sell_response */ + SELL_NORMAL, /* sell_how */ + FALSE, /* auto_credit */ + UNDEFINED_VALUES, /* repo */ + /* sp_lev.c */ NULL, /* lev_message */ NULL, /* lregions */ 0, /* num_lregions */ + UNDEFINED_VALUES, /* SplLev_Map */ + UNDEFINED_VALUE, /* xstart */ + UNDEFINED_VALUE, /* ystart */ + UNDEFINED_VALUE, /* xsize */ + UNDEFINED_VALUE, /* ysize */ + FALSE, /* splev_init_present */ + FALSE, /* icedpools */ + 0, /* mines_prize_count */ + 0, /* soki_prize_count */ + { UNDEFINED_PTR }, /* container_obj */ + 0, /* container_idx */ + NULL, /* invent_carrying_monster */ + { AM_CHAOTIC, AM_NEUTRAL, AM_LAWFUL }, /* ralign */ + + /* spells.c */ + 0, /* spl_sortmode */ + NULL, /* spl_orderindx */ + + /* timeout.c */ + UNDEFINED_PTR, /* timer_base */ + 1, /* timer_id */ + + /* topten.c */ + WIN_ERR, /* topten */ /* trap.c */ 0, /* force_mintrap */ + { 0, 0, FALSE }, + UNDEFINED_VALUES, /* u_init.c */ STRANGE_OBJECT, /* nocreate */ @@ -580,6 +625,9 @@ const struct instance_globals g_init = { /* weapon.c */ UNDEFINED_PTR, /* propellor */ + /* windows.c */ + NULL, /* last_winchoice */ + /* zap.c */ UNDEFINED_VALUE, /* poly_zap */ UNDEFINED_VALUE, /* obj_zapped */ diff --git a/src/pager.c b/src/pager.c index 219a92878..667885c8a 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1910,7 +1910,7 @@ domenucontrols(VOID_ARGS) } /* data for dohelp() */ -static struct { +static const struct { void NDECL((*f)); const char *text; } help_menu_items[] = { diff --git a/src/pickup.c b/src/pickup.c index 4127ade6b..e54c5e366 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -310,9 +310,6 @@ boolean picked_some; } } -/* Value set by query_objlist() for n_or_more(). */ -static long val_for_n_or_more; - /* query_objlist callback: return TRUE if obj's count is >= reference value */ STATIC_OVL boolean n_or_more(obj) @@ -320,20 +317,16 @@ struct obj *obj; { if (obj == uchain) return FALSE; - return (boolean) (obj->quan >= val_for_n_or_more); + return (boolean) (obj->quan >= g.val_for_n_or_more); } -/* list of valid menu classes for query_objlist() and allow_category callback - (with room for all object classes, 'u'npaid, BUCX, and terminator) */ -static char valid_menu_classes[MAXOCLASSES + 1 + 4 + 1]; -static boolean class_filter, bucx_filter, shop_filter; /* check valid_menu_classes[] for an entry; also used by askchain() */ boolean menu_class_present(c) int c; { - return (c && index(valid_menu_classes, c)) ? TRUE : FALSE; + return (c && index(g.valid_menu_classes, c)) ? TRUE : FALSE; } void @@ -344,26 +337,26 @@ int c; if (c == 0) { /* reset */ vmc_count = 0; - class_filter = bucx_filter = shop_filter = FALSE; + g.class_filter = g.bucx_filter = g.shop_filter = FALSE; } else if (!menu_class_present(c)) { - valid_menu_classes[vmc_count++] = (char) c; + g.valid_menu_classes[vmc_count++] = (char) c; /* categorize the new class */ switch (c) { case 'B': case 'U': case 'C': /*FALLTHRU*/ case 'X': - bucx_filter = TRUE; + g.bucx_filter = TRUE; break; case 'u': - shop_filter = TRUE; + g.shop_filter = TRUE; break; default: - class_filter = TRUE; + g.class_filter = TRUE; break; } } - valid_menu_classes[vmc_count] = '\0'; + g.valid_menu_classes[vmc_count] = '\0'; } /* query_objlist callback: return TRUE if not uchain */ @@ -394,12 +387,12 @@ struct obj *obj; * coins are either unknown or uncursed based on an option setting. */ if (obj->oclass == COIN_CLASS) - return class_filter - ? (index(valid_menu_classes, COIN_CLASS) ? TRUE : FALSE) - : shop_filter /* coins are never unpaid, but check anyway */ + return g.class_filter + ? (index(g.valid_menu_classes, COIN_CLASS) ? TRUE : FALSE) + : g.shop_filter /* coins are never unpaid, but check anyway */ ? (obj->unpaid ? TRUE : FALSE) - : bucx_filter - ? (index(valid_menu_classes, iflags.goldX ? 'X' : 'U') + : g.bucx_filter + ? (index(g.valid_menu_classes, iflags.goldX ? 'X' : 'U') ? TRUE : FALSE) : TRUE; /* catchall: no filters specified, so accept */ @@ -424,21 +417,21 @@ struct obj *obj; */ /* if class is expected but obj's class is not in the list, reject */ - if (class_filter && !index(valid_menu_classes, obj->oclass)) + if (g.class_filter && !index(g.valid_menu_classes, obj->oclass)) return FALSE; /* if unpaid is expected and obj isn't unpaid, reject (treat a container holding any unpaid object as unpaid even if isn't unpaid itself) */ - if (shop_filter && !obj->unpaid + if (g.shop_filter && !obj->unpaid && !(Has_contents(obj) && count_unpaid(obj->cobj) > 0)) return FALSE; /* check for particular bless/curse state */ - if (bucx_filter) { + if (g.bucx_filter) { /* first categorize this object's bless/curse state */ char bucx = !obj->bknown ? 'X' : obj->blessed ? 'B' : obj->cursed ? 'C' : 'U'; /* if its category is not in the list, reject */ - if (!index(valid_menu_classes, bucx)) + if (!index(g.valid_menu_classes, bucx)) return FALSE; } /* obj didn't fail any of the filter checks, so accept */ @@ -452,8 +445,8 @@ allow_cat_no_uchain(obj) struct obj *obj; { if (obj != uchain - && ((index(valid_menu_classes, 'u') && obj->unpaid) - || index(valid_menu_classes, obj->oclass))) + && ((index(g.valid_menu_classes, 'u') && obj->unpaid) + || index(g.valid_menu_classes, obj->oclass))) return TRUE; return FALSE; } @@ -569,7 +562,7 @@ int what; /* should be a long */ char qbuf[QBUFSZ]; Sprintf(qbuf, "Pick %d of what?", count); - val_for_n_or_more = count; /* set up callback selector */ + g.val_for_n_or_more = count; /* set up callback selector */ n = query_objlist(qbuf, objchain_p, traverse_how, &pick_list, PICK_ONE, n_or_more); /* correct counts, if any given */ diff --git a/src/pline.c b/src/pline.c index d7acef096..fd3e5a69c 100644 --- a/src/pline.c +++ b/src/pline.c @@ -219,29 +219,25 @@ VA_DECL(const char *, line) return; } -/* work buffer for You(), &c and verbalize() */ -static char *you_buf = 0; -static int you_buf_siz = 0; - static char * You_buf(siz) int siz; { - if (siz > you_buf_siz) { - if (you_buf) - free((genericptr_t) you_buf); - you_buf_siz = siz + 10; - you_buf = (char *) alloc((unsigned) you_buf_siz); + if (siz > g.you_buf_siz) { + if (g.you_buf) + free((genericptr_t) g.you_buf); + g.you_buf_siz = siz + 10; + g.you_buf = (char *) alloc((unsigned) g.you_buf_siz); } - return you_buf; + return g.you_buf; } void free_youbuf() { - if (you_buf) - free((genericptr_t) you_buf), you_buf = (char *) 0; - you_buf_siz = 0; + if (g.you_buf) + free((genericptr_t) g.you_buf), g.you_buf = (char *) 0; + g.you_buf_siz = 0; } /* `prefix' must be a string literal, not a pointer */ diff --git a/src/questpgr.c b/src/questpgr.c index e3ec48dfc..a82ae2991 100644 --- a/src/questpgr.c +++ b/src/questpgr.c @@ -31,12 +31,6 @@ STATIC_DCL void FDECL(deliver_by_pline, (struct qtmsg *)); STATIC_DCL void FDECL(deliver_by_window, (struct qtmsg *, int)); STATIC_DCL boolean FDECL(skip_pager, (BOOLEAN_P)); -static char cvt_buf[64]; -static struct qtlists qt_list; -static dlb *msg_file; -/* used by ldrname() and neminame(), then copied into cvt_buf */ -static char nambuf[sizeof cvt_buf]; - /* dump the character msg list to check appearance; build with DEBUG enabled and use DEBUGFILES=questpgr.c in sysconf file or environment */ @@ -49,8 +43,8 @@ dump_qtlist() if (!explicitdebug(__FILE__)) return; - for (msg = qt_list.chrole; msg->msgnum > 0; msg++) { - (void) dlb_fseek(msg_file, msg->offset, SEEK_SET); + for (msg = g.qt_list.chrole; msg->msgnum > 0; msg++) { + (void) dlb_fseek(g.msg_file, msg->offset, SEEK_SET); deliver_by_window(msg, NHW_MAP); } #endif /* DEBUG */ @@ -78,8 +72,8 @@ long hdr_offset; struct qtmsg *msg_list; int n_msgs; - (void) dlb_fseek(msg_file, hdr_offset, SEEK_SET); - Fread(&n_msgs, sizeof(int), 1, msg_file); + (void) dlb_fseek(g.msg_file, hdr_offset, SEEK_SET); + Fread(&n_msgs, sizeof(int), 1, g.msg_file); msg_list = (struct qtmsg *) alloc((unsigned) (n_msgs + 1) * sizeof (struct qtmsg)); @@ -87,7 +81,7 @@ long hdr_offset; * Load up the list. */ Fread((genericptr_t) msg_list, n_msgs * sizeof (struct qtmsg), 1, - msg_file); + g.msg_file); msg_list[n_msgs].msgnum = -1; return msg_list; @@ -100,8 +94,8 @@ load_qtlist() char qt_classes[N_HDR][LEN_HDR]; long qt_offsets[N_HDR]; - msg_file = dlb_fopen(QTEXT_FILE, RDBMODE); - if (!msg_file) + g.msg_file = dlb_fopen(QTEXT_FILE, RDBMODE); + if (!g.msg_file) panic("CANNOT OPEN QUEST TEXT FILE %s.", QTEXT_FILE); /* @@ -109,29 +103,29 @@ load_qtlist() * each header. */ - Fread(&n_classes, sizeof (int), 1, msg_file); - Fread(&qt_classes[0][0], sizeof (char) * LEN_HDR, n_classes, msg_file); - Fread(qt_offsets, sizeof (long), n_classes, msg_file); + Fread(&n_classes, sizeof (int), 1, g.msg_file); + Fread(&qt_classes[0][0], sizeof (char) * LEN_HDR, n_classes, g.msg_file); + Fread(qt_offsets, sizeof (long), n_classes, g.msg_file); /* * Now construct the message lists for quick reference later * on when we are actually paging the messages out. */ - qt_list.common = qt_list.chrole = (struct qtmsg *) 0; + g.qt_list.common = g.qt_list.chrole = (struct qtmsg *) 0; for (i = 0; i < n_classes; i++) { if (!strncmp(COMMON_ID, qt_classes[i], LEN_HDR)) - qt_list.common = construct_qtlist(qt_offsets[i]); + g.qt_list.common = construct_qtlist(qt_offsets[i]); else if (!strncmp(urole.filecode, qt_classes[i], LEN_HDR)) - qt_list.chrole = construct_qtlist(qt_offsets[i]); + g.qt_list.chrole = construct_qtlist(qt_offsets[i]); #if 0 /* UNUSED but available */ else if (!strncmp(urace.filecode, qt_classes[i], LEN_HDR)) - qt_list.chrace = construct_qtlist(qt_offsets[i]); + g.qt_list.chrace = construct_qtlist(qt_offsets[i]); #endif } - if (!qt_list.common || !qt_list.chrole) + if (!g.qt_list.common || !g.qt_list.chrole) impossible("load_qtlist: cannot load quest text."); dump_qtlist(); return; /* no ***DON'T*** close the msg_file */ @@ -141,12 +135,12 @@ load_qtlist() void unload_qtlist() { - if (msg_file) - (void) dlb_fclose(msg_file), msg_file = 0; - if (qt_list.common) - free((genericptr_t) qt_list.common), qt_list.common = 0; - if (qt_list.chrole) - free((genericptr_t) qt_list.chrole), qt_list.chrole = 0; + if (g.msg_file) + (void) dlb_fclose(g.msg_file), g.msg_file = 0; + if (g.qt_list.common) + free((genericptr_t) g.qt_list.common), g.qt_list.common = 0; + if (g.qt_list.chrole) + free((genericptr_t) g.qt_list.chrole), g.qt_list.chrole = 0; return; } @@ -175,9 +169,9 @@ ldrname() { int i = urole.ldrnum; - Sprintf(nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ", + Sprintf(g.nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ", mons[i].mname); - return nambuf; + return g.nambuf; } /* return your intermediate target string */ @@ -252,9 +246,9 @@ neminame() { int i = urole.neminum; - Sprintf(nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ", + Sprintf(g.nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ", mons[i].mname); - return nambuf; + return g.nambuf; } STATIC_OVL const char * @@ -289,8 +283,8 @@ char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */ * which genders[] doesn't handle; cvt_buf[] already contains name. */ if (who == 'o' - && (strstri(cvt_buf, "Eyes ") - || strcmpi(cvt_buf, makesingular(cvt_buf)))) { + && (strstri(g.cvt_buf, "Eyes ") + || strcmpi(g.cvt_buf, makesingular(g.cvt_buf)))) { pnoun = (lwhich == 'h') ? "they" : (lwhich == 'i') ? "them" : (lwhich == 'j') ? "their" : "?"; @@ -303,10 +297,10 @@ char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */ : (lwhich == 'i') ? genders[godgend].him : (lwhich == 'j') ? genders[godgend].his : "?"; } - Strcpy(cvt_buf, pnoun); + Strcpy(g.cvt_buf, pnoun); /* capitalize for H,I,J */ if (lwhich != which) - cvt_buf[0] = highc(cvt_buf[0]); + g.cvt_buf[0] = highc(g.cvt_buf[0]); return; } @@ -413,7 +407,7 @@ char c; str = ""; break; } - Strcpy(cvt_buf, str); + Strcpy(g.cvt_buf, str); } STATIC_OVL void @@ -438,17 +432,17 @@ char *in_line, *out_line; switch (*(++c)) { /* insert "a"/"an" prefix */ case 'A': - Strcat(cc, An(cvt_buf)); + Strcat(cc, An(g.cvt_buf)); cc += strlen(cc); continue; /* for */ case 'a': - Strcat(cc, an(cvt_buf)); + Strcat(cc, an(g.cvt_buf)); cc += strlen(cc); continue; /* for */ /* capitalize */ case 'C': - cvt_buf[0] = highc(cvt_buf[0]); + g.cvt_buf[0] = highc(g.cvt_buf[0]); break; /* replace name with pronoun; @@ -467,24 +461,24 @@ char *in_line, *out_line; /* pluralize */ case 'P': - cvt_buf[0] = highc(cvt_buf[0]); + g.cvt_buf[0] = highc(g.cvt_buf[0]); /*FALLTHRU*/ case 'p': - Strcpy(cvt_buf, makeplural(cvt_buf)); + Strcpy(g.cvt_buf, makeplural(g.cvt_buf)); break; /* append possessive suffix */ case 'S': - cvt_buf[0] = highc(cvt_buf[0]); + g.cvt_buf[0] = highc(g.cvt_buf[0]); /*FALLTHRU*/ case 's': - Strcpy(cvt_buf, s_suffix(cvt_buf)); + Strcpy(g.cvt_buf, s_suffix(g.cvt_buf)); break; /* strip any "the" prefix */ case 't': - if (!strncmpi(cvt_buf, "the ", 4)) { - Strcat(cc, &cvt_buf[4]); + if (!strncmpi(g.cvt_buf, "the ", 4)) { + Strcat(cc, &g.cvt_buf[4]); cc += strlen(cc); continue; /* for */ } @@ -494,8 +488,8 @@ char *in_line, *out_line; --c; /* undo switch increment */ break; } - Strcat(cc, cvt_buf); - cc += strlen(cvt_buf); + Strcat(cc, g.cvt_buf); + cc += strlen(g.cvt_buf); break; } /* else fall through */ @@ -519,7 +513,7 @@ struct qtmsg *qt_msg; *in_line = '\0'; for (size = 0; size < qt_msg->size; size += (long) strlen(in_line)) { - (void) dlb_fgets(in_line, sizeof in_line, msg_file); + (void) dlb_fgets(in_line, sizeof in_line, g.msg_file); convert_line(in_line, out_line); pline("%s", out_line); } @@ -549,7 +543,7 @@ int how; } #endif for (size = 0; size < qt_msg->size; size += (long) strlen(in_line)) { - (void) dlb_fgets(in_line, sizeof in_line, msg_file); + (void) dlb_fgets(in_line, sizeof in_line, g.msg_file); convert_line(in_line, out_line); putstr(datawin, 0, out_line); } @@ -560,7 +554,7 @@ int how; but have a one-line summary which is put there for ^P recall */ *out_line = '\0'; if (qt_msg->summary_size) { - (void) dlb_fgets(in_line, sizeof in_line, msg_file); + (void) dlb_fgets(in_line, sizeof in_line, g.msg_file); convert_line(in_line, out_line); #ifdef BETA } else if (qt_msg->delivery == 'c') { /* skip for 'qtdump' of 'p' */ @@ -582,7 +576,7 @@ boolean common; /* WIZKIT: suppress plot feedback if starting with quest artifact */ if (program_state.wizkit_wishing) return TRUE; - if (!(common ? qt_list.common : qt_list.chrole)) { + if (!(common ? g.qt_list.common : g.qt_list.chrole)) { panic("%s: no %s quest text data available", common ? "com_pager" : "qt_pager", common ? "common" : "role-specific"); @@ -601,12 +595,12 @@ int msgnum; if (skip_pager(TRUE)) return; - if (!(qt_msg = msg_in(qt_list.common, msgnum))) { + if (!(qt_msg = msg_in(g.qt_list.common, msgnum))) { impossible("com_pager: message %d not found.", msgnum); return; } - (void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET); + (void) dlb_fseek(g.msg_file, qt_msg->offset, SEEK_SET); if (qt_msg->delivery == 'p') deliver_by_pline(qt_msg); else if (msgnum == 1) @@ -625,7 +619,7 @@ int msgnum; if (skip_pager(FALSE)) return; - qt_msg = msg_in(qt_list.chrole, msgnum); + qt_msg = msg_in(g.qt_list.chrole, msgnum); if (!qt_msg) { /* some roles have an alternate message for return to the goal level when the quest artifact is absent (handled by caller) @@ -634,14 +628,14 @@ int msgnum; present which might not be true for wizard mode but we don't worry about quest message references in that situation */ if (msgnum == QT_ALTGOAL) - qt_msg = msg_in(qt_list.chrole, QT_NEXTGOAL); + qt_msg = msg_in(g.qt_list.chrole, QT_NEXTGOAL); } if (!qt_msg) { impossible("qt_pager: message %d not found.", msgnum); return; } - (void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET); + (void) dlb_fseek(g.msg_file, qt_msg->offset, SEEK_SET); if (qt_msg->delivery == 'p' && strcmp(windowprocs.name, "X11")) deliver_by_pline(qt_msg); else diff --git a/src/region.c b/src/region.c index ad94426fa..446d82685 100644 --- a/src/region.c +++ b/src/region.c @@ -45,7 +45,7 @@ NhRegion *FDECL(create_force_field, (XCHAR_P,XCHAR_P,int,long)); STATIC_DCL void FDECL(reset_region_mids, (NhRegion *)); -static callback_proc callbacks[] = { +static const callback_proc callbacks[] = { #define INSIDE_GAS_CLOUD 0 inside_gas_cloud, #define EXPIRE_GAS_CLOUD 1 diff --git a/src/shk.c b/src/shk.c index c2895a29f..9876bbe3f 100644 --- a/src/shk.c +++ b/src/shk.c @@ -1666,11 +1666,6 @@ boolean itemize; return buy; } -static struct repo { /* repossession context */ - struct monst *shopkeeper; - coord location; -} repo; - /* routine called after dying (or quitting) */ boolean paybill(croaked) @@ -1692,8 +1687,8 @@ int croaked; /* -1: escaped dungeon; 0: quit; 1: died */ which has been shut inside a statue] */ /* this is where inventory will end up if any shk takes it */ - repo.location.x = repo.location.y = 0; - repo.shopkeeper = 0; + g.repo.location.x = g.repo.location.y = 0; + g.repo.shopkeeper = 0; /* * Scan all shopkeepers on the level, to prioritize them: @@ -1882,17 +1877,17 @@ struct monst *shkp; oy = u.uy; } /* finish_paybill will deposit invent here */ - repo.location.x = ox; - repo.location.y = oy; - repo.shopkeeper = shkp; + g.repo.location.x = ox; + g.repo.location.y = oy; + g.repo.shopkeeper = shkp; } /* called at game exit, after inventory disclosure but before making bones */ void finish_paybill() { - struct monst *shkp = repo.shopkeeper; - int ox = repo.location.x, oy = repo.location.y; + struct monst *shkp = g.repo.shopkeeper; + int ox = g.repo.location.x, oy = g.repo.location.y; #if 0 /* don't bother */ if (ox == 0 && oy == 0) @@ -2846,13 +2841,6 @@ boolean peaceful, silent; return value; } -/* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */ -static char sell_response = 'a'; -static int sell_how = SELL_NORMAL; -/* can't just use sell_response='y' for auto_credit because the 'a' response - shouldn't carry over from ordinary selling to credit selling */ -static boolean auto_credit = FALSE; - void sellobj_state(deliberate) int deliberate; @@ -2863,9 +2851,9 @@ int deliberate; This retains the old pre-query risk that slippery fingers while in shops entailed: you drop it, you've lost it. */ - sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a'; - sell_how = deliberate; - auto_credit = FALSE; + g.sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a'; + g.sell_how = deliberate; + g.auto_credit = FALSE; } void @@ -2907,7 +2895,7 @@ xchar x, y; /* get one case out of the way: nothing to sell, and no gold */ if (!(isgold || cgold) - && ((offer + gltmp) == 0L || sell_how == SELL_DONTSELL)) { + && ((offer + gltmp) == 0L || g.sell_how == SELL_DONTSELL)) { boolean unpaid = is_unpaid(obj); if (container) { @@ -2919,7 +2907,7 @@ xchar x, y; } else obj->no_charge = 1; - if (!unpaid && (sell_how != SELL_DONTSELL) + if (!unpaid && (g.sell_how != SELL_DONTSELL) && !special_stock(obj, shkp, FALSE)) pline("%s seems uninterested.", Shknam(shkp)); return; @@ -2983,7 +2971,7 @@ xchar x, y; currency(eshkp->credit)); } - if (!offer || sell_how == SELL_DONTSELL) { + if (!offer || g.sell_how == SELL_DONTSELL) { if (!isgold) { if (container) dropped_container(obj, shkp, FALSE); @@ -3013,9 +3001,9 @@ xchar x, y; char c, qbuf[BUFSZ]; long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L); - if (sell_how == SELL_NORMAL || auto_credit) { - c = sell_response = 'y'; - } else if (sell_response != 'n') { + if (g.sell_how == SELL_NORMAL || g.auto_credit) { + c = g.sell_response = 'y'; + } else if (g.sell_response != 'n') { pline("%s cannot pay you at present.", Shknam(shkp)); Sprintf(qbuf, "Will you accept %ld %s in credit for ", tmpcr, currency(tmpcr)); @@ -3023,7 +3011,7 @@ xchar x, y; (obj->quan == 1L) ? "that" : "those")); if (c == 'a') { c = 'y'; - auto_credit = TRUE; + g.auto_credit = TRUE; } } else /* previously specified "quit" */ c = 'n'; @@ -3031,7 +3019,7 @@ xchar x, y; if (c == 'y') { shk_names_obj( shkp, obj, - (sell_how != SELL_NORMAL) + (g.sell_how != SELL_NORMAL) ? "traded %s for %ld zorkmid%s in %scredit." : "relinquish %s and acquire %ld zorkmid%s in %scredit.", tmpcr, (eshkp->credit > 0L) ? "additional " : ""); @@ -3039,7 +3027,7 @@ xchar x, y; subfrombill(obj, shkp); } else { if (c == 'q') - sell_response = 'n'; + g.sell_response = 'n'; if (container) dropped_container(obj, shkp, FALSE); if (!obj->unpaid) @@ -3052,7 +3040,7 @@ xchar x, y; if (short_funds) offer = shkmoney; - if (!sell_response) { + if (!g.sell_response) { long yourc = 0L, shksc; if (container) { @@ -3105,9 +3093,9 @@ xchar x, y; } else qbuf[0] = '\0'; /* just to pacify lint */ - switch (sell_response ? sell_response : ynaq(qbuf)) { + switch (g.sell_response ? g.sell_response : ynaq(qbuf)) { case 'q': - sell_response = 'n'; + g.sell_response = 'n'; /*FALLTHRU*/ case 'n': if (container) @@ -3117,7 +3105,7 @@ xchar x, y; subfrombill(obj, shkp); break; case 'a': - sell_response = 'y'; + g.sell_response = 'y'; /*FALLTHRU*/ case 'y': if (container) @@ -3127,7 +3115,7 @@ xchar x, y; subfrombill(obj, shkp); pay(-offer, shkp); shk_names_obj(shkp, obj, - (sell_how != SELL_NORMAL) + (g.sell_how != SELL_NORMAL) ? ((!ltmp && cltmp && only_partially_your_contents) ? "sold some items inside %s for %ld gold piece%s.%s" : "sold %s for %ld gold piece%s.%s") diff --git a/src/sp_lev.c b/src/sp_lev.c index c450109b2..604e2d719 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -189,21 +189,6 @@ STATIC_DCL boolean FDECL(sp_level_coder, (sp_lev *)); extern struct engr *head_engr; -/* positions touched by level elements explicitly defined in the des-file */ -static char SpLev_Map[COLNO][ROWNO]; - -static aligntyp ralign[3] = { AM_CHAOTIC, AM_NEUTRAL, AM_LAWFUL }; -static NEARDATA xchar xstart, ystart; -static NEARDATA char xsize, ysize; - -static boolean splev_init_present = FALSE; -static boolean icedpools = FALSE; -static int mines_prize_count = 0, soko_prize_count = 0; /* achievements */ - -static struct obj *container_obj[MAX_CONTAINMENT]; -static int container_idx = 0; -static struct monst *invent_carrying_monster = NULL; - #define SPLEV_STACK_RESERVE 128 void @@ -213,7 +198,7 @@ solidify_map() for (x = 0; x < COLNO; x++) for (y = 0; y < ROWNO; y++) - if (IS_STWALL(levl[x][y].typ) && !SpLev_Map[x][y]) + if (IS_STWALL(levl[x][y].typ) && !g.SpLev_Map[x][y]) levl[x][y].wall_info |= (W_NONDIGGABLE | W_NONPASSWALL); } @@ -656,13 +641,13 @@ shuffle_alignments() /* shuffle 3 alignments */ i = rn2(3); - atmp = ralign[2]; - ralign[2] = ralign[i]; - ralign[i] = atmp; + atmp = g.ralign[2]; + g.ralign[2] = g.ralign[i]; + g.ralign[i] = atmp; if (rn2(2)) { - atmp = ralign[1]; - ralign[1] = ralign[0]; - ralign[0] = atmp; + atmp = g.ralign[1]; + g.ralign[1] = g.ralign[0]; + g.ralign[0] = atmp; } } @@ -705,7 +690,7 @@ remove_boundary_syms() if (has_bounds) { for (x = 0; x < x_maze_max; x++) for (y = 0; y < y_maze_max; y++) - if ((levl[x][y].typ == CROSSWALL) && SpLev_Map[x][y]) + if ((levl[x][y].typ == CROSSWALL) && g.SpLev_Map[x][y]) levl[x][y].typ = ROOM; } } @@ -873,10 +858,10 @@ struct mkroom *croom; sx = croom->hx - mx + 1; sy = croom->hy - my + 1; } else { - mx = xstart; - my = ystart; - sx = xsize; - sy = ysize; + mx = g.xstart; + my = g.ystart; + sx = g.xsize; + sy = g.ysize; } if (*x >= 0) { /* normal locations */ @@ -1598,7 +1583,7 @@ struct mkroom *croom; ? Align2amask(noncoalignment(u.ualignbase[A_ORIGINAL])) : (m->align <= -(MAX_REGISTERS + 1)) ? induced_align(80) - : (m->align < 0 ? ralign[-m->align - 1] : m->align); + : (m->align < 0 ? g.ralign[-m->align - 1] : m->align); if (!class) pm = (struct permonst *) 0; @@ -1822,7 +1807,7 @@ struct mkroom *croom; if (m->has_invent) { discard_minvent(mtmp); - invent_carrying_monster = mtmp; + g.invent_carrying_monster = mtmp; } } } @@ -1933,8 +1918,8 @@ struct mkroom *croom; /* contents */ if (o->containment & SP_OBJ_CONTENT) { - if (!container_idx) { - if (!invent_carrying_monster) { + if (!g.container_idx) { + if (!g.invent_carrying_monster) { /*impossible("create_object: no container");*/ /* don't complain, the monster may be gone legally (eg. unique demon already generated) @@ -1948,25 +1933,25 @@ struct mkroom *croom; struct obj *objcheck = otmp; int inuse = -1; - for (ci = 0; ci < container_idx; ci++) - if (container_obj[ci] == objcheck) + for (ci = 0; ci < g.container_idx; ci++) + if (g.container_obj[ci] == objcheck) inuse = ci; remove_object(otmp); - if (mpickobj(invent_carrying_monster, otmp)) { + if (mpickobj(g.invent_carrying_monster, otmp)) { if (inuse > -1) { impossible( "container given to monster was merged or deallocated."); - for (ci = inuse; ci < container_idx - 1; ci++) - container_obj[ci] = container_obj[ci + 1]; - container_obj[container_idx] = NULL; - container_idx--; + for (ci = inuse; ci < g.container_idx - 1; ci++) + g.container_obj[ci] = g.container_obj[ci + 1]; + g.container_obj[g.container_idx] = NULL; + g.container_idx--; } /* we lost track of it. */ return; } } } else { - struct obj *cobj = container_obj[container_idx - 1]; + struct obj *cobj = g.container_obj[g.container_idx - 1]; remove_object(otmp); if (cobj) { @@ -1982,9 +1967,9 @@ struct mkroom *croom; /* container */ if (o->containment & SP_OBJ_CONTAINER) { delete_contents(otmp); - if (container_idx < MAX_CONTAINMENT) { - container_obj[container_idx] = otmp; - container_idx++; + if (g.container_idx < MAX_CONTAINMENT) { + g.container_obj[g.container_idx] = otmp; + g.container_idx++; } else impossible("create_object: too deeply nested containers."); } @@ -2039,17 +2024,17 @@ struct mkroom *croom; if (Is_mineend_level(&u.uz)) { if (otmp->otyp == iflags.mines_prize_type) { otmp->record_achieve_special = MINES_PRIZE; - if (++mines_prize_count > 1) + if (++g.mines_prize_count > 1) impossible(prize_warning, "mines end"); } } else if (Is_sokoend_level(&u.uz)) { if (otmp->otyp == iflags.soko_prize_type1) { otmp->record_achieve_special = SOKO_PRIZE1; - if (++soko_prize_count > 1) + if (++g.soko_prize_count > 1) impossible(prize_warning, "sokoban end"); } else if (otmp->otyp == iflags.soko_prize_type2) { otmp->record_achieve_special = SOKO_PRIZE2; - if (++soko_prize_count > 1) + if (++g.soko_prize_count > 1) impossible(prize_warning, "sokoban end"); } } @@ -2065,8 +2050,8 @@ struct mkroom *croom; boolean dealloced; (void) bury_an_obj(otmp, &dealloced); - if (dealloced && container_idx) { - container_obj[container_idx - 1] = NULL; + if (dealloced && g.container_idx) { + g.container_obj[g.container_idx - 1] = NULL; } } } @@ -2114,7 +2099,7 @@ struct mkroom *croom; ? Align2amask(noncoalignment(u.ualignbase[A_ORIGINAL])) : (a->align == -(MAX_REGISTERS + 1)) ? induced_align(80) - : (a->align < 0 ? ralign[-a->align - 1] : a->align); + : (a->align < 0 ? g.ralign[-a->align - 1] : a->align); levl[x][y].typ = ALTAR; levl[x][y].altarmask = amask; @@ -2608,7 +2593,7 @@ int humidity; y = rn1(y_maze_max - 3, 3); if (--tryct < 0) break; /* give up */ - } while (!(x % 2) || !(y % 2) || SpLev_Map[x][y] + } while (!(x % 2) || !(y % 2) || g.SpLev_Map[x][y] || !is_ok_location((schar) x, (schar) y, humidity)); m->x = (xchar) x, m->y = (xchar) y; @@ -2633,7 +2618,7 @@ fill_empty_maze() for (x = 2; x < x_maze_max; x++) for (y = 0; y < y_maze_max; y++) - if (SpLev_Map[x][y]) + if (g.SpLev_Map[x][y]) mapcount--; if ((mapcount > (int) (mapcountmax / 10))) { @@ -2796,7 +2781,7 @@ lev_init *linit; linit->lit = rn2(2); if (linit->filling > -1) lvlfill_solid(linit->filling, 0); - linit->icedpools = icedpools; + linit->icedpools = g.icedpools; mkmap(linit); break; } @@ -2929,9 +2914,9 @@ void spo_end_moninvent(coder) struct sp_coder *coder UNUSED; { - if (invent_carrying_monster) - m_dowear(invent_carrying_monster, TRUE); - invent_carrying_monster = NULL; + if (g.invent_carrying_monster) + m_dowear(g.invent_carrying_monster, TRUE); + g.invent_carrying_monster = NULL; } /*ARGUSED*/ @@ -2939,9 +2924,9 @@ void spo_pop_container(coder) struct sp_coder *coder UNUSED; { - if (container_idx > 0) { - container_idx--; - container_obj[container_idx] = NULL; + if (g.container_idx > 0) { + g.container_idx--; + g.container_obj[g.container_idx] = NULL; } } @@ -3303,7 +3288,7 @@ struct sp_coder *coder; if (lflags & GRAVEYARD) level.flags.graveyard = 1; if (lflags & ICEDPOOLS) - icedpools = TRUE; + g.icedpools = TRUE; if (lflags & SOLIDIFY) coder->solidify = TRUE; if (lflags & CORRMAZE) @@ -3328,7 +3313,7 @@ struct sp_coder *coder; || !OV_pop_i(filling) || !OV_pop_i(init_style)) return; - splev_init_present = TRUE; + g.splev_init_present = TRUE; init_lev.init_style = OV_i(init_style); init_lev.fg = OV_i(fg); @@ -3465,11 +3450,11 @@ struct sp_coder *coder; room, and there's no MAP. */ - if (xsize <= 1 && ysize <= 1) { - xstart = 1; - ystart = 0; - xsize = COLNO - 1; - ysize = ROWNO; + if (g.xsize <= 1 && g.ysize <= 1) { + g.xstart = 1; + g.ystart = 0; + g.xsize = COLNO - 1; + g.ysize = ROWNO; } } } @@ -3490,7 +3475,7 @@ struct sp_coder *coder; if ((badtrap = t_at(x, y)) != 0) deltrap(badtrap); mkstairs(x, y, (char) OV_i(up), coder->croom); - SpLev_Map[x][y] = 1; + g.SpLev_Map[x][y] = 1; opvar_free(scoord); opvar_free(up); @@ -3510,7 +3495,7 @@ struct sp_coder *coder; get_location_coord(&x, &y, DRY, coder->croom, OV_i(lcoord)); levl[x][y].typ = LADDER; - SpLev_Map[x][y] = 1; + g.SpLev_Map[x][y] = 1; if (OV_i(up)) { xupladder = x; yupladder = y; @@ -4294,7 +4279,7 @@ genericptr_t arg; } set_door_orientation(x, y); /* set/clear levl[x][y].horizontal */ levl[x][y].doormask = typ; - SpLev_Map[x][y] = 1; + g.SpLev_Map[x][y] = 1; } void @@ -4710,7 +4695,7 @@ struct sp_coder *coder; get_location_coord(&x, &y, DRY | WET | HOT, coder->croom, OV_i(dcoord)); if (!create_drawbridge(x, y, OV_i(dir), OV_i(db_open))) impossible("Cannot create drawbridge."); - SpLev_Map[x][y] = 1; + g.SpLev_Map[x][y] = 1; opvar_free(dcoord); opvar_free(db_open); @@ -4876,10 +4861,10 @@ struct sp_coder *coder; dy1 = (xchar) SP_REGION_Y1(OV_i(r)); dx2 = (xchar) SP_REGION_X2(OV_i(r)); dy2 = (xchar) SP_REGION_Y2(OV_i(r)); - wallify_map(dx1 < 0 ? (xstart - 1) : dx1, - dy1 < 0 ? (ystart - 1) : dy1, - dx2 < 0 ? (xstart + xsize + 1) : dx2, - dy2 < 0 ? (ystart + ysize + 1) : dy2); + wallify_map(dx1 < 0 ? (g.xstart - 1) : dx1, + dy1 < 0 ? (g.ystart - 1) : dy1, + dx2 < 0 ? (g.xstart + g.xsize + 1) : dx2, + dy2 < 0 ? (g.ystart + g.ysize + 1) : dy2); break; case 1: if (!OV_pop_typ(r, SPOVAR_SEL)) @@ -4914,15 +4899,15 @@ struct sp_coder *coder; tmpmazepart.halign = upc.x; tmpmazepart.valign = upc.y; - tmpxsize = xsize; - tmpysize = ysize; - tmpxstart = xstart; - tmpystart = ystart; + tmpxsize = g.xsize; + tmpysize = g.ysize; + tmpxstart = g.xstart; + tmpystart = g.ystart; halign = tmpmazepart.halign; valign = tmpmazepart.valign; - xsize = tmpmazepart.xsize; - ysize = tmpmazepart.ysize; + g.xsize = tmpmazepart.xsize; + g.ysize = tmpmazepart.ysize; switch (tmpmazepart.zaligntyp) { default: case 0: @@ -4930,73 +4915,73 @@ struct sp_coder *coder; case 1: switch ((int) halign) { case LEFT: - xstart = splev_init_present ? 1 : 3; + g.xstart = g.splev_init_present ? 1 : 3; break; case H_LEFT: - xstart = 2 + ((x_maze_max - 2 - xsize) / 4); + g.xstart = 2 + ((x_maze_max - 2 - g.xsize) / 4); break; case CENTER: - xstart = 2 + ((x_maze_max - 2 - xsize) / 2); + g.xstart = 2 + ((x_maze_max - 2 - g.xsize) / 2); break; case H_RIGHT: - xstart = 2 + ((x_maze_max - 2 - xsize) * 3 / 4); + g.xstart = 2 + ((x_maze_max - 2 - g.xsize) * 3 / 4); break; case RIGHT: - xstart = x_maze_max - xsize - 1; + g.xstart = x_maze_max - g.xsize - 1; break; } switch ((int) valign) { case TOP: - ystart = 3; + g.ystart = 3; break; case CENTER: - ystart = 2 + ((y_maze_max - 2 - ysize) / 2); + g.ystart = 2 + ((y_maze_max - 2 - g.ysize) / 2); break; case BOTTOM: - ystart = y_maze_max - ysize - 1; + g.ystart = y_maze_max - g.ysize - 1; break; } - if (!(xstart % 2)) - xstart++; - if (!(ystart % 2)) - ystart++; + if (!(g.xstart % 2)) + g.xstart++; + if (!(g.ystart % 2)) + g.ystart++; break; case 2: if (!coder->croom) { - xstart = 1; - ystart = 0; - xsize = COLNO - 1 - tmpmazepart.xsize; - ysize = ROWNO - tmpmazepart.ysize; + g.xstart = 1; + g.ystart = 0; + g.xsize = COLNO - 1 - tmpmazepart.xsize; + g.ysize = ROWNO - tmpmazepart.ysize; } get_location_coord(&halign, &valign, ANY_LOC, coder->croom, OV_i(mpa)); - xsize = tmpmazepart.xsize; - ysize = tmpmazepart.ysize; - xstart = halign; - ystart = valign; + g.xsize = tmpmazepart.xsize; + g.ysize = tmpmazepart.ysize; + g.xstart = halign; + g.ystart = valign; break; } - if (ystart < 0 || ystart + ysize > ROWNO) { + if (g.ystart < 0 || g.ystart + g.ysize > ROWNO) { /* try to move the start a bit */ - ystart += (ystart > 0) ? -2 : 2; - if (ysize == ROWNO) - ystart = 0; - if (ystart < 0 || ystart + ysize > ROWNO) - panic("reading special level with ysize too large"); + g.ystart += (g.ystart > 0) ? -2 : 2; + if (g.ysize == ROWNO) + g.ystart = 0; + if (g.ystart < 0 || g.ystart + g.ysize > ROWNO) + panic("reading special level with g.ysize too large"); } - if (xsize <= 1 && ysize <= 1) { - xstart = 1; - ystart = 0; - xsize = COLNO - 1; - ysize = ROWNO; + if (g.xsize <= 1 && g.ysize <= 1) { + g.xstart = 1; + g.ystart = 0; + g.xsize = COLNO - 1; + g.ysize = ROWNO; } else { xchar x, y, mptyp; /* Load the map */ - for (y = ystart; y < ystart + ysize; y++) - for (x = xstart; x < xstart + xsize; x++) { - mptyp = (mpmap->vardata.str[(y - ystart) * xsize - + (x - xstart)] - 1); + for (y = g.ystart; y < g.ystart + g.ysize; y++) + for (x = g.xstart; x < g.xstart + g.xsize; x++) { + mptyp = (mpmap->vardata.str[(y - g.ystart) * g.xsize + + (x - g.xstart)] - 1); if (mptyp >= MAX_TYPE) continue; levl[x][y].typ = mptyp; @@ -5006,7 +4991,7 @@ struct sp_coder *coder; levl[x][y].horizontal = 0; levl[x][y].roomno = 0; levl[x][y].edge = 0; - SpLev_Map[x][y] = 1; + g.SpLev_Map[x][y] = 1; /* * Set secret doors to closed (why not trapped too?). Set * the horizontal bit. @@ -5019,7 +5004,7 @@ struct sp_coder *coder; * (secret) door, then it is horizontal. This does * not allow (secret) doors to be corners of rooms. */ - if (x != xstart && (IS_WALL(levl[x - 1][y].typ) + if (x != g.xstart && (IS_WALL(levl[x - 1][y].typ) || levl[x - 1][y].horizontal)) levl[x][y].horizontal = 1; } else if (levl[x][y].typ == HWALL @@ -5027,17 +5012,17 @@ struct sp_coder *coder; levl[x][y].horizontal = 1; else if (levl[x][y].typ == LAVAPOOL) levl[x][y].lit = 1; - else if (splev_init_present && levl[x][y].typ == ICE) - levl[x][y].icedpool = icedpools ? ICED_POOL : ICED_MOAT; + else if (g.splev_init_present && levl[x][y].typ == ICE) + levl[x][y].icedpool = g.icedpools ? ICED_POOL : ICED_MOAT; } if (coder->lvl_is_joined) - remove_rooms(xstart, ystart, xstart + xsize, ystart + ysize); + remove_rooms(g.xstart, g.ystart, g.xstart + g.xsize, g.ystart + g.ysize); } if (!OV_i(mpkeepr)) { - xstart = tmpxstart; - ystart = tmpystart; - xsize = tmpxsize; - ysize = tmpysize; + g.xstart = tmpxstart; + g.ystart = tmpystart; + g.xsize = tmpxsize; + g.ysize = tmpysize; } opvar_free(mpxs); @@ -5316,12 +5301,12 @@ sp_lev *lvl; coder->exit_script = FALSE; coder->lvl_is_joined = 0; - splev_init_present = FALSE; - icedpools = FALSE; + g.splev_init_present = FALSE; + g.icedpools = FALSE; /* achievement tracking; static init would suffice except we need to reset if #wizmakemap is used to recreate mines' end or sokoban end; once either level is created, these values can be forgotten */ - mines_prize_count = soko_prize_count = 0; + g.mines_prize_count = g.soko_prize_count = 0; if (wizard) { char *met = nh_getenv("SPCODER_MAX_RUNTIME"); @@ -5338,19 +5323,19 @@ sp_lev *lvl; shuffle_alignments(); for (tmpi = 0; tmpi < MAX_CONTAINMENT; tmpi++) - container_obj[tmpi] = NULL; - container_idx = 0; + g.container_obj[tmpi] = NULL; + g.container_idx = 0; - invent_carrying_monster = NULL; + g.invent_carrying_monster = NULL; - (void) memset((genericptr_t) &SpLev_Map[0][0], 0, sizeof SpLev_Map); + (void) memset((genericptr_t) &g.SpLev_Map[0][0], 0, sizeof g.SpLev_Map); level.flags.is_maze_lev = 0; - xstart = 1; - ystart = 0; - xsize = COLNO - 1; - ysize = ROWNO; + g.xstart = 1; + g.ystart = 0; + g.xsize = COLNO - 1; + g.ysize = ROWNO; while (coder->frame->n_opcode < lvl->n_opcodes && !coder->exit_script) { coder->opcode = lvl->opcodes[coder->frame->n_opcode].opcode; @@ -5911,8 +5896,8 @@ sp_lev *lvl; if (!OV_pop_typ(pt, SPOVAR_SEL)) panic("no selection for rndcoord"); if (selection_rndcoord(pt, &x, &y, FALSE)) { - x -= xstart; - y -= ystart; + x -= g.xstart; + y -= g.ystart; } splev_stack_push(coder->stack, opvar_new_coord(x, y)); opvar_free(pt); diff --git a/src/spell.c b/src/spell.c index a7fd388ca..8cb3ecfa3 100644 --- a/src/spell.c +++ b/src/spell.c @@ -1377,8 +1377,6 @@ static const char *spl_sortchoices[NUM_SPELL_SORTBY] = { /* a menu choice rather than a sort choice */ "reassign casting letters to retain current order", }; -static int spl_sortmode = 0; /* index into spl_sortchoices[] */ -static int *spl_orderindx = 0; /* array of spl_book[] indices */ /* qsort callback routine */ STATIC_PTR int CFDECLSPEC @@ -1399,7 +1397,7 @@ const genericptr vptr2; levl1 = objects[otyp1].oc_level, levl2 = objects[otyp2].oc_level, skil1 = objects[otyp1].oc_skill, skil2 = objects[otyp2].oc_skill; - switch (spl_sortmode) { + switch (g.spl_sortmode) { case SORTBY_LETTER: return indx1 - indx2; case SORTBY_ALPHA: @@ -1450,40 +1448,40 @@ sortspells() int n; #endif - if (spl_sortmode == SORTBY_CURRENT) + if (g.spl_sortmode == SORTBY_CURRENT) return; for (n = 0; n < MAXSPELL && spellid(n) != NO_SPELL; ++n) continue; if (n < 2) return; /* not enough entries to need sorting */ - if (!spl_orderindx) { + if (!g.spl_orderindx) { /* we haven't done any sorting yet; list is in casting order */ - if (spl_sortmode == SORTBY_LETTER /* default */ - || spl_sortmode == SORTRETAINORDER) + if (g.spl_sortmode == SORTBY_LETTER /* default */ + || g.spl_sortmode == SORTRETAINORDER) return; /* allocate enough for full spellbook rather than just N spells */ - spl_orderindx = (int *) alloc(MAXSPELL * sizeof(int)); + g.spl_orderindx = (int *) alloc(MAXSPELL * sizeof(int)); for (i = 0; i < MAXSPELL; i++) - spl_orderindx[i] = i; + g.spl_orderindx[i] = i; } - if (spl_sortmode == SORTRETAINORDER) { + if (g.spl_sortmode == SORTRETAINORDER) { struct spell tmp_book[MAXSPELL]; /* sort spl_book[] rather than spl_orderindx[]; this also updates the index to reflect the new ordering (we could just free it since that ordering becomes the default) */ for (i = 0; i < MAXSPELL; i++) - tmp_book[i] = spl_book[spl_orderindx[i]]; + tmp_book[i] = spl_book[g.spl_orderindx[i]]; for (i = 0; i < MAXSPELL; i++) - spl_book[i] = tmp_book[i], spl_orderindx[i] = i; - spl_sortmode = SORTBY_LETTER; /* reset */ + spl_book[i] = tmp_book[i], g.spl_orderindx[i] = i; + g.spl_sortmode = SORTBY_LETTER; /* reset */ return; } /* usual case, sort the index rather than the spells themselves */ - qsort((genericptr_t) spl_orderindx, n, sizeof *spl_orderindx, spell_cmp); + qsort((genericptr_t) g.spl_orderindx, n, sizeof *g.spl_orderindx, spell_cmp); return; } @@ -1513,7 +1511,7 @@ spellsortmenu() } any.a_int = i + 1; add_menu(tmpwin, NO_GLYPH, &any, let, 0, ATR_NONE, spl_sortchoices[i], - (i == spl_sortmode) ? MENU_SELECTED : MENU_UNSELECTED); + (i == g.spl_sortmode) ? MENU_SELECTED : MENU_UNSELECTED); } end_menu(tmpwin, "View known spells list sorted"); @@ -1522,10 +1520,10 @@ spellsortmenu() if (n > 0) { choice = selected[0].item.a_int - 1; /* skip preselected entry if we have more than one item chosen */ - if (n > 1 && choice == spl_sortmode) + if (n > 1 && choice == g.spl_sortmode) choice = selected[1].item.a_int - 1; free((genericptr_t) selected); - spl_sortmode = choice; + g.spl_sortmode = choice; return TRUE; } return FALSE; @@ -1559,11 +1557,11 @@ dovspell() } } } - if (spl_orderindx) { - free((genericptr_t) spl_orderindx); - spl_orderindx = 0; + if (g.spl_orderindx) { + free((genericptr_t) g.spl_orderindx); + g.spl_orderindx = 0; } - spl_sortmode = SORTBY_LETTER; /* 0 */ + g.spl_sortmode = SORTBY_LETTER; /* 0 */ return 0; } @@ -1602,7 +1600,7 @@ int *spell_no; add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, buf, MENU_UNSELECTED); for (i = 0; i < MAXSPELL && spellid(i) != NO_SPELL; i++) { - splnum = !spl_orderindx ? i : spl_orderindx[i]; + splnum = !g.spl_orderindx ? i : g.spl_orderindx[i]; Sprintf(buf, fmt, spellname(splnum), spellev(splnum), spelltypemnemonic(spell_skilltype(spellid(splnum))), 100 - percent_success(splnum), diff --git a/src/timeout.c b/src/timeout.c index 29b740fcc..70657a5c6 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -1657,10 +1657,6 @@ STATIC_DCL boolean FDECL(mon_is_local, (struct monst *)); STATIC_DCL boolean FDECL(timer_is_local, (timer_element *)); STATIC_DCL int FDECL(maybe_write_timer, (int, int, BOOLEAN_P)); -/* ordered timer list */ -static timer_element *timer_base; /* "active" */ -static unsigned long timer_id = 1; - /* If defined, then include names when printing out the timer queue */ #define VERBOSE_TIMER @@ -1755,7 +1751,7 @@ wiz_timeout_queue() putstr(win, 0, ""); putstr(win, 0, "Active timeout queue:"); putstr(win, 0, ""); - print_queue(win, timer_base); + print_queue(win, g.timer_base); /* Timed properies: * check every one; the majority can't obtain temporary timeouts in @@ -1809,7 +1805,7 @@ timer_sanity_check() timer_element *curr; /* this should be much more complete */ - for (curr = timer_base; curr; curr = curr->next) + for (curr = g.timer_base; curr; curr = curr->next) if (curr->kind == TIMER_OBJECT) { struct obj *obj = curr->arg.a_obj; @@ -1834,9 +1830,9 @@ run_timers() * any time. The list is ordered, we are done when the first element * is in the future. */ - while (timer_base && timer_base->timeout <= monstermoves) { - curr = timer_base; - timer_base = curr->next; + while (g.timer_base && g.timer_base->timeout <= monstermoves) { + curr = g.timer_base; + g.timer_base = curr->next; if (curr->kind == TIMER_OBJECT) (curr->arg.a_obj)->timed--; @@ -1863,7 +1859,7 @@ anything *arg; gnu = (timer_element *) alloc(sizeof(timer_element)); (void) memset((genericptr_t)gnu, 0, sizeof(timer_element)); gnu->next = 0; - gnu->tid = timer_id++; + gnu->tid = g.timer_id++; gnu->timeout = monstermoves + when; gnu->kind = kind; gnu->needs_fixup = 0; @@ -1890,7 +1886,7 @@ anything *arg; timer_element *doomed; long timeout; - doomed = remove_timer(&timer_base, func_index, arg); + doomed = remove_timer(&g.timer_base, func_index, arg); if (doomed) { timeout = doomed->timeout; @@ -1914,7 +1910,7 @@ anything *arg; { timer_element *curr; - for (curr = timer_base; curr; curr = curr->next) { + for (curr = g.timer_base; curr; curr = curr->next) { if (curr->func_index == type && curr->arg.a_void == arg->a_void) return curr->timeout; } @@ -1931,7 +1927,7 @@ struct obj *src, *dest; int count; timer_element *curr; - for (count = 0, curr = timer_base; curr; curr = curr->next) + for (count = 0, curr = g.timer_base; curr; curr = curr->next) if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == src) { curr->arg.a_obj = dest; dest->timed++; @@ -1951,7 +1947,7 @@ struct obj *src, *dest; { timer_element *curr, *next_timer = 0; - for (curr = timer_base; curr; curr = next_timer) { + for (curr = g.timer_base; curr; curr = next_timer) { next_timer = curr->next; /* things may be inserted */ if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == src) { (void) start_timer(curr->timeout - monstermoves, TIMER_OBJECT, @@ -1970,13 +1966,13 @@ struct obj *obj; { timer_element *curr, *prev, *next_timer = 0; - for (prev = 0, curr = timer_base; curr; curr = next_timer) { + for (prev = 0, curr = g.timer_base; curr; curr = next_timer) { next_timer = curr->next; if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == obj) { if (prev) prev->next = curr->next; else - timer_base = curr->next; + g.timer_base = curr->next; if (timeout_funcs[curr->func_index].cleanup) (*timeout_funcs[curr->func_index].cleanup)(&curr->arg, curr->timeout); @@ -2013,14 +2009,14 @@ short func_index; timer_element *curr, *prev, *next_timer = 0; long where = (((long) x << 16) | ((long) y)); - for (prev = 0, curr = timer_base; curr; curr = next_timer) { + for (prev = 0, curr = g.timer_base; curr; curr = next_timer) { next_timer = curr->next; if (curr->kind == TIMER_LEVEL && curr->func_index == func_index && curr->arg.a_long == where) { if (prev) prev->next = curr->next; else - timer_base = curr->next; + g.timer_base = curr->next; if (timeout_funcs[curr->func_index].cleanup) (*timeout_funcs[curr->func_index].cleanup)(&curr->arg, curr->timeout); @@ -2043,7 +2039,7 @@ short func_index; timer_element *curr; long where = (((long) x << 16) | ((long) y)); - for (curr = timer_base; curr; curr = curr->next) { + for (curr = g.timer_base; curr; curr = curr->next) { if (curr->kind == TIMER_LEVEL && curr->func_index == func_index && curr->arg.a_long == where) return curr->timeout; @@ -2067,7 +2063,7 @@ timer_element *gnu; { timer_element *curr, *prev; - for (prev = 0, curr = timer_base; curr; prev = curr, curr = curr->next) + for (prev = 0, curr = g.timer_base; curr; prev = curr, curr = curr->next) if (curr->timeout >= gnu->timeout) break; @@ -2075,7 +2071,7 @@ timer_element *gnu; if (prev) prev->next = gnu; else - timer_base = gnu; + g.timer_base = gnu; } STATIC_OVL timer_element * @@ -2229,7 +2225,7 @@ boolean write_it; int count = 0; timer_element *curr; - for (curr = timer_base; curr; curr = curr->next) { + for (curr = g.timer_base; curr; curr = curr->next) { if (range == RANGE_GLOBAL) { /* global timers */ @@ -2275,7 +2271,7 @@ int fd, mode, range; if (perform_bwrite(mode)) { if (range == RANGE_GLOBAL) - bwrite(fd, (genericptr_t) &timer_id, sizeof(timer_id)); + bwrite(fd, (genericptr_t) &g.timer_id, sizeof(g.timer_id)); count = maybe_write_timer(fd, range, FALSE); bwrite(fd, (genericptr_t) &count, sizeof count); @@ -2283,14 +2279,14 @@ int fd, mode, range; } if (release_data(mode)) { - for (prev = 0, curr = timer_base; curr; curr = next_timer) { + for (prev = 0, curr = g.timer_base; curr; curr = next_timer) { next_timer = curr->next; /* in case curr is removed */ if (!(!!(range == RANGE_LEVEL) ^ !!timer_is_local(curr))) { if (prev) prev->next = curr->next; else - timer_base = curr->next; + g.timer_base = curr->next; free((genericptr_t) curr); /* prev stays the same */ } else { @@ -2314,7 +2310,7 @@ long adjust; /* how much to adjust timeout */ timer_element *curr; if (range == RANGE_GLOBAL) - mread(fd, (genericptr_t) &timer_id, sizeof timer_id); + mread(fd, (genericptr_t) &g.timer_id, sizeof g.timer_id); /* restore elements */ mread(fd, (genericptr_t) &count, sizeof count); @@ -2338,7 +2334,7 @@ long *count, *size; Sprintf(hdrbuf, hdrfmt, (long) sizeof (timer_element)); *count = *size = 0L; - for (te = timer_base; te; te = te->next) { + for (te = g.timer_base; te; te = te->next) { ++*count; *size += (long) sizeof *te; } @@ -2352,7 +2348,7 @@ boolean ghostly; timer_element *curr; unsigned nid; - for (curr = timer_base; curr; curr = curr->next) { + for (curr = g.timer_base; curr; curr = curr->next) { if (curr->needs_fixup) { if (curr->kind == TIMER_OBJECT) { if (ghostly) { diff --git a/src/topten.c b/src/topten.c index 6a226df3f..3e35a2fc7 100644 --- a/src/topten.c +++ b/src/topten.c @@ -82,8 +82,6 @@ STATIC_DCL void FDECL(nsb_mung_line, (char *)); STATIC_DCL void FDECL(nsb_unmung_line, (char *)); #endif -static winid toptenwin = WIN_ERR; - /* "killed by",&c ["an"] 'killer.name' */ void formatkiller(buf, siz, how, incl_helpless) @@ -161,20 +159,20 @@ STATIC_OVL void topten_print(x) const char *x; { - if (toptenwin == WIN_ERR) + if (g.toptenwin == WIN_ERR) raw_print(x); else - putstr(toptenwin, ATR_NONE, x); + putstr(g.toptenwin, ATR_NONE, x); } STATIC_OVL void topten_print_bold(x) const char *x; { - if (toptenwin == WIN_ERR) + if (g.toptenwin == WIN_ERR) raw_print_bold(x); else - putstr(toptenwin, ATR_BOLD, x); + putstr(g.toptenwin, ATR_BOLD, x); } int @@ -517,7 +515,7 @@ time_t when; return; if (iflags.toptenwin) { - toptenwin = create_nhwindow(NHW_TEXT); + g.toptenwin = create_nhwindow(NHW_TEXT); } #if defined(UNIX) || defined(VMS) || defined(__EMX__) @@ -769,13 +767,13 @@ time_t when; showwin: if (iflags.toptenwin && !done_stopprint) - display_nhwindow(toptenwin, 1); + display_nhwindow(g.toptenwin, 1); destroywin: if (!t0_used) dealloc_ttentry(t0); if (iflags.toptenwin) { - destroy_nhwindow(toptenwin); - toptenwin = WIN_ERR; + destroy_nhwindow(g.toptenwin); + g.toptenwin = WIN_ERR; } } diff --git a/src/trap.c b/src/trap.c index d3a219ce9..9111819fb 100644 --- a/src/trap.c +++ b/src/trap.c @@ -1681,36 +1681,26 @@ struct trap *trap; } } -/* - * The following are used to track launched objects to - * prevent them from vanishing if you are killed. They - * will reappear at the launchplace in bones files. - */ -static struct { - struct obj *obj; - xchar x, y; -} launchplace; - STATIC_OVL void launch_drop_spot(obj, x, y) struct obj *obj; xchar x, y; { if (!obj) { - launchplace.obj = (struct obj *) 0; - launchplace.x = 0; - launchplace.y = 0; + g.launchplace.obj = (struct obj *) 0; + g.launchplace.x = 0; + g.launchplace.y = 0; } else { - launchplace.obj = obj; - launchplace.x = x; - launchplace.y = y; + g.launchplace.obj = obj; + g.launchplace.x = x; + g.launchplace.y = y; } } boolean launch_in_progress() { - if (launchplace.obj) + if (g.launchplace.obj) return TRUE; return FALSE; } @@ -1718,9 +1708,9 @@ launch_in_progress() void force_launch_placement() { - if (launchplace.obj) { - launchplace.obj->otrapped = 0; - place_object(launchplace.obj, launchplace.x, launchplace.y); + if (g.launchplace.obj) { + g.launchplace.obj->otrapped = 0; + place_object(g.launchplace.obj, g.launchplace.x, g.launchplace.y); } } @@ -3467,14 +3457,6 @@ struct obj *obj; erode_obj(obj, (char *) 0, ERODE_CORRODE, EF_GREASE | EF_VERBOSE); } -/* context for water_damage(), managed by water_damage_chain(); - when more than one stack of potions of acid explode while processing - a chain of objects, use alternate phrasing after the first message */ -static struct h2o_ctx { - int dkn_boom, unk_boom; /* track dknown, !dknown separately */ - boolean ctx_valid; -} acid_ctx = { 0, 0, FALSE }; - /* Get an object wet and damage it appropriately. * "ostr", if present, is used instead of the object name in some * messages. @@ -3573,9 +3555,9 @@ boolean force; if (Blind && !carried(obj)) obj->dknown = 0; - if (acid_ctx.ctx_valid) - exploded = ((obj->dknown ? acid_ctx.dkn_boom - : acid_ctx.unk_boom) > 0); + if (g.acid_ctx.ctx_valid) + exploded = ((obj->dknown ? g.acid_ctx.dkn_boom + : g.acid_ctx.unk_boom) > 0); /* First message is * "a [potion| potion|potion of acid] explodes" * depending on obj->dknown (potion has been seen) and @@ -3591,11 +3573,11 @@ boolean force; !exploded ? (one ? "A" : "Some") : (one ? "Another" : "More"), bufp, vtense(bufp, "explode")); - if (acid_ctx.ctx_valid) { + if (g.acid_ctx.ctx_valid) { if (obj->dknown) - acid_ctx.dkn_boom++; + g.acid_ctx.dkn_boom++; else - acid_ctx.unk_boom++; + g.acid_ctx.unk_boom++; } setnotworn(obj); delobj(obj); @@ -3637,8 +3619,8 @@ boolean here; /* initialize acid context: so far, neither seen (dknown) potions of acid nor unseen have exploded during this water damage sequence */ - acid_ctx.dkn_boom = acid_ctx.unk_boom = 0; - acid_ctx.ctx_valid = TRUE; + g.acid_ctx.dkn_boom = g.acid_ctx.unk_boom = 0; + g.acid_ctx.ctx_valid = TRUE; for (; obj; obj = otmp) { otmp = here ? obj->nexthere : obj->nobj; @@ -3646,8 +3628,8 @@ boolean here; } /* reset acid context */ - acid_ctx.dkn_boom = acid_ctx.unk_boom = 0; - acid_ctx.ctx_valid = FALSE; + g.acid_ctx.dkn_boom = g.acid_ctx.unk_boom = 0; + g.acid_ctx.ctx_valid = FALSE; } /* diff --git a/src/windows.c b/src/windows.c index ad7b91b0d..5b7f5f616 100644 --- a/src/windows.c +++ b/src/windows.c @@ -185,8 +185,6 @@ wl_addtail(struct winlink *wl) } #endif /* WINCHAIN */ -static struct win_choices *last_winchoice = 0; - boolean genl_can_suspend_no(VOID_ARGS) { @@ -253,11 +251,11 @@ const char *s; if (!strcmpi(s, winchoices[i].procs->name)) { windowprocs = *winchoices[i].procs; - if (last_winchoice && last_winchoice->ini_routine) - (*last_winchoice->ini_routine)(WININIT_UNDO); + if (g.last_winchoice && g.last_winchoice->ini_routine) + (*g.last_winchoice->ini_routine)(WININIT_UNDO); if (winchoices[i].ini_routine) (*winchoices[i].ini_routine)(WININIT); - last_winchoice = &winchoices[i]; + g.last_winchoice = &winchoices[i]; return; } } @@ -374,7 +372,7 @@ commit_windowchain() p->nextlink->linkdata); } else { (void) (*p->wincp->chain_routine)(WINCHAIN_INIT, n, p->linkdata, - last_winchoice->procs, 0); + g.last_winchoice->procs, 0); } } diff --git a/sys/share/random.c b/sys/share/random.c index 3ec33b037..43eaa3aba 100644 --- a/sys/share/random.c +++ b/sys/share/random.c @@ -123,9 +123,9 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88"; #define MAX_TYPES 5 /* max number of types above */ -static int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; +static const int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; -static int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; +static const int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; /* * Initially, everything is set up as if from : From 022d33149b385e4cc6de0a2a8ca743c784941039 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 16 Dec 2018 20:18:52 -0800 Subject: [PATCH 11/11] Correct for rebasing mistakes. --- src/botl.c | 2 +- src/sys.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/botl.c b/src/botl.c index 698bf8bd1..c80f9a3ad 100644 --- a/src/botl.c +++ b/src/botl.c @@ -704,7 +704,7 @@ boolean *valsetlist; if (fld == BL_GOLD && (context.rndencode != oldrndencode || g.showsyms[COIN_CLASS + SYM_OFF_O] != oldgoldsym)) { - update_all = TRUE; /* chg = 2; */ + g.update_all = TRUE; /* chg = 2; */ oldrndencode = context.rndencode; oldgoldsym = g.showsyms[COIN_CLASS + SYM_OFF_O]; } diff --git a/src/sys.c b/src/sys.c index 51b966ff2..442a780cf 100644 --- a/src/sys.c +++ b/src/sys.c @@ -22,6 +22,7 @@ sys_early_init() { decl_globals_init(); objects_globals_init(); + monst_globals_init(); sysopt.support = (char *) 0; sysopt.recover = (char *) 0;