+extern const class_t classes[];
+extern turn_threshold_t turn_thresholds[];
+extern obituary_t obituaries[];
+extern hint_t hints[];
+extern long conditions[];
+extern const size_t CLSSES;
+extern const int maximum_deaths;
+extern const int turn_threshold_count;
+#define HINT_COUNT {}
+
+enum arbitrary_messages_refs {{
+{}
+}};
+
+enum locations_refs {{
+{}
+}};
+
+enum object_descriptions_refs {{
+{}
+}};
+
+/* State definitions */
+
+{}
+#endif /* end NEWDB_H */
+"""
+
+c_template = """/* Generated from adventure.yaml - do not hand-hack! */
+
+#include "common.h"
+#include "{}"
+
+const char* arbitrary_messages[] = {{
+{}
+}};
+
+const class_t classes[] = {{
+{}
+}};
+
+turn_threshold_t turn_thresholds[] = {{
+{}
+}};
+
+location_t locations[] = {{
+{}
+}};
+
+object_description_t object_descriptions[] = {{
+{}
+}};
+
+obituary_t obituaries[] = {{
+{}
+}};
+
+hint_t hints[] = {{
+{}
+}};
+
+long conditions[] = {{
+{}
+}};
+
+const size_t CLSSES = {};
+const int maximum_deaths = {};
+const int turn_threshold_count = {};
+
+/* end */
+"""
+
+def make_c_string(string):
+ """Render a Python string into C string literal format."""
+ if string == None:
+ return "NULL"
+ string = string.replace("\n", "\\n")
+ string = string.replace("\t", "\\t")
+ string = string.replace('"', '\\"')
+ string = string.replace("'", "\\'")
+ string = '"' + string + '"'
+ return string
+
+def get_refs(l):
+ reflist = [x[0] for x in l]
+ ref_str = ""
+ for ref in reflist:
+ ref_str += " {},\n".format(ref)
+ ref_str = ref_str[:-1] # trim trailing newline
+ return ref_str
+
+def get_arbitrary_messages(arb):
+ template = """ {},
+"""
+ arb_str = ""
+ for item in arb:
+ arb_str += template.format(make_c_string(item[1]))
+ arb_str = arb_str[:-1] # trim trailing newline
+ return arb_str
+
+def get_class_messages(cls):
+ template = """ {{
+ .threshold = {},
+ .message = {},
+ }},
+"""
+ cls_str = ""
+ for item in cls:
+ 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
+
+def get_turn_thresholds(trn):
+ template = """ {{
+ .threshold = {},
+ .point_loss = {},
+ .message = {},
+ }},
+"""
+ trn_str = ""
+ for item in trn:
+ 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
+
+def get_locations(loc):
+ template = """ {{
+ .description = {{
+ .small = {},
+ .big = {},
+ }},
+ .sound = {},
+ .loud = {},
+ }},
+"""
+ loc_str = ""
+ for item in loc:
+ short_d = make_c_string(item[1]["description"]["short"])
+ long_d = make_c_string(item[1]["description"]["long"])
+ sound = item[1].get("sound", "SILENT")
+ loud = "true" if item[1].get("loud") else "false"
+ loc_str += template.format(short_d, long_d, sound, loud)
+ loc_str = loc_str[:-1] # trim trailing newline
+ return loc_str