-
Notifications
You must be signed in to change notification settings - Fork 12
288 lines (262 loc) · 5.57 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
@program cmd-@check
1 99999 d
1 i
$include $lib/match
lvar check-obj-addr
: check-next-loop (d -- )
dup not if pop exit then
dup exit? over thing? or
me @ 3 pick controls and if
dup check-obj-addr @ execute
then
next check-next-loop
;
: check-contents (d -- )
contents check-next-loop
;
: check-exits (d -- )
exits check-next-loop
;
: exec-err (d mtypestr warnstr -- )
"On " 4 rotate unparseobj strcat
", in it's " strcat rot strcat
", " strcat swap strcat tell
;
: can-linkto? (player object -- i)
dup "link_ok" flag? if pop pop 1 exit then
controls
;
: check-exec (d mtype execstr -- )
dup "@" 1 strncmp if pop pop pop exit then
1 strcut swap pop
" " split pop
dup "$" 1 strncmp not if
dup match ok? not if
" is not a known registered program." strcat
exec-err exit
then
dup match program? not if
" is not a program." strcat
exec-err exit
then
3 pick owner over match can-linkto? not if
" is not Link_OK." strcat
exec-err exit
then
else
dup number? not if
" is not a program dbref." strcat
"@" swap strcat exec-err exit
then
dup atoi dbref ok? not if
" is not a valid program reference." strcat
"@" swap strcat exec-err exit
then
dup atoi dbref program? not if
" is not a valid program reference." strcat
"@" swap strcat exec-err exit
then
3 pick owner over atoi dbref can-linkto? not if
" is not Link_OK." strcat
"@" swap strcat exec-err exit
then
then
pop pop pop
;
: missing-err ( d s -- )
swap unparseobj
" is missing an "
strcat swap strcat
" message." strcat tell
;
: colon-err ( d s -- )
swap unparseobj
" has an unnecesary ':' at the start of its "
strcat swap strcat
" message." strcat tell
;
: check-desc (d -- )
dup desc not if
"@description" missing-err
else
"@description" over
desc check-exec
then
;
: check-succ (d -- )
dup succ not if
"@success" missing-err
else
"@success" over
succ check-exec
then
;
: check-fail (d -- )
dup fail not if
"@fail" missing-err
else
"@fail" over
fail check-exec
then
;
: check-drop (d -- )
dup drop not if
"@drop" missing-err
else
"@drop" over
drop check-exec
then
;
: check-osucc (d -- )
dup osucc not if
"@osuccess" missing-err
else
dup osucc ":" 1 strncmp not if
"@osuccess" colon-err
else pop
then
then
;
: check-ofail (d -- )
dup ofail not if
"@ofail" missing-err
else
dup ofail ":" 1 strncmp not if
"@ofail" colon-err
else pop
then
then
;
: check-odrop (d -- )
dup odrop not if
"@odrop" missing-err
else
dup odrop ":" 1 strncmp not if
"@odrop" colon-err
else pop
then
then
;
$define islocked? (d -- i) getlockstr "*UNLOCKED*" stringcmp $enddef
: islocked_always? (d -- i)
getlockstr dup "#0" stringcmp not if pop 1 exit then
dup "#" split swap pop atoi
"#" swap intostr strcat
(lockstr "#dbref")
dup "&!" over strcat strcat
3 pick stringcmp not if pop pop 1 exit then
"&" over strcat strcat "!" swap strcat
stringcmp not if 1 exit then
0
;
: check-link ( d -- )
dup getlink not if
dup unparseobj " is unlinked." strcat tell
else
dup getlink over location dbcmp if
dup islocked? not if
dup unparseobj
" is linked to it's location, but is unlocked."
strcat tell
then
else (is not linked to it's location)
dup getlink program? if
dup dup owner swap getlink can-linkto? not if
dup unparseobj
" is linked to a program which is not Link_OK."
strcat tell
then
then
then
then
pop
;
: check-room (d -- )
dup check-desc
dup islocked? if
dup islocked_always? not if
dup check-succ
then
dup check-fail
then
dup getlink if
dup check-drop
dup check-odrop
then
dup check-contents
check-exits
;
: check-exit ( d -- )
dup check-link
dup check-desc
dup getlink dup ok? if
program? not if
dup islocked_always? not if
dup check-succ
dup check-osucc
dup check-odrop
then
dup islocked? if
dup check-fail
dup check-ofail
then
then
else pop
then
pop
;
: check-thing ( d -- )
dup check-desc
dup islocked_always? not if
dup check-succ
dup check-osucc
then
dup islocked? if
dup check-fail
dup check-ofail
then
dup check-drop
dup check-odrop
check-exits
;
: check-player ( d -- )
dup check-desc
dup islocked_always? not if
dup check-succ
dup check-osucc
then
dup islocked? if
dup check-fail
dup check-ofail
then
dup check-contents
check-exits
;
: check-program ( d -- )
check-desc
;
: check-obj (d -- )
dup room? if check-room exit then
dup exit? if check-exit exit then
dup thing? if check-thing exit then
dup player? if check-player exit then
check-program
;
: main
'check-obj check-obj-addr !
strip dup not if pop "here" then
match_controlled
dup #-3 dbcmp if pop me @ getlink then
dup ok? not if pop exit then
check-obj
me @ "Check done." notify
;
.
c
q
@register #me cmd-@check=tmp/prog1
@set $tmp/prog1=3
@set $tmp/prog1=W
@action @check=#0=tmp/exit1
@link $tmp/exit1=$tmp/prog1
@register #me =tmp