~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to inform-6.31.1/include/links.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
!links.h library extension file
 
2
!By Jayson Smith
 
3
!This library provides some classes and the basic interfacing routines
 
4
!and verbs for Spider and Web style linkable objects.  If you have no idea
 
5
!what I'm talking about, please go play Andrew Plotkin's excellent game,
 
6
!"Spider and Web".  Also, a brief summary can be found in the piece of
 
7
!paper in links.inf, the sample game.
 
8
!Note that this code was not, repeat not, used in Spider and Web.  In fact,
 
9
!S&W was what inspired me to write this library!
 
10
!This library and the sample game may be distributed freely.  Having said
 
11
!that, if you use any of this code in a game, I'd appreciate at least a
 
12
!"Thank you" in your game.
 
13
!Notes:
 
14
!This code is very poorly formatted E.G. no indentation.  Also, it may
 
15
!be written sloppily, but appears not to have much in the way of bugs.
 
16
!If you do find any bugs, please send me a letter at jaybird@coldmail.com.
 
17
!Classes in this library are:
 
18
!actuator, used for actuators E.G. buttons, switches, timers, etc, which 
 
19
!are used to activate or trigger devices.
 
20
!device is for devices, E.G. beepers, lights, blenders, etc.
 
21
!switch is what it sounds like, an actuator that is a switch, with proper
 
22
!entries for switchon and switchoff to call the turnon and turnoff routines.
 
23
!remote is used for a device which is meant to remotely control an actuator.
 
24
!This is used for such things as the voice and key transmitters in Spider
 
25
!and Web, and the remote control in my links.inf sample game.
 
26
!Attributes you need to put on your linkable objects are:
 
27
!pluslink indicates that this object has a plus link.  This is usually, but
 
28
!not always, used for actuators, at least it always was in Spider and Web.
 
29
!minuslink means this object has a minus link, which is usually, but not
 
30
!always, used for devices, although it always was in Spider and Web.
 
31
!Note that you can't link two objects with the same type of link together.
 
32
!Also note that once you've chosen what types of links to use for actuators
 
33
!and devices, it's a good idea to stick to those types so as not to confuse
 
34
!anybody.
 
35
!Routines and properties you should provide and know about:
 
36
!turnon is a string or routine which gets executed or run when a device is
 
37
!turned on via an actuator.  It can do anything you want, even kill the
 
38
!player, win the game, or anything else that can normally be done.
 
39
!turnoff is the opposite of turnon in that it is what is run/executed when
 
40
!a device is turned off.
 
41
!brief is what happens when a device is activated briefly, such as the push
 
42
!of a button.  If it's a device which does the same thing either way, such
 
43
!as a bomb, you can just have the brief call self.turnon to get the same
 
44
!result.
 
45
!baseunit is what tells a remote control what to control.  Although it
 
46
!really doesn't get used in this code, your code may use it if it wishes.
 
47
!Also note that remote baseunits needn't have any means by which to activate
 
48
!them, because that's what the remotes are there for!
 
49
!Have fun with this!
 
50
 
 
51
attribute remotely;
 
52
attribute pluslink;
 
53
attribute minuslink;
 
54
fake_action linktake;
 
55
fake_action linkdrop;
 
56
global temporary;
 
57
class actuator
 
58
with before [;
 
59
take:
 
60
linkedtake(self,self.linkto);
 
61
drop:
 
62
linkeddrop(self,self.linkto);
 
63
],
 
64
with after [;
 
65
examine: print "It has a ";
 
66
if (self has pluslink) print "plus link ";
 
67
else print "minus link ";
 
68
print " which ";
 
69
if (self.linkto==0) "isn't connected to anything.";
 
70
else print "is connected to ",(a) self.linkto,".^";
 
71
],
 
72
with turnon [;
 
73
if (self.linkto==0) {
 
74
if (self hasnt remotely) "Nothing happens.";
 
75
else "You perceive no other effect.";
 
76
};
 
77
temporary=self.linkto;
 
78
temporary.turnon();
 
79
rtrue;
 
80
],
 
81
with turnoff [;
 
82
if (self.linkto==0) {
 
83
if (self hasnt remotely) "Nothing happens.";
 
84
else "You perceive no other effect.";
 
85
};
 
86
temporary=self.linkto;
 
87
temporary.turnoff();
 
88
],
 
89
with brief [;
 
90
if (self.linkto==0) {
 
91
if (self hasnt remotely) "Nothing happens.";
 
92
else "You perceive no other effect.";
 
93
};
 
94
temporary=self.linkto;
 
95
temporary.brief();
 
96
],
 
97
with linkto;
 
98
class remote
 
99
with baseunit, turnon, turnoff, brief;
 
100
class device
 
101
with before [;
 
102
take:
 
103
linkedtake(self,self.linkto);
 
104
drop:
 
105
linkeddrop(self,self.linkto);
 
106
],
 
107
with after [;
 
108
examine: print "It has a ";
 
109
if (self has pluslink) print "plus link ";
 
110
else print "minus link ";
 
111
print "which ";
 
112
if (self.linkto==0) "isn't connected to anything.";
 
113
else print "is connected to ",(a) self.linkto,".^";
 
114
],
 
115
with brief, turnon, turnoff, linkto;
 
116
class switch
 
117
class actuator
 
118
has switchable,
 
119
with after [;
 
120
switchon: print "You flip ",(the) self," on.^";
 
121
self.turnon();
 
122
rtrue;
 
123
switchoff: print "You flip ",(the) self," off.^";
 
124
self.turnoff();
 
125
rtrue;
 
126
];
 
127
verb "link" "connect" * noun "to" noun -> link;
 
128
verb "unlink" "disconnect"
 
