Contents | Index | < Browse | Browse >
4.1. The Flow of Execution
The main loop of the game consists of a series of
phases. The built-in routine $phase will return the number
of the phase currently executing (see the flow diagram and
Section 7.12 for the number of each of the phases). At the
beginning of each turn, all active Daemons are executed for
each Actor on the Actor list -- in the REVERSE order in
which the Actors were activated. This is so newly activated
Actors don't act before the older Actors have a chance to
act. The Daemons are executed in the order in which they
were activated.
After all Daemons have executed for all Actors, a
series of phases are executed for each Actor on the Actor
list (in the reverse order of Actor activation). The loop
progresses downward in an orderly fashion unless interrupted
by a call to $exit. For information on $exit see Section
4.2. The following are the phases which are executed for
each Actor on the Actor list:
Clear Sentence The global variables Verb, Conj, Numd,
Dobj, Prep, and Iobj are set to 0. This
is done in a separate phase to facilitate
the implementation of incremental sen-
tences such as "Take. The red ball."
Input A new line buffer is prompted for and read
if the line buffer is empty and the
current Actor is interactive.
The current Actor is deleted from the
Actor list and execution continues start-
ing with the next Actor if the line buffer
is empty and the current Actor is NOT
interactive.
Parse All upper case letters in the line buffer
are transformed into lower case letters.
An attempt is then made at parsing the
line buffer into a Verb, Direct Objects, a
Preposition, and an Indirect Object. Note
that unambiguous abbreviations of words
are recognized by the parser (for example,
if the words "newt" and "newspaper" are in
the vocabulary, "new" is ambiguous but
"news" is an abbreviation of "newspaper").
An appropriate message is printed if this
does not succeed and execution continues
from the Input phase.
ADL sentences are typically of the form
"Verb DobjList Prep Iobj" "Verb Iobj
DobjList", or "Iobj, String". This is an
overly simplistic description - for a full
specification see Chapter 9.
DWIM An object may be ambiguous either through
the lack of a modifier or through the use
of a modifier without a noun (e.g. typing
"Take the ball" when there is both a "red
ball" and a "blue ball", or typing "Take
red" in the same situation).
An ADL routine named "DWIMI" is used if
the Indirect Object is ambiguous. DWIMI
is called once for each Object that could
possibly be the one meant by the player.
If EXACTLY one of these calls returns a
non-zero value then the corresponding
Object becomes the Indirect Object. How-
ever, if DWIMI never returns a non-zero
value or if it returns a non-zero value
more than once, the player is told to be
more specific and execution continues
starting with the Clear Sentence phase
above.
An ADL routine named "DWIMD" is used if
any of the Direct Objects are ambiguous.
DWIMD is called for the Objects in ques-
tion just like DWIMI.
Execution The following phases are executed for
every Direct Object in the Direct Object
list. They are executed exactly once if
there are no Direct Objects. This loop is
the heart of the ADL system and is where
the player's commands are actually carried
out.
Actor ACTION The ACTION routine of
the current Actor is
executed. It typically
checks the sentence and
possibly modifies it.
This allows the handling
of cases like "Take the
beer then drink it"
(where "it" needs to be
massaged to mean "beer")
and "Go north. Again."
(where "Again" needs to
be transformed into "Go
north").
Verb PREACT The PREACT routine of
the current Verb is exe-
cuted. It typically
guards against incorrect
use of multiple Direct
Objects, or the use of
Indirect Objects or
strings where such use
doesn't make sense. It
also might check that
all objects named are
available for use.
Iobj ACTION The ACTION routine of
the current Indirect
Object is executed.
This is where some
object-specific actions
are performed. For
example, the sentence
"Put the coins in the
slot" might be handled
here if putting coins
into the slot (as
opposed to a box or a
bag) causes something
special to happen. If
the Indirect Object is a
string then the ACTION
routine of the prede-
clared ADL Object named
STRING is executed.
Dobj ACTION The ACTION routine of
the current Direct
Object is executed.
This is where most
object-specific actions
are performed. For
example, the sentence
"Rub the lamp" might be
handled here if rubbing
the lamp is different
than rubbing any other
Object. The ACTION rou-
tine of the predeclared
ADL Object STRING is
executed if the Direct
Object is a string.
Verb ACTION The ACTION routine of
the current Verb is exe-
cuted. This is where
general default actions
are usually handled.
For example, the sen-
tence "Rub the floor"
might result in the mes-
sage "Rubbing that
object is not useful."
Room ACTION The ACTION routine of the current Actor's
location is executed once the above loop
has examined all of the Direct Objects.
This routine is typically a "transition"
routine -- that is, it might check whether
the current verb is "north" and move the
current actor to the appropriate location
(it might check other directions as
well!).