X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=make_dungeon.py;h=03b5b04229fc60023a378208cc8525fb8873bb97;hp=4e3c88e219284af62a62de64397d3c7bbfab4f3e;hb=e8a627f964a8337caf0c71dd87b1d7533f489f57;hpb=7be7ac9406512644886fbf4a99d16e1b4f7cefc3 diff --git a/make_dungeon.py b/make_dungeon.py index 4e3c88e..03b5b04 100755 --- a/make_dungeon.py +++ b/make_dungeon.py @@ -1,48 +1,11 @@ -#!/usr/bin/python3 +#!/usr/bin/env python -# This is the new open-adventure dungeon generator. It'll eventually -# replace the existing dungeon.c It currently outputs a .h and .c pair -# for C code. +# This is the open-adventure dungeon generator. It consumes a YAML description of +# the dungeon and outputs a dungeon.h and dungeon.c pair of C code files. # # The nontrivial part of this is the compilation of the YAML for # movement rules to the travel array that's actually used by -# playermove(). This program first compiles the YAML to a form -# identical to the data in section 3 of the old adventure.text file, -# then a second stage unpacks that data into the travel array. -# -# Here are the rules of the intermediate form: -# -# Each row of data 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 300500 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 0500 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 500: + desttype = "dest_speak"; + destval = msgnames[dest - 500] + else: + desttype = "dest_special"; + destval = locnames[dest - 300] + travel.append([len(tkey)-1, + locnames[len(tkey)-1], + rule.pop(0), + condtype, + condarg1, + condarg2, + desttype, + destval, + "true" if nodwarves else "false", + "false"]) + travel[-1][-1] = "true" return (travel, tkey) def get_travel(travel): - template = """ {{ + template = """ {{ // from {}: {} .motion = {}, - .cond = {}, - .dest = {}, + .condtype = {}, + .condarg1 = {}, + .condarg2 = {}, + .desttype = {}, + .destval = {}, .nodwarves = {}, .stop = {}, }}, """ out = "" for entry in travel: - out += template.format(*entry).lower() + out += template.format(*entry) out = out[:-1] # trim trailing newline return out @@ -748,6 +744,7 @@ if __name__ == "__main__": locnames = [x[0] for x in db["locations"]] msgnames = [el[0] for el in db["arbitrary_messages"]] objnames = [el[0] for el in db["objects"]] + motionnames = [el[0] for el in db["motions"]] (travel, tkey) = buildtravel(db["locations"], db["objects"]) @@ -764,7 +761,6 @@ if __name__ == "__main__": get_condbits(db["locations"]), get_motions(db["motions"]), get_actions(db["actions"]), - get_specials(db["specials"]), bigdump(tkey), get_travel(travel), ignore, @@ -783,7 +779,6 @@ if __name__ == "__main__": len(db["turn_thresholds"]), len(db["motions"]), len(db["actions"]), - len(db["specials"]), len(travel), len(tkey), deathbird, @@ -792,7 +787,6 @@ if __name__ == "__main__": get_refs(db["objects"]), get_refs(db["motions"]), get_refs(db["actions"]), - get_refs(db["specials"]), statedefines, )