-
Notifications
You must be signed in to change notification settings - Fork 38
/
util.mud
257 lines (213 loc) · 7.25 KB
/
util.mud
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
"(c) Copyright 1978, Massachusetts Institute of Technology. All rights reserved."
"UTILITY FUNCTIONS ONLY!"
;"Functions for hacking objects, rooms, winner, etc.
REMOVE-OBJECT <obj>
Remove an object from any room or ,WINNER or its container.
INSERT-OBJECT <obj> <room>
Put the object into the room.
REMOVE-FROM <obj1> <obj2>
Make obj1 no longer contain obj2.
INSERT-INTO <obj1> <obj2>
Make obj1 contain obj2.
TAKE-OBJECT <obj> {OPTIONAL} <adv>
Make <obj> one of <adv>'s possessions.
DROP-OBJECT <obj> {OPTIONAL} <adv>
Remove <obj> from <adv>'s possessions.
DROP-IF <obj> {OPTIONAL} <adv>
Do a DROP-OBJECT if <adv> has <obj> as a possession.
SNARF-OBJECT <obj1> <obj2>
Find <obj1>, REMOVE-OBJECT it, and <INSERT-INTO <obj2> <obj1>.
IN-ROOM? <obj> {OPTIONAL} <room>
Is <obj> anywhere inside the room (but not with ,WINNER)?
IN-ROOM? does not check OVISON!
HACKABLE?
Is <obj> either in ,HERE or in current vehicle.
Uses SEARCH-LIST so completely groks visibility, containers, etc.
"
\
<DEFINE REMOVE-OBJECT (OBJ "OPTIONAL" (WINNER ,WINNER) "AUX" OCAN OROOM)
#DECL ((OBJ) OBJECT (OCAN) <OR OBJECT FALSE> (OROOM) <OR FALSE ROOM>
(WINNER) ADV)
<COND (<SET OCAN <OCAN .OBJ>>
<PUT .OCAN ,OCONTENTS <SPLICE-OUT .OBJ <OCONTENTS .OCAN>>>)
(<SET OROOM <OROOM .OBJ>>
<PUT .OROOM ,ROBJS <SPLICE-OUT .OBJ <ROBJS .OROOM>>>)
(<MEMQ .OBJ <AOBJS .WINNER>>
<PUT .WINNER ,AOBJS <SPLICE-OUT .OBJ <AOBJS .WINNER>>>)>
<PUT .OBJ ,OROOM <>>
<PUT .OBJ ,OCAN <>>>
<DEFINE INSERT-OBJECT (OBJ ROOM)
#DECL ((OBJ) OBJECT (ROOM) ROOM)
<PUT .ROOM ,ROBJS (<PUT .OBJ ,OROOM .ROOM> !<ROBJS .ROOM>)>>
<DEFINE INSERT-INTO (CNT OBJ)
#DECL ((OBJ CNT) OBJECT)
<PUT .CNT ,OCONTENTS (.OBJ !<OCONTENTS .CNT>)>
<PUT .OBJ ,OCAN .CNT>
<PUT .OBJ ,OROOM <>>>
<DEFINE REMOVE-FROM (CNT OBJ)
#DECL ((OBJ CNT) OBJECT)
<PUT .CNT ,OCONTENTS <SPLICE-OUT .OBJ <OCONTENTS .CNT>>>
<PUT .OBJ ,OCAN <>>>
<DEFINE TAKE-OBJECT (OBJ "OPTIONAL" (WINNER ,WINNER))
#DECL ((OBJ) OBJECT (WINNER) ADV)
<TRO .OBJ ,TOUCHBIT>
<PUT .WINNER ,AOBJS (<PUT .OBJ ,OROOM <>> !<AOBJS .WINNER>)>>
<DEFINE DROP-OBJECT (OBJ "OPTIONAL" (WINNER ,WINNER))
#DECL ((OBJ) OBJECT (WINNER) ADV)
<PUT .WINNER ,AOBJS <SPLICE-OUT .OBJ <AOBJS .WINNER>>>>
<DEFINE DROP-IF (OBJ "OPTIONAL" (WINNER ,WINNER))
#DECL ((OBJ) OBJECT (WINNER) ADV)
<AND <MEMQ .OBJ <AOBJS .WINNER>>
<DROP-OBJECT .OBJ .WINNER>>>
<DEFINE SNARF-OBJECT (WHO WHAT)
#DECL ((WHO WHAT) OBJECT)
<COND (<AND <N==? <OCAN .WHAT> .WHO>
<OR <OROOM .WHAT>
<OCAN .WHAT>>>
<REMOVE-OBJECT .WHAT>
<INSERT-INTO .WHO .WHAT>)
(.WHO)>>
<DEFINE IN-ROOM? (OBJ "OPTIONAL" (HERE ,HERE) "AUX" TOBJ)
#DECL ((OBJ) OBJECT (HERE) ROOM (TOBJ) <OR OBJECT FALSE>)
<COND (<SET TOBJ <OCAN .OBJ>>
<COND (<==? <OROOM .TOBJ> .HERE>)
(<TRNN .TOBJ ,SEARCHBIT>
<IN-ROOM? .TOBJ .HERE>)>)
(<==? <OROOM .OBJ> .HERE>)>>
<DEFINE HACKABLE? (OBJ RM "AUX" (AV <AVEHICLE ,WINNER>))
#DECL ((OBJ) OBJECT (RM) ROOM (AV) <OR FALSE OBJECT>)
<COND (.AV
<SEARCH-LIST <OID .OBJ> <OCONTENTS .AV> <>>)
(<SEARCH-LIST <OID .OBJ> <ROBJS .RM> <>>)>>
\
"Villains, thieves, and scoundrels"
"ROB-ADV: TAKE ALL OF THE VALUABLES A HACKER IS CARRYING"
<DEFINE ROB-ADV (WIN NEWLIST)
#DECL ((WIN) ADV (NEWLIST) <LIST [REST OBJECT]>)
<MAPF <>
<FUNCTION (X) #DECL ((X) OBJECT)
<COND (<AND <G? <OTVAL .X> 0> <NOT <TRNN .X ,SACREDBIT>>>
<PUT .WIN ,AOBJS <SPLICE-OUT .X <AOBJS .WIN>>>
<SET NEWLIST (.X !.NEWLIST)>)>>
<AOBJS .WIN>>
.NEWLIST>
"ROB-ROOM: TAKE VALUABLES FROM A ROOM, PROBABILISTICALLY"
<DEFINE ROB-ROOM (RM NEWLIST PROB)
#DECL ((RM) ROOM (NEWLIST) <LIST [REST OBJECT]> (PROB) FIX)
<MAPF <>
<FUNCTION (X) #DECL ((X) OBJECT)
<COND (<AND <G? <OTVAL .X> 0>
<NOT <TRNN .X ,SACREDBIT>>
<TRNN .X ,OVISON>
<PROB .PROB>>
<REMOVE-OBJECT .X>
<TRO .X ,TOUCHBIT>
<SET NEWLIST (.X !.NEWLIST)>)
(<OACTOR .X>
<SET NEWLIST <ROB-ADV <OACTOR .X> .NEWLIST>>)>>
<ROBJS .RM>>
.NEWLIST>
<DEFINE GET-DEMON (ID "AUX" (OBJ <FIND-OBJ .ID>) (DEMS ,DEMONS))
#DECL ((ID) STRING (OBJ) OBJECT (DEMS) <LIST [REST HACK]>)
<MAPF <>
<FUNCTION (X) #DECL ((X) HACK)
<COND (<==? <HOBJ .X> .OBJ> <MAPLEAVE .X>)>>
.DEMS>>
\
; "The guiding light"
<DEFINE LIGHT-SOURCE (ME)
#DECL ((ME) ADV)
<MAPF <>
<FUNCTION (X)
#DECL ((X) OBJECT)
<COND (<NOT <TRNN .X ,LIGHTBIT>>
<MAPLEAVE .X>)>>
<AOBJS .ME>>>
;"LIT? --
IS THERE ANY LIGHT SOURCE IN THIS ROOM"
<SETG ALWAYS-LIT <>>
<DEFINE LIT? (RM "AUX" (WIN ,WINNER))
#DECL ((RM) ROOM (WIN) ADV)
<OR <RTRNN .RM ,RLIGHTBIT>
<LFCN <ROBJS .RM>>
<AND <==? ,HERE .RM> <LFCN <AOBJS .WIN>>>
<AND <N==? .WIN ,PLAYER>
<==? ,HERE <AROOM ,PLAYER>>
<LFCN <AOBJS ,PLAYER>>>
,ALWAYS-LIT>>
<DEFINE LFCN LFCN (L "AUX" Y)
#DECL ((L) <LIST [REST OBJECT]> (Y) ADV (LFCN) ACTIVATION)
<MAPF <>
<FUNCTION (X)
#DECL ((X) OBJECT)
<AND <TRNN .X ,ONBIT> <MAPLEAVE T>>
<COND (<AND <TRNN .X ,OVISON>
<OR <TRNN .X ,OPENBIT>
<TRNN .X ,TRANSBIT>>>
<MAPF <>
<FUNCTION (X) #DECL ((X) OBJECT)
<COND (<TRNN .X ,ONBIT>
<RETURN T .LFCN>)>>
<OCONTENTS .X>>)>
<COND (<AND <TRNN .X ,ACTORBIT>
<LFCN <AOBJS <SET Y <OACTOR .X>>>>>
<MAPLEAVE T>)>>
.L>>
\
; "Random Utilities"
<DEFINE PICK-ONE (VEC)
#DECL ((VEC) VECTOR)
<NTH .VEC <+ 1 <MOD <RANDOM> <LENGTH .VEC>>>>>
<SETG LUCKY!-FLAG T>
<DEFINE PROB (GOODLUCK "OPTIONAL" (BADLUCK .GOODLUCK))
#DECL ((GOODLUCK BADLUCK) FIX)
<L=? <MOD <RANDOM> 100>
<COND (,LUCKY!-FLAG .GOODLUCK)
(.BADLUCK)>>>
<DEFINE YES/NO (NO-IS-BAD? "AUX" (INBUF ,INBUF) (INCHAN ,INCHAN))
#DECL ((INBUF) STRING (NO-IS-BAD?) <OR ATOM FALSE> (INCHAN) CHANNEL)
<RESET .INCHAN>
<TTY-INIT <>>
<READST .INBUF "" <>>
<COND (.NO-IS-BAD?
<NOT <MEMQ <1 .INBUF> "NnfF">>)
(T
<MEMQ <1 .INBUF> "TtYy">)>>
<DEFINE SPLICE-OUT (OBJ AL)
#DECL ((AL) LIST (OBJ) ANY)
<COND (<==? <1 .AL> .OBJ> <REST .AL>)
(T
<REPEAT ((NL <REST .AL>) (OL .AL))
#DECL ((NL) LIST (OL) <LIST ANY>)
<COND (<==? <1 .NL> .OBJ>
<PUTREST .OL <REST .NL>>
<RETURN .AL>)
(<SET OL .NL> <SET NL <REST .NL>>)>>)>>
\
; "These are for debugging only!"
<DEFINE FLUSH-OBJ ("TUPLE" OBJS "AUX" (WINNER ,WINNER))
#DECL ((OBJS) <TUPLE [REST STRING]> (WINNER) ADV)
<MAPF <>
<FUNCTION (X "AUX" (Y <FIND-OBJ .X>))
#DECL ((X) STRING (Y) OBJECT)
<AND <MEMQ .Y <AOBJS .WINNER>>
<DROP-OBJECT <FIND-OBJ .X> .WINNER>>>
.OBJS>>
<DEFINE CONS-OBJ ("TUPLE" OBJS "AUX" (WINNER ,WINNER))
#DECL ((OBJS) <TUPLE [REST STRING]> (WINNER) ADV)
<MAPF <>
<FUNCTION (X "AUX" (Y <FIND-OBJ .X>))
#DECL ((Y) OBJECT (X) STRING)
<OR <MEMQ .Y <AOBJS .WINNER>>
<TAKE-OBJECT <FIND-OBJ .X> .WINNER>>>
.OBJS>>
; "No applause, please."
<DEFINE PERFORM (FCN VB "OPTIONAL" (OBJ1 <>) (OBJ2 <>)
"AUX" R (PV ,PRSVEC) (PRSA <PRSA>) (PRSO <PRSO>) (PRSI <PRSI>))
#DECL ((VB PRSA) VERB (OBJ1 OBJ2 PRSO PRSI) <OR FALSE OBJECT>
(R) ANY (PV) VECTOR (FCN) <OR ATOM NOFFSET APPLICABLE>)
<PUT <PUT <PUT .PV 3 .OBJ2> 2 .OBJ1> 1 .VB>
<SET R <COND (<TYPE? .FCN ATOM NOFFSET> <APPLY-RANDOM .FCN>)
(<APPLY .FCN>)>>
<PUT <PUT <PUT .PV 3 .PRSI> 2 .PRSO> 1 .PRSA>
.R>