From: Eric S. Raymond Date: Sat, 24 Jun 2017 13:55:32 +0000 (-0400) Subject: Rationalize names of structure array sizes. X-Git-Tag: 1.1~136 X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=commitdiff_plain;h=985137d9c7ed18ee0777622874efe944218cae6a Rationalize names of structure array sizes. Everything that camn be #define become one, in all caps to signify that it's a constant. --- diff --git a/advent.h b/advent.h index c1fc79b..63b16ff 100644 --- a/advent.h +++ b/advent.h @@ -72,8 +72,8 @@ struct game_t { long fixed[NOBJECTS + 1]; long link[NOBJECTS * 2 + 1]; long place[NOBJECTS + 1]; - long hinted[HINT_COUNT]; - long hintlc[HINT_COUNT]; + long hinted[NHINTS]; + long hintlc[NHINTS]; long prop[NOBJECTS + 1]; }; diff --git a/init.c b/init.c index 46e825b..c197143 100644 --- a/init.c +++ b/init.c @@ -223,7 +223,7 @@ void initialise(void) /* Clear the hint stuff. game.hintlc[i] is how long he's been at LOC * with cond bit i. game.hinted[i] is true iff hint i has been * used. */ - for (int i = 0; i < HINT_COUNT; i++) { + for (int i = 0; i < NHINTS; i++) { game.hinted[i] = false; game.hintlc[i] = 0; } @@ -347,7 +347,7 @@ void initialise(void) * game.iwest How many times he's said "west" instead of "w" * game.knfloc 0 if no knife here, loc if knife here, -1 after caveat * game.limit Lifetime of lamp (not set here) - * maximum_deaths Number of reincarnation messages available (up to 5) + * NDEATHS Number of reincarnation messages available (up to 5) * game.numdie Number of times killed so far * game.trnluz # points lost so far due to number of turns used * game.turns Tallies how many commands he's given (ignores yes/no) diff --git a/main.c b/main.c index f59f600..6fa2ddc 100644 --- a/main.c +++ b/main.c @@ -189,7 +189,7 @@ static bool fallback_handler(char *buf) static void checkhints(void) { if (conditions[game.loc] >= game.conds) { - for (int hint = 0; hint < HINT_COUNT; hint++) { + for (int hint = 0; hint < NHINTS; hint++) { if (game.hinted[hint]) continue; if (!CNDBIT(game.loc, hint + 1 + COND_HBASE)) @@ -468,7 +468,7 @@ static bool dwarfmove(void) /* "You're dead, Jim." * * If the current loc is zero, it means the clown got himself killed. - * We'll allow this maxdie times. maximum_deaths is automatically set based + * We'll allow this maxdie times. NDEATHS is automatically set based * on the number of snide messages available. Each death results in * a message (81, 83, etc.) which offers reincarnation; if accepted, * this results in message 82, 84, etc. The last time, if he wants @@ -496,7 +496,7 @@ static void croak(void) * death and exit. */ rspeak(DEATH_CLOSING); terminate(endgame); - } else if (game.numdie == maximum_deaths || !YES(query, yes_response, arbitrary_messages[OK_MAN])) + } else if (game.numdie == NDEATHS || !YES(query, yes_response, arbitrary_messages[OK_MAN])) terminate(endgame); else { game.place[WATER] = game.place[OIL] = LOC_NOWHERE; @@ -1022,7 +1022,7 @@ L2607: /* If a turn threshold has been met, apply penalties and tell * the player about it. */ - for (int i = 0; i < turn_threshold_count; ++i) + for (int i = 0; i < NTHRESHOLDS; ++i) { if (game.turns == turn_thresholds[i].threshold + 1) { diff --git a/newdungeon.py b/newdungeon.py index 89d8db6..7f70741 100755 --- a/newdungeon.py +++ b/newdungeon.py @@ -69,10 +69,11 @@ extern turn_threshold_t turn_thresholds[]; extern obituary_t obituaries[]; extern hint_t hints[]; extern long conditions[]; -extern const size_t CLSSES; -extern const int maximum_deaths; -extern const int turn_threshold_count; -#define HINT_COUNT {} + +#define NHINTS {} +#define NCLASSES {} +#define NDEATHS {} +#define NTHRESHOLDS {} enum arbitrary_messages_refs {{ {} @@ -129,10 +130,6 @@ long conditions[] = {{ {} }}; -const size_t CLSSES = {}; -const int maximum_deaths = {}; -const int turn_threshold_count = {}; - /* end */ """ @@ -338,13 +335,13 @@ if __name__ == "__main__": get_obituaries(db["obituaries"]), get_hints(db["hints"], db["arbitrary_messages"]), get_condbits(db["locations"]), - len(db["classes"]), - len(db["obituaries"]), - len(db["turn_thresholds"]), ) h = h_template.format( len(db["hints"]), + len(db["classes"]), + len(db["obituaries"]), + len(db["turn_thresholds"]), get_refs(db["arbitrary_messages"]), get_refs(db["locations"]), get_refs(db["object_descriptions"]), diff --git a/score.c b/score.c index cd4b9e6..95efe2c 100644 --- a/score.c +++ b/score.c @@ -50,14 +50,14 @@ long score(enum termination mode) } } - /* Now look at how he finished and how far he got. maximum_deaths and + /* Now look at how he finished and how far he got. NDEATHS and * game.numdie tell us how well he survived. game.dflag will tell us * if he ever got suitably deep into the cave. game.closng still * indicates whether he reached the endgame. And if he got as far as * "cave closed" (indicated by "game.closed"), then bonus is zero for * mundane exits or 133, 134, 135 if he blew it (so to speak). */ - score += (maximum_deaths - game.numdie) * 10; - mxscor += maximum_deaths * 10; + score += (NDEATHS - game.numdie) * 10; + mxscor += NDEATHS * 10; if (mode == endgame) score += 4; mxscor += 4; @@ -87,7 +87,7 @@ long score(enum termination mode) mxscor += 2; /* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */ - for (long i = 0; i < HINT_COUNT; i++) { + for (long i = 0; i < NHINTS; i++) { if (game.hinted[i]) score = score - hints[i].penalty; } @@ -115,7 +115,7 @@ void terminate(enum termination mode) if (points + game.saved + 1 >= mxscor && game.saved != 0) rspeak(WITHOUT_SUSPENDS); rspeak(TOTAL_SCORE, points, mxscor, game.turns, game.turns); - for (long i = 1; i <= (long)CLSSES; i++) { + for (long i = 1; i <= (long)NCLASSES; i++) { if (classes[i].threshold >= points) { speak(classes[i].message); i = classes[i].threshold + 1 - points;