-
Notifications
You must be signed in to change notification settings - Fork 0
/
Multikey.h
275 lines (235 loc) · 6.76 KB
/
Multikey.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
!\-----------------------------------------------------------------------------------------------------
! Multikey.h v 1.1, by Jason McWright
!
! This is a replacement for the verb routines DoLock and DoUnLock. It allows the verb routines
! DoLock and DoUnLock to recognize multiple key objects in a door's key_object property. With
! this extension you can give a door as many key objects an you like.
! It also provides additional messages that tell the player the conditions that need to be met
! in order to lock/unlock a door (open/closed, locked/unlocked, no key, wrong key).
!
! Note that these versions of DoLock/DoUnLock use some standard VMessages and some new messages
! found in this file, called "MultiKeyMessages". Nothing in this file will interfere with existing
! library messages or replacement messages.
!
! To use this extension simply include it after verblib.h.
-------------------------------------------------------------------------------------------------------\!
replace DoLock
{
local a, test_key, flag, not_xobject, not_in_player, xobject_flag
if not CheckReach(object): return false
if object is open
{
VMessage(&DoLock, 2) ! "Have to close it first..."
if xobject: if not InList(object, key_object, xobject): MultiKeyMessage(&DoLock, 5)
else: if not SearchKey(object): MultiKeyMessage(&DoLock, 6)
return true
}
if object is locked
{
VMessage(&DoLock, 1) ! already locked
if xobject: if not InList(object, key_object, xobject): MultiKeyMessage(&DoLock, 5)
else: if not SearchKey(object): MultiKeyMessage(&DoLock, 6)
return true
}
while object.#key_object > a and flag = false
{
a++
test_key = object.key_object #a
if xobject
{
if xobject = test_key
{
flag = true
not_xobject = false
xobject_flag = true
}
else: not_xobject = true
}
if not xobject
{
if Contains(player, test_key)
{
xobject = test_key
flag = true
not_in_player = false
}
else: not_in_player = true
}
}
if not_xobject = true
{
VMessage(&DoUnlock, 1) ! "Doesn't seem to work..."
return true
}
if not_in_player = true
{
VMessage(&DoUnlock, 2) ! no key that fits
return true
}
object is locked
if not object.after
{
if not xobject.after
{
if xobject_flag = true: MultiKeyMessage(&DoLock, 3) ! "Locked."
else: MultiKeyMessage(&DoLock, 3, xobject) ! "(with the...) Locked."
}
}
return true
}
replace DoUnLock
{
local a, z, test_key, flag, not_xobject, not_in_player, xobject_flag
if not CheckReach(object): return false
if object is open
{
MultiKeyMessage(&DoUnLock, 4) ! "The door is open."
if object is not locked
{
MultiKeyMessage(&DoUnLock, 7)
z = 1
}
if xobject: if not InList(object, key_object, xobject): MultiKeyMessage(&DoUnLock, 5, z)
else: if not SearchKey(object): MultiKeyMessage(&DoUnLock, 6, z)
return true
}
if object is not locked
{
VMessage(&DoUnLock, 3) ! already unlocked
if xobject: if not InList(object, key_object, xobject): MultiKeyMessage(&DoUnLock, 5)
else: if not SearchKey(object): MultiKeyMessage(&DoUnLock, 6)
return true
}
while object.#key_object > a and flag = false
{
a++
test_key = object.key_object #a
if xobject
{
if xobject = test_key
{
flag = true
not_xobject = false
xobject_flag = true
}
else: not_xobject = true
}
if not xobject
{
if Contains(player, test_key)
{
xobject = test_key
flag = true
not_in_player = false
}
else: not_in_player = true
}
}
if not_xobject = true
{
VMessage(&DoUnlock, 1) ! "Doesn't seem to do the trick..."
return true
}
if not_in_player = true
{
VMessage(&DoUnlock, 2) ! no key that fits
return true
}
object is not locked
if not object.after
{
if not xobject.after
{
if xobject_flag = true: MultiKeyMessage(&DoUnLock, 3) ! "Unlocked."
else: MultiKeyMessage(&DoUnLock, 3, xobject) ! "(with the...) Unlocked."
}
}
return true
}
routine SearchKey(door_obj)
{
local i, test_key
while door_obj.#key_object > i
{
i++
test_key = door_obj.key_object #i
if Contains(player, test_key): return true
}
return false
}
routine MultiKeyMessage(r, num, a, b)
{
if NewMultiKeyMessages(r, num, a, b): return
select r
case &Dolock
{
select num
case 3
{
if a
print "(with "; The(a); ")"
print "Locked."
return true
}
case 5
{
"(";
CThe(xobject)
" doesn't work anyway.)"
}
case 6
{
"(You'll have to find the right key anyway.)"
}
}
case &DoUnLock
{
select num
case 3
{
if a
print "(with "; The(a); ")"
print "Unlocked."
return true
}
case 4
{
print CThe(object); IsorAre(object); " open."
return true
}
case 5
{
if a = 1
{
" and ";
The(xobject)
}
else
{
"(";
CThe(xobject)
}
" doesn't work anyway.)"
}
case 6
{
if a = 1
{
" and you'll ";
}
else
{
"(You'll ";
}
"have to find the right key anyway.)"
}
case 7
{
"(It's already unlocked";
}
}
}
routine NewMultiKeyMessages(r, num, a, b) ! For replacement messages
{
return false ! Be sure to have replaced messages return true.
}