Moved pray.c globals to instance_globals.

This commit is contained in:
Bart House
2018-11-23 16:50:23 -08:00
parent 1c1e5b7e36
commit 74caa8d8e4
11 changed files with 88 additions and 105 deletions

View File

@@ -464,6 +464,14 @@ struct instance_globals {
/* muse.c */
boolean m_using; /* kludge to use mondided instead of killed */
int trapx;
int trapy;
boolean zap_oseen; /* for wands which use mbhitm and are zapped at
* players. We usually want an oseen local to
* the function, but this is impossible since the
* function mbhitm has to be compatible with the
* normal zap routines, and those routines don't
* remember who zapped the wand. */
/* objname.c */
/* distantname used by distant_name() to pass extra information to
@@ -498,6 +506,13 @@ struct instance_globals {
int potion_nothing;
int potion_unkn;
/* pray.c */
/* values calculated when prayer starts, and used when completed */
aligntyp p_aligntyp;
int p_trouble;
int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */
/* read.c */
boolean known;

View File

@@ -1432,6 +1432,7 @@ E boolean FDECL(angry_guards, (BOOLEAN_P));
E void NDECL(pacify_guards);
E void FDECL(decide_to_shapeshift, (struct monst *, int));
E boolean FDECL(vamp_stone, (struct monst *));
E void NDECL(monst_globals_init);
/* ### mondata.c ### */
@@ -1504,8 +1505,6 @@ E boolean FDECL(undesirable_disp, (struct monst *, XCHAR_P, XCHAR_P));
/* ### monst.c ### */
E void NDECL(monst_init);
/* ### monstr.c ### */
E void NDECL(monstr_init);

View File

@@ -30,11 +30,6 @@ boolean resuming;
int moveamt = 0, wtcap = 0, change = 0;
boolean monscanmove = FALSE;
/* Note: these initializers don't do anything except guarantee that
we're linked properly.
*/
monst_init();
/* if a save file created in normal mode is now being restored in
explore mode, treat it as normal restore followed by 'X' command
to use up the save file and require confirmation for explore mode */

View File

@@ -338,6 +338,9 @@ const struct instance_globals g_init = {
/* mused.c */
FALSE, /* m_using */
UNDEFINED_VALUE, /* trapx */
UNDEFINED_VALUE, /* trapy */
UNDEFINED_VALUE, /* zap_oseen */
/* objname.c */
0, /* distantname */
@@ -363,6 +366,11 @@ const struct instance_globals g_init = {
UNDEFINED_VALUE, /* potion_nothing */
UNDEFINED_VALUE, /* potion_unkn */
/* pray.c */
UNDEFINED_VALUE, /* p_aligntyp */
UNDEFINED_VALUE, /* p_trouble */
UNDEFINED_VALUE, /* p_type */
/* read.c */
UNDEFINED_VALUE, /* known */

View File

@@ -27,7 +27,6 @@
#define C(color)
#endif
void NDECL(monst_init);
/*
* Entry Format: (from permonst.h)
*
@@ -101,7 +100,7 @@ void NDECL(monst_init);
*/
#ifndef SPLITMON_2
NEARDATA struct permonst mons[] = {
NEARDATA struct permonst mons_init[] = {
/*
* ants
*/
@@ -3228,10 +3227,13 @@ struct permonst _mons2[] = {
#endif /* !SPLITMON_1 */
#ifndef SPLITMON_1
/* dummy routine used to force linkage */
struct permonst mons[SIZE(mons_init)];
void
monst_init()
monst_globals_init()
{
memcpy(mons, mons_init, sizeof(mons));
return;
}

View File

@@ -44,13 +44,6 @@ static struct musable {
* If it's an object, the object is also set (it's 0 otherwise).
*/
} m;
static int trapx, trapy;
static boolean zap_oseen; /* for wands which use mbhitm and are zapped at
* players. We usually want an oseen local to
* the function, but this is impossible since the
* function mbhitm has to be compatible with the
* normal zap routines, and those routines don't
* remember who zapped the wand. */
/* Any preliminary checks which may result in the monster being unable to use
* the item. Returns 0 if nothing happened, 2 if the monster can't do
@@ -439,13 +432,13 @@ struct monst *mtmp;
&& !is_floater(mtmp->data)
&& !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
&& Can_fall_thru(&u.uz)) {
trapx = xx;
trapy = yy;
g.trapx = xx;
g.trapy = yy;
m.has_defense = MUSE_TRAPDOOR;
break; /* no need to look at any other spots */
} else if (t->ttyp == TELEP_TRAP) {
trapx = xx;
trapy = yy;
g.trapx = xx;
g.trapy = yy;
m.has_defense = MUSE_TELEPORT_TRAP;
}
}
@@ -665,7 +658,7 @@ struct monst *mtmp;
(void) rloc(mtmp, TRUE);
return 2;
case MUSE_WAN_TELEPORTATION:
zap_oseen = oseen;
g.zap_oseen = oseen;
mzapmsg(mtmp, otmp, FALSE);
otmp->spe--;
g.m_using = TRUE;
@@ -813,26 +806,26 @@ struct monst *mtmp;
return 0;
m_flee(mtmp);
if (vis) {
struct trap *t = t_at(trapx, trapy);
struct trap *t = t_at(g.trapx, g.trapy);
Mnam = Monnam(mtmp);
pline("%s %s into a %s!", Mnam,
vtense(Mnam, locomotion(mtmp->data, "jump")),
(t->ttyp == TRAPDOOR) ? "trap door" : "hole");
if (levl[trapx][trapy].typ == SCORR) {
levl[trapx][trapy].typ = CORR;
unblock_point(trapx, trapy);
if (levl[g.trapx][g.trapy].typ == SCORR) {
levl[g.trapx][g.trapy].typ = CORR;
unblock_point(g.trapx, g.trapy);
}
seetrap(t_at(trapx, trapy));
seetrap(t_at(g.trapx, g.trapy));
}
/* don't use rloc_to() because worm tails must "move" */
remove_monster(mtmp->mx, mtmp->my);
newsym(mtmp->mx, mtmp->my); /* update old location */
place_monster(mtmp, trapx, trapy);
place_monster(mtmp, g.trapx, g.trapy);
if (mtmp->wormno)
worm_move(mtmp);
newsym(trapx, trapy);
newsym(g.trapx, g.trapy);
migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
(coord *) 0);
@@ -915,15 +908,15 @@ struct monst *mtmp;
Mnam = Monnam(mtmp);
pline("%s %s onto a teleport trap!", Mnam,
vtense(Mnam, locomotion(mtmp->data, "jump")));
seetrap(t_at(trapx, trapy));
seetrap(t_at(g.trapx, g.trapy));
}
/* don't use rloc_to() because worm tails must "move" */
remove_monster(mtmp->mx, mtmp->my);
newsym(mtmp->mx, mtmp->my); /* update old location */
place_monster(mtmp, trapx, trapy);
place_monster(mtmp, g.trapx, g.trapy);
if (mtmp->wormno)
worm_move(mtmp);
newsym(trapx, trapy);
newsym(g.trapx, g.trapy);
goto mon_tele;
case MUSE_POT_HEALING:
@@ -1217,7 +1210,7 @@ register struct obj *otmp;
case WAN_STRIKING:
reveal_invis = TRUE;
if (mtmp == &youmonst) {
if (zap_oseen)
if (g.zap_oseen)
makeknown(WAN_STRIKING);
if (Antimagic) {
shieldeff(u.ux, u.uy);
@@ -1239,18 +1232,18 @@ register struct obj *otmp;
tmp = d(2, 12);
hit("wand", mtmp, exclam(tmp));
(void) resist(mtmp, otmp->oclass, tmp, TELL);
if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
if (cansee(mtmp->mx, mtmp->my) && g.zap_oseen)
makeknown(WAN_STRIKING);
} else {
miss("wand", mtmp);
if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
if (cansee(mtmp->mx, mtmp->my) && g.zap_oseen)
makeknown(WAN_STRIKING);
}
break;
#if 0 /* disabled because find_offensive() never picks WAN_TELEPORTATION */
case WAN_TELEPORTATION:
if (mtmp == &youmonst) {
if (zap_oseen)
if (g.zap_oseen)
makeknown(WAN_TELEPORTATION);
tele();
} else {
@@ -1349,7 +1342,7 @@ struct obj *obj; /* 2nd arg to fhitm/fhito */
case WAN_LOCKING:
case WAN_STRIKING:
if (doorlock(obj, bhitpos.x, bhitpos.y)) {
if (zap_oseen)
if (g.zap_oseen)
makeknown(obj->otyp);
/* if a shop door gets broken, add it to
the shk's fix list (no cost to player) */
@@ -1419,7 +1412,7 @@ struct monst *mtmp;
return (DEADMONSTER(mtmp)) ? 1 : 2;
case MUSE_WAN_TELEPORTATION:
case MUSE_WAN_STRIKING:
zap_oseen = oseen;
g.zap_oseen = oseen;
mzapmsg(mtmp, otmp, FALSE);
otmp->spe--;
g.m_using = TRUE;
@@ -1647,8 +1640,8 @@ struct monst *mtmp;
&& !onscary(xx, yy, mtmp)) {
/* use trap if it's the correct type */
if (t->ttyp == POLY_TRAP) {
trapx = xx;
trapy = yy;
g.trapx = xx;
g.trapy = yy;
m.has_misc = MUSE_POLY_TRAP;
return TRUE;
}
@@ -1876,15 +1869,15 @@ struct monst *mtmp;
vtense(Mnam, locomotion(mtmp->data, "jump")));
}
if (vis)
seetrap(t_at(trapx, trapy));
seetrap(t_at(g.trapx, g.trapy));
/* don't use rloc() due to worms */
remove_monster(mtmp->mx, mtmp->my);
newsym(mtmp->mx, mtmp->my);
place_monster(mtmp, trapx, trapy);
place_monster(mtmp, g.trapx, g.trapy);
if (mtmp->wormno)
worm_move(mtmp);
newsym(trapx, trapy);
newsym(g.trapx, g.trapy);
(void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
return 2;

View File

@@ -47,11 +47,6 @@ static const char *godvoices[] = {
"booms out", "thunders", "rings out", "booms",
};
/* values calculated when prayer starts, and used when completed */
static aligntyp p_aligntyp;
static int p_trouble;
static int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */
#define PIOUS 20
#define DEVOUT 14
#define FERVENT 9
@@ -907,7 +902,7 @@ aligntyp g_align;
: Hallucination ? "full" : "satisfied");
/* not your deity */
if (on_altar() && p_aligntyp != u.ualign.type) {
if (on_altar() && g.p_aligntyp != u.ualign.type) {
adjalign(-1);
return;
} else if (u.ualign.record < 2 && trouble <= 0)
@@ -929,7 +924,7 @@ aligntyp g_align;
*/
if (!trouble && u.ualign.record >= DEVOUT) {
/* if hero was in trouble, but got better, no special favor */
if (p_trouble == 0)
if (g.p_trouble == 0)
pat_on_head = 1;
} else {
int action, prayer_luck;
@@ -1768,47 +1763,47 @@ boolean praying; /* false means no messages should be given */
{
int alignment;
p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type;
p_trouble = in_trouble();
g.p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type;
g.p_trouble = in_trouble();
if (is_demon(youmonst.data) && (p_aligntyp != A_CHAOTIC)) {
if (is_demon(youmonst.data) && (g.p_aligntyp != A_CHAOTIC)) {
if (praying)
pline_The("very idea of praying to a %s god is repugnant to you.",
p_aligntyp ? "lawful" : "neutral");
g.p_aligntyp ? "lawful" : "neutral");
return FALSE;
}
if (praying)
You("begin praying to %s.", align_gname(p_aligntyp));
You("begin praying to %s.", align_gname(g.p_aligntyp));
if (u.ualign.type && u.ualign.type == -p_aligntyp)
if (u.ualign.type && u.ualign.type == -g.p_aligntyp)
alignment = -u.ualign.record; /* Opposite alignment altar */
else if (u.ualign.type != p_aligntyp)
else if (u.ualign.type != g.p_aligntyp)
alignment = u.ualign.record / 2; /* Different alignment altar */
else
alignment = u.ualign.record;
if ((p_trouble > 0) ? (u.ublesscnt > 200) /* big trouble */
: (p_trouble < 0) ? (u.ublesscnt > 100) /* minor difficulties */
if ((g.p_trouble > 0) ? (u.ublesscnt > 200) /* big trouble */
: (g.p_trouble < 0) ? (u.ublesscnt > 100) /* minor difficulties */
: (u.ublesscnt > 0)) /* not in trouble */
p_type = 0; /* too soon... */
g.p_type = 0; /* too soon... */
else if ((int) Luck < 0 || u.ugangr || alignment < 0)
p_type = 1; /* too naughty... */
g.p_type = 1; /* too naughty... */
else /* alignment >= 0 */ {
if (on_altar() && u.ualign.type != p_aligntyp)
p_type = 2;
if (on_altar() && u.ualign.type != g.p_aligntyp)
g.p_type = 2;
else
p_type = 3;
g.p_type = 3;
}
if (is_undead(youmonst.data) && !Inhell
&& (p_aligntyp == A_LAWFUL || (p_aligntyp == A_NEUTRAL && !rn2(10))))
p_type = -1;
&& (g.p_aligntyp == A_LAWFUL || (g.p_aligntyp == A_NEUTRAL && !rn2(10))))
g.p_type = -1;
/* Note: when !praying, the random factor for neutrals makes the
return value a non-deterministic approximation for enlightenment.
This case should be uncommon enough to live with... */
return !praying ? (boolean) (p_type == 3 && !Inhell) : TRUE;
return !praying ? (boolean) (g.p_type == 3 && !Inhell) : TRUE;
}
/* #pray commmand */
@@ -1825,7 +1820,7 @@ dopray()
if (!can_pray(TRUE))
return 0;
if (wizard && p_type >= 0) {
if (wizard && g.p_type >= 0) {
if (yn("Force the gods to be pleased?") == 'y') {
u.ublesscnt = 0;
if (u.uluck < 0)
@@ -1833,8 +1828,8 @@ dopray()
if (u.ualign.record <= 0)
u.ualign.record = 1;
u.ugangr = 0;
if (p_type < 2)
p_type = 3;
if (g.p_type < 2)
g.p_type = 3;
}
}
nomul(-3);
@@ -1842,7 +1837,7 @@ dopray()
nomovemsg = "You finish your prayer.";
afternmv = prayer_done;
if (p_type == 3 && !Inhell) {
if (g.p_type == 3 && !Inhell) {
/* if you've been true to your god you can't die while you pray */
if (!Blind)
You("are surrounded by a shimmering light.");
@@ -1855,10 +1850,10 @@ dopray()
STATIC_PTR int
prayer_done() /* M. Stephenson (1.0.3b) */
{
aligntyp alignment = p_aligntyp;
aligntyp alignment = g.p_aligntyp;
u.uinvulnerable = FALSE;
if (p_type == -1) {
if (g.p_type == -1) {
godvoice(alignment,
(alignment == A_LAWFUL)
? "Vile creature, thou durst call upon me?"
@@ -1880,17 +1875,17 @@ prayer_done() /* M. Stephenson (1.0.3b) */
return 0;
}
if (p_type == 0) {
if (g.p_type == 0) {
if (on_altar() && u.ualign.type != alignment)
(void) water_prayer(FALSE);
u.ublesscnt += rnz(250);
change_luck(-3);
gods_upset(u.ualign.type);
} else if (p_type == 1) {
} else if (g.p_type == 1) {
if (on_altar() && u.ualign.type != alignment)
(void) water_prayer(FALSE);
angrygods(u.ualign.type); /* naughty */
} else if (p_type == 2) {
} else if (g.p_type == 2) {
if (water_prayer(FALSE)) {
/* attempted water prayer on a non-coaligned altar */
u.ublesscnt += rnz(250);

View File

@@ -108,9 +108,6 @@ struct lc_vardefs *FDECL(vardef_defined, (struct lc_vardefs *, char *, int));
void FDECL(splev_add_from, (sp_lev *, sp_lev *));
extern void NDECL(monst_init);
extern void NDECL(objects_globals_init);
void FDECL(add_opcode, (sp_lev *, int, genericptr_t));
static boolean FDECL(write_common_data, (int));
@@ -258,11 +255,7 @@ char **argv;
decl_globals_init();
objects_globals_init();
/* Note: these initializers don't do anything except guarantee that
* we're linked properly.
*/
monst_init();
monst_globals_init();
/* this one does something... */
init_obj_classes();

View File

@@ -175,10 +175,9 @@ void NDECL(do_vision);
void NDECL(do_fix_sampleconfig);
#endif
extern void NDECL(monst_init); /* monst.c */
extern void NDECL(monst_globals_init); /* monst.c */
extern void NDECL(objects_globals_init); /* objects.c */
static void NDECL(link_sanity_check);
static char *FDECL(name_file, (const char *, const char *));
static void FDECL(delete_file, (const char *template, const char *));
static FILE *FDECL(getfp, (const char *, const char *, const char *));
@@ -301,16 +300,6 @@ char *argv[];
#endif
static void
link_sanity_check()
{
/* Note: these initializers don't do anything except guarantee that
we're linked properly.
*/
monst_init();
}
void
do_makedefs(options)
char *options;
@@ -318,8 +307,7 @@ char *options;
boolean more_than_one;
objects_globals_init();
link_sanity_check();
monst_globals_init();
/* construct the current version number */
make_version();
@@ -469,8 +457,6 @@ do_ext_makedefs(int argc, char **argv)
{
int todo = 0;
link_sanity_check();
argc--;
argv++; /* skip program name */

View File

@@ -204,6 +204,7 @@ char *argv[];
#endif
objects_globals_init();
monst_globals_init();
tilecount = 0;
xoffset = yoffset = 0;

View File

@@ -109,10 +109,6 @@ int set, entry;
int i, j, condnum, tilenum;
static char buf[BUFSZ];
/* Note: these initializers don't do anything except guarantee that
we're linked properly.
*/
monst_init();
(void) def_char_to_objclass(']');
condnum = tilenum = 0;