Oyster Wide Shut

Example 424

Replacing Inform's default printing of properties such as "(closed)", "(open and providing light)", etc., with our own, more flexible variation.

As we've seen in earlier examples such as "Equipment List", it is possible to vary the way Inform creates inventory listings in general (to create lists that look more like paragraphs of prose, lists divided between what the player is wearing and what he isn't, and so on). We can also use activities to alter the printing of specific objects' names and contents, as with the "omit contents in listing" feature after printing the name of something.

We may find, however, that we would like a great deal more control over Inform's printing of inventory details, not just as a special effect for a few items, but throughout the game.

We start by turning off Inform's native property writer:

"Oyster Wide Shut"
Section 1 - Procedure
The print standard inventory rule is not listed in any rulebook.
Carry out taking inventory (this is the new print inventory rule):
   say "You are carrying: [line break]";
   list the contents of the player, with newlines, indented, including contents, with extra indentation.

This is very much like the library's standard behavior, but with the exception that "giving inventory information" or even "giving brief inventory information" are omitted. Here's how we supplant it:

After printing the name of something (called target) while taking inventory:
   follow the property-aggregation rules for the target.

Now, our property-aggregation rulebook is going to look at a given object and decide on a list of features that should be mentioned in inventory. We'll start by producing something quite similar to Inform's default behavior:

The property-aggregation rules are an object-based rulebook.
The property-aggregation rulebook has a list of text called the tagline.
A first property-aggregation rule for an openable open thing (this is the mention open openables rule):
   add "open" to the tagline.
A first property-aggregation rule for an openable closed thing (this is the mention closed openables rule):
   add "closed" to the tagline.
A property-aggregation rule for a closed transparent container which contains nothing (this is the mention empty transparent containers rule):
   add "empty" to the tagline.
A property-aggregation rule for an open container which contains nothing (this is the mention empty open containers rule):
   add "empty" to the tagline.
A property-aggregation rule for a lit thing (this is the mention lit objects rule):
   add "providing light" to the tagline.
A property-aggregation rule for a thing worn by the player (this is the mention worn objects rule):
   add "being worn" to the tagline.
The last property-aggregation rule (this is the print aggregated properties rule):
   if the number of entries in the tagline is greater than 0:
      say " ([tagline])";
      rule succeeds;
   rule fails.

Notice that we don't need to write any rules about how to print that list of text: because Inform is printing out a list, it will automatically insert commas, spaces, and the word "and" where appropriate; and it will automatically follow the "use serial comma" option, if we have it set.

Now we're free to meddle. Let's give the player a bunch of possessions that will be listed in interesting ways in inventory:

Section 2 - Scenario
The Curved Beach is a room. "White sand stretches away both northeast and northwest, enclosing this attractive little bay. Gentle waves lap at the beach."
The player carries a glowing plastic sack. The glowing plastic sack is lit and transparent and openable and open. It contains a rock. It is wearable.
The player wears a flashlight lanyard. The flashlight lanyard is a device.
Carry out switching on the lanyard: now the noun is lit.
Carry out switching off the lanyard: now the noun is unlit.
The player carries an oyster. The oyster contains a pearl. The oyster is openable.

Now suppose that we don't want the oyster to say "closed" when it's closed. Instead, we'd like it to say "clamped shut". As this is the only property the oyster will ever have, we can simply override his whole property-aggregation rulebook:

A property-aggregation rule for the oyster:
   if the oyster is closed:
      say " (clamped shut)";
   rule succeeds.

That's fine for the oyster because "clamped shut" is the only property he'll ever have. What if we'd like instead just to revise the way the sack (and only the sack) gets described as providing light?

The sacklight rule is listed after the mention lit objects rule in the property-aggregation rules.
A property-aggregation rule for the plastic sack (this is the sacklight rule):
   if "providing light" is listed in the tagline:
      remove "providing light" from the tagline;
      add "gently glowing" to the tagline.

Now the flashlight (and any other regular light sources we might add to the game) will be described as "providing light", but the sack will only be said to be gently glowing – a bit more appropriate for its rather fainter gleam.

We might also wish to add a systematic feature across the board to include a new property in the inventory list? Let's say the player can enchant his possessions, and enchanted possessions should thereafter be listed accordingly:

