The Left Hand of Autumn

Example 295
★★★

The possibility of using a [things] token opens up some interesting complications, because we may want actions on multiple items to be reported differently from actions on just one. Here we look at how to make a multiple examination command that describes groups in special ways.

Suppose that we have a game in which groups of objects can have meaning apart from their individual significance – perhaps there are spells that can only be cast by collecting just the right items in the same place.

In this case, one of the things the player might like to be able to do is look at several items together and get a special response, different from looking at the items individually.

To make this happen, we need to do several things:

(1) we need to create a version of the EXAMINE command that can apply to multiple objects at once.
(2) we need to correct the way Inform normally deals with multiple-object commands, because we want our group description to print only one time, and we want to avoid stubs such as "pear: ... apple: ..." before or after the group description.
(3) we need to define a way for Inform to identify interesting groups and describe them.
"The Left Hand of Autumn"
Section 1 - Procedure
Understand "examine [things]" or "look at [things]" as multiply-examining. Multiply-examining is an action applying to one thing.
Understand "examine [things inside] in/on [something]" or "look at [things inside] in/on [something]" as multiply-examining it from. Multiply-examining it from is an action applying to two things.
Group-description-complete is a truth state that varies.
Carry out multiply-examining it from:
   try multiply-examining the noun instead.
Check multiply-examining when group-description-complete is true:
   stop the action.
Carry out multiply-examining:
   let L be the list of matched things;
   if the number of entries in L is 0, try examining the noun instead;
   if the number of entries in L is 1, try examining entry 1 of L instead;
   describe L;
   say line break;
   now group-description-complete is true.
Before reading a command:
   now group-description-complete is false.

Now for step 2, overriding Inform's usual output of names of objects:

The silently announce items from multiple object lists rule is listed instead of the announce items from multiple object lists rule in the action-processing rules.
This is the silently announce items from multiple object lists rule:
   unless multiply-examining or multiply-examining something from something:
      if the current item from the multiple object list is not nothing, say "[current item from the multiple object list]: [run paragraph on]".
Definition: a thing is matched if it is listed in the multiple object list.

We'll save our "to describe" phrase until Section 2, when we can give the game specific instructions about how to report different lists of objects.

Now, the player might also want to be able to refer to a group of item by some kind of group name, so let's add the option of creating a Table of Collective Names which will interpret these:

After reading a command:
   repeat through the Table of Collective Names:
      let N be "[the player's command]";
      let Y be relevant list entry;
      while N matches the regular expression "[name-text entry]":
         replace the regular expression "(.*)[name-text entry](.*)" in N with "\1[Y]\2";
      change the text of the player's command to N.
Report taking something:
   say "You pick up [the noun]." instead.

And as a bit of polish, because we'd like SEARCH TABLE to have the same effect as EXAMINE ALL ON TABLE:

Understand "look on [something]" as searching.
Instead of searching something which supports at least two things:
   let L be the list of things supported by the noun;
   describe L.
Instead of searching something which contains at least two things:
   let L be the list of things contained by the noun;
   describe L.
Section 2 - Scenario
Eight-Walled Chamber is a room. "A perfectly octagonal room whose walls are tinted in various hues."
The display table is a supporter in the Chamber. A twig of rowan wood is on the table.
The player carries an apple and a pear.
A glove is a kind of thing. A glove is always wearable. Understand "glove" as a glove. The player carries a left glove and a right glove. The left glove and the right glove are gloves.

Now we define a few actual lists of items:

Fruit list is a list of objects which varies. Fruit list is { apple, pear }.
Glove list is a list of objects which varies. Glove list is { right glove, left glove }.
Arcane list is a list of objects which varies. Arcane list is { left glove, twig, pear }.
To describe (L - a list of objects):
   sort L;
   if L is fruit list:
      say "Just a couple of fruits.";
   otherwise if L is glove list:
      say "It's a matched pair of fuzzy blue gloves.";
   otherwise if L is arcane list:
      say "To anyone else it might look like a random collection of objects, but these three things -- [L with definite articles] -- constitute a mystic key known as the Left Hand of Autumn. They practically hum with power.";
   otherwise:
      say "You see [L with indefinite articles]."
When play begins:
   sort fruit list;
   sort glove list;
   sort the arcane list.

We sort the lists so that regardless of how we change the rest of the code (and the order in which objects are coded), the resulting list will always be in sorted order and ready to compare with the list of items the player wants to look at. And thanks to the "Reading a command" code we wrote earlier, we can also teach the game to understand the player's references to "the left hand of autumn" as a specific collection of items.

Table of Collective Names
name-textrelevant list
"left hand of autumn""[arcane list]"
"gloves""[glove list]"
"pair of gloves""[glove list]"
Test me with "x apple and pear / x left and right / put pear on table / put left glove on table / x all on table / put all on table / examine all on table / get apple, twig, pear / x all on table / search table".
Test me with "x apple and pear / x left and right / put pear on table / put left glove on table / x all on table / put all on table / examine all on table / get apple, twig, pear / x all on table / search table".
Eight-Walled Chamber
A perfectly octagonal room whose walls are tinted in various hues.

You can see a display table (on which is a twig of rowan wood) here.

>(Testing.)

>[1] x apple and pear
Just a couple of fruits.

>[2] x left and right
It's a matched pair of fuzzy blue gloves.

>[3] put pear on table
You put the pear on the display table.

>[4] put left glove on table
You put the left glove on the display table.

>[5] x all on table
To anyone else it might look like a random collection of objects, but these three things -- the pear, the left glove and the twig of rowan wood -- constitute a mystic key known as the Left Hand of Autumn. They practically hum with power.

>[6] put all on table
apple: Done.
right glove: Done.

>[7] examine all on table
You see an apple, a pear, a left glove, a right glove and a twig of rowan wood.

>[8] get apple, twig, pear
apple: You pick up the apple.
twig of rowan wood: You pick up the twig of rowan wood.
pear: You pick up the pear.

>[9] x all on table
It's a matched pair of fuzzy blue gloves.

>[10] search table
It's a matched pair of fuzzy blue gloves.