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

« back to all changes in this revision

Viewing changes to html/section17.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 17: The light and the dark</TITLE></HEAD>
 
2
<BODY BGCOLOR="#FFFFFF">
 
3
<TABLE><P>
 
4
<TR><TD Valign="top"><A HREF="contents.html">Contents</A><BR><A HREF="section16.html">Back</A><BR><A HREF="section18.html">Forward</A><TD bgcolor="#F5DEB3"><BLOCKQUOTE><H3>17. The light and the dark</H3></BLOCKQUOTE><TR><TD><TD>
 
5
<P>
 
6
 
 
7
 
 
8
The library maintains light by itself, and copes with events like:
 
9
<BLOCKQUOTE>
 
10
a total eclipse of the sun;<BR>
 
11
fusing all the lights in the house;<BR>
 
12
your lamp going out;<BR>
 
13
a dwarf stealing it and running away;<BR>
 
14
dropping a lit match which you were seeing by;<BR>
 
15
putting your lamp into an opaque box and shutting the lid;<BR>
 
16
black smoke filling up the glass jar that the lamp is in;<BR>
 
17
the dwarf with your lamp running back into your now-dark room.<BR>
 
18
</BLOCKQUOTE>
 
19
 
 
20
The point of this list is to demonstrate that light versus darkness is
 
21
tricky to get right, and best left to the library.  Your code
 
22
needs only to do something like
 
23
<PRE>
 
24
give lamp light;
 
25
remove match;
 
26
give glass_jar ~transparent;
 
27
move dwarf to Dark_Room;
 
28
</PRE>
 
29
 
 
30
and can leave the library to sort out the consequences.  As the above
 
31
suggests, the <TT>light</TT> attribute means that an object is giving off light,
 
32
or that a room is currently lit, e.g. because it is outdoors in day-time.
 
33
If you simply never want to have darkness, a
 
34
sneaky way of doing it is to put the line
 
35
<PRE>
 
36
give player light;
 
37
</PRE>
 
38
 
 
39
in <TT>Initialise</TT>.  The game works as if the player herself were glowing
 
40
enough to provide light to see by.  So there's never darkness near the
 
41
player.
 
42
<P>
 
43
<P>
 
44
 
 
45
The definition of "when there is light" is complicated, involving
 
46
recursion both up and down.  Remember that the parent of the player
 
47
object may not be a room; it may be, say, a red car whose parent is a
 
48
room.<P>
 
49
<P>
 
50
 
 
51
<B> Definition.</B><SAMP>      </SAMP>
 
52
 
 
53
There is light exactly when the parent of the player 'offers light'.
 
54
An object 'offers light' if:
 
55
<BLOCKQUOTE>
 
56
it itself has the <TT>light</TT> attribute set, <B> or</B><BR>
 
57
any of its immediate possessions 'have light', <B> or</B><BR>
 
58
it is see-through and its parent offers light;<BR>
 
59
</BLOCKQUOTE>
 
60
 
 
61
while an object 'has light' if:
 
62
<BLOCKQUOTE>
 
63
it currently has the <TT>light</TT> attribute set, <B> or</B><BR>
 
64
it is see-through and one of its immediate possessions has light, <B> or</B><BR>
 
65
any of the things it "adds to scope'' (see Chapter V) have light.<BR>
 
66
</BLOCKQUOTE>
 
67
 
 
68
The process of checking this stops as soon as light is discovered.  The
 
69
routines
 
70
<BLOCKQUOTE>
 
71
<TT>OffersLight(object)</TT> and <TT>HasLightSource(object)</TT>
 
72
</BLOCKQUOTE>
 
73
 
 
74
return true or false and might occasionally be useful.
 
75
<P>
 
76
 
 
77
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> So light is cast up and down the tree of objects.  In certain
 
78
contrived circumstances this might be troublesome: perhaps an opaque box,
 
79
whose outside is fluorescent but whose interior is dark, and which contains
 
80
an actor who needs not to have other contents of the box in scope...
 
81
The dilemma could be solved by putting an inner box in the outer one.
 
82
</SMALL>
 
83
<TR><TD><TD><P>
 
84
 
 
85
<P><TR><TD Valign="top"><IMG SRC="icons/exercise.gif" ALT="??"><TD bgcolor="#FBB9AC"><A NAME="ex32"><B>EXERCISE 32:</B><BR>(link to <A HREF="answers1/answer32.html">the answer</A>)<TR><TD><TD>  How would you code a troll who is afraid of the dark, and needs
 
86
to be bribed but will only accept a light source... so that the troll will
 
87
be as happy with a goldfish bowl containing a fluorescent jellyfish as he
 
88
would be with a lamp?
 
89
<P>
 
90
 
 
91
 
 
92
Each turn, light is reconsidered.  The presence or absence of light affects
 
93
the <TT>Look</TT>, <TT>Search</TT>, <TT>LookUnder</TT> and <TT>Examine</TT> actions, and
 
94
(since this is a common puzzle) also the <TT>Go</TT> action: you can provide
 
95
a routine called
 
96
<PRE>
 
97
DarkToDark()
 
98
</PRE>
 
99
 
 
100
and if you do then it will be called when the player goes from one dark
 
101
room into another dark one (just before the room description for the new
 
102
dark room, probably "Darkness'', is printed).  If you want, you can take
 
103
the opportunity to kill the player off or extract some other forfeit.
 
104
If you provide no such routine, then the player can move about freely
 
105
(subject to any rules which apply in the places concerned).
 
106
<P>
 
107
 
 
108
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> When the player is in darkness, the current <TT>location</TT> becomes
 
109
<TT>thedark</TT>, a special object which acts like a room and has the short name
 
110
"Darkness''.  You can change the <TT>initial</TT>, <TT>description</TT> or <TT>short_name</TT>
 
111
properties for this.  For example, your <TT>Initialise</TT> routine might set
 
112
<PRE>
 
113
    thedark.short_name = "Creepy, nasty darkness";
 
114
</PRE>
 
115
 
 
116
See <A HREF="section18.html">Section 18</A> for how 'Ruins' makes darkness menacing.
 
117
</SMALL>
 
118
<TR><TD><TD><P>
 
119
 
 
120
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex33"><B>EXERCISE 33:</B><BR>(link to <A HREF="answers1/answer33.html">the answer</A>)<TR><TD><TD> Implement a pet moth which escapes if it's ever
 
121
taken into darkness.
 
122
<P>
 
123
 
 
124
<P><TR><TD Valign="top"><IMG SRC="icons/refs.gif" ALT="*"><TD bgcolor="#EEEEEE"><B>REFERENCES:</B><BR><SMALL>  For a <TT>DarkToDark</TT> routine which discourages wandering about caves
 
125
in the dark, see 'Advent'.
 
126
</SMALL>
 
127
<TR><TD><TD><P>
 
128
 
 
129
 
 
130
</TABLE>
 
131
<HR><A HREF="contents.html">Contents</A> / <A HREF="section16.html">Back</A> / <A HREF="section18.html">Forward</A> <BR>
 
132
<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>