From: Eric S. Raymond Date: Mon, 23 Sep 2024 07:53:28 +0000 (-0400) Subject: Expand a macro to simplify code. X-Git-Tag: 1.20~5 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=40742e112ba73e1fd98c9b898f6ce5812c7c74b7;p=open-adventure.git Expand a macro to simplify code. --- diff --git a/actions.c b/actions.c index 6f93eb0..e5f2e70 100644 --- 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; diff --git a/advent.h b/advent.h index fa3c185..204fce7 100644 --- a/advent.h +++ b/advent.h @@ -67,17 +67,16 @@ * 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 14c9065..c823280 100644 --- 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; }