From: Eric S. Raymond Date: Fri, 7 Apr 2023 13:51:49 +0000 (-0400) Subject: Structurize object info. X-Git-Tag: 1.16~18 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=eebc87f889b0fa1404684aa6e72dda5a5e53d96b;p=open-adventure.git Structurize object info. --- diff --git a/actions.c b/actions.c index 4a86f01..20f0b90 100644 --- a/actions.c +++ b/actions.c @@ -34,7 +34,7 @@ static phase_codes_t attack(command_t command) obj = SNAKE; ++changes; } - if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) { + if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS) { obj = DRAGON; ++changes; } @@ -46,7 +46,7 @@ static phase_codes_t attack(command_t command) obj = OGRE; ++changes; } - if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) { + if (HERE(BEAR) && game.objects[BEAR].prop == UNTAMED_BEAR) { obj = BEAR; ++changes; } @@ -83,13 +83,13 @@ static phase_codes_t attack(command_t command) } if (obj == VEND) { state_change(VEND, - game.prop[VEND] == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS); + game.objects[VEND].prop == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS); return GO_CLEAROBJ; } if (obj == BEAR) { - switch (game.prop[BEAR]) { + switch (game.objects[BEAR].prop) { case UNTAMED_BEAR: rspeak(BEAR_HANDS); break; @@ -105,7 +105,7 @@ static phase_codes_t attack(command_t command) } return GO_CLEAROBJ; } - if (obj == DRAGON && game.prop[DRAGON] == DRAGON_BARS) { + if (obj == DRAGON && game.objects[DRAGON].prop == DRAGON_BARS) { /* Fun stuff for dragon. If he insists on attacking it, win! * Set game.prop to dead, move dragon to central loc (still * fixed), move rug there (not fixed), and move him there, @@ -116,7 +116,7 @@ static phase_codes_t attack(command_t command) return GO_MOVE; } state_change(DRAGON, DRAGON_DEAD); - game.prop[RUG] = RUG_FLOOR; + game.objects[RUG].prop = RUG_FLOOR; /* Hardcoding LOC_SECRET5 as the dragon's death location is ugly. * The way it was computed before was worse; it depended on the * two dragon locations being LOC_SECRET4 and LOC_SECRET6 and @@ -128,8 +128,8 @@ static phase_codes_t attack(command_t command) move(RUG, LOC_SECRET5); drop(BLOOD, LOC_SECRET5); for (obj_t i = 1; i <= NOBJECTS; i++) { - if (game.place[i] == objects[DRAGON].plac || - game.place[i] == objects[DRAGON].fixd) + if (game.objects[i].place == objects[DRAGON].plac || + game.objects[i].place == objects[DRAGON].fixd) move(i, LOC_SECRET5); } game.loc = LOC_SECRET5; @@ -210,15 +210,16 @@ static phase_codes_t bigwords(vocab_t id) return GO_CLEAROBJ; } game.foobar = WORD_EMPTY; - if (game.place[EGGS] == objects[EGGS].plac || + if (game.objects[EGGS].place == objects[EGGS].plac || (TOTING(EGGS) && game.loc == objects[EGGS].plac)) { rspeak(NOTHING_HAPPENS); return GO_CLEAROBJ; } else { /* Bring back troll if we steal the eggs back from him before * crossing. */ - if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID) - game.prop[TROLL] = TROLL_PAIDONCE; + if (game.objects[EGGS].place == LOC_NOWHERE && game.objects[TROLL].place == LOC_NOWHERE + && game.objects[TROLL].prop == TROLL_UNPAID) + game.objects[TROLL].prop = TROLL_PAIDONCE; if (HERE(EGGS)) pspeak(EGGS, look, true, EGGS_VANISHED); else if (game.loc == objects[EGGS].plac) @@ -243,7 +244,7 @@ static phase_codes_t bigwords(vocab_t id) static void blast(void) /* Blast. No effect unless you've got dynamite, which is a neat trick! */ { - if (game.prop[ROD2] == STATE_NOTFOUND || !game.closed) + if (game.objects[ROD2].prop == STATE_NOTFOUND || !game.closed) rspeak(REQUIRES_DYNAMITE); else { if (HERE(ROD2)) { @@ -273,11 +274,11 @@ static phase_codes_t vbreak(verb_t verb, obj_t obj) break; } case VASE: - if (game.prop[VASE] == VASE_WHOLE) { + if (game.objects[VASE].prop == VASE_WHOLE) { if (TOTING(VASE)) drop(VASE, game.loc); state_change(VASE, VASE_BROKEN); - game.fixed[VASE] = IS_FIXED; + game.objects[VASE].fixed = IS_FIXED; break; } /* FALLTHRU */ @@ -321,20 +322,20 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj) return GO_CLEAROBJ; } - if (game.fixed[obj] != IS_FREE) { + if (game.objects[obj].fixed != IS_FREE) { switch (obj) { case PLANT: /* Next guard tests whether plant is tiny or stashed */ - rspeak(game.prop[PLANT] <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING); + rspeak(game.objects[PLANT].prop <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING); break; case BEAR: - rspeak( game.prop[BEAR] == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING); + rspeak( game.objects[BEAR].prop == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING); break; case CHAIN: - rspeak( game.prop[BEAR] != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING); + rspeak( game.objects[BEAR].prop != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING); break; case RUG: - rspeak(game.prop[RUG] == RUG_HOVER ? RUG_HOVERS : YOU_JOKING); + rspeak(game.objects[RUG].prop == RUG_HOVER ? RUG_HOVERS : YOU_JOKING); break; case URN: rspeak(URN_NOBUDGE); @@ -360,7 +361,7 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj) rspeak(NO_CONTAINER); return GO_CLEAROBJ; } - if (game.prop[BOTTLE] == EMPTY_BOTTLE) { + if (game.objects[BOTTLE].prop == EMPTY_BOTTLE) { return (fill(verb, BOTTLE)); } else rspeak(BOTTLE_FULL); @@ -375,8 +376,8 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj) } - if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) { - if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) { + if (obj == BIRD && game.objects[BIRD].prop != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) { + if (game.objects[BIRD].prop == BIRD_FOREST_UNCAGED) { DESTROY(BIRD); rspeak(BIRD_CRAP); return GO_CLEAROBJ; @@ -389,10 +390,10 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj) rspeak(BIRD_EVADES); return GO_CLEAROBJ; } - game.prop[BIRD] = BIRD_CAGED; + game.objects[BIRD].prop = BIRD_CAGED; } if ((obj == BIRD || obj == CAGE) && - (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) { + (game.objects[BIRD].prop == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) { /* expression maps BIRD to CAGE and CAGE to BIRD */ carry(BIRD + CAGE - obj, game.loc); } @@ -400,11 +401,11 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj) carry(obj, game.loc); if (obj == BOTTLE && LIQUID() != NO_OBJECT) - game.place[LIQUID()] = CARRIED; + game.objects[LIQUID()].place = CARRIED; - if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) { - game.prop[obj] = STATE_FOUND; - game.prop[CAVITY] = CAVITY_EMPTY; + if (GSTONE(obj) && game.objects[obj].prop != STATE_FOUND) { + game.objects[obj].prop = STATE_FOUND; + game.objects[CAVITY].prop = CAVITY_EMPTY; } rspeak(OK_MAN); return GO_CLEAROBJ; @@ -414,36 +415,36 @@ static int chain(verb_t verb) /* Do something to the bear's chain */ { if (verb != LOCK) { - if (game.prop[BEAR] == UNTAMED_BEAR) { + if (game.objects[BEAR].prop == UNTAMED_BEAR) { rspeak(BEAR_BLOCKS); return GO_CLEAROBJ; } - if (game.prop[CHAIN] == CHAIN_HEAP) { + if (game.objects[CHAIN].prop == CHAIN_HEAP) { rspeak(ALREADY_UNLOCKED); return GO_CLEAROBJ; } - game.prop[CHAIN] = CHAIN_HEAP; - game.fixed[CHAIN] = IS_FREE; - if (game.prop[BEAR] != BEAR_DEAD) - game.prop[BEAR] = CONTENTED_BEAR; + game.objects[CHAIN].prop = CHAIN_HEAP; + game.objects[CHAIN].fixed = IS_FREE; + if (game.objects[BEAR].prop != BEAR_DEAD) + game.objects[BEAR].prop = CONTENTED_BEAR; - switch (game.prop[BEAR]) { + switch (game.objects[BEAR].prop) { // LCOV_EXCL_START case BEAR_DEAD: /* Can't be reached until the bear can die in some way other * than a bridge collapse. Leave in in case this changes, but * exclude from coverage testing. */ - game.fixed[BEAR] = IS_FIXED; + game.objects[BEAR].fixed = IS_FIXED; break; // LCOV_EXCL_STOP default: - game.fixed[BEAR] = IS_FREE; + game.objects[BEAR].fixed = IS_FREE; } rspeak(CHAIN_UNLOCKED); return GO_CLEAROBJ; } - if (game.prop[CHAIN] != CHAIN_HEAP) { + if (game.objects[CHAIN].prop != CHAIN_HEAP) { rspeak(ALREADY_LOCKED); return GO_CLEAROBJ; } @@ -452,11 +453,11 @@ static int chain(verb_t verb) return GO_CLEAROBJ; } - game.prop[CHAIN] = CHAIN_FIXED; + game.objects[CHAIN].prop = CHAIN_FIXED; if (TOTING(CHAIN)) drop(CHAIN, game.loc); - game.fixed[CHAIN] = IS_FIXED; + game.objects[CHAIN].fixed = IS_FIXED; rspeak(CHAIN_LOCKED); return GO_CLEAROBJ; @@ -476,12 +477,12 @@ static phase_codes_t discard(verb_t verb, obj_t obj) return GO_CLEAROBJ; } - if (GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != CAVITY_FULL) { + if (GSTONE(obj) && AT(CAVITY) && game.objects[CAVITY].prop != CAVITY_FULL) { rspeak(GEM_FITS); - game.prop[obj] = STATE_IN_CAVITY; - game.prop[CAVITY] = CAVITY_FULL; - if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) || - (obj == RUBY && game.prop[RUG] == RUG_HOVER))) { + game.objects[obj].prop = STATE_IN_CAVITY; + game.objects[CAVITY].prop = CAVITY_FULL; + if (HERE(RUG) && ((obj == EMERALD && game.objects[RUG].prop != RUG_HOVER) || + (obj == RUBY && game.objects[RUG].prop == RUG_HOVER))) { if (obj == RUBY) rspeak(RUG_SETTLES); else if (TOTING(RUG)) @@ -489,8 +490,8 @@ static phase_codes_t discard(verb_t verb, obj_t obj) else rspeak(RUG_RISES); if (!TOTING(RUG) || obj == RUBY) { - int k = (game.prop[RUG] == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER; - game.prop[RUG] = k; + int k = (game.objects[RUG].prop == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER; + game.objects[RUG].prop = k; if (k == RUG_HOVER) k = objects[SAPPH].plac; move(RUG + NOBJECTS, k); @@ -510,7 +511,7 @@ static phase_codes_t discard(verb_t verb, obj_t obj) if (LIQUID() == obj) obj = BOTTLE; if (obj == BOTTLE && LIQUID() != NO_OBJECT) { - game.place[LIQUID()] = LOC_NOWHERE; + game.objects[LIQUID()].place = LOC_NOWHERE; } if (obj == BEAR && AT(TROLL)) { @@ -529,19 +530,19 @@ static phase_codes_t discard(verb_t verb, obj_t obj) state_change(VASE, AT(PILLOW) ? VASE_WHOLE : VASE_DROPPED); - if (game.prop[VASE] != VASE_WHOLE) - game.fixed[VASE] = IS_FIXED; + if (game.objects[VASE].prop != VASE_WHOLE) + game.objects[VASE].fixed = IS_FIXED; drop(obj, game.loc); return GO_CLEAROBJ; } } - if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) { + if (obj == CAGE && game.objects[BIRD].prop == BIRD_CAGED) { drop(BIRD, game.loc); } if (obj == BIRD) { - if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) { + if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS) { rspeak(BIRD_BURNT); DESTROY(BIRD); return GO_CLEAROBJ; @@ -552,11 +553,11 @@ static phase_codes_t discard(verb_t verb, obj_t obj) return GO_DWARFWAKE; DESTROY(SNAKE); /* Set game.prop for use by travel options */ - game.prop[SNAKE] = SNAKE_CHASED; + game.objects[SNAKE].prop = SNAKE_CHASED; } else rspeak(OK_MAN); - game.prop[BIRD] = FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED; + game.objects[BIRD].prop = FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED; drop(obj, game.loc); return GO_CLEAROBJ; } @@ -587,7 +588,7 @@ static phase_codes_t drink(verb_t verb, obj_t obj) return GO_CLEAROBJ; } if (LIQUID() == WATER && HERE(BOTTLE)) { - game.place[WATER] = LOC_NOWHERE; + game.objects[WATER].place = LOC_NOWHERE; state_change(BOTTLE, EMPTY_BOTTLE); return GO_CLEAROBJ; } @@ -630,9 +631,9 @@ static phase_codes_t extinguish(verb_t verb, obj_t obj) /* Extinguish. Lamp, urn, dragon/volcano (nice try). */ { if (obj == INTRANSITIVE) { - if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT) + if (HERE(LAMP) && game.objects[LAMP].prop == LAMP_BRIGHT) obj = LAMP; - if (HERE(URN) && game.prop[URN] == URN_LIT) + if (HERE(URN) && game.objects[URN].prop == URN_LIT) obj = URN; if (obj == INTRANSITIVE) return GO_UNKNOWN; @@ -640,7 +641,7 @@ static phase_codes_t extinguish(verb_t verb, obj_t obj) switch (obj) { case URN: - if (game.prop[URN] != URN_EMPTY) { + if (game.objects[URN].prop != URN_EMPTY) { state_change(URN, URN_DARK); } else { pspeak(URN, change, true, URN_DARK); @@ -671,7 +672,7 @@ static phase_codes_t feed(verb_t verb, obj_t obj) rspeak(BIRD_PINING); break; case DRAGON: - if (game.prop[DRAGON] != DRAGON_BARS) + if (game.objects[DRAGON].prop != DRAGON_BARS) rspeak(RIDICULOUS_ATTEMPT); else rspeak(NOTHING_EDIBLE); @@ -694,15 +695,15 @@ static phase_codes_t feed(verb_t verb, obj_t obj) speak(actions[verb].message); break; case BEAR: - if (game.prop[BEAR] == BEAR_DEAD) { + if (game.objects[BEAR].prop == BEAR_DEAD) { rspeak(RIDICULOUS_ATTEMPT); break; } - if (game.prop[BEAR] == UNTAMED_BEAR) { + if (game.objects[BEAR].prop == UNTAMED_BEAR) { if (HERE(FOOD)) { DESTROY(FOOD); - game.fixed[AXE] = IS_FREE; - game.prop[AXE] = AXE_HERE; + game.objects[AXE].fixed = IS_FREE; + game.objects[AXE].prop = AXE_HERE; state_change(BEAR, SITTING_BEAR); } else rspeak(NOTHING_EDIBLE); @@ -736,14 +737,14 @@ phase_codes_t fill(verb_t verb, obj_t obj) return GO_CLEAROBJ; } rspeak(SHATTER_VASE); - game.prop[VASE] = VASE_BROKEN; - game.fixed[VASE] = IS_FIXED; + game.objects[VASE].prop = VASE_BROKEN; + game.objects[VASE].fixed = IS_FIXED; drop(VASE, game.loc); return GO_CLEAROBJ; } if (obj == URN) { - if (game.prop[URN] != URN_EMPTY) { + if (game.objects[URN].prop != URN_EMPTY) { rspeak(FULL_URN); return GO_CLEAROBJ; } @@ -754,12 +755,12 @@ phase_codes_t fill(verb_t verb, obj_t obj) int k = LIQUID(); switch (k) { case WATER: - game.prop[BOTTLE] = EMPTY_BOTTLE; + game.objects[BOTTLE].prop = EMPTY_BOTTLE; rspeak(WATER_URN); break; case OIL: - game.prop[URN] = URN_DARK; - game.prop[BOTTLE] = EMPTY_BOTTLE; + game.objects[URN].prop = URN_DARK; + game.objects[BOTTLE].prop = EMPTY_BOTTLE; rspeak(OIL_URN); break; case NO_OBJECT: @@ -767,7 +768,7 @@ phase_codes_t fill(verb_t verb, obj_t obj) rspeak(FILL_INVALID); return GO_CLEAROBJ; } - game.place[k] = LOC_NOWHERE; + game.objects[k].place = LOC_NOWHERE; return GO_CLEAROBJ; } if (obj != INTRANSITIVE && obj != BOTTLE) { @@ -777,7 +778,7 @@ phase_codes_t fill(verb_t verb, obj_t obj) if (obj == INTRANSITIVE && !HERE(BOTTLE)) return GO_UNKNOWN; - if (HERE(URN) && game.prop[URN] != URN_EMPTY) { + if (HERE(URN) && game.objects[URN].prop != URN_EMPTY) { rspeak(URN_NOPOUR); return GO_CLEAROBJ; } @@ -794,7 +795,7 @@ phase_codes_t fill(verb_t verb, obj_t obj) ? OIL_BOTTLE : WATER_BOTTLE); if (TOTING(BOTTLE)) - game.place[LIQUID()] = CARRIED; + game.objects[LIQUID()].place = CARRIED; return GO_CLEAROBJ; } @@ -830,7 +831,7 @@ static phase_codes_t fly(verb_t verb, obj_t obj) rspeak(FLAP_ARMS); return GO_CLEAROBJ; } - if (game.prop[RUG] != RUG_HOVER) { + if (game.objects[RUG].prop != RUG_HOVER) { rspeak(RUG_NOTHING2); return GO_CLEAROBJ; } @@ -841,7 +842,7 @@ static phase_codes_t fly(verb_t verb, obj_t obj) speak(actions[verb].message); return GO_CLEAROBJ; } - if (game.prop[RUG] != RUG_HOVER) { + if (game.objects[RUG].prop != RUG_HOVER) { rspeak(RUG_NOTHING1); return GO_CLEAROBJ; } @@ -890,11 +891,11 @@ static phase_codes_t light(verb_t verb, obj_t obj) { if (obj == INTRANSITIVE) { int selects = 0; - if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0) { + if (HERE(LAMP) && game.objects[LAMP].prop == LAMP_DARK && game.limit >= 0) { obj = LAMP; selects++; } - if (HERE(URN) && game.prop[URN] == URN_DARK) { + if (HERE(URN) && game.objects[URN].prop == URN_DARK) { obj = URN; selects++; } @@ -904,7 +905,7 @@ static phase_codes_t light(verb_t verb, obj_t obj) switch (obj) { case URN: - state_change(URN, game.prop[URN] == URN_EMPTY ? + state_change(URN, game.objects[URN].prop == URN_EMPTY ? URN_EMPTY : URN_LIT); break; @@ -935,9 +936,9 @@ static phase_codes_t listen(void) soundlatch = true; } for (obj_t i = 1; i <= NOBJECTS; i++) { - if (!HERE(i) || objects[i].sounds[0] == NULL || game.prop[i] < 0) + if (!HERE(i) || objects[i].sounds[0] == NULL || game.objects[i].prop < 0) continue; - int mi = game.prop[i]; + int mi = game.objects[i].prop; /* (ESR) Some unpleasant magic on object states here. Ideally * we'd have liked the bird to be a normal object that we can * use state_change() on; can't do it, because there are @@ -1026,7 +1027,7 @@ static phase_codes_t lock(verb_t verb, obj_t obj) rspeak(OYSTER_OPENS); break; case DOOR: - rspeak((game.prop[DOOR] == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR); + rspeak((game.objects[DOOR].prop == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR); break; case CAGE: rspeak( NO_LOCK); @@ -1058,10 +1059,10 @@ static phase_codes_t pour(verb_t verb, obj_t obj) rspeak(CANT_POUR); return GO_CLEAROBJ; } - if (HERE(URN) && game.prop[URN] == URN_EMPTY) + if (HERE(URN) && game.objects[URN].prop == URN_EMPTY) return fill(verb, URN); - game.prop[BOTTLE] = EMPTY_BOTTLE; - game.place[obj] = LOC_NOWHERE; + game.objects[BOTTLE].prop = EMPTY_BOTTLE; + game.objects[obj].place = LOC_NOWHERE; if (!(AT(PLANT) || AT(DOOR))) { rspeak(GROUND_WET); return GO_CLEAROBJ; @@ -1069,8 +1070,8 @@ static phase_codes_t pour(verb_t verb, obj_t obj) if (!AT(DOOR)) { if (obj == WATER) { /* cycle through the three plant states */ - state_change(PLANT, MOD(game.prop[PLANT] + 1, 3)); - game.prop[PLANT2] = game.prop[PLANT]; + state_change(PLANT, MOD(game.objects[PLANT].prop + 1, 3)); + game.objects[PLANT2].prop = game.objects[PLANT].prop; return GO_MOVE; } else { rspeak(SHAKING_LEAVES); @@ -1098,7 +1099,7 @@ static phase_codes_t read(command_t command) if (command.obj == INTRANSITIVE) { command.obj = NO_OBJECT; for (int i = 1; i <= NOBJECTS; i++) { - if (HERE(i) && objects[i].texts[0] != NULL && game.prop[i] >= 0) + if (HERE(i) && objects[i].texts[0] != NULL && game.objects[i].prop >= 0) command.obj = command.obj * NOBJECTS + i; } if (command.obj > NOBJECTS || command.obj == NO_OBJECT || DARK(game.loc)) @@ -1116,10 +1117,10 @@ static phase_codes_t read(command_t command) pspeak(OYSTER, hear, true, 1); // Not really a sound, but oh well. } } else if (objects[command.obj].texts[0] == NULL || - game.prop[command.obj] == STATE_NOTFOUND) { + game.objects[command.obj].prop == STATE_NOTFOUND) { speak(actions[command.verb].message); } else - pspeak(command.obj, study, true, game.prop[command.obj]); + pspeak(command.obj, study, true, game.objects[command.obj].prop); return GO_CLEAROBJ; } @@ -1131,7 +1132,7 @@ static phase_codes_t reservoir(void) return GO_CLEAROBJ; } else { state_change(RESER, - game.prop[RESER] == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED); + game.objects[RESER].prop == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED); if (AT(RESER)) return GO_CLEAROBJ; else { @@ -1146,10 +1147,10 @@ static phase_codes_t reservoir(void) static phase_codes_t rub(verb_t verb, obj_t obj) /* Rub. Yields various snide remarks except for lit urn. */ { - if (obj == URN && game.prop[URN] == URN_LIT) { + if (obj == URN && game.objects[URN].prop == URN_LIT) { DESTROY(URN); drop(AMBER, game.loc); - game.prop[AMBER] = AMBER_IN_ROCK; + game.objects[AMBER].prop = AMBER_IN_ROCK; --game.tally; drop(CAVITY, game.loc); rspeak(URN_GENIES); @@ -1223,16 +1224,16 @@ static phase_codes_t throwit(command_t command) return (discard(command.verb, command.obj)); else { if (atdwrf(game.loc) <= 0) { - if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) + if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS) return throw_support(DRAGON_SCALES); if (AT(TROLL)) return throw_support(TROLL_RETURNS); if (AT(OGRE)) return throw_support(OGRE_DODGE); - if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) { + if (HERE(BEAR) && game.objects[BEAR].prop == UNTAMED_BEAR) { /* This'll teach him to throw the axe at the bear! */ drop(AXE, game.loc); - game.fixed[AXE] = IS_FIXED; + game.objects[AXE].fixed = IS_FIXED; juggle(BEAR); state_change(AXE, AXE_LOST); return GO_CLEAROBJ; @@ -1295,32 +1296,33 @@ static phase_codes_t wave(verb_t verb, obj_t obj) return GO_CLEAROBJ; } - if (game.prop[BIRD] == BIRD_UNCAGED && game.loc == game.place[STEPS] && game.prop[JADE] == STATE_NOTFOUND) { + if (game.objects[BIRD].prop == BIRD_UNCAGED && game.loc == game.objects[STEPS].place + && game.objects[JADE].prop == STATE_NOTFOUND) { drop(JADE, game.loc); - game.prop[JADE] = STATE_FOUND; + game.objects[JADE].prop = STATE_FOUND; --game.tally; rspeak(NECKLACE_FLY); return GO_CLEAROBJ; } else { if (game.closed) { - rspeak((game.prop[BIRD] == BIRD_CAGED) ? + rspeak((game.objects[BIRD].prop == BIRD_CAGED) ? CAGE_FLY : FREE_FLY); return GO_DWARFWAKE; } if (game.closng || !AT(FISSURE)) { - rspeak((game.prop[BIRD] == BIRD_CAGED) ? + rspeak((game.objects[BIRD].prop == BIRD_CAGED) ? CAGE_FLY : FREE_FLY); return GO_CLEAROBJ; } if (HERE(BIRD)) - rspeak((game.prop[BIRD] == BIRD_CAGED) ? + rspeak((game.objects[BIRD].prop == BIRD_CAGED) ? CAGE_FLY : FREE_FLY); state_change(FISSURE, - game.prop[FISSURE] == BRIDGED ? UNBRIDGED : BRIDGED); + game.objects[FISSURE].prop == BRIDGED ? UNBRIDGED : BRIDGED); return GO_CLEAROBJ; } } @@ -1353,10 +1355,10 @@ phase_codes_t action(command_t command) else if (!game.closed && ((LIQUID() == command.obj && HERE(BOTTLE)) || command.obj == LIQLOC(game.loc))) /* FALL THROUGH */; - else if (command.obj == OIL && HERE(URN) && game.prop[URN] != URN_EMPTY) { + else if (command.obj == OIL && HERE(URN) && game.objects[URN].prop != URN_EMPTY) { command.obj = URN; /* FALL THROUGH */; - } else if (command.obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != PLANT_THIRSTY) { + } else if (command.obj == PLANT && AT(PLANT2) && game.objects[PLANT2].prop != PLANT_THIRSTY) { command.obj = PLANT2; /* FALL THROUGH */; } else if (command.obj == KNIFE && game.knfloc == game.loc) { diff --git a/advent.h b/advent.h index 8150aa2..04d2fc2 100644 --- a/advent.h +++ b/advent.h @@ -51,7 +51,7 @@ /* Map a state property value to a negative range, where the object cannot be * picked up but the value can be recovered later. Avoid colliding with -1, * which has its own meaning as STATE_NOTFOUND. */ -#define STASHED(obj) (-1 - game.prop[obj]) +#define STASHED(obj) (-1 - game.objects[obj].prop) #define PROMPT "> " @@ -76,14 +76,14 @@ */ #define DESTROY(N) move(N, LOC_NOWHERE) #define MOD(N,M) ((N) % (M)) -#define TOTING(OBJ) (game.place[OBJ] == CARRIED) -#define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc) +#define TOTING(OBJ) (game.objects[OBJ].place == CARRIED) +#define AT(OBJ) (game.objects[OBJ].place == game.loc || game.objects[OBJ].fixed == game.loc) #define HERE(OBJ) (AT(OBJ) || TOTING(OBJ)) #define CNDBIT(L,N) (tstbit(conditions[L],N)) -#define LIQUID() (game.prop[BOTTLE] == WATER_BOTTLE? WATER : game.prop[BOTTLE] == OIL_BOTTLE ? OIL : NO_OBJECT ) +#define LIQUID() (game.objects[BOTTLE].prop == WATER_BOTTLE? WATER : game.objects[BOTTLE].prop == OIL_BOTTLE ? OIL : NO_OBJECT ) #define LIQLOC(LOC) (CNDBIT((LOC),COND_FLUID)? CNDBIT((LOC),COND_OILY) ? OIL : WATER : NO_OBJECT) #define FORCED(LOC) CNDBIT(LOC, COND_FORCED) -#define DARK(DUMMY) (!CNDBIT(game.loc,COND_LIT) && (game.prop[LAMP] == LAMP_DARK || !HERE(LAMP))) +#define DARK(DUMMY) (!CNDBIT(game.loc,COND_LIT) && (game.objects[LAMP].prop == LAMP_DARK || !HERE(LAMP))) #define PCT(N) (randrange(100) < (N)) #define GSTONE(OBJ) ((OBJ) == EMERALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH) #define FOREST(LOC) CNDBIT(LOC, COND_FOREST) @@ -191,12 +191,14 @@ struct game_t { loc_t loc; // location of dwarves, initially hard-wired in loc_t oldloc; // prior loc of each dwarf, initially garbage } dwarves[NDWARVES + 1]; - loc_t fixed[NOBJECTS + 1]; // fixed location of object (if not IS_FREE) + struct object { + loc_t fixed; // fixed location of object (if not IS_FREE) + int prop; // object state */ + loc_t place; // location of object + } objects[NOBJECTS + 1]; obj_t link[NOBJECTS * 2 + 1];// object-list links - loc_t place[NOBJECTS + 1]; // location of object 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 - int prop[NOBJECTS + 1]; // object state array */ }; /* diff --git a/init.c b/init.c index 29737be..c384f71 100644 --- a/init.c +++ b/init.c @@ -53,7 +53,7 @@ int initialise(void) set_seed(seedval); for (int i = 1; i <= NOBJECTS; i++) { - game.place[i] = LOC_NOWHERE; + game.objects[i].place = LOC_NOWHERE; } for (int i = 1; i <= NLOCATIONS; i++) { @@ -79,7 +79,7 @@ int initialise(void) for (int i = 1; i <= NOBJECTS; i++) { int k = NOBJECTS + 1 - i; - game.fixed[k] = objects[k].fixd; + game.objects[k].fixed = objects[k].fixd; if (objects[k].plac != 0 && objects[k].fixd <= 0) drop(k, objects[k].plac); } @@ -90,8 +90,8 @@ int initialise(void) for (int treasure = 1; treasure <= NOBJECTS; treasure++) { if (objects[treasure].is_treasure) { if (objects[treasure].inventory != 0) - game.prop[treasure] = STATE_NOTFOUND; - game.tally = game.tally - game.prop[treasure]; + game.objects[treasure].prop = STATE_NOTFOUND; + game.tally = game.tally - game.objects[treasure].prop; } } game.conds = setbit(COND_HBASE); diff --git a/main.c b/main.c index 98a1d7f..5e7d6ab 100644 --- a/main.c +++ b/main.c @@ -117,12 +117,12 @@ static void checkhints(void) switch (hint) { case 0: /* cave */ - if (game.prop[GRATE] == GRATE_CLOSED && !HERE(KEYS)) + if (game.objects[GRATE].prop == GRATE_CLOSED && !HERE(KEYS)) break; game.hintlc[hint] = 0; return; case 1: /* bird */ - if (game.place[BIRD] == game.loc && TOTING(ROD) && game.oldobj == BIRD) + if (game.objects[BIRD].place == game.loc && TOTING(ROD) && game.oldobj == BIRD) break; return; case 2: /* snake */ @@ -139,7 +139,7 @@ static void checkhints(void) game.hintlc[hint] = 0; return; case 4: /* dark */ - if (game.prop[EMERALD] != STATE_NOTFOUND && game.prop[PYRAMID] == STATE_NOTFOUND) + if (game.objects[EMERALD].prop != STATE_NOTFOUND && game.objects[PYRAMID].prop == STATE_NOTFOUND) break; game.hintlc[hint] = 0; return; @@ -166,7 +166,7 @@ static void checkhints(void) break; return; case 9: /* jade */ - if (game.tally == 1 && game.prop[JADE] < 0) + if (game.tally == 1 && game.objects[JADE].prop < 0) break; game.hintlc[hint] = 0; return; @@ -199,7 +199,7 @@ static bool spotted_by_pirate(int i) * that game.place[CHEST] = LOC_NOWHERE might mean that he's thrown * it to the troll, but in that case he's seen the chest * (game.prop[CHEST] == STATE_FOUND). */ - if (game.loc == game.chloc || game.prop[CHEST] != STATE_NOTFOUND) + if (game.loc == game.chloc || game.objects[CHEST].prop != STATE_NOTFOUND) return true; int snarfed = 0; bool movechest = false, robplayer = false; @@ -220,7 +220,7 @@ static bool spotted_by_pirate(int i) } } /* Force chest placement before player finds last treasure */ - if (game.tally == 1 && snarfed == 0 && game.place[CHEST] == LOC_NOWHERE && HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT) { + if (game.tally == 1 && snarfed == 0 && game.objects[CHEST].place == LOC_NOWHERE && HERE(LAMP) && game.objects[LAMP].prop == LAMP_BRIGHT) { rspeak(PIRATE_SPOTTED); movechest = true; } @@ -245,7 +245,7 @@ static bool spotted_by_pirate(int i) continue; if (!(treasure == PYRAMID && (game.loc == objects[PYRAMID].plac || game.loc == objects[EMERALD].plac))) { - if (AT(treasure) && game.fixed[treasure] == IS_FREE) + if (AT(treasure) && game.objects[treasure].fixed == IS_FREE) carry(treasure, game.loc); if (TOTING(treasure)) drop(treasure, game.chloc); @@ -439,9 +439,9 @@ static void croak(void) /* If player wishes to continue, we empty the liquids in the * user's inventory, turn off the lamp, and drop all items * where he died. */ - game.place[WATER] = game.place[OIL] = LOC_NOWHERE; + game.objects[WATER].place = game.objects[OIL].place = LOC_NOWHERE; if (TOTING(LAMP)) - game.prop[LAMP] = LAMP_DARK; + game.objects[LAMP].prop = LAMP_DARK; for (int j = 1; j <= NOBJECTS; j++) { int i = NOBJECTS + 1 - j; if (TOTING(i)) { @@ -628,7 +628,7 @@ static void playermove(int motion) else if (TOTING(condarg1) || (condtype == cond_with && AT(condarg1))) break; /* else fall through to check [not OBJ STATE] */ - } else if (game.prop[condarg1] != condarg2) + } else if (game.objects[condarg1].prop != condarg2) break; /* We arrive here on conditional failure. @@ -698,9 +698,9 @@ static void playermove(int motion) * (standard travel entries check for * game.prop[TROLL]=TROLL_UNPAID.) Special stuff * for bear. */ - if (game.prop[TROLL] == TROLL_PAIDONCE) { + if (game.objects[TROLL].prop == TROLL_PAIDONCE) { pspeak(TROLL, look, true, TROLL_PAIDONCE); - game.prop[TROLL] = TROLL_UNPAID; + game.objects[TROLL].prop = TROLL_UNPAID; DESTROY(TROLL2); move(TROLL2 + NOBJECTS, IS_FREE); move(TROLL, objects[TROLL].plac); @@ -710,15 +710,15 @@ static void playermove(int motion) return; } else { game.newloc = objects[TROLL].plac + objects[TROLL].fixd - game.loc; - if (game.prop[TROLL] == TROLL_UNPAID) - game.prop[TROLL] = TROLL_PAIDONCE; + if (game.objects[TROLL].prop == TROLL_UNPAID) + game.objects[TROLL].prop = TROLL_PAIDONCE; if (!TOTING(BEAR)) return; state_change(CHASM, BRIDGE_WRECKED); - game.prop[TROLL] = TROLL_GONE; + game.objects[TROLL].prop = TROLL_GONE; drop(BEAR, game.newloc); - game.fixed[BEAR] = IS_FIXED; - game.prop[BEAR] = BEAR_DEAD; + game.objects[BEAR].fixed = IS_FIXED; + game.objects[BEAR].prop = BEAR_DEAD; game.oldlc2 = game.newloc; croak(); return; @@ -736,7 +736,7 @@ static void playermove(int motion) static void lampcheck(void) /* Check game limit and lamp timers */ { - if (game.prop[LAMP] == LAMP_BRIGHT) + if (game.objects[LAMP].prop == LAMP_BRIGHT) --game.limit; /* Another way we can force an end to things is by having the @@ -746,9 +746,9 @@ static void lampcheck(void) * Second is for other cases of lamp dying. Even after it goes * out, he can explore outside for a while if desired. */ if (game.limit <= WARNTIME) { - if (HERE(BATTERY) && game.prop[BATTERY] == FRESH_BATTERIES && HERE(LAMP)) { + if (HERE(BATTERY) && game.objects[BATTERY].prop == FRESH_BATTERIES && HERE(LAMP)) { rspeak(REPLACE_BATTERIES); - game.prop[BATTERY] = DEAD_BATTERIES; + game.objects[BATTERY].prop = DEAD_BATTERIES; #ifdef __unused__ /* This code from the original game seems to have been faulty. * No tests ever passed the guard, and with the guard removed @@ -761,9 +761,9 @@ static void lampcheck(void) game.lmwarn = false; } else if (!game.lmwarn && HERE(LAMP)) { game.lmwarn = true; - if (game.prop[BATTERY] == DEAD_BATTERIES) + if (game.objects[BATTERY].prop == DEAD_BATTERIES) rspeak(MISSING_BATTERIES); - else if (game.place[BATTERY] == LOC_NOWHERE) + else if (game.objects[BATTERY].place == LOC_NOWHERE) rspeak(LAMP_DIM); else rspeak(GET_BATTERIES); @@ -771,7 +771,7 @@ static void lampcheck(void) } if (game.limit == 0) { game.limit = -1; - game.prop[LAMP] = LAMP_DARK; + game.objects[LAMP].prop = LAMP_DARK; if (HERE(LAMP)) rspeak(LAMP_OUT); } @@ -824,8 +824,8 @@ static bool closecheck(void) * know the bivalve is an oyster. *And*, the dwarves must * have been activated, since we've found chest. */ if (game.clock1 == 0) { - game.prop[GRATE] = GRATE_CLOSED; - game.prop[FISSURE] = UNBRIDGED; + game.objects[GRATE].prop = GRATE_CLOSED; + game.objects[FISSURE].prop = UNBRIDGED; for (int i = 1; i <= NDWARVES; i++) { game.dwarves[i].seen = false; game.dwarves[i].loc = LOC_NOWHERE; @@ -835,12 +835,12 @@ static bool closecheck(void) move(TROLL2, objects[TROLL].plac); move(TROLL2 + NOBJECTS, objects[TROLL].fixd); juggle(CHASM); - if (game.prop[BEAR] != BEAR_DEAD) + if (game.objects[BEAR].prop != BEAR_DEAD) DESTROY(BEAR); - game.prop[CHAIN] = CHAIN_HEAP; - game.fixed[CHAIN] = IS_FREE; - game.prop[AXE] = AXE_HERE; - game.fixed[AXE] = IS_FREE; + game.objects[CHAIN].prop = CHAIN_HEAP; + game.objects[CHAIN].fixed = IS_FREE; + game.objects[AXE].prop = AXE_HERE; + game.objects[AXE].fixed = IS_FREE; rspeak(CAVE_CLOSING); game.clock1 = -1; game.closng = true; @@ -863,12 +863,12 @@ static bool closecheck(void) * objects he might be carrying (lest he have some which * could cause trouble, such as the keys). We describe the * flash of light and trundle back. */ - game.prop[BOTTLE] = put(BOTTLE, LOC_NE, EMPTY_BOTTLE); - game.prop[PLANT] = put(PLANT, LOC_NE, PLANT_THIRSTY); - game.prop[OYSTER] = put(OYSTER, LOC_NE, STATE_FOUND); - game.prop[LAMP] = put(LAMP, LOC_NE, LAMP_DARK); - game.prop[ROD] = put(ROD, LOC_NE, STATE_FOUND); - game.prop[DWARF] = put(DWARF, LOC_NE, 0); + game.objects[BOTTLE].prop = put(BOTTLE, LOC_NE, EMPTY_BOTTLE); + game.objects[PLANT].prop = put(PLANT, LOC_NE, PLANT_THIRSTY); + game.objects[OYSTER].prop = put(OYSTER, LOC_NE, STATE_FOUND); + game.objects[LAMP].prop = put(LAMP, LOC_NE, LAMP_DARK); + game.objects[ROD].prop = put(ROD, LOC_NE, STATE_FOUND); + game.objects[DWARF].prop = put(DWARF, LOC_NE, 0); game.loc = LOC_NE; game.oldloc = LOC_NE; game.newloc = LOC_NE; @@ -876,15 +876,15 @@ static bool closecheck(void) * Reuse sign. */ put(GRATE, LOC_SW, 0); put(SIGN, LOC_SW, 0); - game.prop[SIGN] = ENDGAME_SIGN; - game.prop[SNAKE] = put(SNAKE, LOC_SW, SNAKE_CHASED); - game.prop[BIRD] = put(BIRD, LOC_SW, BIRD_CAGED); - game.prop[CAGE] = put(CAGE, LOC_SW, STATE_FOUND); - game.prop[ROD2] = put(ROD2, LOC_SW, STATE_FOUND); - game.prop[PILLOW] = put(PILLOW, LOC_SW, STATE_FOUND); + game.objects[SIGN].prop = ENDGAME_SIGN; + game.objects[SNAKE].prop = put(SNAKE, LOC_SW, SNAKE_CHASED); + game.objects[BIRD].prop = put(BIRD, LOC_SW, BIRD_CAGED); + game.objects[CAGE].prop = put(CAGE, LOC_SW, STATE_FOUND); + game.objects[ROD2].prop = put(ROD2, LOC_SW, STATE_FOUND); + game.objects[PILLOW].prop = put(PILLOW, LOC_SW, STATE_FOUND); - game.prop[MIRROR] = put(MIRROR, LOC_NE, STATE_FOUND); - game.fixed[MIRROR] = LOC_SW; + game.objects[MIRROR].prop = put(MIRROR, LOC_NE, STATE_FOUND); + game.objects[MIRROR].fixed = LOC_SW; for (int i = 1; i <= NOBJECTS; i++) { if (TOTING(i)) @@ -917,14 +917,14 @@ static void listobjects(void) obj = obj - NOBJECTS; if (obj == STEPS && TOTING(NUGGET)) continue; - if (game.prop[obj] < 0) { + if (game.objects[obj].prop < 0) { if (game.closed) continue; - game.prop[obj] = STATE_FOUND; + game.objects[obj].prop = STATE_FOUND; if (obj == RUG) - game.prop[RUG] = RUG_DRAGON; + game.objects[RUG].prop = RUG_DRAGON; if (obj == CHAIN) - game.prop[CHAIN] = CHAINING_BEAR; + game.objects[CHAIN].prop = CHAINING_BEAR; if (obj == EGGS) game.seenbigwords = true; --game.tally; @@ -943,9 +943,9 @@ static void listobjects(void) * gross blunder isn't likely to find everything else anyway * (so goes the rationalisation). */ } - int kk = game.prop[obj]; + int kk = game.objects[obj].prop; if (obj == STEPS) - kk = (game.loc == game.fixed[STEPS]) + kk = (game.loc == game.objects[STEPS].fixed) ? STEPS_UP : STEPS_DOWN; pspeak(obj, look, true, kk); @@ -1098,11 +1098,11 @@ static bool do_command(void) * game.prop < 0 and stash them. This way objects won't be * described until they've been picked up and put down * separate from their respective piles. */ - if (game.prop[OYSTER] < 0 && TOTING(OYSTER)) + if (game.objects[OYSTER].prop < 0 && TOTING(OYSTER)) pspeak(OYSTER, look, true, 1); for (size_t i = 1; i <= NOBJECTS; i++) { - if (TOTING(i) && game.prop[i] < 0) - game.prop[i] = STASHED(i); + if (TOTING(i) && game.objects[i].prop < 0) + game.objects[i].prop = STASHED(i); } } diff --git a/misc.c b/misc.c index 450f727..b8bc461 100644 --- a/misc.c +++ b/misc.c @@ -571,8 +571,8 @@ void juggle(obj_t object) { loc_t i, j; - i = game.place[object]; - j = game.fixed[object]; + i = game.objects[object].place; + j = game.objects[object].fixed; move(object, i); move(object + NOBJECTS, j); } @@ -586,9 +586,9 @@ void move(obj_t object, loc_t where) loc_t from; if (object > NOBJECTS) - from = game.fixed[object - NOBJECTS]; + from = game.objects[object - NOBJECTS].fixed; else - from = game.place[object]; + from = game.objects[object].place; /* (ESR) Used to check for !SPECIAL(from). I *think* that was wrong... */ if (from != LOC_NOWHERE && from != CARRIED) carry(object, from); @@ -611,9 +611,9 @@ void carry(obj_t object, loc_t where) int temp; if (object <= NOBJECTS) { - if (game.place[object] == CARRIED) + if (game.objects[object].place == CARRIED) return; - game.place[object] = CARRIED; + game.objects[object].place = CARRIED; /* * Without this conditional your inventory is overcounted @@ -641,9 +641,9 @@ void drop(obj_t object, loc_t where) * game.holdng if the object was being toted. No state change on the object. */ { if (object > NOBJECTS) - game.fixed[object - NOBJECTS] = where; + game.objects[object - NOBJECTS].fixed = where; else { - if (game.place[object] == CARRIED) + if (game.objects[object].place == CARRIED) if (object != BIRD) /* The bird has to be weightless. This ugly hack (and the * corresponding code in the carry function) brought to you @@ -652,7 +652,7 @@ void drop(obj_t object, loc_t where) * happen. */ --game.holdng; - game.place[object] = where; + game.objects[object].place = where; } if (where == LOC_NOWHERE || where == CARRIED) return; @@ -738,7 +738,7 @@ void bug(enum bugtype num, const char *error_string) void state_change(obj_t obj, int state) /* Object must have a change-message list for this to be useful; only some do */ { - game.prop[obj] = state; + game.objects[obj].prop = state; pspeak(obj, change, true, state); } diff --git a/saveresume.c b/saveresume.c index 53278ae..4cac034 100644 --- a/saveresume.c +++ b/saveresume.c @@ -197,8 +197,8 @@ bool is_valid(struct game_t valgame) } for (int i = 0; i <= NOBJECTS; i++) { - if (valgame.place[i] < -1 || valgame.place[i] > NLOCATIONS || - valgame.fixed[i] < -1 || valgame.fixed[i] > NLOCATIONS) { + if (valgame.objects[i].place < -1 || valgame.objects[i].place > NLOCATIONS || + valgame.objects[i].fixed < -1 || valgame.objects[i].fixed > NLOCATIONS) { return false; // LCOV_EXCL_LINE } } @@ -218,7 +218,7 @@ bool is_valid(struct game_t valgame) int temp_tally = 0; for (int treasure = 1; treasure <= NOBJECTS; treasure++) { if (objects[treasure].is_treasure) { - if (valgame.prop[treasure] == STATE_NOTFOUND) { + if (valgame.objects[treasure].prop == STATE_NOTFOUND) { ++temp_tally; } } @@ -230,7 +230,7 @@ bool is_valid(struct game_t valgame) /* Check that properties of objects aren't beyond expected */ for (obj_t obj = 0; obj <= NOBJECTS; obj++) { /* Magic number -2 allows a STASHED version of state 1 */ - if (valgame.prop[obj] < -2 || valgame.prop[obj] > 1) { + if (valgame.objects[obj].prop < -2 || valgame.objects[obj].prop > 1) { switch (obj) { case RUG: case DRAGON: @@ -243,11 +243,11 @@ bool is_valid(struct game_t valgame) case EGGS: case VASE: case CHAIN: - if (valgame.prop[obj] == 2) // There are multiple different states, but it's convenient to clump them together + if (valgame.objects[obj].prop == 2) // There are multiple different states, but it's convenient to clump them together continue; // LCOV_EXCL_LINE /* FALLTHRU */ case BEAR: - if (valgame.prop[BEAR] == CONTENTED_BEAR || valgame.prop[BEAR] == BEAR_DEAD) + if (valgame.objects[BEAR].prop == CONTENTED_BEAR || valgame.objects[BEAR].prop == BEAR_DEAD) continue; /* FALLTHRU */ default: diff --git a/score.c b/score.c index 8e37374..d3eeb0a 100644 --- a/score.c +++ b/score.c @@ -48,9 +48,9 @@ int score(enum termination mode) k = 14; if (i > CHEST) k = 16; - if (game.prop[i] > STATE_NOTFOUND) + if (game.objects[i].prop > STATE_NOTFOUND) score += 2; - if (game.place[i] == LOC_BUILDING && game.prop[i] == STATE_FOUND) + if (game.objects[i].place == LOC_BUILDING && game.objects[i].prop == STATE_FOUND) score += k - 2; mxscor += k; } @@ -86,7 +86,7 @@ int score(enum termination mode) mxscor += 45; /* Did he come to Witt's End as he should? */ - if (game.place[MAGAZINE] == LOC_WITTSEND) + if (game.objects[MAGAZINE].place == LOC_WITTSEND) score += 1; mxscor += 1;