Expand a macro to simplify code.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 23 Sep 2024 07:53:28 +0000 (03:53 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 23 Sep 2024 08:26:59 +0000 (04:26 -0400)
actions.c
advent.h
main.c

index 6f93eb0fee78eb35ce437b89ad141a86b447f3a8..e5f2e70524ac0d89f030f1bc0831f55525a8acab 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -970,7 +970,7 @@ static phase_codes_t listen(void) {
        }
        for (obj_t i = 1; i <= NOBJECTS; i++) {
                if (!HERE(i) || objects[i].sounds[0] == NULL ||
-                   OBJECT_IS_STASHED_OR_UNSEEN(i)) {
+                   OBJECT_IS_STASHED(i) || OBJECT_IS_NOTFOUND(i)) {
                        continue;
                }
                int mi = game.objects[i].prop;
index fa3c185a00df21d35d61a4b53e077436943854f2..204fce7f6f2ffd4e72d57babe6a43839c8fac399 100644 (file)
--- a/advent.h
+++ b/advent.h
  * and readable objects, notably the clam/oyster - but the code around
  * those tests is difficult to read.
  */
-#define PROP_STASHIFY(n) (-1 - (n))
-#define PROP_IS_INVALID(val) (val < -MAX_STATE - 1 || val > MAX_STATE)
-#define OBJECT_IS_STASHED(obj) (game.objects[obj].prop < STATE_NOTFOUND)
 #define OBJECT_IS_NOTFOUND(obj) (game.objects[obj].prop == STATE_NOTFOUND)
 #define OBJECT_IS_FOUND(obj) (game.objects[obj].prop == STATE_FOUND)
-#define OBJECT_IS_STASHED_OR_UNSEEN(obj) (game.objects[obj].prop < 0)
 #define OBJECT_SET_FOUND(obj) (game.objects[obj].prop = STATE_FOUND)
 #define OBJECT_SET_NOT_FOUND(obj) (game.objects[obj].prop = STATE_NOTFOUND)
 #define OBJECT_IS_NOTFOUND2(g, o) (g.objects[o].prop == STATE_NOTFOUND)
-#define OBJECT_STATE_EQUALS(obj, pval) ((game.objects[obj].prop == pval) || (game.objects[obj].prop == PROP_STASHIFY(pval))) 
+#define PROP_IS_INVALID(val) (val < -MAX_STATE - 1 || val > MAX_STATE)
+#define PROP_STASHIFY(n) (-1 - (n))
 #define OBJECT_STASHIFY(obj, pval) game.objects[obj].prop = PROP_STASHIFY(pval)
+#define OBJECT_IS_STASHED(obj) (game.objects[obj].prop < STATE_NOTFOUND)
+#define OBJECT_STATE_EQUALS(obj, pval) ((game.objects[obj].prop == pval) || (game.objects[obj].prop == PROP_STASHIFY(pval))) 
 
 #define PROMPT "> "
 
diff --git a/main.c b/main.c
index 14c90654601b58069245ae2507f45835ffbd5b86..c8232804686f1bfd1d11d4598ec19f4af3352d9b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -188,7 +188,7 @@ static void checkhints(void) {
                                        return;
                                case 9: /* jade */
                                        if (game.tally == 1 &&
-                                           OBJECT_IS_STASHED_OR_UNSEEN(JADE)) {
+                                           (OBJECT_IS_STASHED(JADE) || OBJECT_IS_NOTFOUND(JADE))) {
                                                break;
                                        }
                                        game.hints[hint].lc = 0;
@@ -1061,7 +1061,7 @@ static void listobjects(void) {
                         * running this code only on objects with the treasure
                         * property set. Nope.  There is mystery here.
                         */
-                       if (OBJECT_IS_STASHED_OR_UNSEEN(obj)) {
+                       if (OBJECT_IS_STASHED(i) || OBJECT_IS_NOTFOUND(obj)) {
                                if (game.closed) {
                                        continue;
                                }