Structurize locatiuon info.
This commit is contained in:
parent
ff9c73a37d
commit
8fe07c8bf3
6 changed files with 27 additions and 25 deletions
|
@ -303,11 +303,11 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj)
|
|||
{
|
||||
if (obj == INTRANSITIVE) {
|
||||
/* Carry, no object given yet. OK if only one object present. */
|
||||
if (game.atloc[game.loc] == NO_OBJECT ||
|
||||
game.link[game.atloc[game.loc]] != 0 ||
|
||||
if (game.locs[game.loc].atloc == NO_OBJECT ||
|
||||
game.link[game.locs[game.loc].atloc] != 0 ||
|
||||
atdwrf(game.loc) > 0)
|
||||
return GO_UNKNOWN;
|
||||
obj = game.atloc[game.loc];
|
||||
obj = game.locs[game.loc].atloc;
|
||||
}
|
||||
|
||||
if (TOTING(obj)) {
|
||||
|
|
6
advent.h
6
advent.h
|
@ -182,8 +182,10 @@ struct game_t {
|
|||
turn_t trnluz; // # points lost so far due to turns used
|
||||
turn_t turns; // counts commands given (ignores yes/no)
|
||||
char zzword[TOKLEN + 1]; // randomly generated magic word from bird
|
||||
int abbrev[NLOCATIONS + 1]; // has location been seen?
|
||||
int atloc[NLOCATIONS + 1]; // head of object linked list per location
|
||||
struct {
|
||||
int abbrev; // has location been seen?
|
||||
int atloc; // head of object linked list per location
|
||||
} locs[NLOCATIONS + 1];
|
||||
struct {
|
||||
int seen; // true if dwarf has seen him
|
||||
loc_t loc; // location of dwarves, initially hard-wired in
|
||||
|
|
2
init.c
2
init.c
|
@ -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
|
||||
* 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.
|
||||
|
|
20
main.c
20
main.c
|
@ -131,9 +131,9 @@ static void checkhints(void)
|
|||
game.hintlc[hint] = 0;
|
||||
return;
|
||||
case 3: /* maze */
|
||||
if (game.atloc[game.loc] == NO_OBJECT &&
|
||||
game.atloc[game.oldloc] == NO_OBJECT &&
|
||||
game.atloc[game.oldlc2] == NO_OBJECT &&
|
||||
if (game.locs[game.loc].atloc == NO_OBJECT &&
|
||||
game.locs[game.oldloc].atloc == NO_OBJECT &&
|
||||
game.locs[game.oldlc2].atloc == NO_OBJECT &&
|
||||
game.holdng > 1)
|
||||
break;
|
||||
game.hintlc[hint] = 0;
|
||||
|
@ -151,9 +151,9 @@ static void checkhints(void)
|
|||
game.hintlc[hint] = 0;
|
||||
return;
|
||||
case 7: /* woods */
|
||||
if (game.atloc[game.loc] == NO_OBJECT &&
|
||||
game.atloc[game.oldloc] == NO_OBJECT &&
|
||||
game.atloc[game.oldlc2] == NO_OBJECT)
|
||||
if (game.locs[game.loc].atloc == NO_OBJECT &&
|
||||
game.locs[game.oldloc].atloc == NO_OBJECT &&
|
||||
game.locs[game.oldlc2].atloc == NO_OBJECT)
|
||||
break;
|
||||
return;
|
||||
case 8: /* ogre */
|
||||
|
@ -458,7 +458,7 @@ static void describe_location(void)
|
|||
{
|
||||
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;
|
||||
|
||||
if (!FORCED(game.loc) && DARK(game.loc)) {
|
||||
|
@ -551,7 +551,7 @@ static void playermove(int motion)
|
|||
rspeak(NO_MORE_DETAIL);
|
||||
++game.detail;
|
||||
game.wzdark = false;
|
||||
game.abbrev[game.loc] = 0;
|
||||
game.locs[game.loc].abbrev = 0;
|
||||
return;
|
||||
} else if (motion == CAVE) {
|
||||
/* Cave. Different messages depending on whether above ground. */
|
||||
|
@ -910,8 +910,8 @@ static void listobjects(void)
|
|||
* get full score. */
|
||||
{
|
||||
if (!DARK(game.loc)) {
|
||||
++game.abbrev[game.loc];
|
||||
for (int i = game.atloc[game.loc]; i != 0; i = game.link[i]) {
|
||||
++game.locs[game.loc].abbrev;
|
||||
for (int i = game.locs[game.loc].atloc; i != 0; i = game.link[i]) {
|
||||
obj_t obj = i;
|
||||
if (obj > NOBJECTS)
|
||||
obj = obj - NOBJECTS;
|
||||
|
|
14
misc.c
14
misc.c
|
@ -581,7 +581,7 @@ void move(obj_t object, loc_t where)
|
|||
/* 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
|
||||
* 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;
|
||||
|
||||
|
@ -625,11 +625,11 @@ void carry(obj_t object, loc_t where)
|
|||
if (object != BIRD)
|
||||
++game.holdng;
|
||||
}
|
||||
if (game.atloc[where] == object) {
|
||||
game.atloc[where] = game.link[object];
|
||||
if (game.locs[where].atloc == object) {
|
||||
game.locs[where].atloc = game.link[object];
|
||||
return;
|
||||
}
|
||||
temp = game.atloc[where];
|
||||
temp = game.locs[where].atloc;
|
||||
while (game.link[temp] != object) {
|
||||
temp = game.link[temp];
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ void carry(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. */
|
||||
{
|
||||
if (object > NOBJECTS)
|
||||
|
@ -656,8 +656,8 @@ void drop(obj_t object, loc_t where)
|
|||
}
|
||||
if (where == LOC_NOWHERE || where == CARRIED)
|
||||
return;
|
||||
game.link[object] = game.atloc[where];
|
||||
game.atloc[where] = object;
|
||||
game.link[object] = game.locs[where].atloc;
|
||||
game.locs[where].atloc = object;
|
||||
}
|
||||
|
||||
int atdwrf(loc_t where)
|
||||
|
|
|
@ -109,7 +109,7 @@ int resume(void)
|
|||
#endif
|
||||
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);
|
||||
if (!yes_or_no(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
|
||||
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 */
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue