Implement and document new state-label syntax.

This commit is contained in:
Eric S. Raymond 2017-07-03 20:27:56 -04:00
parent 217f05b28b
commit 659f797d8a
2 changed files with 99 additions and 74 deletions

View file

@ -83,12 +83,10 @@
# #
# objects: Objects have attributes as follows... # objects: Objects have attributes as follows...
# inventory: A description for use in the inventory command. # inventory: A description for use in the inventory command.
# states: A list of state labels for states from 0 up. Each
# becomes a #define, and is also a state label that
# can be used in travel-rule 'not' clauses.
# descriptions: Messages describing the object in different states. # descriptions: Messages describing the object in different states.
# If a state message is a tuple then the first element
# is made the name of a #define visible to the code for
# the associated state, numbered from zero upwards; it
# is also a state label that can be used in travel-rule
# 'not' clauses.
# changes: State-change messages to be emitted whenever the object # changes: State-change messages to be emitted whenever the object
# *changes* to the (0-origin) state that is the index of the # *changes* to the (0-origin) state that is the index of the
# message in this array. # message in this array.
@ -3212,9 +3210,10 @@ objects: !!omap
words: ['lamp', 'lante'] words: ['lamp', 'lante']
inventory: 'Brass lantern' inventory: 'Brass lantern'
locations: LOC_BUILDING locations: LOC_BUILDING
states: [LAMP_DARK, LAMP_BRIGHT]
descriptions: descriptions:
- [LAMP_DARK, 'There is a shiny brass lamp nearby.'] - 'There is a shiny brass lamp nearby.'
- [LAMP_BRIGHT, 'There is a lamp shining nearby.'] - 'There is a lamp shining nearby.'
changes: changes:
- 'Your lamp is now off.' - 'Your lamp is now off.'
- 'Your lamp is now on.' - 'Your lamp is now on.'
@ -3223,9 +3222,10 @@ objects: !!omap
inventory: '*grate' inventory: '*grate'
locations: [LOC_GRATE, LOC_BELOWGRATE] locations: [LOC_GRATE, LOC_BELOWGRATE]
immovable: true immovable: true
states: [GRATE_CLOSED, GRATE_OPEN]
descriptions: descriptions:
- [GRATE_CLOSED, 'The grate is locked.'] - 'The grate is locked.'
- [GRATE_OPEN, 'The grate is open.'] - 'The grate is open.'
changes: changes:
- 'The grate is now locked.' - 'The grate is now locked.'
- 'The grate is now unlocked.' - 'The grate is now unlocked.'
@ -3259,10 +3259,11 @@ objects: !!omap
words: ['bird'] words: ['bird']
inventory: 'Little bird in cage' inventory: 'Little bird in cage'
locations: LOC_BIRD locations: LOC_BIRD
states: [BIRD_UNCAGED, BIRD_CAGED, BIRD_FOREST_UNCAGED]
descriptions: descriptions:
- [BIRD_UNCAGED, 'A cheerful little bird is sitting here singing.'] - 'A cheerful little bird is sitting here singing.'
- [BIRD_CAGED, 'There is a little bird in the cage.'] - 'There is a little bird in the cage.'
- [BIRD_FOREST_UNCAGED, 'A cheerful little bird is sitting here singing.'] - 'A cheerful little bird is sitting here singing.'
sounds: sounds:
- 'The bird''s singing is quite melodious.' - 'The bird''s singing is quite melodious.'
- 'The bird does not seem inclined to sing while in the cage.' - 'The bird does not seem inclined to sing while in the cage.'
@ -3282,9 +3283,10 @@ objects: !!omap
inventory: '*rusty door' inventory: '*rusty door'
locations: LOC_IMMENSE locations: LOC_IMMENSE
immovable: true immovable: true
states: [DOOR_RUSTED, DOOR_UNRUSTED]
descriptions: descriptions:
- [DOOR_RUSTED, 'The way north is barred by a massive, rusty, iron door.'] - 'The way north is barred by a massive, rusty, iron door.'
- [DOOR_UNRUSTED, 'The way north leads through a massive, rusty, iron door.'] - 'The way north leads through a massive, rusty, iron door.'
changes: changes:
- 'The hinges are quite thoroughly rusted now and won''t budge.' - 'The hinges are quite thoroughly rusted now and won''t budge.'
- |- - |-
@ -3301,9 +3303,10 @@ objects: !!omap
inventory: '*snake' inventory: '*snake'
locations: LOC_KINGHALL locations: LOC_KINGHALL
immovable: true immovable: true
states: [SNAKE_BLOCKS, SNAKE_CHASED]
descriptions: descriptions:
- [SNAKE_BLOCKS, 'A huge green fierce snake bars the way!'] - 'A huge green fierce snake bars the way!'
- [SNAKE_CHASED, ''] # chased away - '' # chased away
sounds: sounds:
- 'The snake is hissing venomously.' - 'The snake is hissing venomously.'
- FISSURE: - FISSURE:
@ -3311,10 +3314,11 @@ objects: !!omap
inventory: '*fissure' inventory: '*fissure'
locations: [LOC_EASTBANK, LOC_WESTBANK] locations: [LOC_EASTBANK, LOC_WESTBANK]
immovable: true immovable: true
states: [UNBRIDGED, BRIDGED, VANISHED]
descriptions: descriptions:
- [UNBRIDGED, ''] - ''
- [BRIDGED, 'A crystal bridge now spans the fissure.'] - 'A crystal bridge now spans the fissure.'
- [VANISHED, 'The crystal bridge has vanished!'] - 'The crystal bridge has vanished!'
- OBJ_13: - OBJ_13:
words: ['table'] words: ['table']
inventory: '*stone tablet' inventory: '*stone tablet'
@ -3375,10 +3379,11 @@ objects: !!omap
words: ['bottl', 'jar'] words: ['bottl', 'jar']
inventory: 'Small bottle' inventory: 'Small bottle'
locations: LOC_BUILDING locations: LOC_BUILDING
states: [WATER_BOTTLE, EMPTY_BOTTLE, OIL_BOTTLE]
descriptions: descriptions:
- [WATER_BOTTLE, 'There is a bottle of water here.'] - 'There is a bottle of water here.'
- [EMPTY_BOTTLE, 'There is an empty bottle here.'] - 'There is an empty bottle here.'
- [OIL_BOTTLE, 'There is a bottle of oil here.'] - 'There is a bottle of oil here.'
- WATER: - WATER:
words: ['water', 'h2o'] words: ['water', 'h2o']
inventory: 'Water in the bottle' inventory: 'Water in the bottle'
@ -3400,10 +3405,11 @@ objects: !!omap
inventory: '*plant' inventory: '*plant'
locations: LOC_WESTPIT locations: LOC_WESTPIT
immovable: true immovable: true
states: [PLANT_THIRSTY, PLANT_BELLOWING, PLANT_GROWN]
descriptions: descriptions:
- 'There is a tiny little plant in the pit, murmuring "water, water, ..."' - 'There is a tiny little plant in the pit, murmuring "water, water, ..."'
- [PLANT_BELLOWING, 'There is a 12-foot-tall beanstalk stretching up out of the pit,\nbellowing "WATER!! WATER!!"'] - 'There is a 12-foot-tall beanstalk stretching up out of the pit,\nbellowing "WATER!! WATER!!"'
- [PLANT_GROWN, 'There is a gigantic beanstalk stretching all the way up to the hole.'] - 'There is a gigantic beanstalk stretching all the way up to the hole.'
- 'The plant spurts into furious growth for a few seconds.' - 'The plant spurts into furious growth for a few seconds.'
- 'The plant grows explosively, almost filling the bottom of the pit.' - 'The plant grows explosively, almost filling the bottom of the pit.'
- 'You''ve over-watered the plant! It''s shriveling up! And now . . .' - 'You''ve over-watered the plant! It''s shriveling up! And now . . .'
@ -3438,9 +3444,10 @@ objects: !!omap
words: ['axe'] words: ['axe']
inventory: 'Dwarf''s axe' inventory: 'Dwarf''s axe'
locations: LOC_NOWHERE locations: LOC_NOWHERE
states: [AXE_HERE, AXE_LOST]
descriptions: descriptions:
- [AXE_HERE, 'There is a little axe here.'] - 'There is a little axe here.'
- [AXE_LOST, 'There is a little axe lying beside the bear.'] - 'There is a little axe lying beside the bear.'
changes: changes:
- '' - ''
- 'The axe misses and lands near the bear where you can''t get at it.' - 'The axe misses and lands near the bear where you can''t get at it.'
@ -3461,10 +3468,11 @@ objects: !!omap
inventory: '*dragon' inventory: '*dragon'
locations: [LOC_SECRET4, LOC_SECRET6] locations: [LOC_SECRET4, LOC_SECRET6]
immovable: true immovable: true
states: [DRAGON_BARS, DRAGON_DEAD, DRAGON_BLOODLESS]
descriptions: descriptions:
- [DRAGON_BARS, 'A huge green fierce dragon bars the way!'] - 'A huge green fierce dragon bars the way!'
- [DRAGON_DEAD, 'The blood-specked body of a huge green dead dragon lies to one side.'] - 'The blood-specked body of a huge green dead dragon lies to one side.'
- [DRAGON_BLOODLESS, 'The body of a huge green dead dragon is lying off to one side.'] - 'The body of a huge green dead dragon is lying off to one side.'
changes: changes:
- '' - ''
- |- - |-
@ -3480,18 +3488,20 @@ objects: !!omap
inventory: '*chasm' inventory: '*chasm'
locations: [LOC_SWCHASM, LOC_NECHASM] locations: [LOC_SWCHASM, LOC_NECHASM]
immovable: true immovable: true
states: [TROLL_BRIDGE, BRIDGE_WRECKED]
descriptions: descriptions:
- [TROLL_BRIDGE, 'A rickety wooden bridge extends across the chasm, vanishing into the\nmist. A notice posted on the bridge reads, "Stop! Pay troll!"'] - 'A rickety wooden bridge extends across the chasm, vanishing into the\nmist. A notice posted on the bridge reads, "Stop! Pay troll!"'
- [BRIDGE_WRECKED, 'The wreckage of a bridge (and a dead bear) can be seen at the bottom\nof the chasm.'] - 'The wreckage of a bridge (and a dead bear) can be seen at the bottom\nof the chasm.'
- TROLL: - TROLL:
words: ['troll'] words: ['troll']
inventory: '*troll' inventory: '*troll'
locations: [LOC_SWCHASM, LOC_NECHASM] locations: [LOC_SWCHASM, LOC_NECHASM]
immovable: true immovable: true
states: [TROLL_UNPAID, TROLL_PAIDONCE, TROLL_GONE]
descriptions: descriptions:
- [TROLL_UNPAID, 'A burly troll stands by the bridge and insists you throw him a\ntreasure before you may cross.'] - 'A burly troll stands by the bridge and insists you throw him a\ntreasure before you may cross.'
- [TROLL_PAIDONCE, 'The troll steps out from beneath the bridge and blocks your way.'] - 'The troll steps out from beneath the bridge and blocks your way.'
- [TROLL_GONE, ''] # chased away - '' # chased away
sounds: sounds:
- 'The troll sounds quite adamant in his demand for a treasure.' - 'The troll sounds quite adamant in his demand for a treasure.'
- 'The troll sounds quite adamant in his demand for a treasure.' - 'The troll sounds quite adamant in his demand for a treasure.'
@ -3507,11 +3517,12 @@ objects: !!omap
inventory: !!null # bear uses rtext 141 inventory: !!null # bear uses rtext 141
locations: LOC_BARRENROOM locations: LOC_BARRENROOM
immovable: true immovable: true
states: [UNTAMED_BEAR, SITTING_BEAR, CONTENTED_BEAR, BEAR_DEAD]
descriptions: descriptions:
- [UNTAMED_BEAR, 'There is a ferocious cave bear eying you from the far end of the room!'] - 'There is a ferocious cave bear eying you from the far end of the room!'
- [SITTING_BEAR, 'There is a gentle cave bear sitting placidly in one corner.'] - 'There is a gentle cave bear sitting placidly in one corner.'
- [CONTENTED_BEAR, 'There is a contented-looking bear wandering about nearby.'] - 'There is a contented-looking bear wandering about nearby.'
- [BEAR_DEAD, ''] - ''
- MESSAG: - MESSAG:
words: ['messa'] words: ['messa']
inventory: '*message in second maze' inventory: '*message in second maze'
@ -3534,9 +3545,14 @@ objects: !!omap
inventory: '*vending machine' inventory: '*vending machine'
locations: LOC_DEADEND13 locations: LOC_DEADEND13
immovable: true immovable: true
states: [VEND_BLOCKS, VEND_UNBLOCKS]
descriptions: descriptions:
- [VEND_BLOCKS, 'There is a massive and somewhat battered vending machine here. The\ninstructions on it read: "Drop coins here to receive fresh batteries."'] - |-
- [VEND_UNBLOCKS, 'There is a massive vending machine here, swung back to reveal a\nsouthward passage.'] There is a massive and somewhat battered vending machine here. The
instructions on it read: "Drop coins here to receive fresh batteries."
- |-
There is a massive vending machine here, swung back to reveal a
southward passage.
changes: changes:
- 'The vending machine swings back to block the passage.' - 'The vending machine swings back to block the passage.'
- 'As you strike the vending machine, it pivots backward along with a\nsection of wall, revealing a dark passage leading south.' - 'As you strike the vending machine, it pivots backward along with a\nsection of wall, revealing a dark passage leading south.'
@ -3547,9 +3563,10 @@ objects: !!omap
words: ['batte'] words: ['batte']
inventory: 'Batteries' inventory: 'Batteries'
locations: LOC_NOWHERE locations: LOC_NOWHERE
states: [FRESH_BATTERIES, DEAD_BATTERIES]
descriptions: descriptions:
- [FRESH_BATTERIES, 'There are fresh batteries here.'] - 'There are fresh batteries here.'
- [DEAD_BATTERIES, 'Some worn-out batteries have been discarded nearby.'] - 'Some worn-out batteries have been discarded nearby.'
- OBJ_40: - OBJ_40:
words: ['carpe', 'moss'] words: ['carpe', 'moss']
inventory: '*carpet and/or moss and/or curtains' inventory: '*carpet and/or moss and/or curtains'
@ -3570,10 +3587,11 @@ objects: !!omap
inventory: '*urn' inventory: '*urn'
locations: LOC_CLIFF locations: LOC_CLIFF
immovable: true immovable: true
states: [URN_EMPTY, URN_DARK, URN_LIT]
descriptions: descriptions:
- [URN_EMPTY, 'A small urn is embedded in the rock.'] - 'A small urn is embedded in the rock.'
- [URN_DARK, 'A small urn full of oil is embedded in the rock.'] - 'A small urn full of oil is embedded in the rock.'
- [URN_LIT, 'A small oil flame extrudes from an urn embedded in the rock.'] - 'A small oil flame extrudes from an urn embedded in the rock.'
changes: changes:
- 'The urn is empty and will not light.' - 'The urn is empty and will not light.'
- 'The urn is now dark.' - 'The urn is now dark.'
@ -3583,9 +3601,10 @@ objects: !!omap
inventory: '*cavity' inventory: '*cavity'
locations: LOC_NOWHERE locations: LOC_NOWHERE
immovable: true immovable: true
states: [CAVITY_FULL, CAVITY_EMPTY]
descriptions: descriptions:
- [CAVITY_FULL, ''] # something in it - '' # something in it
- [CAVITY_EMPTY, 'There is a small urn-shaped cavity in the rock.'] - 'There is a small urn-shaped cavity in the rock.'
- BLOOD: - BLOOD:
words: ['blood'] words: ['blood']
inventory: '*blood' inventory: '*blood'
@ -3598,9 +3617,10 @@ objects: !!omap
inventory: '*reservoir' inventory: '*reservoir'
locations: [LOC_RESERVOIR, LOC_RESNORTH] locations: [LOC_RESERVOIR, LOC_RESNORTH]
immovable: true immovable: true
states: [WATERS_UNPARTED, WATERS_PARTED, WATERS_CRASH]
descriptions: descriptions:
- '' - ''
- [WATERS_PARTED, 'The waters have parted to form a narrow path across the reservoir.'] - 'The waters have parted to form a narrow path across the reservoir.'
- 'The waters crash together again.' - 'The waters crash together again.'
- OBJ_46: - OBJ_46:
words: ['appen', 'lepor'] words: ['appen', 'lepor']
@ -3631,9 +3651,10 @@ objects: !!omap
inventory: '*sign' inventory: '*sign'
locations: LOC_ANTEROOM locations: LOC_ANTEROOM
immovable: true immovable: true
states: [INGAME_SIGN, ENDGAME_SIGN]
descriptions: descriptions:
- [INGAME_SIGN, ''] - ''
- [ENDGAME_SIGN, ''] - ''
texts: texts:
- |- - |-
Cave under construction beyond this point. Cave under construction beyond this point.
@ -3687,10 +3708,11 @@ objects: !!omap
inventory: 'Golden eggs' inventory: 'Golden eggs'
locations: LOC_GIANTROOM locations: LOC_GIANTROOM
treasure: true treasure: true
states: [EGGS_HERE, EGGS_VANISHED, EGGS_DONE]
descriptions: descriptions:
- [EGGS_HERE, 'There is a large nest here, full of golden eggs!'] - 'There is a large nest here, full of golden eggs!'
- [EGGS_VANISHED, 'The nest of golden eggs has vanished!'] - 'The nest of golden eggs has vanished!'
- [EGGS_DONE, 'Done!'] - 'Done!'
- TRIDENT: - TRIDENT:
words: ['tride'] words: ['tride']
inventory: 'Jeweled trident' inventory: 'Jeweled trident'
@ -3703,11 +3725,12 @@ objects: !!omap
inventory: 'Ming vase' inventory: 'Ming vase'
locations: LOC_ORIENTAL locations: LOC_ORIENTAL
treasure: true treasure: true
states: [VASE_WHOLE, VASE_RESTING, VASE_BROKEN, VASE_DROPS]
descriptions: descriptions:
- [VASE_WHOLE, 'There is a delicate, precious, ming vase here!'] - 'There is a delicate, precious, ming vase here!'
- [VASE_RESTING, 'The vase is now resting, delicately, on a velvet pillow.'] - 'The vase is now resting, delicately, on a velvet pillow.'
- [VASE_BROKEN, 'The floor is littered with worthless shards of pottery.'] - 'The floor is littered with worthless shards of pottery.'
- [VASE_DROPS, 'The ming vase drops with a delicate crash.'] - 'The ming vase drops with a delicate crash.'
changes: changes:
- '' - ''
- '' - ''
@ -3740,10 +3763,11 @@ objects: !!omap
locations: [LOC_SECRET4, LOC_SECRET6] locations: [LOC_SECRET4, LOC_SECRET6]
immovable: true immovable: true
treasure: true treasure: true
states: [RUG_FLOOR, RUG_DRAGON, RUG_HOVER]
descriptions: descriptions:
- [RUG_FLOOR, 'There is a persian rug spread out on the floor!'] - 'There is a persian rug spread out on the floor!'
- [RUG_DRAGON, 'The dragon is sprawled out on a persian rug!!'] - 'The dragon is sprawled out on a persian rug!!'
- [RUG_HOVER, 'There is a persian rug here, hovering in mid-air!'] - 'There is a persian rug here, hovering in mid-air!'
- OBJ_63: - OBJ_63:
words: ['spice'] words: ['spice']
inventory: 'Rare spices' inventory: 'Rare spices'
@ -3757,10 +3781,11 @@ objects: !!omap
locations: LOC_BARRENROOM locations: LOC_BARRENROOM
immovable: true immovable: true
treasure: true treasure: true
states: [CHAIN_HEAP, CHAINING_BEAR, CHAIN_FIXED]
descriptions: descriptions:
- [CHAIN_HEAP, 'There is a golden chain lying in a heap on the floor!'] - 'There is a golden chain lying in a heap on the floor!'
- [CHAINING_BEAR, 'The bear is locked to the wall with a golden chain!'] - 'The bear is locked to the wall with a golden chain!'
- [CHAIN_FIXED, 'There is a golden chain locked to the wall!'] - 'There is a golden chain locked to the wall!'
- RUBY: - RUBY:
words: ['ruby'] words: ['ruby']
inventory: 'Giant ruby' inventory: 'Giant ruby'
@ -3781,9 +3806,10 @@ objects: !!omap
inventory: 'Amber gemstone' inventory: 'Amber gemstone'
locations: LOC_NOWHERE locations: LOC_NOWHERE
treasure: true treasure: true
states: [AMBER_IN_URN, AMBER_IN_ROCK]
descriptions: descriptions:
- [AMBER_IN_URN, 'There is a rare amber gemstone here!'] - 'There is a rare amber gemstone here!'
- [AMBER_IN_ROCK, 'There is an amber gemstone resting in a small cavity in the rock!'] - 'There is an amber gemstone resting in a small cavity in the rock!'
- SAPPH: - SAPPH:
words: ['sapph'] words: ['sapph']
inventory: 'Star sapphire' inventory: 'Star sapphire'

