Initial check in of icontext work.

This commit is contained in:
Bart House
2018-11-22 22:17:03 -08:00
parent 02749b7621
commit 8111624d0e
15 changed files with 110 additions and 77 deletions
-1
View File
@@ -552,7 +552,6 @@ typedef unsigned char uchar;
#endif #endif
/* End of Section 4 */ /* End of Section 4 */
#ifdef TTY_TILES_ESCCODES #ifdef TTY_TILES_ESCCODES
+26
View File
@@ -192,6 +192,7 @@ E NEARDATA char dogname[];
E NEARDATA char catname[]; E NEARDATA char catname[];
E NEARDATA char horsename[]; E NEARDATA char horsename[];
E char preferred_pet; E char preferred_pet;
E const char *occtxt; /* defined when occupation != NULL */ E const char *occtxt; /* defined when occupation != NULL */
E const char *nomovemsg; E const char *nomovemsg;
E char lock[]; E char lock[];
@@ -437,6 +438,31 @@ struct early_opt {
boolean valallowed; boolean valallowed;
}; };
/* instance_context holds per game instance data that does not need to be
* persisted upon game exit. This game instance data is one of the first
* things initialized during the initialization of the game engine.
* It is initialized with icontext_initial_state found in decl.c */
struct instance_context {
int oldcap; /* encumberance - pickup.c */
int petname_used; /* user preferred pet name has been used - dog.c */
int jumping_is_magic; /* current jump result of magic - apply.c */
int polearm_range_min; /* apply.c */
int polearm_range_max; /* apply.c */
int spec_dbon_applies; /* coordinate effects from spec_dbon() with
* messages in artifact_hit() - artifact.c */
int mrank_sz; /* loaded by max_rank_sz - botl.c */
short nocreate; /* ini_inv() - u_init.c = STRANGE_OBJECT */
short nocreate2; /* ini_inv() - u_init.c = STRANGE_OBJECT */
short nocreate3; /* ini_inv() - u_init.c = STRANGE_OBJECT */
short nocreate4; /* ini_inv() - u_init.c = STRANGE_OBJECT */
};
E struct instance_context icontext;
E void icontext_init();
#undef E #undef E
#endif /* DECL_H */ #endif /* DECL_H */
+6 -11
View File
@@ -1600,15 +1600,13 @@ boolean showmsg;
return TRUE; return TRUE;
} }
static int jumping_is_magic;
STATIC_OVL boolean STATIC_OVL boolean
get_valid_jump_position(x,y) get_valid_jump_position(x,y)
int x,y; int x,y;
{ {
return (isok(x, y) return (isok(x, y)
&& (ACCESSIBLE(levl[x][y].typ) || Passes_walls) && (ACCESSIBLE(levl[x][y].typ) || Passes_walls)
&& is_valid_jump_pos(x, y, jumping_is_magic, FALSE)); && is_valid_jump_pos(x, y, icontext.jumping_is_magic, FALSE));
} }
void void
@@ -1722,7 +1720,7 @@ int magic; /* 0=Physical, otherwise skill level */
pline("Where do you want to jump?"); pline("Where do you want to jump?");
cc.x = u.ux; cc.x = u.ux;
cc.y = u.uy; cc.y = u.uy;
jumping_is_magic = magic; icontext.jumping_is_magic = magic;
getpos_sethilite(display_jump_positions, get_valid_jump_position); getpos_sethilite(display_jump_positions, get_valid_jump_position);
if (getpos(&cc, TRUE, "the desired position") < 0) if (getpos(&cc, TRUE, "the desired position") < 0)
return 0; /* user pressed ESC */ return 0; /* user pressed ESC */
@@ -2914,16 +2912,13 @@ int min_range, max_range;
return TRUE; return TRUE;
} }
static int polearm_range_min = -1;
static int polearm_range_max = -1;
STATIC_OVL boolean STATIC_OVL boolean
get_valid_polearm_position(x, y) get_valid_polearm_position(x, y)
int x, y; int x, y;
{ {
return (isok(x, y) && ACCESSIBLE(levl[x][y].typ) return (isok(x, y) && ACCESSIBLE(levl[x][y].typ)
&& distu(x, y) >= polearm_range_min && distu(x, y) >= icontext.polearm_range_min
&& distu(x, y) <= polearm_range_max); && distu(x, y) <= icontext.polearm_range_max);
} }
void void
@@ -2995,8 +2990,8 @@ struct obj *obj;
else else
max_range = 8; /* (P_SKILL(typ) >= P_EXPERT) */ max_range = 8; /* (P_SKILL(typ) >= P_EXPERT) */
polearm_range_min = min_range; icontext.polearm_range_min = min_range;
polearm_range_max = max_range; icontext.polearm_range_max = max_range;
/* Prompt for a location */ /* Prompt for a location */
pline(where_to_hit); pline(where_to_hit);
+16 -19
View File
@@ -40,9 +40,6 @@ STATIC_DCL int FDECL(count_surround_traps, (int, int));
of hit points that will fit in a 15 bit integer. */ of hit points that will fit in a 15 bit integer. */
#define FATAL_DAMAGE_MODIFIER 200 #define FATAL_DAMAGE_MODIFIER 200
/* coordinate effects from spec_dbon() with messages in artifact_hit() */
STATIC_OVL int spec_dbon_applies = 0;
/* flags including which artifacts have already been created */ /* flags including which artifacts have already been created */
static boolean artiexist[1 + NROFARTIFACTS + 1]; static boolean artiexist[1 + NROFARTIFACTS + 1];
/* and a discovery list for them (no dummy first entry here) */ /* and a discovery list for them (no dummy first entry here) */
@@ -847,15 +844,15 @@ int tmp;
if (!weap || (weap->attk.adtyp == AD_PHYS /* check for `NO_ATTK' */ if (!weap || (weap->attk.adtyp == AD_PHYS /* check for `NO_ATTK' */
&& weap->attk.damn == 0 && weap->attk.damd == 0)) && weap->attk.damn == 0 && weap->attk.damd == 0))
spec_dbon_applies = FALSE; icontext.spec_dbon_applies = FALSE;
else if (otmp->oartifact == ART_GRIMTOOTH) else if (otmp->oartifact == ART_GRIMTOOTH)
/* Grimtooth has SPFX settings to warn against elves but we want its /* Grimtooth has SPFX settings to warn against elves but we want its
damage bonus to apply to all targets, so bypass spec_applies() */ damage bonus to apply to all targets, so bypass spec_applies() */
spec_dbon_applies = TRUE; icontext.spec_dbon_applies = TRUE;
else else
spec_dbon_applies = spec_applies(weap, mon); icontext.spec_dbon_applies = spec_applies(weap, mon);
if (spec_dbon_applies) if (icontext.spec_dbon_applies)
return weap->attk.damd ? rnd((int) weap->attk.damd) : max(tmp, 1); return weap->attk.damd ? rnd((int) weap->attk.damd) : max(tmp, 1);
return 0; return 0;
} }
@@ -979,14 +976,14 @@ char *hittee; /* target's name: "you" or mon_nam(mdef) */
scare_dieroll /= (1 << (mb->spe / 3)); scare_dieroll /= (1 << (mb->spe / 3));
/* if target successfully resisted the artifact damage bonus, /* if target successfully resisted the artifact damage bonus,
reduce overall likelihood of the assorted special effects */ reduce overall likelihood of the assorted special effects */
if (!spec_dbon_applies) if (!icontext.spec_dbon_applies)
dieroll += 1; dieroll += 1;
/* might stun even when attempting a more severe effect, but /* might stun even when attempting a more severe effect, but
in that case it will only happen if the other effect fails; in that case it will only happen if the other effect fails;
extra damage will apply regardless; 3.4.1: sometimes might extra damage will apply regardless; 3.4.1: sometimes might
just probe even when it hasn't been enchanted */ just probe even when it hasn't been enchanted */
do_stun = (max(mb->spe, 0) < rn2(spec_dbon_applies ? 11 : 7)); do_stun = (max(mb->spe, 0) < rn2(icontext.spec_dbon_applies ? 11 : 7));
/* the special effects also boost physical damage; increments are /* the special effects also boost physical damage; increments are
generally cumulative, but since the stun effect is based on a generally cumulative, but since the stun effect is based on a
@@ -1185,12 +1182,12 @@ int dieroll; /* needed for Magicbane and vorpal blades */
if (attacks(AD_FIRE, otmp)) { if (attacks(AD_FIRE, otmp)) {
if (realizes_damage) if (realizes_damage)
pline_The("fiery blade %s %s%c", pline_The("fiery blade %s %s%c",
!spec_dbon_applies !icontext.spec_dbon_applies
? "hits" ? "hits"
: (mdef->data == &mons[PM_WATER_ELEMENTAL]) : (mdef->data == &mons[PM_WATER_ELEMENTAL])
? "vaporizes part of" ? "vaporizes part of"
: "burns", : "burns",
hittee, !spec_dbon_applies ? '.' : '!'); hittee, !icontext.spec_dbon_applies ? '.' : '!');
if (!rn2(4)) if (!rn2(4))
(void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE); (void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
if (!rn2(4)) if (!rn2(4))
@@ -1204,8 +1201,8 @@ int dieroll; /* needed for Magicbane and vorpal blades */
if (attacks(AD_COLD, otmp)) { if (attacks(AD_COLD, otmp)) {
if (realizes_damage) if (realizes_damage)
pline_The("ice-cold blade %s %s%c", pline_The("ice-cold blade %s %s%c",
!spec_dbon_applies ? "hits" : "freezes", hittee, !icontext.spec_dbon_applies ? "hits" : "freezes", hittee,
!spec_dbon_applies ? '.' : '!'); !icontext.spec_dbon_applies ? '.' : '!');
if (!rn2(4)) if (!rn2(4))
(void) destroy_mitem(mdef, POTION_CLASS, AD_COLD); (void) destroy_mitem(mdef, POTION_CLASS, AD_COLD);
return realizes_damage; return realizes_damage;
@@ -1213,9 +1210,9 @@ int dieroll; /* needed for Magicbane and vorpal blades */
if (attacks(AD_ELEC, otmp)) { if (attacks(AD_ELEC, otmp)) {
if (realizes_damage) if (realizes_damage)
pline_The("massive hammer hits%s %s%c", pline_The("massive hammer hits%s %s%c",
!spec_dbon_applies ? "" : "! Lightning strikes", !icontext.spec_dbon_applies ? "" : "! Lightning strikes",
hittee, !spec_dbon_applies ? '.' : '!'); hittee, !icontext.spec_dbon_applies ? '.' : '!');
if (spec_dbon_applies) if (icontext.spec_dbon_applies)
wake_nearto(mdef->mx, mdef->my, 4 * 4); wake_nearto(mdef->mx, mdef->my, 4 * 4);
if (!rn2(5)) if (!rn2(5))
(void) destroy_mitem(mdef, RING_CLASS, AD_ELEC); (void) destroy_mitem(mdef, RING_CLASS, AD_ELEC);
@@ -1226,10 +1223,10 @@ int dieroll; /* needed for Magicbane and vorpal blades */
if (attacks(AD_MAGM, otmp)) { if (attacks(AD_MAGM, otmp)) {
if (realizes_damage) if (realizes_damage)
pline_The("imaginary widget hits%s %s%c", pline_The("imaginary widget hits%s %s%c",
!spec_dbon_applies !icontext.spec_dbon_applies
? "" ? ""
: "! A hail of magic missiles strikes", : "! A hail of magic missiles strikes",
hittee, !spec_dbon_applies ? '.' : '!'); hittee, !icontext.spec_dbon_applies ? '.' : '!');
return realizes_damage; return realizes_damage;
} }
@@ -1238,7 +1235,7 @@ int dieroll; /* needed for Magicbane and vorpal blades */
return Mb_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee); return Mb_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee);
} }
if (!spec_dbon_applies) { if (!icontext.spec_dbon_applies) {
/* since damage bonus didn't apply, nothing more to do; /* since damage bonus didn't apply, nothing more to do;
no further attacks have side-effects on inventory */ no further attacks have side-effects on inventory */
return FALSE; return FALSE;
+2 -3
View File
@@ -11,7 +11,6 @@ extern const char *hu_stat[]; /* defined in eat.c */
const char *const enc_stat[] = { "", "Burdened", "Stressed", const char *const enc_stat[] = { "", "Burdened", "Stressed",
"Strained", "Overtaxed", "Overloaded" }; "Strained", "Overtaxed", "Overloaded" };
STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */
STATIC_DCL const char *NDECL(rank); STATIC_DCL const char *NDECL(rank);
#ifdef STATUS_HILITES #ifdef STATUS_HILITES
STATIC_DCL void NDECL(bot_via_windowport); STATIC_DCL void NDECL(bot_via_windowport);
@@ -65,7 +64,7 @@ do_statusline1()
Strcpy(nb = eos(nb), rank()); Strcpy(nb = eos(nb), rank());
Sprintf(nb = eos(nb), " "); Sprintf(nb = eos(nb), " ");
i = mrank_sz + 15; i = icontext.mrank_sz + 15;
j = (int) ((nb + 2) - newbot1); /* strlen(newbot1) but less computation */ j = (int) ((nb + 2) - newbot1); /* strlen(newbot1) but less computation */
if ((i - j) > 0) if ((i - j) > 0)
Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */ Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */
@@ -346,7 +345,7 @@ max_rank_sz()
if (urole.rank[i].f && (r = strlen(urole.rank[i].f)) > maxr) if (urole.rank[i].f && (r = strlen(urole.rank[i].f)) > maxr)
maxr = r; maxr = r;
} }
mrank_sz = maxr; icontext.mrank_sz = maxr;
return; return;
} }
+28 -23
View File
@@ -284,7 +284,7 @@ char *fqn_prefix_names[PREFIX_COUNT] = {
}; };
#endif #endif
NEARDATA struct savefile_info sfcap = { const struct savefile_info default_sfinfo = {
#ifdef NHSTDC #ifdef NHSTDC
0x00000000UL 0x00000000UL
#else #else
@@ -307,28 +307,7 @@ NEARDATA struct savefile_info sfcap = {
#endif #endif
}; };
NEARDATA struct savefile_info sfrestinfo, sfsaveinfo = { NEARDATA struct savefile_info sfcap, sfrestinfo, sfsaveinfo;
#ifdef NHSTDC
0x00000000UL
#else
0x00000000L
#endif
#if defined(COMPRESS) || defined(ZLIB_COMP)
| SFI1_EXTERNALCOMP
#endif
#if defined(ZEROCOMP)
| SFI1_ZEROCOMP
#endif
#if defined(RLECOMP)
| SFI1_RLECOMP
#endif
,
#ifdef NHSTDC
0x00000000UL, 0x00000000UL
#else
0x00000000L, 0x00000000L
#endif
};
struct plinemsg_type *plinemsg_types = (struct plinemsg_type *) 0; struct plinemsg_type *plinemsg_types = (struct plinemsg_type *) 0;
@@ -346,4 +325,30 @@ decl_init()
return; return;
} }
const struct instance_context icontext_initial_state = {
0, /* oldcap - last encumberance in pickup.c */
0, /* petname_used - dog.c */
0, /* jumping_is_magic - apply.c */
-1, /* polearm_range_min - apply.c */
-1, /* polearm_range_max - apply.c */
0, /* spec_dbon_applies - artifact.c */
0, /* mrank_sz - botl.c */
STRANGE_OBJECT, /* nocreate - ini_inv() in u_init.c */
STRANGE_OBJECT, /* nocreate2 - ini_inv() in u_init.c */
STRANGE_OBJECT, /* nocreate3 - ini_inv() in u_init.c */
STRANGE_OBJECT, /* nocreate4 - ini_inv() in u_init.c */
};
struct instance_context icontext;
void
icontext_init()
{
icontext = icontext_initial_state;
sfcap = default_sfinfo;
sfrestinfo = default_sfinfo;
sfsaveinfo = default_sfinfo;
};
/*decl.c*/ /*decl.c*/
+1 -2
View File
@@ -160,7 +160,6 @@ makedog()
register struct obj *otmp; register struct obj *otmp;
const char *petname; const char *petname;
int pettype; int pettype;
static int petname_used = 0;
if (preferred_pet == 'n') if (preferred_pet == 'n')
return ((struct monst *) 0); return ((struct monst *) 0);
@@ -198,7 +197,7 @@ makedog()
put_saddle_on_mon(otmp, mtmp); put_saddle_on_mon(otmp, mtmp);
} }
if (!petname_used++ && *petname) if (!icontext.petname_used++ && *petname)
mtmp = christen_monst(mtmp, petname); mtmp = christen_monst(mtmp, petname);
initedog(mtmp); initedog(mtmp);
+3 -4
View File
@@ -1556,10 +1556,9 @@ struct obj *otmp;
int int
encumber_msg() encumber_msg()
{ {
static int oldcap = UNENCUMBERED;
int newcap = near_capacity(); int newcap = near_capacity();
if (oldcap < newcap) { if (icontext.oldcap < newcap) {
switch (newcap) { switch (newcap) {
case 1: case 1:
Your("movements are slowed slightly because of your load."); Your("movements are slowed slightly because of your load.");
@@ -1577,7 +1576,7 @@ encumber_msg()
break; break;
} }
context.botl = 1; context.botl = 1;
} else if (oldcap > newcap) { } else if (icontext.oldcap > newcap) {
switch (newcap) { switch (newcap) {
case 0: case 0:
Your("movements are now unencumbered."); Your("movements are now unencumbered.");
@@ -1596,7 +1595,7 @@ encumber_msg()
context.botl = 1; context.botl = 1;
} }
oldcap = newcap; icontext.oldcap = newcap;
return newcap; return newcap;
} }
+1 -1
View File
@@ -899,7 +899,7 @@ register int fd;
#ifdef MFLOPPY #ifdef MFLOPPY
gameDiskPrompt(); gameDiskPrompt();
#endif #endif
max_rank_sz(); /* to recompute mrank_sz (botl.c) */ max_rank_sz(); /* to recompute icontext.mrank_sz (botl.c) */
/* take care of iron ball & chain */ /* take care of iron ball & chain */
for (otmp = fobj; otmp; otmp = otmp->nobj) for (otmp = fobj; otmp; otmp = otmp->nobj)
if (otmp->owornmask) if (otmp->owornmask)
+9 -13
View File
@@ -974,15 +974,11 @@ register struct trobj *trop;
struct obj *obj; struct obj *obj;
int otyp, i; int otyp, i;
while (trop->trclass) { while (trop->trclass) {
otyp = (int) trop->trotyp; otyp = (int) trop->trotyp;
if (otyp != UNDEF_TYP) { if (otyp != UNDEF_TYP) {
obj = mksobj(otyp, TRUE, FALSE); obj = mksobj(otyp, TRUE, FALSE);
} else { /* UNDEF_TYP */ } else { /* UNDEF_TYP */
static NEARDATA short nocreate = STRANGE_OBJECT;
static NEARDATA short nocreate2 = STRANGE_OBJECT;
static NEARDATA short nocreate3 = STRANGE_OBJECT;
static NEARDATA short nocreate4 = STRANGE_OBJECT;
/* /*
* For random objects, do not create certain overly powerful * For random objects, do not create certain overly powerful
* items: wand of wishing, ring of levitation, or the * items: wand of wishing, ring of levitation, or the
@@ -995,9 +991,9 @@ register struct trobj *trop;
*/ */
obj = mkobj(trop->trclass, FALSE); obj = mkobj(trop->trclass, FALSE);
otyp = obj->otyp; otyp = obj->otyp;
while (otyp == WAN_WISHING || otyp == nocreate while (otyp == WAN_WISHING || otyp == icontext.nocreate
|| otyp == nocreate2 || otyp == nocreate3 || otyp == icontext.nocreate2 || otyp == icontext.nocreate3
|| otyp == nocreate4 || otyp == RIN_LEVITATION || otyp == icontext.nocreate4 || otyp == RIN_LEVITATION
/* 'useless' items */ /* 'useless' items */
|| otyp == POT_HALLUCINATION || otyp == POT_HALLUCINATION
|| otyp == POT_ACID || otyp == POT_ACID
@@ -1039,16 +1035,16 @@ register struct trobj *trop;
case WAN_POLYMORPH: case WAN_POLYMORPH:
case RIN_POLYMORPH: case RIN_POLYMORPH:
case POT_POLYMORPH: case POT_POLYMORPH:
nocreate = RIN_POLYMORPH_CONTROL; icontext.nocreate = RIN_POLYMORPH_CONTROL;
break; break;
case RIN_POLYMORPH_CONTROL: case RIN_POLYMORPH_CONTROL:
nocreate = RIN_POLYMORPH; icontext.nocreate = RIN_POLYMORPH;
nocreate2 = SPE_POLYMORPH; icontext.nocreate2 = SPE_POLYMORPH;
nocreate3 = POT_POLYMORPH; icontext.nocreate3 = POT_POLYMORPH;
} }
/* Don't have 2 of the same ring or spellbook */ /* Don't have 2 of the same ring or spellbook */
if (obj->oclass == RING_CLASS || obj->oclass == SPBOOK_CLASS) if (obj->oclass == RING_CLASS || obj->oclass == SPBOOK_CLASS)
nocreate4 = otyp; icontext.nocreate4 = otyp;
} }
if (urace.malenum != PM_HUMAN) { if (urace.malenum != PM_HUMAN) {
+2
View File
@@ -97,7 +97,9 @@ char *argv[];
nethack_enter(argc, argv); nethack_enter(argc, argv);
icontext_init();
sys_early_init(); sys_early_init();
#if defined(WIN32) && defined(TTY_GRAPHICS) #if defined(WIN32) && defined(TTY_GRAPHICS)
Strcpy(default_window_sys, "tty"); Strcpy(default_window_sys, "tty");
#else #else
+1
View File
@@ -37,6 +37,7 @@ char *argv[];
{ {
boolean resuming; boolean resuming;
icontext_init();
sys_early_init(); sys_early_init();
Strcpy(default_window_sys, "tty"); Strcpy(default_window_sys, "tty");
resuming = pcmain(argc, argv); resuming = pcmain(argc, argv);
+7
View File
@@ -1637,4 +1637,11 @@ short ospeed;
#endif #endif
#endif /* STRICT_REF_DEF */ #endif /* STRICT_REF_DEF */
/* nhassert_failed is called when an nhassert's condition is false */
void nhassert_failed(const char * exp, const char * file, int line)
{
fprintf(stderr, "NHASSERT(%s) in '%s' at line %d\n", exp, file, line);
exit(EXIT_FAILURE);
}
/*lev_main.c*/ /*lev_main.c*/
+7
View File
@@ -360,3 +360,10 @@ pixel (*pixels)[TILE_X];
} }
} }
} }
/* nhassert_failed is called when an nhassert's condition is false */
void nhassert_failed(const char * exp, const char * file, int line)
{
Fprintf(stderr, "NHASSERT(%s) in '%s' at line %d\n", exp, file, line);
exit(EXIT_FAILURE);
}
+1
View File
@@ -97,6 +97,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
win10_init(); win10_init();
icontext_init();
sys_early_init(); sys_early_init();
/* init applicatio structure */ /* init applicatio structure */