-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathobjects.adi
More file actions
624 lines (535 loc) · 13.7 KB
/
objects.adi
File metadata and controls
624 lines (535 loc) · 13.7 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
; This is the object-oriented runtime package
; For AdvSys version 1.3
; by David Betz
; May 17, 1987
; ****************************
; HANDLER FORWARD DECLARATIONS
; ****************************
(action init)
(action update)
(action before)
(action after)
(action error)
; ****************************
; EXTENDED FUNCTION DEFINTIONS
; ****************************
(extended randomize 0)
(extended rand 1)
(extended picture 2)
(extended resource 3)
; ********************
; PROPERTY DEFINITIONS
; ********************
; These properties will be used for connections between locations
(property
north ; the location to the north
south ; the location to the south
east ; the location to the east
west ; the location to the west
up ; the location above
down) ; the location below
; Basic object properties
(property
initial-location ; the initial location of a "thing"
description ; the "long" description of a location
short-description) ; the "short" description of a location
; Connection properties
(property
parent ; the parent of an object
sibling ; the next sibling of an object
child) ; the first child of an object
; Location properties
(property
visited) ; true if location has been visited by player
; Portal properties
(property
closed ; true if the portal is closed
locked ; true if the portal is locked
key ; key to unlock the portal
other-side) ; the other portal in a pair
; **********************
; VOCABULARY DEFINITIONS
; **********************
; Some abbreviations for common commands
(synonym north n)
(synonym south s)
(synonym east e)
(synonym west w)
(synonym inventory i)
; Define the basic vocabulary
(conjunction and)
(article the that)
; ********************
; VARIABLE DEFINITIONS
; ********************
(variable
curloc ; the location of the player character
%actor ; the actor object
%dobject ; the direct object
%iobject) ; the indirect object
; *************
; THE MAIN LOOP
; *************
; handler status codes
(define ST-ABORT 1)
(define ST-CHAIN 2)
(define ST-FINISH 3)
; Handle a single command
(define (single &aux sts)
(setq sts (catch 1 (before) ST-CHAIN))
(if (= sts ST-ABORT)
(return NIL)
(if (= sts ST-CHAIN)
(progn
(if (= (catch 1 ($action) ST-CHAIN) ST-ABORT)
(return NIL))
(catch 1 (after))))))
; The main loop
(main
(catch 1 (init))
(while t
(catch 1 (update))
(if (parse)
(if (single)
(while (and (next) (single))))
(catch 1 (error)))))
; ****************************
; HANDLER SEQUENCING FUNCTIONS
; ****************************
; Abort this turn
(define (abort)
(throw 1 ST-ABORT))
; Exit from this handler, chain to the next
(define (chain)
(throw 1 ST-CHAIN))
; Finish this turn (go directly to the after handler
(define (finish)
(throw 1 ST-FINISH))
; *********************
; CONNECTION PRIMITIVES
; *********************
; Connect an object to a parent
(define (connect p c)
(setp c parent p)
(setp c sibling (getp p child))
(setp p child c))
; Connect all objects to their initial parents
(define (connect-all &aux obj maxp1 par)
(setq obj 1)
(setq maxp1 (+ $ocount 1))
(while (< obj maxp1)
(if (setq par (getp obj initial-location))
(connect par obj))
(setq obj (+ obj 1))))
; Disconnect an object from its current parent
(define (disconnect obj &aux this prev)
(setq this (getp (getp obj parent) child))
(setq prev nil)
(while this
(if (= this obj)
(progn
(if prev
(setp prev sibling (getp this sibling))
(setp (getp this parent) child (getp this sibling)))
(setp this parent nil)
(return)))
(setq prev this)
(setq this (getp this sibling))))
; Print the contents of an object (used by "look")
(define (print-contents obj prop &aux desc)
(setq obj (getp obj child))
(while obj
(if (setq desc (getp obj prop))
(progn
(print " ")
(print desc)))
(setq obj (getp obj sibling))))
; List the contents of an object (used for "inventory")
(define (list-contents obj prop &aux desc)
(setq obj (getp obj child))
(while obj
(if (setq desc (getp obj prop))
(progn
(print "\t")
(print desc)
(terpri)))
(setq obj (getp obj sibling))))
; ************************
; OBJECT CLASS DEFINITIONS
; ************************
; ***********************
; The "basic-thing" class
; ***********************
(object basic-thing
(property
parent nil ; the parent of this object
sibling nil)) ; the next sibling of this object
; ***************************
; The "location" object class
; ***************************
(object location
(property
child nil ; the first object in this location
visited nil) ; has the player been here yet?
(method (knock? obj)
T)
(method (enter obj)
(connect self obj)
T)
(method (leave obj dir &aux loc)
(if (setq loc (getp self dir))
(if (send loc knock? obj)
(progn
(disconnect obj)
(send loc enter obj)))
(progn
(print "There is no exit in that direction.\n")
nil)))
(method (describe)
(if (getp self visited)
(print (getp self short-description))
(progn
(print (getp self description))
(print-contents self description)
(setp self visited t)))
(terpri)))
; ******************
; The "portal" class
; ******************
(basic-thing portal
(method (knock? obj)
(if (getp self closed)
(progn
(print "The ")
(print (getp self short-description))
(print " is closed!\n")
nil)
T))
(method (enter obj)
(connect (getp (getp self other-side) parent) obj))
(method (open)
(if (not (getp self closed))
(progn
(print "The ")
(print (getp self short-description))
(print " is already open!\n")
nil)
(if (getp self locked)
(progn
(print "The ")
(print (getp self short-description))
(print " is locked!\n")
nil)
(progn
(setp self closed nil)
T))))
(method (close)
(if (getp self closed)
(progn
(print "The ")
(print (getp self short-description))
(print " is already closed!\n")
nil)
(progn
(setp self closed T)
T)))
(method (lock thekey)
(if (not (getp self closed))
(progn
(print "The ")
(print (getp self short-description))
(print " is not closed!\n")
nil)
(if (getp self locked)
(progn
(print "The ")
(print (getp self short-description))
(print " is already locked!\n")
nil)
(if (not (= thekey (getp self key)))
(progn
(print "It doesn't fit the lock!\n")
nil)
(progn
(setp self locked t)
T)))))
(method (unlock thekey)
(if (not (getp self closed))
(progn
(print "The ")
(print (getp self short-description))
(print " is already open!\n")
nil)
(if (not (getp self locked))
(progn
(print "The ")
(print (getp self short-description))
(print " is not locked!\n")
nil)
(if (not (= thekey (getp self key)))
(progn
(print "It doesn't fit the lock!\n")
nil)
(progn
(setp self locked nil)
T))))))
; *****************
; The "actor" class
; *****************
(basic-thing actor
(property
child nil) ; the first "thing" carried by this actor
(method (move dir)
(send (getp self parent) leave self dir))
(method (take obj)
(disconnect obj)
(connect self obj))
(method (drop obj)
(disconnect obj)
(connect (getp self parent) obj))
(method (carrying? obj)
(= (getp obj parent) self))
(method (inventory)
(cond ((getp %actor child)
(print "You are carrying:\n")
(list-contents %actor short-description))
(T (print "You are empty-handed.\n")))))
; *****************
; The "thing" class (things that can be taken)
; *****************
(basic-thing thing
(class-property
takeable t))
; ****************************
; The "stationary-thing" class (things that can't be moved)
; ****************************
(basic-thing stationary-thing)
; ***********************
; MISCELLANEOUS FUNCTIONS
; ***********************
; Complain about a noun phrase
(define (complain head n tail)
(print head)
(print-noun n)
(print tail)
(abort))
; Find an object in a location
(define (findobject loc n &aux this found)
(setq this (getp loc child))
(setq found nil)
(while this
(if (match this n)
(if found
(complain "I don't know which " n " you mean!\n")
(setq found this)))
(setq this (getp this sibling)))
found)
; Find an object in the player's current location
; (or in the player's inventory)
(define (in-location n &aux obj)
(if (or (setq obj (findobject curloc n))
(setq obj (findobject %actor n)))
obj
(complain "I don't see a " n " here!\n")))
; Find an object in the player's inventory
; (or in the player's current location)
(define (in-pocket n &aux obj)
(if (or (setq obj (findobject %actor n))
(setq obj (findobject curloc n)))
obj
(complain "You don't have a " n "!\n")))
; ***************
; ACTION DEFAULTS
; ***************
(default
(actor optional))
; ******************
; ACTION DEFINITIONS
; ******************
(action look
(verb look)
(code
(setp curloc visited nil)
(send curloc describe)))
(action a-take
(verb take get (pick up))
(direct-object)
(code
(setq %dobject (in-location $dobject))
(if (getp %dobject takeable)
(progn
(if (send %actor carrying? %dobject)
(complain "You are already carrying the " $dobject "!\n"))
(send %actor take %dobject)
(print-noun $dobject)
(print " taken.\n"))
(complain "You can't take the " $dobject "!\n"))))
(action take-err
(verb take get (pick up))
(code
(print "Take what?\n")))
(action a-drop
(verb drop (put down))
(direct-object)
(code
(setq %dobject (in-pocket $dobject))
(if (send %actor carrying? %dobject)
(progn
(send %actor drop %dobject)
(print-noun $dobject)
(print " dropped.\n"))
(complain "You aren't carrying the " $dobject "!\n"))))
(action drop-err
(verb drop (put down))
(code
(print "Drop what?\n")))
(action give
(verb give)
(direct-object)
(preposition to)
(indirect-object)
(code
(setq %dobject (in-pocket $dobject))
(setq %iobject (in-location $iobject))
(if (send %actor carrying? %dobject)
(progn
(send %actor drop %dobject)
(send %iobject take %dobject)
(print-noun $dobject)
(print " given.\n"))
(complain "You aren't carrying the " $dobject "!\n"))))
(action give-err
(verb give)
(direct-object optional)
(code
(if $dobject
(complain "Give the " $dobject " to who?\n"))
(print "Give what?\n")))
(action a-inventory
(verb inventory)
(code
(send %actor inventory)))
; ***************
; PORTAL COMMANDS
; ***************
(action a-open
(verb open)
(direct-object)
(code
(setq %dobject (in-location $dobject))
(send %dobject open)))
(action open-err
(verb open)
(code
(print "Open what?\n")))
(action a-close
(verb close)
(direct-object)
(code
(setq %dobject (in-location $dobject))
(send %dobject close)))
(action close-err
(verb close)
(code
(print "Close what?\n")))
(action a-lock
(verb lock)
(direct-object)
(preposition with)
(indirect-object)
(code
(setq %dobject (in-location $dobject))
(setq %iobject (in-pocket $iobject))
(send %dobject lock %iobject)))
(action lock-err
(verb lock)
(direct-object optional)
(code
(if $dobject
(complain "Lock the " $dobject " with what?\n"))
(print "Lock what?\n")))
(action a-unlock
(verb unlock)
(direct-object)
(preposition with)
(indirect-object)
(code
(setq %dobject (in-location $dobject))
(setq %iobject (in-pocket $iobject))
(send %dobject unlock %iobject)))
(action unlock-err
(verb unlock)
(direct-object optional)
(code
(if $dobject
(complain "Unlock the " $dobject " with what?\n"))
(print "Unlock what?\n")))
; *********************
; GAME CONTROL COMMANDS
; *********************
(action save
(verb save)
(code
(save)))
(action restore
(verb restore)
(code
(restore)))
(action restart
(verb restart)
(code
(restart)))
(action quit
(verb quit)
(code
(print "Are you sure you want to quit? ")
(if (yes-or-no)
(exit))))
; **************
; TRAVEL ACTIONS
; **************
(action go-north
(verb north (go north))
(code
(send %actor move north)))
(action go-south
(verb south (go south))
(code
(send %actor move south)))
(action go-east
(verb east (go east))
(code
(send %actor move east)))
(action go-west
(verb west (go west))
(code
(send %actor move west)))
(action go-up
(verb up (go up))
(code
(send %actor move up)))
(action go-down
(verb down (go down))
(code
(send %actor move down)))
; *******************
; HANDLER DEFINITIONS
; *******************
(define (init)
(print welcome)
(connect-all)
(setq curloc nil))
(define (update)
(if (not (= (getp adventurer parent) curloc))
(progn
(setq curloc (getp adventurer parent))
(send curloc describe))))
(define (before)
(setq %actor adventurer)
(if $actor
(progn
(setq %actor (in-location $actor))
(if (not (= (class %actor) actor))
(complain "You can't talk to a " $actor "!\n")))))
(define (after))
(define (error))