Structurize locatiuon info.

This commit is contained in:
Eric S. Raymond 2023-04-07 09:30:33 -04:00
parent ff9c73a37d
commit 8fe07c8bf3
6 changed files with 27 additions and 25 deletions

View file

@ -303,11 +303,11 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj)
{ {
if (obj == INTRANSITIVE) { if (obj == INTRANSITIVE) {
/* Carry, no object given yet. OK if only one object present. */ /* Carry, no object given yet. OK if only one object present. */
if (game.atloc[game.loc] == NO_OBJECT || if (game.locs[game.loc].atloc == NO_OBJECT ||
game.link[game.atloc[game.loc]] != 0 || game.link[game.locs[game.loc].atloc] != 0 ||
atdwrf(game.loc) > 0) atdwrf(game.loc) > 0)
return GO_UNKNOWN; return GO_UNKNOWN;
obj = game.atloc[game.loc]; obj = game.locs[game.loc].atloc;
} }
if (TOTING(obj)) { if (TOTING(obj)) {

View file

@ -182,8 +182,10 @@ struct game_t {
turn_t trnluz; // # points lost so far due to turns used turn_t trnluz; // # points lost so far due to turns used
turn_t turns; // counts commands given (ignores yes/no) turn_t turns; // counts commands given (ignores yes/no)
char zzword[TOKLEN + 1]; // randomly generated magic word from bird char zzword[TOKLEN + 1]; // randomly generated magic word from bird
int abbrev[NLOCATIONS + 1]; // has location been seen? struct {
int atloc[NLOCATIONS + 1]; // head of object linked list per location int abbrev; // has location been seen?
int atloc; // head of object linked list per location
} locs[NLOCATIONS + 1];
struct { struct {
int seen; // true if dwarf has seen him int seen; // true if dwarf has seen him
loc_t loc; // location of dwarves, initially hard-wired in loc_t loc; // location of dwarves, initially hard-wired in

2
init.c
View file

@ -64,7 +64,7 @@ int initialise(void)
} }
} }
/* Set up the game.atloc and game.link arrays. /* Set up the game.locs atloc and game.link arrays.
* We'll use the DROP subroutine, which prefaces new objects on the * We'll use the DROP subroutine, which prefaces new objects on the
* lists. Since we want things in the other order, we'll run the * lists. Since we want things in the other order, we'll run the
* loop backwards. If the object is in two locs, we drop it twice. * loop backwards. If the object is in two locs, we drop it twice.

20
main.c
View file

@ -131,9 +131,9 @@ static void checkhints(void)
game.hintlc[hint] = 0; game.hintlc[hint] = 0;
return; return;
case 3: /* maze */ case 3: /* maze */
if (game.atloc[game.loc] == NO_OBJECT && if (game.locs[game.loc].atloc == NO_OBJECT &&
game.atloc[game.oldloc] == NO_OBJECT && game.locs[game.oldloc].atloc == NO_OBJECT &&
game.atloc[game.oldlc2] == NO_OBJECT && game.locs[game.oldlc2].atloc == NO_OBJECT &&
game.holdng > 1) game.holdng > 1)
break; break;
game.hintlc[hint] = 0; game.hintlc[hint] = 0;
@ -151,9 +151,9 @@ static void checkhints(void)
game.hintlc[hint] = 0; game.hintlc[hint] = 0;
return; return;
case 7: /* woods */ case 7: /* woods */
if (game.atloc[game.loc] == NO_OBJECT && if (game.locs[game.loc].atloc == NO_OBJECT &&
game.atloc[game.oldloc] == NO_OBJECT && game.locs[game.oldloc].atloc == NO_OBJECT &&
game.atloc[game.oldlc2] == NO_OBJECT) game.locs[game.oldlc2].atloc == NO_OBJECT)
break; break;
return; return;
case 8: /* ogre */ case 8: /* ogre */
@ -458,7 +458,7 @@ static void describe_location(void)
{ {
const char* msg = locations[game.loc].description.small; const char* msg = locations[game.loc].description.small;
if (MOD(game.abbrev[game.loc], game.abbnum) == 0 || msg == NO_MESSAGE) if (MOD(game.locs[game.loc].abbrev, game.abbnum) == 0 || msg == NO_MESSAGE)
msg = locations[game.loc].description.big; msg = locations[game.loc].description.big;
if (!FORCED(game.loc) && DARK(game.loc)) { if (!FORCED(game.loc) && DARK(game.loc)) {
@ -551,7 +551,7 @@ static void playermove(int motion)
rspeak(NO_MORE_DETAIL); rspeak(NO_MORE_DETAIL);
++game.detail; ++game.detail;
game.wzdark = false; game.wzdark = false;
game.abbrev[game.loc] = 0; game.locs[game.loc].abbrev = 0;
return; return;
} else if (motion == CAVE) { } else if (motion == CAVE) {
/* Cave. Different messages depending on whether above ground. */ /* Cave. Different messages depending on whether above ground. */
@ -910,8 +910,8 @@ static void listobjects(void)
* get full score. */ * get full score. */
{ {
if (!DARK(game.loc)) { if (!DARK(game.loc)) {
++game.abbrev[game.loc]; ++game.locs[game.loc].abbrev;
for (int i = game.atloc[game.loc]; i != 0; i = game.link[i]) { for (int i = game.locs[game.loc].atloc; i != 0; i = game.link[i]) {
obj_t obj = i; obj_t obj = i;
if (obj > NOBJECTS) if (obj > NOBJECTS)
obj = obj - NOBJECTS; obj = obj - NOBJECTS;

14
misc.c
View file

@ -581,7 +581,7 @@ void move(obj_t object, loc_t where)
/* Place any object anywhere by picking it up and dropping it. May /* Place any object anywhere by picking it up and dropping it. May
* already be toting, in which case the carry is a no-op. Mustn't * already be toting, in which case the carry is a no-op. Mustn't
* pick up objects which are not at any loc, since carry wants to * pick up objects which are not at any loc, since carry wants to
* remove objects from game.atloc chains. */ * remove objects from game atloc chains. */
{ {
loc_t from; loc_t from;
@ -625,11 +625,11 @@ void carry(obj_t object, loc_t where)
if (object != BIRD) if (object != BIRD)
++game.holdng; ++game.holdng;
} }
if (game.atloc[where] == object) { if (game.locs[where].atloc == object) {
game.atloc[where] = game.link[object]; game.locs[where].atloc = game.link[object];
return; return;
} }
temp = game.atloc[where]; temp = game.locs[where].atloc;
while (game.link[temp] != object) { while (game.link[temp] != object) {
temp = game.link[temp]; temp = game.link[temp];
} }
@ -637,7 +637,7 @@ void carry(obj_t object, loc_t where)
} }
void drop(obj_t object, loc_t where) void drop(obj_t object, loc_t where)
/* Place an object at a given loc, prefixing it onto the game.atloc list. Decr /* Place an object at a given loc, prefixing it onto the game atloc list. Decr
* game.holdng if the object was being toted. No state change on the object. */ * game.holdng if the object was being toted. No state change on the object. */
{ {
if (object > NOBJECTS) if (object > NOBJECTS)
@ -656,8 +656,8 @@ void drop(obj_t object, loc_t where)
} }
if (where == LOC_NOWHERE || where == CARRIED) if (where == LOC_NOWHERE || where == CARRIED)
return; return;
game.link[object] = game.atloc[where]; game.link[object] = game.locs[where].atloc;
game.atloc[where] = object; game.locs[where].atloc = object;
} }
int atdwrf(loc_t where) int atdwrf(loc_t where)

View file

@ -109,7 +109,7 @@ int resume(void)
#endif #endif
FILE *fp = NULL; FILE *fp = NULL;
if (game.loc != LOC_START || game.abbrev[LOC_START] != 1) { if (game.loc != LOC_START || game.locs[LOC_START].abbrev != 1) {
rspeak(RESUME_ABANDON); rspeak(RESUME_ABANDON);
if (!yes_or_no(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN])) if (!yes_or_no(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
return GO_CLEAROBJ; return GO_CLEAROBJ;
@ -258,7 +258,7 @@ bool is_valid(struct game_t valgame)
/* Check that values in linked lists for objects in locations are inside bounds */ /* Check that values in linked lists for objects in locations are inside bounds */
for (loc_t loc = LOC_NOWHERE; loc <= NLOCATIONS; loc++) { for (loc_t loc = LOC_NOWHERE; loc <= NLOCATIONS; loc++) {
if (valgame.atloc[loc] < NO_OBJECT || valgame.atloc[loc] > NOBJECTS * 2) { if (valgame.locs[loc].atloc < NO_OBJECT || valgame.locs[loc].atloc > NOBJECTS * 2) {
return false; // LCOV_EXCL_LINE return false; // LCOV_EXCL_LINE
} }
} }