summaryrefslogtreecommitdiff
path: root/VegetationConfiguration.cpp
diff options
context:
space:
mode:
authorJapa2010-04-09 14:24:27 +0000
committerJapa2010-04-09 14:24:27 +0000
commit114df922d3073bd296b38cf522997f520fb17850 (patch)
treec4cf372825118c3663cd77e18c69a6c3b59d070f /VegetationConfiguration.cpp
parent81aefc8e03ff3f647494012e18bcdc8f33f4de42 (diff)
downloadstonesense-114df922d3073bd296b38cf522997f520fb17850.tar.gz
stonesense-114df922d3073bd296b38cf522997f520fb17850.tar.bz2
stonesense-114df922d3073bd296b38cf522997f520fb17850.tar.xz
updated trunk to the new graphics engine, and the latest DFhack
Diffstat (limited to 'VegetationConfiguration.cpp')
-rw-r--r--VegetationConfiguration.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/VegetationConfiguration.cpp b/VegetationConfiguration.cpp
new file mode 100644
index 0000000..1f48fa1
--- /dev/null
+++ b/VegetationConfiguration.cpp
@@ -0,0 +1,101 @@
+#include "common.h"
+#include "CreatureConfiguration.h"
+#include "Creatures.h"
+#include "MapLoading.h"
+#include "GUI.h"
+#include "ContentLoader.h"
+
+#include "dfhack/depends/tinyxml/tinyxml.h"
+
+
+VegetationConfiguration::VegetationConfiguration(int gameID, t_SpriteWithOffset &sprite, bool live, bool grown)
+{
+ memset(this, 0, sizeof(VegetationConfiguration) );
+ this->sprite = sprite;
+ this->gameID = gameID;
+ this->live = live;
+ this->grown = grown;
+}
+
+VegetationConfiguration::~VegetationConfiguration(void)
+{
+}
+
+bool addSingleVegetationConfig( TiXmlElement* elemRoot, vector<VegetationConfiguration>* vegetationConfigs, vector<t_matgloss>& plantNames )
+{
+ const char* sheetIndexStr;
+ t_SpriteWithOffset sprite;
+ int basefile = -1;
+ sprite.fileIndex=basefile;
+ sprite.x=0;
+ sprite.y=0;
+ sprite.animFrames=ALL_FRAMES;
+
+ const char* filename = elemRoot->Attribute("file");
+ if (filename != NULL && filename[0] != 0)
+ {
+ basefile = loadConfigImgFile((char*)filename, elemRoot);
+ }
+
+ //kinda round about- looking to needing to shift the lot into the plant elem
+ sprite.fileIndex=basefile;
+
+ 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)
+ {
+ contentError("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]);
+ sheetIndexStr = elemTree->Attribute("sheetIndex");
+ /* No animated trees.
+ But we may repurpose it later to make a xyz variance?
+ sprite.animFrames = getAnimFrames(elemProfession->Attribute("frames"));
+ if (sprite.animFrames == 0)
+ sprite.animFrames = ALL_FRAMES;*/
+
+ //create profession config
+ sprite.sheetIndex=atoi(sheetIndexStr);
+
+ //check for randomised tiles
+ const char* spriteVariationsStr = elemTree->Attribute("variations");
+ if (spriteVariationsStr == NULL || spriteVariationsStr[0] == 0)
+ {
+ sprite.numVariations = 0;
+ }
+ else sprite.numVariations=atoi(spriteVariationsStr);
+
+ VegetationConfiguration vegetationConfiguration(gameID, sprite, !dead, !sapling);
+ //add a copy to known creatures
+ vegetationConfigs->push_back( vegetationConfiguration );
+ }
+
+ return true;
+}
+
+t_SpriteWithOffset getVegetationSprite(vector<VegetationConfiguration>& vegetationConfigs,int index,bool live,bool grown)
+{
+ int vcmax = (int)vegetationConfigs.size();
+ for (int i=0;i<vcmax;i++)
+ {
+ VegetationConfiguration* current = &(vegetationConfigs[i]);
+ if (current->gameID != INVALID_INDEX && current->gameID != index) continue;
+ if (current->live != live) continue;
+ if (current->grown != grown) continue;
+ return current->sprite;
+ }
+ t_SpriteWithOffset sprite = {-1,0,0,-1,ALL_FRAMES};
+ return sprite;
+}
+