It's fairly common that we want to be able to refer to a container in terms of what it has in it: a bottle of wine, a salt shaker, a chicken sandwich. The player is free to remove the contents again, and the object will go back to using its usual name:
"Cinco"
Cinco de Mayo Fundraiser is a room.
The taco shell is an edible thing in the Fundraiser. It is a portable container. It has carrying capacity 1.
Understand "[something related by containment] taco" as the taco.
Rule for printing the name of the taco shell while not inserting or removing:
if the taco contains something (called filling), say "[filling] taco";
otherwise say "taco shell";
omit contents in listing.
The player carries shredded beef. It is edible.
The taking action has an object called source (matched as "from").
Setting action variables for taking:
now source is the holder of the noun.
Report taking something from the taco shell:
say "You gingerly pick [the noun] out of the taco shell." instead.
Test me with "x taco / put shredded beef in taco / get taco / i / x shredded beef taco / get shredded beef / x shredded beef taco".
First to lay some groundwork:
"Shipping Trunk"
A chest is a kind of container. A chest is always openable. A lid is a kind of supporter. A lid is part of every chest.
Before opening a chest when something (called the obstruction) is on a lid which is part of the noun:
say "Better remove [the obstruction]." instead.
A thing can be innocent or smelly.
The Storage Unit is a room. The shipping trunk is a closed chest in the Storage Unit. The trunk contains some garlic, a loaf of moldy sourdough, a mildewy bathtowel, a pair of unwashed socks, two dead trout, and a box of baking powder. The garlic, trout, sourdough, bathtowel, and socks are smelly. The baking powder is innocent.
The shipping trunk's lid supports a small card. The description of the small card is "'Please, please do not open this trunk.'"
After opening the trunk:
if the trunk had been open:
say "You steel yourself...";
continue the action;
otherwise:
say "There roils up from inside an indescribable funk, which, when you can see straight, you have no trouble attributing to the presence of [a list of smelly things in the trunk]. You also note [a list of innocent things in the trunk] in the corner.".
And now, with that preparation:
Before printing the name of the baking powder when the powder is in a container which contains a smelly thing: say "completely ineffective ".
Test me with "open trunk / examine card / get card / open trunk / get powder / inventory".
It is not difficult to implement a safe which can be set to a single number to open; but a more common scenario in the real world is for the safe to open on a sequence of numbers when they have been dialed in the right order.
For IF, this means that we have to keep running track of the last N digits the player has dialed, dropping the first digit and adding a new one to the end each time the player re-dials the safe. This is a perfect occasion for lists:
"Eyes, Fingers, Toes"
The Addams Wine Cellar is a room. It contains a closed lockable locked container called a safe.
The safe has a list of numbers called the current combination.
The safe has a list of numbers called the true combination. The true combination of the safe is {2, 10, 11}.
Understand "set [something] to [a number]" as setting it numerically to. Setting it numerically to is an action applying to one thing and one number.
Instead of examining the safe:
if the number of entries in the current combination of the safe is 0,
say "You haven't dialed the safe to any combination yet.";
otherwise say "You have dialed the safe to [the current combination of the safe].".
Check setting something numerically to (this is the block setting numerically rule):
say "[The noun] cannot be set."
Instead of setting the safe numerically to the number understood:
truncate the current combination of the safe to the last 2 entries;
add the number understood to the current combination of the safe;
if the safe is locked and the current combination of the safe is the true combination of the safe:
say "You dial [the number understood], and [the safe] gives a joyous CLICK.";
now the safe is unlocked;
otherwise if safe is unlocked and the safe is closed and the current combination of the safe is not the true combination of the safe:
say "You spin the dial, and [the safe] snicks locked.";
now the safe is locked;
otherwise:
say "You dial [the number understood] on the safe."
Test me with "x safe / set safe to 10 / x safe / set safe to 29 / x safe / set safe to 2 / x safe / set safe to 10 / x safe / set safe to 11 / open safe / set safe to 14 / close safe / set safe to 15 / open safe".
"Trachypachidae Maturin 1803"
A bottle is a kind of container. Bottles are usually openable, transparent, and closed. A cork is a kind of thing. A cork is in every bottle.
Understand "cork [something]" as corking.
Understand the command "stopper" as "cork".
Understand "uncork [something]" as uncorking.
Corking is an action applying to one thing.
Check corking:
if the noun is not a bottle, say "[The noun] cannot be corked." instead.
Carry out corking:
try closing the noun.
Uncorking is an action applying to one thing.
Check uncorking:
if the noun is not a bottle, say "[The noun] cannot be uncorked." instead.
Carry out uncorking:
try opening the noun.
Understand "close [something] with [something preferably held]" as corking it with.
Understand "cork [something] with [something preferably held]" as corking it with.
Corking it with is an action applying to one thing and one carried thing.
Check corking it with:
if the noun is not a bottle, say "[The noun] cannot be corked." instead;
if the second noun is not a cork, say "[The second noun] will not fit in [the noun]." instead.
Carry out corking it with:
try inserting the second noun into the noun instead.
Instead of closing a bottle:
if a cork (called the item) is carried by the player, try inserting the item into the noun instead;
otherwise say "You need a stopper of some kind."
Instead of opening a bottle:
if a cork (called the item) is in the noun, try taking the item instead;
otherwise say "[The noun] has no stopper."
Carry out inserting a cork into a bottle:
now the second noun is closed.
After inserting a cork into a bottle:
say "You stopper [the second noun] with [the noun]."
Before taking a cork when the noun is in a closed bottle (called the item):
now the item is open.
Instead of taking a cork when the noun is in a bottle (called the item):
move the noun to the player;
say "You pull [the noun] from [the item]." instead.
Before printing the name of a bottle (called target) while not inserting, taking, searching, or removing:
if the target is closed, say "sealed ";
otherwise say "now open ".
After printing the name of a bottle (called target) while not inserting, searching, examining, or removing:
if the target contains a noncork thing, say " containing [a list of noncork things in the target]";
omit contents in listing.
Instead of examining a bottle:
say "[The noun] contains [a list of noncork things in the noun]."
Definition: a thing is noncork if it is not a cork.
The Doctor's Cabin is a room. "A dark, cramped triangle, like a slice of cake, except that its sharp end has been cut off: and so low that a moderately tall man would strike his head on the deck above if he were to stand upright. Every free surface is covered with sheets of best Venetian looking-glass, to increase the light filtering in. Long use and the carpenter's ingenuity have packed in a folding cot and table, and lockers are built into unlikely places: lockers filled with specimens, skeletons, sketches, drafts and serial letters." The jug is a bottle in the Doctor's Cabin. The jug contains a beetle. The description of the beetle is "The doctor assures you that it is a nondescript."
Test me with "get jug / x jug / open jug / x jug / i / x cork / cork jug / i / uncork jug / i / x jug / get beetle / i / close jug / i / x jug".
In this scenario, the player starts with a bag full of unsorted letters. These can be polite or rude, but he won't know which until he has examined them. What's more, he is allowed to sort the letters, in which case a group of letters will be shown as (for instance) "two polite letters"; but a group of mixed letters, even if they have all been read, will be called "unsorted letters".
Further, the player should be allowed to refer to sorted letters by tone, but not unsorted letters.
To do this, we'll need printing the name... and printing the plural name..., as well as some special understanding rules.
"Hudsucker Industries"
Tone is a kind of value. The tones are effusive, affectionate, polite, curt, and flamingly rude.
A letter is a kind of thing. The description of a letter is usually "On inspection, it turns out to be quite [tone]." A letter has a tone. The tone of a letter is usually polite.
A letter can be read or unread. A letter is usually unread. Carry out examining a letter: now the noun is read.
Before printing the name of a read letter: say "[tone] ".
Before printing the name of an ungrouped letter: say "random ".
Before printing the plural name of a letter (called the subject):
if the subject is grouped:
say "[tone] ";
otherwise if the number of unread letters which are next to the subject is 0:
say "unsorted ".
After printing the plural name of a letter (called the subject):
if the number of read letters which are next to the subject is 0, say " (all unread, at the moment)" instead;
if the number of unread letters which are next to the subject is greater than 0, say " (some as yet unread)" instead.
Proximity relates a thing (called X) to a thing (called Y) when the holder of X is the holder of Y. The verb to be next to means the proximity relation.
Definition: a letter is grouped:
if it is unread, no;
if the number of unread letters next to it is greater than 0, no;
repeat with item running through letters which are next to it:
if the tone of item is not the tone of it, no;
yes.
Definition: a letter is ungrouped if it is not grouped.
The Mailroom is a room. "Usually a thrumming hive of bee-like workers, but you got in early to get a jump on the day's work."
The satchel is carried by the player. Two flamingly rude letters are in the satchel. Five polite letters are in the satchel.
The mail wall are fixed in place in the mailroom. "Before you is a wall of mailboxes, including [a list of mailboxes which are part of the mail wall]."
The plural of mailbox is mailboxes. A mailbox is a kind of container. The CEO box is a mailbox. The Hold box is a mailbox. The Trash box is a mailbox. Understand "mailbox" as a mailbox.
Now, there's a good bit of interaction to streamline. We intend that the player will be taking letters from the satchel, reading them, and putting them (perhaps grouped) into boxes. Our interaction rules should assist in this process as much as possible. To start with, the player will be most likely to examine letters he hasn't read yet:
Does the player mean examining a letter (called the subject):
if we have examined the subject, it is very unlikely;
it is very likely.
The rules about taking are more subtle: the player is more likely to want to take an ungrouped letter than a grouped one; he is more likely to want one from the satchel than not; and he is most unlikely to want to take a letter (grouped or ungrouped) that he is already holding.
Does the player mean taking a letter (called subject) which is grouped:
if the player carries the subject, it is very unlikely;
if the subject is in the satchel, it is possible;
it is unlikely.
Does the player mean taking a letter (called subject) which is ungrouped:
if the player carries the subject, it is very unlikely;
if the subject is in the satchel, it is very likely;
it is possible.
And finally, we will assume by default that anything other than examining or taking is most likely to apply to a letter he's already identified:
Does the player mean doing something other than examining or taking with a letter (called the subject):
if we have examined the subject, it is likely;
it is unlikely.
And we would also like to understand properties under the same circumstances as printing -- a letter will be identifiable as "polite" if it's already been read and it is either by itself or in a sorted stack of polite letters, but otherwise not. What's more, to make it possible to disambiguate commands in the other direction, we'll call any unsorted letter "random", to represent that the player doesn't know what it is.
Understand the tone property as referring to a letter when the item described is grouped. Understand "random" as a letter when the item described is ungrouped.
When play begins:
now every mailbox is part of the mail wall;
repeat with switch count running from 1 to 5:
move a random letter to the satchel.
Test me with "inventory / examine letter / get letter / i / put letter in ceo box / inventory / get letter / x letter / g / g / i / x letter / g / g / i / put letter in hold box / get letter / g / g / i".
That last "repeat" is merely a device to shuffle the order of items in the satchel so that the player will not always encounter the letters in a neatly presorted order, despite our defining them that way. (Of course, that means that the test produced by TEST ME cannot be very exciting...)
It may not be immediately obvious why we might want to create new intermediate categories of the kinds hierarchy. But there may be times, for instance, where we would like to make an action that applies in the same way to both containers and supporters, but to nothing else in the game. To avoid creating two nearly-identical rules, we would instead roll the two categories together into one, on the principle that duplicating source text is usually a sign of bad design.
So for instance let's say the player is able to zap objects to make them go away, but any contents -- things inside a container or on top of a supporter -- should always be left as residue. Here's one way we might do this:
"Fallout Enclosure"
Section 1 - Procedure
An enclosure is a kind of thing. A container is a kind of enclosure. A supporter is a kind of enclosure.
Understand "zap [something]" as zapping. Zapping is an action applying to one thing. The Zapping action has a list of things called the remnants.
Carry out zapping an enclosure:
if the noun holds something:
now the remnants is the list of things held by the noun;
repeat with N running through the remnants:
move N to the holder of the noun.
Carry out zapping:
now the noun is nowhere.
Report zapping:
say "You zap [the noun], destroying [them][if the remnants is not empty] and leaving [the remnants with indefinite articles] behind[end if]."
Section 2 - Scenario
SuperDuperMart is a room. SuperDuperMart contains some shelves and a cash register.
The shelves support a bottle of Buffout and a container of Jet.
The cash register contains some prewar money, a coin purse, and a bottle cap. The coin purse contains a prewar nickel. It is closed.
The cash register is closed and locked.
Test me with "zap shelves / zap buffout / zap register / zap purse".