From 6d6623cf578353dc66637040ca953c30bdbf2fdb Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 24 Nov 2018 19:27:56 -0800 Subject: [PATCH] Even more globals moved to instance_globals. --- include/decl.h | 62 +++++++++++++ include/lev.h | 35 ------- src/decl.c | 18 +++- src/files.c | 1 - src/invent.c | 45 ++++----- src/light.c | 46 +++++---- src/makemon.c | 2 +- src/mkmap.c | 4 +- src/mkmaze.c | 130 +++++++++++++------------- src/mkobj.c | 2 +- src/mkroom.c | 2 +- src/mon.c | 23 ++--- src/muse.c | 246 ++++++++++++++++++++++++------------------------- 13 files changed, 315 insertions(+), 301 deletions(-) diff --git a/include/decl.h b/include/decl.h index 16195e1ab..517abe793 100644 --- a/include/decl.h +++ b/include/decl.h @@ -578,6 +578,49 @@ struct rogueroom { int nroom; /* Only meaningful for "real" rooms */ }; +typedef struct ls_t { + struct ls_t *next; + xchar x, y; /* source's position */ + short range; /* source's current range */ + short flags; + short type; /* type of light source */ + anything id; /* source's identifier */ +} light_source; + +struct container { + struct container *next; + xchar x, y; + short what; + genericptr_t list; +}; + +enum bubble_contains_types { + CONS_OBJ = 0, + CONS_MON, + CONS_HERO, + CONS_TRAP +}; + +#define MAX_BMASK 4 + +struct bubble { + xchar x, y; /* coordinates of the upper left corner */ + schar dx, dy; /* the general direction of the bubble's movement */ + uchar bm[MAX_BMASK + 2]; /* bubble bit mask */ + struct bubble *prev, *next; /* need to traverse the list up and down */ + struct container *cons; +}; + +struct musable { + struct obj *offensive; + struct obj *defensive; + struct obj *misc; + int has_offense, has_defense, has_misc; + /* =0, no capability; otherwise, different numbers. + * If it's an object, the object is also set (it's 0 otherwise). + */ +}; + /* instance_globals holds engine state that does not need to be * persisted upon game exit. The initialization state is well defined * an set in decl.c during early early engine initialization. @@ -720,6 +763,18 @@ struct instance_globals { * reset by sortloot when done */ char *invbuf; unsigned invbufsiz; + /* for perm_invent when operating on a partial inventory display, so that + the persistent one doesn't get shrunk during filtering for item selection + then regrown to full inventory, possibly being resized in the process */ + winid cached_pickinv_win; + /* query objlist callback: return TRUE if obj type matches "this_type" */ + int this_type; + /* query objlist callback: return TRUE if obj is at given location */ + coord only; + + /* light.c */ + light_source *light_base; + /* lock.c */ struct xlock_s xlock; @@ -760,10 +815,16 @@ struct instance_globals { lev_region bughack; /* for preserving the insect legs when wallifying * baalz level */ boolean was_waterlevel; /* ugh... this shouldn't be needed */ + struct bubble *bbubbles; + struct bubble *ebubbles; + struct trap *wportal; + int xmin, ymin, xmax, ymax; /* level boundaries */ /* mon.c */ boolean vamp_rise_msg; boolean disintegested; + short *animal_list; /* list of PM values for animal monsters */ + int animal_list_count; /* muse.c */ boolean m_using; /* kludge to use mondided instead of killed */ @@ -775,6 +836,7 @@ struct instance_globals { * function mbhitm has to be compatible with the * normal zap routines, and those routines don't * remember who zapped the wand. */ + struct musable m; /* objname.c */ /* distantname used by distant_name() to pass extra information to diff --git a/include/lev.h b/include/lev.h index 17fd8dddd..97fe8d660 100644 --- a/include/lev.h +++ b/include/lev.h @@ -12,43 +12,8 @@ #define WRITE_SAVE 0x2 #define FREE_SAVE 0x4 -#define MAX_BMASK 4 - /* operations of the various saveXXXchn & co. routines */ #define perform_bwrite(mode) ((mode) & (COUNT_SAVE | WRITE_SAVE)) #define release_data(mode) ((mode) &FREE_SAVE) -/* The following are used in mkmaze.c */ -struct container { - struct container *next; - xchar x, y; - short what; - genericptr_t list; -}; - -enum bubble_contains_types { - CONS_OBJ = 0, - CONS_MON, - CONS_HERO, - CONS_TRAP -}; - -struct bubble { - xchar x, y; /* coordinates of the upper left corner */ - schar dx, dy; /* the general direction of the bubble's movement */ - uchar bm[MAX_BMASK + 2]; /* bubble bit mask */ - struct bubble *prev, *next; /* need to traverse the list up and down */ - struct container *cons; -}; - -/* used in light.c */ -typedef struct ls_t { - struct ls_t *next; - xchar x, y; /* source's position */ - short range; /* source's current range */ - short flags; - short type; /* type of light source */ - anything id; /* source's identifier */ -} light_source; - #endif /* LEV_H */ diff --git a/src/decl.c b/src/decl.c index 0f18aacba..267d038e7 100644 --- a/src/decl.c +++ b/src/decl.c @@ -438,6 +438,12 @@ const struct instance_globals g_init = { 0, /* sortloogmode */ NULL, /* invbuf */ 0, /* inbufsize */ + WIN_ERR, /* cached_pickinv_win */ + UNDEFINED_VALUE, + UNDEFINED_VALUES, + + /* light.c */ + NULL, /* light_source */ /* lock.c */ UNDEFINED_VALUES, @@ -472,16 +478,26 @@ const struct instance_globals g_init = { /* mkmaze.c */ { {COLNO, ROWNO, 0, 0}, {COLNO, ROWNO, 0, 0} }, /* bughack */ UNDEFINED_VALUE, /* was_waterlevel */ + UNDEFINED_PTR, /* bbubbles */ + UNDEFINED_PTR, /* ebubbles */ + UNDEFINED_PTR, /* wportal */ + UNDEFINED_VALUE, /* xmin */ + UNDEFINED_VALUE, /* ymin */ + UNDEFINED_VALUE, /* xmax */ + UNDEFINED_VALUE, /* ymax */ /* mon.c */ UNDEFINED_VALUE, /* vamp_rise_msg */ UNDEFINED_VALUE, /* disintegested */ + NULL, /* animal_list */ + UNDEFINED_VALUE, /* animal_list_count */ - /* mused.c */ + /* muse.c */ FALSE, /* m_using */ UNDEFINED_VALUE, /* trapx */ UNDEFINED_VALUE, /* trapy */ UNDEFINED_VALUE, /* zap_oseen */ + UNDEFINED_VALUES, /* m */ /* objname.c */ 0, /* distantname */ diff --git a/src/files.c b/src/files.c index d80ee27cc..28e805971 100644 --- a/src/files.c +++ b/src/files.c @@ -3127,7 +3127,6 @@ boolean FDECL((*proc), (char *)); return rv; } -extern struct symparse loadsyms[]; /* drawing.c */ extern const char *known_handling[]; /* drawing.c */ extern const char *known_restrictions[]; /* drawing.c */ diff --git a/src/invent.c b/src/invent.c index 3da2ab31d..2f00b222e 100644 --- a/src/invent.c +++ b/src/invent.c @@ -48,7 +48,7 @@ STATIC_DCL char FDECL(obj_to_let, (struct obj *)); * confused: 'WIZARD' used to be a compile-time conditional so this was * guarded by #ifdef WIZARD/.../#endif.] */ -static char venom_inv[] = { VENOM_CLASS, 0 }; /* (constant) */ +static const char venom_inv[] = { VENOM_CLASS, 0 }; /* (constant) */ /* sortloot() classification; called at most once for each object sorted */ STATIC_OVL void @@ -2464,17 +2464,12 @@ struct obj *list, **last_found; return (struct obj *) 0; } -/* for perm_invent when operating on a partial inventory display, so that - the persistent one doesn't get shrunk during filtering for item selection - then regrown to full inventory, possibly being resized in the process */ -static winid cached_pickinv_win = WIN_ERR; - void free_pickinv_cache() { - if (cached_pickinv_win != WIN_ERR) { - destroy_nhwindow(cached_pickinv_win); - cached_pickinv_win = WIN_ERR; + if (g.cached_pickinv_win != WIN_ERR) { + destroy_nhwindow(g.cached_pickinv_win); + g.cached_pickinv_win = WIN_ERR; } } @@ -2494,7 +2489,7 @@ long *out_cnt; static const char not_carrying_anything[] = "Not carrying anything"; struct obj *otmp, wizid_fakeobj; char ilet, ret; - char *invlet = flags.inv_order; + const char *invlet = flags.inv_order; int n, classcount; winid win; /* windows being used */ anything any; @@ -2510,9 +2505,9 @@ long *out_cnt; /* partial inventory in perm_invent setting; don't operate on full inventory window, use an alternate one instead; create the first time needed and keep it for re-use as needed later */ - if (cached_pickinv_win == WIN_ERR) - cached_pickinv_win = create_nhwindow(NHW_MENU); - win = cached_pickinv_win; + if (g.cached_pickinv_win == WIN_ERR) + g.cached_pickinv_win = create_nhwindow(NHW_MENU); + win = g.cached_pickinv_win; } else win = WIN_INVEN; @@ -2997,22 +2992,20 @@ dounpaid() destroy_nhwindow(win); } -/* query objlist callback: return TRUE if obj type matches "this_type" */ -static int this_type; STATIC_OVL boolean this_type_only(obj) struct obj *obj; { - boolean res = (obj->oclass == this_type); + boolean res = (obj->oclass == g.this_type); if (obj->oclass == COIN_CLASS) { /* if filtering by bless/curse state, gold is classified as either unknown or uncursed based on user option setting */ - if (this_type && index("BUCX", this_type)) - res = (this_type == (iflags.goldX ? 'X' : 'U')); + if (g.this_type && index("BUCX", g.this_type)) + res = (g.this_type == (iflags.goldX ? 'X' : 'U')); } else { - switch (this_type) { + switch (g.this_type) { case 'B': res = (obj->bknown && obj->blessed); break; @@ -3071,7 +3064,7 @@ dotypeinv() n = query_category(prompt, invent, i, &pick_list, PICK_ONE); if (!n) return 0; - this_type = c = pick_list[0].item.a_int; + g.this_type = c = pick_list[0].item.a_int; free((genericptr_t) pick_list); } } @@ -3189,7 +3182,7 @@ dotypeinv() You("have no %sobjects%s.", before, after); return 0; } - this_type = oclass; + g.this_type = oclass; } if (query_objlist((char *) 0, &invent, ((flags.invlet_constant ? USE_INVLET : 0) @@ -4289,14 +4282,12 @@ register struct obj *obj; return ret; } -/* query objlist callback: return TRUE if obj is at given location */ -static coord only; STATIC_OVL boolean only_here(obj) struct obj *obj; { - return (obj->ox == only.x && obj->oy == only.y); + return (obj->ox == g.only.x && obj->oy == g.only.y); } /* @@ -4323,13 +4314,13 @@ boolean as_if_seen; } if (n) { - only.x = x; - only.y = y; + g.only.x = x; + g.only.y = y; if (query_objlist("Things that are buried here:", &level.buriedobjlist, INVORDER_SORT, &selected, PICK_NONE, only_here) > 0) free((genericptr_t) selected); - only.x = only.y = 0; + g.only.x = g.only.y = 0; } return n; } diff --git a/src/light.c b/src/light.c index 446dc390e..c9e4dba24 100644 --- a/src/light.c +++ b/src/light.c @@ -42,8 +42,6 @@ #define LSF_SHOW 0x1 /* display the light source */ #define LSF_NEEDS_FIXUP 0x2 /* need oid fixup */ -static light_source *light_base = 0; - STATIC_DCL void FDECL(write_ls, (int, light_source *)); STATIC_DCL int FDECL(maybe_write_ls, (int, int, BOOLEAN_P)); @@ -67,14 +65,14 @@ anything *id; ls = (light_source *) alloc(sizeof(light_source)); - ls->next = light_base; + ls->next = g.light_base; ls->x = x; ls->y = y; ls->range = range; ls->type = type; ls->id = *id; ls->flags = 0; - light_base = ls; + g.light_base = ls; vision_full_recalc = 1; /* make the source show up */ } @@ -107,7 +105,7 @@ anything *id; break; } - for (prev = 0, curr = light_base; curr; prev = curr, curr = curr->next) { + for (prev = 0, curr = g.light_base; curr; prev = curr, curr = curr->next) { if (curr->type != type) continue; if (curr->id.a_obj @@ -115,7 +113,7 @@ anything *id; if (prev) prev->next = curr->next; else - light_base = curr->next; + g.light_base = curr->next; free((genericptr_t) curr); vision_full_recalc = 1; @@ -137,7 +135,7 @@ char **cs_rows; light_source *ls; char *row; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { ls->flags &= ~LSF_SHOW; /* @@ -255,7 +253,7 @@ int fd, mode, range; } if (release_data(mode)) { - for (prev = &light_base; (curr = *prev) != 0;) { + for (prev = &g.light_base; (curr = *prev) != 0;) { if (!curr->id.a_monst) { impossible("save_light_sources: no id! [range=%d]", range); is_global = 0; @@ -301,8 +299,8 @@ int fd; while (count-- > 0) { ls = (light_source *) alloc(sizeof(light_source)); mread(fd, (genericptr_t) ls, sizeof(light_source)); - ls->next = light_base; - light_base = ls; + ls->next = g.light_base; + g.light_base = ls; } } @@ -317,7 +315,7 @@ long *count, *size; Sprintf(hdrbuf, hdrfmt, (long) sizeof (light_source)); *count = *size = 0L; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { ++*count; *size += (long) sizeof *ls; } @@ -332,7 +330,7 @@ boolean ghostly; unsigned nid; light_source *ls; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { if (ls->flags & LSF_NEEDS_FIXUP) { if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) { if (ghostly) { @@ -371,7 +369,7 @@ boolean write_it; int count = 0, is_global; light_source *ls; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { if (!ls->id.a_monst) { impossible("maybe_write_ls: no id! [range=%d]", range); continue; @@ -408,7 +406,7 @@ light_sources_sanity_check() struct obj *otmp; unsigned int auint; - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { if (!ls->id.a_monst) panic("insane light source: no id!"); if (ls->type == LS_OBJECT) { @@ -475,7 +473,7 @@ struct obj *src, *dest; { light_source *ls; - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) if (ls->type == LS_OBJECT && ls->id.a_obj == src) ls->id.a_obj = dest; src->lamplit = 0; @@ -486,7 +484,7 @@ struct obj *src, *dest; boolean any_light_source() { - return (boolean) (light_base != (light_source *) 0); + return (boolean) (g.light_base != (light_source *) 0); } /* @@ -500,7 +498,7 @@ int x, y; light_source *ls; struct obj *obj; - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) /* * Is this position check valid??? Can I assume that the positions * will always be correct because the objects would have been @@ -553,7 +551,7 @@ struct obj *src, *dest; { light_source *ls, *new_ls; - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) if (ls->type == LS_OBJECT && ls->id.a_obj == src) { /* * Insert the new source at beginning of list. This will @@ -569,8 +567,8 @@ struct obj *src, *dest; vision_full_recalc = 1; /* in case range changed */ } new_ls->id.a_obj = dest; - new_ls->next = light_base; - light_base = new_ls; + new_ls->next = g.light_base; + g.light_base = new_ls; dest->lamplit = 1; /* now an active light source */ } } @@ -587,7 +585,7 @@ struct obj *src, *dest; if (src != dest) end_burn(src, TRUE); /* extinguish candles */ - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) if (ls->type == LS_OBJECT && ls->id.a_obj == dest) { ls->range = candle_light_range(dest); vision_full_recalc = 1; /* in case range changed */ @@ -603,7 +601,7 @@ int new_radius; { light_source *ls; - for (ls = light_base; ls; ls = ls->next) + for (ls = g.light_base; ls; ls = ls->next) if (ls->type == LS_OBJECT && ls->id.a_obj == obj) { if (new_radius != ls->range) vision_full_recalc = 1; @@ -709,10 +707,10 @@ wiz_light_sources() putstr(win, 0, buf); putstr(win, 0, ""); - if (light_base) { + if (g.light_base) { putstr(win, 0, "location range flags type id"); putstr(win, 0, "-------- ----- ------ ---- -------"); - for (ls = light_base; ls; ls = ls->next) { + for (ls = g.light_base; ls; ls = ls->next) { Sprintf(buf, " %2d,%2d %2d 0x%04x %s %s", ls->x, ls->y, ls->range, ls->flags, (ls->type == LS_OBJECT diff --git a/src/makemon.c b/src/makemon.c index 4ecb2dc59..e4d40e887 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -2112,7 +2112,7 @@ struct monst *mtmp; MCORPSENM(mtmp) = NON_PM; } -static NEARDATA char syms[] = { +static const NEARDATA char syms[] = { MAXOCLASSES, MAXOCLASSES + 1, RING_CLASS, WAND_CLASS, WEAPON_CLASS, FOOD_CLASS, COIN_CLASS, SCROLL_CLASS, POTION_CLASS, ARMOR_CLASS, AMULET_CLASS, TOOL_CLASS, ROCK_CLASS, GEM_CLASS, SPBOOK_CLASS, diff --git a/src/mkmap.c b/src/mkmap.c index b953a3d47..26c534cd6 100644 --- a/src/mkmap.c +++ b/src/mkmap.c @@ -61,8 +61,8 @@ schar bg_typ; return levl[col][row].typ; } -static int dirs[16] = { -1, -1 /**/, -1, 0 /**/, -1, 1 /**/, 0, -1 /**/, - 0, 1 /**/, 1, -1 /**/, 1, 0 /**/, 1, 1 }; +static const int dirs[16] = { -1, -1 /**/, -1, 0 /**/, -1, 1 /**/, 0, -1 /**/, + 0, 1 /**/, 1, -1 /**/, 1, 0 /**/, 1, 1 }; STATIC_OVL void pass_one(bg_typ, fg_typ) diff --git a/src/mkmaze.c b/src/mkmaze.c index a2a072487..18622609a 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -1371,15 +1371,11 @@ fumaroles() * other source files, but they are all so nicely encapsulated here. */ -static struct bubble *bbubbles, *ebubbles; - -static struct trap *wportal; -static int xmin, ymin, xmax, ymax; /* level boundaries */ /* bubble movement boundaries */ -#define bxmin (xmin + 1) -#define bymin (ymin + 1) -#define bxmax (xmax - 1) -#define bymax (ymax - 1) +#define gbxmin (g.xmin + 1) +#define gbymin (g.ymin + 1) +#define gbxmax (g.xmax - 1) +#define gbymax (g.ymax - 1) STATIC_DCL void NDECL(set_wportal); STATIC_DCL void FDECL(mk_bubble, (int, int, int)); @@ -1398,7 +1394,7 @@ movebubbles() 1, 0, 0, 0, 0 }; /* set up the portal the first time bubbles are moved */ - if (!wportal) + if (!g.wportal) set_wportal(); vision_recalc(2); @@ -1412,7 +1408,7 @@ movebubbles() * Pick up everything inside of a bubble then fill all bubble * locations. */ - for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { + for (b = up ? g.bbubbles : g.ebubbles; b; b = up ? b->next : b->prev) { if (b->cons) panic("movebubbles: cons != null"); for (i = 0, x = b->x; i < (int) b->bm[0]; i++, x++) @@ -1511,7 +1507,7 @@ movebubbles() * would eventually end up in the last bubble in the chain. */ up = !up; - for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { + for (b = up ? g.bbubbles : g.ebubbles; b; b = up ? b->next : b->prev) { int rx = rn2(3), ry = rn2(3); mv_bubble(b, b->dx + 1 - (!b->dx ? rx : (rx ? 1 : 0)), @@ -1570,14 +1566,14 @@ int fd, mode; if (perform_bwrite(mode)) { int n = 0; - for (b = bbubbles; b; b = b->next) + for (b = g.bbubbles; b; b = b->next) ++n; bwrite(fd, (genericptr_t) &n, sizeof(int)); - bwrite(fd, (genericptr_t) &xmin, sizeof(int)); - bwrite(fd, (genericptr_t) &ymin, sizeof(int)); - bwrite(fd, (genericptr_t) &xmax, sizeof(int)); - bwrite(fd, (genericptr_t) &ymax, sizeof(int)); - for (b = bbubbles; b; b = b->next) + bwrite(fd, (genericptr_t) &g.xmin, sizeof(int)); + bwrite(fd, (genericptr_t) &g.ymin, sizeof(int)); + bwrite(fd, (genericptr_t) &g.xmax, sizeof(int)); + bwrite(fd, (genericptr_t) &g.ymax, sizeof(int)); + for (b = g.bbubbles; b; b = b->next) bwrite(fd, (genericptr_t) b, sizeof(struct bubble)); } if (release_data(mode)) @@ -1596,24 +1592,24 @@ int fd; set_wportal(); mread(fd, (genericptr_t) &n, sizeof(int)); - mread(fd, (genericptr_t) &xmin, sizeof(int)); - mread(fd, (genericptr_t) &ymin, sizeof(int)); - mread(fd, (genericptr_t) &xmax, sizeof(int)); - mread(fd, (genericptr_t) &ymax, sizeof(int)); + mread(fd, (genericptr_t) &g.xmin, sizeof(int)); + mread(fd, (genericptr_t) &g.ymin, sizeof(int)); + mread(fd, (genericptr_t) &g.xmax, sizeof(int)); + mread(fd, (genericptr_t) &g.ymax, sizeof(int)); for (i = 0; i < n; i++) { btmp = b; b = (struct bubble *) alloc(sizeof(struct bubble)); mread(fd, (genericptr_t) b, sizeof(struct bubble)); - if (bbubbles) { + if (g.bbubbles) { btmp->next = b; b->prev = btmp; } else { - bbubbles = b; + g.bbubbles = b; b->prev = (struct bubble *) 0; } mv_bubble(b, 0, 0, TRUE); } - ebubbles = b; + g.ebubbles = b; b->next = (struct bubble *) 0; g.was_waterlevel = TRUE; } @@ -1652,8 +1648,8 @@ STATIC_OVL void set_wportal() { /* there better be only one magic portal on water level... */ - for (wportal = ftrap; wportal; wportal = wportal->ntrap) - if (wportal->ttyp == MAGIC_PORTAL) + for (g.wportal = ftrap; g.wportal; g.wportal = g.wportal->ntrap) + if (g.wportal->ttyp == MAGIC_PORTAL) return; impossible("set_wportal(): no portal!"); } @@ -1668,15 +1664,15 @@ setup_waterlevel() /* ouch, hardcoded... */ - xmin = 3; - ymin = 1; - xmax = 78; - ymax = 20; + g.xmin = 3; + g.ymin = 1; + g.xmax = 78; + g.ymax = 20; /* set hero's memory to water */ - for (x = xmin; x <= xmax; x++) - for (y = ymin; y <= ymax; y++) + for (x = g.xmin; x <= g.xmax; x++) + for (y = g.ymin; y <= g.ymax; y++) levl[x][y].glyph = Is_waterlevel(&u.uz) ? water_glyph : air_glyph; /* make bubbles */ @@ -1689,8 +1685,8 @@ setup_waterlevel() yskip = 3 + rn2(3); } - for (x = bxmin; x <= bxmax; x += xskip) - for (y = bymin; y <= bymax; y += yskip) + for (x = gbxmin; x <= gbxmax; x += xskip) + for (y = gbymin; y <= gbymax; y += yskip) mk_bubble(x, y, rn2(7)); } @@ -1701,11 +1697,11 @@ unsetup_waterlevel() /* free bubbles */ - for (b = bbubbles; b; b = bb) { + for (b = g.bbubbles; b; b = bb) { bb = b->next; free((genericptr_t) b); } - bbubbles = ebubbles = (struct bubble *) 0; + g.bbubbles = g.ebubbles = (struct bubble *) 0; } STATIC_OVL void @@ -1729,7 +1725,7 @@ int x, y, n; *bmask[] = { bm2, bm3, bm4, bm5, bm6, bm7, bm8 }; struct bubble *b; - if (x >= bxmax || y >= bymax) + if (x >= gbxmax || y >= gbymax) return; if (n >= SIZE(bmask)) { impossible("n too large (mk_bubble)"); @@ -1739,10 +1735,10 @@ int x, y, n; panic("bmask size is larger than MAX_BMASK"); } b = (struct bubble *) alloc(sizeof(struct bubble)); - if ((x + (int) bmask[n][0] - 1) > bxmax) - x = bxmax - bmask[n][0] + 1; - if ((y + (int) bmask[n][1] - 1) > bymax) - y = bymax - bmask[n][1] + 1; + if ((x + (int) bmask[n][0] - 1) > gbxmax) + x = gbxmax - bmask[n][0] + 1; + if ((y + (int) bmask[n][1] - 1) > gbymax) + y = gbymax - bmask[n][1] + 1; b->x = x; b->y = y; b->dx = 1 - rn2(3); @@ -1751,15 +1747,15 @@ int x, y, n; (void) memcpy((genericptr_t) b->bm, (genericptr_t) bmask[n], (bmask[n][1] + 2) * sizeof(b->bm[0])); b->cons = 0; - if (!bbubbles) - bbubbles = b; - if (ebubbles) { - ebubbles->next = b; - b->prev = ebubbles; + if (!g.bbubbles) + g.bbubbles = b; + if (g.ebubbles) { + g.ebubbles->next = b; + b->prev = g.ebubbles; } else b->prev = (struct bubble *) 0; b->next = (struct bubble *) 0; - ebubbles = b; + g.ebubbles = b; mv_bubble(b, 0, 0, TRUE); } @@ -1793,42 +1789,42 @@ boolean ini; * collision with level borders? * 1 = horizontal border, 2 = vertical, 3 = corner */ - if (b->x <= bxmin) + if (b->x <= gbxmin) colli |= 2; - if (b->y <= bymin) + if (b->y <= gbymin) colli |= 1; - if ((int) (b->x + b->bm[0] - 1) >= bxmax) + if ((int) (b->x + b->bm[0] - 1) >= gbxmax) colli |= 2; - if ((int) (b->y + b->bm[1] - 1) >= bymax) + if ((int) (b->y + b->bm[1] - 1) >= gbymax) colli |= 1; - if (b->x < bxmin) { - pline("bubble xmin: x = %d, xmin = %d", b->x, bxmin); - b->x = bxmin; + if (b->x < gbxmin) { + pline("bubble xmin: x = %d, xmin = %d", b->x, gbxmin); + b->x = gbxmin; } - if (b->y < bymin) { - pline("bubble ymin: y = %d, ymin = %d", b->y, bymin); - b->y = bymin; + if (b->y < gbymin) { + pline("bubble ymin: y = %d, ymin = %d", b->y, gbymin); + b->y = gbymin; } - if ((int) (b->x + b->bm[0] - 1) > bxmax) { + if ((int) (b->x + b->bm[0] - 1) > gbxmax) { pline("bubble xmax: x = %d, xmax = %d", b->x + b->bm[0] - 1, - bxmax); - b->x = bxmax - b->bm[0] + 1; + gbxmax); + b->x = gbxmax - b->bm[0] + 1; } - if ((int) (b->y + b->bm[1] - 1) > bymax) { + if ((int) (b->y + b->bm[1] - 1) > gbymax) { pline("bubble ymax: y = %d, ymax = %d", b->y + b->bm[1] - 1, - bymax); - b->y = bymax - b->bm[1] + 1; + gbymax); + b->y = gbymax - b->bm[1] + 1; } /* bounce if we're trying to move off the border */ - if (b->x == bxmin && dx < 0) + if (b->x == gbxmin && dx < 0) dx = -dx; - if (b->x + b->bm[0] - 1 == bxmax && dx > 0) + if (b->x + b->bm[0] - 1 == gbxmax && dx > 0) dx = -dx; - if (b->y == bymin && dy < 0) + if (b->y == gbymin && dy < 0) dy = -dy; - if (b->y + b->bm[1] - 1 == bymax && dy > 0) + if (b->y + b->bm[1] - 1 == gbymax && dy > 0) dy = -dy; b->x += dx; diff --git a/src/mkobj.c b/src/mkobj.c index 9a0ec48f2..31deb2087 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -1436,7 +1436,7 @@ register struct obj *obj; return (wt ? wt * (int) obj->quan : ((int) obj->quan + 1) >> 1); } -static int treefruits[] = { APPLE, ORANGE, PEAR, BANANA, EUCALYPTUS_LEAF }; +static const int treefruits[] = { APPLE, ORANGE, PEAR, BANANA, EUCALYPTUS_LEAF }; struct obj * rnd_treefruit_at(x, y) diff --git a/src/mkroom.c b/src/mkroom.c index d0995c7f1..51b5020e2 100644 --- a/src/mkroom.c +++ b/src/mkroom.c @@ -759,7 +759,7 @@ courtmon() #define NSTYPES (PM_CAPTAIN - PM_SOLDIER + 1) -static struct { +static const struct { unsigned pm; unsigned prob; } squadprob[NSTYPES] = { { PM_SOLDIER, 80 }, diff --git a/src/mon.c b/src/mon.c index 4b512d000..10803e874 100644 --- a/src/mon.c +++ b/src/mon.c @@ -3056,9 +3056,6 @@ struct monst *mon; } } -static short *animal_list = 0; /* list of PM values for animal monsters */ -static int animal_list_count; - void mon_animal_list(construct) boolean construct; @@ -3074,14 +3071,14 @@ boolean construct; animal_temp[n++] = i; /* if (n == 0) animal_temp[n++] = NON_PM; */ - animal_list = (short *) alloc(n * sizeof *animal_list); - (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp, - n * sizeof *animal_list); - animal_list_count = n; + g.animal_list = (short *) alloc(n * sizeof *g.animal_list); + (void) memcpy((genericptr_t) g.animal_list, (genericptr_t) animal_temp, + n * sizeof *g.animal_list); + g.animal_list_count = n; } else { /* release */ - if (animal_list) - free((genericptr_t) animal_list), animal_list = 0; - animal_list_count = 0; + if (g.animal_list) + free((genericptr_t) g.animal_list), g.animal_list = 0; + g.animal_list_count = 0; } } @@ -3090,15 +3087,15 @@ pick_animal() { int res; - if (!animal_list) + if (!g.animal_list) mon_animal_list(TRUE); - res = animal_list[rn2(animal_list_count)]; + res = g.animal_list[rn2(g.animal_list_count)]; /* rogue level should use monsters represented by uppercase letters only, but since chameleons aren't generated there (not uppercase!) we don't perform a lot of retries */ if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet)) - res = animal_list[rn2(animal_list_count)]; + res = g.animal_list[rn2(g.animal_list_count)]; return res; } diff --git a/src/muse.c b/src/muse.c index b15aebb3b..58a02bbde 100644 --- a/src/muse.c +++ b/src/muse.c @@ -35,16 +35,6 @@ STATIC_DCL boolean FDECL(muse_unslime, (struct monst *, struct obj *, STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *)); STATIC_DCL boolean FDECL(green_mon, (struct monst *)); -static struct musable { - struct obj *offensive; - struct obj *defensive; - struct obj *misc; - int has_offense, has_defense, has_misc; - /* =0, no capability; otherwise, different numbers. - * If it's an object, the object is also set (it's 0 otherwise). - */ -} m; - /* Any preliminary checks which may result in the monster being unable to use * the item. Returns 0 if nothing happened, 2 if the monster can't do * anything (i.e. it teleported) and 1 if it's dead. @@ -148,7 +138,7 @@ struct obj *obj; monkilled(mon, "", AD_RBRE); return 1; } - m.has_defense = m.has_offense = m.has_misc = 0; + g.m.has_defense = g.m.has_offense = g.m.has_misc = 0; /* Only one needed to be set to 0 but the others are harmless */ } return 0; @@ -265,18 +255,18 @@ struct monst *mtmp; { struct obj *obj = 0; if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_FULL_HEALING; return TRUE; } if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_EXTRA_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_EXTRA_HEALING; return TRUE; } if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_HEALING; return TRUE; } return FALSE; @@ -302,8 +292,8 @@ struct monst *mtmp; if (u.uswallow && stuck) return FALSE; - m.defensive = (struct obj *) 0; - m.has_defense = 0; + g.m.defensive = (struct obj *) 0; + g.m.has_defense = 0; /* since unicorn horns don't get used up, the monster would look * silly trying to use the same cursed horn round after round @@ -315,8 +305,8 @@ struct monst *mtmp; break; } if (obj || is_unicorn(mtmp->data)) { - m.defensive = obj; - m.has_defense = MUSE_UNICORN_HORN; + g.m.defensive = obj; + g.m.has_defense = MUSE_UNICORN_HORN; return TRUE; } } @@ -326,8 +316,8 @@ struct monst *mtmp; for (obj = mtmp->minvent; obj; obj = obj->nobj) { if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) { - m.defensive = obj; - m.has_defense = MUSE_LIZARD_CORPSE; + g.m.defensive = obj; + g.m.has_defense = MUSE_LIZARD_CORPSE; return TRUE; } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) { liztin = obj; @@ -335,9 +325,9 @@ struct monst *mtmp; } /* confused or stunned monster might not be able to open tin */ if (liztin && mcould_eat_tin(mtmp) && rn2(3)) { - m.defensive = liztin; + g.m.defensive = liztin; /* tin and corpse ultimately end up being handled the same */ - m.has_defense = MUSE_LIZARD_CORPSE; + g.m.has_defense = MUSE_LIZARD_CORPSE; return TRUE; } } @@ -374,22 +364,22 @@ struct monst *mtmp; } else if (levl[x][y].typ == STAIRS) { if (x == xdnstair && y == ydnstair) { if (!is_floater(mtmp->data)) - m.has_defense = MUSE_DOWNSTAIRS; + g.m.has_defense = MUSE_DOWNSTAIRS; } else if (x == xupstair && y == yupstair) { - m.has_defense = MUSE_UPSTAIRS; + g.m.has_defense = MUSE_UPSTAIRS; } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) { if (sstairs.up || !is_floater(mtmp->data)) - m.has_defense = MUSE_SSTAIRS; + g.m.has_defense = MUSE_SSTAIRS; } } else if (levl[x][y].typ == LADDER) { if (x == xupladder && y == yupladder) { - m.has_defense = MUSE_UP_LADDER; + g.m.has_defense = MUSE_UP_LADDER; } else if (x == xdnladder && y == ydnladder) { if (!is_floater(mtmp->data)) - m.has_defense = MUSE_DN_LADDER; + g.m.has_defense = MUSE_DN_LADDER; } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) { if (sstairs.up || !is_floater(mtmp->data)) - m.has_defense = MUSE_SSTAIRS; + g.m.has_defense = MUSE_SSTAIRS; } } else { /* Note: trap doors take precedence over teleport traps. */ @@ -434,12 +424,12 @@ struct monst *mtmp; && Can_fall_thru(&u.uz)) { g.trapx = xx; g.trapy = yy; - m.has_defense = MUSE_TRAPDOOR; + g.m.has_defense = MUSE_TRAPDOOR; break; /* no need to look at any other spots */ } else if (t->ttyp == TELEP_TRAP) { g.trapx = xx; g.trapy = yy; - m.has_defense = MUSE_TELEPORT_TRAP; + g.m.has_defense = MUSE_TELEPORT_TRAP; } } } @@ -462,8 +452,8 @@ struct monst *mtmp; if ((mon = m_at(xx, yy)) != 0 && is_mercenary(mon->data) && mon->data != &mons[PM_GUARD] && (mon->msleeping || !mon->mcanmove)) { - m.defensive = obj; - m.has_defense = MUSE_BUGLE; + g.m.defensive = obj; + g.m.has_defense = MUSE_BUGLE; goto toot; /* double break */ } } @@ -473,7 +463,7 @@ struct monst *mtmp; } /* use immediate physical escape prior to attempting magic */ - if (m.has_defense) /* stairs, trap door or tele-trap, bugle alert */ + if (g.m.has_defense) /* stairs, trap door or tele-trap, bugle alert */ goto botm; /* kludge to cut down on trap destruction (particularly portals) */ @@ -482,16 +472,16 @@ struct monst *mtmp; || t->ttyp == BEAR_TRAP)) t = 0; /* ok for monster to dig here */ -#define nomore(x) if (m.has_defense == x) continue; +#define nomore(x) if (g.m.has_defense == x) continue; /* selection could be improved by collecting all possibilities into an array and then picking one at random */ for (obj = mtmp->minvent; obj; obj = obj->nobj) { /* don't always use the same selection pattern */ - if (m.has_defense && !rn2(3)) + if (g.m.has_defense && !rn2(3)) break; /* nomore(MUSE_WAN_DIGGING); */ - if (m.has_defense == MUSE_WAN_DIGGING) + if (g.m.has_defense == MUSE_WAN_DIGGING) break; if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest @@ -504,8 +494,8 @@ struct monst *mtmp; && !(is_ice(x, y) || is_pool(x, y) || is_lava(x, y)) && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER] && In_V_tower(&u.uz))) { - m.defensive = obj; - m.has_defense = MUSE_WAN_DIGGING; + g.m.defensive = obj; + g.m.has_defense = MUSE_WAN_DIGGING; } nomore(MUSE_WAN_TELEPORTATION_SELF); nomore(MUSE_WAN_TELEPORTATION); @@ -518,8 +508,8 @@ struct monst *mtmp; */ if (!level.flags.noteleport || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) { - m.defensive = obj; - m.has_defense = (mon_has_amulet(mtmp)) + g.m.defensive = obj; + g.m.has_defense = (mon_has_amulet(mtmp)) ? MUSE_WAN_TELEPORTATION : MUSE_WAN_TELEPORTATION_SELF; } @@ -532,52 +522,52 @@ struct monst *mtmp; /* see WAN_TELEPORTATION case above */ if (!level.flags.noteleport || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) { - m.defensive = obj; - m.has_defense = MUSE_SCR_TELEPORTATION; + g.m.defensive = obj; + g.m.has_defense = MUSE_SCR_TELEPORTATION; } } if (mtmp->data != &mons[PM_PESTILENCE]) { nomore(MUSE_POT_FULL_HEALING); if (obj->otyp == POT_FULL_HEALING) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_FULL_HEALING; } nomore(MUSE_POT_EXTRA_HEALING); if (obj->otyp == POT_EXTRA_HEALING) { - m.defensive = obj; - m.has_defense = MUSE_POT_EXTRA_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_EXTRA_HEALING; } nomore(MUSE_WAN_CREATE_MONSTER); if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { - m.defensive = obj; - m.has_defense = MUSE_WAN_CREATE_MONSTER; + g.m.defensive = obj; + g.m.has_defense = MUSE_WAN_CREATE_MONSTER; } nomore(MUSE_POT_HEALING); if (obj->otyp == POT_HEALING) { - m.defensive = obj; - m.has_defense = MUSE_POT_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_HEALING; } } else { /* Pestilence */ nomore(MUSE_POT_FULL_HEALING); if (obj->otyp == POT_SICKNESS) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; + g.m.defensive = obj; + g.m.has_defense = MUSE_POT_FULL_HEALING; } nomore(MUSE_WAN_CREATE_MONSTER); if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { - m.defensive = obj; - m.has_defense = MUSE_WAN_CREATE_MONSTER; + g.m.defensive = obj; + g.m.has_defense = MUSE_WAN_CREATE_MONSTER; } } nomore(MUSE_SCR_CREATE_MONSTER); if (obj->otyp == SCR_CREATE_MONSTER) { - m.defensive = obj; - m.has_defense = MUSE_SCR_CREATE_MONSTER; + g.m.defensive = obj; + g.m.has_defense = MUSE_SCR_CREATE_MONSTER; } } botm: - return (boolean) !!m.has_defense; + return (boolean) !!g.m.has_defense; #undef nomore } @@ -590,7 +580,7 @@ use_defensive(mtmp) struct monst *mtmp; { int i, fleetim, how = 0; - struct obj *otmp = m.defensive; + struct obj *otmp = g.m.defensive; boolean vis, vismon, oseen; const char *Mnam; @@ -608,7 +598,7 @@ struct monst *mtmp; monflee(m, fleetim, FALSE, FALSE); \ } - switch (m.has_defense) { + switch (g.m.has_defense) { case MUSE_UNICORN_HORN: if (vismon) { if (otmp) @@ -968,7 +958,7 @@ struct monst *mtmp; return 0; /* i.e. an exploded wand */ default: impossible("%s wanted to perform action %d?", Monnam(mtmp), - m.has_defense); + g.m.has_defense); break; } return 0; @@ -1051,8 +1041,8 @@ struct monst *mtmp; boolean reflection_skip = (Reflecting && rn2(2)); struct obj *helmet = which_armor(mtmp, W_ARMH); - m.offensive = (struct obj *) 0; - m.has_offense = 0; + g.m.offensive = (struct obj *) 0; + g.m.has_offense = 0; if (mtmp->mpeaceful || is_animal(mtmp->data) || mindless(mtmp->data) || nohands(mtmp->data)) return FALSE; @@ -1068,55 +1058,55 @@ struct monst *mtmp; if (!lined_up(mtmp)) return FALSE; -#define nomore(x) if (m.has_offense == x) continue; +#define nomore(x) if (g.m.has_offense == x) continue; /* this picks the last viable item rather than prioritizing choices */ for (obj = mtmp->minvent; obj; obj = obj->nobj) { if (!reflection_skip) { nomore(MUSE_WAN_DEATH); if (obj->otyp == WAN_DEATH && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_DEATH; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_DEATH; } nomore(MUSE_WAN_SLEEP); if (obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_SLEEP; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_SLEEP; } nomore(MUSE_WAN_FIRE); if (obj->otyp == WAN_FIRE && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_FIRE; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_FIRE; } nomore(MUSE_FIRE_HORN); if (obj->otyp == FIRE_HORN && obj->spe > 0 && can_blow(mtmp)) { - m.offensive = obj; - m.has_offense = MUSE_FIRE_HORN; + g.m.offensive = obj; + g.m.has_offense = MUSE_FIRE_HORN; } nomore(MUSE_WAN_COLD); if (obj->otyp == WAN_COLD && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_COLD; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_COLD; } nomore(MUSE_FROST_HORN); if (obj->otyp == FROST_HORN && obj->spe > 0 && can_blow(mtmp)) { - m.offensive = obj; - m.has_offense = MUSE_FROST_HORN; + g.m.offensive = obj; + g.m.has_offense = MUSE_FROST_HORN; } nomore(MUSE_WAN_LIGHTNING); if (obj->otyp == WAN_LIGHTNING && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_LIGHTNING; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_LIGHTNING; } nomore(MUSE_WAN_MAGIC_MISSILE); if (obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_MAGIC_MISSILE; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_MAGIC_MISSILE; } } nomore(MUSE_WAN_STRIKING); if (obj->otyp == WAN_STRIKING && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_STRIKING; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_STRIKING; } #if 0 /* use_offensive() has had some code to support wand of teleportation * for a long time, but find_offensive() never selected one; @@ -1132,34 +1122,34 @@ struct monst *mtmp; || (u.ux == sstairs.sx && u.uy == sstairs.sy) || (u.ux == xupladder && u.uy == yupladder) || (u.ux == xdnladder && u.uy == ydnladder))) { - m.offensive = obj; - m.has_offense = MUSE_WAN_TELEPORTATION; + g.m.offensive = obj; + g.m.has_offense = MUSE_WAN_TELEPORTATION; } #endif nomore(MUSE_POT_PARALYSIS); if (obj->otyp == POT_PARALYSIS && multi >= 0) { - m.offensive = obj; - m.has_offense = MUSE_POT_PARALYSIS; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_PARALYSIS; } nomore(MUSE_POT_BLINDNESS); if (obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) { - m.offensive = obj; - m.has_offense = MUSE_POT_BLINDNESS; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_BLINDNESS; } nomore(MUSE_POT_CONFUSION); if (obj->otyp == POT_CONFUSION) { - m.offensive = obj; - m.has_offense = MUSE_POT_CONFUSION; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_CONFUSION; } nomore(MUSE_POT_SLEEPING); if (obj->otyp == POT_SLEEPING) { - m.offensive = obj; - m.has_offense = MUSE_POT_SLEEPING; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_SLEEPING; } nomore(MUSE_POT_ACID); if (obj->otyp == POT_ACID) { - m.offensive = obj; - m.has_offense = MUSE_POT_ACID; + g.m.offensive = obj; + g.m.has_offense = MUSE_POT_ACID; } /* we can safely put this scroll here since the locations that * are in a 1 square radius are a subset of the locations that @@ -1175,20 +1165,20 @@ struct monst *mtmp; && mtmp->mcansee && haseyes(mtmp->data) && !Is_rogue_level(&u.uz) && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) { - m.offensive = obj; - m.has_offense = MUSE_SCR_EARTH; + g.m.offensive = obj; + g.m.has_offense = MUSE_SCR_EARTH; } #if 0 nomore(MUSE_SCR_FIRE); if (obj->otyp == SCR_FIRE && resists_fire(mtmp) && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2 && mtmp->mcansee && haseyes(mtmp->data)) { - m.offensive = obj; - m.has_offense = MUSE_SCR_FIRE; + g.m.offensive = obj; + g.m.has_offense = MUSE_SCR_FIRE; } #endif /* 0 */ } - return (boolean) !!m.has_offense; + return (boolean) !!g.m.has_offense; #undef nomore } @@ -1371,7 +1361,7 @@ use_offensive(mtmp) struct monst *mtmp; { int i; - struct obj *otmp = m.offensive; + struct obj *otmp = g.m.offensive; boolean oseen; /* offensive potions are not drunk, they're thrown */ @@ -1379,7 +1369,7 @@ struct monst *mtmp; return i; oseen = otmp && canseemon(mtmp); - switch (m.has_offense) { + switch (g.m.has_offense) { case MUSE_WAN_DEATH: case MUSE_WAN_SLEEP: case MUSE_WAN_FIRE: @@ -1534,7 +1524,7 @@ struct monst *mtmp; return 0; /* i.e. an exploded wand */ default: impossible("%s wanted to perform action %d?", Monnam(mtmp), - m.has_offense); + g.m.has_offense); break; } return 0; @@ -1610,8 +1600,8 @@ struct monst *mtmp; boolean immobile = (mdat->mmove == 0); boolean stuck = (mtmp == u.ustuck); - m.misc = (struct obj *) 0; - m.has_misc = 0; + g.m.misc = (struct obj *) 0; + g.m.has_misc = 0; if (is_animal(mdat) || mindless(mdat)) return 0; if (u.uswallow && stuck) @@ -1642,7 +1632,7 @@ struct monst *mtmp; if (t->ttyp == POLY_TRAP) { g.trapx = xx; g.trapy = yy; - m.has_misc = MUSE_POLY_TRAP; + g.m.has_misc = MUSE_POLY_TRAP; return TRUE; } } @@ -1650,7 +1640,7 @@ struct monst *mtmp; if (nohands(mdat)) return 0; -#define nomore(x) if (m.has_misc == x) continue +#define nomore(x) if (g.m.has_misc == x) continue /* * [bug?] Choice of item is not prioritized; the last viable one * in the monster's inventory will be chosen. @@ -1663,8 +1653,8 @@ struct monst *mtmp; if (obj->otyp == POT_GAIN_LEVEL && (!obj->cursed || (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) { - m.misc = obj; - m.has_misc = MUSE_POT_GAIN_LEVEL; + g.m.misc = obj; + g.m.has_misc = MUSE_POT_GAIN_LEVEL; } nomore(MUSE_BULLWHIP); if (obj->otyp == BULLWHIP && !mtmp->mpeaceful @@ -1678,8 +1668,8 @@ struct monst *mtmp; prevent cursed weapons from being targetted) */ && (canletgo(uwep, "") || (u.twoweap && canletgo(uswapwep, "")))) { - m.misc = obj; - m.has_misc = MUSE_BULLWHIP; + g.m.misc = obj; + g.m.has_misc = MUSE_BULLWHIP; } /* Note: peaceful/tame monsters won't make themselves * invisible unless you can see them. Not really right, but... @@ -1688,41 +1678,41 @@ struct monst *mtmp; if (obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && !mtmp->minvis && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible) && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { - m.misc = obj; - m.has_misc = MUSE_WAN_MAKE_INVISIBLE; + g.m.misc = obj; + g.m.has_misc = MUSE_WAN_MAKE_INVISIBLE; } nomore(MUSE_POT_INVISIBILITY); if (obj->otyp == POT_INVISIBILITY && !mtmp->minvis && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible) && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { - m.misc = obj; - m.has_misc = MUSE_POT_INVISIBILITY; + g.m.misc = obj; + g.m.has_misc = MUSE_POT_INVISIBILITY; } nomore(MUSE_WAN_SPEED_MONSTER); if (obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0 && mtmp->mspeed != MFAST && !mtmp->isgd) { - m.misc = obj; - m.has_misc = MUSE_WAN_SPEED_MONSTER; + g.m.misc = obj; + g.m.has_misc = MUSE_WAN_SPEED_MONSTER; } nomore(MUSE_POT_SPEED); if (obj->otyp == POT_SPEED && mtmp->mspeed != MFAST && !mtmp->isgd) { - m.misc = obj; - m.has_misc = MUSE_POT_SPEED; + g.m.misc = obj; + g.m.has_misc = MUSE_POT_SPEED; } nomore(MUSE_WAN_POLYMORPH); if (obj->otyp == WAN_POLYMORPH && obj->spe > 0 && (mtmp->cham == NON_PM) && mons[monsndx(mdat)].difficulty < 6) { - m.misc = obj; - m.has_misc = MUSE_WAN_POLYMORPH; + g.m.misc = obj; + g.m.has_misc = MUSE_WAN_POLYMORPH; } nomore(MUSE_POT_POLYMORPH); if (obj->otyp == POT_POLYMORPH && (mtmp->cham == NON_PM) && mons[monsndx(mdat)].difficulty < 6) { - m.misc = obj; - m.has_misc = MUSE_POT_POLYMORPH; + g.m.misc = obj; + g.m.has_misc = MUSE_POT_POLYMORPH; } } - return (boolean) !!m.has_misc; + return (boolean) !!g.m.has_misc; #undef nomore } @@ -1748,7 +1738,7 @@ use_misc(mtmp) struct monst *mtmp; { int i; - struct obj *otmp = m.misc; + struct obj *otmp = g.m.misc; boolean vis, vismon, oseen; char nambuf[BUFSZ]; @@ -1758,7 +1748,7 @@ struct monst *mtmp; vismon = canseemon(mtmp); oseen = otmp && vismon; - switch (m.has_misc) { + switch (g.m.has_misc) { case MUSE_POT_GAIN_LEVEL: mquaffmsg(mtmp, otmp); if (otmp->cursed) { @@ -1951,7 +1941,7 @@ struct monst *mtmp; return 0; /* i.e. an exploded wand */ default: impossible("%s wanted to perform action %d?", Monnam(mtmp), - m.has_misc); + g.m.has_misc); break; } return 0;