# 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:
# 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
(184, 33, 1),
)
+def destdecode(dest):
+ "Decode a destinatio nnumber"
+ if dest <= 300:
+ return '["move", %s]' % locnames[dest]
+ elif dest <= 500:
+ return '["goto", %s]' % (dest - 300)
+ else:
+ return '["speak", %s]' % (msgnames[dest - 500])
+
def genline(loc):
attrs = []
sys.stdout.write(" travel: {\n")
for t in section3:
t = list(t)
- if t.pop(0) == loc:
- sys.stdout.write(" %s,\n" % t)
+ 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(" %s %s %s,\n" % (destdecode(dest), cond, t))
sys.stdout.write(" }\n")
db = yaml.load(fp)
fp.seek(0)
locnames = [el[0] for el in db["locations"]]
+ 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()