-
Notifications
You must be signed in to change notification settings - Fork 2
/
things.pas
2438 lines (2206 loc) · 92.5 KB
/
things.pas
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
{$MODE OBJFPC} { -*- delphi -*- }
{$INCLUDE settings.inc}
unit things;
interface
uses
storable, physics, messages, thingdim, grammarian, matcher, textstream, properties;
type
TNamedThing = class(TThing)
protected
FName, FCachedLongName: UTF8String;
FCachedLongNameMatcherFlags: TMatcherFlags;
FSingularPattern, FPluralPattern: TMatcher;
FPlural: Boolean;
function GetMatcherFlags(Perspective: TAvatar): TMatcherFlags; virtual;
class function CreateFromProperties(Properties: TTextStreamProperties): TNamedThing; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String);
destructor Destroy(); override;
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetName(Perspective: TAvatar): UTF8String; override;
function GetLongName(Perspective: TAvatar): UTF8String; override;
function IsPlural(Perspective: TAvatar): Boolean; override;
function IsExplicitlyReferencedThing(Tokens: TTokens; Start: Cardinal; Perspective: TAvatar; out Count: Cardinal; out GrammaticalNumber: TGrammaticalNumber): Boolean; override;
{$IFDEF DEBUG} function Debug(Perspective: TAvatar): UTF8String; override; {$ENDIF}
property Plural: Boolean read FPlural write FPlural;
end;
// things that have a description
TDescribedThing = class(TNamedThing)
protected
FDescription: UTF8String;
class function CreateFromProperties(Properties: TTextStreamProperties): TDescribedThing; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetDescriptionSelf(Perspective: TAvatar): UTF8String; override;
end;
// Things that have a specific mass and size
TPhysicalThing = class(TNamedThing)
protected
FMass: TThingMass;
FSize: TThingSize;
class function CreateFromProperties(Properties: TTextStreamProperties): TPhysicalThing; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Mass: TThingMass; Size: TThingSize);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetIntrinsicMass(): TThingMass; override;
function GetIntrinsicSize(): TThingSize; override;
property Mass: TThingMass read FMass write FMass;
property Size: TThingSize read FSize write FSize;
end;
// Things that never change: MacGuffins, set pieces, and other non-interactive nouns
TDescribedPhysicalThing = class(TPhysicalThing) // @RegisterStorableClass
protected
FDescription: UTF8String;
FCannotPlaceExcuse: UTF8String;
class function CreateFromProperties(Properties: TTextStreamProperties): TDescribedPhysicalThing; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass; ASize: TThingSize);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetDescriptionSelf(Perspective: TAvatar): UTF8String; override;
function CanPut(Thing: TThing; ThingPosition: TThingPosition; Care: TPlacementStyle; Perspective: TAvatar; var Message: TMessage): Boolean; override;
property CannotPlaceExcuse: UTF8String read FCannotPlaceExcuse write FCannotPlaceExcuse; // if not '', CanPut returns False
end;
// Things that are really just aspects of other things and are typically very small and light
TFeature = class(TDescribedPhysicalThing) // @RegisterStorableClass
protected
class function CreateFromProperties(Properties: TTextStreamProperties): TFeature; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass = tmLight; ASize: TThingSize = tsSmall);
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetRepresentative(): TAtom; override;
function GetSurface(): TThing; override;
function CanMove(Perspective: TAvatar; var Message: TMessage): Boolean; override;
end;
// Things that are really just the room itself, or aspects thereof; the inside is the parent
TLocationRepresentative = class(TDescribedPhysicalThing) // @RegisterStorableClass
protected
class function CreateFromProperties(Properties: TTextStreamProperties): TLocationRepresentative; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass = tmLudicrous; ASize: TThingSize = tsLudicrous);
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetRepresentative(): TAtom; override;
function GetInside(var PositionOverride: TThingPosition): TThing; override;
function GetSurface(): TThing; override;
function CanMove(Perspective: TAvatar; var Message: TMessage): Boolean; override;
end;
// Things that never change and don't even ever move and are typically gigantic
TScenery = class(TDescribedPhysicalThing) // @RegisterStorableClass
protected
FUnderDescription: UTF8String;
FFindDescription: UTF8String;
FCannotMoveExcuse: UTF8String;
FOpened: Boolean;
class function CreateFromProperties(Properties: TTextStreamProperties): TScenery; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass = tmLudicrous; ASize: TThingSize = tsLudicrous);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function IsOpen(): Boolean; override;
function CanMove(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function GetPresenceStatement(Perspective: TAvatar; Mode: TGetPresenceStatementMode): UTF8String; override;
function GetLookUnder(Perspective: TAvatar): UTF8String; override;
property UnderDescription: UTF8String read FUnderDescription write FUnderDescription;
property FindDescription: UTF8String read FFindDescription write FFindDescription;
property CannotMoveExcuse: UTF8String read FCannotMoveExcuse write FCannotMoveExcuse;
property Opened: Boolean read FOpened write FOpened;
end;
// Things that don't change and don't move but that provide a portal to other locations
TLocationProxy = class abstract(TScenery)
protected
FDestination: TLocation;
class function CreateFromProperties(Properties: TTextStreamProperties): TLocationProxy; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; Destination: TLocation; AMass: TThingMass = tmLudicrous; ASize: TThingSize = tsLudicrous);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetDescriptionDirectional(Perspective: TAvatar; Mode: TGetPresenceStatementMode; Direction: TCardinalDirection): UTF8String; override;
end;
TPath = class(TLocationProxy) // @RegisterStorableClass
protected
class function CreateFromProperties(Properties: TTextStreamProperties): TPath; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; Destination: TLocation; ASize: TThingSize);
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetTransportationDestination(Perspective: TAvatar): TTransportationInstruction; override;
end;
TOpening = class(TLocationProxy) // @RegisterStorableClass
protected
class function CreateFromProperties(Properties: TTextStreamProperties): TOpening; override;
function CanEnter(Traveller: TThing; Direction: TCardinalDirection; Perspective: TAvatar; var Message: TMessage): Boolean; virtual;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; Destination: TLocation; ASize: TThingSize);
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetEntrance(Traveller: TThing; Direction: TCardinalDirection; Perspective: TAvatar; var PositionOverride: TThingPosition; var DisambiguationOpening: TThing; var Message: TMessage; NotificationList: TAtomList): TAtom; override;
function GetInside(var PositionOverride: TThingPosition): TThing; override;
function IsOpen(): Boolean; override;
function GetLookUnder(Perspective: TAvatar): UTF8String; override;
function CanMove(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function CanTake(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function CanShake(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function GetFeatures(): TThingFeatures; override;
function CanInsideHold(const Manifest: TThingSizeManifest; const ManifestCount: Integer): Boolean; override;
end;
// The ground, mainly
TSurface = class(TDescribedPhysicalThing) // @RegisterStorableClass
protected
class function CreateFromProperties(Properties: TTextStreamProperties): TSurface; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass = tmLudicrous; ASize: TThingSize = tsLudicrous);
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function CanMove(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function GetRepresentative(): TAtom; override;
end;
THole = class;
TEarthGround = class(TSurface) // @RegisterStorableClass
protected
FHole: THole;
{$IFOPT C+} procedure AssertChildPositionOk(Thing: TThing; APosition: TThingPosition); override; {$ENDIF}
class function CreateFromProperties(Properties: TTextStreamProperties): TEarthGround; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass = tmLudicrous; ASize: TThingSize = tsLudicrous; AHole: THole = nil);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetDescriptionRemoteDetailed(Perspective: TAvatar; Direction: TCardinalDirection; LeadingPhrase: UTF8String; Options: TLeadingPhraseOptions): UTF8String; override;
function GetLookIn(Perspective: TAvatar): UTF8String; override;
function GetLookUnder(Perspective: TAvatar): UTF8String; override;
function GetFeatures(): TThingFeatures; override;
function Dig(Spade: TThing; Perspective: TAvatar; var Message: TMessage): Boolean; override;
function GetInside(var PositionOverride: TThingPosition): TThing; override;
function CanInsideHold(const Manifest: TThingSizeManifest; const ManifestCount: Integer): Boolean; override;
function GetDescriptionNoInside(Perspective: TAvatar): UTF8String; override;
procedure Removed(Thing: TThing); override;
end;
// Boxes, crates, etc
TContainer = class(TDescribedPhysicalThing) // @RegisterStorableClass
protected
FOpenable: Boolean;
FOpen: Boolean;
class function CreateFromProperties(Properties: TTextStreamProperties): TContainer; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AOpen: Boolean = True; AOpenable: Boolean = False; AMass: TThingMass = tmLudicrous; ASize: TThingSize = tsLudicrous);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetInside(var PositionOverride: TThingPosition): TThing; override;
function CanInsideHold(const Manifest: TThingSizeManifest; const ManifestCount: Integer): Boolean; override;
function IsOpen(): Boolean; override;
function GetFeatures(): TThingFeatures; override;
function Open(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function Close(Perspective: TAvatar; var Message: TMessage): Boolean; override;
end;
TSpade = class(TDescribedPhysicalThing) // @RegisterStorableClass
protected
class function CreateFromProperties(Properties: TTextStreamProperties): TSpade; override;
public
constructor Create();
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetFeatures(): TThingFeatures; override;
function CanDig(Target: TThing; Perspective: TAvatar; var Message: TMessage): Boolean; override;
end;
TSign = class(TScenery) // @RegisterStorableClass
protected
FWriting: UTF8String;
class function CreateFromProperties(Properties: TTextStreamProperties): TSign; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; Writing: UTF8String; AMass: TThingMass; ASize: TThingSize);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetFeatures(): TThingFeatures; override;
function GetDescriptionWriting(Perspective: TAvatar): UTF8String; override;
end;
TTree = class(TScenery) // @RegisterStorableClass
end;
// Convenience constructor for TScenery that always has a CannotPlaceExcuse.
TStructure = class(TScenery) // @RegisterStorableClass
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description, ACannotPlaceExcuse: UTF8String);
end;
// More complicated things
TBag = class(TDescribedThing) // @RegisterStorableClass
protected
FMaxSize: TThingSize;
class function CreateFromProperties(Properties: TTextStreamProperties): TBag; override;
public
constructor Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; MaxSize: TThingSize);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetIntrinsicMass(): TThingMass; override;
function GetIntrinsicSize(): TThingSize; override;
function GetOutsideSizeManifest(): TThingSizeManifest; override;
function GetInside(var PositionOverride: TThingPosition): TThing; override;
function CanInsideHold(const Manifest: TThingSizeManifest; const ManifestCount: Integer): Boolean; override;
function IsOpen(): Boolean; override;
function GetFeatures(): TThingFeatures; override;
end;
TPileClass = class of TPile;
THole = class(TDescribedThing) // @RegisterStorableClass
protected
FSize: TThingSize;
FPileClass: TPileClass;
class function CreateFromProperties(Properties: TTextStreamProperties): THole; override;
public
constructor Create(Description: UTF8String; Size: TThingSize; PileClass: TPileClass);
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetTitle(Perspective: TAvatar): UTF8String; override;
function GetHorizonDescription(Perspective: TAvatar): UTF8String; override;
function GetPresenceStatement(Perspective: TAvatar; Mode: TGetPresenceStatementMode): UTF8String; override;
function GetDescriptionState(Perspective: TAvatar): UTF8String; override;
function GetDescriptionClosed(Perspective: TAvatar): UTF8String; override;
function GetLookUnder(Perspective: TAvatar): UTF8String; override;
function GetLookTowardsDirection(Perspective: TAvatar; Direction: TCardinalDirection): UTF8String; override;
function GetIntrinsicMass(): TThingMass; override;
function GetIntrinsicSize(): TThingSize; override;
function GetInside(var PositionOverride: TThingPosition): TThing; override;
function CanInsideHold(const Manifest: TThingSizeManifest; const ManifestCount: Integer): Boolean; override;
function CanMove(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function CanTake(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function CanShake(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function CanPut(Thing: TThing; ThingPosition: TThingPosition; Care: TPlacementStyle; Perspective: TAvatar; var Message: TMessage): Boolean; override;
procedure HandleAdd(Thing: TThing; Blame: TAvatar); override;
function IsOpen(): Boolean; override;
function GetNavigationInstructions(Direction: TCardinalDirection; Child: TThing; Perspective: TAvatar; var Message: TMessage): TNavigationInstruction; override;
function GetBiggestCoverer: TThing; { only call if IsOpen() is false meaning there is a coverer in the first place }
function GetFeatures(): TThingFeatures; override;
end;
TPile = class(TDescribedPhysicalThing) // @RegisterStorableClass
protected
FIngredient: UTF8String;
class function CreateFromProperties(Properties: TTextStreamProperties): TPile; override;
public
constructor Create(SingularIngredients: array of UTF8String; PluralIngredients: array of UTF8String; Description: UTF8String; AMass: TThingMass; ASize: TThingSize); { ingredient must be canonical plural form }
constructor Read(Stream: TReadStream); override;
procedure Write(Stream: TWriteStream); override;
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
function GetOutsideSizeManifest(): TThingSizeManifest; override;
function GetLookUnder(Perspective: TAvatar): UTF8String; override;
function GetDescriptionIn(Perspective: TAvatar; Options: TGetDescriptionChildrenOptions; Prefix: UTF8String): UTF8String; override;
function GetDescriptionInTitle(Perspective: TAvatar; Options: TGetDescriptionChildrenOptions): UTF8String; override;
function GetDescriptionEmpty(Perspective: TAvatar): UTF8String; override;
function CanTake(Perspective: TAvatar; var Message: TMessage): Boolean; override;
function GetInside(var PositionOverride: TThingPosition): TThing; override;
function CanInsideHold(const Manifest: TThingSizeManifest; const ManifestCount: Integer): Boolean; override;
function IsOpen(): Boolean; override;
end;
TEarthPile = class(TPile) // @RegisterStorableClass
protected
class function CreateFromProperties(Properties: TTextStreamProperties): TEarthPile; override;
public
constructor Create(ASize: TThingSize);
class procedure DescribeProperties(Describer: TPropertyDescriber); override;
end;
implementation
uses
sysutils, broadcast, exceptions;
constructor TNamedThing.Create(Name: UTF8String; Pattern: UTF8String);
var
TokenisedName: TTokens;
NameIsSingular: Boolean;
{$IFOPT C+} NameIsPlural: Boolean; {$ENDIF}
begin
inherited Create();
FCachedLongNameMatcherFlags := mfUnset;
FName := Name;
{$IFOPT C+} Assert(HasSingularVsPluralAnnotation(Pattern), 'The ' + Name + ' needs explicit singular and plural patterns (no slashes found in "' + Pattern + '").'); {$ENDIF}
CompilePattern(Pattern, FSingularPattern, FPluralPattern);
TokenisedName := TokeniseCanonically(Name);
NameIsSingular := FSingularPattern.Matches(TokenisedName, 0) = Length(TokenisedName);
{$IFOPT C+}
NameIsPlural := FPluralPattern.Matches(TokenisedName, 0) = Length(TokenisedName);
if ((not NameIsSingular) and (not NameIsPlural)) then
Assert(False, 'Default name ("' + Name + '") does not match given pattern ("' + Pattern + '")');
{$ENDIF}
FPlural := not NameIsSingular;
end;
destructor TNamedThing.Destroy();
begin
FSingularPattern.Free();
FPluralPattern.Free();
inherited;
end;
constructor TNamedThing.Read(Stream: TReadStream);
begin
inherited;
FCachedLongNameMatcherFlags := mfUnset;
FName := Stream.ReadString();
FSingularPattern := Stream.ReadObject() as TMatcher;
FPluralPattern := Stream.ReadObject() as TMatcher;
FPlural := Stream.ReadBoolean();
end;
procedure TNamedThing.Write(Stream: TWriteStream);
begin
inherited;
Stream.WriteString(FName);
Stream.WriteObject(FSingularPattern);
Stream.WriteObject(FPluralPattern);
Stream.WriteBoolean(FPlural);
end;
class function TNamedThing.CreateFromProperties(Properties: TTextStreamProperties): TNamedThing;
var
Name: UTF8String;
Pattern: UTF8String;
StreamedChildren: TStreamedChildren;
begin
while (not Properties.Done) do
begin
if (Properties.HandleUniqueStringProperty(pnName, Name) and
Properties.HandleUniqueStringProperty(pnPattern, Pattern) and
HandleChildProperties(Properties, StreamedChildren)) then
Properties.FailUnknownProperty();
end;
Properties.EnsureSeen([pnName, pnPattern]);
Result := Create(Name, Pattern);
StreamedChildren.Apply(Result);
end;
class procedure TNamedThing.DescribeProperties(Describer: TPropertyDescriber);
begin
Describer.AddProperty(pnName, ptString);
Describer.AddProperty(pnPattern, ptPattern);
Describer.AddProperty(pnChild, ptChild);
end;
function TNamedThing.GetMatcherFlags(Perspective: TAvatar): TMatcherFlags;
begin
Result := 0;
end;
function TNamedThing.GetName(Perspective: TAvatar): UTF8String;
begin
Result := FName;
end;
function TNamedThing.GetLongName(Perspective: TAvatar): UTF8String;
var
CurrentFlags: TMatcherFlags;
begin
CurrentFlags := GetMatcherFlags(Perspective);
if (FCachedLongNameMatcherFlags <> CurrentFlags) then
begin
if (FPlural) then
begin
FCachedLongName := FPluralPattern.GetCanonicalMatch(' ', CurrentFlags);
Assert(FCachedLongName <> '', 'Couldn''t get a long name out of:'#10 + FPluralPattern.GetPatternDescription());
end
else
begin
FCachedLongName := FSingularPattern.GetCanonicalMatch(' ', CurrentFlags);
Assert(FCachedLongName <> '', 'Couldn''t get a long name out of:'#10 + FSingularPattern.GetPatternDescription());
end;
Assert(FCachedLongName <> '', 'Long name is empty.');
FCachedLongNameMatcherFlags := CurrentFlags;
end
else
begin
Assert(FCachedLongName <> '', 'Flags were already ' + IntToStr(FCachedLongNameMatcherFlags) + ' but didn''t have a cached name.');
end;
Result := FCachedLongName;
end;
function TNamedThing.IsExplicitlyReferencedThing(Tokens: TTokens; Start: Cardinal; Perspective: TAvatar; out Count: Cardinal; out GrammaticalNumber: TGrammaticalNumber): Boolean;
var
PossibleCount: Cardinal;
begin
Result := False;
GrammaticalNumber := [];
Count := FSingularPattern.Matches(Tokens, Start, GetMatcherFlags(Perspective));
if (Count > 0) then
begin
Result := True;
GrammaticalNumber := [gnSingular];
end;
PossibleCount := FPluralPattern.Matches(Tokens, Start, GetMatcherFlags(Perspective));
if ((PossibleCount > 0) and (PossibleCount >= Count)) then
begin
if (Count = PossibleCount) then
begin
GrammaticalNumber := gnAmbiguous;
end
else
begin
Result := True;
Count := PossibleCount;
GrammaticalNumber := [gnPlural];
end;
end;
end;
function TNamedThing.IsPlural(Perspective: TAvatar): Boolean;
begin
Result := FPlural;
end;
{$IFDEF DEBUG}
function TNamedThing.Debug(Perspective: TAvatar): UTF8String;
begin
Result := inherited;
Result := Result + #10 +
'Singular pattern as dot file: ' + #10 + FSingularPattern.GetPatternDotFileLabels();
end;
{$ENDIF}
constructor TDescribedThing.Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String);
begin
inherited Create(Name, Pattern);
FDescription := Description;
end;
constructor TDescribedThing.Read(Stream: TReadStream);
begin
inherited;
FDescription := Stream.ReadString();
end;
procedure TDescribedThing.Write(Stream: TWriteStream);
begin
inherited;
Stream.WriteString(FDescription);
end;
class function TDescribedThing.CreateFromProperties(Properties: TTextStreamProperties): TDescribedThing;
var
Name: UTF8String;
Pattern: UTF8String;
Description: UTF8String;
StreamedChildren: TStreamedChildren;
begin
while (not Properties.Done) do
begin
if (Properties.HandleUniqueStringProperty(pnName, Name) and
Properties.HandleUniqueStringProperty(pnPattern, Pattern) and
Properties.HandleUniqueStringProperty(pnDescription, Description) and
HandleChildProperties(Properties, StreamedChildren)) then
Properties.FailUnknownProperty();
end;
Properties.EnsureSeen([pnName, pnPattern, pnDescription]);
Result := Create(Name, Pattern, Description);
StreamedChildren.Apply(Result);
end;
class procedure TDescribedThing.DescribeProperties(Describer: TPropertyDescriber);
begin
Describer.AddProperty(pnName, ptString);
Describer.AddProperty(pnPattern, ptPattern);
Describer.AddProperty(pnDescription, ptString);
Describer.AddProperty(pnChild, ptChild);
end;
function TDescribedThing.GetDescriptionSelf(Perspective: TAvatar): UTF8String;
begin
Result := FDescription;
end;
constructor TPhysicalThing.Create(Name: UTF8String; Pattern: UTF8String; Mass: TThingMass; Size: TThingSize);
begin
inherited Create(Name, Pattern);
FMass := Mass;
FSize := Size;
end;
constructor TPhysicalThing.Read(Stream: TReadStream);
begin
inherited;
FMass := TThingMass(Stream.ReadCardinal());
FSize := TThingSize(Stream.ReadCardinal());
end;
procedure TPhysicalThing.Write(Stream: TWriteStream);
begin
inherited;
Stream.WriteCardinal(Cardinal(FMass));
Stream.WriteCardinal(Cardinal(FSize));
end;
class function TPhysicalThing.CreateFromProperties(Properties: TTextStreamProperties): TPhysicalThing;
var
Name: UTF8String;
Pattern: UTF8String;
MassValue: TThingMass;
SizeValue: TThingSize;
StreamedChildren: TStreamedChildren;
begin
while (not Properties.Done) do
begin
if (Properties.HandleUniqueStringProperty(pnName, Name) and
Properties.HandleUniqueStringProperty(pnPattern, Pattern) and
Properties.specialize HandleUniqueEnumProperty<TThingMass>(pnMass, MassValue) and {BOGUS Hint: Local variable "MassValue" does not seem to be initialized}
Properties.specialize HandleUniqueEnumProperty<TThingSize>(pnSize, SizeValue) and {BOGUS Hint: Local variable "SizeValue" does not seem to be initialized}
HandleChildProperties(Properties, StreamedChildren)) then
Properties.FailUnknownProperty();
end;
Properties.EnsureSeen([pnName, pnPattern, pnMass, pnSize]);
Result := Create(Name, Pattern, MassValue, SizeValue);
StreamedChildren.Apply(Result);
end;
class procedure TPhysicalThing.DescribeProperties(Describer: TPropertyDescriber);
begin
Describer.AddProperty(pnName, ptString);
Describer.AddProperty(pnPattern, ptPattern);
Describer.AddProperty(pnMass, ptMass);
Describer.AddProperty(pnSize, ptSize);
Describer.AddProperty(pnChild, ptChild);
end;
function TPhysicalThing.GetIntrinsicMass(): TThingMass;
begin
Result := FMass;
end;
function TPhysicalThing.GetIntrinsicSize(): TThingSize;
begin
Result := FSize;
end;
constructor TDescribedPhysicalThing.Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass; ASize: TThingSize);
begin
inherited Create(Name, Pattern, AMass, ASize);
FDescription := Description;
end;
constructor TDescribedPhysicalThing.Read(Stream: TReadStream);
begin
inherited;
FDescription := Stream.ReadString();
FCannotPlaceExcuse := Stream.ReadString();
end;
procedure TDescribedPhysicalThing.Write(Stream: TWriteStream);
begin
inherited;
Stream.WriteString(FDescription);
Stream.WriteString(FCannotPlaceExcuse);
end;
class function TDescribedPhysicalThing.CreateFromProperties(Properties: TTextStreamProperties): TDescribedPhysicalThing;
var
Name: UTF8String;
Pattern: UTF8String;
Description: UTF8String;
CannotPlaceExcuseValue: UTF8String = '';
MassValue: TThingMass;
SizeValue: TThingSize;
StreamedChildren: TStreamedChildren;
begin
while (not Properties.Done) do
begin
if (Properties.HandleUniqueStringProperty(pnName, Name) and
Properties.HandleUniqueStringProperty(pnPattern, Pattern) and
Properties.HandleUniqueStringProperty(pnDescription, Description) and
Properties.HandleUniqueStringProperty(pnCannotPlaceExcuse, CannotPlaceExcuseValue) and
Properties.specialize HandleUniqueEnumProperty<TThingMass>(pnMass, MassValue) and {BOGUS Hint: Local variable "MassValue" does not seem to be initialized}
Properties.specialize HandleUniqueEnumProperty<TThingSize>(pnSize, SizeValue) and {BOGUS Hint: Local variable "SizeValue" does not seem to be initialized}
HandleChildProperties(Properties, StreamedChildren)) then
Properties.FailUnknownProperty();
end;
Properties.EnsureSeen([pnName, pnPattern, pnDescription, pnMass, pnSize]);
Result := Create(Name, Pattern, Description, MassValue, SizeValue);
Result.CannotPlaceExcuse := CannotPlaceExcuseValue;
StreamedChildren.Apply(Result);
end;
class procedure TDescribedPhysicalThing.DescribeProperties(Describer: TPropertyDescriber);
begin
Describer.AddProperty(pnName, ptString);
Describer.AddProperty(pnPattern, ptPattern);
Describer.AddProperty(pnDescription, ptString);
Describer.AddProperty(pnCannotPlaceExcuse, ptString);
Describer.AddProperty(pnMass, ptMass);
Describer.AddProperty(pnSize, ptSize);
Describer.AddProperty(pnChild, ptChild);
end;
function TDescribedPhysicalThing.GetDescriptionSelf(Perspective: TAvatar): UTF8String;
begin
Result := FDescription;
end;
function TDescribedPhysicalThing.CanPut(Thing: TThing; ThingPosition: TThingPosition; Care: TPlacementStyle; Perspective: TAvatar; var Message: TMessage): Boolean;
begin
Assert(Message.IsValid);
if ((ThingPosition = tpOn) and (FCannotPlaceExcuse <> '')) then
begin
Result := False;
Message := TMessage.Create(mkBogus, FCannotPlaceExcuse);
end
else
begin
Result := inherited;
end;
end;
constructor TFeature.Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass = tmLight; ASize: TThingSize = tsSmall);
begin
{ needed for default values }
inherited;
end;
function TFeature.GetRepresentative(): TAtom;
begin
Assert(Assigned(FParent));
Result := FParent;
end;
function TFeature.GetSurface(): TThing;
begin
if (FParent is TThing) then
begin
Result := FParent as TThing;
end
else
begin
Assert(Assigned(FParent));
Result := FParent.GetSurface(); // might be nil
end;
end;
function TFeature.CanMove(Perspective: TAvatar; var Message: TMessage): Boolean;
begin
Assert(Message.IsValid);
Result := False;
Message := TMessage.Create(mkCannotMoveBecauseLocation, '_ _ _ _.',
[Capitalise(GetDefiniteName(Perspective)),
IsAre(IsPlural(Perspective)),
ThingPositionToString(FPosition),
FParent.GetDefiniteName(Perspective)]);
end;
class function TFeature.CreateFromProperties(Properties: TTextStreamProperties): TFeature;
var
Name: UTF8String;
Pattern: UTF8String;
Description: UTF8String;
MassValue: TThingMass = tmLight;
SizeValue: TThingSize = tsSmall;
StreamedChildren: TStreamedChildren;
begin
while (not Properties.Done) do
begin
if (Properties.HandleUniqueStringProperty(pnName, Name) and
Properties.HandleUniqueStringProperty(pnPattern, Pattern) and
Properties.HandleUniqueStringProperty(pnDescription, Description) and
Properties.specialize HandleUniqueEnumProperty<TThingMass>(pnMass, MassValue) and
Properties.specialize HandleUniqueEnumProperty<TThingSize>(pnSize, SizeValue) and
HandleChildProperties(Properties, StreamedChildren)) then
Properties.FailUnknownProperty();
end;
Properties.EnsureSeen([pnName, pnPattern, pnDescription]);
Result := Create(Name, Pattern, Description);
StreamedChildren.Apply(Result);
end;
class procedure TFeature.DescribeProperties(Describer: TPropertyDescriber);
begin
Describer.AddProperty(pnName, ptString);
Describer.AddProperty(pnPattern, ptPattern);
Describer.AddProperty(pnDescription, ptString);
Describer.AddProperty(pnMass, ptMass);
Describer.AddProperty(pnSize, ptSize);
Describer.AddProperty(pnChild, ptChild);
end;
constructor TLocationRepresentative.Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass = tmLudicrous; ASize: TThingSize = tsLudicrous);
begin
{ needed for default values }
inherited;
end;
function TLocationRepresentative.GetRepresentative(): TAtom;
begin
Assert(Assigned(FParent));
Result := FParent;
end;
function TLocationRepresentative.GetInside(var PositionOverride: TThingPosition): TThing;
begin
if (FParent is TThing) then
begin
Result := FParent as TThing;
end
else
begin
Result := FParent.GetInside(PositionOverride);
if (not Assigned(Result)) then
begin
PositionOverride := tpOn;
Result := GetSurface();
Assert(Assigned(Result)); // XXX if it's nil, what should we do?
end;
end;
end;
function TLocationRepresentative.GetSurface(): TThing;
begin
if (FParent is TThing) then
begin
Result := FParent as TThing;
end
else
begin
Result := FParent.GetSurface();
end;
end;
function TLocationRepresentative.CanMove(Perspective: TAvatar; var Message: TMessage): Boolean;
begin
Assert(Message.IsValid);
Result := False;
Message := TMessage.Create(mkCannotMoveBecauseLocation, '_ _ _ _.',
[Capitalise(GetDefiniteName(Perspective)),
IsAre(IsPlural(Perspective)),
ThingPositionToString(FPosition),
FParent.GetDefiniteName(Perspective)]);
end;
class function TLocationRepresentative.CreateFromProperties(Properties: TTextStreamProperties): TLocationRepresentative;
var
Name: UTF8String;
Pattern: UTF8String;
Description: UTF8String;
MassValue: TThingMass = tmLudicrous;
SizeValue: TThingSize = tsLudicrous;
StreamedChildren: TStreamedChildren;
begin
while (not Properties.Done) do
begin
if (Properties.HandleUniqueStringProperty(pnName, Name) and
Properties.HandleUniqueStringProperty(pnPattern, Pattern) and
Properties.HandleUniqueStringProperty(pnDescription, Description) and
Properties.specialize HandleUniqueEnumProperty<TThingMass>(pnMass, MassValue) and
Properties.specialize HandleUniqueEnumProperty<TThingSize>(pnSize, SizeValue) and
HandleChildProperties(Properties, StreamedChildren)) then
Properties.FailUnknownProperty();
end;
Properties.EnsureSeen([pnName, pnPattern, pnDescription]);
Result := Create(Name, Pattern, Description);
StreamedChildren.Apply(Result);
end;
class procedure TLocationRepresentative.DescribeProperties(Describer: TPropertyDescriber);
begin
Describer.AddProperty(pnName, ptString);
Describer.AddProperty(pnPattern, ptPattern);
Describer.AddProperty(pnDescription, ptString);
Describer.AddProperty(pnMass, ptMass);
Describer.AddProperty(pnSize, ptSize);
Describer.AddProperty(pnChild, ptChild);
end;
constructor TScenery.Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; AMass: TThingMass = tmLudicrous; ASize: TThingSize = tsLudicrous);
begin
{ needed for default values }
inherited;
end;
constructor TScenery.Read(Stream: TReadStream);
begin
inherited;
FUnderDescription := Stream.ReadString();
FFindDescription := Stream.ReadString();
FCannotMoveExcuse := Stream.ReadString();
FOpened := Stream.ReadBoolean();
end;
procedure TScenery.Write(Stream: TWriteStream);
begin
inherited;
Stream.WriteString(FUnderDescription);
Stream.WriteString(FFindDescription);
Stream.WriteString(FCannotMoveExcuse);
Stream.WriteBoolean(FOpened);
end;
class function TScenery.CreateFromProperties(Properties: TTextStreamProperties): TScenery;
var
Name: UTF8String;
Pattern: UTF8String;
Description, UnderDescriptionValue, FindDescriptionValue, CannotMoveExcuseValue, CannotPlaceExcuseValue: UTF8String;
MassValue: TThingMass = tmLudicrous;
SizeValue: TThingSize = tsLudicrous;
OpenedValue: Boolean = False;
StreamedChildren: TStreamedChildren;
begin
while (not Properties.Done) do
begin
if (Properties.HandleUniqueStringProperty(pnName, Name) and
Properties.HandleUniqueStringProperty(pnPattern, Pattern) and
Properties.HandleUniqueStringProperty(pnDescription, Description) and
Properties.HandleUniqueStringProperty(pnUnderDescription, UnderDescriptionValue) and
Properties.HandleUniqueStringProperty(pnFindDescription, FindDescriptionValue) and
Properties.HandleUniqueStringProperty(pnCannotMoveExcuse, CannotMoveExcuseValue) and
Properties.HandleUniqueStringProperty(pnCannotPlaceExcuse, CannotPlaceExcuseValue) and
Properties.HandleUniqueBooleanProperty(pnOpened, OpenedValue) and
Properties.specialize HandleUniqueEnumProperty<TThingMass>(pnMass, MassValue) and
Properties.specialize HandleUniqueEnumProperty<TThingSize>(pnSize, SizeValue) and
HandleChildProperties(Properties, StreamedChildren)) then
Properties.FailUnknownProperty();
end;
Properties.EnsureSeen([pnName, pnPattern, pnDescription]);
Result := Create(Name, Pattern, Description, MassValue, SizeValue);
if (Properties.Seen(pnUnderDescription)) then
Result.UnderDescription := UnderDescriptionValue;
if (Properties.Seen(pnFindDescription)) then
Result.FindDescription := FindDescriptionValue;
if (Properties.Seen(pnCannotMoveExcuse)) then
Result.CannotMoveExcuse := CannotMoveExcuseValue;
if (Properties.Seen(pnCannotPlaceExcuse)) then
Result.CannotPlaceExcuse := CannotPlaceExcuseValue;
if (Properties.Seen(pnOpened)) then
Result.Opened := OpenedValue;
StreamedChildren.Apply(Result);
end;
class procedure TScenery.DescribeProperties(Describer: TPropertyDescriber);
begin
Describer.AddProperty(pnName, ptString);
Describer.AddProperty(pnPattern, ptPattern);
Describer.AddProperty(pnDescription, ptString);
Describer.AddProperty(pnUnderDescription, ptString);
Describer.AddProperty(pnFindDescription, ptString);
Describer.AddProperty(pnCannotMoveExcuse, ptString);
Describer.AddProperty(pnCannotPlaceExcuse, ptString);
Describer.AddProperty(pnOpened, ptBoolean);
Describer.AddProperty(pnMass, ptMass);
Describer.AddProperty(pnSize, ptSize);
Describer.AddProperty(pnChild, ptChild);
end;
function TScenery.IsOpen(): Boolean;
begin
Result := FOpened;
end;
function TScenery.CanMove(Perspective: TAvatar; var Message: TMessage): Boolean;
begin
Assert(Message.IsValid);
Result := False;
if (Length(FCannotMoveExcuse) > 0) then
Message := TMessage.Create(mkCannotMoveBecauseCustom, FCannotMoveExcuse)
else
if (FPosition = tpPartOfImplicit) then
Message := TMessage.Create(mkCannotMoveBecauseLocation, '_ _ _ _.',
[Capitalise(GetDefiniteName(Perspective)),
IsAre(IsPlural(Perspective)),
ThingPositionToString(FPosition),
FParent.GetDefiniteName(Perspective)])
else
if (FPosition in tpOpening) then
Message := TMessage.Create(mkBogus, 'Moving _ doesn''t even make sense.', [GetIndefiniteName(Perspective)])
else
Message := TMessage.Create(mkCannotMoveBecauseLocation, '_ cannot be moved.',
[Capitalise(GetDefiniteName(Perspective))]);
end;
function TScenery.GetPresenceStatement(Perspective: TAvatar; Mode: TGetPresenceStatementMode): UTF8String;
begin
if ((Mode = psTheThingIsOnThatThing) and (Length(FFindDescription) > 0)) then
Result := FFindDescription
else
Result := inherited;
end;
function TScenery.GetLookUnder(Perspective: TAvatar): UTF8String;
begin
if (FPosition in tpScenery) then
begin
if (Length(FUnderDescription) > 0) then
Result := FUnderDescription
else
Result := Capitalise(Perspective.GetDefiniteName(Perspective)) + ' cannot see under ' + GetDefiniteName(Perspective) + '.';
end
else
Result := inherited;
end;
constructor TLocationProxy.Create(Name: UTF8String; Pattern: UTF8String; Description: UTF8String; Destination: TLocation; AMass: TThingMass = tmLudicrous; ASize: TThingSize = tsLudicrous);
begin
Assert(Assigned(Destination));
inherited Create(Name, Pattern, Description, AMass, ASize);
FDestination := Destination;
end;
constructor TLocationProxy.Read(Stream: TReadStream);
begin
inherited;
Stream.ReadReference(@Pointer(FDestination));
end;
procedure TLocationProxy.Write(Stream: TWriteStream);
begin
inherited;
Stream.WriteReference(FDestination);
end;
class function TLocationProxy.CreateFromProperties(Properties: TTextStreamProperties): TLocationProxy;
var
Name: UTF8String;
Pattern: UTF8String;
Description: UTF8String;
Destination: TLocation;
MassValue: TThingMass = tmLudicrous;
SizeValue: TThingSize = tsLudicrous;
StreamedChildren: TStreamedChildren;
begin
while (not Properties.Done) do