~ubuntu-branches/ubuntu/gutsy/inform/gutsy

« back to all changes in this revision

Viewing changes to html/section12.html

  • Committer: Bazaar Package Importer
  • Author(s): Mark Baker
  • Date: 2004-03-29 23:52:44 UTC
  • Revision ID: james.westby@ubuntu.com-20040329235244-fox1z1yv7d6vojoo
Tags: upstream-6.30
ImportĀ upstreamĀ versionĀ 6.30

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<HTML><HEAD><TITLE>Section 12: Doors</TITLE></HEAD>
 
2
<BODY BGCOLOR="#FFFFFF">
 
3
<TABLE></SMALL>
 
4
<TR><TD><TD><P>
 
5
<TR><TD Valign="top"><A HREF="contents.html">Contents</A><BR><A HREF="section11.html">Back</A><BR><A HREF="section13.html">Forward</A><TD bgcolor="#F5DEB3"><BLOCKQUOTE><H3>12. Doors</H3></BLOCKQUOTE><TR><TD><TD>
 
6
<P>
 
7
 
 
8
<BLOCKQUOTE>
 
9
Standing in front of you to the north, however, is a door surpassing
 
10
anything you could have imagined. For starters, its massive lock is
 
11
wrapped in a dozen six-inch thick iron chains. In addition, a certain
 
12
five-headed monster...
 
13
<P>...Marc Blank and P. David Lebling, <I>'Enchanter'</I></BLOCKQUOTE>
 
14
<BLOCKQUOTE>
 
15
<BR>O for doors to be open and an invite with gilded edges
 
16
<BR>To dine with Lord Lobcock and Count Asthma.
 
17
<BR><P>...W. H. Auden (<B>1907</B>--<B>1973</B>), <I>Song</I></BLOCKQUOTE>
 
18
<P>
 
19
 
 
20
 
 
21
A useful kind of object is a <TT>door</TT>.  This need not literally be a door:
 
22
it might be a rope-bridge or a ladder, for instance.  To set up a <TT>door</TT>:
 
23
 
 
24
<P>(a) --  give the object the <TT>door</TT> attribute;
 
25
<P>(b) --  set its <TT>door_to</TT> property to the destination;
 
26
<P>(c) --  set its <TT>door_dir</TT> property to the direction which that would be,
 
27
such as <TT>n_to</TT>;
 
28
<P>(d) --  make the room's map connection in that direction point to the
 
29
door itself.
 
30
 
 
31
\PAR
 
32
For example, here is a closed and locked door, blocking the
 
33
way into the 'Ruins' shrine:
 
34
<PRE>
 
35
Object Corridor "Stooped Corridor"
 
36
  with description "A low, square-cut corridor, running north to south,
 
37
           stooping you over.",
 
38
       n_to Square_Chamber,
 
39
       s_to StoneDoor;
 
40
Object -&#62; StoneDoor "stone door"
 
41
  with description "It's just a big stone door.",
 
42
       name "door" "massive" "big" "stone" "yellow",
 
43
       when_closed
 
44
           "Passage south is barred by a massive door of yellow stone.",
 
45
       when_open
 
46
           "The great yellow stone door to the south is open.",
 
47
       door_to Shrine,
 
48
       door_dir s_to,
 
49
       with_key stone_key
 
50
  has  static door openable lockable locked;
 
51
</PRE>
 
52
 
 
53
Note that the door is <TT>static</TT> -- otherwise the player could pick it up and
 
54
walk away with it!  The properties <TT>when_closed</TT> and <TT>when_open</TT> give
 
55
descriptions appropriate for the door in these two states.
 
56
 
 
57
<P>
 
58
 
 
59
Doors are rather one-way: they are only really present on one side.  If
 
60
a door needs to be accessible (openable and lockable from either side),
 
61
a neat trick is to make it present in both locations and to fix the
 
62
<TT>door_to</TT> and <TT>door_dir</TT> to the right way round for whichever side the player
 
63
is on.  Here, then, is a two-way door:
 
64
<PRE>
 
65
Object -&#62; StoneDoor "stone door"
 
66
  with description "It's just a big stone door.",
 
