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 pathlists_manager.pas
2622 lines (2127 loc) · 61.4 KB
/
lists_manager.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 lists_manager;
{$I compilersetup.inc}
interface
uses
Classes, SysUtils, gmap, gutil, gvector, fgl, Types, fpjson, filesystem_base, editor_consts,
editor_types, editor_utils, vcmi_json, h3_txt, base_info, editor_classes,
logical_id_condition, logical_expression, logical_building_condition;
type
TListsManager = class;
{$push}
{$m+}
{ TTextDataConfig }
TTextDataConfig = class
private
FArtifact: integer;
FCreature: integer;
FFaction: integer;
FHero: integer;
FHeroClass: integer;
FSpell: integer;
procedure SetArtifact(AValue: integer);
procedure SetCreature(AValue: integer);
procedure SetFaction(AValue: integer);
procedure SetHero(AValue: integer);
procedure SetHeroClass(AValue: integer);
procedure SetSpell(AValue: integer);
published
property HeroClass: integer read FHeroClass write SetHeroClass default HEROCLASS_QUANTITY;
property Artifact: integer read FArtifact write SetArtifact default ARTIFACT_QUANTITY;
property Creature: integer read FCreature write SetCreature default CREATURE_QUANTITY;
property Faction: integer read FFaction write SetFaction default FACTION_QUANTITY;
property Hero: integer read FHero write SetHero default HERO_QUANTITY;
property Spell: integer read FSpell write SetSpell default SPELL_QUANTITY;
end;
{$pop}
{ TMetaclassInfo }
TMetaclassInfo = class(TBaseInfo)
private
FList: THashedCollection;
FMaxValue: Int64;
FMinValue: Int64;
function GetMetaclass: TMetaclass;
procedure SetMaxValue(AValue: Int64);
procedure SetMetaclass(AValue: TMetaclass);
procedure SetMinValue(AValue: Int64);
public
property Metaclass: TMetaclass read GetMetaclass write SetMetaclass;
function IsEntity: Boolean;
property MinValue: Int64 read FMinValue write SetMinValue;
property MaxValue: Int64 read FMaxValue write SetMaxValue;
//only for entities
property List: THashedCollection read FList write FList;
end;
{ TMetaclassInfos }
TMetaclassInfos = class(specialize TGNamedCollection<TMetaclassInfo>)
end;
{ TResourceTypeInfo }
TResourceTypeInfo = class(TBaseInfo)
end;
{ TResourceTypeInfos }
TResourceTypeInfos = class(specialize TGNamedCollection<TResourceTypeInfo>)
end;
{ TPrimSkillInfo }
TPrimSkillInfo = class(TBaseInfo)
end;
{ TPrimSkillInfos }
TPrimSkillInfos = class (specialize TGNamedCollection<TPrimSkillInfo>)
public
end;
{ TSkillInfo }
TSkillInfo = class (TBaseInfo)
end;
{ TSkillInfos }
TSkillInfos = class (specialize TGNamedCollection<TSkillInfo>)
public
procedure FillWithAllIds(AList: TLogicalIDCondition);
end;
TSpellType = (adventure=0, combat=1, ability=2);
{ TSpellInfo }
TSpellInfo = class (TBaseInfo)
private
Ftype: TSpellType;
FLevel: integer;
procedure SetType(AValue: TSpellType);
procedure SetLevel(AValue: integer);
public
function IsValid: Boolean; override;
published
property level: integer read FLevel write SetLevel;
property &type: TSpellType read FType write SetType;
end;
{ TSpellInfos }
TSpellInfos = class (specialize TGNamedCollection<TSpellInfo>)
public
//all except abilities
procedure FillWithAllIds(AList: TLogicalIDCondition);
//all except abilities with level = ALevel if ALevel <> 0; fills with Name and TSpellInfo
procedure FillWithAllIds(AList: TStrings; ALevel: integer);
end;
{$push}
{$m+}
{ TGuildSpell }
TGuildSpell = class(TNamedCollectionItem, IEmbeddedValue)
private
FChance: Integer;
procedure SetChance(AValue: Integer);
published
property Chance: Integer read FChance write SetChance nodefault;
end;
{ TGuildSpells }
TGuildSpells = class(specialize TGNamedCollection<TGuildSpell>)
end;
{ TTownBuilding }
TTownBuilding = class(TNamedCollectionItem)
private
FDescription: TLocalizedString;
FID: Integer;
FMode: TBuildMode;
FName: TLocalizedString;
FRequires: TBuildingCondition;
FUpgrades: AnsiString;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
function GetDisplayName: string; override;
published
property ID:Integer read FID write FID;
property Name: TLocalizedString read FName write FName;
property Description: TLocalizedString read FDescription write FDescription;
property Mode: TBuildMode read FMode write FMode default TBuildMode.normal;
property Upgrades: AnsiString read FUpgrades write FUpgrades;
property Requires: TBuildingCondition read FRequires;
end;
{ TTownBuildings }
TTownBuildings = class(specialize TGNamedCollection<TTownBuilding>)
end;
{ TTownInfo }
TTownInfo = class
private
FBuildings: TTownBuildings;
FGuildSpells: TGuildSpells;
FMageGuild: Integer;
FMapObject: TJSONObject;
procedure SetMageGuild(AValue: Integer);
public
constructor Create;
destructor Destroy; override;
published
property MapObject: TJSONObject read FMapObject;
property GuildSpells:TGuildSpells read FGuildSpells;
property Buildings:TTownBuildings read FBuildings;
property MageGuild:Integer read FMageGuild write SetMageGuild;
end;
{$pop}
{ TFactionInfo }
TFactionInfo = class(TBaseInfo, ISerializeNotify)
private
FHasTown: Boolean;
FTown: TTownInfo;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
property HasTown: Boolean read FHasTown;
public //ISerializeNotify
procedure BeforeSerialize(Sender:TObject);
procedure AfterSerialize(Sender:TObject; AData: TJSONData);
procedure BeforeDeSerialize(Sender:TObject; AData: TJSONData);
procedure AfterDeSerialize(Sender:TObject; AData: TJSONData);
published
property Town: TTownInfo read FTown;
end;
{ TFactionInfos }
TFactionInfos = class (specialize TGNamedCollection<TFactionInfo>)
public
procedure FillWithAllIds(AList: TLogicalIDCondition; AIncludeMods: Boolean);
procedure FillWithAllIds(AList: TStrings; AIncludeMods: Boolean);
procedure FillWithTownIds(AList: TStrings; AIncludeMods: Boolean);
end;
{ THeroClassInfo }
THeroClassInfo = class(TMapObjectInfo)
private
FPrimarySkills: THeroPrimarySkills;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
published
property PrimarySkills: THeroPrimarySkills read FPrimarySkills;
end;
{ THeroClassInfos }
THeroClassInfos = class(specialize TGNamedCollection<THeroClassInfo>)
public
end;
{$push}
{$m+}
{ TBaseGraphics }
TBaseGraphics = class
private
FMap: AnsiString;
procedure SetMap(AValue: AnsiString);
public
procedure AddTemplates(ASubtypeConfig: TJSONObject);
published
property Map: AnsiString read FMap write SetMap;
end;
{ TBaseTexts }
TBaseTexts = class
private
FName: TLocalizedString;
procedure SetName(AValue: TLocalizedString);
published
property Name: TLocalizedString read FName write SetName;
end;
{ TCreatureName }
TCreatureName = class
private
FPlural: TLocalizedString;
FSingular: TLocalizedString;
procedure SetPlural(AValue: TLocalizedString);
procedure SetSingular(AValue: TLocalizedString);
published
property Singular: TLocalizedString read FSingular write SetSingular;
property Plural: TLocalizedString read FPlural write SetPlural;
end;
{$pop}
TCreatureGraphics = class(TBaseGraphics)
end;
{ TCreatureInfo }
TCreatureInfo = class(TBaseInfo)
private
FDisabled: Boolean;
FFaction: AnsiString;
FGraphics: TCreatureGraphics;
FName: TCreatureName;
FSpecial: Boolean;
protected
function GetName: TLocalizedString; override;
procedure SetName(const AValue: TLocalizedString); override;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
function IsValid: Boolean; override;
published
property Name:TCreatureName read FName;
property Graphics: TCreatureGraphics read FGraphics;
property Disabled: Boolean read FDisabled write FDisabled;
property Special: Boolean read FSpecial write FSpecial;
property Faction: AnsiString read FFaction write FFaction;
end;
{ TCreatureInfos }
TCreatureInfos = class(specialize TGNamedCollection<TCreatureInfo>)
public
end;
{ TArtifactGraphics }
TArtifactGraphics = class(TBaseGraphics)
end;
TArtifactTexts = class(TBaseTexts)
end;
TArtifactType = (HERO, CREATURE, COMMANDER);
TArtifactTypes = set of TArtifactType;
{ TArtifactInfo }
TArtifactInfo = class(TBaseInfo)
private
FClass: TArtifactClass;
FGraphics: TArtifactGraphics;
FTexts: TArtifactTexts;
FSlot: TStrings;
FType: TArtifactTypes;
procedure SetType(AValue: TArtifactTypes);
protected
function GetName: TLocalizedString; override;
procedure SetName(const AValue: TLocalizedString); override;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
published
property &Class: TArtifactClass read FClass write FClass;
property Graphics: TArtifactGraphics read FGraphics;
property Slot: TStrings read FSlot;
property Text: TArtifactTexts read FTexts;
property &type:TArtifactTypes read FType write SetType;
end;
{ TArtifactInfos }
TArtifactInfos = class(specialize TGNamedCollection<TArtifactInfo>)
public
//all not special
procedure FillWithAllIds(AList: TLogicalIDCondition);
end;
{ THeroTexts }
THeroTexts = class(TBaseTexts)
private
FBiography: TLocalizedString;
procedure SetBiography(AValue: TLocalizedString);
published
property Biography: TLocalizedString read FBiography write SetBiography;
end;
{$push}
{$m+}
{ THeroImages }
THeroImages = class
private
FLarge: AnsiString;
FSmall: AnsiString;
published
property Large: AnsiString read FLarge write FLarge;
property Small: AnsiString read FSmall write FSmall;
end;
{$pop}
{ THeroInfo }
THeroInfo = class(TBaseInfo, IHeroInfo, ISerializeNotify)
private
FFemale: Boolean;
FHeroClass: TIdentifier;
FImages: THeroImages;
FPortraitIndex: Int32;
FSkills: THeroSecondarySkills;
FSpecial: Boolean;
FSpellBook: TStrings;
FTexts: THeroTexts;
procedure SetFemale(AValue: Boolean);
procedure SetHeroClass(AValue: TIdentifier);
procedure SetPortraitIndex(AValue: Int32);
procedure SetSpecial(AValue: Boolean);
protected
procedure SetName(const AValue: TLocalizedString); override;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
class function UseMeta: boolean; override;
//IHeroInfo
function GetHeroIdentifier: AnsiString;
function GetPortrait: Int32;
function GetBiography: TLocalizedString;
function GetExperience: UInt64;
function GetName: TLocalizedString; override;
function GetSex: THeroSex;
function GetPrimarySkills: THeroPrimarySkills;
function GetSecondarySkills: THeroSecondarySkills;
public// ISerializeNotify
procedure BeforeSerialize(Sender:TObject);
procedure AfterSerialize(Sender:TObject; AData: TJSONData);
procedure BeforeDeSerialize(Sender:TObject; AData: TJSONData);
procedure AfterDeSerialize(Sender:TObject; AData: TJSONData);
public
//index of portrait info in the list
property PortraitIndex: Int32 read FPortraitIndex write SetPortraitIndex;
published
property Images: THeroImages read FImages;
property Texts: THeroTexts read FTexts;
property Female: Boolean read FFemale write SetFemale nodefault;
property Special: Boolean read FSpecial write SetSpecial default False;
property &Class: TIdentifier read FHeroClass write SetHeroClass;
property Spellbook: TStrings read FSpellBook;
public//not "standard" format
property Skills: THeroSecondarySkills read FSkills;
end;
{ THeroInfos }
THeroInfos = class(specialize TGNamedCollection<THeroInfo>)
private
FOwner:TListsManager;
protected
procedure PushResolveRequest(AObject: TNamedCollectionItem; AMetaClass: TMetaclass; const AProperty: ShortString); override;
public
constructor Create(AOwner: TListsManager);
procedure FillWithNotSpecial(AList: TLogicalIDCondition);
procedure FillWithHeroesOfClass(ATarget: TStrings; AHeroClass: AnsiString);
end;
{ THeroPortraitInfo }
THeroPortraitInfo = class(TCollectionItem)
private
FHeroIdentifier: AnsiString;
FIconIndex: Int32;
FIconPath: AnsiString;
FName: TLocalizedString;
procedure SetHeroIdentifier(AValue: AnsiString);
procedure SetIconIndex(AValue: Int32);
procedure SetIconPath(AValue: AnsiString);
procedure SetName(AValue: TLocalizedString);
public
constructor Create(ACollection: TCollection); override;
function IsEmpty: Boolean;
property HeroIdentifier: AnsiString read FHeroIdentifier write SetHeroIdentifier;
property IconIndex: Int32 read FIconIndex write SetIconIndex;
property IconPath: AnsiString read FIconPath write SetIconPath;
property Name: TLocalizedString read FName write SetName;
end;
{ THeroPortraitInfos }
THeroPortraitInfos = class(specialize TGArrayCollection<THeroPortraitInfo>)
end;
{ TListsManager }
TListsManager = class (TFSConsumer)
private
type
TSlotMap = specialize gmap.TMap<AnsiString, Integer, TStringCompare>;
TLessInteger = specialize gutil.TLess<Integer>;
TBuildingCnv = specialize gmap.TMap<Integer, Integer, TLessInteger>;
PResolveRequest = ^TResolveRequest;
TResolveRequest = record
AObject: TNamedCollectionItem;
AMetaClass: TMetaclass;
AProperty: ShortString;
end;
TResolveRequests = specialize TVector<TResolveRequest>;
strict private
FDestreamer: TVCMIJSONDestreamer;
FNameMap: TNameToIdMap;
FMetaclassInfos: TMetaclassInfos;
FResourceTypeInfos: TResourceTypeInfos;
FPrimSkillInfos: TPrimSkillInfos;
FSkillInfos: TSkillInfos;
FSpellInfos: TSpellInfos;
FFactionInfos: TFactionInfos;
FRandomFaction: TFactionInfo;
FBuildingCnv:TBuildingCnv;
FBuildingCnvSpec: TJSONArray;
FHeroClassInfos: THeroClassInfos;
FCreatureInfos: TCreatureInfos;
FHeroInfos: THeroInfos;
FArtifactInfos: TArtifactInfos;
FArtifactSlotMaps: array[0..ARTIFACT_SLOT_COUNT-1] of TStringList;
FSlotIds: TSlotMap;
FResolveRequests: TResolveRequests;
procedure FillSlotIds;
procedure LoadMetaclasses;
procedure LoadBuildings;
procedure LoadPrimSkills;
procedure LoadSkills;
procedure LoadResourceTypes;
procedure LoadTextDataConfig;
strict private //Accesors
function GetPlayerName(const APlayer: TPlayer): TLocalizedString;
strict private
FHeroPortraits: THeroPortraitInfos;
FTextDataConfig: TTextDataConfig;
function GetArtifactSlotMap(ASlot: Integer): TStrings;
function GetHeroClasses(AId: AnsiString): THeroClassInfo;
function GetHeroes(AId: AnsiString): THeroInfo;
procedure MergeLegacy(ASrc: TJsonObjectList; ADest:TJSONObject);
procedure FillArtifactCache;
procedure Load(AProgess: IProgressCallback; APaths: TModdedConfigPaths; ALegacyConfig: TJsonObjectList; ATarget:THashedCollection);
procedure ResolveIdentifier(var AIdentifier: AnsiString; ALocalScope: AnsiString; AMetaclass: TMetaclass);
function ResolveIdentifier(AIdentifier: AnsiString; AMetaclass: TMetaclass): Boolean ;
function ResolveHeroClass(AIdentifier: AnsiString): Boolean;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure PushResolveRequest(AObject: TNamedCollectionItem; AMetaClass: TMetaclass; const AProperty: ShortString);
procedure PreLoad;
procedure LoadFactions(AProgess: IProgressCallback; APaths: TModdedConfigPaths);
procedure LoadHeroClasses(AProgess: IProgressCallback; APaths: TModdedConfigPaths);
procedure LoadCreatures(AProgess: IProgressCallback; APaths: TModdedConfigPaths);
procedure LoadArtifacts(AProgess: IProgressCallback; APaths: TModdedConfigPaths);
procedure LoadSpells(AProgess: IProgressCallback; APaths: TModdedConfigPaths);
procedure LoadHeroes(AProgess: IProgressCallback; APaths: TModdedConfigPaths);
procedure LoadHeroPortraits(AProgess: IProgressCallback);
procedure ProcessResolveRequests;
public
property TextDataConfig: TTextDataConfig read FTextDataConfig;
property PlayerName[const APlayer: TPlayer]: TLocalizedString read GetPlayerName;
procedure FillWithPlayers(ATarget: TStrings; AIncludeNeutral: Boolean);
function SIDIdNID(AID: AnsiString): TCustomID;
//mods
function GetEnabledMods: TStringDynArray;
//metaclasses
property Metaclasses: TMetaclassInfos read FMetaclassInfos;
//primary skills
property PrimarySkills: TPrimSkillInfos read FPrimSkillInfos;
//secondary skills
function SkillNidToString (ASkill: TCustomID): AnsiString;
property SkillInfos: TSkillInfos read FSkillInfos;
function GetSkill(const AID: AnsiString): TSkillInfo;
//Spells
function SpellIndexToString (ASpell: TCustomID): AnsiString;
property SpellInfos: TSpellInfos read FSpellInfos;
function GetSpell(const AID: AnsiString): TSpellInfo;
//Factions
property FactionInfos:TFactionInfos read FFactionInfos;
function FactionIndexToString (AIndex: TCustomID):AnsiString;
function GetFaction(const AID: AnsiString): TFactionInfo;
property RandomFaction: TFactionInfo read FRandomFaction;
//Buildings
function BuildingIdToString (ABuilding: TCustomID): AnsiString; deprecated; //vcmi id to string
function BuildingIndexToString (ATown, ABuilding: TCustomID): AnsiString; //h3 id to string
//Hero classes
property HeroClassInfos:THeroClassInfos read FHeroClassInfos;
function HeroClassIndexToString (AIndex: TCustomID):AnsiString;
property HeroClasses[AId: AnsiString]: THeroClassInfo read GetHeroClasses;
//Creatures
function CreatureIndexToString (AIndex: TCustomID): AnsiString;
property CreatureInfos: TCreatureInfos read FCreatureInfos;
//Artifacts
function ArtifactIndexToString (AIndex: TCustomID): AnsiString;
property ArtifactInfos: TArtifactInfos read FArtifactInfos;
property ArtifactSlotMap[ASlot: Integer]: TStrings read GetArtifactSlotMap;
//Heroes
function HeroIndexToString (AIndex: TCustomID): AnsiString;
property HeroInfos: THeroInfos read FHeroInfos;
property Heroes[AId: AnsiString]: THeroInfo read GetHeroes;
procedure FillWithHeroesOfClass(ATarget: TStrings; AHeroClass: AnsiString);
property HeroPortraits: THeroPortraitInfos read FHeroPortraits;
procedure SaveHeroPortrait(ADest: TJSONData; AValue: Int32);
function LoadHeroPortrait(ASrc: TJSONData):Int32;
end;
implementation
uses FileUtil, LazLoggerBase, typinfo;
const
SEC_SKILL_TRAITS = 'data\sstraits';
SPELL_TRAITS = 'data\sptraits';
HERO_CLASS_TRAITS = 'data\hctraits';
CREATURE_TRAITS = 'data\crtraits';
ARTIFACT_TRAITS = 'data\artraits';
HERO_TRAITS = 'data\hotraits';
HERO_BIOS = 'data\herobios';
TEXT_DATA_CONFIG = 'config\defaultMods';
{ THeroPortraitInfo }
procedure THeroPortraitInfo.SetHeroIdentifier(AValue: AnsiString);
begin
FHeroIdentifier:=AValue;
end;
procedure THeroPortraitInfo.SetIconIndex(AValue: Int32);
begin
FIconIndex:=AValue;
end;
procedure THeroPortraitInfo.SetIconPath(AValue: AnsiString);
begin
FIconPath:=AValue;
end;
procedure THeroPortraitInfo.SetName(AValue: TLocalizedString);
begin
FName:=AValue;
end;
constructor THeroPortraitInfo.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
FHeroIdentifier := '';
FIconIndex := -1;
FIconPath:='';
end;
function THeroPortraitInfo.IsEmpty: Boolean;
begin
Result := (IconIndex = -1) and (FHeroIdentifier = '') or (IconPath = '');
end;
{ TMetaclassInfo }
function TMetaclassInfo.GetMetaclass: TMetaclass;
begin
result := TMetaclass(Index);
end;
procedure TMetaclassInfo.SetMaxValue(AValue: Int64);
begin
if FMaxValue=AValue then Exit;
FMaxValue:=AValue;
end;
procedure TMetaclassInfo.SetMetaclass(AValue: TMetaclass);
begin
Index:=TCustomID(AValue);
Identifier:= GetEnumName(TypeInfo(TMetaclass), index);
end;
procedure TMetaclassInfo.SetMinValue(AValue: Int64);
begin
if FMinValue=AValue then Exit;
FMinValue:=AValue;
end;
function TMetaclassInfo.IsEntity: Boolean;
begin
Result := Assigned(FList);
end;
{ TTownBuilding }
constructor TTownBuilding.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
FRequires := TBuildingCondition.CreateRoot(TBuildingConditionItem);
FMode:=TBuildMode.normal;
end;
destructor TTownBuilding.Destroy;
begin
FRequires.Free;
inherited Destroy;
end;
function TTownBuilding.GetDisplayName: string;
begin
if FName = '' then
begin
Result:=inherited GetDisplayName;
end
else begin
Result:=FName;
end;
end;
{ TCreatureName }
procedure TCreatureName.SetPlural(AValue: TLocalizedString);
begin
if FPlural=AValue then Exit;
FPlural:=AValue;
end;
procedure TCreatureName.SetSingular(AValue: TLocalizedString);
begin
if FSingular=AValue then Exit;
FSingular:=AValue;
end;
{ THeroClassInfo }
constructor THeroClassInfo.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
FPrimarySkills := THeroPrimarySkills.Create;
FPrimarySkills.SetZero;
end;
destructor THeroClassInfo.Destroy;
begin
FPrimarySkills.Free;
inherited Destroy;
end;
{ TGuildSpell }
procedure TGuildSpell.SetChance(AValue: Integer);
begin
if FChance=AValue then Exit;
FChance:=AValue;
end;
{ TTownInfo }
procedure TTownInfo.SetMageGuild(AValue: Integer);
begin
if FMageGuild=AValue then Exit;
if (AValue <1) or (AValue >5) then
begin
raise EConfigurationError.CreateFmt('Invalid magic guild level %d',[AValue]);
end;
FMageGuild:=AValue;
end;
constructor TTownInfo.Create;
begin
inherited Create;
FMapObject := CreateJSONObject([]);
FGuildSpells := TGuildSpells.Create;
FBuildings := TTownBuildings.Create;
end;
destructor TTownInfo.Destroy;
begin
FBuildings.Free;
FGuildSpells.Free;
FMapObject.Free;
inherited Destroy;
end;
{ THeroInfos }
procedure THeroInfos.PushResolveRequest(AObject: TNamedCollectionItem; AMetaClass: TMetaclass;
const AProperty: ShortString);
begin
FOwner.PushResolveRequest(AObject, AMetaClass, AProperty);
end;
constructor THeroInfos.Create(AOwner: TListsManager);
begin
inherited Create;
FOwner := AOwner;
end;
procedure THeroInfos.FillWithNotSpecial(AList: TLogicalIDCondition);
var
obj: THeroInfo;
idx: Integer;
begin
for idx := 0 to Count - 1 do
begin
obj := Items[idx];
if obj.Special then
begin
AList.NoneOf.Add(obj.Identifier);
end;
end;
end;
procedure THeroInfos.FillWithHeroesOfClass(ATarget: TStrings; AHeroClass: AnsiString);
var
hero_info: THeroInfo;
i: Integer;
begin
ATarget.Clear;
for i := 0 to Count - 1 do
begin
hero_info := Items[i];
if hero_info.&Class = AHeroClass then
begin
ATarget.AddObject(hero_info.Name, hero_info);
end;
end;
end;
{ THeroInfo }
procedure THeroInfo.SetHeroClass(AValue: TIdentifier);
begin
if FHeroClass=AValue then Exit;
FHeroClass:=AValue;
PushResolveRequest(TMetaclass.HeroClass, 'Class');
end;
procedure THeroInfo.SetPortraitIndex(AValue: Int32);
begin
FPortraitIndex:=AValue;
end;
procedure THeroInfo.SetSpecial(AValue: Boolean);
begin
if FSpecial=AValue then Exit;
FSpecial:=AValue;
end;
function THeroInfo.GetName: TLocalizedString;
begin
Result:=FTexts.Name;
end;
procedure THeroInfo.SetName(const AValue: TLocalizedString);
begin
FTexts.Name:=AValue;
end;
procedure THeroInfo.SetFemale(AValue: Boolean);
begin
if FFemale=AValue then Exit;
FFemale:=AValue;
end;
constructor THeroInfo.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
FImages := THeroImages.Create;
FTexts := THeroTexts.Create;
FSpellBook := TIdentifierSet.Create(nil);
FSkills := THeroSecondarySkills.Create;
FPortraitIndex:=-1;
end;
destructor THeroInfo.Destroy;
begin
FSkills.Free;
FSpellBook.Free;
FTexts.Free;
FImages.Free;
inherited Destroy;
end;
class function THeroInfo.UseMeta: boolean;
begin
Result:=False;
end;
function THeroInfo.GetPortrait: Int32;
begin
Result := FPortraitIndex;
end;
function THeroInfo.GetHeroIdentifier: AnsiString;
begin
Result := Identifier;
end;
function THeroInfo.GetSex: THeroSex;
begin
if Female then
Result := THeroSex.female
else
Result := THeroSex.male;
end;
function THeroInfo.GetPrimarySkills: THeroPrimarySkills;
var
c_info: THeroClassInfo;
begin
if FHeroClass = '' then
begin
Result := nil;
raise Exception.Create('No hero class to get attributes from.');
end;
c_info := THeroInfos(Collection).FOwner.HeroClasses[FHeroClass];
Result := c_info.PrimarySkills;
end;
function THeroInfo.GetSecondarySkills: THeroSecondarySkills;
begin
Result := FSkills;
end;
function THeroInfo.GetBiography: TLocalizedString;
begin
Result := FTexts.Biography;
end;
function THeroInfo.GetExperience: UInt64;
begin
Result := 0;
end;
procedure THeroInfo.BeforeSerialize(Sender: TObject);
begin