Abolish HNTMAX and HNTSIZ in favor of HINT_COUNT.
authorJason S. Ninneman <jsn@mbar.us>
Wed, 21 Jun 2017 17:01:16 +0000 (10:01 -0700)
committerJason S. Ninneman <jsn@mbar.us>
Wed, 21 Jun 2017 17:25:12 +0000 (10:25 -0700)
This change necessitated include guards on newdb.h.

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

index 4a6679ef2a1a4f804d0c6dd2b709e35bfda51de3..a4714614c6df892448d863ec5406b65d26e383ed 100644 (file)
--- a/advent.h
+++ b/advent.h
@@ -3,6 +3,7 @@
 #include <stdbool.h>
 
 #include "common.h"
 #include <stdbool.h>
 
 #include "common.h"
+#include "newdb.h"
 
 #define LINESIZE       100
 #define NDWARVES       6               /* number of dwarves */
 
 #define LINESIZE       100
 #define NDWARVES       6               /* number of dwarves */
@@ -70,8 +71,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[HNTSIZ + 1];
-    long hintlc[HNTSIZ + 1];
+    long hinted[HINT_COUNT];
+    long hintlc[HINT_COUNT];
     long prop[NOBJECTS + 1];
 };
 
     long prop[NOBJECTS + 1];
 };
 
index 942a2716e7a796368689980c349a32cb32ffadd6..801bf365a5af24f97e8697595e3d83c5f1df6ca1 100644 (file)
--- a/common.h
+++ b/common.h
@@ -4,7 +4,6 @@
 
 #define LOCSIZ         185
 #define NOBJECTS       100
 
 #define LOCSIZ         185
 #define NOBJECTS       100
-#define HNTSIZ          20
 
 extern const char advent_to_ascii[128];
 extern const char ascii_to_advent[128];
 
 extern const char advent_to_ascii[128];
 extern const char ascii_to_advent[128];
index e92dcc98039e55a5ecf8a3f5aadf8e9df8877670..997b49ecff7b4b472b7aaa721b715f4c9b8626e0 100644 (file)
--- a/dungeon.c
+++ b/dungeon.c
@@ -14,6 +14,7 @@
 #define TRVSIZ 885
 #define TOKLEN 5
 #define HINTLEN 5
 #define TRVSIZ 885
 #define TOKLEN 5
 #define HINTLEN 5
+#define HNTSIZ 20
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -448,11 +449,6 @@ static int read_database(FILE* database)
  *  whether the abbreviated description is printed.  Counts modulo 5
  *  unless "LOOK" is used. */
 
  *  whether the abbreviated description is printed.  Counts modulo 5
  *  unless "LOOK" is used. */
 
-static void write_0d(FILE* header_file, long single, const char* varname)
-{
-    fprintf(header_file, "LOCATION long %s INITIALIZE(= %ld);\n", varname, single);
-}
-
 static void write_1d(FILE* header_file, long array[], long dim, const char* varname)
 {
     fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname);
 static void write_1d(FILE* header_file, long array[], long dim, const char* varname)
 {
     fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname);
@@ -490,7 +486,6 @@ static void write_file(FILE* header_file)
     fprintf(header_file, "\n");
 
     // content variables
     fprintf(header_file, "\n");
 
     // content variables
-    write_0d(header_file, HNTMAX, "HNTMAX");
     write_1d(header_file, OBJSND, NOBJECTS + 1, "OBJSND");
     write_1d(header_file, OBJTXT, NOBJECTS + 1, "OBJTXT");
     write_1d(header_file, COND, LOCSIZ + 1, "COND");
     write_1d(header_file, OBJSND, NOBJECTS + 1, "OBJSND");
     write_1d(header_file, OBJTXT, NOBJECTS + 1, "OBJTXT");
     write_1d(header_file, COND, LOCSIZ + 1, "COND");
diff --git a/init.c b/init.c
index d7789ad7ce85aa17a9f23bb4b0d9165107a26e7e..220f9cbe197aa6084376683dda0da8934995c9bb 100644 (file)
--- a/init.c
+++ b/init.c
@@ -5,7 +5,6 @@
 
 #include "advent.h"
 #include "database.h"
 
 #include "advent.h"
 #include "database.h"
-#include "newdb.h"
 
 /*
  * Initialisation
 
 /*
  * Initialisation
@@ -226,7 +225,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 = 1; i <= HNTMAX; i++) {
+    for (int i = 1; i <= HINT_COUNT; i++) {
         game.hinted[i] = false;
         game.hintlc[i] = 0;
     }
         game.hinted[i] = false;
         game.hintlc[i] = 0;
     }
diff --git a/main.c b/main.c
index 8ed28043f4994ca378658b33b21a81d37dab0d4c..f9d0284e8b775eea35b2bf08965676f60e71ca8d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -189,7 +189,7 @@ static bool fallback_handler(char *buf)
 static void checkhints(void)
 {
     if (COND[game.loc] >= game.conds) {
 static void checkhints(void)
 {
     if (COND[game.loc] >= game.conds) {
-        for (int hint = 1; hint <= HNTMAX; hint++) {
+        for (int hint = 1; hint <= HINT_COUNT; hint++) {
             if (game.hinted[hint])
                 continue;
             if (!CNDBIT(game.loc, hint + HBASE))
             if (game.hinted[hint])
                 continue;
             if (!CNDBIT(game.loc, hint + HBASE))
index 52380e6705c55a5774c15055c5d079eca892f084..dffb8d142b0d58d136c6234ca7ddfe68e780ad12 100755 (executable)
@@ -9,6 +9,8 @@ h_name = "newdb.h"
 c_name = "newdb.c"
 
 h_template = """/* Generated from adventure.yaml - do not hand-hack! */
 c_name = "newdb.c"
 
 h_template = """/* Generated from adventure.yaml - do not hand-hack! */
+#ifndef NEWDB_H
+#define NEWDB_H
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
@@ -61,6 +63,7 @@ extern hint_t hints[];
 extern const size_t CLSSES;
 extern const int maximum_deaths;
 extern const int turn_threshold_count;
 extern const size_t CLSSES;
 extern const int maximum_deaths;
 extern const int turn_threshold_count;
+#define HINT_COUNT {}
 
 enum arbitrary_messages_refs {{
 {}
 
 enum arbitrary_messages_refs {{
 {}
@@ -74,7 +77,7 @@ enum object_descriptions_refs {{
 {}
 }};
 
 {}
 }};
 
-/* end */
+#endif /* end NEWDB_H */
 """
 
 c_template = """/* Generated from adventure.yaml - do not hand-hack! */
 """
 
 c_template = """/* Generated from adventure.yaml - do not hand-hack! */
@@ -253,6 +256,7 @@ if __name__ == "__main__":
         db = yaml.load(f)
 
     h = h_template.format(
         db = yaml.load(f)
 
     h = h_template.format(
+        len(db["hints"]),
         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 0916b9a82bf740010f011393f97375f22db10094..b2db8a6a54097913ad2068c701533b34b8f66008 100644 (file)
--- a/score.c
+++ b/score.c
@@ -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 = 1; i <= HNTMAX; i++) {
+    for (long i = 1; i <= HINT_COUNT; i++) {
         if (game.hinted[i])
             score = score - hints[i-1].penalty;
     }
         if (game.hinted[i])
             score = score - hints[i-1].penalty;
     }