"Being Prepared"
A jacket is a kind of thing. A jacket is always wearable.
A pocket is a kind of container. A pocket is part of every jacket. The carrying capacity of a pocket is always 2.
After examining a jacket:
let target be a random pocket which is part of the noun;
say "[The target] contains [a list of things in the target]."
Now we've created the rules that will govern any specific jackets we might happen to put in our game: each one will always have one pocket, which will be able to contain no more than two things. The description of "a list of things" is text with a list, which we will learn about further in a few sections.
Next we might want to create the environment and an actual example of the jacket kind:
Tent is a room. "A dome made of two flexible rods and a lot of bright green ripstop nylon. It bills itself as a one-man tent, but you'd call it a two-dwarf tent: there is no way to arrange yourself on its square floor so that you can stretch out completely."
The hoodie is a jacket. "Your hoodie is balled up in the corner." The description of the hoodie is "Both elbows are stained from yesterday's entrenching project."
The hoodie's pocket contains a Swiss army knife and a folded map. The hoodie is in the Tent.
Notice that, since Inform has created a pocket for the hoodie, we can now refer to it by name in our source, giving it any additional properties we need to define. Here we simply put a few items into it.
The player wears a whistle. The description of the whistle is "To frighten bears."
Test me with "x hoodie / get hoodie / get knife / get map / i / put hoodie in pocket / put whistle in pocket / put map in pocket / put knife in pocket / i".
Notice that Inform automatically refuses to put the hoodie into its own pocket: as a default, a container cannot contain something of which it is itself a part.
We now have the mechanisms in place to do some fairly sophisticated renaming of objects. For instance:
"Some Assembly Required"
Garment type is a kind of value. The garment types are vest, t-shirt, polo shirt, mandarin blouse, button-down, shell, experiment.
Every turn:
assign identities.
When play begins: assign identities.
To assign identities:
repeat with item running through torsos:
reassess item.
To reassess (item - a torso):
if the number of things which are part of the item is 0:
now garment type of the item is vest;
rule succeeds;
if exactly two short sleeves are part of the item:
if a collar is part of the item,
now garment type of the item is polo shirt;
otherwise now garment type of the item is t-shirt;
rule succeeds;
if exactly two long sleeves are part of the item:
if a collar is part of the item,
now garment type of the item is button-down;
otherwise now garment type of the item is mandarin blouse;
rule succeeds;
if a collar is part of the item and the number of sleeves which are part of the item is 0, now garment type of the item is shell;
otherwise now garment type of the item is experiment.
Before cutting something which is worn by the player:
try taking off the noun.
Instead of cutting something when something is part of the noun:
say "You cut up [the noun], snipping off [a list of things which are part of the noun].";
now every thing which is part of the noun is in the holder of the noun.
Instead of cutting something which is part of something:
say "You carefully snip [the noun] free.";
now the player carries the noun.
Rule for printing the name of a torso: say "[garment type]".
A torso is a kind of thing. A torso is always wearable. Understand "shirt" or "blouse" as a torso. A torso has a garment type. Understand the garment type property as describing a torso. A sleeve is a kind of thing. A short sleeve is a kind of sleeve. A long sleeve is a kind of sleeve. A collar is a kind of thing.
Understand "sew [something] to [something]" as affixing it to. Affixing it to is an action applying to two things. Carry out affixing something to something: now the noun is part of the second noun. Report affixing something to something: assign identities; say "You sew [the noun] on, creating [a second noun]." Understand the command "stitch" as "sew".
Instead of affixing something to something when the second noun is worn: say "You're wearing [the second noun]!"
Instead of affixing a torso to something:
if the second noun is a torso, say "Couture for Siamese twins is a daring field, but a bit of a niche market.";
otherwise try affixing the second noun to the noun.
Instead of affixing a sleeve to something when at least two sleeves are part of the second noun: say "[The second noun] already sports [a list of sleeves that are part of the second noun]."
Instead of affixing a collar to something when a collar is part of the second noun: say "[The second noun] already sports [a list of collars that are part of the second noun]."
Instead of examining something when something is part of the noun: say "Stitched to [the noun] [is-are a list of things which are part of the noun]."
Here is where the issue of precedence arises. We want to encourage Inform to select a cuttable object that is part of something else, rather than one of the spares:
Definition: a thing is removable if it is part of something. Understand "cut [removable thing]" as cutting.
The Boutique is a room. "Still festively strewn with the confetti and streamers of the Grand Opening party, and still almost totally customer-free."
The player carries a torso. The player carries three short sleeves. The player carries two long sleeves. The player carries two collars.
Test me with "sew collar to shirt / i / sew short sleeve to shirt / g / i / x polo shirt / cut collar / i / cut shirt / sew long sleeve to shirt / i / sew long sleeve to shirt / i / sew collar to shirt / g / i / wear button-down".
"What Not To Wear"
Section 1 - Overlying and Underlying
We start by borrowing some of the same ideas from the Bogart example, but we're also going to make a kind called "garment-element". This kind will include both garments (objects of clothing) and body parts (things that can be covered by clothing); using it allows us to restrict the way our underlying and overlying relations apply, which will make them a bit faster at run-time.
A garment-element is a kind of thing.
Underlying relates various garment-elements to various garment-elements with fast route-finding. The verb to underlie means the underlying relation. The verb to be under implies the underlying relation.
Check taking off:
if the noun underlies something (called the impediment) which is worn by the player, say "[The impediment] [are] in the way." instead.
Carry out taking off:
now the noun is not underlaid by anything.
Report taking off something:
say "[We] [are] now wearing [a list of uppermost things worn by the player]." instead.
Definition: a garment-element is uppermost if it is not under something opaque.
Here we've expanded on the previous ideas of 'uppermost' because it is possible for an upper layer to reveal what lies beneath: a tie, a clear plastic trenchcoat, an open-knit sweater, etc. We'll make such items transparent.
Before taking off something which underlies something which is worn by the player:
while the noun underlies something (called the impediment) which is worn by the player:
say "(first removing [the impediment])[command clarification break]";
silently try taking off the impediment;
if the noun underlies the impediment, stop the action.
Overlying relates various garment-elements to various garment-elements. The verb to overlie means the overlying relation.
Covering relates a garment-element (called A) to a garment-element (called B) when the number of steps via the overlying relation from A to B is greater than 0. The verb to cover means the covering relation.
Before wearing something when a garment which covers the noun is worn by the player:
while the player wears a garment (called the impediment) which covers the noun:
say "(first removing [the impediment])[command clarification break]";
silently try taking off the impediment;
if the player is wearing the impediment, stop the action.
Carry out wearing:
repeat with hidden item running through things worn by the player:
if the noun covers the hidden item, now the hidden item underlies the noun.
Instead of looking under something which is worn by the player:
if something (called the underwear) underlies the noun, say "[We] [peek] at [the underwear]. Yup, still there.";
otherwise say "Just [us] in there."
Instead of taking inventory:
say "[if the player carries something][We]['re] carrying [a list of things carried by the player][else][We]['re] empty-handed[end if][if the player wears something]. [We] [are] wearing [a list of uppermost garments worn by the player][end if]."
To peek is a verb.
Section 2 - Regional Coverage
Here we draw in the idea that different clothes go over different areas of the body, and that they should be in competition with each other only if both sets of clothes belong at the same level over the same body area.
Before wearing something:
let N be the layering depth of the noun;
repeat with item running through things worn by the player:
if the layering depth of the item is N and the item covers a body-part which is covered by the noun:
say "(first taking off [the item])[command clarification break]";
silently try taking off the item;
if the player wears the item, stop the action.
This may seem like overkill, but it allows us to create garments that cover different subsets of the body -- pants and shirt vs. a dress, for instance.
To decide what number is the layering depth of (chosen garment - a thing):
let N be 0;
if the chosen garment covers a body-part (called base):
let N be the number of steps via the overlying relation from the chosen garment to the base;
decide on N.
To help with modeling, we'll give everyone body parts, broken down according to their relevance to clothing:
A body-part is a kind of garment-element. A torso, a seat, a head, pair of legs, and pair of feet are kinds of body-part.
If we wanted to allow gloves, we might put in hands as well; but this is enough for now.
One head is part of every person. One torso is part of every person. One pair of legs is part of every person. One pair of feet is part of every person. One seat is part of every person.
And now we make some categories of clothing:
A garment is a kind of garment-element. A garment can be transparent. A pair of pants, a pair of underpants, a foundation garment, a pair of socks, a pair of shoes, a jacket, a hat, a dress, and a shirt are kinds of garment.
The plural of pair of pants is pairs of pants. The plural of pair of underpants is pairs of underpants. The plural of pair of socks is pairs of socks. The plural of pair of shoes is pairs of shoes.
A pair of pants, a pair of underpants, a foundation garment, a pair of socks, a pair of shoes, a jacket, a hat, a dress, and a shirt are usually wearable.
When play begins:
now every pair of socks overlies every pair of feet;
now every pair of shoes overlies every pair of socks;
now every pair of underpants overlies every seat;
now every pair of pants overlies every pair of underpants;
now every foundation garment overlies every torso;
now every jacket overlies every shirt;
now every jacket overlies every dress;
now every hat overlies every head;
now every dress overlies every pair of underpants;
now every dress overlies every foundation garment.
Section 2 - The Scenario
The Dressing Room is a room.
The player carries some capris, some jeans, a corset, a plunge bra, a thong, boy-shorts, black satin D'Orsay pumps, brown leather boots, a camisole, a cocktail dress, a bolero, a cashmere shrug, a sheer wrap, and a linen tunic.
The woolly socks are a pair of socks.
The D'Orsay pumps and the brown leather boots are pairs of shoes.
The thong and the boy-shorts are pairs of underpants.
The capris and the jeans are pairs of pants.
The tunic is a shirt.
The camisole, the corset, and the plunge bra are foundation garments.
The cocktail dress is a dress.
The bolero, the cashmere shrug, and the sheer wrap are jackets. The shrug and the wrap are transparent.
Test me with "wear capris / wear jeans / i / wear thong / i / wear dress / wear corset / wear dress / i / wear wrap / i / wear boots / wear pumps / i".
Inform's default handling of wearable things does not make any rules about what can be worn together. Suppose, however, we have a game in which there are a large number of different garments, and we want to keep the player from wearing (say) more than one pair of pants at once:
"Get Me to the Church on Time"
A pair of pants and a shirt are kinds of thing. A pair of pants and a shirt are usually wearable.
Some golf pants are a pair of pants. The description is "Checked in red and green, with tiny frolicking gophers every few inches."
Some tuxedo trousers are a pair of pants. The description is "Black, pressed, and slimming."
The frilly shirt is a shirt. The description of the frilly shirt is "She insisted."
The polo shirt is a shirt. The description is "Turquoise and bright yellow, the colors selected by your golfing buddies."
The player wears the golf pants and the polo shirt. The player carries the tuxedo trousers and the frilly shirt.
The Wedding Chapel Dressing Room is a room. "The bride's dressing room is a lavish suite with closets, hangers, dressmaker's dummies, boxes of straight pins and sewing notions, combs, lotions, brushes, and hair fixatives, plus room for fifteen female attendants and a photographer. Before they shoved you out of the room you even got a glimpse of a small reference library including '1001 French Braids' and 'Corset-Lacing For Beginners.'
This is the groom's dressing room. You get a framed photograph of Elvis, a dusty mirror, and the floor space of an average toilet stall."
The dusty mirror and the photograph of Elvis are scenery in the Dressing Room. The description of the mirror is "You can't really get more than a silhouette impression of yourself." The description of Elvis is "He reminds you that you'd better get out there before the organist switches to Hound Dog."
And now the rule itself, borrowed from a later chapter:
Instead of wearing a pair of pants when the player is wearing a pair of pants (called the wrong trousers):
say "You'll have to take off [the wrong trousers] first."
Instead of wearing a shirt when the player is wearing a shirt (called the wrong top):
say "You'll have to take off [the wrong top] first."
When play begins:
say "From the other side of the door, you hear the organist move on from his instrumental interpretation of 'I Wanna Hold Your Hand' to a somewhat more spirited rendition of 'Help! I Need Somebody!'. Okay, okay, but you've been rushing things along since the 16th fairway, and you can't be more than a half-hour late... Surely that mother of hers can't blame you for that?"
Test me with "i / x trousers / wear trousers / x golf pants / take off golf pants / wear trousers / x frilly shirt / x polo shirt / wear frilly shirt / doff polo shirt / wear frilly shirt".
If we wanted to, we could make similar kinds for hats, shoes, and so on, and have a simple but effective system of clothing. A more complicated treatment might keep track of layering and describe the player's outfit differently depending on which clothes were outermost -- an example for a later chapter.
We have two things to keep track of with our layering clothing: what currently is covering something else; and what can cover something else. This implementation goes for a fairly simple treatment, assuming that each item of clothing will completely conceal those beneath it, and that we are not implementing entire sets of shirts, jackets, etc. But it will do for a demonstration.
"Bogart"
Section 1 - Clothing Behavior
First we make our relation to represent what *is* underneath another item:
Underlying relates one thing to various things. The verb to underlie means the underlying relation. The verb to be under implies the underlying relation.
And now we prevent taking a lower layer off before the thing that is worn over it:
Before taking off something which underlies something (called the impediment) which is worn by the player:
say "(first removing [the impediment])[command clarification break]";
silently try taking off the impediment;
if the noun underlies something which is worn by the player, stop the action.
Check taking off:
if the noun underlies something (called the impediment) which is worn by the player, say "[The impediment] [are] in the way." instead.
Carry out taking off:
now the noun is not underlaid by anything.
Report taking off something:
say "[We] [are] now wearing [a list of uppermost things worn by the player]." instead.
Definition: a thing is uppermost if it is not under something.
That covers order of clothing removal, but we also want to restrict what can be worn on top of what else. This time we need Inform to have some idea of what customarily can be layered on top of what other clothing:
Overlying relates one thing to various things. The verb to overlie means the overlying relation.
Covering relates a thing (called A) to a thing (called B) when the number of steps via the overlying relation from A to B is greater than 0. The verb to cover means the covering relation.
With these definitions, we can say that a jacket should go over a shirt and a shirt over an undershirt (say), and then Inform will know that a jacket will cover both shirt and undershirt.
Before wearing something when something (called the impediment) which covers the noun is worn by the player:
while the player wears something which covers the noun:
say "(first removing [the impediment])[command clarification break]";
silently try taking off the impediment;
if the player is wearing the impediment, stop the action.
Carry out wearing:
if the noun covers something (called the hidden item) worn by the player, now the hidden item underlies the noun.
Instead of looking under something which is worn by the player:
if something (called the underwear) underlies the noun, say "[We] [peek] at [the underwear]. Yup, still there.";
otherwise say "Just [us] in there."
Instead of taking inventory:
say "[if the player carries something][We]['re] carrying [a list of things carried by the player][else][We]['re] empty-handed[end if][if the player wears something]. [We] [are] wearing [a list of uppermost things worn by the player][end if]."
To peek is a verb.
Notice that our inventory only describes the things that the player can see as the upper layer of clothing.
Section 2 - The Scenario
The Trailer is a room. "A full-length mirror is the main amenity in here, and that suits you just fine." The full-length mirror is scenery in the Trailer. Instead of examining or searching the mirror, try taking inventory.
The player wears a fedora, a jacket, a shirt, some undershorts, an undershirt, some slacks, a pair of socks, and a pair of shoes.
The shirt underlies the jacket. The pair of socks underlies the pair of shoes. The undershorts underlie the slacks. The undershirt underlies the shirt.
The jacket overlies the shirt. The shoes overlie the socks. The slacks overlie the undershorts. The shirt overlies the undershirt.
Test me with "x mirror / remove fedora / remove jacket / remove shirt / remove slacks / remove undershirt / remove shoes / remove socks / remove shorts / remove undershorts".
If we further wanted to prevent the player from taking off clothes in inappropriate places, we might add something like this:
Instead of taking off something in the presence of someone who is not the player:
say "[We] [are] far too modest to strip in public."