From: Jason S. Ninneman Date: Tue, 27 Jun 2017 04:53:24 +0000 (-0700) Subject: Express actions[] in newdb.[ch]. X-Git-Tag: 1.1~89 X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=commitdiff_plain;h=4d212476431be635c2b757816c20f6fe8936f334 Express actions[] in newdb.[ch]. --- diff --git a/newdungeon.py b/newdungeon.py index 8974a5a..ff48cae 100755 --- a/newdungeon.py +++ b/newdungeon.py @@ -92,6 +92,11 @@ typedef struct {{ const char** words; }} motion_t; +typedef struct {{ + const char** words; + const long message; +}} action_t; + extern const location_t locations[]; extern const object_t objects[]; extern const char* arbitrary_messages[]; @@ -109,7 +114,7 @@ extern const motion_t motions[]; #define NCLASSES {} #define NDEATHS {} #define NTHRESHOLDS {} -#define NVERBS {} +#define NACTIONS {} #define NTRAVEL {} enum arbitrary_messages_refs {{ @@ -128,6 +133,10 @@ enum motion_refs {{ {} }}; +enum action_refs {{ +{} +}}; + /* State definitions */ {} @@ -180,6 +189,10 @@ const motion_t motions[] = {{ {} }}; +const action_t actions[] = {{ +{} +}}; + /* end */ """ @@ -484,6 +497,31 @@ def get_motions(motions): mot_str += template.format(words_str) return mot_str +def get_actions(actions): + template = """ {{ + .words = {}, + .message = {}, + }}, +""" + act_str = "" + for action in actions: + contents = action[1] + + if contents["words"] == None: + words_str = "NULL" + else: + c_words = [make_c_string(s) for s in contents["words"]] + words_str = "(const char* []) {" + ", ".join(c_words) + "}" + + if contents["message"] == None: + message = "NO_MESSAGE" + else: + message = contents["message"] + + act_str += template.format(words_str, message) + act_str = act_str[:-1] # trim trailing newline + return act_str + if __name__ == "__main__": with open(yaml_name, "r") as f: db = yaml.load(f) @@ -506,6 +544,7 @@ if __name__ == "__main__": get_condbits(db["locations"]), get_actspk(db["actspk"]), get_motions(db["motions"]), + get_actions(db["actions"]), ) h = h_template.format( @@ -521,6 +560,7 @@ if __name__ == "__main__": get_refs(db["locations"]), get_refs(db["objects"]), get_refs(db["motions"]), + get_refs(db["actions"]), statedefines, )