-
Notifications
You must be signed in to change notification settings - Fork 54
/
FluidConfiguration.cpp
89 lines (80 loc) · 2.87 KB
/
FluidConfiguration.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
#include "FluidConfiguration.h"
#include "ContentLoader.h"
using namespace std;
using namespace DFHack;
using namespace df::enums;
FluidConfiguration::FluidConfiguration()
{
fluidset = 0;
sprite.reset();
}
void parseFluidElement( TiXmlElement* elemFluid, int basefile)
{
c_sprite tempSprite;
bool type = 0;
unsigned char level;
const char* fluidTypeStr = elemFluid->Attribute("type");
if(fluidTypeStr == NULL || fluidTypeStr[0] == 0) {
contentError("Invalid or missing type attribute",elemFluid);
return; //nothing to work with
}
if (strcmp(fluidTypeStr, "water") == 0) {
type = 0;
} else if (strcmp(fluidTypeStr, "lava") == 0) {
type = 1;
} else if (strcmp(fluidTypeStr, "magma") == 0) {
type = 1;
} else {
contentError("Invalid or missing type attribute",elemFluid);
}
const char* fluidLevelStr = elemFluid->Attribute("level");
if(fluidLevelStr == NULL || fluidLevelStr[0] == 0) {
contentError("Invalid or missing level attribute",elemFluid);
return; //nothing to work with
}
level = atoi(fluidLevelStr);
if( (level <= 0) || (level > 8)) {
contentError("Invalid or missing level attribute",elemFluid);
return; //nothing to work with
}
const char* spriteSheetIndexStr = elemFluid->Attribute("sheetIndex");
const char* spriteSpriteStr = elemFluid->Attribute("sprite");
const char* spriteIndexStr = elemFluid->Attribute("index");
if ((spriteSheetIndexStr == NULL || spriteSheetIndexStr[0] == 0) && (spriteSpriteStr == NULL || spriteSpriteStr[0] == 0) && (spriteIndexStr == NULL || spriteIndexStr[0] == 0)) {
contentError("Invalid or missing sprite attribute",elemFluid);
return; //nothing to work with
}
tempSprite.set_by_xml(elemFluid, basefile);
if(type) {
if(contentLoader->lava[level-1].fluidset == 0) {
contentLoader->lava[level-1].sprite = tempSprite;
contentLoader->lava[level-1].fluidset = 1;
}
} else {
if(contentLoader->water[level-1].fluidset == 0) {
contentLoader->water[level-1].sprite = tempSprite;
contentLoader->water[level-1].fluidset = 1;
}
}
}
bool addSingleFluidConfig( TiXmlElement* elemRoot)
{
int basefile = 0;
const char* filename = elemRoot->Attribute("file");
if (filename != NULL && filename[0] != 0) {
basefile = loadConfigImgFile((char*)filename,elemRoot);
if(basefile == -1) {
return false;
}
}
string elementType = elemRoot->Value();
if(elementType.compare( "fluids" ) == 0) {
//parse floors
TiXmlElement* elemFluid = elemRoot->FirstChildElement("fluid");
while( elemFluid ) {
parseFluidElement( elemFluid, basefile);
elemFluid = elemFluid->NextSiblingElement("fluid");
}
}
return true;
}