Some Assembly Required

Example 332

Building different styles of shirt from component sleeves and collars.

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 held by 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".
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".
Boutique
Still festively strewn with the confetti and streamers of the Grand Opening party, and still almost totally customer-free.

>(Testing.)

>[1] sew collar to shirt
You sew the collar on, creating a shell.

>[2] i
You are carrying:
a shell
three short sleeves
two long sleeves
a collar

>[3] sew short sleeve to shirt
You sew the short sleeve on, creating an experiment.

>[4] g
You sew the short sleeve on, creating a polo shirt.

>[5] i
You are carrying:
a polo shirt
a short sleeve
two long sleeves
a collar

>[6] x polo shirt
Stitched to the polo shirt are two short sleeves and a collar.

>[7] cut collar
You carefully snip the collar free.

>[8] i
You are carrying:
two collars
a t-shirt
a short sleeve
two long sleeves

>[9] cut shirt
You cut up the t-shirt, snipping off two short sleeves.

>[10] sew long sleeve to shirt
You sew the long sleeve on, creating an experiment.

>[11] i
You are carrying:
three short sleeves
two collars
an experiment
a long sleeve

>[12] sew long sleeve to shirt
You sew the long sleeve on, creating a mandarin blouse.

>[13] i
You are carrying:
three short sleeves
two collars
a mandarin blouse

>[14] sew collar to shirt
You sew the collar on, creating a button-down.

>[15] g
The button-down already sports a collar.

>[16] i
You are carrying:
three short sleeves
a button-down
a collar

>[17] wear button-down
You put on the button-down.