Encapsulate object-state state tests and setttings in macros.
[open-adventure.git] / main.c
diff --git a/main.c b/main.c
index 5e7d6abf932a1713c2c5f4e719cacae5a77d4325..4b6165e4e5acf81fc1f27bb41a0aad0b7f897cbf 100644 (file)
--- a/main.c
+++ b/main.c
@@ -104,14 +104,14 @@ static void checkhints(void)
 {
     if (conditions[game.loc] >= game.conds) {
         for (int hint = 0; hint < NHINTS; hint++) {
-            if (game.hinted[hint])
+            if (game.hints[hint].used)
                 continue;
             if (!CNDBIT(game.loc, hint + 1 + COND_HBASE))
-                game.hintlc[hint] = -1;
-            ++game.hintlc[hint];
+                game.hints[hint].lc = -1;
+            ++game.hints[hint].lc;
             /*  Come here if he's been int enough at required loc(s) for some
              *  unused hint. */
-            if (game.hintlc[hint] >= hints[hint].turns) {
+            if (game.hints[hint].lc >= hints[hint].turns) {
                 int i;
 
                 switch (hint) {
@@ -119,7 +119,7 @@ static void checkhints(void)
                     /* cave */
                     if (game.objects[GRATE].prop == GRATE_CLOSED && !HERE(KEYS))
                         break;
-                    game.hintlc[hint] = 0;
+                    game.hints[hint].lc = 0;
                     return;
                 case 1:        /* bird */
                     if (game.objects[BIRD].place == game.loc && TOTING(ROD) && game.oldobj == BIRD)
@@ -128,7 +128,7 @@ static void checkhints(void)
                 case 2:        /* snake */
                     if (HERE(SNAKE) && !HERE(BIRD))
                         break;
-                    game.hintlc[hint] = 0;
+                    game.hints[hint].lc = 0;
                     return;
                 case 3:        /* maze */
                     if (game.locs[game.loc].atloc == NO_OBJECT &&
@@ -136,19 +136,19 @@ static void checkhints(void)
                         game.locs[game.oldlc2].atloc == NO_OBJECT &&
                         game.holdng > 1)
                         break;
-                    game.hintlc[hint] = 0;
+                    game.hints[hint].lc = 0;
                     return;
                 case 4:        /* dark */
-                    if (game.objects[EMERALD].prop != STATE_NOTFOUND && game.objects[PYRAMID].prop == STATE_NOTFOUND)
+                    if (!PROP_IS_NOTFOUND(EMERALD) && PROP_IS_NOTFOUND(PYRAMID))
                         break;
-                    game.hintlc[hint] = 0;
+                    game.hints[hint].lc = 0;
                     return;
                 case 5:        /* witt */
                     break;
                 case 6:        /* urn */
                     if (game.dflag == 0)
                         break;
-                    game.hintlc[hint] = 0;
+                    game.hints[hint].lc = 0;
                     return;
                 case 7:        /* woods */
                     if (game.locs[game.loc].atloc == NO_OBJECT &&
@@ -159,16 +159,16 @@ static void checkhints(void)
                 case 8:        /* ogre */
                     i = atdwrf(game.loc);
                     if (i < 0) {
-                        game.hintlc[hint] = 0;
+                        game.hints[hint].lc = 0;
                         return;
                     }
                     if (HERE(OGRE) && i == 0)
                         break;
                     return;
                 case 9:        /* jade */
-                    if (game.tally == 1 && game.objects[JADE].prop < 0)
+                    if (game.tally == 1 && PROP_IS_STASHED_OR_UNSEEN(JADE))
                         break;
-                    game.hintlc[hint] = 0;
+                    game.hints[hint].lc = 0;
                     return;
                 default: // LCOV_EXCL_LINE
                     // Should never happen
@@ -176,12 +176,12 @@ static void checkhints(void)
                 }
 
                 /* 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]))
                     return;
                 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]);
-                if (game.hinted[hint] && game.limit > WARNTIME)
+                game.hints[hint].used = yes_or_no(arbitrary_messages[WANT_HINT], hints[hint].hint, arbitrary_messages[OK_MAN]);
+                if (game.hints[hint].used && game.limit > WARNTIME)
                     game.limit += WARNTIME * hints[hint].penalty;
             }
         }
@@ -196,10 +196,10 @@ static bool spotted_by_pirate(int i)
     /*  The pirate's spotted him.  Pirate leaves him alone once we've
      *  found chest.  K counts if a treasure is here.  If not, and
      *  tally=1 for an unseen chest, let the pirate be spotted.  Note
-     *  that game.place[CHEST] = LOC_NOWHERE might mean that he's thrown
+     *  that game.objexts,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.objects[CHEST].prop != STATE_NOTFOUND)
+     *  PROP_IS_FOUND(CHEST) == true. */
+    if (game.loc == game.chloc || !PROP_IS_NOTFOUND(CHEST))
         return true;
     int snarfed = 0;
     bool movechest = false, robplayer = false;
@@ -863,27 +863,27 @@ 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.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);
+        put(BOTTLE, LOC_NE, EMPTY_BOTTLE);
+        put(PLANT, LOC_NE, PLANT_THIRSTY);
+        put(OYSTER, LOC_NE, STATE_FOUND);
+        put(LAMP, LOC_NE, LAMP_DARK);
+        put(ROD, LOC_NE, STATE_FOUND);
+        put(DWARF, LOC_NE, 0);
         game.loc = LOC_NE;
         game.oldloc = LOC_NE;
         game.newloc = LOC_NE;
         /*  Leave the grate with normal (non-negative) property.
          *  Reuse sign. */
-        put(GRATE, LOC_SW, 0);
-        put(SIGN, LOC_SW, 0);
+        move(GRATE, LOC_SW);
+        move(SIGN, LOC_SW);
         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);
+        put(SNAKE, LOC_SW, SNAKE_CHASED);
+        put(BIRD, LOC_SW, BIRD_CAGED);
+        put(CAGE, LOC_SW, STATE_FOUND);
+        put(ROD2, LOC_SW, STATE_FOUND);
+        put(PILLOW, LOC_SW, STATE_FOUND);
 
-        game.objects[MIRROR].prop = put(MIRROR, LOC_NE, STATE_FOUND);
+        put(MIRROR, LOC_NE, STATE_FOUND);
         game.objects[MIRROR].fixed = LOC_SW;
 
         for (int i = 1; i <= NOBJECTS; i++) {
@@ -917,10 +917,10 @@ static void listobjects(void)
                 obj = obj - NOBJECTS;
             if (obj == STEPS && TOTING(NUGGET))
                 continue;
-            if (game.objects[obj].prop < 0) {
+            if (PROP_IS_STASHED_OR_UNSEEN(obj)) {
                 if (game.closed)
                     continue;
-                game.objects[obj].prop = STATE_FOUND;
+                PROP_SET_FOUND(obj);
                 if (obj == RUG)
                     game.objects[RUG].prop = RUG_DRAGON;
                 if (obj == CHAIN)
@@ -1102,7 +1102,7 @@ static bool do_command(void)
                     pspeak(OYSTER, look, true, 1);
                 for (size_t i = 1; i <= NOBJECTS; i++) {
                     if (TOTING(i) && game.objects[i].prop < 0)
-                        game.objects[i].prop = STASHED(i);
+                        game.objects[i].prop = PROP_STASHED(i);
                 }
             }