More readable dungeon.c output.
[open-adventure.git] / make_dungeon.py
1 #!/usr/bin/python3
2
3 # This is the new open-adventure dungeon generator. It'll eventually
4 # replace the existing dungeon.c It currently outputs a .h and .c pair
5 # for C code.
6 #
7 # The nontrivial part of this is the compilation of the YAML for
8 # movement rules to the travel array that's actually used by
9 # playermove().  This program first compiles the YAML to a form
10 # identical to the data in section 3 of the old adventure.text file,
11 # then a second stage unpacks that data into the travel array.
12 #
13 # Here are the rules of the intermediate form:
14 #
15 # Each row of data contains a location number (X), a second
16 # location number (Y), and a list of motion numbers (see section 4).
17 # each motion represents a verb which will go to Y if currently at X.
18 # Y, in turn, is interpreted as follows.  Let M=Y/1000, N=Y mod 1000.
19 #               If N<=300       it is the location to go to.
20 #               If 300<N<=500   N-300 is used in a computed goto to
21 #                                       a section of special code.
22 #               If N>500        message N-500 from section 6 is printed,
23 #                                       and he stays wherever he is.
24 # Meanwhile, M specifies the conditions on the motion.
25 #               If M=0          it's unconditional.
26 #               If 0<M<100      it is done with M% probability.
27 #               If M=100        unconditional, but forbidden to dwarves.
28 #               If 100<M<=200   he must be carrying object M-100.
29 #               If 200<M<=300   must be carrying or in same room as M-200.
30 #               If 300<M<=400   game.prop(M % 100) must *not* be 0.
31 #               If 400<M<=500   game.prop(M % 100) must *not* be 1.
32 #               If 500<M<=600   game.prop(M % 100) must *not* be 2, etc.
33 # If the condition (if any) is not met, then the next *different*
34 # "destination" value is used (unless it fails to meet *its* conditions,
35 # in which case the next is found, etc.).  Typically, the next dest will
36 # be for one of the same verbs, so that its only use is as the alternate
37 # destination for those verbs.  For instance:
38 #               15      110022  29      31      34      35      23      43
39 #               15      14      29
40 # This says that, from loc 15, any of the verbs 29, 31, etc., will take
41 # him to 22 if he's carrying object 10, and otherwise will go to 14.
42 #               11      303008  49
43 #               11      9       50
44 # This says that, from 11, 49 takes him to 8 unless game.prop(3)=0, in which
45 # case he goes to 9.  Verb 50 takes him to 9 regardless of game.prop(3).
46
47 import sys, yaml
48
49 yaml_name = "adventure.yaml"
50 h_name = "dungeon.h"
51 c_name = "dungeon.c"
52
53 statedefines = ""
54
55 h_template = """/* Generated from adventure.yaml - do not hand-hack! */
56 #ifndef DUNGEON_H
57 #define DUNGEON_H
58
59 #include <stdio.h>
60 #include <stdbool.h>
61
62 #define SILENT  -1      /* no sound */
63
64 /* Symbols for cond bits */
65 #define COND_LIT        0       /* Light */
66 #define COND_OILY       1       /* If bit 2 is on: on for oil, off for water */
67 #define COND_FLUID      2       /* Liquid asset, see bit 1 */
68 #define COND_NOARRR     3       /* Pirate doesn't go here unless following */
69 #define COND_NOBACK     4       /* Cannot use "back" to move away */
70 #define COND_ABOVE      5
71 #define COND_DEEP       6       /* Deep - e.g where dwarves are active */
72 #define COND_FOREST     7       /* In the forest */
73 #define COND_FORCED     8       /* Only one way in or out of here */
74 /* Bits past 10 indicate areas of interest to "hint" routines */
75 #define COND_HBASE      10      /* Base for location hint bits */
76 #define COND_HCAVE      11      /* Trying to get into cave */
77 #define COND_HBIRD      12      /* Trying to catch bird */
78 #define COND_HSNAKE     13      /* Trying to deal with snake */
79 #define COND_HMAZE      14      /* Lost in maze */
80 #define COND_HDARK      15      /* Pondering dark room */
81 #define COND_HWITT      16      /* At Witt's End */
82 #define COND_HCLIFF     17      /* Cliff with urn */
83 #define COND_HWOODS     18      /* Lost in forest */
84 #define COND_HOGRE      19      /* Trying to deal with ogre */
85 #define COND_HJADE      20      /* Found all treasures except jade */
86
87 typedef struct {{
88   const char** strs;
89   const int n;
90 }} string_group_t;
91
92 typedef struct {{
93   const string_group_t words;
94   const char* inventory;
95   int plac, fixd;
96   bool is_treasure;
97   const char** descriptions;
98   const char** sounds;
99   const char** texts;
100   const char** changes;
101 }} object_t;
102
103 typedef struct {{
104   const char* small;
105   const char* big;
106 }} descriptions_t;
107
108 typedef struct {{
109   descriptions_t description;
110   const long sound;
111   const bool loud;
112 }} location_t;
113
114 typedef struct {{
115   const char* query;
116   const char* yes_response;
117 }} obituary_t;
118
119 typedef struct {{
120   const int threshold;
121   const int point_loss;
122   const char* message;
123 }} turn_threshold_t;
124
125 typedef struct {{
126   const int threshold;
127   const char* message;
128 }} class_t;
129
130 typedef struct {{
131   const int number;
132   const int turns;
133   const int penalty;
134   const char* question;
135   const char* hint;
136 }} hint_t;
137
138 typedef struct {{
139   const string_group_t words;
140 }} motion_t;
141
142 typedef struct {{
143   const string_group_t words;
144   const char* message;
145 }} action_t;
146
147 typedef struct {{
148   const string_group_t words;
149   const char* message;
150 }} special_t;
151
152 typedef struct {{
153   const long motion;
154   const long cond;
155   const long dest;
156   const bool nodwarves;
157   const bool stop;
158 }} travelop_t;
159
160 /* Abstract out the encoding of words in the travel array.  Gives us
161  * some hope of getting to a less cryptic representation than we
162  * inherited from FORTRAN, someday. To understand these, read the
163  * encoding description for travel.
164  */
165 #define T_TERMINATE(entry)      ((entry).motion == 1)
166 #define L_SPEAK(loc)            ((loc) - 500)
167
168 extern const location_t locations[];
169 extern const object_t objects[];
170 extern const char* arbitrary_messages[];
171 extern const class_t classes[];
172 extern const turn_threshold_t turn_thresholds[];
173 extern const obituary_t obituaries[];
174 extern const hint_t hints[];
175 extern long conditions[];
176 extern const motion_t motions[];
177 extern const action_t actions[];
178 extern const special_t specials[];
179 extern const travelop_t travel[];
180 extern const long tkey[];
181 extern const char *ignore;
182
183 #define NLOCATIONS      {}
184 #define NOBJECTS        {}
185 #define NHINTS          {}
186 #define NCLASSES        {}
187 #define NDEATHS         {}
188 #define NTHRESHOLDS     {}
189 #define NMOTIONS        {}
190 #define NACTIONS        {}
191 #define NSPECIALS       {}
192 #define NTRAVEL         {}
193 #define NKEYS           {}
194
195 #define BIRD_ENDSTATE   {}
196
197 enum arbitrary_messages_refs {{
198 {}
199 }};
200
201 enum locations_refs {{
202 {}
203 }};
204
205 enum object_refs {{
206 {}
207 }};
208
209 enum motion_refs {{
210 {}
211 }};
212
213 enum action_refs {{
214 {}
215 }};
216
217 enum special_refs {{
218 {}
219 }};
220
221 /* State definitions */
222
223 {}
224 #endif /* end DUNGEON_H */
225 """
226
227 c_template = """/* Generated from adventure.yaml - do not hand-hack! */
228
229 #include "{}"
230
231 const char* arbitrary_messages[] = {{
232 {}
233 }};
234
235 const class_t classes[] = {{
236 {}
237 }};
238
239 const turn_threshold_t turn_thresholds[] = {{
240 {}
241 }};
242
243 const location_t locations[] = {{
244 {}
245 }};
246
247 const object_t objects[] = {{
248 {}
249 }};
250
251 const obituary_t obituaries[] = {{
252 {}
253 }};
254
255 const hint_t hints[] = {{
256 {}
257 }};
258
259 long conditions[] = {{
260 {}
261 }};
262
263 const motion_t motions[] = {{
264 {}
265 }};
266
267 const action_t actions[] = {{
268 {}
269 }};
270
271 const special_t specials[] = {{
272 {}
273 }};
274
275 const long tkey[] = {{{}}};
276
277 const travelop_t travel[] = {{
278 {}
279 }};
280
281 const char *ignore = \"{}\";
282
283 /* end */
284 """
285
286 def make_c_string(string):
287     """Render a Python string into C string literal format."""
288     if string == None:
289         return "NULL"
290     string = string.replace("\n", "\\n")
291     string = string.replace("\t", "\\t")
292     string = string.replace('"', '\\"')
293     string = string.replace("'", "\\'")
294     string = '"' + string + '"'
295     return string
296
297 def get_refs(l):
298     reflist = [x[0] for x in l]
299     ref_str = ""
300     for ref in reflist:
301         ref_str += "    {},\n".format(ref)
302     ref_str = ref_str[:-1] # trim trailing newline
303     return ref_str
304
305 def get_string_group(strings):
306     template = """{{
307             .strs = {},
308             .n = {},
309         }}"""
310     if strings == []:
311         strs = "NULL"
312     else:
313         strs = "(const char* []) {" + ", ".join([make_c_string(s) for s in strings]) + "}"
314     n = len(strings)
315     sg_str = template.format(strs, n)
316     return sg_str
317
318 def get_arbitrary_messages(arb):
319     template = """    {},
320 """
321     arb_str = ""
322     for item in arb:
323         arb_str += template.format(make_c_string(item[1]))
324     arb_str = arb_str[:-1] # trim trailing newline
325     return arb_str
326
327 def get_class_messages(cls):
328     template = """    {{
329         .threshold = {},
330         .message = {},
331     }},
332 """
333     cls_str = ""
334     for item in cls:
335         threshold = item["threshold"]
336         message = make_c_string(item["message"])
337         cls_str += template.format(threshold, message)
338     cls_str = cls_str[:-1] # trim trailing newline
339     return cls_str
340
341 def get_turn_thresholds(trn):
342     template = """    {{
343         .threshold = {},
344         .point_loss = {},
345         .message = {},
346     }},
347 """
348     trn_str = ""
349     for item in trn:
350         threshold = item["threshold"]
351         point_loss = item["point_loss"]
352         message = make_c_string(item["message"])
353         trn_str += template.format(threshold, point_loss, message)
354     trn_str = trn_str[:-1] # trim trailing newline
355     return trn_str
356
357 def get_locations(loc):
358     template = """    {{ // {}: {}
359         .description = {{
360             .small = {},
361             .big = {},
362         }},
363         .sound = {},
364         .loud = {},
365     }},
366 """
367     loc_str = ""
368     for (i, item) in enumerate(loc):
369         short_d = make_c_string(item[1]["description"]["short"])
370         long_d = make_c_string(item[1]["description"]["long"])
371         sound = item[1].get("sound", "SILENT")
372         loud = "true" if item[1].get("loud") else "false"
373         loc_str += template.format(i, item[0], short_d, long_d, sound, loud)
374     loc_str = loc_str[:-1] # trim trailing newline
375     return loc_str
376
377 def get_objects(obj):
378     template = """    {{ // {}: {}
379         .words = {},
380         .inventory = {},
381         .plac = {},
382         .fixd = {},
383         .is_treasure = {},
384         .descriptions = (const char* []) {{
385 {}
386         }},
387         .sounds = (const char* []) {{
388 {}
389         }},
390         .texts = (const char* []) {{
391 {}
392         }},
393         .changes = (const char* []) {{
394 {}
395         }},
396     }},
397 """
398     obj_str = ""
399     for (i, item) in enumerate(obj):
400         attr = item[1]
401         try:
402             words_str = get_string_group(attr["words"])
403         except KeyError:
404             words_str = get_string_group([])
405         i_msg = make_c_string(attr["inventory"])
406         descriptions_str = ""
407         if attr["descriptions"] == None:
408             descriptions_str = " " * 12 + "NULL,"
409         else:
410             labels = []
411             for l_msg in attr["descriptions"]:
412                 descriptions_str += " " * 12 + make_c_string(l_msg) + ",\n"
413             for label in attr.get("states", []):
414                 labels.append(label)
415             descriptions_str = descriptions_str[:-1] # trim trailing newline
416             if labels:
417                 global statedefines
418                 statedefines += "/* States for %s */\n" % item[0]
419                 for (i, label) in enumerate(labels):
420                     statedefines += "#define %s\t%d\n" % (label, i)
421                 statedefines += "\n"
422         sounds_str = ""
423         if attr.get("sounds") == None:
424             sounds_str = " " * 12 + "NULL,"
425         else:
426              for l_msg in attr["sounds"]:
427                  sounds_str += " " * 12 + make_c_string(l_msg) + ",\n"
428              sounds_str = sounds_str[:-1] # trim trailing newline
429         texts_str = ""
430         if attr.get("texts") == None:
431             texts_str = " " * 12 + "NULL,"
432         else:
433              for l_msg in attr["texts"]:
434                  texts_str += " " * 12 + make_c_string(l_msg) + ",\n"
435              texts_str = texts_str[:-1] # trim trailing newline
436         changes_str = ""
437         if attr.get("changes") == None:
438             changes_str = " " * 12 + "NULL,"
439         else:
440              for l_msg in attr["changes"]:
441                  changes_str += " " * 12 + make_c_string(l_msg) + ",\n"
442              changes_str = changes_str[:-1] # trim trailing newline
443         locs = attr.get("locations", ["LOC_NOWHERE", "LOC_NOWHERE"])
444         immovable = attr.get("immovable", False)
445         try:
446             if type(locs) == str:
447                 locs = [locs, -1 if immovable else 0]
448         except IndexError:
449             sys.stderr.write("dungeon: unknown object location in %s\n" % locs)
450             sys.exit(1)
451         treasure = "true" if attr.get("treasure") else "false"
452         obj_str += template.format(i, item[0], words_str, i_msg, locs[0], locs[1], treasure, descriptions_str, sounds_str, texts_str, changes_str)
453     obj_str = obj_str[:-1] # trim trailing newline
454     return obj_str
455
456 def get_obituaries(obit):
457     template = """    {{
458         .query = {},
459         .yes_response = {},
460     }},
461 """
462     obit_str = ""
463     for o in obit:
464         query = make_c_string(o["query"])
465         yes = make_c_string(o["yes_response"])
466         obit_str += template.format(query, yes)
467     obit_str = obit_str[:-1] # trim trailing newline
468     return obit_str
469
470 def get_hints(hnt, arb):
471     template = """    {{
472         .number = {},
473         .penalty = {},
474         .turns = {},
475         .question = {},
476         .hint = {},
477     }},
478 """
479     hnt_str = ""
480     md = dict(arb)
481     for member in hnt:
482         item = member["hint"]
483         number = item["number"]
484         penalty = item["penalty"]
485         turns = item["turns"]
486         question = make_c_string(item["question"])
487         hint = make_c_string(item["hint"])
488         hnt_str += template.format(number, penalty, turns, question, hint)
489     hnt_str = hnt_str[:-1] # trim trailing newline
490     return hnt_str
491
492 def get_condbits(locations):
493     cnd_str = ""
494     for (name, loc) in locations:
495         conditions = loc["conditions"]
496         hints = loc.get("hints") or []
497         flaglist = []
498         for flag in conditions:
499             if conditions[flag]:
500                 flaglist.append(flag)
501         line = "|".join([("(1<<COND_%s)" % f) for f in flaglist])
502         trail = "|".join([("(1<<COND_H%s)" % f['name']) for f in hints])
503         if trail:
504             line += "|" + trail
505         if line.startswith("|"):
506             line = line[1:]
507         if not line:
508             line = "0"
509         cnd_str += "    " + line + ",\t// " + name + "\n"
510     return cnd_str
511
512 def get_motions(motions):
513     template = """    {{
514         .words = {},
515     }},
516 """
517     mot_str = ""
518     for motion in motions:
519         contents = motion[1]
520         if contents["words"] == None:
521             words_str = get_string_group([])
522         else:
523             words_str = get_string_group(contents["words"])
524         mot_str += template.format(words_str)
525         global ignore
526         if contents.get("oldstyle", True) == False:
527             for word in contents["words"]:
528                 if len(word) == 1:
529                     ignore += word.upper()
530     return mot_str
531
532 def get_actions(actions):
533     template = """    {{
534         .words = {},
535         .message = {},
536     }},
537 """
538     act_str = ""
539     for action in actions:
540         contents = action[1]
541         
542         if contents["words"] == None:
543             words_str = get_string_group([])
544         else:
545             words_str = get_string_group(contents["words"])
546
547         if contents["message"] == None:
548             message = "NO_MESSAGE"
549         else:
550             message = contents["message"]
551             
552         act_str += template.format(words_str, message)
553         global ignore
554         if contents.get("oldstyle", True) == False:
555             for word in contents["words"]:
556                 if len(word) == 1:
557                     ignore += word.upper()
558     act_str = act_str[:-1] # trim trailing newline
559     return act_str
560
561 def get_specials(specials):
562     template = """    {{
563         .words = {},
564         .message = {},
565     }},
566 """
567     spc_str = ""
568     for special in specials:
569         contents = special[1]
570
571         if contents["words"] == None:
572             words_str = get_string_group([])
573         else:
574             words_str = get_string_group(contents["words"])
575
576         if contents["message"] == None:
577             message = "NULL"
578         else:
579             message = make_c_string(contents["message"])
580
581         spc_str += template.format(words_str, message)
582         global ignore
583         if contents.get("oldstyle", True) == False:
584             for word in contents["words"]:
585                 if len(word) == 1:
586                     ignore += word.upper()
587     spc_str = spc_str[:-1] # trim trailing newline
588     return spc_str
589
590 def bigdump(arr):
591     out = ""
592     for (i, entry) in enumerate(arr):
593         if i % 10 == 0:
594             if out and out[-1] == ' ':
595                 out = out[:-1]
596             out += "\n    "
597         out += str(arr[i]).lower() + ", "
598     out = out[:-2] + "\n"
599     return out
600
601 def buildtravel(locs, objs):
602     ltravel = []
603     verbmap = {}
604     for i, motion in enumerate(db["motions"]):
605         try:
606             for word in motion[1]["words"]:
607                 verbmap[word.upper()] = i
608         except TypeError:
609             pass
610     def dencode(action, name):
611         "Decode a destination number"
612         if action[0] == "goto":
613             try:
614                 return locnames.index(action[1])
615             except ValueError:
616                 sys.stderr.write("dungeon: unknown location %s in goto clause of %s\n" % (cond[1], name))
617         elif action[0] == "special":
618             return 300 + action[1]
619         elif action[0] == "speak":
620             try:
621                 return 500 + msgnames.index(action[1])
622             except ValueError:
623                 sys.stderr.write("dungeon: unknown location %s in carry clause of %s\n" % (cond[1], name))
624         else:
625             print(cond)
626             raise ValueError
627     def cencode(cond, name):
628         if cond is None:
629             return 0
630         elif cond == ["nodwarves"]:
631             return 100
632         elif cond[0] == "pct":
633             return cond[1]
634         elif cond[0] == "carry":
635             try:
636                 return 100 + objnames.index(cond[1])
637             except ValueError:
638                 sys.stderr.write("dungeon: unknown object name %s in carry clause of %s\n" % (cond[1], name))
639                 sys.exit(1)
640         elif cond[0] == "with":
641             try:
642                 return 200 + objnames.index(cond[1])
643             except IndexError:
644                 sys.stderr.write("dungeon: unknown object name %s in with clause of \n" % (cond[1], name))
645                 sys.exit(1)
646         elif cond[0] == "not":
647             try:
648                 obj = objnames.index(cond[1])
649                 if type(cond[2]) == int:
650                     state = cond[2]
651                 elif cond[2] in objs[obj][1].get("states", []):
652                     state = objs[obj][1].get("states").index(cond[2])
653                 else:
654                     for (i, stateclause) in enumerate(objs[obj][1]["descriptions"]):
655                         if type(stateclause) == list:
656                             if stateclause[0] == cond[2]:
657                                 state = i
658                                 break
659                     else:
660                         sys.stderr.write("dungeon: unmatched state symbol %s in not clause of %s\n" % (cond[2], name))
661                         sys.exit(0);
662                 return 300 + obj + 100 * state
663             except ValueError:
664                 sys.stderr.write("dungeon: unknown object name %s in not clause of %s\n" % (cond[1], name))
665                 sys.exit(1)
666         else:
667             print(cond)
668             raise ValueError
669
670     for (i, (name, loc)) in enumerate(locs):
671         if "travel" in loc:
672             for rule in loc["travel"]:
673                 tt = [i]
674                 dest = dencode(rule["action"], name) + 1000 * cencode(rule.get("cond"), name)
675                 tt.append(dest)
676                 tt += [motionnames[verbmap[e]].upper() for e in rule["verbs"]]
677                 if not rule["verbs"]:
678                     tt.append(1)
679                 ltravel.append(tuple(tt))
680
681     # At this point the ltravel data is in the Section 3
682     # representation from the FORTRAN version.  Next we perform the
683     # same mapping into the runtime format.  This was the C translation
684     # of the FORTRAN code:
685     # long loc;
686     # while ((loc = GETNUM(database)) != -1) {
687     #     long newloc = GETNUM(NULL);
688     #     long L;
689     #     if (TKEY[loc] == 0) {
690     #         TKEY[loc] = TRVS;
691     #     } else {
692     #         TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
693     #     }
694     #     while ((L = GETNUM(NULL)) != 0) {
695     #         TRAVEL[TRVS] = newloc * 1000 + L;
696     #         TRVS = TRVS + 1;
697     #         if (TRVS == TRVSIZ)
698     #             BUG(TOO_MANY_TRAVEL_OPTIONS);
699     #     }
700     #     TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
701     # }
702     #
703     # In order to de-crypticize the runtime code, we're going to break these
704     # magic numbers up into a struct.
705     travel = [[0, "LOC_NOWHERE", 0, 0, 0, "false", "false"]]
706     tkey = [0]
707     oldloc = 0
708     while ltravel:
709         rule = list(ltravel.pop(0))
710         loc = rule.pop(0)
711         newloc = rule.pop(0)
712         if loc != oldloc:
713             tkey.append(len(travel))
714             oldloc = loc 
715         elif travel:
716             travel[-1][-1] = "false" if travel[-1][-1] == "true" else "true" 
717         while rule:
718             cond = newloc // 1000
719             dest = newloc % 1000
720             travel.append([len(tkey)-1,
721                            locnames[len(tkey)-1],
722                            rule.pop(0),
723                            cond,
724                            locnames[dest] if dest <= 300 else dest,
725                            "true" if cond==100 else "false",
726                            "false"])
727         travel[-1][-1] = "true"
728     return (travel, tkey)
729
730 def get_travel(travel):
731     template = """    {{ // from {}: {}
732         .motion = {},
733         .cond = {},
734         .dest = {},
735         .nodwarves = {},
736         .stop = {},
737     }},
738 """
739     out = ""
740     for entry in travel:
741         out += template.format(*entry)
742     out = out[:-1] # trim trailing newline
743     return out
744
745 if __name__ == "__main__":
746     with open(yaml_name, "r") as f:
747         db = yaml.load(f)
748
749     locnames = [x[0] for x in db["locations"]]
750     msgnames = [el[0] for el in db["arbitrary_messages"]]
751     objnames = [el[0] for el in db["objects"]]
752     motionnames = [el[0] for el in db["motions"]]
753
754     (travel, tkey) = buildtravel(db["locations"],
755                                  db["objects"])
756     ignore = ""
757     c = c_template.format(
758         h_name,
759         get_arbitrary_messages(db["arbitrary_messages"]),
760         get_class_messages(db["classes"]),
761         get_turn_thresholds(db["turn_thresholds"]),
762         get_locations(db["locations"]),
763         get_objects(db["objects"]),
764         get_obituaries(db["obituaries"]),
765         get_hints(db["hints"], db["arbitrary_messages"]),
766         get_condbits(db["locations"]),
767         get_motions(db["motions"]),
768         get_specials(db["actions"]),
769         get_specials(db["specials"]),
770         bigdump(tkey),
771         get_travel(travel), 
772         ignore,
773     )
774
775     # 0-origin index of birds's last song.  Bird should
776     # die after player hears this.
777     deathbird = len(dict(db["objects"])["BIRD"]["sounds"]) - 1
778
779     h = h_template.format(
780         len(db["locations"])-1,
781         len(db["objects"])-1,
782         len(db["hints"]),
783         len(db["classes"])-1,
784         len(db["obituaries"]),
785         len(db["turn_thresholds"]),
786         len(db["motions"]),
787         len(db["actions"]),
788         len(db["specials"]),
789         len(travel),
790         len(tkey),
791         deathbird,
792         get_refs(db["arbitrary_messages"]),
793         get_refs(db["locations"]),
794         get_refs(db["objects"]),
795         get_refs(db["motions"]),
796         get_refs(db["actions"]),
797         get_refs(db["specials"]),
798         statedefines,
799     )
800
801     with open(h_name, "w") as hf:
802         hf.write(h)
803
804     with open(c_name, "w") as cf:
805         cf.write(c)
806
807 # end