Structurization of hints.

This commit is contained in:
Eric S. Raymond 2023-04-07 10:52:16 -04:00
parent eebc87f889
commit 8d4d64fafb
3 changed files with 20 additions and 18 deletions

View file

@ -191,14 +191,16 @@ struct game_t {
loc_t loc; // location of dwarves, initially hard-wired in loc_t loc; // location of dwarves, initially hard-wired in
loc_t oldloc; // prior loc of each dwarf, initially garbage loc_t oldloc; // prior loc of each dwarf, initially garbage
} dwarves[NDWARVES + 1]; } dwarves[NDWARVES + 1];
struct object { struct {
loc_t fixed; // fixed location of object (if not IS_FREE) loc_t fixed; // fixed location of object (if not IS_FREE)
int prop; // object state */ int prop; // object state */
loc_t place; // location of object loc_t place; // location of object
} objects[NOBJECTS + 1]; } objects[NOBJECTS + 1];
struct {
bool used; // hints[i].used = true iff hint i has been used.
int lc; // hints[i].lc = show int at LOC with cond bit i
} hints[NHINTS];
obj_t link[NOBJECTS * 2 + 1];// object-list links obj_t link[NOBJECTS * 2 + 1];// object-list links
bool hinted[NHINTS]; // hinted[i] = true iff hint i has been used.
int hintlc[NHINTS]; // hintlc[i] = show int at LOC with cond bit i
}; };
/* /*

28
main.c
View file

@ -104,14 +104,14 @@ static void checkhints(void)
{ {
if (conditions[game.loc] >= game.conds) { if (conditions[game.loc] >= game.conds) {
for (int hint = 0; hint < NHINTS; hint++) { for (int hint = 0; hint < NHINTS; hint++) {
if (game.hinted[hint]) if (game.hints[hint].used)
continue; continue;
if (!CNDBIT(game.loc, hint + 1 + COND_HBASE)) if (!CNDBIT(game.loc, hint + 1 + COND_HBASE))
game.hintlc[hint] = -1; game.hints[hint].lc = -1;
++game.hintlc[hint]; ++game.hints[hint].lc;
/* Come here if he's been int enough at required loc(s) for some /* Come here if he's been int enough at required loc(s) for some
* unused hint. */ * unused hint. */
if (game.hintlc[hint] >= hints[hint].turns) { if (game.hints[hint].lc >= hints[hint].turns) {
int i; int i;
switch (hint) { switch (hint) {
@ -119,7 +119,7 @@ static void checkhints(void)
/* cave */ /* cave */
if (game.objects[GRATE].prop == GRATE_CLOSED && !HERE(KEYS)) if (game.objects[GRATE].prop == GRATE_CLOSED && !HERE(KEYS))
break; break;
game.hintlc[hint] = 0; game.hints[hint].lc = 0;
return; return;
case 1: /* bird */ case 1: /* bird */
if (game.objects[BIRD].place == game.loc && TOTING(ROD) && game.oldobj == BIRD) if (game.objects[BIRD].place == game.loc && TOTING(ROD) && game.oldobj == BIRD)
@ -128,7 +128,7 @@ static void checkhints(void)
case 2: /* snake */ case 2: /* snake */
if (HERE(SNAKE) && !HERE(BIRD)) if (HERE(SNAKE) && !HERE(BIRD))
break; break;
game.hintlc[hint] = 0; game.hints[hint].lc = 0;
return; return;
case 3: /* maze */ case 3: /* maze */
if (game.locs[game.loc].atloc == NO_OBJECT && if (game.locs[game.loc].atloc == NO_OBJECT &&
@ -136,19 +136,19 @@ static void checkhints(void)
game.locs[game.oldlc2].atloc == NO_OBJECT && game.locs[game.oldlc2].atloc == NO_OBJECT &&
game.holdng > 1) game.holdng > 1)
break; break;
game.hintlc[hint] = 0; game.hints[hint].lc = 0;
return; return;
case 4: /* dark */ case 4: /* dark */
if (game.objects[EMERALD].prop != STATE_NOTFOUND && game.objects[PYRAMID].prop == STATE_NOTFOUND) if (game.objects[EMERALD].prop != STATE_NOTFOUND && game.objects[PYRAMID].prop == STATE_NOTFOUND)
break; break;
game.hintlc[hint] = 0; game.hints[hint].lc = 0;
return; return;
case 5: /* witt */ case 5: /* witt */
break; break;
case 6: /* urn */ case 6: /* urn */
if (game.dflag == 0) if (game.dflag == 0)
break; break;
game.hintlc[hint] = 0; game.hints[hint].lc = 0;
return; return;
case 7: /* woods */ case 7: /* woods */
if (game.locs[game.loc].atloc == NO_OBJECT && if (game.locs[game.loc].atloc == NO_OBJECT &&
@ -159,7 +159,7 @@ static void checkhints(void)
case 8: /* ogre */ case 8: /* ogre */
i = atdwrf(game.loc); i = atdwrf(game.loc);
if (i < 0) { if (i < 0) {
game.hintlc[hint] = 0; game.hints[hint].lc = 0;
return; return;
} }
if (HERE(OGRE) && i == 0) if (HERE(OGRE) && i == 0)
@ -168,7 +168,7 @@ static void checkhints(void)
case 9: /* jade */ case 9: /* jade */
if (game.tally == 1 && game.objects[JADE].prop < 0) if (game.tally == 1 && game.objects[JADE].prop < 0)
break; break;
game.hintlc[hint] = 0; game.hints[hint].lc = 0;
return; return;
default: // LCOV_EXCL_LINE default: // LCOV_EXCL_LINE
// Should never happen // Should never happen
@ -176,12 +176,12 @@ static void checkhints(void)
} }
/* Fall through to hint display */ /* Fall through to hint display */
game.hintlc[hint] = 0; game.hints[hint].lc = 0;
if (!yes_or_no(hints[hint].question, arbitrary_messages[NO_MESSAGE], arbitrary_messages[OK_MAN])) if (!yes_or_no(hints[hint].question, arbitrary_messages[NO_MESSAGE], arbitrary_messages[OK_MAN]))
return; return;
rspeak(HINT_COST, hints[hint].penalty, hints[hint].penalty); rspeak(HINT_COST, hints[hint].penalty, hints[hint].penalty);
game.hinted[hint] = yes_or_no(arbitrary_messages[WANT_HINT], hints[hint].hint, arbitrary_messages[OK_MAN]); game.hints[hint].used = yes_or_no(arbitrary_messages[WANT_HINT], hints[hint].hint, arbitrary_messages[OK_MAN]);
if (game.hinted[hint] && game.limit > WARNTIME) if (game.hints[hint].used && game.limit > WARNTIME)
game.limit += WARNTIME * hints[hint].penalty; game.limit += WARNTIME * hints[hint].penalty;
} }
} }

View file

@ -96,7 +96,7 @@ int score(enum termination mode)
/* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */ /* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */
for (int i = 0; i < NHINTS; i++) { for (int i = 0; i < NHINTS; i++) {
if (game.hinted[i]) if (game.hints[i].used)
score = score - hints[i].penalty; score = score - hints[i].penalty;
} }
if (game.novice) if (game.novice)