+++ /dev/null
-#!/usr/bin/env python3
-#
-# Enhance adventure.yaml entries with explicit properties based on Section 3
-# of adventure.text.
-#
-# This script is meant to be gotten right, used once, and then discarded.
-# We'll leave a copy in the repository history for reference
-#
-# When in doubt, make the code dumber and the data smarter.
-#
-# Here's the original format description:
-#
-# Section 3: Travel table. Each line contains a location number (X), a second
-# location number (Y), and a list of motion numbers (see section 4).
-# each motion represents a verb which will go to Y if currently at X.
-# Y, in turn, is interpreted as follows. Let M=Y/1000, N=Y mod 1000.
-# If N<=300 it is the location to go to.
-# If 300<N<=500 N-300 is used in a computed goto to
-# a section of special code.
-# If N>500 message N-500 from section 6 is printed,
-# and he stays wherever he is.
-# Meanwhile, M specifies the conditions on the motion.
-# 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 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:
-# 15 110022 29 31 34 35 23 43
-# 15 14 29
-# This says that, from loc 15, any of the verbs 29, 31, etc., will take
-# 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).
-#
-# 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
-section3 = (
- (1, 2, 2, 44, 29),
- (1, 3, 3, 12, 19, 43),
- (1, 4, 5, 13, 14, 46, 30),
- (1, 145, 6, 45),
- (1, 8, 63),
- (2, 1, 12, 43),
- (2, 5, 44),
- (2, 164, 45),
- (2, 157, 46, 6),
- (2, 580, 30),
- (3, 1, 11, 32, 44),
- (3, 179, 62),
- (3, 181, 65),
- (3, 79, 5, 14),
- (4, 1, 4, 12, 45),
- (4, 150, 43, 6),
- (4, 156, 44),
- (4, 7, 5, 46, 30),
- (4, 8, 63),
- (4, 745, 14),
- (5, 2, 2, 43, 29),
- (5, 1, 12),
- (5, 158, 46, 6),
- (5, 159, 44),
- (5, 165, 45),
- (6, 161, 46, 6),
- (6, 163, 43),
- (6, 21, 39),
- (7, 1, 12),
- (7, 4, 4, 45),
- (7, 150, 43, 6),
- (7, 154, 44),
- (7, 8, 5, 16, 46, 63),
- (7, 595, 60, 14, 30, 19, 3),
- (8, 151, 43, 6),
- (8, 154, 46),
- (8, 153, 44),
- (8, 1, 12),
- (8, 7, 4, 13, 45),
- (8, 303009, 3, 19, 30),
- (8, 593, 3),
- (9, 303008, 11, 29),
- (9, 593, 11),
- (9, 10, 17, 18, 19, 44),
- (9, 14, 31),
- (9, 11, 51),
- (10, 9, 11, 20, 21, 43),
- (10, 11, 19, 22, 44, 51),
- (10, 14, 31),
- (11, 303008, 63),
- (11, 9, 64),
- (11, 10, 17, 18, 23, 24, 43),
- (11, 12, 25, 19, 29, 44),
- (11, 180, 62),
- (11, 14, 31),
- (12, 303008, 63),
- (12, 9, 64),
- (12, 11, 30, 43, 51),
- (12, 13, 19, 29, 44),
- (12, 14, 31),
- (13, 303008, 63),
- (13, 9, 64),
- (13, 11, 51),
- (13, 12, 25, 43),
- (13, 14, 23, 31, 44),
- (14, 303008, 63),
- (14, 9, 64),
- (14, 11, 51),
- (14, 13, 23, 43),
- (14, 150020, 30, 31, 34),
- (14, 15, 30),
- (14, 16, 33, 44),
- (15, 18, 36, 46),
- (15, 17, 7, 38, 44),
- (15, 19, 10, 30, 45),
- (15, 150022, 29, 31, 34, 35, 23, 43),
- (15, 14, 29),
- (15, 34, 55),
- (16, 14, 1),
- (17, 15, 38, 43),
- (17, 312596, 39),
- (17, 412021, 7),
- (17, 412597, 41, 42, 44, 69),
- (17, 27, 41),
- (18, 15, 38, 11, 45),
- (19, 15, 10, 29, 43),
- (19, 311028, 45, 37),
- (19, 311029, 46, 36),
- (19, 311030, 44, 7),
- (19, 32, 45),
- (19, 35074, 49),
- (19, 211032, 49),
- (19, 74, 66),
- (20, 0, 1),
- (21, 0, 1),
- (22, 15, 1),
- (23, 67, 43, 42),
- (23, 68, 44, 61),
- (23, 25, 30, 31),
- (23, 648, 52),
- (24, 67, 29, 11),
- (25, 23, 29, 11),
- (25, 524031, 56),
- (25, 26, 56),
- (26, 88, 1),
- (27, 312596, 39),
- (27, 412021, 7),
- (27, 412597, 41, 42, 43, 69),
- (27, 17, 41),
- (27, 40, 45),
- (27, 41, 44),
- (28, 19, 38, 11, 46),
- (28, 33, 45, 55),
- (28, 36, 30, 52),
- (29, 19, 38, 11, 45),
- (30, 19, 38, 11, 43),
- (30, 62, 44, 29),
- (31, 424089, 1),
- (31, 90, 1),
- (32, 19, 1),
- (33, 182, 65),
- (33, 28, 46),
- (33, 34, 43, 53, 54),
- (33, 35, 44),
- (33, 159302, 71),
- (33, 183, 71),
- (34, 33, 30, 55),
- (34, 15, 29),
- (35, 33, 43, 55),
- (35, 20, 39),
- (36, 37, 43, 17),
- (36, 28, 29, 52),
- (36, 39, 44),
- (36, 65, 70),
- (37, 36, 44, 17),
- (37, 38, 30, 31, 56),
- (38, 37, 56, 29, 11),
- (38, 595, 60, 14, 30, 4, 5, 3, 19),
- (39, 36, 43, 23),
- (39, 64, 30, 52, 58),
- (39, 65, 70),
- (40, 41, 1),
- (41, 42, 46, 29, 23, 56),
- (41, 27, 43),
- (41, 59, 45),
- (41, 60, 44, 17),
- (42, 41, 29),
- (42, 42, 45),
- (42, 43, 43),
- (42, 45, 46),
- (42, 80, 44),
- (43, 42, 44),
- (43, 44, 46),
- (43, 45, 43),
- (44, 43, 43),
- (44, 48, 30),
- (44, 50, 46),
- (44, 82, 45),
- (45, 42, 44),
- (45, 43, 45),
- (45, 46, 43),
- (45, 47, 46),
- (45, 87, 29, 30),
- (46, 45, 44, 11),
- (47, 45, 43, 11),
- (48, 44, 29, 11),
- (49, 50, 43),
- (49, 51, 44),
- (50, 44, 43),
- (50, 49, 44),
- (50, 51, 30),
- (50, 52, 46),
- (51, 49, 44),
- (51, 50, 29),
- (51, 52, 43),
- (51, 53, 46),
- (52, 50, 44),
- (52, 51, 43),
- (52, 52, 46),
- (52, 53, 29),
- (52, 55, 45),
- (52, 86, 30),
- (53, 51, 44),
- (53, 52, 45),
- (53, 54, 46),
- (54, 53, 44, 11),
- (55, 52, 44),
- (55, 55, 45),
- (55, 56, 30),
- (55, 57, 43),
- (56, 55, 29, 11),
- (57, 13, 30, 56),
- (57, 55, 44),
- (57, 58, 46),
- (57, 83, 45),
- (57, 84, 43),
- (58, 57, 43, 11),
- (59, 27, 1),
- (60, 41, 43, 29, 17),
- (60, 61, 44),
- (60, 62, 45, 30, 52),
- (61, 60, 43),
- (61, 62, 45),
- (61, 100107, 46),
- (62, 60, 44),
- (62, 63, 45),
- (62, 30, 43),
- (62, 61, 46),
- (63, 62, 46, 11),
- (64, 39, 29, 56, 59),
- (64, 65, 44, 70),
- (64, 103, 45, 74),
- (64, 106, 43),
- (65, 64, 43),
- (65, 66, 44),
- (65, 65556, 46),
- (65, 68, 61),
- (65, 60556, 29),
- (65, 70070, 29),
- (65, 39, 29),
- (65, 50556, 45),
- (65, 75072, 45),
- (65, 71, 45),
- (65, 65556, 30),
- (65, 106, 30),
- (66, 65, 47),
- (66, 67, 44),
- (66, 80556, 46),
- (66, 77, 25),
- (66, 96, 43),
- (66, 50556, 50),
- (66, 97, 72),
- (67, 66, 43),
- (67, 23, 44, 42),
- (67, 24, 30, 31),
- (68, 23, 46),
- (68, 69, 29, 56),
- (68, 65, 45),
- (69, 68, 30, 61),
- (69, 331120, 46),
- (69, 119, 46),
- (69, 109, 45),
- (69, 113, 75),
- (70, 71, 45),
- (70, 65, 30, 23),
- (70, 111, 46),
- (71, 65, 48),
- (71, 70, 46),
- (71, 110, 45),
- (72, 65, 70),
- (72, 118, 49),
- (72, 73, 45),
- (72, 97, 48, 72),
- (73, 72, 46, 17, 11),
- (74, 19, 43),
- (74, 331120, 44),
- (74, 121, 44),
- (74, 75, 30),
- (75, 76, 46),
- (75, 77, 45),
- (76, 75, 45),
- (77, 75, 43),
- (77, 78, 44),
- (77, 66, 45, 17),
- (78, 77, 46),
- (79, 3, 1),
- (80, 42, 45),
- (80, 80, 44),
- (80, 80, 46),
- (80, 81, 43),
- (81, 80, 44, 11),
- (82, 44, 46, 11),
- (83, 57, 46),
- (83, 84, 43),
- (83, 85, 44),
- (84, 57, 45),
- (84, 83, 44),
- (84, 114, 50),
- (85, 83, 43, 11),
- (86, 52, 29, 11),
- (87, 45, 29, 30),
- (88, 25, 30, 56, 43),
- (88, 20, 39),
- (88, 92, 44, 27),
- (89, 25, 1),
- (90, 23, 1),
- (91, 95, 45, 73, 23),
- (91, 72, 30, 56),
- (92, 88, 46),
- (92, 93, 43),
- (92, 94, 45),
- (93, 92, 46, 27, 11),
- (94, 92, 46, 27, 23),
- (94, 309095, 45, 3, 73),
- (94, 611, 45),
- (95, 94, 46, 11),
- (95, 92, 27),
- (95, 91, 44),
- (96, 66, 44, 11),
- (97, 66, 48),
- (97, 72, 44, 17),
- (97, 98, 29, 45, 73),
- (98, 97, 46, 72),
- (98, 99, 44),
- (99, 98, 50, 73),
- (99, 301, 43, 23),
- (99, 100, 43),
- (100, 301, 44, 23, 11),
- (100, 99, 44),
- (100, 159302, 71),
- (100, 184, 71),
- (100, 101, 47, 22),
- (101, 100, 46, 71, 11),
- (102, 103, 30, 74, 11),
- (103, 102, 29, 38),
- (103, 104, 30),
- (103, 114618, 46),
- (103, 115619, 46),
- (103, 64, 46),
- (104, 103, 29, 74),
- (104, 105, 30),
- (105, 104, 29, 11),
- (105, 103, 74),
- (106, 64, 29),
- (106, 65, 44),
- (106, 108, 43),
- (107, 131, 46),
- (107, 132, 49),
- (107, 133, 47),
- (107, 134, 48),
- (107, 135, 29),
- (107, 136, 50),
- (107, 137, 43),
- (107, 138, 44),
- (107, 139, 45),
- (107, 61, 30),
- (108, 95556, 43, 45, 46, 47, 48, 49, 50, 29, 30),
- (108, 106, 43),
- (108, 626, 44),
- (109, 69, 46),
- (109, 113, 45, 75),
- (110, 71, 44),
- (110, 20, 39),
- (111, 70, 45),
- (111, 40050, 30, 39, 56),
- (111, 50053, 30),
- (111, 45, 30),
- (112, 131, 49),
- (112, 132, 45),
- (112, 133, 43),
- (112, 134, 50),
- (112, 135, 48),
- (112, 136, 47),
- (112, 137, 44),
- (112, 138, 30),
- (112, 139, 29),
- (112, 140, 46),
- (113, 109, 46, 11),
- (113, 445552, 45, 42, 69),
- (113, 168, 45),
- (114, 84, 48),
- (115, 116, 49),
- (116, 115, 47),
- (116, 593, 30),
- (117, 118, 49),
- (117, 233660, 41, 42, 69, 47),
- (117, 332661, 41),
- (117, 303, 41),
- (117, 332021, 39),
- (117, 596, 39),
- (118, 72, 30),
- (118, 117, 29),
- (119, 69, 45, 11),
- (119, 653, 43, 7),
- (120, 69, 45),
- (120, 74, 43),
- (121, 74, 43, 11),
- (121, 653, 45, 7),
- (122, 123, 47),
- (122, 233660, 41, 42, 69, 49),
- (122, 303, 41),
- (122, 596, 39),
- (122, 124, 15),
- (122, 126, 28),
- (122, 129, 40),
- (123, 122, 44),
- (123, 124, 43, 15),
- (123, 126, 28),
- (123, 129, 40),
- (124, 123, 44),
- (124, 125, 47, 36),
- (124, 128, 48, 37, 30),
- (124, 126, 28),
- (124, 129, 40),
- (125, 124, 46, 15),
- (125, 126, 45, 28),
- (125, 127, 43, 17),
- (126, 125, 46, 23, 11),
- (126, 124, 15),
- (126, 610, 30),
- (126, 178, 39),
- (127, 125, 44, 11, 17),
- (127, 124, 15),
- (127, 126, 28),
- (128, 124, 45, 29, 15),
- (128, 129, 46, 30, 40),
- (128, 126, 28),
- (129, 128, 44, 29),
- (129, 124, 15),
- (129, 130, 43, 19, 40, 3),
- (129, 126, 28),
- (130, 129, 44, 11),
- (130, 124, 15),
- (130, 126, 28),
- (131, 107, 44),
- (131, 132, 48),
- (131, 133, 50),
- (131, 134, 49),
- (131, 135, 47),
- (131, 136, 29),
- (131, 137, 30),
- (131, 138, 45),
- (131, 139, 46),
- (131, 112, 43),
- (132, 107, 50),
- (132, 131, 29),
- (132, 133, 45),
- (132, 134, 46),
- (132, 135, 44),
- (132, 136, 49),
- (132, 137, 47),
- (132, 138, 43),
- (132, 139, 30),
- (132, 112, 48),
- (133, 107, 29),
- (133, 131, 30),
- (133, 132, 44),
- (133, 134, 47),
- (133, 135, 49),
- (133, 136, 43),
- (133, 137, 45),
- (133, 138, 50),
- (133, 139, 48),
- (133, 112, 46),
- (134, 107, 47),
- (134, 131, 45),
- (134, 132, 50),
- (134, 133, 48),
- (134, 135, 43),
- (134, 136, 30),
- (134, 137, 46),
- (134, 138, 29),
- (134, 139, 44),
- (134, 112, 49),
- (135, 107, 45),
- (135, 131, 48),
- (135, 132, 30),
- (135, 133, 46),
- (135, 134, 43),
- (135, 136, 44),
- (135, 137, 49),
- (135, 138, 47),
- (135, 139, 50),
- (135, 112, 29),
- (136, 107, 43),
- (136, 131, 44),
- (136, 132, 29),
- (136, 133, 49),
- (136, 134, 30),
- (136, 135, 46),
- (136, 137, 50),
- (136, 138, 48),
- (136, 139, 47),
- (136, 112, 45),
- (137, 107, 48),
- (137, 131, 47),
- (137, 132, 46),
- (137, 133, 30),
- (137, 134, 29),
- (137, 135, 50),
- (137, 136, 45),
- (137, 138, 49),
- (137, 139, 43),
- (137, 112, 44),
- (138, 107, 30),
- (138, 131, 43),
- (138, 132, 47),
- (138, 133, 29),
- (138, 134, 44),
- (138, 135, 45),
- (138, 136, 46),
- (138, 137, 48),
- (138, 139, 49),
- (138, 112, 50),
- (139, 107, 49),
- (139, 131, 50),
- (139, 132, 43),
- (139, 133, 44),
- (139, 134, 45),
- (139, 135, 30),
- (139, 136, 48),
- (139, 137, 29),
- (139, 138, 46),
- (139, 112, 47),
- (140, 112, 45, 11),
- (140, 338141, 46),
- (140, 142, 46),
- (141, 140, 45),
- (141, 143, 46),
- (142, 140, 1),
- (143, 141, 44),
- (143, 241560, 45),
- (143, 144, 45),
- (144, 143, 46, 11),
- (145, 1, 43),
- (145, 157, 44),
- (145, 146, 45),
- (145, 147, 46),
- (146, 145, 43),
- (146, 163, 44),
- (146, 147, 45),
- (146, 162, 46),
- (147, 148, 43, 44),
- (147, 146, 45),
- (147, 145, 46),
- (148, 147, 43, 45),
- (148, 149, 44, 46),
- (149, 148, 43, 45),
- (149, 151, 44),
- (149, 150, 46),
- (150, 149, 43),
- (150, 151, 44),
- (150, 4, 45),
- (150, 7, 46),
- (151, 149, 43),
- (151, 150, 44),
- (151, 8, 45),
- (151, 152, 46),
- (152, 153, 43),
- (152, 155, 44),
- (152, 166, 45),
- (152, 151, 46),
- (153, 155, 43),
- (153, 152, 44),
- (153, 154, 45),
- (153, 8, 46),
- (154, 7, 43),
- (154, 155, 44),
- (154, 153, 45),
- (154, 8, 46),
- (155, 154, 43),
- (155, 152, 44),
- (155, 166, 45),
- (155, 153, 46),
- (156, 157, 43),
- (156, 158, 44),
- (156, 166, 45),
- (156, 4, 46),
- (157, 145, 43),
- (157, 156, 44),
- (157, 164, 45),
- (157, 2, 46),
- (158, 5, 43),
- (158, 160, 44),
- (158, 159, 45),
- (158, 156, 46),
- (159, 160, 43),
- (159, 166, 44),
- (159, 5, 45),
- (159, 158, 46),
- (160, 161, 43, 45),
- (160, 158, 44),
- (160, 159, 46),
- (161, 162, 43),
- (161, 160, 44, 46),
- (161, 6, 45),
- (162, 163, 43),
- (162, 161, 44),
- (162, 146, 45),
- (162, 165, 46),
- (163, 146, 43),
- (163, 162, 44),
- (163, 6, 45),
- (163, 164, 46),
- (164, 2, 43),
- (164, 165, 44),
- (164, 163, 45),
- (164, 157, 46),
- (165, 164, 43),
- (165, 5, 44),
- (165, 162, 45),
- (165, 165, 46),
- (166, 152, 43),
- (166, 155, 44),
- (166, 159, 45),
- (166, 156, 46),
- (167, 21, 39),
- (168, 169, 45),
- (168, 113, 46),
- (169, 445552, 46, 42, 69),
- (169, 168, 46),
- (169, 170, 50, 29, 11),
- (170, 171, 29, 50),
- (170, 169, 30, 48),
- (171, 170, 30, 48),
- (171, 172, 29, 50),
- (172, 171, 30, 48),
- (172, 173, 29, 56),
- (173, 172, 30),
- (173, 146175, 29),
- (173, 174, 29),
- (174, 0, 1),
- (175, 176, 1),
- (176, 173, 56, 30),
- (176, 177, 47, 17),
- (177, 176, 49, 11, 17),
- (178, 0, 1),
- (179, 11, 1),
- (180, 3, 1),
- (181, 33, 1),
- (182, 3, 1),
- (183, 100, 1),
- (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")
- for t in section3:
- t = list(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(" {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)
- 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()
- if not line:
- break
- if line.startswith("- LOC"):
- if ln > -1:
- genline(ln)
- ln += 1
- sys.stdout.write(line)
-
-# end