-
Notifications
You must be signed in to change notification settings - Fork 54
/
VegetationConfiguration.cpp
83 lines (73 loc) · 2.49 KB
/
VegetationConfiguration.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
#include "common.h"
#include "CreatureConfiguration.h"
#include "Creatures.h"
#include "MapLoading.h"
#include "GUI.h"
#include "ContentLoader.h"
#include "SpriteObjects.h"
#include "tinyxml.h"
using namespace std;
using namespace DFHack;
using namespace df::enums;
VegetationConfiguration::VegetationConfiguration(int gameID, c_tile_tree &tree, bool live, bool grown) :
gameID(gameID),
live(live),
grown(grown),
tree(tree)
{
}
VegetationConfiguration::~VegetationConfiguration(void)
{
}
bool addSingleVegetationConfig( TiXmlElement* elemRoot, vector<std::unique_ptr<VegetationConfiguration>>* vegetationConfigs, vector<t_matgloss>& plantNames )
{
int basefile = -1;
const char* filename = elemRoot->Attribute("file");
if (filename != NULL && filename[0] != 0) {
basefile = loadConfigImgFile((char*)filename, elemRoot);
if(basefile == -1) {
return false;
}
}
TiXmlElement* elemTree;
for (elemTree = elemRoot->FirstChildElement("plant");
elemTree; elemTree = elemTree->NextSiblingElement("plant") ) {
const char* idstr = elemTree->Attribute("gameID");
int gameID = INVALID_INDEX;
if (idstr && idstr[0]) {
gameID = lookupIndexedType(idstr,plantNames);
if (gameID == INVALID_INDEX) {
contentWarning("No matching plant type",elemTree);
continue;
}
}
const char* deadstr = elemTree->Attribute("dead");
bool dead = (deadstr && deadstr[0]);
const char* saplingstr = elemTree->Attribute("sapling");
bool sapling = (saplingstr && saplingstr[0]);
c_tile_tree tree;
tree.set_by_xml(elemTree, basefile);
auto vegetationConfiguration = std::make_unique<VegetationConfiguration>(gameID, tree, !dead, !sapling);
//add a copy to known creatures
vegetationConfigs->push_back( std::move(vegetationConfiguration) );
}
return true;
}
c_tile_tree * getVegetationTree(vector<std::unique_ptr<VegetationConfiguration>>& vegetationConfigs,int index,bool live,bool grown)
{
for (const auto& current : vegetationConfigs) {
if (current->gameID != INVALID_INDEX && current->gameID != index) {
continue;
}
if (current->live != live) {
continue;
}
if (current->grown != grown) {
continue;
}
return &(current->tree);
}
static c_tile_tree* tree = new c_tile_tree;
tree->reset();
return tree;
}