-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathstdlib.dg
More file actions
6730 lines (5410 loc) · 166 KB
/
Copy pathstdlib.dg
File metadata and controls
6730 lines (5410 loc) · 166 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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(library version) Library version 1.2.3.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Global variables
%% The following variables may be queried directly from the story, but the
%% library gets confused if you modify them directly with (now). Instead, use
%% the predicates mentioned in the comments:
%% Update with (select player $):
(global variable (current player $))
%% Update with (enter $) or (move player to $ $):
(global variable (current room $))
%% Update with (increase score by $) or (decrease score by $):
(global variable (current score $))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Style class declarations
%% These declarations are merely hints to the backend and/or interpreter.
%% Attributes can be ignored based on context. On the Z-machine backend, for
%% instance, 'height' only has an effect on (status bar $) boxes, whereas
%% 'width' and 'float' only affect (div $) boxes that are nested inside a
%% (status bar $) box. The height and width may be specified in em/ch or %.
(style class @status)
height: 1em;
(style class @score)
float: right;
width: 17ch;
(style class @initial-spacer)
margin-bottom: 2em;
(style class @title)
font-family: Geneva, sans-serif;
font-weight: bold;
font-size: 1.4em;
margin-top: 1em;
(style class @roomheader)
margin-top: .3em;
font-family: Geneva, sans-serif;
(style class @gameover)
font-weight: bold;
margin-top: 1em;
margin-bottom: 1em;
(style class @bold)
font-weight: bold;
(style class @italic)
font-style: italic;
%% For messages that come from the program, rather than from the game world
(style class @meta)
font-face: sans-serif;
font-style: italic;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Interface declarations for predicates typically defined in story code
(interface (name $<Obj))
(interface (tagged name $<Obj))
(interface (descr $<Obj))
(interface (initial appearance $<Obj))
(interface (appearance $<Obj))
(interface (appearance $<Obj $<Rel $<Loc))
(interface (feel $<Obj))
(interface (room header $<Obj))
(interface (look $<Obj))
(interface (dict $<Obj))
(interface (plural dict $<Obj))
(interface (heads $<Obj))
(interface (from $<Room go $>Dir to $>Obj))
(interface (from $<Room through $>Door to $>Obj))
(interface ($<Room attracts $>Obj))
(interface (maximum score $>Number))
(interface (clarify location of $<Obj))
(interface ($>Obj provides light))
(interface ($<Key unlocks $<Door))
(interface ($<Door blocks passage))
(interface ($<Door blocks light))
(interface (fungible $<Obj1 $<Obj2))
(interface (on every tick in $<Room))
(interface (understand $<Words as $>Action))
(interface (understand $<Words))
(interface (describe action $<Action))
(interface (unlikely $<Action))
(interface (very unlikely $<Action))
(interface (before $<Action))
(interface (refuse $<Action))
(interface (instead of $<Action))
(interface (prevent $<Action))
(interface (perform $<Action))
(interface (after $<Action))
(interface (action $<Action requires $>Obj to be present))
(interface (action $<Action requires $>Obj to be touched))
(interface (group-before $<GroupAction))
(interface (group-refuse $<GroupAction))
(interface (group-instead of $<GroupAction))
(interface (group-prevent $<GroupAction))
(interface (group-perform $<GroupAction))
(interface (group-after $<GroupAction))
(interface (narrate taking $<Obj))
(interface (narrate removing $<Obj))
(interface (narrate wearing $<Obj))
(interface (narrate putting $<Obj $<Rel $<Dest))
(interface (narrate dropping $<Obj))
(interface (narrate opening $<Obj))
(interface (narrate closing $<Obj))
(interface (narrate unlocking $<Obj with $<Key))
(interface (narrate locking $<Obj with $<Key))
(interface (narrate switching on $<Obj))
(interface (narrate switching off $<Obj))
(interface (narrate eating $<Obj))
(interface (narrate climbing $<Obj))
(interface (narrate entering $<Obj))
(interface (narrate leaving $<Obj))
(interface (narrate leaving $<Room $<Dir))
(interface (narrate leaving $<Room $<Dir with $<Obj))
(interface (narrate leaving $<Room $<Dir by $<Vehicle))
(interface (narrate failing to look $<Dir))
(interface (describe topic $<Topic))
(interface (default action $<Obj $>Action))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Relations
%% Avoid compiler warnings with --warn-not-topic
#in
#on
#partof
#heldby
#wornby
#under
#behind
(relation #in) %% Note: #in is also a direction
(relation #on)
(relation #partof)
(relation #heldby)
(relation #wornby)
(relation #under)
(relation #behind)
(name #in) in
(name #on) on
(name #partof) part of
(name #heldby) held by
(name #wornby) worn by
(name #under) under
(name #behind) behind
(Name #partof) As part of
(interface (present-name $<Rel))
(present-name #in) inside
(present-name #on) on top of
(present-name $Rel) (name $Rel)
(interface (towards-name $<Rel))
(towards-name #in) into
(towards-name #on) onto
(towards-name $Rel) (name $Rel)
(interface (reverse-name $<Rel))
(reverse-name #in) out of
(reverse-name #on) off
(reverse-name #partof) away from
(reverse-name #heldby) away from
(reverse-name #wornby) off
(reverse-name #under) out from under
(reverse-name #behind) out from behind
(the (relation $Rel)) (name $Rel)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Directions
(interface (opposite of $<Dir1 is $>Dir2))
(interface (present-adverb $<Dir))
(interface (from-adverb $<Dir))
#north
(direction *)
(name *) north
(dict *) n northern
(opposite of * is #south)
#south
(direction *)
(name *) south
(dict *) s southern
(opposite of * is #north)
#east
(direction *)
(name *) east
(dict *) e eastern
(opposite of * is #west)
#west
(direction *)
(name *) west
(dict *) w western
(opposite of * is #east)
#northeast
(direction *)
(name *) northeast
(dict *) ne north-east
(opposite of * is #southwest)
#northwest
(direction *)
(name *) northwest
(dict *) nw north-west
(opposite of * is #southeast)
#southwest
(direction *)
(name *) southwest
(dict *) sw south-west
(opposite of * is #northeast)
#southeast
(direction *)
(name *) southeast
(dict *) se south-east
(opposite of * is #northwest)
#up
(direction *)
(name *) up
(dict *) u ceiling sky above
(present-adverb *) above
(from-adverb *) above
(opposite of * is #down)
#down
(direction *)
(name *) down
(dict *) d below
(present-adverb *) below
(from-adverb *) below
(opposite of * is #up)
#in %% Note: #in is also a relation
(direction *)
(present-adverb *) inside
(from-adverb *) inside
(opposite of * is #out)
#out
(direction *)
(name *) out
(dict *) outside outwards
(present-adverb *) outside
(opposite of * is #in)
(present-adverb $Dir) to the (name $Dir)
(from-adverb $Dir) the (name $Dir)
(proper (direction $))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Common traits and per-object flags
%% Negations
@($Obj is open) ~($Obj is closed)
@($Obj is unlocked) ~($Obj is locked)
@($Obj is on) ~($Obj is off)
@($Obj is revealed) ~($Obj is hidden)
@($Obj is pristine) ~($Obj is handled)
@($Obj is unvisited) ~($Obj is visited)
@($Obj is in order) ~($Obj is broken)
%% Inheritance relations
(actor container $Obj) *(room $Obj)
(animate $Obj) *(female $Obj)
(animate $Obj) *(male $Obj)
(animate $Obj) *(gender-neutral $Obj)
(container $Obj) *(actor container $Obj)
(item $Obj) *(wearable $Obj)
(supporter $Obj) *(actor supporter $Obj)
(excluded from all $Obj) *(not here $Obj)
(excluded from all $Obj) *(room $Obj)
(actor container $Obj) *(in-seat $Obj)
(actor supporter $Obj) *(on-seat $Obj)
(seat $Obj) *(in-seat $Obj)
(seat $Obj) *(on-seat $Obj)
(opaque $Obj) *(openable $Obj)
(openable $Obj) *(lockable $Obj)
(plural $Obj) *(pair $Obj)
%% "Edison's Lament: No switch is ever in the right position."
%% (From "The Grand List Of Console Role Playing Game Clichés")
%% Of course, you can override these defaults on an object-by-object basis:
((openable $) is closed)
((lockable $) is locked)
((switchable $) is off)
%% Convenience predicate:
(interface (reveal $<Obj))
(reveal $Obj)
(now) ($Obj is revealed)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Rules to prevent compiler warnings
%% The following rule definitions have no effect on the behaviour of the
%% program, but they prevent warnings about undefined predicates. They have
%% zero impact on performance.
%% These are typically static traits:
(ambiguously plural $) (fail)
(an $) (fail)
(door $) (fail)
(edible $) (fail)
(female $) (fail)
(gender-neutral $) (fail)
(fine where it is $) (fail)
(inherently dark $) (fail)
(item $) (fail)
(lockable $) (fail)
(male $) (fail)
(not here $) (fail)
(openable $) (fail)
(out of reach $) (fail)
(pair $) (fail)
(potable $) (fail)
(pushable $) (fail)
(sharp $) (fail)
(singleton $) (fail)
(switchable $) (fail)
(uncountable $) (fail)
(wearable $) (fail)
(vehicle $) (fail)
(your $) (fail)
(on-seat $) (fail)
(in-seat $) (fail)
(consultable $) (fail)
%% These typically involve rule bodies with further conditions:
($ provides light) (fail)
%% These are typically dynamic (i.e. per-object flags):
($ is broken) (fail)
($ is hidden) (fail)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Rooms and doors
(name (room $)) location
(room header $Room) (Tagged name $Room)
(look (room $R)) You are here.
(interface (from $<Room go $>Dir to room $>Obj))
%% Given a room and a direction, what room (if any) is reachable that way?
%% Given a room and a target room, what direction (if any) leads there?
(from $Here go $Dir to room $Room)
(if) (bound $Room) (then)
(from $Here go $Dir to $Room)
(or)
(from $Here through $Door to $Room)
(from $Here go $Dir to $Door)
(else)
*(from $Here go $Dir to $Target)
(if) (room $Target) (then)
($Target = $Room)
(elseif) (direction $Target) (then)
(from $Here go $Target to room $Room)
(else)
(door $Target)
~($Target blocks passage)
(from $Here through $Target to $Room)
(endif)
(endif)
(interface (from $<Room go $<Dir to object $>Obj))
%% Given a room and a direction, what object, door and/or room is visible
%% that way? (Usually multi-queried)
(from $Room go $Dir to object $Obj)
(from $Room go $Dir to $Point)
(if) (direction $Point) (then)
*(from $Room go $Point to object $Obj)
(elseif) (door $Point) (then)
{
~($Point blocks light)
(from $Room through $Point to $Obj)
(or)
($Obj = $Point)
}
(else)
($Obj = $Point)
(endif)
(the (current room $)) this location
(name (door $)) door
($Door blocks passage)
($Door is closed)
((opaque $Door) blocks light)
($Door is closed)
@(from $Room go $Dir through $Door to $Target)
*(from $Room go $Dir to $Door)
*(from $Room through $Door to $Target)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Access rules
(interface (visibility ceiling of $<Obj is $>Ceil))
(visibility ceiling of $Obj is $Ceil)
(if) ($Obj has parent $Parent) (then)
(if)
(opaque $Parent)
($Obj has relation $Rel)
(if) ($Rel = #in) (then)
($Parent is closed)
(else)
($Rel = #under)
(endif)
(then)
($Ceil = $Parent)
(else)
(visibility ceiling of $Parent is $Ceil)
(endif)
(else)
($Ceil = $Obj)
(endif)
(interface (light reaches ceiling $<Ceil))
(light reaches ceiling (room $Ceil))
~(inherently dark $Ceil)
(light reaches ceiling $Ceil)
*($Obj provides light)
(visibility ceiling of $Obj is $Ceil)
(global variable (current scope ceiling $))
(recompute visibility)
(current player $Player)
(visibility ceiling of $Player is $Ceil)
(if) (light reaches ceiling $Ceil) (then)
(now) (current scope ceiling $Ceil)
(now) (player can see)
(else)
(reachability ceiling of $Player is $RCeil)
(now) (current scope ceiling $RCeil)
(now) ~(player can see)
(endif)
(recompute visibility)
%% Fallback e.g. if there is no current player.
(interface (player can see $<Obj))
(player can see $Obj)
(player can see)
(current scope ceiling $Ceil)
(if) (room $Obj) ~($Obj = $Ceil) (then)
(room $Ceil)
{
(from $Ceil go $ to $Obj)
(or)
(from $Ceil through $Door to $Obj)
~($Door blocks light)
}
(else)
(visibility ceiling of $Obj is $Ceil)
(endif)
(interface (reachability ceiling of $<Obj is $>Ceil))
(reachability ceiling of $Obj is $Ceil)
(if) ($Obj is $Rel $Parent) (then)
(if)
($Rel = #in)
($Parent is closed)
(or)
($Rel = #under)
($Parent is #wornby $Actor)
~(current player $Actor)
(then)
($Ceil = $Parent)
(else)
(reachability ceiling of $Parent is $Ceil)
(endif)
(else)
($Ceil = $Obj)
(endif)
(interface (player can reach $<Obj))
(player can reach $Obj)
~(out of reach $Obj)
(current player $Player)
(reachability ceiling of $Player is $Ceil)
{
($Obj = $Ceil)
(or)
(reachability ceiling of $Obj is $Ceil)
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Scope
%% The following predicate can be extended by the game, typically using rules
%% that check certain conditions, e.g. what the current room is:
(interface (add $>Obj to scope))
(add #darkness to scope)
~(player can see)
%% The default scope is everything that the player can see or reach, plus
%% objects that are marked out of reach but would be reachable otherwise.
%% Instead of querying the predicates defined above, we compute all of this in
%% a single traversal of the object tree, for better performance.
(interface ($>Obj is in scope))
($Obj is in scope)
*(add $Obj to scope)
($Obj is in scope)
(current scope ceiling $Ceil)
(if) (fully bound $Obj) (then)
(if) (player can see) (then)
(traverse scope bottom-up $Obj to $Ceil wearer $)
(else)
{
($Obj = $Ceil)
(or)
(reachability ceiling of $Obj is $Ceil)
}
(endif)
(else)
{
($Obj = $Ceil)
(or)
*($InCeil is #in $Ceil)
*(traverse scope top-down $Obj from $InCeil wearer $)
}
(endif)
($Obj is in scope)
(if) (bound $Obj) (then)
(room $Obj)
(endif)
(player can see)
(current scope ceiling $Ceil)
(room $Ceil)
{
*(from $Ceil go $ to $Obj)
(room $Obj)
(or)
*(from $Ceil through $Door to $Obj)
~($Door blocks light)
}
(interface (traverse scope bottom-up $<Obj to $<Ceil wearer $Wearer))
(traverse scope bottom-up $Ceil to $Ceil wearer $)
(traverse scope bottom-up $Obj to $Ceil wearer $Wearer)
($Obj is $Rel $Parent)
(if) ($Rel = #wornby) (then)
($Parent = $Wearer)
(endif)
(if) ($Parent = $Ceil) (then)
($Rel = #in)
(elseif) (opaque $Parent) (then)
(if) ($Rel = #in) (then)
($Parent is open)
(elseif) ($Rel = #under) (then)
(current player $Wearer)
(endif)
(endif)
(traverse scope bottom-up $Parent to $Ceil wearer $Wearer)
(interface (traverse scope top-down $>Obj from $<Ceil wearer $Wearer))
(traverse scope top-down $Obj from $Obj wearer $)
(traverse scope top-down $Output from $Obj wearer $Wearer)
(if) (opaque $Obj) (then)
*($Child is $Rel $Obj)
(if) ($Rel = #in) (then)
($Obj is open)
(elseif) ($Rel = #under) (then)
(current player $Wearer)
(endif)
(else)
*($Child is $Rel $Obj)
(endif)
(if) ($Rel = #wornby) (then)
($Wearer = $Obj)
(endif)
*(traverse scope top-down $Output from $Child wearer $Wearer)
#darkness
(name *) darkness
(dict *) dark
(singleton *)
(intangible *)
(descr *) (narrate darkness)
(rebuild scope)
(update environment around player)
(forget pronouns out of scope)
%% Debugging predicate:
(interface (scope))
(scope)
(rebuild scope)
The current scope is: (line)
(exhaust) {
*($Obj is in scope)
$Obj:
%% Prevent (the $) from revealing hidden objects
(if) ($Obj is hidden) (then)
(the $Obj)
(now) ($Obj is hidden)
(else)
(the $Obj)
(endif)
(line)
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Select player, enter a room or other location, move floating objects
(interface (select player $<Player))
(select player $Player)
(clear all pronouns)
(now) (current player $Player)
(update environment around player)
(interface (move player to $<Rel $<Loc))
(move player to $Rel $Loc)
(current player $Player)
(now) ($Player is $Rel $Loc)
(update environment around player)
(interface (enter $<Room))
(enter $Room)
(now) (don't mark the room as visited yet) %% We keep ($ is visited) unset until after (narrate entering $) has had its chance to describe things
(move player to #in $Room)
(narrate entering $Room)
(mark the location as visited)
(interface (enter $<Room by $<Vehicle))
(enter $Room by $Vehicle)
(now) ($Vehicle is #in $Room)
(now) ($Vehicle is handled)
(now) (don't mark the room as visited yet)
(update environment around player)
(narrate entering $Room)
(mark the location as visited)
(update environment around player)
(if) (current player $Player) ($Player is in room $Room) (then)
(now) (current room $Room)
(exhaust) {
*($Room attracts $Object)
(now) ($Object is #in $Room)
}
(recompute visibility)
(mark the location as visited)
(endif)
(mark the location as visited)
(don't mark the room as visited yet) %% This flag prevents it only once
(now) ~(don't mark the room as visited yet)
(mark the location as visited)
(if) (current room $Room) ($Room is unvisited) (player can see) (then)
(now) ($Room is visited)
(endif)
(narrate entering (room $Room))
(now) (looking after moving)
(par)
(try [look])
(narrate entering $Obj)
You get into (the $Obj).
(interface (prevent entering $<Obj))
(prevent entering $Obj)
(when $Obj won't accept actor #in)
(interface (narrate failing to leave $<Obj $<Dir))
(narrate failing to leave $ $)
There doesn't appear to be an exit in that direction.
%% Extend the following predicate to simulate objects occupying multiple rooms:
($Room attracts $Obj)
*(from $Room go $ to $Obj)
~(direction $Obj)
~(room $Obj)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Standard actions
%% LOOK <dir>
(grammar [examine/x/look/l [direction]] for [look $])
(unlikely [look $])
(prevent [look $])
~(player can see)
You can't see in the darkness.
(perform [look $Dir])
(if)
(current scope ceiling $Room)
(room $Room)
(from $Room go $Dir to $Target)
(then)
(if) (direction $Target) (then)
(try [look $Target])
(elseif) (door $Target) ~($Target blocks light) (then)
(from $Room through $Target to $OtherRoom)
(if) ($OtherRoom is visited) (then)
Through (the $Target) you see (a $OtherRoom).
(notice $OtherRoom)
(else)
You can't quite make out what's on the other
side of (the $Target).
(notice $Target)
(endif)
(elseif) (room $Target) ($Target is unvisited) (then)
You can't get a good view of what's in that direction.
(else)
(Name $Dir) from here (is $Target) (a $Target).
(notice $Target)
(endif)
(else)
(narrate failing to look $Dir)
(endif)
(narrate failing to look #up)
You see nothing unexpected above.
(narrate failing to look #down)
You see nothing unexpected below.
(narrate failing to look #in)
Your introspection reveals nothing.
(narrate failing to look #out)
There's no obvious way out of here.
(narrate failing to look $)
You see nothing unexpected in that direction.
%% LOOK <rel> <obj>
(grammar [look/l [in inside into through] [single]] for [look #in $])
(grammar [look/l [on upon] [single]] for [look #on $])
(grammar [look/l behind [single]] for [look #behind $])
(grammar [look/l under [single]] for [look #under $])
(unlikely [look #in $Obj])
~(container $Obj)
(unlikely [look #on $Obj])
~(supporter $Obj)
%% Reachability not required, but visibility:
~(action [look $ $] requires $ to be touched)
(refuse [look $ $Obj]) (when $Obj is out of sight)
%% This is the only action in the standard library that refuses based on visibility, so it's implemented as a specific rule here instead of a more general (action $ requires $ to be seen). If more actions require it in the future, though, that could easily change.
(before [look #in (opaque $Obj)])
($Obj is closed)
(first try [open $Obj])
(instead of [look #in (current room $)])
(try [look])
(instead of [look #in $Obj])
{ (room $Obj) (or) (door $Obj) }
(current room $Here)
{
(from $Here go $Dir to $Obj)
(or)
(from $Here through $Door to $Obj)
(from $Here go $Dir to $Door)
}
(direction $Dir)
(try [look $Dir])
(prevent [look #in $Obj])
~(container $Obj)
(The $Obj) can't contain things.
(prevent [look #in (opaque $Obj)])
($Obj is closed)
~(current scope ceiling $Obj)
(if) (openable $Obj) (then)
(The $Obj is) closed.
(else)
You can't look inside (the $Obj).
(endif)
(prevent [look #behind (room $Obj)])
Looking behind (the $Obj) doesn't make sense.
(prevent [look #under $Obj])
($Obj is #wornby $Actor)
~(current player $Actor)
(animate $Actor)
(The $Actor) might not like that.
(perform [look $Rel $Obj])
(collect $C)
*($C is $Rel $Obj)
(now) ($C is revealed)
(into $List)
(if) (empty $List) (then)
(if) (#in = $Rel) (then)
(The $Obj is) empty.
(else)
(if) ($Rel is one of [#under #behind]) (then)
You find
(else)
There's
(endif)
nothing (present-name $Rel) (the $Obj).
(endif)
(else)
(Name $Rel) (the $Obj) you see (a $List). (notice $List)
(endif)
%% FIND <obj>
%% FIND takes the player to the room that currently contains the object.
%% For objects that move around autonomously, it may be a good idea to override
%% this rule, to say e.g. "you don't know where the cat might be right now".
%% Note that floating objects, including doors, will remain in the room where
%% they were last encountered. This will usually put the player on the expected
%% side of doors.
(grammar [find [any]] for [find $])
(grammar [look/l for [any]] for [find $])
(unlikely [find $Obj])
($Obj is nowhere)
~(action [find $] requires $ to be present)
(prevent [find (not here $Obj)])
You don't know where to find (the $Obj).
(prevent [find $Obj])
(when $Obj is already held)
(prevent [find $Obj])
($Obj is in room $Room)
(current room $Room)
(The $Obj) (is $Obj)
(if) ($Obj is $Rel $Loc) ~(room $Loc) (then)
(name $Rel) (the $Loc)
(else)
here
(endif)
.
(prevent [find $Obj])
($Obj is in room $Room)
(current room $Here)
~(shortest path from $Here to $Room is $)
You don't know how to get to (the $Obj) from here.
(perform [find $Obj])
(if) ($Obj is in room $Room) (then)
(line) \( attempting to go to (the $Room) \) (line)
(try [go to $Room])
(else)
You don't know where to find (the $Obj).
(endif)
%% EXAMINE <obj>
(grammar [examine/x/watch/describe/check/look/l [object]] for [examine $])
(grammar [look/l at [object]] for [examine $])
(understand [who am i] as [examine $Player])
(current player $Player)
~(action [examine $] requires $ to be touched)
(instead of [examine (room $Obj)])
(current room $Here)
~($Here = $Obj)
(if)
(from $Here go $Dir to $Obj)
(then)
(try [look $Dir])
(elseif)
(from $Here through $Door to $Obj)
~($Door blocks light)
(from $Here go $Dir to $Door)
(then)
(try [look $Dir])
(else)
You can't get a good view of (the $Obj) from here.
(endif)
(perform [examine $Obj])
(current player $Player)
($Player is nested #in $Obj)
(look $Obj)
(perform [examine $Obj])
(descr $Obj)
(if) (supporter $Obj) (then)
(if) (fungibility enabled) (then)
(collect $Child)
*($Child is #on $Obj)
(into $OnList)
(fungibility-enabled appearance $OnList #on $Obj)
(else)
(exhaust) {
*($Child is #on $Obj)
(par)
(appearance $Child #on $Obj)
(notice $Child)
}
(endif)
(endif)
(if) (container $Obj) ~{ (opaque $Obj) ($Obj is closed) } (then)
(if) (fungibility enabled) (then)
(collect $Child)
*($Child is #in $Obj)
(into $InList)
(fungibility-enabled appearance $InList #in $Obj)
(else)
(exhaust) {
*($Child is #in $Obj)
(par)
(appearance $Child #in $Obj)
(notice $Child)
}