X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=make_dungeon.py;h=03b5b04229fc60023a378208cc8525fb8873bb97;hp=576601d675f3ee4142ef37962082e306e1d40c11;hb=e8a627f964a8337caf0c71dd87b1d7533f489f57;hpb=659f797d8adb0b3894f042ca11372196bff84e9d diff --git a/make_dungeon.py b/make_dungeon.py index 576601d..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 @@ -746,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"]) @@ -762,12 +761,15 @@ 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, ) + # 0-origin index of birds's last song. Bird should + # die after player hears this. + deathbird = len(dict(db["objects"])["BIRD"]["sounds"]) - 1 + h = h_template.format( len(db["locations"])-1, len(db["objects"])-1, @@ -777,15 +779,14 @@ if __name__ == "__main__": len(db["turn_thresholds"]), len(db["motions"]), len(db["actions"]), - len(db["specials"]), len(travel), len(tkey), + deathbird, get_refs(db["arbitrary_messages"]), get_refs(db["locations"]), get_refs(db["objects"]), get_refs(db["motions"]), get_refs(db["actions"]), - get_refs(db["specials"]), statedefines, )