View file

@ -407,18 +407,15 @@ def get_objects(obj):
else: else:
labels = [] labels = []
for l_msg in attr["descriptions"]: for l_msg in attr["descriptions"]:
if not isinstance(l_msg, str):
labels.append(l_msg)
l_msg = l_msg[1]
descriptions_str += " " * 12 + make_c_string(l_msg) + ",\n" descriptions_str += " " * 12 + make_c_string(l_msg) + ",\n"
for label in attr.get("states", []):
labels.append(label)
descriptions_str = descriptions_str[:-1] # trim trailing newline descriptions_str = descriptions_str[:-1] # trim trailing newline
if labels: if labels:
global statedefines global statedefines
statedefines += "/* States for %s */\n" % item[0] statedefines += "/* States for %s */\n" % item[0]
for (i, (label, message)) in enumerate(labels): for (i, label) in enumerate(labels):
if len(message) >= 45: statedefines += "#define %s\t%d\n" % (label, i)
message = message[:45] + "..."
statedefines += "#define %s\t%d /* %s */\n" % (label, i, message)
statedefines += "\n" statedefines += "\n"
sounds_str = "" sounds_str = ""
if attr.get("sounds") == None: if attr.get("sounds") == None:
@ -651,6 +648,8 @@ def buildtravel(locs, objs):
obj = objnames.index(cond[1]) obj = objnames.index(cond[1])
if type(cond[2]) == int: if type(cond[2]) == int:
state = cond[2] state = cond[2]
elif cond[2] in objs[obj][1].get("states", []):
state = objs[obj][1].get("states").index(cond[2])
else: else:
for (i, stateclause) in enumerate(objs[obj][1]["descriptions"]): for (i, stateclause) in enumerate(objs[obj][1]["descriptions"]):
if type(stateclause) == list: if type(stateclause) == list: