Smell restrictions (Inform 7 example)

From IFWiki

"Smell example" by IFWiki

[Inform has a built-in smelling action but all it does is say "You smell nothing unexpected." Let's turn it into a 'proper' action. Normally an action doesn't say anything in the carry out rules, leaving that to the report rules. However, smelling is arguably like examining in that the act of smelling *is* getting the report so we'll copy what examining does. We'll also follow the examine model in that examining something shows its "description" property; we'll make smelling something show its "odour property".]

[First we'll create the property for all things and rooms.]
A thing has a text called odour.
A room has a text called odour.

[We need to remove the default blocking rule.]
The block smelling rule is not listed in the check smelling rulebook.

[Now we'll add a default carry out rule.]
The last carry out smelling rule:
   say "[if the odour of the noun is not empty][the odour of the noun][paragraph break][otherwise]You smell nothing unexpected.[end if]".

[For completeness we'll add a rule for NPCs smelling things.]
Report someone smelling:
   say "[The person asked] smells [the noun]."


Street is a room. "You are in a street. The sewer is below you." The odour is "You pick up a faint odour from below."

A flower is here. The description is "It's just a nice flower. You don't know what type." The odour is "It smells wonderful."

A spacesuit is here. It is wearable. Understand "space suit" and "suit" as the spacesuit. The description is "Spacesuits are wonderful things, but they make EVERYONE look fat."

Sewer is below Street. "You are in a sewer. The street is above you."

Some sewage is here. It is fixed in place. The description is "Horrible smelly sewage is everywhere in the sewer." The odour is "It reeks."


[Finally we'll add some rules to restrict smelling.]
Instead of smelling when the spacesuit is worn and the noun is not yourself and the noun is not the spacesuit:
   say "You can't smell anything while wearing the spacesuit."

Instead of smelling in the presence of the sewage when the spacesuit is not worn and the noun is not the sewage:
   say "The disgusting reek of the sewage overwhelms your nose. You can't smell anything else."

[If we wanted to write the second rule to be independent of the previous (by omitting the 'spacesuit is not worn' part) we'd just need to adjust the ordering to make sure its rule comes after the one above. Unless we say otherwise Inform will reorder the rules putting the sewage rule before the suit rule, thinking it's more specific (see 18.18 for the gory details). To override this we'd either use "last" (or first) or name the rules and use "The sewage smelling rule is listed before the spacesuit smelling rule in the instead rulebook."]


Test me with "smell / take flower / smell it / take suit / smell it / d / smell / smell sewage / smell flower / wear suit / smell / smell sewage / smell flower / smell suit / smell me".

Troubleshooting

In the example above, one might replace

[We need to remove the default blocking rule.] The block smelling rule is not listed in the check smelling rulebook.

with

[We need to remove the default blocking rule.] The report smelling rule is not listed in the report smelling rulebook.