Specials excised from adventure.yaml
[open-adventure.git] / make_dungeon.py
index f8b3147e46c4fc65ad64ad40cc3e2c620bf342cb..03b5b04229fc60023a378208cc8525fb8873bb97 100755 (executable)
@@ -1,8 +1,7 @@
-#!/usr/bin/python3
+#!/usr/bin/env python
 
-# This is the new open-adventure dungeon generator. It'll eventually
-# replace the existing dungeon.c It currently outputs a .h and .c pair
-# for C code.
+# This is the open-adventure dungeon generator. It consumes a YAML description of
+# the dungeon and outputs a dungeon.h and dungeon.c pair of C code files.
 #
 # The nontrivial part of this is the compilation of the YAML for
 # movement rules to the travel array that's actually used by
@@ -106,13 +105,9 @@ typedef struct {{
 typedef struct {{
   const string_group_t words;
   const char* message;
+  const bool noaction;
 }} action_t;
 
-typedef struct {{
-  const string_group_t words;
-  const char* message;
-}} special_t;
-
 enum condtype_t {{cond_goto, cond_pct, cond_carry, cond_with, cond_not}};
 enum desttype_t {{dest_goto, dest_special, dest_speak}};
 
@@ -144,7 +139,6 @@ extern const hint_t hints[];
 extern long conditions[];
 extern const motion_t motions[];
 extern const action_t actions[];
-extern const special_t specials[];
 extern const travelop_t travel[];
 extern const long tkey[];
 extern const char *ignore;
@@ -155,9 +149,8 @@ extern const char *ignore;
 #define NCLASSES       {}
 #define NDEATHS                {}
 #define NTHRESHOLDS    {}
-#define NMOTIONS        {}
+#define NMOTIONS    {}
 #define NACTIONS       {}
-#define NSPECIALS       {}
 #define NTRAVEL                {}
 #define NKEYS          {}
 
@@ -183,10 +176,6 @@ enum action_refs {{
 {}
 }};
 
-enum special_refs {{
-{}
-}};
-
 /* State definitions */
 
 {}
@@ -237,10 +226,6 @@ const action_t actions[] = {{
 {}
 }};
 
-const special_t specials[] = {{
-{}
-}};
-
 const long tkey[] = {{{}}};
 
 const travelop_t travel[] = {{
@@ -385,8 +370,8 @@ def get_objects(obj):
             if labels:
                 global statedefines
                 statedefines += "/* States for %s */\n" % item[0]
-                for (i, label) in enumerate(labels):
-                    statedefines += "#define %s\t%d\n" % (label, i)
+                for (j, label) in enumerate(labels):
+                    statedefines += "#define %s\t%d\n" % (label, j)
                 statedefines += "\n"
         sounds_str = ""
         if attr.get("sounds") == None:
@@ -502,40 +487,12 @@ def get_actions(actions):
     template = """    {{
         .words = {},
         .message = {},
+        .noaction = {},
     }},
 """
     act_str = ""
     for action in actions:
         contents = action[1]
-        
-        if contents["words"] == None:
-            words_str = get_string_group([])
-        else:
-            words_str = get_string_group(contents["words"])
-
-        if contents["message"] == None:
-            message = "NO_MESSAGE"
-        else:
-            message = contents["message"]
-            
-        act_str += template.format(words_str, message)
-        global ignore
-        if contents.get("oldstyle", True) == False:
-            for word in contents["words"]:
-                if len(word) == 1:
-                    ignore += word.upper()
-    act_str = act_str[:-1] # trim trailing newline
-    return act_str
-
-def get_specials(specials):
-    template = """    {{
-        .words = {},
-        .message = {},
-    }},
-"""
-    spc_str = ""
-    for special in specials:
-        contents = special[1]
 
         if contents["words"] == None:
             words_str = get_string_group([])
@@ -547,14 +504,19 @@ def get_specials(specials):
         else:
             message = make_c_string(contents["message"])
 
-        spc_str += template.format(words_str, message)
+        if contents.get("noaction") == None:
+            noaction = "false"
+        else:
+            noaction = "true"
+
+        act_str += template.format(words_str, message, noaction)
         global ignore
         if contents.get("oldstyle", True) == False:
             for word in contents["words"]:
                 if len(word) == 1:
                     ignore += word.upper()
-    spc_str = spc_str[:-1] # trim trailing newline
-    return spc_str
+    act_str = act_str[:-1] # trim trailing newline
+    return act_str
 
 def bigdump(arr):
     out = ""
@@ -611,8 +573,8 @@ def buildtravel(locs, objs):
     # him to 22 if he's carrying object 10, and otherwise will go to 14.
     #          11      303008  49
     #          11      9       50
-    # This says that, from 11, 49 takes him to 8 unless game.prop(3)=0, in which
-    # case he goes to 9.  Verb 50 takes him to 9 regardless of game.prop(3).
+    # This says that, from 11, 49 takes him to 8 unless game.prop[3]=0, in which
+    # case he goes to 9.  Verb 50 takes him to 9 regardless of game.prop[3].
     ltravel = []
     verbmap = {}
     for i, motion in enumerate(db["motions"]):
@@ -627,7 +589,7 @@ def buildtravel(locs, objs):
             try:
                 return locnames.index(action[1])
             except ValueError:
-                sys.stderr.write("dungeon: unknown location %s in goto clause of %s\n" % (cond[1], name))
+                sys.stderr.write("dungeon: unknown location %s in goto clause of %s\n" % (action[1], name))
         elif action[0] == "special":
             return 300 + action[1]
         elif action[0] == "speak":
@@ -689,7 +651,7 @@ def buildtravel(locs, objs):
                 tt.append(dest)
                 tt += [motionnames[verbmap[e]].upper() for e in rule["verbs"]]
                 if not rule["verbs"]:
-                    tt.append(1)
+                    tt.append(1)       # Magic dummy entry for null rules
                 ltravel.append(tuple(tt))
 
     # At this point the ltravel data is in the Section 3
@@ -798,8 +760,7 @@ if __name__ == "__main__":
         get_hints(db["hints"], db["arbitrary_messages"]),
         get_condbits(db["locations"]),
         get_motions(db["motions"]),
-        get_specials(db["actions"]),
-        get_specials(db["specials"]),
+        get_actions(db["actions"]),
         bigdump(tkey),
         get_travel(travel), 
         ignore,
@@ -818,7 +779,6 @@ if __name__ == "__main__":
         len(db["turn_thresholds"]),
         len(db["motions"]),
         len(db["actions"]),
-        len(db["specials"]),
         len(travel),
         len(tkey),
         deathbird,
@@ -827,7 +787,6 @@ if __name__ == "__main__":
         get_refs(db["objects"]),
         get_refs(db["motions"]),
         get_refs(db["actions"]),
-        get_refs(db["specials"]),
         statedefines,
     )