-
Notifications
You must be signed in to change notification settings - Fork 55
/
ContentLoader.cpp
948 lines (888 loc) · 30.8 KB
/
ContentLoader.cpp
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
#include <fstream>
#include "common.h"
#include "ContentLoader.h"
#include "ContentBuildingReader.h"
#include "MapLoading.h"
#include "ColorConfiguration.h"
#include "tinyxml.h"
#include "GUI.h"
#include "df/world_raws.h"
#include "df/itemdef.h"
#include "df/itemdef_weaponst.h"
#include "df/itemdef_armorst.h"
#include "df/itemdef_shoesst.h"
#include "df/itemdef_shieldst.h"
#include "df/itemdef_helmst.h"
#include "df/itemdef_glovesst.h"
#include "df/itemdef_pantsst.h"
#include "df/creature_raw.h"
#include "df/caste_raw.h"
#include "df/tissue_style_raw.h"
#include "df/entity_position_raw.h"
#include "df/entity_raw.h"
#include "df/historical_entity.h"
#include "df/entity_position.h"
void DumpStringVector(const char* filename, vector<std::string> * input)
{
FILE* fp = fopen(filename, "w");
// Run through until perfect match found or hit end.
for(int i = 0; i < input->size(); i++){
fprintf(fp, "%i:%s\n", i, input->at(i).c_str());
}
fclose(fp);
}
ContentLoader * contentLoader;
ContentLoader::ContentLoader(void) { }
ContentLoader::~ContentLoader(void)
{
//flush content on exit
flushBuildingConfig(&buildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainWallConfigs);
flushItemConfig(itemConfigs);
flushCreatureConfig();
colorConfigs.clear();
}
bool ContentLoader::Load()
{
/*draw_textf_border(font,
ssState.ScreenW/2,
ssState.ScreenH/2,
ALLEGRO_ALIGN_CENTRE, "Loading...");
al_flip_display();*/
//flush old config
flushBuildingConfig(&buildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainWallConfigs);
flushItemConfig(itemConfigs);
colorConfigs.clear();
flushCreatureConfig();
treeConfigs.clear();
shrubConfigs.clear();
flushImgFiles();
// This is an extra suspend/resume, but it only happens when reloading the config
// ie not enough to worry about
//DF.Suspend();
////read data from DF
//const vector<string> *tempClasses = DF.getMemoryInfo()->getClassIDMapping();
//// make a copy for our use
//classIdStrings = *tempClasses;
try {
Mats = Core::getInstance().getMaterials();
} catch(exception &e) {
LogError("DFhack exeption: %s\n", e.what());
}
if(!ssConfig.skipCreatureTypes) {
try {
Mats->ReadCreatureTypes();
} catch(exception &e) {
LogError("DFhack exeption: %s\n", e.what());
ssConfig.skipCreatureTypes = true;
}
}
if(!ssConfig.skipCreatureTypesEx) {
try {
Mats->ReadCreatureTypesEx();
} catch(exception &e) {
LogError("DFhack exeption: %s\n", e.what());
ssConfig.skipCreatureTypesEx = true;
}
}
if(!ssConfig.skipDescriptorColors) {
try {
Mats->ReadDescriptorColors();
} catch(exception &e) {
LogError("DFhack exeption: %s\n", e.what());
ssConfig.skipDescriptorColors = true;
}
}
if(!ssConfig.skipInorganicMats) {
if(!Mats->CopyInorganicMaterials(this->inorganic)) {
LogError("Missing inorganic materials!\n");
ssConfig.skipInorganicMats = true;
}
}
if(!ssConfig.skipOrganicMats) {
if(!Mats->CopyOrganicMaterials(this->organic)) {
LogError("Missing organic materials!\n");
ssConfig.skipOrganicMats = true;
}
}
Buildings::ReadCustomWorkshopTypes(custom_workshop_types);
if(professionStrings.empty()) {
FOR_ENUM_ITEMS(profession, i) {
if(i<0) {
continue;
}
professionStrings.push_back(string(ENUM_KEY_STR(profession, i)));
}
for(int i = 0; i < df::global::world->entities.all.size(); i++){
df::historical_entity * currentity = df::global::world->entities.all[i];
if(!currentity) continue;
for(int j = 0; j < currentity->positions.own.size(); j++) {
df::entity_position * currentpos = currentity->positions.own[j];
if(!currentpos) continue;
int found = -1;
for(int k = 0; k < professionStrings.size(); k++){
if( professionStrings[k] == currentpos->code){
found = k;
break;
}
}
if(found < 0){
professionStrings.push_back(currentpos->code);
found = professionStrings.size()-1;
}
int ent_id = currentity->id;
int pos_id = currentpos->id;
if(ent_id >= position_Indices.size())
position_Indices.resize(ent_id+1, NULL);
if(!position_Indices[ent_id])
position_Indices[ent_id] = new vector<int32_t>;
if(pos_id >= position_Indices[ent_id]->size())
position_Indices[ent_id]->resize(pos_id+1, NULL);
position_Indices[ent_id]->at(pos_id) = found;
//LogError("%d(%d):%s->%d(%d):%s = %d\n", i, currentity->id, currentity->entity_raw->code.c_str(), j,currentpos->id, currentpos->code.c_str(), found);
}
for(int j = 0; j < currentity->positions.site.size(); j++) {
df::entity_position * currentpos = currentity->positions.site[j];
if(!currentpos) continue;
int found = -1;
for(int k = 0; k < professionStrings.size(); k++){
if( professionStrings[k] == currentpos->code){
found = k;
break;
}
}
if(found < 0){
professionStrings.push_back(currentpos->code);
found = professionStrings.size()-1;
}
int ent_id = currentity->id;
int pos_id = currentpos->id;
if(ent_id >= position_Indices.size())
position_Indices.resize(ent_id+1, NULL);
if(!position_Indices[ent_id])
position_Indices[ent_id] = new vector<int32_t>;
if(pos_id >= position_Indices[ent_id]->size())
position_Indices[ent_id]->resize(pos_id+1, NULL);
position_Indices[ent_id]->at(pos_id) = found;
//LogError("%d(%d):%s->%d(%d):%s = %d\n", i, currentity->id, currentity->entity_raw->code.c_str(), j,currentpos->id, currentpos->code.c_str(), found);
}
for(int j = 0; j < currentity->positions.conquered_site.size(); j++) {
df::entity_position * currentpos = currentity->positions.conquered_site[j];
if(!currentpos) continue;
int found = -1;
for(int k = 0; k < professionStrings.size(); k++){
if( professionStrings[k] == currentpos->code){
found = k;
break;
}
}
if(found < 0){
professionStrings.push_back(currentpos->code);
found = professionStrings.size()-1;
}
int ent_id = currentity->id;
int pos_id = currentpos->id;
if(ent_id >= position_Indices.size())
position_Indices.resize(ent_id+1, NULL);
if(!position_Indices[ent_id])
position_Indices[ent_id] = new vector<int32_t>;
if(pos_id >= position_Indices[ent_id]->size())
position_Indices[ent_id]->resize(pos_id+1, NULL);
position_Indices[ent_id]->at(pos_id) = found;
//LogError("%d(%d):%s->%d(%d):%s = %d\n", i, currentity->id, currentity->entity_raw->code.c_str(), j,currentpos->id, currentpos->code.c_str(), found);
}
}
}
//DumpStringVector("professiondump.txt", &professionStrings);
gatherStyleIndices(&df::global::world->raws);
/*
if(classIdStrings.empty())
{
for(int i = 0; ; i++)
{
string temp;
if(!MemInfo->resolveClassIDToClassname(i, temp))
{
break;
}
classIdStrings.push_back(temp);
}
}
*/
//Find what is obsidian
contentLoader->obsidian = lookupMaterialIndex(INORGANIC, "OBSIDIAN");
loadGraphicsFromDisk(); //these get destroyed when flushImgFiles is called.
ALLEGRO_PATH * p = al_create_path("stonesense/index.txt");
bool overallResult = parseContentIndexFile( al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP) );
al_destroy_path(p);
translationComplete = false;
return true;
}
bool ContentLoader::reload_configs()
{
flushBuildingConfig(&buildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainWallConfigs);
flushItemConfig(itemConfigs);
colorConfigs.clear();
creatureConfigs.clear();
treeConfigs.clear();
shrubConfigs.clear();
grassConfigs.clear();
flushImgFiles();
loadGraphicsFromDisk(); //these get destroyed when flushImgFiles is called.
ALLEGRO_PATH * p = al_create_path("stonesense/index.txt");
bool overallResult = parseContentIndexFile( al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP) );
al_destroy_path(p);
return overallResult;
}
// takes a filename and the file referring to it, and makes a combined filename in
// HTML style: (ie "/something" is relative to the stonesense root, everything
// else is relative to the referrer)
// buffer must be FILENAME_BUFFERSIZE chars
// returns true if it all works
bool getLocalFilename(char * buffer, const char* filename, const char* relativeto)
{
ALLEGRO_PATH * temppath;
if (filename[0] == '/' || filename[0] == '\\') {
temppath = al_create_path(filename);
al_make_path_canonical(temppath);
} else {
temppath = al_create_path(relativeto);
al_join_paths(temppath, al_create_path(filename));
al_make_path_canonical(temppath);
}
buffer = strcpy(buffer, al_path_cstr(temppath, ALLEGRO_NATIVE_PATH_SEP));
return true;
}
bool ContentLoader::parseContentIndexFile( const char* filepath )
{
/*
al_clear_to_color(al_map_rgb(0,0,0));
draw_textf_border(font, ssState.ScreenW/2,
ssState.ScreenH/2,
ALLEGRO_ALIGN_CENTRE, "Loading %s...", filepath);
al_flip_display();
*/
string line;
ifstream myfile( filepath );
if (myfile.is_open() == false) {
LogError( "Unable to load config index file at: %s!\n", filepath );
return false;
}
LogVerbose("Reading index at %s...\n", filepath);
while ( !myfile.eof() ) {
char configfilepath[FILENAME_BUFFERSIZE] = {0};
getline (myfile,line);
// some systems don't remove the \r char as a part of the line change:
// also trim trailing space
int resize = (int)line.size()-1;
for (; resize>0; resize--) {
char test = line[resize];
if (test == '\r') {
continue;
}
if (test == '\t') {
continue;
}
if (test == ' ') {
continue;
}
break;
}
if (resize <= 0) {
continue;
}
line.resize(resize+1);
// allow comments
if (line[0] == '#') {
continue;
}
if (!getLocalFilename(configfilepath,line.c_str(),filepath)) {
LogError("File name parsing failed on %s\n",line.c_str());
continue;
}
//WriteErr("but it's all fucked here: %s\n",configfilepath);
ALLEGRO_PATH * temppath = al_create_path(configfilepath);
const char* extension;
extension = al_get_path_extension(temppath);
//WriteErr("extension: %s\n",extension);
if (strcmp(extension,".xml") == 0) {
LogVerbose("Reading xml %s...\n", configfilepath);
if (!parseContentXMLFile(configfilepath)) {
LogError("Failure in reading %s\n",configfilepath);
}
} else if (strcmp(extension,".txt") == 0) {
LogVerbose("Reading index %s...\n", configfilepath);
if (!parseContentIndexFile(configfilepath)) {
LogError("Failure in reading %s\n",configfilepath);
}
} else {
LogError("Invalid filename: %s\n",configfilepath);
}
}
myfile.close();
return true;
}
bool ContentLoader::parseContentXMLFile( const char* filepath )
{
/*
al_clear_to_color(al_map_rgb(0,0,0));
draw_textf_border(font, ssState.ScreenW/2,
ssState.ScreenH/2,
ALLEGRO_ALIGN_CENTRE, "Loading %s...", filepath);
al_flip_display();*/
TiXmlDocument doc( filepath );
if(!doc.LoadFile()) {
LogError("File load failed: %s\n", filepath);
return false;
}
TiXmlHandle hDoc(&doc);
TiXmlElement* elemRoot;
bool runningResult = true;
elemRoot = hDoc.FirstChildElement().Element();
while( elemRoot ) {
string elementType = elemRoot->Value();
if( elementType.compare( "building" ) == 0 ) {
runningResult &= parseBuildingContent( elemRoot );
} else if( elementType.compare( "creatures" ) == 0 ) {
runningResult &= parseCreatureContent( elemRoot );
} else if( elementType.compare( "floors" ) == 0 ) {
runningResult &= parseTerrainContent( elemRoot );
} else if( elementType.compare( "walls" ) == 0 ) {
runningResult &= parseTerrainContent( elemRoot );
} else if( elementType.compare( "shrubs" ) == 0 ) {
runningResult &= parseShrubContent( elemRoot );
} else if( elementType.compare( "trees" ) == 0 ) {
runningResult &= parseTreeContent( elemRoot );
} else if( elementType.compare( "grasses" ) == 0 ) {
runningResult &= parseGrassContent( elemRoot );
} else if( elementType.compare( "colors" ) == 0 ) {
runningResult &= parseColorContent( elemRoot );
} else if( elementType.compare( "fluids" ) == 0 ) {
runningResult &= parseFluidContent( elemRoot );
} else if( elementType.compare( "items" ) == 0 ) {
runningResult &= parseItemContent( elemRoot );
} else {
contentError("Unrecognised root element",elemRoot);
}
elemRoot = elemRoot->NextSiblingElement();
}
return runningResult;
}
bool ContentLoader::parseBuildingContent(TiXmlElement* elemRoot )
{
return addSingleBuildingConfig( elemRoot, &buildingConfigs );
}
bool ContentLoader::parseCreatureContent(TiXmlElement* elemRoot )
{
return addCreaturesConfig( elemRoot, creatureConfigs );
}
bool ContentLoader::parseShrubContent(TiXmlElement* elemRoot )
{
return addSingleVegetationConfig( elemRoot, &shrubConfigs, organic );
}
bool ContentLoader::parseTreeContent(TiXmlElement* elemRoot )
{
return addSingleVegetationConfig( elemRoot, &treeConfigs, organic );
}
bool ContentLoader::parseGrassContent(TiXmlElement* elemRoot )
{
return addSingleVegetationConfig( elemRoot, &grassConfigs, organic );
}
bool ContentLoader::parseTerrainContent(TiXmlElement* elemRoot )
{
return addSingleTerrainConfig( elemRoot );
}
bool ContentLoader::parseColorContent(TiXmlElement* elemRoot )
{
return addSingleColorConfig( elemRoot );
}
bool ContentLoader::parseFluidContent(TiXmlElement* elemRoot )
{
return addSingleFluidConfig( elemRoot );
}
bool ContentLoader::parseItemContent(TiXmlElement* elemRoot )
{
return addSingleItemConfig( elemRoot );
}
const char* getDocument(TiXmlNode* element)
{
//walk up the tree to the root
TiXmlNode* parent = element->Parent();
while (parent != null) {
element = parent;
parent = element->Parent();
}
// topmost node *should* be a document, but lets be sure
parent = dynamic_cast<TiXmlDocument*>(element);
if (parent == NULL) {
return NULL;
}
return parent->Value();
}
void contentError(const char* message, TiXmlNode* element)
{
LogError("%s: %s: %s (Line %d)\n",getDocument(element),message,element->Value(),element->Row());
}
void contentWarning(const char* message, TiXmlNode* element)
{
LogVerbose("%s: %s: %s (Line %d)\n",getDocument(element),message,element->Value(),element->Row());
}
// converts list of characters 0-5 into bits, ignoring garbage
// eg "035" or "0 3 5" or "0xx3x5" are all good
char getAnimFrames(const char* framestring)
{
if (framestring == NULL) {
return ALL_FRAMES;
}
char aframes=0;
for (int i=0; i<6; i++) {
if (framestring[i]==0) {
return aframes;
}
char temp = framestring[i]-'0';
if (temp < 0 || temp > 5) {
continue;
}
aframes = aframes | (1 << temp);
}
return aframes;
}
int lookupMaterialIndex(int matType, const char* strValue)
{
// for appropriate elements, look up subtype
if (matType == INORGANIC && !ssConfig.skipInorganicMats) {
return lookupIndexedType(strValue,contentLoader->inorganic);
} else if (matType == WOOD && !ssConfig.skipOrganicMats) {
return lookupIndexedType(strValue,contentLoader->organic);
} else if (matType == PLANT && !ssConfig.skipOrganicMats) {
return lookupIndexedType(strValue,contentLoader->organic);
} else if (matType == PLANTCLOTH && !ssConfig.skipOrganicMats) {
return lookupIndexedType(strValue,contentLoader->organic);
} else if (matType == LEATHER && !ssConfig.skipCreatureTypes) {
return lookupIndexedType(strValue,contentLoader->Mats->race);
} else {
//maybe allow some more in later
return INVALID_INDEX;
}
}
#include "df/siegeengine_type.h"
#include "df/workshop_type.h"
#include "df/trap_type.h"
#include "df/shop_type.h"
#include "df/construction_type.h"
#include "df/furnace_type.h"
const char *lookupBuildingSubtype(int main_type, int i)
{
// process types
switch (main_type) {
case building_type::Furnace:
return enum_item_key_str((df::furnace_type)i);
case building_type::Construction:
return enum_item_key_str((df::construction_type)i);
case building_type::SiegeEngine:
return enum_item_key_str((df::siegeengine_type)i);
case building_type::Shop:
return enum_item_key_str((df::shop_type)i);
case building_type::Workshop:
return enum_item_key_str((df::workshop_type)i);
default:
return "NA";
}
return "NA";
}
const char *lookupMaterialTypeName(int matType)
{
switch (matType) {
case INORGANIC:
return "Inorganic";
case GREEN_GLASS:
return "GreenGlass";
case WOOD:
return "Wood";
case PLANT:
return "Plant";
case ICE:
return "Ice";
case CLEAR_GLASS:
return "ClearGlass";
case CRYSTAL_GLASS:
return "CrystalGlass";
case PLANTCLOTH:
return "PlantCloth";
case LEATHER:
return "Leather";
case VOMIT:
return "Vomit";
default:
return NULL;
}
}
MAT_BASICS lookupMaterialType(const char* strValue)
{
if (strValue == NULL || strValue[0] == 0) {
return INVALID;
} else if( strcmp(strValue, "Stone") == 0) {
return INORGANIC;
} else if( strcmp(strValue, "Metal") == 0) {
return INORGANIC;
} else if( strcmp(strValue, "Inorganic") == 0) {
return INORGANIC;
} else if( strcmp(strValue, "GreenGlass") == 0) {
return GREEN_GLASS;
} else if( strcmp(strValue, "Wood") == 0) {
return WOOD;
} else if( strcmp(strValue, "Plant") == 0) {
return PLANT;
} else if( strcmp(strValue, "Ice") == 0) {
return ICE;
} else if( strcmp(strValue, "ClearGlass") == 0) {
return CLEAR_GLASS;
} else if( strcmp(strValue, "CrystalGlass") == 0) {
return CRYSTAL_GLASS;
} else if( strcmp(strValue, "PlantCloth") == 0) {
return PLANTCLOTH;
} else if( strcmp(strValue, "Leather") == 0) {
return LEATHER;
} else if( strcmp(strValue, "Vomit") == 0) {
return VOMIT;
}
//TODO this needs fixing on dfhack side
return INVALID;
}
const char *lookupMaterialName(int matType,int matIndex)
{
if (matIndex < 0) {
return NULL;
}
vector<t_matgloss>* typeVector;
// for appropriate elements, look up subtype
if ((matType == INORGANIC) && (!ssConfig.skipInorganicMats)) {
if(matIndex < contentLoader->inorganic.size()) {
return contentLoader->inorganic[matIndex].id.c_str();
} else {
return NULL;
}
} else if ((matType == WOOD) && (!ssConfig.skipOrganicMats)) {
typeVector=&(contentLoader->organic);
} else if ((matType == PLANTCLOTH) && (!ssConfig.skipOrganicMats)) {
typeVector=&(contentLoader->organic);
} else if (matType == LEATHER) {
if(!ssConfig.skipCreatureTypes) {
typeVector=&(contentLoader->Mats->race);
}
} else {
//maybe allow some more in later
return NULL;
}
if (matIndex >= typeVector->size()) {
return NULL;
}
return (*typeVector)[matIndex].id.c_str();
}
const char *lookupTreeName(int matIndex)
{
if(ssConfig.skipOrganicMats) {
return NULL;
}
if (matIndex < 0) {
return NULL;
}
vector<t_matgloss>* typeVector;
// for appropriate elements, look up subtype
typeVector=&(contentLoader->organic);
if (matIndex >= typeVector->size()) {
return NULL;
}
return (*typeVector)[matIndex].id.c_str();
}
const char * lookupFormName(int formType)
{
switch (formType) {
case item_type::BAR:
return "bar";
case item_type::BLOCKS:
return "block";
case item_type::BOULDER:
return "boulder";
case item_type::WOOD:
return "log";
default:
return NULL;
}
}
uint8_t lookupMaterialFore(int matType,int matIndex)
{
if (matIndex < 0) {
return 0;
}
vector<t_matgloss>* typeVector;
//// for appropriate elements, look up subtype
//if (matType == Mat_Wood)
//{
// typeVector=&(contentLoader.woodNameStrings);
//}
//else if (matType == 0)
//{
// typeVector=&(contentLoader.stoneNameStrings);
//}
//else if (matType == Mat_Metal)
//{
// typeVector=&(contentLoader.metalNameStrings);
//}
//else
//{
//maybe allow some more in later
return 0;
//}
if (matIndex >= typeVector->size()) {
return 0;
}
return (*typeVector)[matIndex].fore;
}
uint8_t lookupMaterialBack(int matType,int matIndex)
{
if (matIndex < 0) {
return 0;
}
vector<t_matgloss>* typeVector;
//// for appropriate elements, look up subtype
//if (matType == Mat_Wood)
//{
// typeVector=&(contentLoader.woodNameStrings);
//}
//else if (matType == 0)
//{
// typeVector=&(contentLoader.stoneNameStrings);
//}
//else if (matType == Mat_Metal)
//{
// typeVector=&(contentLoader.metalNameStrings);
//}
//else
//{
//maybe allow some more in later
return 0;
//}
if (matIndex >= typeVector->size()) {
return 0;
}
return (*typeVector)[matIndex].back;
}
uint8_t lookupMaterialBright(int matType,int matIndex)
{
if (matIndex < 0) {
return 0;
}
vector<t_matgloss>* typeVector;
//// for appropriate elements, look up subtype
//if (matType == Mat_Wood)
//{
// typeVector=&(contentLoader.woodNameStrings);
//}
//else if (matType == 0)
//{
// typeVector=&(contentLoader.stoneNameStrings);
//}
//else if (matType == Mat_Metal)
//{
// typeVector=&(contentLoader.metalNameStrings);
//}
//else
//{
//maybe allow some more in later
return 0;
//}
if (matIndex >= typeVector->size()) {
return 0;
}
return (*typeVector)[matIndex].bright;
}
int loadConfigImgFile(const char* filename, TiXmlElement* referrer)
{
const char* documentRef = getDocument(referrer);
char configfilepath[FILENAME_BUFFERSIZE] = {0};
if (!getLocalFilename(configfilepath,filename,documentRef)) {
contentError("Failed to parse sprites filename",referrer);
return -1;
}
return loadImgFile(configfilepath);
}
void ContentLoader::flushCreatureConfig()
{
uint32_t num = (uint32_t)creatureConfigs.size();
for ( int i = 0 ; i < num; i++ ) {
if (creatureConfigs[i]) {
delete creatureConfigs[i];
}
}
// make big enough to hold all creatures
creatureConfigs.clear();
for ( int i = 0; i < style_indices.size();i++){
if(style_indices[i]){
for ( int j = 0; j < style_indices[i]->size();j++){
if(style_indices[i]->at(j)){
style_indices[i]->at(j)->clear();
delete style_indices[i]->at(j);
}
}
style_indices[i]->clear();
delete style_indices[i];
}
}
style_indices.clear();
}
void ContentLoader::gatherStyleIndices(df::world_raws * raws)
{
for(int creatureIndex = 0; creatureIndex < raws->creatures.all.size(); creatureIndex++)
{
df::creature_raw * cre = raws->creatures.all[creatureIndex];
for(int casteIndex = 0; casteIndex < cre->caste.size(); casteIndex++)
{
df::caste_raw * cas = cre->caste[casteIndex];
for(int styleIndex = 0; styleIndex < cas->tissue_styles.size(); styleIndex++)
{
df::tissue_style_raw * sty = cas->tissue_styles[styleIndex];
hairtypes type = hairtypes_invalid;
if(sty->token == "HAIR")
type = HAIR;
else if(sty->token == "BEARD")
type = BEARD;
else if(sty->token == "MOUSTACHE")
type = MOUSTACHE;
else if(sty->token == "SIDEBURNS")
type = SIDEBURNS;
else LogError("Unknown hair type: %s", raws->creatures.all[creatureIndex]->caste[casteIndex]->tissue_styles[styleIndex]->token.c_str());
if(type != hairtypes_invalid)
{
if(creatureIndex >= style_indices.size())
style_indices.resize(creatureIndex+1, NULL);
if(!style_indices.at(creatureIndex))
style_indices.at(creatureIndex) = new vector<vector<int32_t>*>;
vector<vector<int32_t>*>* creatureStyle = style_indices.at(creatureIndex);
if(casteIndex >= creatureStyle->size())
creatureStyle->resize(casteIndex+1, NULL);
if(!creatureStyle->at(casteIndex))
creatureStyle->at(casteIndex) = new vector<int32_t>;
vector<int32_t>* casteStyle = creatureStyle->at(casteIndex);
if(type >= casteStyle->size())
casteStyle->resize(type+1, 0);
casteStyle->at(type) = sty->id;
LogVerbose("%s:%s : %d:%s\n", raws->creatures.all[creatureIndex]->creature_id.c_str(),raws->creatures.all[creatureIndex]->caste[casteIndex]->caste_id.c_str(), sty->id, sty->token.c_str());
}
}
}
}
}
ALLEGRO_COLOR lookupMaterialColor(DFHack::t_matglossPair matt, ALLEGRO_COLOR defaultColor)
{
return lookupMaterialColor((int) matt.type, (int) matt.index, -1, -1, defaultColor);
}
ALLEGRO_COLOR lookupMaterialColor(DFHack::t_matglossPair matt, DFHack::t_matglossPair dyematt, ALLEGRO_COLOR defaultColor)
{
return lookupMaterialColor((int) matt.type, (int) matt.index, (int) dyematt.type, (int) dyematt.index, defaultColor);
}
ALLEGRO_COLOR lookupMaterialColor(int matType, int matIndex, ALLEGRO_COLOR defaultColor)
{
return lookupMaterialColor( matType, matIndex, -1, -1, defaultColor);
}
ALLEGRO_COLOR lookupMaterialColor(int matType, int matIndex, int dyeType, int dyeIndex, ALLEGRO_COLOR defaultColor)
{
if (matType < 0) {
//This should not normally happen, but if it does, we don't want crashes, so we'll return magic pink so show something's wrong.
return al_map_rgb(255, 0, 255);
}
if (matType >= contentLoader->colorConfigs.size()) {
//if it's more than the size of our colorconfigs, then just make a guess based off what DF tells us.
goto DFColor;
}
if (matIndex < 0) {
return contentLoader->colorConfigs.at(matType).color;
}
if (matIndex >= contentLoader->colorConfigs.at(matType).colorMaterials.size()) {
goto DFColor;
}
if (contentLoader->colorConfigs.at(matType).colorMaterials.at(matIndex).colorSet) {
return contentLoader->colorConfigs.at(matType).colorMaterials.at(matIndex).color;
}
DFColor:
MaterialInfo mat, dye;
if(mat.decode(matType, matIndex)) {
if(dyeType>=0 && dyeIndex>=0 && dye.decode(dyeType, dyeIndex))
return al_map_rgb_f(
contentLoader->Mats->color[dye.material->powder_dye].red * contentLoader->Mats->color[mat.material->state_color[0]].red,
contentLoader->Mats->color[dye.material->powder_dye].green * contentLoader->Mats->color[mat.material->state_color[0]].green,
contentLoader->Mats->color[dye.material->powder_dye].blue * contentLoader->Mats->color[mat.material->state_color[0]].blue);
else
return al_map_rgb_f(
contentLoader->Mats->color[mat.material->state_color[0]].red,
contentLoader->Mats->color[mat.material->state_color[0]].green,
contentLoader->Mats->color[mat.material->state_color[0]].blue);
}
return defaultColor;
}
ShadeBy getShadeType(const char* Input)
{
if( strcmp(Input, "none") == 0) {
return ShadeNone;
}
if( strcmp(Input, "xml") == 0) {
return ShadeXml;
}
if( strcmp(Input, "named") == 0) {
return ShadeNamed;
}
if( strcmp(Input, "material") == 0) {
return ShadeMat;
}
if( strcmp(Input, "layer") == 0) {
return ShadeLayer;
}
if( strcmp(Input, "vein") == 0) {
return ShadeVein;
}
if( strcmp(Input, "material_fore") == 0) {
return ShadeMatFore;
}
if( strcmp(Input, "material_back") == 0) {
return ShadeMatBack;
}
if( strcmp(Input, "layer_fore") == 0) {
return ShadeLayerFore;
}
if( strcmp(Input, "layer_back") == 0) {
return ShadeLayerBack;
}
if( strcmp(Input, "vein_fore") == 0) {
return ShadeVeinFore;
}
if( strcmp(Input, "vein_back") == 0) {
return ShadeVeinBack;
}
if( strcmp(Input, "bodypart") == 0) {
return ShadeBodyPart;
}
if( strcmp(Input, "profession") == 0) {
return ShadeJob;
}
if( strcmp(Input, "blood") == 0) {
return ShadeBlood;
}
if( strcmp(Input, "building") == 0) {
return ShadeBuilding;
}
if( strcmp(Input, "grass") == 0) {
return ShadeGrass;
}
if( strcmp(Input, "equipment") == 0) {
return ShadeEquip;
}
if( strcmp(Input, "item") == 0) {
return ShadeItem;
}
return ShadeNone;
}