Last big push for moving globals to instance_globals.

This commit is contained in:
Bart House
2018-11-24 22:33:37 -08:00
parent af949cb1df
commit cb42021389
17 changed files with 441 additions and 378 deletions

View File

@@ -621,6 +621,23 @@ struct musable {
*/
};
struct h2o_ctx {
int dkn_boom, unk_boom; /* track dknown, !dknown separately */
boolean ctx_valid;
};
struct launchplace {
struct obj *obj;
xchar x, y;
};
struct repo { /* repossession context */
struct monst *shopkeeper;
coord location;
};
/* instance_globals holds engine state that does not need to be
* persisted upon game exit. The initialization state is well defined
* an set in decl.c during early early engine initialization.
@@ -629,6 +646,7 @@ struct musable {
#define BSIZE 20
#define WIZKIT_MAX 128
#define CVT_BUF_SIZE 64
struct instance_globals {
@@ -859,6 +877,14 @@ struct instance_globals {
and use_container(). Also used by menu_loot() and container_gone(). */
struct obj *current_container;
boolean abort_looting;
/* Value set by query_objlist() for n_or_more(). */
long val_for_n_or_more;
/* list of valid menu classes for query_objlist() and allow_category callback
(with room for all object classes, 'u'npaid, BUCX, and terminator) */
char valid_menu_classes[MAXOCLASSES + 1 + 4 + 1];
boolean class_filter;
boolean bucx_filter;
boolean shop_filter;
/* pline.c */
unsigned pline_flags;
@@ -867,6 +893,9 @@ struct instance_globals {
unsigned saved_pline_index; /* slot in saved_plines[] to use next */
char *saved_plines[DUMPLOG_MSG_COUNT];
#endif
/* work buffer for You(), &c and verbalize() */
char *you_buf;
int you_buf_siz;
/* polyself.c */
int sex_change_ok; /* controls whether taking on new form or becoming new
@@ -884,6 +913,12 @@ struct instance_globals {
int p_trouble;
int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */
/* questpgr.c */
char cvt_buf[CVT_BUF_SIZE];
struct qtlists qt_list;
struct dlb_handle *msg_file;
/* used by ldrname() and neminame(), then copied into cvt_buf */
char nambuf[CVT_BUF_SIZE];
/* read.c */
boolean known;
@@ -914,14 +949,60 @@ struct instance_globals {
unsigned ustuck_id; /* need to preserve during save */
unsigned usteed_id; /* need to preserve during save */
/* shk.c */
/* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */
char sell_response;
int sell_how;
/* can't just use sell_response='y' for auto_credit because the 'a' response
shouldn't carry over from ordinary selling to credit selling */
boolean auto_credit;
struct repo repo;
/* sp_lev.c */
char *lev_message;
lev_region *lregions;
int num_lregions;
/* positions touched by level elements explicitly defined in the des-file */
char SpLev_Map[COLNO][ROWNO];
xchar xstart, ystart;
char xsize, ysize;
boolean splev_init_present;
boolean icedpools;
int mines_prize_count;
int soko_prize_count; /* achievements */
struct obj *container_obj[MAX_CONTAINMENT];
int container_idx;
struct monst *invent_carrying_monster;
aligntyp ralign[3];
/* spells.c */
int spl_sortmode; /* index into spl_sortchoices[] */
int *spl_orderindx; /* array of spl_book[] indices */
/* timeout.c */
/* ordered timer list */
struct fe *timer_base; /* "active" */
unsigned long timer_id;
/* topten.c */
winid toptenwin;
/* trap.c */
int force_mintrap; /* mintrap() should take a flags argument, but for time
being we use this */
/* context for water_damage(), managed by water_damage_chain();
when more than one stack of potions of acid explode while processing
a chain of objects, use alternate phrasing after the first message */
struct h2o_ctx acid_ctx;
/*
* The following are used to track launched objects to
* prevent them from vanishing if you are killed. They
* will reappear at the launchplace in bones files.
*/
struct launchplace launchplace;
/* u_init.c */
short nocreate;
short nocreate2;
@@ -930,8 +1011,13 @@ struct instance_globals {
/* uhitm.c */
boolean override_confirmation; /* Used to flag attacks caused by
Stormbringer's maliciousness. */
/* weapon.c */
struct obj *propellor;
/* windows.c */
struct win_choices *last_winchoice;
/* zap.c */
int poly_zapped;
boolean obj_zapped;

View File

@@ -167,6 +167,9 @@ typedef struct strbuf {
char buf[256];
} strbuf_t;
/* max. layers of object containment from sp_lev.h */
#define MAX_CONTAINMENT 10
/* str_or_len from sp_lev.h */
typedef union str_or_len {
char *str;
@@ -198,6 +201,7 @@ typedef struct {
#include "context.h"
#include "rm.h"
#include "botl.h"
#include "qtext.h"
/* Symbol offsets */
#define SYM_OFF_P (0)

View File

@@ -42,9 +42,6 @@ enum lvlinit_types {
LVLINIT_ROGUE
};
/* max. layers of object containment */
#define MAX_CONTAINMENT 10
/* max. # of random registers */
#define MAX_REGISTERS 10

View File

@@ -512,6 +512,11 @@ const struct instance_globals g_init = {
0, /* oldcap */
UNDEFINED_PTR, /* current_container */
UNDEFINED_VALUE, /* abort_looting */
UNDEFINED_VALUE, /* val_for_n_or_more */
UNDEFINED_VALUES, /* valid_menu_classes */
UNDEFINED_VALUE, /* class_filter */
UNDEFINED_VALUE, /* bucx_filter */
UNDEFINED_VALUE, /* shop_filter */
/* pline.c */
0, /* pline_flags */
@@ -520,6 +525,8 @@ const struct instance_globals g_init = {
0, /* saved_pline_index */
UNDEFINED_VALUES,
#endif
NULL, /* you_buf */
0, /* you_buf_siz */
/* polyself.c */
0, /* sex_change_ok */
@@ -534,6 +541,12 @@ const struct instance_globals g_init = {
UNDEFINED_VALUE, /* p_trouble */
UNDEFINED_VALUE, /* p_type */
/* questpgr.c */
UNDEFINED_VALUES, /* cvt_buf */
UNDEFINED_VALUES, /* qt_list */
UNDEFINED_PTR, /* msg_file */
UNDEFINED_VALUES, /* nambuf */
/* read.c */
UNDEFINED_VALUE, /* known */
@@ -560,13 +573,45 @@ const struct instance_globals g_init = {
0, /* ustuck_id */
0, /* usteed_id */
/* shk.c */
'a', /* sell_response */
SELL_NORMAL, /* sell_how */
FALSE, /* auto_credit */
UNDEFINED_VALUES, /* repo */
/* sp_lev.c */
NULL, /* lev_message */
NULL, /* lregions */
0, /* num_lregions */
UNDEFINED_VALUES, /* SplLev_Map */
UNDEFINED_VALUE, /* xstart */
UNDEFINED_VALUE, /* ystart */
UNDEFINED_VALUE, /* xsize */
UNDEFINED_VALUE, /* ysize */
FALSE, /* splev_init_present */
FALSE, /* icedpools */
0, /* mines_prize_count */
0, /* soki_prize_count */
{ UNDEFINED_PTR }, /* container_obj */
0, /* container_idx */
NULL, /* invent_carrying_monster */
{ AM_CHAOTIC, AM_NEUTRAL, AM_LAWFUL }, /* ralign */
/* spells.c */
0, /* spl_sortmode */
NULL, /* spl_orderindx */
/* timeout.c */
UNDEFINED_PTR, /* timer_base */
1, /* timer_id */
/* topten.c */
WIN_ERR, /* topten */
/* trap.c */
0, /* force_mintrap */
{ 0, 0, FALSE },
UNDEFINED_VALUES,
/* u_init.c */
STRANGE_OBJECT, /* nocreate */
@@ -580,6 +625,9 @@ const struct instance_globals g_init = {
/* weapon.c */
UNDEFINED_PTR, /* propellor */
/* windows.c */
NULL, /* last_winchoice */
/* zap.c */
UNDEFINED_VALUE, /* poly_zap */
UNDEFINED_VALUE, /* obj_zapped */

View File

@@ -1910,7 +1910,7 @@ domenucontrols(VOID_ARGS)
}
/* data for dohelp() */
static struct {
static const struct {
void NDECL((*f));
const char *text;
} help_menu_items[] = {

View File

@@ -310,9 +310,6 @@ boolean picked_some;
}
}
/* Value set by query_objlist() for n_or_more(). */
static long val_for_n_or_more;
/* query_objlist callback: return TRUE if obj's count is >= reference value */
STATIC_OVL boolean
n_or_more(obj)
@@ -320,20 +317,16 @@ struct obj *obj;
{
if (obj == uchain)
return FALSE;
return (boolean) (obj->quan >= val_for_n_or_more);
return (boolean) (obj->quan >= g.val_for_n_or_more);
}
/* list of valid menu classes for query_objlist() and allow_category callback
(with room for all object classes, 'u'npaid, BUCX, and terminator) */
static char valid_menu_classes[MAXOCLASSES + 1 + 4 + 1];
static boolean class_filter, bucx_filter, shop_filter;
/* check valid_menu_classes[] for an entry; also used by askchain() */
boolean
menu_class_present(c)
int c;
{
return (c && index(valid_menu_classes, c)) ? TRUE : FALSE;
return (c && index(g.valid_menu_classes, c)) ? TRUE : FALSE;
}
void
@@ -344,26 +337,26 @@ int c;
if (c == 0) { /* reset */
vmc_count = 0;
class_filter = bucx_filter = shop_filter = FALSE;
g.class_filter = g.bucx_filter = g.shop_filter = FALSE;
} else if (!menu_class_present(c)) {
valid_menu_classes[vmc_count++] = (char) c;
g.valid_menu_classes[vmc_count++] = (char) c;
/* categorize the new class */
switch (c) {
case 'B':
case 'U':
case 'C': /*FALLTHRU*/
case 'X':
bucx_filter = TRUE;
g.bucx_filter = TRUE;
break;
case 'u':
shop_filter = TRUE;
g.shop_filter = TRUE;
break;
default:
class_filter = TRUE;
g.class_filter = TRUE;
break;
}
}
valid_menu_classes[vmc_count] = '\0';
g.valid_menu_classes[vmc_count] = '\0';
}
/* query_objlist callback: return TRUE if not uchain */
@@ -394,12 +387,12 @@ struct obj *obj;
* coins are either unknown or uncursed based on an option setting.
*/
if (obj->oclass == COIN_CLASS)
return class_filter
? (index(valid_menu_classes, COIN_CLASS) ? TRUE : FALSE)
: shop_filter /* coins are never unpaid, but check anyway */
return g.class_filter
? (index(g.valid_menu_classes, COIN_CLASS) ? TRUE : FALSE)
: g.shop_filter /* coins are never unpaid, but check anyway */
? (obj->unpaid ? TRUE : FALSE)
: bucx_filter
? (index(valid_menu_classes, iflags.goldX ? 'X' : 'U')
: g.bucx_filter
? (index(g.valid_menu_classes, iflags.goldX ? 'X' : 'U')
? TRUE : FALSE)
: TRUE; /* catchall: no filters specified, so accept */
@@ -424,21 +417,21 @@ struct obj *obj;
*/
/* if class is expected but obj's class is not in the list, reject */
if (class_filter && !index(valid_menu_classes, obj->oclass))
if (g.class_filter && !index(g.valid_menu_classes, obj->oclass))
return FALSE;
/* if unpaid is expected and obj isn't unpaid, reject (treat a container
holding any unpaid object as unpaid even if isn't unpaid itself) */
if (shop_filter && !obj->unpaid
if (g.shop_filter && !obj->unpaid
&& !(Has_contents(obj) && count_unpaid(obj->cobj) > 0))
return FALSE;
/* check for particular bless/curse state */
if (bucx_filter) {
if (g.bucx_filter) {
/* first categorize this object's bless/curse state */
char bucx = !obj->bknown ? 'X'
: obj->blessed ? 'B' : obj->cursed ? 'C' : 'U';
/* if its category is not in the list, reject */
if (!index(valid_menu_classes, bucx))
if (!index(g.valid_menu_classes, bucx))
return FALSE;
}
/* obj didn't fail any of the filter checks, so accept */
@@ -452,8 +445,8 @@ allow_cat_no_uchain(obj)
struct obj *obj;
{
if (obj != uchain
&& ((index(valid_menu_classes, 'u') && obj->unpaid)
|| index(valid_menu_classes, obj->oclass)))
&& ((index(g.valid_menu_classes, 'u') && obj->unpaid)
|| index(g.valid_menu_classes, obj->oclass)))
return TRUE;
return FALSE;
}
@@ -569,7 +562,7 @@ int what; /* should be a long */
char qbuf[QBUFSZ];
Sprintf(qbuf, "Pick %d of what?", count);
val_for_n_or_more = count; /* set up callback selector */
g.val_for_n_or_more = count; /* set up callback selector */
n = query_objlist(qbuf, objchain_p, traverse_how,
&pick_list, PICK_ONE, n_or_more);
/* correct counts, if any given */

View File

@@ -219,29 +219,25 @@ VA_DECL(const char *, line)
return;
}
/* work buffer for You(), &c and verbalize() */
static char *you_buf = 0;
static int you_buf_siz = 0;
static char *
You_buf(siz)
int siz;
{
if (siz > you_buf_siz) {
if (you_buf)
free((genericptr_t) you_buf);
you_buf_siz = siz + 10;
you_buf = (char *) alloc((unsigned) you_buf_siz);
if (siz > g.you_buf_siz) {
if (g.you_buf)
free((genericptr_t) g.you_buf);
g.you_buf_siz = siz + 10;
g.you_buf = (char *) alloc((unsigned) g.you_buf_siz);
}
return you_buf;
return g.you_buf;
}
void
free_youbuf()
{
if (you_buf)
free((genericptr_t) you_buf), you_buf = (char *) 0;
you_buf_siz = 0;
if (g.you_buf)
free((genericptr_t) g.you_buf), g.you_buf = (char *) 0;
g.you_buf_siz = 0;
}
/* `prefix' must be a string literal, not a pointer */

View File

@@ -31,12 +31,6 @@ STATIC_DCL void FDECL(deliver_by_pline, (struct qtmsg *));
STATIC_DCL void FDECL(deliver_by_window, (struct qtmsg *, int));
STATIC_DCL boolean FDECL(skip_pager, (BOOLEAN_P));
static char cvt_buf[64];
static struct qtlists qt_list;
static dlb *msg_file;
/* used by ldrname() and neminame(), then copied into cvt_buf */
static char nambuf[sizeof cvt_buf];
/* dump the character msg list to check appearance;
build with DEBUG enabled and use DEBUGFILES=questpgr.c
in sysconf file or environment */
@@ -49,8 +43,8 @@ dump_qtlist()
if (!explicitdebug(__FILE__))
return;
for (msg = qt_list.chrole; msg->msgnum > 0; msg++) {
(void) dlb_fseek(msg_file, msg->offset, SEEK_SET);
for (msg = g.qt_list.chrole; msg->msgnum > 0; msg++) {
(void) dlb_fseek(g.msg_file, msg->offset, SEEK_SET);
deliver_by_window(msg, NHW_MAP);
}
#endif /* DEBUG */
@@ -78,8 +72,8 @@ long hdr_offset;
struct qtmsg *msg_list;
int n_msgs;
(void) dlb_fseek(msg_file, hdr_offset, SEEK_SET);
Fread(&n_msgs, sizeof(int), 1, msg_file);
(void) dlb_fseek(g.msg_file, hdr_offset, SEEK_SET);
Fread(&n_msgs, sizeof(int), 1, g.msg_file);
msg_list = (struct qtmsg *) alloc((unsigned) (n_msgs + 1)
* sizeof (struct qtmsg));
@@ -87,7 +81,7 @@ long hdr_offset;
* Load up the list.
*/
Fread((genericptr_t) msg_list, n_msgs * sizeof (struct qtmsg), 1,
msg_file);
g.msg_file);
msg_list[n_msgs].msgnum = -1;
return msg_list;
@@ -100,8 +94,8 @@ load_qtlist()
char qt_classes[N_HDR][LEN_HDR];
long qt_offsets[N_HDR];
msg_file = dlb_fopen(QTEXT_FILE, RDBMODE);
if (!msg_file)
g.msg_file = dlb_fopen(QTEXT_FILE, RDBMODE);
if (!g.msg_file)
panic("CANNOT OPEN QUEST TEXT FILE %s.", QTEXT_FILE);
/*
@@ -109,29 +103,29 @@ load_qtlist()
* each header.
*/
Fread(&n_classes, sizeof (int), 1, msg_file);
Fread(&qt_classes[0][0], sizeof (char) * LEN_HDR, n_classes, msg_file);
Fread(qt_offsets, sizeof (long), n_classes, msg_file);
Fread(&n_classes, sizeof (int), 1, g.msg_file);
Fread(&qt_classes[0][0], sizeof (char) * LEN_HDR, n_classes, g.msg_file);
Fread(qt_offsets, sizeof (long), n_classes, g.msg_file);
/*
* Now construct the message lists for quick reference later
* on when we are actually paging the messages out.
*/
qt_list.common = qt_list.chrole = (struct qtmsg *) 0;
g.qt_list.common = g.qt_list.chrole = (struct qtmsg *) 0;
for (i = 0; i < n_classes; i++) {
if (!strncmp(COMMON_ID, qt_classes[i], LEN_HDR))
qt_list.common = construct_qtlist(qt_offsets[i]);
g.qt_list.common = construct_qtlist(qt_offsets[i]);
else if (!strncmp(urole.filecode, qt_classes[i], LEN_HDR))
qt_list.chrole = construct_qtlist(qt_offsets[i]);
g.qt_list.chrole = construct_qtlist(qt_offsets[i]);
#if 0 /* UNUSED but available */
else if (!strncmp(urace.filecode, qt_classes[i], LEN_HDR))
qt_list.chrace = construct_qtlist(qt_offsets[i]);
g.qt_list.chrace = construct_qtlist(qt_offsets[i]);
#endif
}
if (!qt_list.common || !qt_list.chrole)
if (!g.qt_list.common || !g.qt_list.chrole)
impossible("load_qtlist: cannot load quest text.");
dump_qtlist();
return; /* no ***DON'T*** close the msg_file */
@@ -141,12 +135,12 @@ load_qtlist()
void
unload_qtlist()
{
if (msg_file)
(void) dlb_fclose(msg_file), msg_file = 0;
if (qt_list.common)
free((genericptr_t) qt_list.common), qt_list.common = 0;
if (qt_list.chrole)
free((genericptr_t) qt_list.chrole), qt_list.chrole = 0;
if (g.msg_file)
(void) dlb_fclose(g.msg_file), g.msg_file = 0;
if (g.qt_list.common)
free((genericptr_t) g.qt_list.common), g.qt_list.common = 0;
if (g.qt_list.chrole)
free((genericptr_t) g.qt_list.chrole), g.qt_list.chrole = 0;
return;
}
@@ -175,9 +169,9 @@ ldrname()
{
int i = urole.ldrnum;
Sprintf(nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ",
Sprintf(g.nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ",
mons[i].mname);
return nambuf;
return g.nambuf;
}
/* return your intermediate target string */
@@ -252,9 +246,9 @@ neminame()
{
int i = urole.neminum;
Sprintf(nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ",
Sprintf(g.nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ",
mons[i].mname);
return nambuf;
return g.nambuf;
}
STATIC_OVL const char *
@@ -289,8 +283,8 @@ char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */
* which genders[] doesn't handle; cvt_buf[] already contains name.
*/
if (who == 'o'
&& (strstri(cvt_buf, "Eyes ")
|| strcmpi(cvt_buf, makesingular(cvt_buf)))) {
&& (strstri(g.cvt_buf, "Eyes ")
|| strcmpi(g.cvt_buf, makesingular(g.cvt_buf)))) {
pnoun = (lwhich == 'h') ? "they"
: (lwhich == 'i') ? "them"
: (lwhich == 'j') ? "their" : "?";
@@ -303,10 +297,10 @@ char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */
: (lwhich == 'i') ? genders[godgend].him
: (lwhich == 'j') ? genders[godgend].his : "?";
}
Strcpy(cvt_buf, pnoun);
Strcpy(g.cvt_buf, pnoun);
/* capitalize for H,I,J */
if (lwhich != which)
cvt_buf[0] = highc(cvt_buf[0]);
g.cvt_buf[0] = highc(g.cvt_buf[0]);
return;
}
@@ -413,7 +407,7 @@ char c;
str = "";
break;
}
Strcpy(cvt_buf, str);
Strcpy(g.cvt_buf, str);
}
STATIC_OVL void
@@ -438,17 +432,17 @@ char *in_line, *out_line;
switch (*(++c)) {
/* insert "a"/"an" prefix */
case 'A':
Strcat(cc, An(cvt_buf));
Strcat(cc, An(g.cvt_buf));
cc += strlen(cc);
continue; /* for */
case 'a':
Strcat(cc, an(cvt_buf));
Strcat(cc, an(g.cvt_buf));
cc += strlen(cc);
continue; /* for */
/* capitalize */
case 'C':
cvt_buf[0] = highc(cvt_buf[0]);
g.cvt_buf[0] = highc(g.cvt_buf[0]);
break;
/* replace name with pronoun;
@@ -467,24 +461,24 @@ char *in_line, *out_line;
/* pluralize */
case 'P':
cvt_buf[0] = highc(cvt_buf[0]);
g.cvt_buf[0] = highc(g.cvt_buf[0]);
/*FALLTHRU*/
case 'p':
Strcpy(cvt_buf, makeplural(cvt_buf));
Strcpy(g.cvt_buf, makeplural(g.cvt_buf));
break;
/* append possessive suffix */
case 'S':
cvt_buf[0] = highc(cvt_buf[0]);
g.cvt_buf[0] = highc(g.cvt_buf[0]);
/*FALLTHRU*/
case 's':
Strcpy(cvt_buf, s_suffix(cvt_buf));
Strcpy(g.cvt_buf, s_suffix(g.cvt_buf));
break;
/* strip any "the" prefix */
case 't':
if (!strncmpi(cvt_buf, "the ", 4)) {
Strcat(cc, &cvt_buf[4]);
if (!strncmpi(g.cvt_buf, "the ", 4)) {
Strcat(cc, &g.cvt_buf[4]);
cc += strlen(cc);
continue; /* for */
}
@@ -494,8 +488,8 @@ char *in_line, *out_line;
--c; /* undo switch increment */
break;
}
Strcat(cc, cvt_buf);
cc += strlen(cvt_buf);
Strcat(cc, g.cvt_buf);
cc += strlen(g.cvt_buf);
break;
} /* else fall through */
@@ -519,7 +513,7 @@ struct qtmsg *qt_msg;
*in_line = '\0';
for (size = 0; size < qt_msg->size; size += (long) strlen(in_line)) {
(void) dlb_fgets(in_line, sizeof in_line, msg_file);
(void) dlb_fgets(in_line, sizeof in_line, g.msg_file);
convert_line(in_line, out_line);
pline("%s", out_line);
}
@@ -549,7 +543,7 @@ int how;
}
#endif
for (size = 0; size < qt_msg->size; size += (long) strlen(in_line)) {
(void) dlb_fgets(in_line, sizeof in_line, msg_file);
(void) dlb_fgets(in_line, sizeof in_line, g.msg_file);
convert_line(in_line, out_line);
putstr(datawin, 0, out_line);
}
@@ -560,7 +554,7 @@ int how;
but have a one-line summary which is put there for ^P recall */
*out_line = '\0';
if (qt_msg->summary_size) {
(void) dlb_fgets(in_line, sizeof in_line, msg_file);
(void) dlb_fgets(in_line, sizeof in_line, g.msg_file);
convert_line(in_line, out_line);
#ifdef BETA
} else if (qt_msg->delivery == 'c') { /* skip for 'qtdump' of 'p' */
@@ -582,7 +576,7 @@ boolean common;
/* WIZKIT: suppress plot feedback if starting with quest artifact */
if (program_state.wizkit_wishing)
return TRUE;
if (!(common ? qt_list.common : qt_list.chrole)) {
if (!(common ? g.qt_list.common : g.qt_list.chrole)) {
panic("%s: no %s quest text data available",
common ? "com_pager" : "qt_pager",
common ? "common" : "role-specific");
@@ -601,12 +595,12 @@ int msgnum;
if (skip_pager(TRUE))
return;
if (!(qt_msg = msg_in(qt_list.common, msgnum))) {
if (!(qt_msg = msg_in(g.qt_list.common, msgnum))) {
impossible("com_pager: message %d not found.", msgnum);
return;
}
(void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET);
(void) dlb_fseek(g.msg_file, qt_msg->offset, SEEK_SET);
if (qt_msg->delivery == 'p')
deliver_by_pline(qt_msg);
else if (msgnum == 1)
@@ -625,7 +619,7 @@ int msgnum;
if (skip_pager(FALSE))
return;
qt_msg = msg_in(qt_list.chrole, msgnum);
qt_msg = msg_in(g.qt_list.chrole, msgnum);
if (!qt_msg) {
/* some roles have an alternate message for return to the goal
level when the quest artifact is absent (handled by caller)
@@ -634,14 +628,14 @@ int msgnum;
present which might not be true for wizard mode but we don't
worry about quest message references in that situation */
if (msgnum == QT_ALTGOAL)
qt_msg = msg_in(qt_list.chrole, QT_NEXTGOAL);
qt_msg = msg_in(g.qt_list.chrole, QT_NEXTGOAL);
}
if (!qt_msg) {
impossible("qt_pager: message %d not found.", msgnum);
return;
}
(void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET);
(void) dlb_fseek(g.msg_file, qt_msg->offset, SEEK_SET);
if (qt_msg->delivery == 'p' && strcmp(windowprocs.name, "X11"))
deliver_by_pline(qt_msg);
else

View File

@@ -45,7 +45,7 @@ NhRegion *FDECL(create_force_field, (XCHAR_P,XCHAR_P,int,long));
STATIC_DCL void FDECL(reset_region_mids, (NhRegion *));
static callback_proc callbacks[] = {
static const callback_proc callbacks[] = {
#define INSIDE_GAS_CLOUD 0
inside_gas_cloud,
#define EXPIRE_GAS_CLOUD 1

View File

@@ -1666,11 +1666,6 @@ boolean itemize;
return buy;
}
static struct repo { /* repossession context */
struct monst *shopkeeper;
coord location;
} repo;
/* routine called after dying (or quitting) */
boolean
paybill(croaked)
@@ -1692,8 +1687,8 @@ int croaked; /* -1: escaped dungeon; 0: quit; 1: died */
which has been shut inside a statue] */
/* this is where inventory will end up if any shk takes it */
repo.location.x = repo.location.y = 0;
repo.shopkeeper = 0;
g.repo.location.x = g.repo.location.y = 0;
g.repo.shopkeeper = 0;
/*
* Scan all shopkeepers on the level, to prioritize them:
@@ -1882,17 +1877,17 @@ struct monst *shkp;
oy = u.uy;
}
/* finish_paybill will deposit invent here */
repo.location.x = ox;
repo.location.y = oy;
repo.shopkeeper = shkp;
g.repo.location.x = ox;
g.repo.location.y = oy;
g.repo.shopkeeper = shkp;
}
/* called at game exit, after inventory disclosure but before making bones */
void
finish_paybill()
{
struct monst *shkp = repo.shopkeeper;
int ox = repo.location.x, oy = repo.location.y;
struct monst *shkp = g.repo.shopkeeper;
int ox = g.repo.location.x, oy = g.repo.location.y;
#if 0 /* don't bother */
if (ox == 0 && oy == 0)
@@ -2861,13 +2856,6 @@ boolean peaceful, silent;
return value;
}
/* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */
static char sell_response = 'a';
static int sell_how = SELL_NORMAL;
/* can't just use sell_response='y' for auto_credit because the 'a' response
shouldn't carry over from ordinary selling to credit selling */
static boolean auto_credit = FALSE;
void
sellobj_state(deliberate)
int deliberate;
@@ -2878,9 +2866,9 @@ int deliberate;
This retains the old pre-query risk that slippery fingers while in
shops entailed: you drop it, you've lost it.
*/
sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a';
sell_how = deliberate;
auto_credit = FALSE;
g.sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a';
g.sell_how = deliberate;
g.auto_credit = FALSE;
}
void
@@ -2922,7 +2910,7 @@ xchar x, y;
/* get one case out of the way: nothing to sell, and no gold */
if (!(isgold || cgold)
&& ((offer + gltmp) == 0L || sell_how == SELL_DONTSELL)) {
&& ((offer + gltmp) == 0L || g.sell_how == SELL_DONTSELL)) {
boolean unpaid = is_unpaid(obj);
if (container) {
@@ -2934,7 +2922,7 @@ xchar x, y;
} else
obj->no_charge = 1;
if (!unpaid && (sell_how != SELL_DONTSELL)
if (!unpaid && (g.sell_how != SELL_DONTSELL)
&& !special_stock(obj, shkp, FALSE))
pline("%s seems uninterested.", Shknam(shkp));
return;
@@ -2998,7 +2986,7 @@ xchar x, y;
currency(eshkp->credit));
}
if (!offer || sell_how == SELL_DONTSELL) {
if (!offer || g.sell_how == SELL_DONTSELL) {
if (!isgold) {
if (container)
dropped_container(obj, shkp, FALSE);
@@ -3028,9 +3016,9 @@ xchar x, y;
char c, qbuf[BUFSZ];
long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L);
if (sell_how == SELL_NORMAL || auto_credit) {
c = sell_response = 'y';
} else if (sell_response != 'n') {
if (g.sell_how == SELL_NORMAL || g.auto_credit) {
c = g.sell_response = 'y';
} else if (g.sell_response != 'n') {
pline("%s cannot pay you at present.", Shknam(shkp));
Sprintf(qbuf, "Will you accept %ld %s in credit for ", tmpcr,
currency(tmpcr));
@@ -3038,7 +3026,7 @@ xchar x, y;
(obj->quan == 1L) ? "that" : "those"));
if (c == 'a') {
c = 'y';
auto_credit = TRUE;
g.auto_credit = TRUE;
}
} else /* previously specified "quit" */
c = 'n';
@@ -3046,7 +3034,7 @@ xchar x, y;
if (c == 'y') {
shk_names_obj(
shkp, obj,
(sell_how != SELL_NORMAL)
(g.sell_how != SELL_NORMAL)
? "traded %s for %ld zorkmid%s in %scredit."
: "relinquish %s and acquire %ld zorkmid%s in %scredit.",
tmpcr, (eshkp->credit > 0L) ? "additional " : "");
@@ -3054,7 +3042,7 @@ xchar x, y;
subfrombill(obj, shkp);
} else {
if (c == 'q')
sell_response = 'n';
g.sell_response = 'n';
if (container)
dropped_container(obj, shkp, FALSE);
if (!obj->unpaid)
@@ -3067,7 +3055,7 @@ xchar x, y;
if (short_funds)
offer = shkmoney;
if (!sell_response) {
if (!g.sell_response) {
long yourc = 0L, shksc;
if (container) {
@@ -3120,9 +3108,9 @@ xchar x, y;
} else
qbuf[0] = '\0'; /* just to pacify lint */
switch (sell_response ? sell_response : ynaq(qbuf)) {
switch (g.sell_response ? g.sell_response : ynaq(qbuf)) {
case 'q':
sell_response = 'n';
g.sell_response = 'n';
/*FALLTHRU*/
case 'n':
if (container)
@@ -3132,7 +3120,7 @@ xchar x, y;
subfrombill(obj, shkp);
break;
case 'a':
sell_response = 'y';
g.sell_response = 'y';
/*FALLTHRU*/
case 'y':
if (container)
@@ -3142,7 +3130,7 @@ xchar x, y;
subfrombill(obj, shkp);
pay(-offer, shkp);
shk_names_obj(shkp, obj,
(sell_how != SELL_NORMAL)
(g.sell_how != SELL_NORMAL)
? ((!ltmp && cltmp && only_partially_your_contents)
? "sold some items inside %s for %ld gold piece%s.%s"
: "sold %s for %ld gold piece%s.%s")

View File

@@ -189,21 +189,6 @@ STATIC_DCL boolean FDECL(sp_level_coder, (sp_lev *));
extern struct engr *head_engr;
/* positions touched by level elements explicitly defined in the des-file */
static char SpLev_Map[COLNO][ROWNO];
static aligntyp ralign[3] = { AM_CHAOTIC, AM_NEUTRAL, AM_LAWFUL };
static NEARDATA xchar xstart, ystart;
static NEARDATA char xsize, ysize;
static boolean splev_init_present = FALSE;
static boolean icedpools = FALSE;
static int mines_prize_count = 0, soko_prize_count = 0; /* achievements */
static struct obj *container_obj[MAX_CONTAINMENT];
static int container_idx = 0;
static struct monst *invent_carrying_monster = NULL;
#define SPLEV_STACK_RESERVE 128
void
@@ -213,7 +198,7 @@ solidify_map()
for (x = 0; x < COLNO; x++)
for (y = 0; y < ROWNO; y++)
if (IS_STWALL(levl[x][y].typ) && !SpLev_Map[x][y])
if (IS_STWALL(levl[x][y].typ) && !g.SpLev_Map[x][y])
levl[x][y].wall_info |= (W_NONDIGGABLE | W_NONPASSWALL);
}
@@ -656,13 +641,13 @@ shuffle_alignments()
/* shuffle 3 alignments */
i = rn2(3);
atmp = ralign[2];
ralign[2] = ralign[i];
ralign[i] = atmp;
atmp = g.ralign[2];
g.ralign[2] = g.ralign[i];
g.ralign[i] = atmp;
if (rn2(2)) {
atmp = ralign[1];
ralign[1] = ralign[0];
ralign[0] = atmp;
atmp = g.ralign[1];
g.ralign[1] = g.ralign[0];
g.ralign[0] = atmp;
}
}
@@ -705,7 +690,7 @@ remove_boundary_syms()
if (has_bounds) {
for (x = 0; x < x_maze_max; x++)
for (y = 0; y < y_maze_max; y++)
if ((levl[x][y].typ == CROSSWALL) && SpLev_Map[x][y])
if ((levl[x][y].typ == CROSSWALL) && g.SpLev_Map[x][y])
levl[x][y].typ = ROOM;
}
}
@@ -873,10 +858,10 @@ struct mkroom *croom;
sx = croom->hx - mx + 1;
sy = croom->hy - my + 1;
} else {
mx = xstart;
my = ystart;
sx = xsize;
sy = ysize;
mx = g.xstart;
my = g.ystart;
sx = g.xsize;
sy = g.ysize;
}
if (*x >= 0) { /* normal locations */
@@ -1598,7 +1583,7 @@ struct mkroom *croom;
? Align2amask(noncoalignment(u.ualignbase[A_ORIGINAL]))
: (m->align <= -(MAX_REGISTERS + 1))
? induced_align(80)
: (m->align < 0 ? ralign[-m->align - 1] : m->align);
: (m->align < 0 ? g.ralign[-m->align - 1] : m->align);
if (!class)
pm = (struct permonst *) 0;
@@ -1822,7 +1807,7 @@ struct mkroom *croom;
if (m->has_invent) {
discard_minvent(mtmp);
invent_carrying_monster = mtmp;
g.invent_carrying_monster = mtmp;
}
}
}
@@ -1933,8 +1918,8 @@ struct mkroom *croom;
/* contents */
if (o->containment & SP_OBJ_CONTENT) {
if (!container_idx) {
if (!invent_carrying_monster) {
if (!g.container_idx) {
if (!g.invent_carrying_monster) {
/*impossible("create_object: no container");*/
/* don't complain, the monster may be gone legally
(eg. unique demon already generated)
@@ -1948,25 +1933,25 @@ struct mkroom *croom;
struct obj *objcheck = otmp;
int inuse = -1;
for (ci = 0; ci < container_idx; ci++)
if (container_obj[ci] == objcheck)
for (ci = 0; ci < g.container_idx; ci++)
if (g.container_obj[ci] == objcheck)
inuse = ci;
remove_object(otmp);
if (mpickobj(invent_carrying_monster, otmp)) {
if (mpickobj(g.invent_carrying_monster, otmp)) {
if (inuse > -1) {
impossible(
"container given to monster was merged or deallocated.");
for (ci = inuse; ci < container_idx - 1; ci++)
container_obj[ci] = container_obj[ci + 1];
container_obj[container_idx] = NULL;
container_idx--;
for (ci = inuse; ci < g.container_idx - 1; ci++)
g.container_obj[ci] = g.container_obj[ci + 1];
g.container_obj[g.container_idx] = NULL;
g.container_idx--;
}
/* we lost track of it. */
return;
}
}
} else {
struct obj *cobj = container_obj[container_idx - 1];
struct obj *cobj = g.container_obj[g.container_idx - 1];
remove_object(otmp);
if (cobj) {
@@ -1982,9 +1967,9 @@ struct mkroom *croom;
/* container */
if (o->containment & SP_OBJ_CONTAINER) {
delete_contents(otmp);
if (container_idx < MAX_CONTAINMENT) {
container_obj[container_idx] = otmp;
container_idx++;
if (g.container_idx < MAX_CONTAINMENT) {
g.container_obj[g.container_idx] = otmp;
g.container_idx++;
} else
impossible("create_object: too deeply nested containers.");
}
@@ -2039,17 +2024,17 @@ struct mkroom *croom;
if (Is_mineend_level(&u.uz)) {
if (otmp->otyp == iflags.mines_prize_type) {
otmp->record_achieve_special = MINES_PRIZE;
if (++mines_prize_count > 1)
if (++g.mines_prize_count > 1)
impossible(prize_warning, "mines end");
}
} else if (Is_sokoend_level(&u.uz)) {
if (otmp->otyp == iflags.soko_prize_type1) {
otmp->record_achieve_special = SOKO_PRIZE1;
if (++soko_prize_count > 1)
if (++g.soko_prize_count > 1)
impossible(prize_warning, "sokoban end");
} else if (otmp->otyp == iflags.soko_prize_type2) {
otmp->record_achieve_special = SOKO_PRIZE2;
if (++soko_prize_count > 1)
if (++g.soko_prize_count > 1)
impossible(prize_warning, "sokoban end");
}
}
@@ -2065,8 +2050,8 @@ struct mkroom *croom;
boolean dealloced;
(void) bury_an_obj(otmp, &dealloced);
if (dealloced && container_idx) {
container_obj[container_idx - 1] = NULL;
if (dealloced && g.container_idx) {
g.container_obj[g.container_idx - 1] = NULL;
}
}
}
@@ -2114,7 +2099,7 @@ struct mkroom *croom;
? Align2amask(noncoalignment(u.ualignbase[A_ORIGINAL]))
: (a->align == -(MAX_REGISTERS + 1))
? induced_align(80)
: (a->align < 0 ? ralign[-a->align - 1] : a->align);
: (a->align < 0 ? g.ralign[-a->align - 1] : a->align);
levl[x][y].typ = ALTAR;
levl[x][y].altarmask = amask;
@@ -2608,7 +2593,7 @@ int humidity;
y = rn1(y_maze_max - 3, 3);
if (--tryct < 0)
break; /* give up */
} while (!(x % 2) || !(y % 2) || SpLev_Map[x][y]
} while (!(x % 2) || !(y % 2) || g.SpLev_Map[x][y]
|| !is_ok_location((schar) x, (schar) y, humidity));
m->x = (xchar) x, m->y = (xchar) y;
@@ -2633,7 +2618,7 @@ fill_empty_maze()
for (x = 2; x < x_maze_max; x++)
for (y = 0; y < y_maze_max; y++)
if (SpLev_Map[x][y])
if (g.SpLev_Map[x][y])
mapcount--;
if ((mapcount > (int) (mapcountmax / 10))) {
@@ -2796,7 +2781,7 @@ lev_init *linit;
linit->lit = rn2(2);
if (linit->filling > -1)
lvlfill_solid(linit->filling, 0);
linit->icedpools = icedpools;
linit->icedpools = g.icedpools;
mkmap(linit);
break;
}
@@ -2929,9 +2914,9 @@ void
spo_end_moninvent(coder)
struct sp_coder *coder UNUSED;
{
if (invent_carrying_monster)
m_dowear(invent_carrying_monster, TRUE);
invent_carrying_monster = NULL;
if (g.invent_carrying_monster)
m_dowear(g.invent_carrying_monster, TRUE);
g.invent_carrying_monster = NULL;
}
/*ARGUSED*/
@@ -2939,9 +2924,9 @@ void
spo_pop_container(coder)
struct sp_coder *coder UNUSED;
{
if (container_idx > 0) {
container_idx--;
container_obj[container_idx] = NULL;
if (g.container_idx > 0) {
g.container_idx--;
g.container_obj[g.container_idx] = NULL;
}
}
@@ -3303,7 +3288,7 @@ struct sp_coder *coder;
if (lflags & GRAVEYARD)
level.flags.graveyard = 1;
if (lflags & ICEDPOOLS)
icedpools = TRUE;
g.icedpools = TRUE;
if (lflags & SOLIDIFY)
coder->solidify = TRUE;
if (lflags & CORRMAZE)
@@ -3328,7 +3313,7 @@ struct sp_coder *coder;
|| !OV_pop_i(filling) || !OV_pop_i(init_style))
return;
splev_init_present = TRUE;
g.splev_init_present = TRUE;
init_lev.init_style = OV_i(init_style);
init_lev.fg = OV_i(fg);
@@ -3465,11 +3450,11 @@ struct sp_coder *coder;
room,
and there's no MAP.
*/
if (xsize <= 1 && ysize <= 1) {
xstart = 1;
ystart = 0;
xsize = COLNO - 1;
ysize = ROWNO;
if (g.xsize <= 1 && g.ysize <= 1) {
g.xstart = 1;
g.ystart = 0;
g.xsize = COLNO - 1;
g.ysize = ROWNO;
}
}
}
@@ -3490,7 +3475,7 @@ struct sp_coder *coder;
if ((badtrap = t_at(x, y)) != 0)
deltrap(badtrap);
mkstairs(x, y, (char) OV_i(up), coder->croom);
SpLev_Map[x][y] = 1;
g.SpLev_Map[x][y] = 1;
opvar_free(scoord);
opvar_free(up);
@@ -3510,7 +3495,7 @@ struct sp_coder *coder;
get_location_coord(&x, &y, DRY, coder->croom, OV_i(lcoord));
levl[x][y].typ = LADDER;
SpLev_Map[x][y] = 1;
g.SpLev_Map[x][y] = 1;
if (OV_i(up)) {
xupladder = x;
yupladder = y;
@@ -4294,7 +4279,7 @@ genericptr_t arg;
}
set_door_orientation(x, y); /* set/clear levl[x][y].horizontal */
levl[x][y].doormask = typ;
SpLev_Map[x][y] = 1;
g.SpLev_Map[x][y] = 1;
}
void
@@ -4710,7 +4695,7 @@ struct sp_coder *coder;
get_location_coord(&x, &y, DRY | WET | HOT, coder->croom, OV_i(dcoord));
if (!create_drawbridge(x, y, OV_i(dir), OV_i(db_open)))
impossible("Cannot create drawbridge.");
SpLev_Map[x][y] = 1;
g.SpLev_Map[x][y] = 1;
opvar_free(dcoord);
opvar_free(db_open);
@@ -4876,10 +4861,10 @@ struct sp_coder *coder;
dy1 = (xchar) SP_REGION_Y1(OV_i(r));
dx2 = (xchar) SP_REGION_X2(OV_i(r));
dy2 = (xchar) SP_REGION_Y2(OV_i(r));
wallify_map(dx1 < 0 ? (xstart - 1) : dx1,
dy1 < 0 ? (ystart - 1) : dy1,
dx2 < 0 ? (xstart + xsize + 1) : dx2,
dy2 < 0 ? (ystart + ysize + 1) : dy2);
wallify_map(dx1 < 0 ? (g.xstart - 1) : dx1,
dy1 < 0 ? (g.ystart - 1) : dy1,
dx2 < 0 ? (g.xstart + g.xsize + 1) : dx2,
dy2 < 0 ? (g.ystart + g.ysize + 1) : dy2);
break;
case 1:
if (!OV_pop_typ(r, SPOVAR_SEL))
@@ -4914,15 +4899,15 @@ struct sp_coder *coder;
tmpmazepart.halign = upc.x;
tmpmazepart.valign = upc.y;
tmpxsize = xsize;
tmpysize = ysize;
tmpxstart = xstart;
tmpystart = ystart;
tmpxsize = g.xsize;
tmpysize = g.ysize;
tmpxstart = g.xstart;
tmpystart = g.ystart;
halign = tmpmazepart.halign;
valign = tmpmazepart.valign;
xsize = tmpmazepart.xsize;
ysize = tmpmazepart.ysize;
g.xsize = tmpmazepart.xsize;
g.ysize = tmpmazepart.ysize;
switch (tmpmazepart.zaligntyp) {
default:
case 0:
@@ -4930,73 +4915,73 @@ struct sp_coder *coder;
case 1:
switch ((int) halign) {
case LEFT:
xstart = splev_init_present ? 1 : 3;
g.xstart = g.splev_init_present ? 1 : 3;
break;
case H_LEFT:
xstart = 2 + ((x_maze_max - 2 - xsize) / 4);
g.xstart = 2 + ((x_maze_max - 2 - g.xsize) / 4);
break;
case CENTER:
xstart = 2 + ((x_maze_max - 2 - xsize) / 2);
g.xstart = 2 + ((x_maze_max - 2 - g.xsize) / 2);
break;
case H_RIGHT:
xstart = 2 + ((x_maze_max - 2 - xsize) * 3 / 4);
g.xstart = 2 + ((x_maze_max - 2 - g.xsize) * 3 / 4);
break;
case RIGHT:
xstart = x_maze_max - xsize - 1;
g.xstart = x_maze_max - g.xsize - 1;
break;
}
switch ((int) valign) {
case TOP:
ystart = 3;
g.ystart = 3;
break;
case CENTER:
ystart = 2 + ((y_maze_max - 2 - ysize) / 2);
g.ystart = 2 + ((y_maze_max - 2 - g.ysize) / 2);
break;
case BOTTOM:
ystart = y_maze_max - ysize - 1;
g.ystart = y_maze_max - g.ysize - 1;
break;
}
if (!(xstart % 2))
xstart++;
if (!(ystart % 2))
ystart++;
if (!(g.xstart % 2))
g.xstart++;
if (!(g.ystart % 2))
g.ystart++;
break;
case 2:
if (!coder->croom) {
xstart = 1;
ystart = 0;
xsize = COLNO - 1 - tmpmazepart.xsize;
ysize = ROWNO - tmpmazepart.ysize;
g.xstart = 1;
g.ystart = 0;
g.xsize = COLNO - 1 - tmpmazepart.xsize;
g.ysize = ROWNO - tmpmazepart.ysize;
}
get_location_coord(&halign, &valign, ANY_LOC, coder->croom,
OV_i(mpa));
xsize = tmpmazepart.xsize;
ysize = tmpmazepart.ysize;
xstart = halign;
ystart = valign;
g.xsize = tmpmazepart.xsize;
g.ysize = tmpmazepart.ysize;
g.xstart = halign;
g.ystart = valign;
break;
}
if (ystart < 0 || ystart + ysize > ROWNO) {
if (g.ystart < 0 || g.ystart + g.ysize > ROWNO) {
/* try to move the start a bit */
ystart += (ystart > 0) ? -2 : 2;
if (ysize == ROWNO)
ystart = 0;
if (ystart < 0 || ystart + ysize > ROWNO)
panic("reading special level with ysize too large");
g.ystart += (g.ystart > 0) ? -2 : 2;
if (g.ysize == ROWNO)
g.ystart = 0;
if (g.ystart < 0 || g.ystart + g.ysize > ROWNO)
panic("reading special level with g.ysize too large");
}
if (xsize <= 1 && ysize <= 1) {
xstart = 1;
ystart = 0;
xsize = COLNO - 1;
ysize = ROWNO;
if (g.xsize <= 1 && g.ysize <= 1) {
g.xstart = 1;
g.ystart = 0;
g.xsize = COLNO - 1;
g.ysize = ROWNO;
} else {
xchar x, y, mptyp;
/* Load the map */
for (y = ystart; y < ystart + ysize; y++)
for (x = xstart; x < xstart + xsize; x++) {
mptyp = (mpmap->vardata.str[(y - ystart) * xsize
+ (x - xstart)] - 1);
for (y = g.ystart; y < g.ystart + g.ysize; y++)
for (x = g.xstart; x < g.xstart + g.xsize; x++) {
mptyp = (mpmap->vardata.str[(y - g.ystart) * g.xsize
+ (x - g.xstart)] - 1);
if (mptyp >= MAX_TYPE)
continue;
levl[x][y].typ = mptyp;
@@ -5006,7 +4991,7 @@ struct sp_coder *coder;
levl[x][y].horizontal = 0;
levl[x][y].roomno = 0;
levl[x][y].edge = 0;
SpLev_Map[x][y] = 1;
g.SpLev_Map[x][y] = 1;
/*
* Set secret doors to closed (why not trapped too?). Set
* the horizontal bit.
@@ -5019,7 +5004,7 @@ struct sp_coder *coder;
* (secret) door, then it is horizontal. This does
* not allow (secret) doors to be corners of rooms.
*/
if (x != xstart && (IS_WALL(levl[x - 1][y].typ)
if (x != g.xstart && (IS_WALL(levl[x - 1][y].typ)
|| levl[x - 1][y].horizontal))
levl[x][y].horizontal = 1;
} else if (levl[x][y].typ == HWALL
@@ -5027,17 +5012,17 @@ struct sp_coder *coder;
levl[x][y].horizontal = 1;
else if (levl[x][y].typ == LAVAPOOL)
levl[x][y].lit = 1;
else if (splev_init_present && levl[x][y].typ == ICE)
levl[x][y].icedpool = icedpools ? ICED_POOL : ICED_MOAT;
else if (g.splev_init_present && levl[x][y].typ == ICE)
levl[x][y].icedpool = g.icedpools ? ICED_POOL : ICED_MOAT;
}
if (coder->lvl_is_joined)
remove_rooms(xstart, ystart, xstart + xsize, ystart + ysize);
remove_rooms(g.xstart, g.ystart, g.xstart + g.xsize, g.ystart + g.ysize);
}
if (!OV_i(mpkeepr)) {
xstart = tmpxstart;
ystart = tmpystart;
xsize = tmpxsize;
ysize = tmpysize;
g.xstart = tmpxstart;
g.ystart = tmpystart;
g.xsize = tmpxsize;
g.ysize = tmpysize;
}
opvar_free(mpxs);
@@ -5316,12 +5301,12 @@ sp_lev *lvl;
coder->exit_script = FALSE;
coder->lvl_is_joined = 0;
splev_init_present = FALSE;
icedpools = FALSE;
g.splev_init_present = FALSE;
g.icedpools = FALSE;
/* achievement tracking; static init would suffice except we need to
reset if #wizmakemap is used to recreate mines' end or sokoban end;
once either level is created, these values can be forgotten */
mines_prize_count = soko_prize_count = 0;
g.mines_prize_count = g.soko_prize_count = 0;
if (wizard) {
char *met = nh_getenv("SPCODER_MAX_RUNTIME");
@@ -5338,19 +5323,19 @@ sp_lev *lvl;
shuffle_alignments();
for (tmpi = 0; tmpi < MAX_CONTAINMENT; tmpi++)
container_obj[tmpi] = NULL;
container_idx = 0;
g.container_obj[tmpi] = NULL;
g.container_idx = 0;
invent_carrying_monster = NULL;
g.invent_carrying_monster = NULL;
(void) memset((genericptr_t) &SpLev_Map[0][0], 0, sizeof SpLev_Map);
(void) memset((genericptr_t) &g.SpLev_Map[0][0], 0, sizeof g.SpLev_Map);
level.flags.is_maze_lev = 0;
xstart = 1;
ystart = 0;
xsize = COLNO - 1;
ysize = ROWNO;
g.xstart = 1;
g.ystart = 0;
g.xsize = COLNO - 1;
g.ysize = ROWNO;
while (coder->frame->n_opcode < lvl->n_opcodes && !coder->exit_script) {
coder->opcode = lvl->opcodes[coder->frame->n_opcode].opcode;
@@ -5911,8 +5896,8 @@ sp_lev *lvl;
if (!OV_pop_typ(pt, SPOVAR_SEL))
panic("no selection for rndcoord");
if (selection_rndcoord(pt, &x, &y, FALSE)) {
x -= xstart;
y -= ystart;
x -= g.xstart;
y -= g.ystart;
}
splev_stack_push(coder->stack, opvar_new_coord(x, y));
opvar_free(pt);

View File

@@ -1377,8 +1377,6 @@ static const char *spl_sortchoices[NUM_SPELL_SORTBY] = {
/* a menu choice rather than a sort choice */
"reassign casting letters to retain current order",
};
static int spl_sortmode = 0; /* index into spl_sortchoices[] */
static int *spl_orderindx = 0; /* array of spl_book[] indices */
/* qsort callback routine */
STATIC_PTR int CFDECLSPEC
@@ -1399,7 +1397,7 @@ const genericptr vptr2;
levl1 = objects[otyp1].oc_level, levl2 = objects[otyp2].oc_level,
skil1 = objects[otyp1].oc_skill, skil2 = objects[otyp2].oc_skill;
switch (spl_sortmode) {
switch (g.spl_sortmode) {
case SORTBY_LETTER:
return indx1 - indx2;
case SORTBY_ALPHA:
@@ -1450,40 +1448,40 @@ sortspells()
int n;
#endif
if (spl_sortmode == SORTBY_CURRENT)
if (g.spl_sortmode == SORTBY_CURRENT)
return;
for (n = 0; n < MAXSPELL && spellid(n) != NO_SPELL; ++n)
continue;
if (n < 2)
return; /* not enough entries to need sorting */
if (!spl_orderindx) {
if (!g.spl_orderindx) {
/* we haven't done any sorting yet; list is in casting order */
if (spl_sortmode == SORTBY_LETTER /* default */
|| spl_sortmode == SORTRETAINORDER)
if (g.spl_sortmode == SORTBY_LETTER /* default */
|| g.spl_sortmode == SORTRETAINORDER)
return;
/* allocate enough for full spellbook rather than just N spells */
spl_orderindx = (int *) alloc(MAXSPELL * sizeof(int));
g.spl_orderindx = (int *) alloc(MAXSPELL * sizeof(int));
for (i = 0; i < MAXSPELL; i++)
spl_orderindx[i] = i;
g.spl_orderindx[i] = i;
}
if (spl_sortmode == SORTRETAINORDER) {
if (g.spl_sortmode == SORTRETAINORDER) {
struct spell tmp_book[MAXSPELL];
/* sort spl_book[] rather than spl_orderindx[];
this also updates the index to reflect the new ordering (we
could just free it since that ordering becomes the default) */
for (i = 0; i < MAXSPELL; i++)
tmp_book[i] = spl_book[spl_orderindx[i]];
tmp_book[i] = spl_book[g.spl_orderindx[i]];
for (i = 0; i < MAXSPELL; i++)
spl_book[i] = tmp_book[i], spl_orderindx[i] = i;
spl_sortmode = SORTBY_LETTER; /* reset */
spl_book[i] = tmp_book[i], g.spl_orderindx[i] = i;
g.spl_sortmode = SORTBY_LETTER; /* reset */
return;
}
/* usual case, sort the index rather than the spells themselves */
qsort((genericptr_t) spl_orderindx, n, sizeof *spl_orderindx, spell_cmp);
qsort((genericptr_t) g.spl_orderindx, n, sizeof *g.spl_orderindx, spell_cmp);
return;
}
@@ -1513,7 +1511,7 @@ spellsortmenu()
}
any.a_int = i + 1;
add_menu(tmpwin, NO_GLYPH, &any, let, 0, ATR_NONE, spl_sortchoices[i],
(i == spl_sortmode) ? MENU_SELECTED : MENU_UNSELECTED);
(i == g.spl_sortmode) ? MENU_SELECTED : MENU_UNSELECTED);
}
end_menu(tmpwin, "View known spells list sorted");
@@ -1522,10 +1520,10 @@ spellsortmenu()
if (n > 0) {
choice = selected[0].item.a_int - 1;
/* skip preselected entry if we have more than one item chosen */
if (n > 1 && choice == spl_sortmode)
if (n > 1 && choice == g.spl_sortmode)
choice = selected[1].item.a_int - 1;
free((genericptr_t) selected);
spl_sortmode = choice;
g.spl_sortmode = choice;
return TRUE;
}
return FALSE;
@@ -1559,11 +1557,11 @@ dovspell()
}
}
}
if (spl_orderindx) {
free((genericptr_t) spl_orderindx);
spl_orderindx = 0;
if (g.spl_orderindx) {
free((genericptr_t) g.spl_orderindx);
g.spl_orderindx = 0;
}
spl_sortmode = SORTBY_LETTER; /* 0 */
g.spl_sortmode = SORTBY_LETTER; /* 0 */
return 0;
}
@@ -1602,7 +1600,7 @@ int *spell_no;
add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, buf,
MENU_UNSELECTED);
for (i = 0; i < MAXSPELL && spellid(i) != NO_SPELL; i++) {
splnum = !spl_orderindx ? i : spl_orderindx[i];
splnum = !g.spl_orderindx ? i : g.spl_orderindx[i];
Sprintf(buf, fmt, spellname(splnum), spellev(splnum),
spelltypemnemonic(spell_skilltype(spellid(splnum))),
100 - percent_success(splnum),

View File

@@ -1659,10 +1659,6 @@ STATIC_DCL boolean FDECL(mon_is_local, (struct monst *));
STATIC_DCL boolean FDECL(timer_is_local, (timer_element *));
STATIC_DCL int FDECL(maybe_write_timer, (int, int, BOOLEAN_P));
/* ordered timer list */
static timer_element *timer_base; /* "active" */
static unsigned long timer_id = 1;
/* If defined, then include names when printing out the timer queue */
#define VERBOSE_TIMER
@@ -1757,7 +1753,7 @@ wiz_timeout_queue()
putstr(win, 0, "");
putstr(win, 0, "Active timeout queue:");
putstr(win, 0, "");
print_queue(win, timer_base);
print_queue(win, g.timer_base);
/* Timed properies:
* check every one; the majority can't obtain temporary timeouts in
@@ -1811,7 +1807,7 @@ timer_sanity_check()
timer_element *curr;
/* this should be much more complete */
for (curr = timer_base; curr; curr = curr->next)
for (curr = g.timer_base; curr; curr = curr->next)
if (curr->kind == TIMER_OBJECT) {
struct obj *obj = curr->arg.a_obj;
@@ -1836,9 +1832,9 @@ run_timers()
* any time. The list is ordered, we are done when the first element
* is in the future.
*/
while (timer_base && timer_base->timeout <= monstermoves) {
curr = timer_base;
timer_base = curr->next;
while (g.timer_base && g.timer_base->timeout <= monstermoves) {
curr = g.timer_base;
g.timer_base = curr->next;
if (curr->kind == TIMER_OBJECT)
(curr->arg.a_obj)->timed--;
@@ -1865,7 +1861,7 @@ anything *arg;
gnu = (timer_element *) alloc(sizeof(timer_element));
(void) memset((genericptr_t)gnu, 0, sizeof(timer_element));
gnu->next = 0;
gnu->tid = timer_id++;
gnu->tid = g.timer_id++;
gnu->timeout = monstermoves + when;
gnu->kind = kind;
gnu->needs_fixup = 0;
@@ -1892,7 +1888,7 @@ anything *arg;
timer_element *doomed;
long timeout;
doomed = remove_timer(&timer_base, func_index, arg);
doomed = remove_timer(&g.timer_base, func_index, arg);
if (doomed) {
timeout = doomed->timeout;
@@ -1916,7 +1912,7 @@ anything *arg;
{
timer_element *curr;
for (curr = timer_base; curr; curr = curr->next) {
for (curr = g.timer_base; curr; curr = curr->next) {
if (curr->func_index == type && curr->arg.a_void == arg->a_void)
return curr->timeout;
}
@@ -1933,7 +1929,7 @@ struct obj *src, *dest;
int count;
timer_element *curr;
for (count = 0, curr = timer_base; curr; curr = curr->next)
for (count = 0, curr = g.timer_base; curr; curr = curr->next)
if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == src) {
curr->arg.a_obj = dest;
dest->timed++;
@@ -1953,7 +1949,7 @@ struct obj *src, *dest;
{
timer_element *curr, *next_timer = 0;
for (curr = timer_base; curr; curr = next_timer) {
for (curr = g.timer_base; curr; curr = next_timer) {
next_timer = curr->next; /* things may be inserted */
if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == src) {
(void) start_timer(curr->timeout - monstermoves, TIMER_OBJECT,
@@ -1972,13 +1968,13 @@ struct obj *obj;
{
timer_element *curr, *prev, *next_timer = 0;
for (prev = 0, curr = timer_base; curr; curr = next_timer) {
for (prev = 0, curr = g.timer_base; curr; curr = next_timer) {
next_timer = curr->next;
if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == obj) {
if (prev)
prev->next = curr->next;
else
timer_base = curr->next;
g.timer_base = curr->next;
if (timeout_funcs[curr->func_index].cleanup)
(*timeout_funcs[curr->func_index].cleanup)(&curr->arg,
curr->timeout);
@@ -2015,14 +2011,14 @@ short func_index;
timer_element *curr, *prev, *next_timer = 0;
long where = (((long) x << 16) | ((long) y));
for (prev = 0, curr = timer_base; curr; curr = next_timer) {
for (prev = 0, curr = g.timer_base; curr; curr = next_timer) {
next_timer = curr->next;
if (curr->kind == TIMER_LEVEL && curr->func_index == func_index
&& curr->arg.a_long == where) {
if (prev)
prev->next = curr->next;
else
timer_base = curr->next;
g.timer_base = curr->next;
if (timeout_funcs[curr->func_index].cleanup)
(*timeout_funcs[curr->func_index].cleanup)(&curr->arg,
curr->timeout);
@@ -2045,7 +2041,7 @@ short func_index;
timer_element *curr;
long where = (((long) x << 16) | ((long) y));
for (curr = timer_base; curr; curr = curr->next) {
for (curr = g.timer_base; curr; curr = curr->next) {
if (curr->kind == TIMER_LEVEL && curr->func_index == func_index
&& curr->arg.a_long == where)
return curr->timeout;
@@ -2069,7 +2065,7 @@ timer_element *gnu;
{
timer_element *curr, *prev;
for (prev = 0, curr = timer_base; curr; prev = curr, curr = curr->next)
for (prev = 0, curr = g.timer_base; curr; prev = curr, curr = curr->next)
if (curr->timeout >= gnu->timeout)
break;
@@ -2077,7 +2073,7 @@ timer_element *gnu;
if (prev)
prev->next = gnu;
else
timer_base = gnu;
g.timer_base = gnu;
}
STATIC_OVL timer_element *
@@ -2231,7 +2227,7 @@ boolean write_it;
int count = 0;
timer_element *curr;
for (curr = timer_base; curr; curr = curr->next) {
for (curr = g.timer_base; curr; curr = curr->next) {
if (range == RANGE_GLOBAL) {
/* global timers */
@@ -2277,7 +2273,7 @@ int fd, mode, range;
if (perform_bwrite(mode)) {
if (range == RANGE_GLOBAL)
bwrite(fd, (genericptr_t) &timer_id, sizeof(timer_id));
bwrite(fd, (genericptr_t) &g.timer_id, sizeof(g.timer_id));
count = maybe_write_timer(fd, range, FALSE);
bwrite(fd, (genericptr_t) &count, sizeof count);
@@ -2285,14 +2281,14 @@ int fd, mode, range;
}
if (release_data(mode)) {
for (prev = 0, curr = timer_base; curr; curr = next_timer) {
for (prev = 0, curr = g.timer_base; curr; curr = next_timer) {
next_timer = curr->next; /* in case curr is removed */
if (!(!!(range == RANGE_LEVEL) ^ !!timer_is_local(curr))) {
if (prev)
prev->next = curr->next;
else
timer_base = curr->next;
g.timer_base = curr->next;
free((genericptr_t) curr);
/* prev stays the same */
} else {
@@ -2316,7 +2312,7 @@ long adjust; /* how much to adjust timeout */
timer_element *curr;
if (range == RANGE_GLOBAL)
mread(fd, (genericptr_t) &timer_id, sizeof timer_id);
mread(fd, (genericptr_t) &g.timer_id, sizeof g.timer_id);
/* restore elements */
mread(fd, (genericptr_t) &count, sizeof count);
@@ -2340,7 +2336,7 @@ long *count, *size;
Sprintf(hdrbuf, hdrfmt, (long) sizeof (timer_element));
*count = *size = 0L;
for (te = timer_base; te; te = te->next) {
for (te = g.timer_base; te; te = te->next) {
++*count;
*size += (long) sizeof *te;
}
@@ -2354,7 +2350,7 @@ boolean ghostly;
timer_element *curr;
unsigned nid;
for (curr = timer_base; curr; curr = curr->next) {
for (curr = g.timer_base; curr; curr = curr->next) {
if (curr->needs_fixup) {
if (curr->kind == TIMER_OBJECT) {
if (ghostly) {

View File

@@ -82,8 +82,6 @@ STATIC_DCL void FDECL(nsb_mung_line, (char *));
STATIC_DCL void FDECL(nsb_unmung_line, (char *));
#endif
static winid toptenwin = WIN_ERR;
/* "killed by",&c ["an"] 'killer.name' */
void
formatkiller(buf, siz, how, incl_helpless)
@@ -161,20 +159,20 @@ STATIC_OVL void
topten_print(x)
const char *x;
{
if (toptenwin == WIN_ERR)
if (g.toptenwin == WIN_ERR)
raw_print(x);
else
putstr(toptenwin, ATR_NONE, x);
putstr(g.toptenwin, ATR_NONE, x);
}
STATIC_OVL void
topten_print_bold(x)
const char *x;
{
if (toptenwin == WIN_ERR)
if (g.toptenwin == WIN_ERR)
raw_print_bold(x);
else
putstr(toptenwin, ATR_BOLD, x);
putstr(g.toptenwin, ATR_BOLD, x);
}
int
@@ -517,7 +515,7 @@ time_t when;
return;
if (iflags.toptenwin) {
toptenwin = create_nhwindow(NHW_TEXT);
g.toptenwin = create_nhwindow(NHW_TEXT);
}
#if defined(UNIX) || defined(VMS) || defined(__EMX__)
@@ -769,13 +767,13 @@ time_t when;
showwin:
if (iflags.toptenwin && !done_stopprint)
display_nhwindow(toptenwin, 1);
display_nhwindow(g.toptenwin, 1);
destroywin:
if (!t0_used)
dealloc_ttentry(t0);
if (iflags.toptenwin) {
destroy_nhwindow(toptenwin);
toptenwin = WIN_ERR;
destroy_nhwindow(g.toptenwin);
g.toptenwin = WIN_ERR;
}
}

View File

@@ -1681,36 +1681,26 @@ struct trap *trap;
}
}
/*
* The following are used to track launched objects to
* prevent them from vanishing if you are killed. They
* will reappear at the launchplace in bones files.
*/
static struct {
struct obj *obj;
xchar x, y;
} launchplace;
STATIC_OVL void
launch_drop_spot(obj, x, y)
struct obj *obj;
xchar x, y;
{
if (!obj) {
launchplace.obj = (struct obj *) 0;
launchplace.x = 0;
launchplace.y = 0;
g.launchplace.obj = (struct obj *) 0;
g.launchplace.x = 0;
g.launchplace.y = 0;
} else {
launchplace.obj = obj;
launchplace.x = x;
launchplace.y = y;
g.launchplace.obj = obj;
g.launchplace.x = x;
g.launchplace.y = y;
}
}
boolean
launch_in_progress()
{
if (launchplace.obj)
if (g.launchplace.obj)
return TRUE;
return FALSE;
}
@@ -1718,9 +1708,9 @@ launch_in_progress()
void
force_launch_placement()
{
if (launchplace.obj) {
launchplace.obj->otrapped = 0;
place_object(launchplace.obj, launchplace.x, launchplace.y);
if (g.launchplace.obj) {
g.launchplace.obj->otrapped = 0;
place_object(g.launchplace.obj, g.launchplace.x, g.launchplace.y);
}
}
@@ -3467,14 +3457,6 @@ struct obj *obj;
erode_obj(obj, (char *) 0, ERODE_CORRODE, EF_GREASE | EF_VERBOSE);
}
/* context for water_damage(), managed by water_damage_chain();
when more than one stack of potions of acid explode while processing
a chain of objects, use alternate phrasing after the first message */
static struct h2o_ctx {
int dkn_boom, unk_boom; /* track dknown, !dknown separately */
boolean ctx_valid;
} acid_ctx = { 0, 0, FALSE };
/* Get an object wet and damage it appropriately.
* "ostr", if present, is used instead of the object name in some
* messages.
@@ -3573,9 +3555,9 @@ boolean force;
if (Blind && !carried(obj))
obj->dknown = 0;
if (acid_ctx.ctx_valid)
exploded = ((obj->dknown ? acid_ctx.dkn_boom
: acid_ctx.unk_boom) > 0);
if (g.acid_ctx.ctx_valid)
exploded = ((obj->dknown ? g.acid_ctx.dkn_boom
: g.acid_ctx.unk_boom) > 0);
/* First message is
* "a [potion|<color> potion|potion of acid] explodes"
* depending on obj->dknown (potion has been seen) and
@@ -3591,11 +3573,11 @@ boolean force;
!exploded ? (one ? "A" : "Some")
: (one ? "Another" : "More"),
bufp, vtense(bufp, "explode"));
if (acid_ctx.ctx_valid) {
if (g.acid_ctx.ctx_valid) {
if (obj->dknown)
acid_ctx.dkn_boom++;
g.acid_ctx.dkn_boom++;
else
acid_ctx.unk_boom++;
g.acid_ctx.unk_boom++;
}
setnotworn(obj);
delobj(obj);
@@ -3637,8 +3619,8 @@ boolean here;
/* initialize acid context: so far, neither seen (dknown) potions of
acid nor unseen have exploded during this water damage sequence */
acid_ctx.dkn_boom = acid_ctx.unk_boom = 0;
acid_ctx.ctx_valid = TRUE;
g.acid_ctx.dkn_boom = g.acid_ctx.unk_boom = 0;
g.acid_ctx.ctx_valid = TRUE;
for (; obj; obj = otmp) {
otmp = here ? obj->nexthere : obj->nobj;
@@ -3646,8 +3628,8 @@ boolean here;
}
/* reset acid context */
acid_ctx.dkn_boom = acid_ctx.unk_boom = 0;
acid_ctx.ctx_valid = FALSE;
g.acid_ctx.dkn_boom = g.acid_ctx.unk_boom = 0;
g.acid_ctx.ctx_valid = FALSE;
}
/*

View File

@@ -185,8 +185,6 @@ wl_addtail(struct winlink *wl)
}
#endif /* WINCHAIN */
static struct win_choices *last_winchoice = 0;
boolean
genl_can_suspend_no(VOID_ARGS)
{
@@ -253,11 +251,11 @@ const char *s;
if (!strcmpi(s, winchoices[i].procs->name)) {
windowprocs = *winchoices[i].procs;
if (last_winchoice && last_winchoice->ini_routine)
(*last_winchoice->ini_routine)(WININIT_UNDO);
if (g.last_winchoice && g.last_winchoice->ini_routine)
(*g.last_winchoice->ini_routine)(WININIT_UNDO);
if (winchoices[i].ini_routine)
(*winchoices[i].ini_routine)(WININIT);
last_winchoice = &winchoices[i];
g.last_winchoice = &winchoices[i];
return;
}
}
@@ -374,7 +372,7 @@ commit_windowchain()
p->nextlink->linkdata);
} else {
(void) (*p->wincp->chain_routine)(WINCHAIN_INIT, n, p->linkdata,
last_winchoice->procs, 0);
g.last_winchoice->procs, 0);
}
}

View File

@@ -123,9 +123,9 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88";
#define MAX_TYPES 5 /* max number of types above */
static int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
static const int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
static int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
static const int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
/*
* Initially, everything is set up as if from :