summaryrefslogtreecommitdiff
path: root/VegetationConfiguration.cpp
diff options
context:
space:
mode:
authorJapa2010-06-23 07:27:17 +0000
committerJapa2010-06-23 07:27:17 +0000
commitccf3c8c845742534f0cae1135835b4cd40fe1079 (patch)
tree4a014a6704166d4bf520012b192d4ff5776c4c73 /VegetationConfiguration.cpp
parentd1a624de4a674c5735e43fb1b543a7fa6410e0c3 (diff)
downloadstonesense-ccf3c8c845742534f0cae1135835b4cd40fe1079.tar.gz
stonesense-ccf3c8c845742534f0cae1135835b4cd40fe1079.tar.bz2
stonesense-ccf3c8c845742534f0cae1135835b4cd40fe1079.tar.xz
made the tree sprites object oriented
Diffstat (limited to 'VegetationConfiguration.cpp')
-rw-r--r--VegetationConfiguration.cpp109
1 files changed, 40 insertions, 69 deletions
diff --git a/VegetationConfiguration.cpp b/VegetationConfiguration.cpp
index 69ff476..08b263a 100644
--- a/VegetationConfiguration.cpp
+++ b/VegetationConfiguration.cpp
@@ -4,17 +4,18 @@
#include "MapLoading.h"
#include "GUI.h"
#include "ContentLoader.h"
+#include "spriteObjects.h"
#include "dfhack/depends/tinyxml/tinyxml.h"
-VegetationConfiguration::VegetationConfiguration(int gameID, t_SpriteWithOffset &sprite, bool live, bool grown)
+VegetationConfiguration::VegetationConfiguration(int gameID, c_sprite &sprite, bool live, bool grown)
{
- memset(this, 0, sizeof(VegetationConfiguration) );
- this->sprite = sprite;
- this->gameID = gameID;
- this->live = live;
- this->grown = grown;
+ memset(this, 0, sizeof(VegetationConfiguration) );
+ this->sprite = sprite;
+ this->gameID = gameID;
+ this->live = live;
+ this->grown = grown;
}
VegetationConfiguration::~VegetationConfiguration(void)
@@ -23,68 +24,46 @@ 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");
+ const char* sheetIndexStr;
+ c_sprite sprite;
+ int basefile = -1;
+
+ 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;
- }
+ basefile = loadConfigImgFile((char*)filename, elemRoot);
}
- 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)
+ TiXmlElement* elemTree;
+ for (elemTree = elemRoot->FirstChildElement("plant");
+ elemTree; elemTree = elemTree->NextSiblingElement("plant") )
{
- sprite.numVariations = 0;
- }
- else sprite.numVariations=atoi(spriteVariationsStr);
+ 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]);
- VegetationConfiguration vegetationConfiguration(gameID, sprite, !dead, !sapling);
- //add a copy to known creatures
- vegetationConfigs->push_back( vegetationConfiguration );
- }
+ sprite.set_by_xml(elemTree, basefile);
+ VegetationConfiguration vegetationConfiguration(gameID, sprite, !dead, !sapling);
+ //add a copy to known creatures
+ vegetationConfigs->push_back( vegetationConfiguration );
+ }
- return true;
+ return true;
}
-
-t_SpriteWithOffset getVegetationSprite(vector<VegetationConfiguration>& vegetationConfigs,int index,bool live,bool grown)
+
+c_sprite getVegetationSprite(vector<VegetationConfiguration>& vegetationConfigs,int index,bool live,bool grown)
{
int vcmax = (int)vegetationConfigs.size();
for (int i=0;i<vcmax;i++)
@@ -95,15 +74,7 @@ t_SpriteWithOffset getVegetationSprite(vector<VegetationConfiguration>& vegetati
if (current->grown != grown) continue;
return current->sprite;
}
- t_SpriteWithOffset sprite =
- {
- -1,
- 0,
- 0,
- -1,
- 0,
- ALL_FRAMES
- };
+ c_sprite sprite;
return sprite;
}