This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathobject_options.pas
2880 lines (2372 loc) · 72.4 KB
/
object_options.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
{ This file is a part of Map editor for VCMI project
Copyright (C) 2013-2017 Alexander Shishkin [email protected]
This source is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
version.
This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
A copy of the GNU General Public License is available on the World Wide Web at
<http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
unit object_options;
{$I compilersetup.inc}
{$INTERFACES CORBA}
interface
uses
Classes, SysUtils, math, typinfo, fpjson,
LazLoggerBase,
editor_types, editor_classes,
editor_utils, logical_id_condition, vcmi_json, editor_consts, map_objects, lists_manager;
type
{$push}
{$m+}
TObjectOptions = class;
TObjectOptionsClass = class of TObjectOptions;
IObjectOptionsVisitor = interface;
{ IMapObject }
IMapObject = interface(IReferenceNotify)
function GetType: AnsiString;
function GetSubtype: AnsiString;
procedure SetPlayer(AValue: TPlayer);
function GetPlayer: TPlayer;
//for hero pool management
procedure NotifyHeroTypeChanged(AOldType, ANewType: AnsiString);
//for filtered appearance
procedure InvalidateAppearance();
function GetListsManager: TListsManager;
end;
{ TObjectOptions }
TObjectOptions = class(TObject, ISerializeNotify)
private
FObject: IMapObject;
function GetOwner: TPlayer;
procedure SetOwner(AValue: TPlayer);
public//ISerializeNotify
procedure BeforeDeSerialize(Sender: TObject; AData: TJSONData); virtual;
procedure AfterDeSerialize(Sender: TObject; AData: TJSONData); virtual;
procedure BeforeSerialize(Sender: TObject); virtual;
procedure AfterSerialize(Sender: TObject; AData: TJSONData); virtual;
public
constructor Create(AObject: IMapObject); virtual;
procedure Clear; virtual;
procedure ApplyVisitor({%H-}AVisitor: IObjectOptionsVisitor); virtual;
property MapObject: IMapObject read FObject;
class function CanBeOwned: Boolean; virtual;
class function MustBeOwned: Boolean; virtual;
class function GetClassByID(ID: AnsiString; SubID: AnsiString): TObjectOptionsClass;
class function CreateByID(ID: AnsiString; SubID: AnsiString; AObject: IMapObject): TObjectOptions;
class function ZIndex: Integer; virtual;
//initialize options with external template
procedure AssignTemplate(ATemplate: TMapObjectTemplate); virtual;
//return template with best fit on current configuration, may return nil
function SelectTemplate(AType: TMapObjectType): TMapObjectTemplate; virtual;
public
property Owner: TPlayer read GetOwner write SetOwner;
end;
{$pop}
{ TBaseCreatureInstInfo }
TBaseCreatureInstInfo = class (TCollectionItem)
private
FAmount: Integer;
FType: AnsiString;
procedure SetAmount(AValue: Integer);
procedure SetType(AValue: AnsiString);
public
constructor Create(ACollection: TCollection); override;
function IsEmpty: Boolean; virtual;
published
property &type: AnsiString read FType write SetType;
property Amount: Integer read FAmount write SetAmount default 0;
end;
{ TCreatureInstInfo }
TCreatureInstInfo = class(TBaseCreatureInstInfo)
private
FLevel: Integer;
FUpgraded: Boolean;
function GetRawRandom: integer;
procedure SetRawRandom(AValue: integer);
public
property RawRandom: integer Read GetRawRandom write SetRawRandom;
function IsEmpty: Boolean; override;
published
property Level: Integer read FLevel write FLevel default 0;
property Upgraded: Boolean Read FUpgraded write FUpgraded default false;
end;
{ TCreatureSet }
TCreatureSet = class (specialize TGArrayCollection<TCreatureInstInfo>)
private
FOwner: IMapObject;
FTightFormation: Boolean;
procedure SetTightFormation(AValue: Boolean);
public
constructor Create(AOwner: IMapObject);
procedure NotifyReferenced(AOldIdentifier, ANewIdentifier: AnsiString);
function IsEmpty: Boolean;
property TightFormation:Boolean read FTightFormation write SetTightFormation;
end;
{$push}
{$m+}
{ TResourceSet }
TResourceSet = class abstract
protected
function GetAmount(AType: TResType): integer; virtual; abstract;
procedure SetAmount(AType: TResType; AValue: integer); virtual; abstract;
public
property Amount[AType: TResType]: integer read GetAmount write SetAmount;
function IsEmpty: Boolean; virtual;
procedure Clear; virtual;
published
property Wood: integer index TResType.wood read GetAmount write SetAmount default 0;
property Mercury: integer index TResType.mercury read GetAmount write SetAmount default 0;
property Ore: integer index TResType.ore read GetAmount write SetAmount default 0;
property Sulfur: integer index TResType.sulfur read GetAmount write SetAmount default 0;
property Crystal: integer index TResType.crystal read GetAmount write SetAmount default 0;
property Gems: integer index TResType.gems read GetAmount write SetAmount default 0;
property Gold: integer index TResType.gold read GetAmount write SetAmount default 0;
property Mithril: integer index TResType.mithril read GetAmount write SetAmount default 0;
end;
{ TIndepResourceSet }
TIndepResourceSet = class(TResourceSet)
strict private
Fvalue: array[TResType] of Integer;
protected
function GetAmount(AType: TResType): integer; override;
procedure SetAmount(AType: TResType; AValue: integer); override;
end;
{ TQuest }
TQuestMission = (None=0, Level=1, PrimaryStat=2, KillHero=3, KillCreature=4, Artifact=5, Army=6, Resources=7, Hero=8, Player=9{, Keymaster=10});
TQuest = class
private
FOwner: IMapObject;
FCreatures: TCreatureSet;
FCompletedText: TLocalizedString;
FFirstVisitText: TLocalizedString;
FHeroID: AnsiString;
FHeroLevel: Integer;
FKillTarget: String;
FMissionType: TQuestMission;
FNextVisitText: TLocalizedString;
FPlayerID: TPlayer;
FPrimarySkills: THeroPrimarySkills;
FResources: TResourceSet;
FTimeLimit: Integer;
FArtifacts:TStrings;
function IsCreaturesStored: Boolean;
function IsArtifactsStored: Boolean;
function IsHeroIDStored: Boolean;
function IsHeroLevelStored: Boolean;
function IsKillTargetStored: Boolean;
function IsPlayerIDStored: Boolean;
function IsPrimarySkillsStored: Boolean;
function IsResourcesStored: Boolean;
procedure SetCompletedText(AValue: TLocalizedString);
procedure SetFirstVisitText(AValue: TLocalizedString);
procedure SetHeroID(AValue: AnsiString);
procedure SetHeroLevel(AValue: Integer);
procedure SetMissionType(AValue: TQuestMission);
procedure SetNextVisitText(AValue: TLocalizedString);
procedure SetPlayerID(AValue: TPlayer);
procedure SetTimeLimit(AValue: Integer);
public
constructor Create(AOwner: IMapObject);
destructor Destroy; override;
procedure Clear;
procedure SetKillTarget(AValue: String);
published
property FirstVisitText: TLocalizedString read FFirstVisitText write SetFirstVisitText;
property NextVisitText: TLocalizedString read FNextVisitText write SetNextVisitText;
property CompletedText: TLocalizedString read FCompletedText write SetCompletedText;
property MissionType: TQuestMission read FMissionType write SetMissionType default TQuestMission.None;
property TimeLimit: Integer read FTimeLimit write SetTimeLimit default -1;
property Artifacts: TStrings read FArtifacts stored IsArtifactsStored;
property Creatures: TCreatureSet read FCreatures stored IsCreaturesStored;
property Resources: TResourceSet read FResources stored IsResourcesStored;
property PrimarySkills: THeroPrimarySkills read FPrimarySkills stored IsPrimarySkillsStored;
property HeroLevel: Integer read FHeroLevel write SetHeroLevel stored IsHeroLevelStored default 0;
property Hero: AnsiString read FHeroID write SetHeroID stored IsHeroIDStored;
property Player: TPlayer read FPlayerID write SetPlayerID stored IsPlayerIDStored default TPlayer.NONE;
property KillTarget: String read FKillTarget write SetKillTarget stored IsKillTargetStored;
end;
{ THeroArtifacts }
THeroArtifacts = class
strict private
FOwner: IReferenceNotify;
FSlots: array[0..ARTIFACT_SLOT_COUNT-1] of AnsiString;
FBackpack: TStrings;
function GetBackpack: TStrings;
function GetBySlotNumber(ASlotID: Integer): AnsiString;
function IsBackpackStored: Boolean;
procedure SetBySlotNumber(ASlotID: Integer; AValue: AnsiString);
public
constructor Create(AOwner: IReferenceNotify);
destructor Destroy; override;
property BySlotNumber[ASlotID: Integer]: AnsiString read GetBySlotNumber write SetBySlotNumber;
function IsEmpty: Boolean;
procedure Clear;
published
property Head: AnsiString index 0 read GetBySlotNumber write SetBySlotNumber;
property Shoulders: AnsiString index 1 read GetBySlotNumber write SetBySlotNumber;
property Neck: AnsiString index 2 read GetBySlotNumber write SetBySlotNumber;
property RightHand: AnsiString index 3 read GetBySlotNumber write SetBySlotNumber;
property LeftHand: AnsiString index 4 read GetBySlotNumber write SetBySlotNumber;
property Torso: AnsiString index 5 read GetBySlotNumber write SetBySlotNumber;
property RightRing: AnsiString index 6 read GetBySlotNumber write SetBySlotNumber;
property LeftRing: AnsiString index 7 read GetBySlotNumber write SetBySlotNumber;
property Feet: AnsiString index 8 read GetBySlotNumber write SetBySlotNumber;
property Misc1: AnsiString index 9 read GetBySlotNumber write SetBySlotNumber;
property Misc2: AnsiString index 10 read GetBySlotNumber write SetBySlotNumber;
property Misc3: AnsiString index 11 read GetBySlotNumber write SetBySlotNumber;
property Misc4: AnsiString index 12 read GetBySlotNumber write SetBySlotNumber;
property Mach1: AnsiString index 13 read GetBySlotNumber write SetBySlotNumber;
property Mach2: AnsiString index 14 read GetBySlotNumber write SetBySlotNumber;
property Mach3: AnsiString index 15 read GetBySlotNumber write SetBySlotNumber;
property Mach4: AnsiString index 16 read GetBySlotNumber write SetBySlotNumber;
property Spellbook: AnsiString index 17 read GetBySlotNumber write SetBySlotNumber;
property Misc5: AnsiString index 18 read GetBySlotNumber write SetBySlotNumber;
property Backpack: TStrings read GetBackpack stored IsBackpackStored;
end;
{ TReward }
TReward = class(TNamedCollectionItem, IEmbeddedValue)
private
FValue: Int64;
function GetMetaclass: TMetaclass;
protected
procedure AssignTo(Dest: TPersistent); override;
property Metaclass: TMetaclass read GetMetaclass;
published
property Value: Int64 read FValue write FValue;
end;
{ TRewards }
TRewards = class(specialize TGNamedCollection<TReward>)
public
type TAllowedRewards = set of TMetaclass;
const IMPOSSIBLE_REWARDS: TAllowedRewards = [TMetaclass.faction, TMetaclass.hero, TMetaclass.heroClass];
private
FOwner: IMapObject;
FAllowedReward: TAllowedRewards;
procedure SetAllowedReward(AValue: TAllowedRewards);
protected
procedure ItemIdentifierChanged(Item: TCollectionItem; AOldName: String; ANewName: String); override;
public
constructor Create(AOwner: IMapObject);
property AllowedReward:TAllowedRewards read FAllowedReward write SetAllowedReward;
procedure AddOrUpdateReward(AType: TMetaclass; AIdentifier: AnsiString; AValue: Int64);
function GetValue(AType: TMetaclass; AIdentifier: AnsiString = ''): Int64;
property Owner: IMapObject read FOwner;
end;
{ TRewardResourceSet }
TRewardResourceSet = class(TResourceSet)
strict private
FData: TRewards;
protected
function GetAmount(AType: TResType): integer; override;
procedure SetAmount(AType: TResType; AValue: integer); override;
public
constructor Create(AData: TRewards);
end;
{ TRewardPrimarySkills }
TRewardPrimarySkills = class(TPrimarySkills)
private
FData: TRewards;
protected
function GetAttack: Integer; override;
function GetDefence: Integer; override;
function GetKnowledge: Integer; override;
function GetSpellpower: Integer; override;
procedure SetAttack(AValue: Integer); override;
procedure SetDefence(AValue: Integer); override;
procedure SetKnowledge(AValue: Integer); override;
procedure SetSpellpower(AValue: Integer); override;
public
constructor Create(AReward: TRewards);
function IsDefault: Boolean; override;
procedure Clear; override;
published
property Attack default 0;
property Defence default 0;
property Spellpower default 0;
property Knowledge default 0;
end;
{$pop}
{ TCustomObjectOptions }
TCustomObjectOptions = class(TObjectOptions)
end
unimplemented;
{ TGuardedObjectOptions }
TGuardedObjectOptions = class abstract (TObjectOptions)
private
FGuardMessage: TLocalizedString;
FGuards: TCreatureSet;
function IsGuardsStored: Boolean;
procedure SetGuardMessage(AValue: TLocalizedString);
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure Clear; override;
published
property Guards: TCreatureSet read FGuards stored IsGuardsStored;
property GuardMessage:TLocalizedString read FGuardMessage write SetGuardMessage;
end;
{ TOwnedObjectOptions }
TOwnedObjectOptions = class (TObjectOptions)
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
class function CanBeOwned: Boolean; override;
procedure Clear; override;
published
property Owner default TPlayer.none;
end;
{ TOwnedArmedObjectOptions }
TOwnedArmedObjectOptions = class abstract(TOwnedObjectOptions)
strict private
FArmy: TCreatureSet;
function IsArmyStored: Boolean;
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure Clear; override;
published
property Army: TCreatureSet read FArmy stored IsArmyStored;
end;
{ TSignBottleOptions }
TSignBottleOptions = class(TObjectOptions)
private
FText: TLocalizedString;
procedure SetText(AValue: TLocalizedString);
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property Text: TLocalizedString read FText write SetText;
end;
{ TPandorasOptions }
TPandorasOptions = class (TGuardedObjectOptions)
private
FArtifacts: TStrings;
FCreatures: TCreatureSet;
FPrimarySkills: TRewardPrimarySkills;
FResources: TResourceSet;
FReward: TRewards;
FSecondarySkills: THeroSecondarySkills;
FSpells: TStrings;
function GetExperience: UInt64;
function GetLuck: Int32;
function GetMana: Int32;
function GetMorale: Int32;
function IsArtifactsStored: Boolean;
function IsCreaturesStored: Boolean;
function IsPrimarySkillsStored: Boolean;
function IsResourcesStored: Boolean;
function IsSecondarySkillsStored: Boolean;
function IsSpellsStored: Boolean;
procedure SetExperience(AValue: UInt64);
procedure SetLuck(AValue: Int32);
procedure SetMana(AValue: Int32);
procedure SetMorale(AValue: Int32);
public//ISerializeNotify
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
public
procedure BeforeSerialize(Sender:TObject); override;
procedure AfterDeSerialize(Sender:TObject; AData: TJSONData);override;
procedure UpdateRewards;
published
property Experience: UInt64 read GetExperience write SetExperience default 0;
property Mana: Int32 read GetMana write SetMana default 0;
property Morale: Int32 read GetMorale write SetMorale default 0;
property Luck: Int32 read GetLuck write SetLuck default 0;
property Resources: TResourceSet read FResources stored IsResourcesStored;
property PrimarySkills: TRewardPrimarySkills read FPrimarySkills stored IsPrimarySkillsStored;
//not for interative editing, only for serialization
property Artifacts: TStrings read FArtifacts stored IsArtifactsStored;
property Creatures: TCreatureSet read FCreatures stored IsCreaturesStored;
property SecondarySkills: THeroSecondarySkills read FSecondarySkills stored IsSecondarySkillsStored;
property Spells: TStrings read FSpells stored IsSpellsStored;
property Reward: TRewards read FReward stored false;//todo: Pandoras box full reward support in format version 1.1
end;
{ TLocalEventOptions }
TLocalEventOptions = class(TPandorasOptions)
private
FAIActivable: boolean;
FAvailableFor: TPlayers;
FHumanActivable: boolean;
FRemoveAfterVisit: Boolean;
public
constructor Create(AObject: IMapObject); override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property HumanActivable: boolean read FHumanActivable write FHumanActivable default True;
property AIActivable: boolean read FAIActivable write FAIActivable default False;
property RemoveAfterVisit: Boolean read FRemoveAfterVisit write FRemoveAfterVisit default False;
property AvailableFor: TPlayers read FAvailableFor write FAvailableFor default ALL_PLAYERS;
end;
{ THeroOptions }
THeroOptions = class abstract (TOwnedArmedObjectOptions, IEditableHeroInfo)
private
FArtifacts: THeroArtifacts;
FBiography: TLocalizedString;
FExperience: UInt64;
FType: AnsiString;
FName: TLocalizedString;
FPatrolRadius: Integer;
FPortrait: Int32;
FPrimarySkills: THeroPrimarySkills;
FSex: THeroSex;
FSecondarySkills: THeroSecondarySkills;
FSpellBook: TStrings;
function GetTightFormation: Boolean;
function IsArtifactsStored: Boolean;
function IsPrimarySkillsStored: Boolean;
function IsSecondarySkillsStored: Boolean;
function IsSpellBookStored: Boolean;
procedure SetType(AValue: AnsiString);
procedure SetPatrolRadius(AValue: Integer);
procedure SetTightFormation(AValue: Boolean);
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure AfterSerialize(Sender: TObject; AData: TJSONData); override;
procedure AfterDeSerialize(Sender: TObject; AData: TJSONData); override;
procedure Clear; override;
public//IEditableHeroInfo, IHeroInfo
function GetHeroIdentifier: AnsiString;
function GetBiography: TLocalizedString;
procedure SetBiography(const AValue: TLocalizedString);
function GetExperience: UInt64;
procedure SetExperience(const AValue: UInt64);
function GetName: TLocalizedString;
procedure SetName(const AValue: TLocalizedString);
function GetPortrait: Int32;
procedure SetPortrait(const AValue: Int32);
function GetSex: THeroSex;
procedure SetSex(const AValue: THeroSex);
function GetPrimarySkills: THeroPrimarySkills;
function GetSecondarySkills: THeroSecondarySkills;
published
property &type: AnsiString read FType write SetType;
property TightFormation: Boolean read GetTightFormation write SetTightFormation default false;
property PatrolRadius: Integer read FPatrolRadius write SetPatrolRadius default -1;
property Artifacts: THeroArtifacts read FArtifacts stored IsArtifactsStored;
property Biography: TLocalizedString read FBiography write SetBiography;
property Experience: UInt64 read GetExperience write SetExperience default 0;
property Name: TLocalizedString read FName write SetName;
property PrimarySkills:THeroPrimarySkills read FPrimarySkills stored IsPrimarySkillsStored;
property SecondarySkills: THeroSecondarySkills read FSecondarySkills stored IsSecondarySkillsStored;
property SpellBook: TStrings read FSpellBook stored IsSpellBookStored;
public //manual streaming
property Sex: THeroSex read FSex write SetSex;
//internal icon index
//serialized as index in VCMI image list or as hero identifier
property Portrait: Int32 read FPortrait write FPortrait;
end;
{ TNormalHeroOptions }
TNormalHeroOptions = class(THeroOptions, IEditableHeroInfo)
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
class function MustBeOwned: Boolean; override;
class function ZIndex: Integer; override;
end;
{ TRandomHeroOptions }
TRandomHeroOptions = class(THeroOptions, IEditableHeroInfo)
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
class function MustBeOwned: Boolean; override;
class function ZIndex: Integer; override;
end;
{ TPrisonOptions }
TPrisonOptions = class(THeroOptions, IEditableHeroInfo)
public
constructor Create(AObject: IMapObject); override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
end;
{ TCreatureOptions }
TCreatureOptions = class(TObjectOptions)
private
FCharacter: TCreatureCharacter;
FAmount: Integer;
FNeverFlees: boolean;
FNoGrowing: boolean;
FReward: TRewards;
FRewardArtifact: AnsiString;
FRewardMessage: TLocalizedString;
FRewardResources: TResourceSet;
function IsRewardArtifactStored: Boolean;
function IsRewardMessageStored: Boolean;
function IsRewardResourcesStored: Boolean;
function IsRewardStored: Boolean;
procedure SetAmount(AValue: Integer);
procedure SetNeverFlees(AValue: boolean);
procedure SetNoGrowing(AValue: boolean);
procedure SetRewardArtifact(AValue: AnsiString);
procedure SetRewardMessage(AValue: TLocalizedString);
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property NeverFlees: boolean read FNeverFlees write SetNeverFlees default False;
property NoGrowing: boolean read FNoGrowing write SetNoGrowing default False;
property Amount: Integer read FAmount write SetAmount default 0; //0=random
property Character: TCreatureCharacter read FCharacter write FCharacter nodefault;
property RewardMessage: TLocalizedString read FRewardMessage write SetRewardMessage stored IsRewardMessageStored;
property RewardResources: TResourceSet read FRewardResources stored IsRewardResourcesStored;
property RewardArtifact: AnsiString read FRewardArtifact write SetRewardArtifact stored IsRewardArtifactStored;
property Reward: TRewards read FReward stored false;//todo: Creature full reward support in format version 1.1
end;
{ TSeerHutOptions }
TSeerHutOptions = class(TObjectOptions)
public
const
ALLOWED_REWARDS: TRewards.TAllowedRewards =
[TMetaclass.artifact, TMetaclass.creature, TMetaclass.experience, TMetaclass.luck, TMetaclass.mana,
TMetaclass.morale, TMetaclass.movement, TMetaclass.primarySkill, TMetaclass.secondarySkill, TMetaclass.spell,
TMetaclass.resource];
private
FQuest: TQuest;
FReward: TRewards;
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
procedure AddReward(AType: TSeerHutReward; AIdentifier: AnsiString; AValue: Int64);
published
property Quest: TQuest read FQuest;
property Reward: TRewards read FReward;
end;
{ TWitchHutOptions }
TWitchHutOptions = class(TObjectOptions)
private
FAllowedSkills: TLogicalIDCondition;
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property AllowedSkills: TLogicalIDCondition read FAllowedSkills;
end;
{ TScholarOptions }
TScholarOptions = class(TObjectOptions)
strict private
FReward: TRewards;
FRewardPrimSkill: AnsiString;
FRewardSecSkill: AnsiString;
FRewardSpell: AnsiString;
procedure SetRewardPrimSkill(AValue: AnsiString);
procedure SetRewardSecSkill(AValue: AnsiString);
procedure SetRewardSpell(AValue: AnsiString);
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property RewardPrimSkill: AnsiString read FRewardPrimSkill write SetRewardPrimSkill;
property RewardSkill: AnsiString read FRewardSecSkill write SetRewardSecSkill;
property RewardSpell: AnsiString read FRewardSpell write SetRewardSpell;
property Reward: TRewards read FReward stored false;//todo: Shcolar full reward support in format version 1.1
end;
{ TGarrisonOptions }
TGarrisonOptions = class(TOwnedArmedObjectOptions)
private
FRemovableUnits: Boolean;
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property RemovableUnits: Boolean read FRemovableUnits write FRemovableUnits default False;
end;
{ TArtifactOptions }
TArtifactOptions = class(TGuardedObjectOptions)
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
end;
{ TSpellScrollOptions }
TSpellScrollOptions = class(TArtifactOptions)
private
FSpell: AnsiString;
procedure SetSpell(AValue: AnsiString);
public
constructor Create(AObject: IMapObject); override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property Spell: AnsiString read FSpell write SetSpell;
end;
{ TResourceOptions }
TResourceOptions = class(TGuardedObjectOptions)
private
FAmount: Integer;
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property Amount: Integer read FAmount write FAmount default 0;
end;
{ TTownOptions }
TTownOptions = class(TOwnedArmedObjectOptions, IFPObserver)
private
FBuildings: TLogicalIDCondition;
FHasFort: Boolean;
FName: TLocalizedString;
FSpells: TLogicalIDCondition;
function GetTightFormation: Boolean;
function HasFortStored: Boolean;
function IsBuildingsStored: Boolean;
function IsSpellsStored: Boolean;
procedure SetHasFort(AValue: Boolean);
procedure SetTightFormation(AValue: Boolean);
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure AssignTemplate(ATemplate: TMapObjectTemplate); override;
function SelectTemplate(AType: TMapObjectType): TMapObjectTemplate; override;
procedure Clear; override;
public //IFPObserver
procedure FPOObservedChanged(ASender: TObject; Operation: TFPObservedOperation; Data: Pointer);
published
property TightFormation: Boolean read GetTightFormation write SetTightFormation default false;
property Name: TLocalizedString read FName write FName;
property Spells: TLogicalIDCondition read FSpells stored IsSpellsStored;
property Buildings: TLogicalIDCondition read FBuildings stored IsBuildingsStored;
property HasFort: Boolean read FHasFort write SetHasFort stored HasFortStored;
end;
{ TAbandonedOptions }
TAbandonedOptions = class(TObjectOptions)
private
FPossibleResources: TStrings;
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property PossibleResources: TStrings read FPossibleResources;
end;
{ TMineOptions }
TMineOptions = class (TOwnedArmedObjectOptions)
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
end;
{ TShrineOptions }
TShrineOptions = class abstract (TObjectOptions)
private
FSpell: AnsiString;
procedure SetSpell(AValue: AnsiString);
strict protected
class function GetSpellLevel: Integer; virtual; abstract;
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
property SpellLevel: Integer read GetSpellLevel;
published
property Spell: AnsiString read FSpell write SetSpell;
end;
{ TShrine1Options }
TShrine1Options = class (TShrineOptions)
strict protected
class function GetSpellLevel: Integer; override;
end;
{ TShrine2Options }
TShrine2Options = class (TShrineOptions)
strict protected
class function GetSpellLevel: Integer; override;
end;
{ TShrine3Options }
TShrine3Options = class (TShrineOptions)
strict protected
class function GetSpellLevel: Integer; override;
end;
{ TGrailOptions }
TGrailOptions = class (TObjectOptions)
private
FRadius: Integer;
procedure SetRadius(AValue: Integer);
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property Radius: Integer read FRadius write FRadius;
end;
{ TBaseRandomDwellingOptions }
TBaseRandomDwellingOptions = class abstract (TObjectOptions)
private
FAllowedFactions: TLogicalIDCondition;
FMaxLevel: UInt8;
FMinLevel: UInt8;
FSameAsTown: String;
procedure SetMaxLevel(AValue: UInt8);
procedure SetMinLevel(AValue: UInt8);
function IsAllowedFactionsStored: boolean;
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure Clear; override;
property MinLevel: UInt8 read FMinLevel write SetMinLevel default 0;
property MaxLevel: UInt8 read FMaxLevel write SetMaxLevel default 7;
property AllowedFactions: TLogicalIDCondition read FAllowedFactions stored IsAllowedFactionsStored;
procedure SetSameAsTown(AValue: string);
property SameAsTown: string read FSameAsTown write SetSameAsTown;
class function CanBeOwned: Boolean; override;
published
property Owner default TPlayer.none;
end;
{ TRandomDwellingOptions }
TRandomDwellingOptions = class (TBaseRandomDwellingOptions)
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
published
property MinLevel;
property MaxLevel;
property AllowedFactions;
property SameAsTown;
end;
{ TRandomDwellingLVLOptions }
TRandomDwellingLVLOptions = class (TBaseRandomDwellingOptions)
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
published
property AllowedFactions;
property SameAsTown;
end;
{ TRandomDwellingTownOptions }
TRandomDwellingTownOptions = class (TBaseRandomDwellingOptions)
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
published
property MinLevel;
property MaxLevel;
end;
{ TQuestGuardOptions }
TQuestGuardOptions = class (TObjectOptions)
private
FQuest: TQuest;
public
constructor Create(AObject: IMapObject); override;
destructor Destroy; override;
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
published
property Quest: TQuest read FQuest;
end;
{ THeroPlaceholderOptions }
THeroPlaceholderOptions = class (TObjectOptions)
private
FPower: UInt8;
FTypeID: AnsiString;
procedure SetPower(AValue: UInt8);
procedure SetTypeID(AValue: AnsiString);
public
procedure ApplyVisitor(AVisitor: IObjectOptionsVisitor); override;
procedure Clear; override;
class function ZIndex: Integer; override;
class function CanBeOwned: Boolean; override;
class function MustBeOwned: Boolean; override;
published
property &Type: AnsiString read FTypeID write SetTypeID;
property Power: UInt8 read FPower write SetPower default 0;
property Owner default TPlayer.none;
end;
{ IObjectOptionsVisitor }
IObjectOptionsVisitor = interface
procedure VisitLocalEvent(AOptions: TLocalEventOptions);
procedure VisitSignBottle(AOptions: TSignBottleOptions);
procedure VisitNormalHero(AOptions: TNormalHeroOptions);
procedure VisitRandomHero(AOptions: TRandomHeroOptions);
procedure VisitPrison(AOptions: TPrisonOptions);
procedure VisitMonster(AOptions: TCreatureOptions);
procedure VisitSeerHut(AOptions: TSeerHutOptions);
procedure VisitWitchHut(AOptions: TWitchHutOptions);
procedure VisitScholar(AOptions: TScholarOptions);
procedure VisitGarrison(AOptions: TGarrisonOptions);
procedure VisitArtifact(AOptions: TArtifactOptions);
procedure VisitSpellScroll(AOptions: TSpellScrollOptions);
procedure VisitResource(AOptions: TResourceOptions);
procedure VisitTown(AOptions: TTownOptions);
procedure VisitAbandonedMine(AOptions:TAbandonedOptions);
procedure VisitMine(AOptions: TMineOptions);
procedure VisitShrine(AOptions: TShrineOptions);
procedure VisitPandorasBox(AOptions: TPandorasOptions);
procedure VisitGrail(AOptions: TGrailOptions);
procedure VisitRandomDwelling(AOptions: TRandomDwellingOptions);
procedure VisitRandomDwellingLVL(AOptions: TRandomDwellingLVLOptions);
procedure VisitRandomDwellingTown(AOptions: TRandomDwellingTownOptions);
procedure VisitQuestGuard(AOptions:TQuestGuardOptions);
procedure VisitHeroPlaceholder(AOptions: THeroPlaceholderOptions);
procedure VisitOwnedObject(AOptions: TOwnedObjectOptions);
end;
implementation
{ TCreatureInstInfo }
function TCreatureInstInfo.GetRawRandom: integer;
begin
Result := (Level - 1) * 2 + ifthen(Upgraded, 1, 0);
end;
procedure TCreatureInstInfo.SetRawRandom(AValue: integer);
var
random_type: Integer;
begin
random_type := AValue;
if (random_type < 0) or (random_type > 13) then
begin
raise Exception.CreateFmt('Invalid raw random type %d ', [random_type]);
end;
Level:= (random_type div 2) + 1;
Upgraded:=(random_type mod 2) > 0;
end;
function TCreatureInstInfo.IsEmpty: Boolean;