Rationalize names of structure array sizes.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 24 Jun 2017 13:55:32 +0000 (09:55 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 24 Jun 2017 13:55:32 +0000 (09:55 -0400)
Everything that camn be #define become one, in all caps to signify that
it's a constant.

advent.h
init.c
main.c
newdungeon.py
score.c

index c1fc79bad8aecd0edb1a0741a835b13074e0021b..63b16ffa0155707543dd67dcd2a49c880df442d9 100644 (file)
--- 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 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];
 };
 
     long prop[NOBJECTS + 1];
 };
 
diff --git a/init.c b/init.c
index 46e825b14e8331412a2a8171cfd6e39746d502bc..c197143eef49085194b3a8f4dd6cacb553bc27fb 100644 (file)
--- 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. */
     /*  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;
     }
         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)
      * 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)
      * 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 f59f600347381796b094d80a719398dd2f5a3270..6fa2ddcbc7c954f53fd111b5ce4bfbd386208586 100644 (file)
--- 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) {
 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))
             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.
 /*  "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
  *  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);
          *  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;
         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. */
 
        /* 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)
              {
          {
            if (game.turns == turn_thresholds[i].threshold + 1)
              {
index 89d8db6f794aca63f9e722c1fbc87f04dfdef9c4..7f70741d331f62aebe962f47a8e09434db3dbf6b 100755 (executable)
@@ -69,10 +69,11 @@ extern turn_threshold_t turn_thresholds[];
 extern obituary_t obituaries[];
 extern hint_t hints[];
 extern long conditions[];
 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 {{
 {}
 
 enum arbitrary_messages_refs {{
 {}
@@ -129,10 +130,6 @@ long conditions[] = {{
 {}
 }};
 
 {}
 }};
 
-const size_t CLSSES = {};
-const int maximum_deaths = {};
-const int turn_threshold_count = {};
-
 /* end */
 """
 
 /* end */
 """
 
@@ -338,13 +335,13 @@ if __name__ == "__main__":
         get_obituaries(db["obituaries"]),
         get_hints(db["hints"], db["arbitrary_messages"]),
         get_condbits(db["locations"]),
         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"]),
     )
 
     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"]),
         get_refs(db["arbitrary_messages"]),
         get_refs(db["locations"]),
         get_refs(db["object_descriptions"]),
diff --git a/score.c b/score.c
index cd4b9e6d2ff779ce65ca37decc1667165adc9723..95efe2c512236166cda0ac3122c07ea2ef122595 100644 (file)
--- 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). */
      *  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;
     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. */
     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;
     }
         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);
     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;
         if (classes[i].threshold >= points) {
             speak(classes[i].message);
             i = classes[i].threshold + 1 - points;