§19.15. Two rulebooks used internally
Rulebooks handle almost all of the important tasks which an Inform work of IF must carry out in order to keep play going. We have seen them used in clarifying the player's command, supplying missing ingredients, processing the action to see what should happen, responding, and so on: by this point in the documentation, it must look as if Inform uses rulebooks for everything.
This is nearly true. There is not actually a super-rulebook controlling everything. (Such a super-rulebook would need to repeat itself and never finish, something a rulebook is not allowed to do.) Instead, what happens during play looks like so:
1. Following the "when play begins" rulebook.
2(a). Reading and parsing a command into an action;
2(b). Following the "action processing" rulebook;
2(c). Following the "turn sequence" rulebook.
until the game has finished.
3. Following the "when play ends" rulebook.
The command parser occasionally calls on the services of activity rulebooks to help it, but otherwise gets on with its job in ways that we do not "see" as Inform 7 users. The rest of what happens involves rulebooks, and in particular two important beneath-the-surface rulebooks: action processing and the turn sequence.
The action processing rules are used whenever an action must be tried, by whoever tries it. This usually happens in response to player commands, but not always: it might happen because of a "try...", and it can certainly interrupt an existing action.
The turn sequence rules are used at the end of each turn, and include housekeeping as well as timekeeping. They consult the "every turn" rulebook, and advance the time of day, among other useful tasks.
In general, we should only modify the operation of these two crucial rulebooks as a last resort. Play can evidently fall to pieces if they cease to work normally.
|Start of Chapter 19: Rulebooks|
|Back to §19.14. Abide by|
|Onward to §19.16. The Laws for Sorting Rulebooks|
Suppose we want to prevent the player from touching anything electrified -- not just as a response to TOUCH OBJECT, but at any time when the action would require contact with the object in question.
A thing can be safe or electrified. A thing is usually safe.
The Open Field is a room. "At this end of the field is a wire fence separating farm country from the government testing grounds beyond." The wire fence is an electrified thing in Open Field. It is scenery. The description of the wire fence is "Built into the fence is [a list of things which are part of the fence]." The scary box is an electrified container. It is part of wire fence. In the scary box is an alluring prize.
The player carries a flashlight, a grappling hook, a very thick rubber glove, and a length of rope. The glove is wearable.
This is the electrocution-wisdom rule:
if the player wears the very thick rubber glove, make no decision;
if the action requires a touchable noun and the noun is electrified, say "You fear touching [the noun]." instead;
if the action requires a touchable second noun and the second noun is electrified, say "You fear touching [the second noun]." instead.
The electrocution-wisdom rule is listed before the basic accessibility rule in the action-processing rules.
Before touching the scary box:
say "You can't help noticing a bright red sticker on the surface of the box." [This rule will fire even if we are not wearing the glove, because Before rules occur before basic accessibility.]
Instead of opening the scary box:
say "The scary box seems to be super-glued shut." [This one won't, because Instead rules occur after basic accessibility.]
Test me with "touch fence / touch box / open box / wear glove / open box".
In a game with tight timing, it is sometimes friendliest to the player to let him LOOK and EXAMINE as much as necessary without being penalized.
Examining something is acting fast. Looking is acting fast.
Now we need a rule which, just at the right moment, stops the turn sequence rulebook in the cast of our new fast-acting actions:
The take visual actions out of world rule is listed before the every turn stage rule in the turn sequence rules.
This is the take visual actions out of world rule: if acting fast, rule succeeds.
Thus the rest of the turn sequence rulebook is omitted for looking or examining: in effect, they become out-of-world actions like "saving the game". If we wanted to add, say, taking inventory to the list of instant activities, we would just need to define it as acting fast, too.
Now the scenario for testing:
When play begins:
say "You are cornered by a pack of zombie wolves, armed only with a torch and a pair of pinking shears. This may be your last moment on earth, unless you can think fast!"
Cleft is a room. "You're backed into a cleft in the granite: behind you are only steep, high faces of stone, and before you a narrow passage."
The plural of zombie wolf is zombie wolves. A zombie wolf is a kind of animal. Four zombie wolves are in Cleft.
Rule for writing a paragraph about zombie wolves:
say "The good news is that there isn't much space in which for the zombie wolves to attack.";
now every zombie wolf is mentioned.
A steep high face of stone is scenery in Cleft. Understand "rock" as the stone. The description is "Now that you look more closely, there appear to be pitons driven into the rock."
Some pitons are part of the stone. The description of the pitons is "It looks as though someone else has made this ascent before."
Instead of climbing the stone, try going up. Instead of climbing the pitons, try going up.
Above the Cleft is Clifftop.
Every turn when the location is Cleft:
say "Alas, your time has run out. The alpha wolf springs--";
end the story.
Every turn when the location is Clifftop:
say "After a breathless climb, you emerge at last onto the open clifftop.";
end the story finally.
Test me with "x me / x stone / x pitons / climb pitons".
Here we move to a systematic way of giving different durations to different actions, including even variations on the same act -- so that for instance climbing a steep hill might take several minutes more than other going actions. We do this by setting a number, "work duration", to represent the number of minutes consumed by a given action, and then consulting a rulebook to find out how long the past turn's action should take. By default, an action will take 1 minute.
We'll start by emulating the behavior of "Uptempo": each turn we'll set the clock forward most of the way, then check to see what has changed since the last turn, print any relevant events, and only then set the clock forward the final minute. The exception is when an action is set to take no time at all; in that case, we'll skip the rest of the turn sequence rules entirely.
Work duration is a number that varies.
now work duration is 0;
increment the turn count;
follow the time allotment rules;
if work duration is 0, rule succeeds;
increase the time of day by (work duration minutes - 1 minute).
The time allotment rules are a rulebook.
A time allotment rule for examining or looking:
now work duration is 0;
A time allotment rule for going:
now work duration is 2;
A time allotment rule for going up:
now work duration is 5;
A time allotment rule for waiting:
now work duration is 10;
The last time allotment rule:
now work duration is 1.
When play begins: now the right hand status line is "[time of day]".
The Quai is a room. "An attractive park at the edge of the river Aude: here you can wander among palm trees, and watch cyclists go by on the bike path; in the water there are ducks. In the cafe to your north, patrons sip their pastis; and above you is the medieval walled city and its castle."
The Cafe is north of the Quai. "A charming collection of umbrella-shaded tables, from which one can watch the river and the walls of the city beyond. The noise of traffic is only a minor distraction."
The City is above the Quai.
After going to the City:
say "You struggle uphill for some distance...";
continue the action.
At 9:15 AM:
say "The bells ring out from Place Carnot."
Test me with "z / n / s / u".
Escape from the Seraglio
"Escape from the Seraglio"
Section 1 - Special Announcement Rules
The number of takes this turn is a number that varies. Every turn: now the number of takes this turn is 0.
The friskily announce items from multiple object lists rule is listed instead of the announce items from multiple object lists rule in the action-processing rules.
This is the friskily announce items from multiple object lists rule:
if the current item from the multiple object list is not nothing:
increment the number of takes this turn;
say "[if number of takes this turn is 1]First [otherwise if the number of takes this turn is 2]And then [otherwise if the number of takes this turn is 3]And I suppose also [otherwise if the number of takes this turn is 7]And on we wearily go with [otherwise if the number of takes this turn is 9]Oh, and not forgetting [otherwise]And [end if][the current item from the multiple object list]: [run paragraph on]";
if the current item from the multiple object list is not nothing, say "[current item from the multiple object list]: [run paragraph on]".
Rule for deciding whether all includes the person asked: it does not.
Rule for deciding whether all includes a person when taking: it does not.
Section 2 - The Scenario
The Palm Chamber is a room. Sarissa is a woman in the Palm Chamber.
The Palm Chamber contains a bottle of ink, a quill pen, a tangerine, a bunch of grapes, a length of silken rope, some perfume, a cake of incense, a fitted leather bodice, a sapphire anklet, an illustrated novel, a whip, and a heavy iron key.
A persuasion rule for asking Sarissa to try taking the key:
say "Sarissa nervously demurs, knowing that it is forbidden.";
A persuasion rule: persuasion succeeds.
Test me with "take all / drop all / sarissa, take all".