A thing can be magical or non-magical. A thing is usually non-magical.
Understand "enchant [something]" as enchanting. Enchanting is an action applying to one thing.
Carry out enchanting something:
   now the noun is magical.
Report enchanting something:
   say "Ding! You turn [the noun] magical."
A property-aggregation rule for a magical thing:
   add "enchanted" to the tagline.
Test me with "i / close oyster / i / turn on flashlight / i / take off flashlight / i / turn off flashlight / i / close sack / i / open sack / i / take all from sack / i / close sack / i / wear sack / i / enchant sack / i / open sack / put all in sack / i / close sack / i".
Test me with "i / close oyster / i / turn on flashlight / i / take off flashlight / i / turn off flashlight / i / close sack / i / open sack / i / take all from sack / i / close sack / i / wear sack / i / enchant sack / i / open sack / put all in sack / i / close sack / i".
Curved Beach
White sand stretches away both northeast and northwest, enclosing this attractive little bay. Gentle waves lap at the beach.

>(Testing.)

>[1] i
You are carrying:
a glowing plastic sack (open and gently glowing)
a rock
a flashlight lanyard (being worn)
an oyster
a pearl

>[2] close oyster
You close the oyster.

>[3] i
You are carrying:
a glowing plastic sack (open and gently glowing)
a rock
a flashlight lanyard (being worn)
an oyster (clamped shut)

>[4] turn on flashlight
You switch the flashlight lanyard on.

>[5] i
You are carrying:
a glowing plastic sack (open and gently glowing)
a rock
a flashlight lanyard (being worn and providing light)
an oyster (clamped shut)

>[6] take off flashlight
You take off the flashlight lanyard.

>[7] i
You are carrying:
a glowing plastic sack (open and gently glowing)
a rock
a flashlight lanyard (providing light)
an oyster (clamped shut)

>[8] turn off flashlight
You switch the flashlight lanyard off.

>[9] i
You are carrying:
a glowing plastic sack (open and gently glowing)
a rock
a flashlight lanyard
an oyster (clamped shut)

>[10] close sack
You close the glowing plastic sack.

>[11] i
You are carrying:
a glowing plastic sack (closed and gently glowing)
a rock
a flashlight lanyard
an oyster (clamped shut)

>[12] open sack
You open the glowing plastic sack.

>[13] i
You are carrying:
a glowing plastic sack (open and gently glowing)
a rock
a flashlight lanyard
an oyster (clamped shut)

>[14] take all from sack
Taken.

>[15] i
You are carrying:
a rock
a glowing plastic sack (open, empty and gently glowing)
a flashlight lanyard
an oyster (clamped shut)

>[16] close sack
You close the glowing plastic sack.

>[17] i
You are carrying:
a rock
a glowing plastic sack (closed, empty and gently glowing)
a flashlight lanyard
an oyster (clamped shut)

>[18] wear sack
You put on the glowing plastic sack.

>[19] i
You are carrying:
a rock
a glowing plastic sack (closed, empty, being worn and gently glowing)
a flashlight lanyard
an oyster (clamped shut)

>[20] enchant sack
Ding! You turn the glowing plastic sack magical.

>[21] i
You are carrying:
a rock
a glowing plastic sack (closed, empty, being worn, gently glowing and enchanted)
a flashlight lanyard
an oyster (clamped shut)

>[22] open sack
You open the glowing plastic sack.

>[23] put all in sack
rock: Done.
flashlight lanyard: Done.
oyster: Done.

>[24] i
You are carrying:
a glowing plastic sack (open, being worn, gently glowing and enchanted)
an oyster (clamped shut)
a flashlight lanyard
a rock

>[25] close sack
You close the glowing plastic sack.

>[26] i
You are carrying:
a glowing plastic sack (closed, being worn, gently glowing and enchanted)
an oyster (clamped shut)
a flashlight lanyard
a rock

Further variations are possible as well: if we used a "before printing the name…" rather than an "after printing the name…" rule, we could automatically generate lines like "an open and empty phosphorescent plastic sack", removing some of the artificiality of the parentheses.

Or we could add more logic to the rules about which properties are mentioned, so that some features of objects were mentioned in inventory only if the player was wearing the correct detection device, like so:

The player wears enchantment-detecting goggles.
A property-aggregation rule for a magical thing:
   if the player is wearing the goggles:
      add "enchanted" to the tagline.