Fallout Enclosure
Example 35
★★★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".
Test me with "zap shelves / zap buffout / zap register / zap purse".
SuperDuperMart
You can see some shelves (on which are a bottle of Buffout and a container of Jet) and a cash register (closed) here.
>(Testing.)
>[1] zap shelves
You zap the shelves, destroying them and leaving a bottle of Buffout and a container of Jet behind.
>[2] zap buffout
You zap the bottle of Buffout, destroying it.
>[3] zap register
You zap the cash register, destroying it and leaving some prewar money, a coin purse and a bottle cap behind.
>[4] zap purse
You zap the coin purse, destroying it and leaving a prewar nickel behind.
You can see some shelves (on which are a bottle of Buffout and a container of Jet) and a cash register (closed) here.
>(Testing.)
>[1] zap shelves
You zap the shelves, destroying them and leaving a bottle of Buffout and a container of Jet behind.
>[2] zap buffout
You zap the bottle of Buffout, destroying it.
>[3] zap register
You zap the cash register, destroying it and leaving some prewar money, a coin purse and a bottle cap behind.
>[4] zap purse
You zap the coin purse, destroying it and leaving a prewar nickel behind.