129
* noun -> unlink;
 
130
[linksub;
 
131
if (noun has remotely) {
 
132
print (the) noun," doesn't have a link.  It works via ",(the) self.baseunit,".^";
 
133
rtrue;
 
134
};
 
135
if (second has remotely) {
 
136
print (the) second," doesn't have a link.  It works via",
 
137
(the) second.baseunit,".^";
 
138
rtrue;
 
139
};
 
140
if (noun has pluslink && (second has minuslink)) {
 
141
link(noun,second);
 
142
rtrue;
 
143
}
 
144
if (noun has minuslink && (second has pluslink)) {
 
145
link(noun,second);
 
146
rtrue;
 
147
}
 
148
if (noun has pluslink && (second has pluslink)) {
 
149
"You can't link those together because they both have plus links.^";
 
150
}
 
151
if (noun has minuslink && (second has minuslink)) {
 
152
"You can't link those together because they both have minus links.";
 
153
}
 
154
if (noun hasnt pluslink && (noun hasnt minuslink)) {
 
155
print (the) noun," doesn't have a link so you can't link it to anything.^";
 
156
rtrue;
 
157
}
 
158
if (second hasnt pluslink && (second hasnt minuslink)) {
 
159
print (the) second," doesn't have a link so you can't link anything to it.^";
 
160
rtrue;
 
161
}
 
162
if (noun.linkto~=0) {
 
163
print (the) noun," is already linked to ",(the) noun.linkto,".  You'll 
 
164
have to unlink it first.^";
 
165
rtrue;
 
166
}
 
167
if (second.linkto~=0) {
 
168
print (the) second," is already linked to ",(the) second.linkto,".  You'll 
 
169
have to unlink it first.^";
 
170
rtrue;
 
171
}
 
172
];
 
173
[link i j;
 
174
i.linkto=j;
 
175
j.linkto=i;
 
176
print "You link ",(the) i," to ",(the) j,".^";
 
177
if (indirectlycontains(player,i) && (indirectlycontains(player,j) == false)) {
 
178
print "You also let go of ",(the) i,".^";
 
179
move i to parent(player);
 
180
};
 
181
if (indirectlycontains(player,i) == false && (indirectlycontains(player,j))) {
 
182
print "You also let go of ",(the) j,".^";
 
183
move j to parent(player);
 
184
};
 
185
if (i has on) {
 
186
j.turnon();
 
187
}
 
188
];
 
189
[unlinksub;
 
190
if (noun has remotely) {
 
191
print (the) noun," doesn't have a link.  It works via ", (the) noun.baseunit,".^";
 
192
rtrue;
 
193
};
 
194
if (second==0) {
 
195
if (noun provides linkto) {
 
196
temporary=noun.linkto;
 
197
if (temporary==0) "That isn't linked to anything.^";
 
198
print "You unlink ",(the) noun," from ",(the) temporary,".^";
 
199
noun.linkto=0;
 
200
temporary.linkto=0;
 
201
if (noun has on) {
 
202
temporary.turnoff();
 
203
}
 
204
rtrue;
 
205
}
 
206
}
 
207
else if (noun provides linkto && (second provides linkto)) {
 
208
if (noun.linkto ~= second) "Those aren't linked together.^";
 
209
print "You unlink ",(the) noun," from ",(the) second,".^";
 
210
noun.linkto=0;
 
211
second.linkto=0;
 
212
if (noun has on) {
 
213
second.turnoff();
 
214
}
 
215
rtrue;
 
216
}
 
217
else if (noun provides ~linkto) {
 
218
print (the) noun," doesn't have a link.^";
 
219
rtrue;
 
220
}
 
221
else if (second~=0) {
 
222
if (second provides ~linkto) {
 
223
print (the) second," doesn't have a link.^";
 
224
rtrue;
 
225
}
 
226
}
 
227
];
 
228
[linkedtake i j;
 
229
if (j==0) rtrue;
 
230
if (i in player) rtrue;
 
231
if (i has static || (i has scenery)) rtrue;
 
232
action=##linktake;
 
233
if (runroutines(j,before) ~= 0 || (j has static || (j has scenery))) {
 
234
print "You'll have to disconnect ",(the) i," from ",(the) j," first.^";
 
235
rtrue;
 
236
}
 
237
else {
 
238
if (runroutines(i,before)~=0 || (i has static || (i has scenery))) {
 
239
print "You'll have to disconnect ",(the) i," from ",(the) j," first.^";
 
240
rtrue;
 
241
}
 
242
else
 
243
if (j hasnt concealed && j hasnt static) move j to player;
 
244
if (i hasnt static && i hasnt concealed) move i to player;
 
245
action=##linktake;
 
246
if (runroutines(j,after) ~= 0) rtrue;
 
247
print "You take ",(the) i," and ",(the) j," connected to it.^";
 
248
rtrue;
 
249
}
 
250
];
 
251
[linkeddrop i j;
 
252
if (j==0) rtrue;
 
253
if (i notin player) rtrue;
 
254
action=##linkdrop;
 
255
if (runroutines(j,before)~=0) {
 
256
print "You'll have to disconnect ",(the) i," from ",(the) j," first.^";
 
257
rtrue;
 
258
}
 
259
else {
 
260
if (runroutines(i,before)~=0) {
 
261
print "You'll have to disconnect ",(the) i," from ",(the) j," first.^";
 
262
rtrue;
 
263
}
 
264
else
 
265
move i to location;
 
266
move j to location;
 
267
action=##linkdrop;
 
268
if (runroutines(j,after)~=0) rtrue;
 
269
print "You drop ",(the) i," and ",(the) j," connected to it.^";
 
270
rtrue;
 
271
}
 
272
];