Namespace splittiing to prune the maze graph. No eeffect on gameplay.
[open-adventure.git] / make_graph.py
1 #!/usr/bin/env python3
2
3 # Make a DOT graph of the dungeon
4 #
5 # Copyright (c) 2017 by Eric S. Raymond
6 # SPDX-License-Identifier: BSD-2-clause
7
8 import sys, yaml
9
10 def allalike(loc):
11     "Select out loci related to the Maze All Alike"
12     return (loc == "LOC_MISTWEST") or ("ALIKE" in loc) or ("MAZEEND" in loc) or ("STALACTITE" in loc)
13
14 def abbreviate(d):
15     m = {"NORTH":"N", "EAST":"E", "SOUTH":"S", "WEST":"W", "UPWAR":"U", "DOWN":"D"}
16     return m.get(d, d)
17
18 if __name__ == "__main__":
19     with open("adventure.yaml", "r") as f:
20         db = yaml.safe_load(f)
21
22     print("digraph G {")
23     for (loc, attrs) in db["locations"]:
24         if not allalike(loc):
25             continue
26         travel = attrs["travel"]
27         if len(travel) > 0:
28             for dest in travel:
29                 verbs = [abbreviate(x) for x in dest["verbs"]]
30                 if len(verbs) == 0:
31                     continue
32                 action = dest["action"]
33                 if action[0] == "goto":
34                     arc = "%s -> %s" % (loc[4:], action[1][4:])
35                     label=",".join(verbs).lower()
36                     if len(label) > 0:
37                         arc += ' [label="%s"]' % label
38                     print("    " + arc)
39     print("}")
40
41