3 # Enhance adventure.yaml entries with explicit properties based on Section 3
6 # This script is meant to be gotten right, used once, and then discarded.
7 # We'll leave a copy in the repository history for reference
9 # When in doubt, make the code dumber and the data smarter.
11 # Here's the original format description:
13 # Section 3: Travel table. Each line contains a location number (X), a second
14 # location number (Y), and a list of motion numbers (see section 4).
15 # each motion represents a verb which will go to Y if currently at X.
16 # Y, in turn, is interpreted as follows. Let M=Y/1000, N=Y mod 1000.
17 # If N<=300 it is the location to go to.
18 # If 300<N<=500 N-300 is used in a computed goto to
19 # a section of special code.
20 # If N>500 message N-500 from section 6 is printed,
21 # and he stays wherever he is.
22 # Meanwhile, M specifies the conditions on the motion.
23 # If M=0 it's unconditional.
24 # If 0<M<100 it is done with M% probability.
25 # If M=100 unconditional, but forbidden to dwarves.
26 # If 100<M<=200 he must be carrying object M-100.
27 # If 200<M<=300 must be carrying or in same room as M-200.
28 # If 300<M<=400 game.prop(M % 100) must *not* be 0.
29 # If 400<M<=500 game.prop(M % 100) must *not* be 1.
30 # If 500<M<=600 game.prop(M % 100) must *not* be 2, etc.
31 # If the condition (if any) is not met, then the next different
32 # "destination" value is used (unless it fails to meet *its* conditions,
33 # in which case the next is found, etc.). Typically, the next dest will
34 # be for one of the same verbs, so that its only use is as the alternate
35 # destination for those verbs. For instance:
36 # 15 110022 29 31 34 35 23 43
38 # This says that, from loc 15, any of the verbs 29, 31, etc., will take
39 # him to 22 if he's carrying object 10, and otherwise will go to 14.
42 # This says that, from 11, 49 takes him to 8 unless game.prop(3)=0, in which
43 # case he goes to 9. Verb 50 takes him to 9 regardless of game.prop(3).
47 # This is the original travel table from section 3 of adventure.text
50 (1, 3, 3, 12, 19, 43),
51 (1, 4, 5, 13, 14, 46, 30),
81 (7, 8, 5, 16, 46, 63),
82 (7, 595, 60, 14, 30, 19, 3),
88 (8, 303009, 3, 19, 30),
92 (9, 10, 17, 18, 19, 44),
95 (10, 9, 11, 20, 21, 43),
96 (10, 11, 19, 22, 44, 51),
100 (11, 10, 17, 18, 23, 24, 43),
101 (11, 12, 25, 19, 29, 44),
106 (12, 11, 30, 43, 51),
107 (12, 13, 19, 29, 44),
113 (13, 14, 23, 31, 44),
118 (14, 150020, 30, 31, 34),
123 (15, 19, 10, 30, 45),
124 (15, 150022, 29, 31, 34, 35, 23, 43),
131 (17, 412597, 41, 42, 44, 69),
133 (18, 15, 38, 11, 45),
134 (19, 15, 10, 29, 43),
135 (19, 311028, 45, 37),
136 (19, 311029, 46, 36),
156 (27, 412597, 41, 42, 43, 69),
160 (28, 19, 38, 11, 46),
163 (29, 19, 38, 11, 45),
164 (30, 19, 38, 11, 43),
171 (33, 34, 43, 53, 54),
184 (37, 38, 30, 31, 56),
185 (38, 37, 56, 29, 11),
186 (38, 595, 60, 14, 30, 4, 5, 3, 19),
188 (39, 64, 30, 52, 58),
191 (41, 42, 46, 29, 23, 56),
247 (60, 41, 43, 29, 17),
249 (60, 62, 45, 30, 52),
258 (64, 39, 29, 56, 59),
302 (73, 72, 46, 17, 11),
330 (88, 25, 30, 56, 43),
335 (91, 95, 45, 73, 23),
340 (93, 92, 46, 27, 11),
341 (94, 92, 46, 27, 23),
342 (94, 309095, 45, 3, 73),
350 (97, 98, 29, 45, 73),
356 (100, 301, 44, 23, 11),
361 (101, 100, 46, 71, 11),
362 (102, 103, 30, 74, 11),
385 (108, 95556, 43, 45, 46, 47, 48, 49, 50, 29, 30),
393 (111, 40050, 30, 39, 56),
407 (113, 445552, 45, 42, 69),
414 (117, 233660, 41, 42, 69, 47),
428 (122, 233660, 41, 42, 69, 49),
440 (124, 128, 48, 37, 30),
446 (126, 125, 46, 23, 11),
450 (127, 125, 44, 11, 17),
453 (128, 124, 45, 29, 15),
454 (128, 129, 46, 30, 40),
458 (129, 130, 43, 19, 40, 3),
648 (169, 445552, 46, 42, 69),
650 (169, 170, 50, 29, 11),
664 (177, 176, 49, 11, 17),
674 def destdecode(dest):
675 "Decode a destinatio nnumber"
677 return '["move", %s]' % locnames[dest]
679 return '["goto", %s]' % (dest - 300)
681 return '["speak", %s]' % (msgnames[dest - 500])
685 sys.stdout.write(" travel: {\n")
693 print("cond %s, dest %s, words: %s" % (cond, dest, t))
694 t = [verbs[e] for e in t]
695 sys.stdout.write(" %s %s %s,\n" % (destdecode(dest), cond, t))
696 sys.stdout.write(" }\n")
700 if __name__ == "__main__":
701 with open("adventure.yaml", "r") as fp:
704 locnames = [el[0] for el in db["locations"]]
705 msgnames = [el[0] for el in db["arbitrary_messages"]]
707 for entry in db["vocabulary"]:
708 if entry["type"] == "motion" and entry["value"] not in verbs:
709 verbs[entry["value"]] = entry["word"]
716 if line.startswith("- LOC"):
720 sys.stdout.write(line)