From 3645e415e391140d9bc92b4f2b056d9424e250f4 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 24 Nov 2018 02:13:54 -0800 Subject: [PATCH] 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 a441ef20e..5dc9e3bbd 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 3438a44b1..bf7cc9b5a 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 }; @@ -894,9 +892,6 @@ drop_done: return n_dropped; } -/* on a ladder, used in goto_level */ -static NEARDATA boolean at_ladder = FALSE; - /* the '>' command */ int dodown() @@ -1027,9 +1022,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; } @@ -1080,14 +1075,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() @@ -1224,7 +1217,7 @@ boolean at_stairs, falling, portal; (void) next_to_u(); return; } else - at_stairs = at_ladder = FALSE; + at_stairs = g.at_ladder = FALSE; } } @@ -1300,7 +1293,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); } @@ -1374,7 +1367,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); @@ -1387,10 +1380,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); @@ -1401,10 +1394,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); @@ -1414,13 +1407,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"); } } @@ -1618,9 +1611,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) @@ -1645,9 +1635,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 */ @@ -1659,8 +1649,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); @@ -1670,14 +1660,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 e9dd2481d..87991e3ac 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 @@ -514,7 +505,7 @@ update_l_symset(symp, val) struct symparse *symp; int val; { - l_syms[symp->idx] = val; + g.l_syms[symp->idx] = val; } void @@ -522,7 +513,7 @@ update_r_symset(symp, val) struct symparse *symp; int val; { - r_syms[symp->idx] = val; + g.r_syms[symp->idx] = val; } void @@ -530,20 +521,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 33539c91a..f0d0542c9 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__) @@ -912,18 +891,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; } @@ -1410,14 +1389,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 @@ -1468,7 +1447,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 93939ad86..87f25ce57 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 67966db5f..aa575c979 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 16cc32bde..ba7661407 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 aea499ffb..aeb9eaaf5 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, @@ -772,9 +772,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 @@ -789,7 +789,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); } @@ -798,10 +798,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 @@ -1158,7 +1158,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 @@ -2289,7 +2289,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( @@ -2314,7 +2314,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( @@ -2322,7 +2322,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 @@ -3780,10 +3780,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); @@ -3813,12 +3813,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); @@ -3851,10 +3851,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); @@ -5212,8 +5212,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); @@ -5295,7 +5295,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; } @@ -5339,8 +5339,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) @@ -5348,7 +5348,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 { @@ -5427,7 +5427,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); @@ -5612,8 +5612,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)); @@ -5672,8 +5672,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")) { @@ -5904,9 +5904,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 6982860c9..48632e780 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; }