Hello, newbie here
As a first exercise I decided to try and “fix” the layered clothing model presented in “What Not To Wear” (http://inform7.com/learn/man/Rex426.html#e426).
The issues I want to fix:
-
It only works on the player (should be easy to fix, not my focus at the moment)
-
It relates every piece of clothing in existence, which seems wasteful. My idea here is to create a set of garment archetypes and establish relations between those. Then each real garment holds a reference to the appropriate archetype.
A garment-element is a kind of thing. It has a garment-element called archetype.
The hat-archetype is a garment-element.
A hat is a kind of garment-element. The archetype of a hat is usually the hat-archetype.
The beanie, the fedora and the baseball cap are hats.
And so forth. It’s a bit of a mess; I’m having trouble working with object models in Inform. My current implementation (see below) appears to work, but it’s slow. The original code also feels more sluggish that I’d expected, but mine is even worse.
I’d appreciate any suggestions for improvements
[spoiler][code]
“Test” by blah
[Original “What Not To Wear”]
[Include Plurality by Emily Short.]
[ Not used yet, maybe useful at some point:
To decide whether (X - a value) is sibling to (Y - a value): no.
To decide whether (X - a value of kind K) is sibling to (Y - a value of kind M): if K is M, yes; no.
]
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. A garment-element has a garment-element called archetype.
Underlying relates various garment-elements to various garment-elements with fast route-finding.
The verb to underlie (it underlies, they underlie, it is underlying, it is underlaid) implies the underlying relation.
The verb to be under implies the underlying relation.
Overlying relates various garment-elements to various garment-elements.
The verb to overlie (it overlies, they overlie, it is overlying) implies 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 (it covers, they cover, it is covering, it is covered) implies the covering relation.
Definition: a garment-element is uppermost if it is not under something opaque.
Check taking off:
if the noun underlies something (called the impediment) which is worn by the actor, say “[The impediment] is in the way.” instead.
Carry out taking off:
now the noun is not underlaid by anything.
Report taking off something:
say “You are now wearing [a list of garments worn by the player].” instead. [uppermost removed]
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.
[ ORIGINAL:
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.
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 garment-region 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.
]
Before wearing something:
repeat with worn-garment running through garments worn by the actor:
if the archetype of the worn-garment covers the archetype of the noun:
say “(first removing [the worn-garment])[command clarification break]”;
silently try taking off the worn-garment;
if the actor is wearing the worn-garment, stop the action;
let regions-covered-by-noun be the list of garment-regions covered by the archetype of the noun;
say “regions-covered-by-noun = [regions-covered-by-noun].”;
repeat with worn-garment running through garments worn by the actor:
let I be regions-covered-by-noun;
repeat with region-covered-by-worn-garment running through garment-regions covered by the archetype of the worn-garment:
if region-covered-by-worn-garment is not listed in regions-covered-by-noun, remove region-covered-by-worn-garment from I, if present;
repeat with shared-region running through I:
let A be the layering depth of the worn-garment for shared-region;
let B be the layering depth of the noun for shared-region;
if A is B:
say “shared-region = [shared-region], depth of worn-garment = [A], depth of the noun = [B]”;
say “(first taking off [the worn-garment])[command clarification break]”;
silently try taking off the worn-garment;
if the actor is wearing the worn-garment, stop the action;
break.
Carry out wearing:
repeat with worn-garment running through things worn by the actor:
if the archetype of the noun covers the archetype of the worn-garment, now the worn-garment underlies the noun.
[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 garment) for (target-region - garment-region):
let N be 0;
if the archetype of the chosen garment covers the archetype of the target-region:
let N be the number of steps via the overlying relation from the archetype of the chosen garment to the archetype of the target-region;
decide on N.
[
To decide what number is the layering depth of (chosen garment - a thing):
let N be 0;
if the chosen garment covers a garment-region (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 (garment regions), broken down according to their relevance to clothing:]
A garment-region is a kind of garment-element.
A torso, a hip, a head, a pair of legs, and a pair of feet are kinds of garment-region.
One head, one torso, one pair of legs, one pair of feet and one hip are part of every person. [One pair of legs is part of every person. …]
The torso-archetype is a torso.
The hip-archetype is a hip.
The head-archetype is a head.
The legs-archetype is a pair of legs.
The feet-archetype is a pair of feet.
The archetype of a torso is usually torso-archetype.
The archetype of a hip is usually hip-archetype.
The archetype of a head is usually head-archetype.
The archetype of a pair of legs is usually legs-archetype.
The archetype of a pair of feet is usually feet-archetype.
[And now we make some categories of clothing:]
A garment is a kind of garment-element. A garment can be transparent. A garment is usually wearable. [A garment has a garment called archetype.]
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.
The pants-archetype is a pair of pants.
The underpants-archetype is a pair of underpants.
The foundation-archetype is a foundation garment.
The socks-archetype is a pair of socks.
The shoes-archetype is a pair of shoes.
The jacket-archetype is a jacket.
The hat-archetype is a hat.
The dress-archetype is a dress.
The shirt-archetype is a shirt.
The archetype of a pair of pants is usually pants-archetype.
The archetype of a pair of underpants is usually underpants-archetype.
The archetype of a foundation garment is usually foundation-archetype.
The archetype of a pair of socks is usually socks-archetype.
The archetype of a pair of shoes is usually shoes-archetype.
The archetype of a jacket is usually jacket-archetype.
The archetype of a hat is usually hat-archetype.
The archetype of a dress is usually dress-archetype.
The archetype of a shirt is usually shirt-archetype.
Instead of taking inventory: [uppermost removed]
say “You’re carrying [a list of things carried by the player][if the player wears something]. You are wearing [a list of garments worn by the player][end if].”
When play begins:
now socks-archetype overlies feet-archetype;
now shoes-archetype overlies socks-archetype;
now underpants-archetype overlies hip-archetype;
now pants-archetype overlies legs-archetype;
now pants-archetype overlies underpants-archetype;
now foundation-archetype overlies torso-archetype;
now jacket-archetype overlies shirt-archetype;
now jacket-archetype overlies dress-archetype;
now hat-archetype overlies head-archetype;
now dress-archetype overlies underpants-archetype;
now dress-archetype overlies foundation-archetype.
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, woolly socks, and a linen tunic.
The thong has the description “a red barely-there crime against good taste”.
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.
[Aaron, Ben, Carl, David, Earl, Fargo, Gabriel, Harry, Ian, Jack, Kyle, Larry, Michael, Nate, Ozzy and Patrick are men in the Dressing Room.]
[The player is wearing the thong and the jeans.]
Test legs with “wear thong / wear jeans”.
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”.
[/code][/spoiler]