Inform 7 Home Page / Documentation
§10.4. Glass and Other Damage-Prone Substances
Just as Inform normally assumes everything is solid, it also assumes that these solid objects will not buckle, crack, break or deform under pressure, and cannot be fragmented. But breakability adds realism, and breakage need not be negative: sometimes we want the player to break her way in to something.
In IF the word DROP is more often used to mean "put down" or "leave behind" than "let go from a height": so it is perhaps unfair that in Ming Vase something fragile, when dropped, shatters (into nothing). In Spring Cleaning, fragile objects must be explicitly attacked by the player in order to break, and although they leave no tangible debris behind, their loss is at least remembered. Kyoto provides a general-purpose model for things being thrown at other things, with consequences including things moving (even between rooms) as well as breaking each other.
Debris from breakages is to be avoided if possible because it means keeping track of increasing numbers of objects. But we can increase realism by allowing something to have a visibly "broken" state, which it changes to when it breaks, rather than simply vanishing. Terracottissima provides for broken and unbroken flowerpots in this way.
Since "part of" allows us to have two objects joined together into what the player sees as one, it also gives us a natural seam which allows the whole to be broken back down into its component parts, and this is the neatest way of providing a breakage into pieces. Paddington demonstrates a cutting action which allows component parts to be cut away from their holders but will only make small surface gashes in any individual thing: so the player can cut something up, but only into the pieces we specifically choose to allow. Cutting also forces an opening into containers.
See Combat and Death for a robot that breaks into its component limbs when shot with a blaster
See Goal-Seeking Characters for a character who eats donuts, leaving crumbs on the floor
See Volume, Height, Weight for containers breaking under the weight of their contents
See Ropes for cutting up string into up to 35 different pieces of different lengths - a limit the player is unlikely to find out about, but a limit all the same, and an expensive solution since we need 35 different things for the "debris" when string is "broken"
|Start of Chapter 10: Physics: Substances, Ropes, Energy and Weight|
|Back to §10.3. Dispensers and Supplies of Small Objects|
|Onward to §10.5. Volume, Height, Weight|
In emulation of a certain annoying aspect of the original Adventure, in which there is a Ming vase that cannot safely be dropped:
A thing can be strong or fragile. A thing is usually strong.
Instead of attacking or dropping a fragile thing:
now the noun is nowhere;
say "[The noun] breaks into thousands of pieces!"
The Cave is a room. The Ming vase is carried by the player. The vase is fragile.
We could also implement an additional refinement from Adventure, that a fragile thing is safe if dropped when there is a cushion nearby.
The pillow is a portable supporter. It is carried by the player.
Instead of dropping a fragile thing when the pillow is in the location: try putting the noun on the pillow instead.
After putting a fragile thing on the pillow:
say "You set [the noun] down gently on the pillow."
Test me with "drop pillow / drop vase / get vase / get pillow / drop vase".
In this rule, the pillow is the second noun; if we had a general rule about setting fragile things on soft things, we could say "You set [the noun] down gently on [the second noun]." for the same effect.
If we wanted to be more refined, we would provide extra code so that breaking a container or a supporter would leave behind their contents. We will see how to do that later.
Here we have a destruction action that allows the player to break any fragile items. Once destroyed, these things are removed from play, but we can still refer to them: they are now off-stage. This makes it easy for our sulking character to list the ones that have been destroyed:
Instead of attacking something fragile:
say "You smash [the noun] to smithereens!";
now the noun is nowhere.
Every turn when a knick-knack is off-stage and Granny Blue can see the player:
say "'Ohh,' whimpers Granny to herself softly. 'How I will miss [the list of off-stage knick-knacks]!'"
The Parlor is a room. Granny Blue is a woman in the Parlor. A china lamb, a porcelain milkmaid, a frolicking Dutch cow, and a crystal unicorn are knick-knacks in the Parlor.
Test me with "break lamb / break milkmaid / break cow / break unicorn".
Suppose we intend a game in which the player needs to cut things open on a regular basis. We'll want to check whether he has the proper tools handy, and deal graciously with commands such as CUT [something] when no tool is specified. So:
Understand "cut [something] with [something]" as cutting it with.
Instead of cutting something:
if a blade (called the edge) is held by the player,
try cutting the noun with the edge;
otherwise say "Your fingernails are not sharp enough."
Check cutting it with:
if the noun is a person, say "That would hurt." instead;
if the second noun is not a blade, say "[The second noun] has not got enough of a blade." instead.
Carry out cutting it with:
increment the count of rips of the noun.
Report cutting it with:
say "You slash [the noun] with [the second noun]."
We'll need a way to account for all these cuts and rips.
Definition: a thing is ripped if the count of rips of it > 0. A thing has a number called the count of rips. After examining something ripped, say "You see [the count of rips of the noun in words] rip[s] in [the noun][if something is in the noun], revealing [a list of things in the noun][end if]."
Moreover, because open containers normally list their contents when examined but we'd prefer Paddington's to be mentioned in the ripping paragraph:
The examine containers rule does nothing when examining the teddy bear.
So far, so good. But suppose that we'd like cutting also to make containers be permanently open and impossible to close again. We could write an "instead" rule, but that would mean that only our instead instructions would take effect, overriding the normal cutting it with rules entirely. Better would be to add a second carry out rule:
Carry out cutting a container with something:
now the noun is open;
now the noun is unopenable.
Now our rule will occur whenever a container is cut, but play will still go on to the reporting stage. And indeed we can add more of these, of varying degrees of specificity:
Carry out cutting something which is part of something with something:
move the noun to the player.
Carry out cutting the quilt with something:
now the description of the quilt is "Horribly tattered."
For that matter, we might want to add a report rule as well, to occur after the "You slash..." rule, so that every time the player cuts something open which has contents, the contents will be listed.
Report cutting it with:
if the noun is open and the noun contains something,
say "Visible within [is-are a list of things in the noun]."
This time we do not add the condition to the rule (i.e., Report cutting an open noun...) If we did, this report rule would be more specific than the general report rule, and would occur first.
The teddy bear is a closed thing in the Safehouse. The description is "Fluffy[if the head is part of the bear], with an outsized head[otherwise], but headless[end if]." The head is a closed part of the teddy bear. In the bear is a large wad of stuffing. In the head are a small wad of stuffing and a packet of smuggled diamonds.
The quilt is in the Safehouse. The description is "An old but comforting quilt."
Here is a final nicety to get rid of the "which is closed" statement on our closed unopenable teddy bear, using an "activity" rule:
After printing the name of a closed unopenable container:
omit contents in listing.
Test me with "cut quilt with bear / cut quilt with switchblade / examine quilt / cut bear with switchblade / again / examine bear / cut head with switchblade / get diamonds / mourn loss of innocence".
This easiest way to do this uses the "printing the name of" activity, which will come up in the following chapter:
A flowerpot is a kind of thing. Understand "pot" as a flowerpot.
A flowerpot can be unbroken or broken. After dropping an unbroken flowerpot: say "Crack!"; now the noun is broken. Understand the broken property as describing a flowerpot.
Before printing the name of a broken flowerpot, say "broken ". Before printing the name of an unbroken flowerpot: if a flowerpot is broken, say "unbroken ".
Before printing the plural name of a broken flowerpot, say "broken ". Before printing the plural name of an unbroken flowerpot: if a flowerpot is broken, say "unbroken ".
The Herb Garden is a room. In the Herb Garden are ten unbroken flowerpots.
Suppose we want to expand the function of the existing THROW SOMETHING AT command so that a thrown object actually does make contact most of the time. A glance at the Actions index tells us that the Throwing it at rulebook currently looks like this:
Throwing something at something (past tense thrown it at)
"drop [something held] at/against/on/onto [something]"
an actor throwing something at
implicitly remove thrown clothing rule
an actor throwing something at
futile to throw things at inanimate objects rule
an actor throwing something at
block throwing at rule
Some of those still look useful. We want to leave the "implicitly remove thrown clothing" rule, for instance -- no fair having the player throw a hat that's on his head. On the other hand, the "futile to throw things at inanimate objects rule" is going to have to go, because that would prevent us from ever being able to complete the throwing command. So let's get rid of that:
The futile to throw things at inanimate objects rule is not listed in the check throwing it at rules.
That "block throwing at" rule also looks sinister: any "block..." rule in the standard actions library is there to print a message telling the player he can't do what he's asked to do.
But it's not enough to ignore it, the way we did the "futile" rule. Since we are only expanding the command to affect inanimate objects, let's replace the "block throwing at" rule with a different one which will only prevent the player throwing things at people:
The block throwing at people rule is listed instead of the block throwing at rule in the check throwing it at rules.
This is the block throwing at people rule:
if the second noun is a person, say "That might be construed as an attack." instead.
Now we've changed the command so that some action can sometimes be carried out here -- but we don't have any rules for what happens. It's time to create some rules for our model world.
A thing can be hard or soft. A thing can be fragile or strong. Shape is a kind of value. The shapes are round, flat, and linear. A thing has shape.
If we're actually going to allow throwing, we might want to add a couple of extra checks to the rulebook to make sure that this happens when it ought:
Check throwing it at (this is the block juggling rule):
if the player is carrying the second noun, say "It would be difficult to throw at something you are yourself holding." instead.
Check throwing it at (this is the avoid throwing things into themselves rule):
if the second noun is within the noun, say "That would be a nice magic trick." instead.
And then the rules for the action itself:
Carry out throwing it at (this is the check aerodynamics rule):
if the noun is flat:
move noun to location;
say "[The noun], unwieldy, flutters to the ground.";
That "rule succeeds" ends the action here, if the noun is flat. If not, Inform goes on to the next rule in the carry out throwing it at rulebook:
Carry out throwing it at (this is the contact rule):
say "[The noun] hits [the second noun].[paragraph break]";
if the second noun is fragile and the noun is hard:
destroy the second noun.
Carry out throwing it at (this is the landing rule):
let destination be the location;
if the second noun is on a supporter (called endtable), let destination be the endtable;
if the second noun is a supporter, let destination be the second noun;
move the noun to the destination;
if the noun is fragile and the second noun is hard:
destroy the noun;
say "[The noun] lands [if the destination is the location]nearby[otherwise]on [the destination][end if]."
These rules are assuming some backup information, so let's provide that as well:
Reliance relates a thing (called X) to a thing (called Y) when X is part of Y or X is in Y or X is on Y. The verb to be relying on means the reliance relation.
To destroy (item - a thing):
let home be the holder of the item;
if the item is part of something (called the superstructure), let home be the holder of the superstructure;
if the item is visible:
say "[The item] breaks[if something is relying on the item], leaving [a list of things which are relying on the item] behind[end if].";
if something is relying on the item,
now all the things which are relying on the item are in the home;
now the item is nowhere.
Now suppose we'd like to add some further cases for what happens if the player breaks a fragile door this way:
To destroy (item - a door):
now the item is open;
now the item is unopenable;
say "[The item] smashes."
Rule for printing the name of an unopenable open door while not throwing something at something:
say "open doorway".
This works, except that objects will continue to "strike" open, unopenable doors, with the result that the player can smash the same door over and over. What we need is another rule, after the aerodynamics rule and before the contact rule, that tells Inform how to handle throwing things at open doors.
This is the flying through doorways rule:
if the second noun is an open door:
let the distant room be the other side of the second noun;
move the noun to the distant room;
say "[The noun] flies out of sight into [the distant room].";
If the original rulebook is one we wrote ourselves, we could just add that rule in the proper spot in order. If we got it from an extension, though, we might need to put it in the right place explicitly:
The flying through doorways rule is listed before the contact rule in the carry out throwing it at rules.
The magic of rulebooks is that they allow authors to amend each other's work (or the Standard Rules) with a fair amount of freedom. A well-written extension will give individual names to its rules, to allow subsequent authors to modify the function of the extension without too much trouble.
Now for an actual scenario with which to test this:
The sliding paper screen is a door. It is north of the Moss Garden and south of the Study. The paper screen is fragile.
The player carries a netsuke and a shamisen. The description of the netsuke is "A weight for the cord on which you wear your purse or your medicine box. This particular one has the shape of a bullfrog, carved from green stone." The netsuke is round, hard, and strong. Understand "green" or "stone" or "bullfrog" as the netsuke.
The description of the shamisen is "An instrument you have only begun to learn to play." The shamisen is linear, soft, and fragile. A neck is part of the shamisen. The neck is linear, strong, and hard. A body is part of the shamisen. The body is round, fragile, and soft. A string is part of the shamisen. The string is linear, soft, and strong. The printed name of the body is "[if the body is not part of the shamisen]shamisen [end if]body". The printed name of the neck is "[if the neck is not part of the shamisen]shamisen [end if]neck". Understand "shamisen" as the body when the body is not part of the shamisen. Understand "shamisen" as the neck when the neck is not part of the shamisen.
The description of the Study is "A restful three-tatami room." The Study contains a calligraphy box and a hanging scroll. The initial appearance of the hanging scroll is "A handsome scroll depicts two women in kimonos crossing a bridge; Mount Fuji is in the background." The calligraphy box contains a brush. The box is openable and closed. The brush is hard, linear, and strong. The calligraphy box is round, soft, and strong. The hanging scroll is flat, soft, and strong.
The description of the Moss Garden is "Earlier today, you arranged three leaves on the moss in imitation of autumn. They must not be disturbed." The leaves are scenery in the Moss Garden. Instead of throwing something at the leaves: say "You spent too long over their placement."
Test one with "open screen / throw netsuke at screen / n / get netsuke / close screen / get scroll / throw scroll at screen / throw netsuke at scroll / get netsuke / throw netsuke at shamisen / drop netsuke".
Test two with "throw shamisen at netsuke / get all / throw netsuke at screen / get netsuke / throw netsuke at door / s / get netsuke".