Abolish HNTMAX and HNTSIZ in favor of HINT_COUNT.
This change necessitated include guards on newdb.h.
This commit is contained in:
parent
deb61e3dcd
commit
c8f6ff3701
7 changed files with 12 additions and 14 deletions
5
advent.h
5
advent.h
|
@ -3,6 +3,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "newdb.h"
|
||||||
|
|
||||||
#define LINESIZE 100
|
#define LINESIZE 100
|
||||||
#define NDWARVES 6 /* number of dwarves */
|
#define NDWARVES 6 /* number of dwarves */
|
||||||
|
@ -70,8 +71,8 @@ struct game_t {
|
||||||
long fixed[NOBJECTS + 1];
|
long fixed[NOBJECTS + 1];
|
||||||
long link[NOBJECTS * 2 + 1];
|
long link[NOBJECTS * 2 + 1];
|
||||||
long place[NOBJECTS + 1];
|
long place[NOBJECTS + 1];
|
||||||
long hinted[HNTSIZ + 1];
|
long hinted[HINT_COUNT];
|
||||||
long hintlc[HNTSIZ + 1];
|
long hintlc[HINT_COUNT];
|
||||||
long prop[NOBJECTS + 1];
|
long prop[NOBJECTS + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
1
common.h
1
common.h
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
#define LOCSIZ 185
|
#define LOCSIZ 185
|
||||||
#define NOBJECTS 100
|
#define NOBJECTS 100
|
||||||
#define HNTSIZ 20
|
|
||||||
|
|
||||||
extern const char advent_to_ascii[128];
|
extern const char advent_to_ascii[128];
|
||||||
extern const char ascii_to_advent[128];
|
extern const char ascii_to_advent[128];
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#define TRVSIZ 885
|
#define TRVSIZ 885
|
||||||
#define TOKLEN 5
|
#define TOKLEN 5
|
||||||
#define HINTLEN 5
|
#define HINTLEN 5
|
||||||
|
#define HNTSIZ 20
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -448,11 +449,6 @@ static int read_database(FILE* database)
|
||||||
* whether the abbreviated description is printed. Counts modulo 5
|
* whether the abbreviated description is printed. Counts modulo 5
|
||||||
* unless "LOOK" is used. */
|
* 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)
|
static void write_1d(FILE* header_file, long array[], long dim, const char* varname)
|
||||||
{
|
{
|
||||||
fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", 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");
|
fprintf(header_file, "\n");
|
||||||
|
|
||||||
// content variables
|
// content variables
|
||||||
write_0d(header_file, HNTMAX, "HNTMAX");
|
|
||||||
write_1d(header_file, OBJSND, NOBJECTS + 1, "OBJSND");
|
write_1d(header_file, OBJSND, NOBJECTS + 1, "OBJSND");
|
||||||
write_1d(header_file, OBJTXT, NOBJECTS + 1, "OBJTXT");
|
write_1d(header_file, OBJTXT, NOBJECTS + 1, "OBJTXT");
|
||||||
write_1d(header_file, COND, LOCSIZ + 1, "COND");
|
write_1d(header_file, COND, LOCSIZ + 1, "COND");
|
||||||
|
|
3
init.c
3
init.c
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include "advent.h"
|
#include "advent.h"
|
||||||
#include "database.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
|
/* 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
|
* with cond bit i. game.hinted[i] is true iff hint i has been
|
||||||
* used. */
|
* used. */
|
||||||
for (int i = 1; i <= HNTMAX; i++) {
|
for (int i = 1; i <= HINT_COUNT; i++) {
|
||||||
game.hinted[i] = false;
|
game.hinted[i] = false;
|
||||||
game.hintlc[i] = 0;
|
game.hintlc[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
2
main.c
2
main.c
|
@ -189,7 +189,7 @@ static bool fallback_handler(char *buf)
|
||||||
static void checkhints(void)
|
static void checkhints(void)
|
||||||
{
|
{
|
||||||
if (COND[game.loc] >= game.conds) {
|
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])
|
if (game.hinted[hint])
|
||||||
continue;
|
continue;
|
||||||
if (!CNDBIT(game.loc, hint + HBASE))
|
if (!CNDBIT(game.loc, hint + HBASE))
|
||||||
|
|
|
@ -9,6 +9,8 @@ h_name = "newdb.h"
|
||||||
c_name = "newdb.c"
|
c_name = "newdb.c"
|
||||||
|
|
||||||
h_template = """/* Generated from adventure.yaml - do not hand-hack! */
|
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 size_t CLSSES;
|
||||||
extern const int maximum_deaths;
|
extern const int maximum_deaths;
|
||||||
extern const int turn_threshold_count;
|
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)
|
db = yaml.load(f)
|
||||||
|
|
||||||
h = h_template.format(
|
h = h_template.format(
|
||||||
|
len(db["hints"]),
|
||||||
get_refs(db["arbitrary_messages"]),
|
get_refs(db["arbitrary_messages"]),
|
||||||
get_refs(db["locations"]),
|
get_refs(db["locations"]),
|
||||||
get_refs(db["object_descriptions"]),
|
get_refs(db["object_descriptions"]),
|
||||||
|
|
2
score.c
2
score.c
|
@ -87,7 +87,7 @@ long score(enum termination mode)
|
||||||
mxscor += 2;
|
mxscor += 2;
|
||||||
|
|
||||||
/* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */
|
/* 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])
|
if (game.hinted[i])
|
||||||
score = score - hints[i-1].penalty;
|
score = score - hints[i-1].penalty;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue