Generate initializer from YAML for Section 9 bits.

This commit is contained in:
Eric S. Raymond 2017-06-22 15:56:42 -04:00
parent 94d1aa5183
commit 537c4511e2
5 changed files with 81 additions and 46 deletions

View file

@ -65,7 +65,7 @@ newdb.o: newdb.c newdb.h
database.h: dungeon
./dungeon
newdb.c newdb.h:
newdb.c newdb.h: newdungeon.py adventure.yaml
python3 newdungeon.py
linenoise.o: linenoise/linenoise.h

View file

@ -128,25 +128,6 @@ extern int suspend(void);
extern int resume(void);
extern int restore(FILE *);
/* Symbols for cond bits - used by following macros */
#define COND_LIT 0 /* Light */
#define COND_OILY 1 /* If bit 2 is on: on for oil, off for water */
#define COND_FLUID 2 /* Liquid asset, see bit 1 */
#define COND_NOARRR 3 /* Pirate doesn't go here unless following */
#define COND_NOBACK 4 /* Cannot use "back" to move away */
/* Bits past 10 indicate areas of interest to "hint" routines */
#define COND_HBASE 10 /* Base for location hint bits */
#define COND_HCAVE 11 /* Trying to get into cave */
#define COND_HBIRD 12 /* Trying to catch bird */
#define COND_HSNAKE 13 /* Trying to deal with snake */
#define COND_HMAZE 14 /* Lost in maze */
#define COND_HDARK 15 /* Pondering dark room */
#define COND_HWITT 16 /* At Witt's End */
#define COND_HCLIFF 17 /* Cliff with urn */
#define COND_HWOODS 18 /* Lost in forest */
#define COND_HOGRE 19 /* Trying to deal with ogre */
#define COND_HJADE 20 /* Found all treasures except jade */
/*
* MOD(N,M) = Arithmetic modulus
* AT(OBJ) = true if on either side of two-placed object

View file

@ -69,60 +69,70 @@
# FIXME: Hint texts shouldn't be in arbitrary_messages, but inlined here
hints:
- hint: &grate
name: CAVE
number: 1
turns: 4
penalty: 2
question: ENTRY_QUERY
hint: HARD_GRATE
- hint: &bird
name: BIRD
number: 2
turns: 5
penalty: 2
question: BIRD_QUERY
hint: SKITTISH_BIRD
- hint: &snake
name: SNAKE
number: 3
turns: 8
penalty: 2
question: SNAKE_QUERY
hint: SNAKE_HINT
- hint: &maze
name: MAZE
number: 4
turns: 75
penalty: 4
question: MAZE_HELP
hint: DROP_THINGS
- hint: &dark
name: DARK
number: 5
turns: 25
penalty: 5
question: PLOVER_QUERY
hint: EXPLORE_HINT
- hint: &witt
name: WITT
number: 6
turns: 20
penalty: 3
question: HELP_LEAVING
hint: NOGO_WEST
- hint: &cliff
- hint: &urn
name: CLIFF
number: 7
turns: 8
penalty: 2
question: WONDERING_QUERY
hint: ADVANCED_SECTION
- hint: &forest
name: WOODS
number: 8
turns: 25
penalty: 2
question: FOREST_QUERY
hint: GO_EAST
- hint: &ogre
name: OGRE
number: 9
turns: 10
penalty: 4
question: OGRE_QUERY
hint: OGRE_CLUE
- hint: &jade
name: JADE
number: 10
turns: 1
penalty: 4
@ -165,7 +175,7 @@ locations: !!omap
long: 'The forest thins out here to reveal a steep cliff. There is no way\ndown, but a small ledge can be seen to the west across the chasm.'
short: 'You''re at cliff.'
conditions: {ABOVE: true, NOBACK: true, LIT: true}
hints: [*cliff]
hints: [*urn]
- LOC_SLIT:
description:
long: 'At your feet all the water of the stream splashes into a 2-inch slit\nin the rock. Downstream the streambed is bare rock.'
@ -656,19 +666,19 @@ locations: !!omap
long: 'You are in an alcove. A small nw path seems to widen after a short\ndistance. An extremely tight tunnel leads east. It looks like a very\ntight squeeze. An eerie light can be seen at the other end.'
short: 'You''re in alcove.'
conditions: {DEEP: true}
hits: [*dark]
hints: [*dark]
- LOC_PLOVER:
description:
long: 'You''re in a small chamber lit by an eerie green light. An extremely\nnarrow tunnel exits to the west. A dark corridor leads ne.'
short: 'You''re in Plover Room.'
conditions: {DEEP: true, LIT: true}
hits: [*dark]
hints: [*dark]
- LOC_DARKROOM:
description:
long: 'You''re in the dark-room. A corridor leading south is the only exit.'
short: 'You''re in dark-room.'
conditions: {DEEP: true}
hits: [*dark]
hints: [*dark]
- LOC_ARCHED:
description:
long: 'You are in an arched hall. A coral passage once continued up and east\nfrom here, but is now blocked by debris. The air smells of sea water.'
@ -882,7 +892,7 @@ locations: !!omap
long: 'You are in a large chamber with passages to the west and north.'
short: !!null
conditions: {DEEP: true}
hits: [*ogre]
hints: [*ogre]
- LOC_STOREROOM:
description:
long: 'You are in the ogre''s storeroom. The only exit is to the south.'
@ -899,19 +909,19 @@ locations: !!omap
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST3:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST4:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: { FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST5:
description:
long: 'You are wandering aimlessly through the forest.'
@ -923,19 +933,19 @@ locations: !!omap
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST7:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST8:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST9:
description:
long: 'You are wandering aimlessly through the forest.'
@ -947,19 +957,19 @@ locations: !!omap
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST11:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST12:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST13:
description:
long: 'You are wandering aimlessly through the forest.'
@ -971,19 +981,19 @@ locations: !!omap
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST15:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST16:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST17:
description:
long: 'You are wandering aimlessly through the forest.'
@ -995,19 +1005,19 @@ locations: !!omap
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST19:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST20:
description:
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true, DEEP: true}
hits: [*forest]
hints: [*forest]
- LOC_FOREST21:
description:
long: 'You are wandering aimlessly through the forest.'
@ -1019,7 +1029,7 @@ locations: !!omap
long: 'You are wandering aimlessly through the forest.'
short: !!null
conditions: {FOREST: true, NOBACK: true, LIT: true}
hits: [*forest]
hints: [*forest]
- LOC_LEDGE:
description:
long: 'You are on a small ledge on one face of a sheer cliff. There are no\npaths away from the ledge. Across the chasm is a small clearing\nsurrounded by forest.'
@ -1110,10 +1120,6 @@ locations: !!omap
long: '>>Foof!<<'
short: !!null
conditions: {DEEP: true}
- LOC_NUGGET5:
description:
long: !!null
short: !!null
arbitrary_messages: !!omap
- NO_MESSAGE: !!null

View file

@ -8,6 +8,28 @@
extern const char advent_to_ascii[128];
extern const char ascii_to_advent[128];
/* Symbols for cond bits - used by advent.h */
#define COND_LIT 0 /* Light */
#define COND_OILY 1 /* If bit 2 is on: on for oil, off for water */
#define COND_FLUID 2 /* Liquid asset, see bit 1 */
#define COND_NOARRR 3 /* Pirate doesn't go here unless following */
#define COND_NOBACK 4 /* Cannot use "back" to move away */
#define COND_ABOVE 5
#define COND_DEEP 6 /* Deep - e.g where dwarves are active */
#define COND_FOREST 7 /* in the forest */
/* Bits past 10 indicate areas of interest to "hint" routines */
#define COND_HBASE 10 /* Base for location hint bits */
#define COND_HCAVE 11 /* Trying to get into cave */
#define COND_HBIRD 12 /* Trying to catch bird */
#define COND_HSNAKE 13 /* Trying to deal with snake */
#define COND_HMAZE 14 /* Lost in maze */
#define COND_HDARK 15 /* Pondering dark room */
#define COND_HWITT 16 /* At Witt's End */
#define COND_HCLIFF 17 /* Cliff with urn */
#define COND_HWOODS 18 /* Lost in forest */
#define COND_HOGRE 19 /* Trying to deal with ogre */
#define COND_HJADE 20 /* Found all treasures except jade */
enum bugtype {
MESSAGE_LINE_GT_70_CHARACTERS, // 0
NULL_LINE_IN_MESSAGE, // 1

View file

@ -59,6 +59,7 @@ extern const class_t classes[];
extern turn_threshold_t turn_thresholds[];
extern obituary_t obituaries[];
extern hint_t hints[];
extern const long conditions[];
extern const size_t CLSSES;
extern const int maximum_deaths;
@ -82,6 +83,7 @@ enum object_descriptions_refs {{
c_template = """/* Generated from adventure.yaml - do not hand-hack! */
#include "common.h"
#include "{}"
const char* arbitrary_messages[] = {{
@ -112,6 +114,10 @@ hint_t hints[] = {{
{}
}};
const long conditions[] = {{
{}
}};
const size_t CLSSES = {};
const int maximum_deaths = {};
const int turn_threshold_count = {};
@ -251,6 +257,25 @@ def get_hints(hnt, arb):
hnt_str = hnt_str[:-1] # trim trailing newline
return hnt_str
def get_condbits(locations):
cnd_str = ""
for (name, loc) in locations:
conditions = loc["conditions"]
hints = loc.get("hints") or []
flaglist = []
for flag in conditions:
if conditions[flag]:
flaglist.append(flag)
line = "|".join([("(1<<COND_%s)" % f) for f in flaglist])
trail = "|".join([("(1<<COND_H%s)" % f['name']) for f in hints])
if trail:
line += "|" + trail
if line.startswith("|"):
line = line[1:]
if not line:
line = "0"
cnd_str += " " + line + ",\t// " + name + "\n"
return cnd_str
if __name__ == "__main__":
with open(yaml_name, "r") as f:
@ -272,6 +297,7 @@ if __name__ == "__main__":
get_object_descriptions(db["object_descriptions"]),
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"]),