67
       name "door" "massive" "big" "stone" "yellow",
 
68
       when_closed
 
69
           "The passage is barred by a massive door of yellow stone.",
 
70
       when_open
 
71
           "The great yellow stone door is open.",
 
72
       door_to
 
73
       [;  if (location==Corridor) return Shrine; return Corridor; ],
 
74
       door_dir
 
75
       [;  if (location==Shrine) return n_to; return s_to; ],
 
76
       with_key stone_key,
 
77
       found_in  Corridor  Shrine,
 
78
  has  static door openable lockable locked;
 
79
</PRE>
 
80
 
 
81
where <TT>Corridor</TT> has <TT>s_to</TT> set to <TT>StoneDoor</TT>, and <TT>Shrine</TT> has
 
82
<TT>n_to</TT> set to <TT>StoneDoor</TT>.  The door can now be opened, closed, entered,
 
83
locked or unlocked from either side.  We could also make <TT>when_open</TT>
 
84
and <TT>when_closed</TT> into routines to print different descriptions of the
 
85
door on each side.
 
86
<P>
 
87
 
 
88
At first sight, it isn't obvious why doors have the <TT>door_dir</TT>
 
89
 
 
90
property.  Why does a door need to know which way it faces?  The point is
 
91
that two different actions cause the player to go through the door.
 
92
Suppose the door is in the south wall.  The player may type "go south'',
 
93
which directly causes the action <TT>Go s_obj</TT>.  Or the player may "enter
 
94
door'' or "go through door'', causing <TT>Enter the_door</TT>.  Provided the
 
95
door is actually open, the <TT>Enter</TT> action then looks at the door's
 
96
<TT>door_dir</TT> property, finds that the door faces south and generates
 
97
the action <TT>Go s_obj</TT>.  Thus, however the player tries to go through
 
98
the door, it is the <TT>Go</TT> action that finally results.
 
99
<P>
 
100
 
 
101
This has an important consequence: if you put <TT>before</TT> and <TT>after</TT>
 
102
routines on the <TT>Enter</TT> action for the <TT>StoneDoor</TT>, they only apply to
 
103
a player typing "enter door" and not to one just typing "south".  So
 
104
one safe way is to trap the <TT>Go</TT> action.  A neater method is to
 
105
put some code into a <TT>door_to</TT> routine.  If a <TT>door_to</TT>
 
106
routine returns 0 instead of a room, then the player is told that
 
107
the door "leads nowhere'' (like the famous broken bridge of Avignon).
 
108
If <TT>door_to</TT> returns 1, or 'true', then the library stops the action
 
109
on the assumption that something has happened and the player has been
 
110
told already.
 
111
<P>
 
112
 
 
113
<P><TR><TD Valign="top"><IMG SRC="icons/exercise.gif" ALT="??"><TD bgcolor="#FBB9AC"><A NAME="ex13"><B>EXERCISE 13:</B><BR>(link to <A HREF="answers1/answer13.html">the answer</A>)<TR><TD><TD> Create a plank bridge across a chasm, which collapses if
 
114
the player walks across it while carrying
 
115
anything.
 
116
<P>
 
117
 
 
118
<P><TR><TD Valign="top"><IMG SRC="icons/refs.gif" ALT="*"><TD bgcolor="#EEEEEE"><B>REFERENCES:</B><BR><SMALL>  'Advent' is especially rich in two-way doors: the steel grate
 
119
in the streambed, two bridges (one of crystal, the other of rickety
 
120
wood) and a door with rusty hinges.  See also the iron gate in 'Balances'.
 
121
</TABLE>
 
122
<HR><A HREF="contents.html">Contents</A> / <A HREF="section11.html">Back</A> / <A HREF="section13.html">Forward</A> <BR>
 
123
<A HREF="chapter1.html">Chapter I</A> / <A HREF="chapter2.html">Chapter II</A> / <A HREF="chapter3.html">Chapter III</A> / <A HREF="chapter4.html">Chapter IV</A> / <A HREF="chapter5.html">Chapter V</A> / <A HREF="chapter6.html">Chapter VI</A> / <A HREF="chapterA.html">Appendix</A><HR><SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright &#169; Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>