From c8f6ff3701534e6c1ce59cf3e33aec5e824ed144 Mon Sep 17 00:00:00 2001 From: "Jason S. Ninneman" Date: Wed, 21 Jun 2017 10:01:16 -0700 Subject: [PATCH] Abolish HNTMAX and HNTSIZ in favor of HINT_COUNT. This change necessitated include guards on newdb.h. --- advent.h | 5 +++-- common.h | 1 - dungeon.c | 7 +------ init.c | 3 +-- main.c | 2 +- newdungeon.py | 6 +++++- score.c | 2 +- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/advent.h b/advent.h index 4a6679e..a471461 100644 --- a/advent.h +++ b/advent.h @@ -3,6 +3,7 @@ #include #include "common.h" +#include "newdb.h" #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 hinted[HNTSIZ + 1]; - long hintlc[HNTSIZ + 1]; + long hinted[HINT_COUNT]; + long hintlc[HINT_COUNT]; long prop[NOBJECTS + 1]; }; diff --git a/common.h b/common.h index 942a271..801bf36 100644 --- a/common.h +++ b/common.h @@ -4,7 +4,6 @@ #define LOCSIZ 185 #define NOBJECTS 100 -#define HNTSIZ 20 extern const char advent_to_ascii[128]; extern const char ascii_to_advent[128]; diff --git a/dungeon.c b/dungeon.c index e92dcc9..997b49e 100644 --- a/dungeon.c +++ b/dungeon.c @@ -14,6 +14,7 @@ #define TRVSIZ 885 #define TOKLEN 5 #define HINTLEN 5 +#define HNTSIZ 20 #include #include @@ -448,11 +449,6 @@ static int read_database(FILE* database) * 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); @@ -490,7 +486,6 @@ static void write_file(FILE* header_file) 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"); diff --git a/init.c b/init.c index d7789ad..220f9cb 100644 --- a/init.c +++ b/init.c @@ -5,7 +5,6 @@ #include "advent.h" #include "database.h" -#include "newdb.h" /* * 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. */ - for (int i = 1; i <= HNTMAX; i++) { + for (int i = 1; i <= HINT_COUNT; i++) { game.hinted[i] = false; game.hintlc[i] = 0; } diff --git a/main.c b/main.c index 8ed2804..f9d0284 100644 --- 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) { - 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)) diff --git a/newdungeon.py b/newdungeon.py index 52380e6..dffb8d1 100755 --- a/newdungeon.py +++ b/newdungeon.py @@ -9,6 +9,8 @@ h_name = "newdb.h" c_name = "newdb.c" h_template = """/* Generated from adventure.yaml - do not hand-hack! */ +#ifndef NEWDB_H +#define NEWDB_H #include @@ -61,6 +63,7 @@ extern hint_t hints[]; extern const size_t CLSSES; extern const int maximum_deaths; extern const int turn_threshold_count; +#define HINT_COUNT {} 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! */ @@ -253,6 +256,7 @@ if __name__ == "__main__": 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"]), diff --git a/score.c b/score.c index 0916b9a..b2db8a6 100644 --- 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. */ - 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; } -- 2.31.1