Abstract out some state arithmetic.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 4 Jul 2017 17:40:05 +0000 (13:40 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 4 Jul 2017 17:41:12 +0000 (13:41 -0400)
actions.c
advent.h
main.c

index d817c6d23c6d328e87bb5702e546560b19fdfb21..ec17c07b2145254be33b052c1700b9912df1f8a6 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -361,7 +361,7 @@ static int vcarry(token_t verb, token_t obj)
 
     }
 
-    if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && -1 - game.prop[BIRD] != BIRD_CAGED) {
+    if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) {
         if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) {
             DESTROY(BIRD);
             rspeak(BIRD_CRAP);
@@ -380,8 +380,7 @@ static int vcarry(token_t verb, token_t obj)
     /* FIXME: Arithmetic on state numbers */
     if ((obj == BIRD ||
          obj == CAGE) &&
-        (game.prop[BIRD] == BIRD_CAGED ||
-         -1 - game.prop[BIRD] == 1))
+        (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED))
         carry(BIRD + CAGE - obj, game.loc);
     carry(obj, game.loc);
     if (obj == BOTTLE && LIQUID() != NO_OBJECT)
index cca1dbab1d328e310643fc1f389639d03444f0c4..3c3372576b8c9cfdec568b5a296e286e8357a661 100644 (file)
--- a/advent.h
+++ b/advent.h
 #define STATE_NOTFOUND  -1       // 'Not found" state of treasures */
 #define STATE_GROUND   0         // After discovered, before messed with
 
+/* 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. */
+#define STASHED(obj)   (-1 - game.prop[obj])
+
 /*
  *  MOD(N,M)    = Arithmetic modulus
  *  AT(OBJ)     = true if on either side of two-placed object
diff --git a/main.c b/main.c
index 2790696de2ca7f7e5af4ce43d0c1d32f3a5c6910..71a7dac55da8c4d7cd3fbe480f1a9fd7f98075b3 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1028,7 +1028,7 @@ L2600:
                 pspeak(OYSTER, look, 1, true);
             for (size_t i = 1; i <= NOBJECTS; i++) {
                 if (TOTING(i) && game.prop[i] < 0)
-                    game.prop[i] = -1 - game.prop[i];
+                    game.prop[i] = STASHED(i);
             }
         }
         game.wzdark = DARK(game.loc);