summaryrefslogtreecommitdiff
path: root/CreatureConfiguration.cpp
diff options
context:
space:
mode:
authorJonas Ask2009-11-16 15:26:51 +0000
committerJonas Ask2009-11-16 15:26:51 +0000
commitb47288fbbe4a11b2980c3655d75a2e7c7ef36874 (patch)
tree517ebe6eb3899fa9924e52208768eb3090480c20 /CreatureConfiguration.cpp
parent87e09d2e7d8d212f1a2a69174572e76c075f6587 (diff)
downloadstonesense-b47288fbbe4a11b2980c3655d75a2e7c7ef36874.tar.gz
stonesense-b47288fbbe4a11b2980c3655d75a2e7c7ef36874.tar.bz2
stonesense-b47288fbbe4a11b2980c3655d75a2e7c7ef36874.tar.xz
First half of improved creature config done. Need to upgrade dfHack version to continue.
Fixed a floor. Plugged major leak in MapLoading.cpp.
Diffstat (limited to 'CreatureConfiguration.cpp')
-rw-r--r--CreatureConfiguration.cpp56
1 files changed, 54 insertions, 2 deletions
diff --git a/CreatureConfiguration.cpp b/CreatureConfiguration.cpp
index 71494d7..4ec40c0 100644
--- a/CreatureConfiguration.cpp
+++ b/CreatureConfiguration.cpp
@@ -2,18 +2,27 @@
#include "CreatureConfiguration.h"
#include "Creatures.h"
+#include "dfhack/library/tinyxml/tinyxml.h"
+
bool CreatureNamesTranslatedFromGame = false;
-CreatureConfiguration::CreatureConfiguration(char* gameIDstr, int sheetIndex)
+CreatureConfiguration::CreatureConfiguration(char* gameIDstr, char* professionStr, enumCreatureSex sex, int sheetIndex)
{
memset(this, 0, sizeof(CreatureConfiguration) );
this->sheetIndex = sheetIndex;
this->gameID = INVALID_INDEX;
+ this->professionID = 0;
+ this->sex = sex;
int len = (int) strlen(gameIDstr);
- if(len > 100) len = 100;
+ if(len > CREATURESTRLENGTH) len = CREATURESTRLENGTH;
memcpy(this->gameIDstr, gameIDstr, len);
+ if(professionStr){
+ len = (int) strlen(professionStr);
+ if(len > CREATURESTRLENGTH) len = CREATURESTRLENGTH;
+ memcpy(this->professionstr, professionStr, len);
+ }
}
CreatureConfiguration::~CreatureConfiguration(void)
@@ -48,4 +57,47 @@ void TranslateCreatureNames(){
}
CreatureNamesTranslatedFromGame = true;
+}
+
+
+void LoadCreatureConfiguration( vector<CreatureConfiguration>* knownCreatures ){
+ char* filename = "Creatures.xml";
+ TiXmlDocument doc( filename );
+ bool loadOkay = doc.LoadFile();
+ TiXmlHandle hDoc(&doc);
+ TiXmlElement* elemCreature;
+ TiXmlElement* elemProfession;
+
+ knownCreatures->clear();
+
+ elemCreature = hDoc.FirstChildElement("Creature").Element();
+ while( elemCreature ){
+ const char* name = elemCreature->Attribute("gameID");
+ const char* sheetIndexStr = elemCreature->Attribute("sheetIndex");
+
+ elemProfession = elemCreature->FirstChildElement("Profession");
+ while( elemProfession ){
+ const char* professionstr = elemProfession->Attribute("name");
+ const char* sexstr = elemProfession->Attribute("sex");
+ enumCreatureSex cresex = eCreatureSex_NA;
+ if(sexstr){
+ if(strcmp( sexstr, "M" ) == 0) cresex = eCreatureSex_Male;
+ if(strcmp( sexstr, "F" ) == 0) cresex = eCreatureSex_Female;
+ }
+ //create profession config
+ CreatureConfiguration cre( (char*)name, (char*)professionstr, cresex, atoi(sheetIndexStr) );
+ //add a copy to known creatures
+ knownCreatures->push_back( cre );
+
+ elemProfession = elemProfession->NextSiblingElement("Profession");
+ }
+ //create default config
+ CreatureConfiguration cre( (char*)name, "", eCreatureSex_NA, atoi(sheetIndexStr) );
+ //add a copy to known creatures
+ knownCreatures->push_back( cre );
+
+ elemCreature = elemCreature->NextSiblingElement("Creature");
+ }
+
+ CreatureNamesTranslatedFromGame = false;
} \ No newline at end of file