X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=newdungeon.py;h=f8ef9571abd0bc897aa2145041c3d3f646e49f2c;hp=923fb397373b769624cfab520e93dfcd501e2018;hb=f6373dd32e4ed75b18c9c6fb7dfa103d4ef68891;hpb=6c4f14033363169eae5c73be7d9f77d84c296150 diff --git a/newdungeon.py b/newdungeon.py index 923fb39..f8ef957 100755 --- a/newdungeon.py +++ b/newdungeon.py @@ -29,28 +29,32 @@ typedef struct {{ const char* yes_response; }} obituary_t; +typedef struct {{ + const int threshold; + const int point_loss; + const char* message; +}} turn_threshold_t; + +typedef struct {{ + const int threshold; + const char* message; +}} class_t; + extern location_t locations[]; extern object_description_t object_descriptions[]; extern const char* arbitrary_messages[]; -extern const char* class_messages[]; -extern const char* turn_threshold_messages[]; +extern const class_t classes[]; +extern turn_threshold_t turn_thresholds[]; extern obituary_t obituaries[]; extern size_t CLSSES; extern int maximum_deaths; +extern int turn_threshold_count; enum arbitrary_messages_refs {{ {} }}; -enum class_messages_refs {{ -{} -}}; - -enum turn_threshold_messages_refs {{ -{} -}}; - enum locations_refs {{ {} }}; @@ -66,11 +70,11 @@ const char* arbitrary_messages[] = {{ {} }}; -const char* class_messages[] = {{ +const class_t classes[] = {{ {} }}; -const char* turn_threshold_messages[] = {{ +turn_threshold_t turn_thresholds[] = {{ {} }}; @@ -88,6 +92,7 @@ obituary_t obituaries[] = {{ size_t CLSSES = {}; int maximum_deaths = {}; +int turn_threshold_count = {}; """ def make_c_string(string): @@ -119,20 +124,32 @@ def get_arbitrary_messages(arb): return arb_str def get_class_messages(cls): - template = """ {}, + template = """ {{ + .threshold = {}, + .message = {}, + }}, """ cls_str = "" for item in cls: - cls_str += template.format(make_c_string(item[1])) + threshold = item["threshold"] + message = make_c_string(item["message"]) + cls_str += template.format(threshold, message) cls_str = cls_str[:-1] # trim trailing newline - return cls_str + return cls_str -def get_turn_threshold_messages(trn): - template = """ {}, +def get_turn_thresholds(trn): + template = """ {{ + .threshold = {}, + .point_loss = {}, + .message = {}, + }}, """ trn_str = "" for item in trn: - trn_str += template.format(make_c_string(item[1])) + threshold = item["threshold"] + point_loss = item["point_loss"] + message = make_c_string(item["message"]) + trn_str += template.format(threshold, point_loss, message) trn_str = trn_str[:-1] # trim trailing newline return trn_str @@ -193,8 +210,6 @@ with open(yaml_name, "r") as f: h = h_template.format( get_refs(db["arbitrary_messages"]), - get_refs(db["class_messages"]), - get_refs(db["turn_threshold_messages"]), get_refs(db["locations"]), get_refs(db["object_descriptions"]), ) @@ -202,13 +217,14 @@ h = h_template.format( c = c_template.format( h_name, get_arbitrary_messages(db["arbitrary_messages"]), - get_class_messages(db["class_messages"]), - get_turn_threshold_messages(db["turn_threshold_messages"]), + get_class_messages(db["classes"]), + get_turn_thresholds(db["turn_thresholds"]), get_locations(db["locations"]), get_object_descriptions(db["object_descriptions"]), get_obituaries(db["obituaries"]), - len(db["class_messages"]), + len(db["classes"]), len(db["obituaries"]), + len(db["turn_thresholds"]), ) with open(h_name, "w") as hf: