Removed advent.info and added to .gitignore
[open-adventure.git] / travel.py
index 6e7a8f0dd7a0fc51393e019be4734d70880a5acc..a3529386307527ca7be6fe4da259d385002d6602 100755 (executable)
--- a/travel.py
+++ b/travel.py
 #              If M=100        unconditional, but forbidden to dwarves.
 #              If 100<M<=200   he must be carrying object M-100.
 #              If 200<M<=300   must be carrying or in same room as M-200.
-#              If 300<M<=400   game.prop(M % 100) must#not* be 0.
-#              If 400<M<=500   game.prop(M % 100) must#not* be 1.
-#              If 500<M<=600   game.prop(M % 100) must#not* be 2, etc.
-#      If the condition (if any) is not met, then the next#different*
-#      "destination" value is used (unless it fails to meet#its* conditions,
+#              If 300<M<=400   game.prop(M % 100) must *not* be 0.
+#              If 400<M<=500   game.prop(M % 100) must *not* be 1.
+#              If 500<M<=600   game.prop(M % 100) must *not* be 2, etc.
+#      If the condition (if any) is not met, then the next different
+#      "destination" value is used (unless it fails to meet *its* conditions,
 #      in which case the next is found, etc.).  Typically, the next dest will
 #      be for one of the same verbs, so that its only use is as the alternate
 #      destination for those verbs.  For instance:
@@ -42,6 +42,9 @@
 #      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).
 #
+# In addition, it looks as though the action verb value 1 is a sentinel used
+# when a table entry would have no motions at all in it.
+#
 import sys, yaml
 
 # This is the original travel table from section 3 of adventure.text
@@ -671,22 +674,70 @@ section3 = (
     (184, 33, 1),
     )
 
+def destdecode(dest):
+    "Decode a destinatio nnumber"
+    if dest <= 300:
+        return '["goto", %s]' % locnames[dest]
+    elif dest <= 500:
+        return '["special", %s]' % (dest - 300)
+    else:
+        return '["speak", %s]' % (msgnames[dest - 500])
+
+def conddecode(cond):
+    #          If M=0          it's unconditional.
+    #          If 0<M<100      it is done with M% probability.
+    #          If M=100        unconditional, but forbidden to dwarves.
+    #          If 100<M<=200   he must be carrying object M-100.
+    #          If 200<M<=300   must be carrying or in same room as M-200.
+    #          If 300<M<=400   game.prop(M % 100) must *not* be 0.
+    #          If 400<M<=500   game.prop(M % 100) must *not* be 1.
+    #          If 500<M<=600   game.prop(M % 100) must *not* be 2, etc.
+    if cond == 0:
+        return ""
+    elif cond < 100:
+        return "cond: [pct %d], " % cond
+    elif cond <= 200:
+        return "cond: [carry %s], " % objnames[cond-100]    
+    elif cond <= 300:
+        return "cond: [with %s], " % objnames[cond-200]
+    else:
+        return "cond: [not %s %d], " % (objnames[cond % 100], (cond - 300) // 100)
+
 def genline(loc):
     attrs = []
-    sys.stdout.write("    travel: {\n")
+    sys.stdout.write("    travel: [\n")
     for t in section3:
         t = list(t)
-        if t.pop(0) == loc:
-            sys.stdout.write("       %s,\n" % t)
-    sys.stdout.write("    }\n")
-        
-    
+        src = t.pop(0)
+        if src == loc:
+            dest = t.pop(0)
+            try:
+                if t.index(1) == len(t) - 1:
+                    t.pop()
+                else:
+                    sys.stderr.write("%s (%d): action value 1 in unexpected place\n" %\
+                                     (locnames[loc], loc))
+                    sys.exit(1)
+            except ValueError:
+                pass
+            cond = dest // 1000
+            dest = dest % 1000
+            t = [verbs[e] for e in t]
+            sys.stdout.write("      {verbs: %s, %saction: %s},\n" %\
+                             (t, conddecode(cond), destdecode(dest)))
+    sys.stdout.write("    ]\n")
 
 if __name__ == "__main__":
     with open("adventure.yaml", "r") as fp:
         db = yaml.load(fp)
-        fp.seek(0)
+        fp.seek(0) 
         locnames = [el[0] for el in db["locations"]]
+        objnames = [el[0] for el in db["object_descriptions"]]
+        msgnames = [el[0] for el in db["arbitrary_messages"]]
+        verbs = {}
+        for entry in db["vocabulary"]:
+            if entry["type"] == "motion" and entry["value"] not in verbs:
+                verbs[entry["value"]] = entry["word"]
         ln = -1
         while True:
             line = fp.readline()