summaryrefslogtreecommitdiff
path: root/CreatureConfiguration.cpp
diff options
context:
space:
mode:
authorJapa2010-06-24 10:21:25 +0000
committerJapa2010-06-24 10:21:25 +0000
commit313d5fd88087eded7fb9cfa24419b34d2fdaf23f (patch)
treea40e4d80f10f0421aa9bf1161a6b266cda03112f /CreatureConfiguration.cpp
parent7973416e41f0e27600706a0fda42282daae52d82 (diff)
downloadstonesense-313d5fd88087eded7fb9cfa24419b34d2fdaf23f.tar.gz
stonesense-313d5fd88087eded7fb9cfa24419b34d2fdaf23f.tar.bz2
stonesense-313d5fd88087eded7fb9cfa24419b34d2fdaf23f.tar.xz
Moved more stuff to OO sprites.
Much is commented out.
Diffstat (limited to 'CreatureConfiguration.cpp')
-rw-r--r--CreatureConfiguration.cpp230
1 files changed, 6 insertions, 224 deletions
diff --git a/CreatureConfiguration.cpp b/CreatureConfiguration.cpp
index 85042fe..651029e 100644
--- a/CreatureConfiguration.cpp
+++ b/CreatureConfiguration.cpp
@@ -9,7 +9,7 @@
#include "dfhack/depends/tinyxml/tinyxml.h"
-CreatureConfiguration::CreatureConfiguration(int professionID, const char* professionStr, uint8_t sex, enumCreatureSpecialCases special, t_SpriteWithOffset &sprite, int shadow)
+CreatureConfiguration::CreatureConfiguration(int professionID, const char* professionStr, uint8_t sex, enumCreatureSpecialCases special, c_sprite &sprite, int shadow)
{
memset(this, 0, sizeof(CreatureConfiguration) );
this->sprite = sprite;
@@ -24,7 +24,6 @@ CreatureConfiguration::CreatureConfiguration(int professionID, const char* profe
memcpy(this->professionstr, professionStr, len);
this->professionstr[CREATURESTRLENGTH-1]=0;
}
- //WriteErr("CC %d %d %d %d %s\n",this->gameID,this->professionID,this->sprite.fileIndex,this->sprite.sheetIndex,(this->professionstr[0]?this->professionstr:"-"));
}
CreatureConfiguration::~CreatureConfiguration(void)
@@ -104,13 +103,9 @@ bool addSingleCreatureConfig( TiXmlElement* elemCreature, vector<vector<Creature
return false;
const char* sheetIndexStr;
int defaultFile = basefile;
- t_SpriteWithOffset sprite;
- sprite.fileIndex=basefile;
- sprite.x=0;
- sprite.y=0;
- sprite.animFrames=ALL_FRAMES;
+ c_sprite sprite;
+ sprite.set_fileindex(basefile);
int baseShadow = DEFAULT_SHADOW;
- uint8_t red, green, blue;
const char* shadowStr = elemCreature->Attribute("shadow");
if (shadowStr != NULL && shadowStr[0] != 0)
{
@@ -121,7 +116,7 @@ bool addSingleCreatureConfig( TiXmlElement* elemCreature, vector<vector<Creature
const char* filename = elemCreature->Attribute("file");
if (filename != NULL && filename[0] != 0)
{
- sprite.fileIndex = defaultFile = loadConfigImgFile((char*)filename,elemCreature);
+ defaultFile = loadConfigImgFile((char*)filename,elemCreature);
}
TiXmlElement* elemVariant = elemCreature->FirstChildElement("variant");
while( elemVariant ){
@@ -144,13 +139,6 @@ bool addSingleCreatureConfig( TiXmlElement* elemCreature, vector<vector<Creature
WriteErr("custom: %s\n",customStr);
}
- const char* filename = elemVariant->Attribute("file");
- if (filename != NULL && filename[0] != 0)
- {
- sprite.fileIndex = loadConfigImgFile((char*)filename,elemCreature);
- }
- else sprite.fileIndex = defaultFile;
-
const char* sexstr = elemVariant->Attribute("sex");
sheetIndexStr = elemVariant->Attribute("sheetIndex");
uint8_t cresex = 0;
@@ -167,9 +155,6 @@ bool addSingleCreatureConfig( TiXmlElement* elemCreature, vector<vector<Creature
if(strcmp( specstr, "Zombie" ) == 0) crespec = eCSC_Zombie;
if(strcmp( specstr, "Skeleton" ) == 0) crespec = eCSC_Skeleton;
}
- sprite.animFrames = getAnimFrames(elemVariant->Attribute("frames"));
- if (sprite.animFrames == 0)
- sprite.animFrames = ALL_FRAMES;
int shadow = baseShadow;
const char* shadowStr = elemVariant->Attribute("shadow");
@@ -180,220 +165,17 @@ bool addSingleCreatureConfig( TiXmlElement* elemCreature, vector<vector<Creature
if (shadow < 0 || shadow > MAX_SHADOW)
shadow = baseShadow;
- //decide what the sprite should be shaded by.
- const char* spriteVarColorStr = elemVariant->Attribute("color");
- if (spriteVarColorStr == NULL || spriteVarColorStr[0] == 0)
- {
- sprite.shadeBy = ShadeNone;
- }
- else
- {
- sprite.shadeBy = getShadeType(spriteVarColorStr);
- }
-
- //do bodyparts
- const char* bodyVarPartStr = elemVariant->Attribute("bodypart");
- //clear old bodypart string
- memset(sprite.bodyPart, 0, sizeof(sprite.bodyPart));
- //copy new, if found
- if (bodyVarPartStr != NULL && bodyVarPartStr[0] != 0)
- {
- strcpy(sprite.bodyPart, bodyVarPartStr);
- }
-
- //subsprites
- sprite.subSprites.clear();
- TiXmlElement* elemVarSubSprite = elemVariant->FirstChildElement("subsprite");
- while(elemVarSubSprite)
- {
- const char* subVarSpriteIndexStr = elemVarSubSprite->Attribute("sheetIndex");
- if (subVarSpriteIndexStr == NULL || subVarSpriteIndexStr[0] == 0)
- {
- contentError("Invalid Subsprite definition",elemVarSubSprite);
- break; //nothing to work with
- }
- // make a base sprite
- t_subSprite subVarSprite;
- subVarSprite.sheetIndex=atoi(subVarSpriteIndexStr);
- subVarSprite.fileIndex=sprite.fileIndex; //should be the same file as the main sprite by default.
-
- //do custom colors
- const char* subVarSpriteRedStr = elemVarSubSprite->Attribute("red");
- if (subVarSpriteRedStr == NULL || subVarSpriteRedStr[0] == 0)
- {
- red = 255;
- }
- else red=atoi(subVarSpriteRedStr);
- const char* subVarSpriteGreenStr = elemVarSubSprite->Attribute("green");
- if (subVarSpriteGreenStr == NULL || subVarSpriteGreenStr[0] == 0)
- {
- green = 255;
- }
- else green=atoi(subVarSpriteGreenStr);
- const char* subVarSpriteBlueStr = elemVarSubSprite->Attribute("blue");
- if (subVarSpriteBlueStr == NULL || subVarSpriteBlueStr[0] == 0)
- {
- blue = 255;
- }
- else blue=atoi(subVarSpriteBlueStr);
- subVarSprite.shadeColor = al_map_rgb(red, green, blue);
-
- //decide what the sprite should be shaded by.
- const char* subVarSpriteColorStr = elemVarSubSprite->Attribute("color");
- if (subVarSpriteColorStr == NULL || subVarSpriteColorStr[0] == 0)
- {
- subVarSprite.shadeBy = ShadeNone;
- }
- else
- {
- subVarSprite.shadeBy = getShadeType(subVarSpriteColorStr);
- }
-
- //do bodyparts
- const char* subBodyPartStr = elemVarSubSprite->Attribute("bodypart");
- //clear old bodypart string
- memset(subVarSprite.bodyPart, 0, sizeof(sprite.bodyPart));
- //copy new, if found
- if (subBodyPartStr != NULL && subBodyPartStr[0] != 0)
- {
- strcpy(subVarSprite.bodyPart, subBodyPartStr);
- }
-
- // check for local file definitions
- const char* subfilename = elemVarSubSprite->Attribute("file");
- if (subfilename != NULL && subfilename[0] != 0)
- {
- subVarSprite.fileIndex = loadConfigImgFile((char*)subfilename,elemVarSubSprite);
- }
- sprite.subSprites.push_back(subVarSprite);
- elemVarSubSprite = elemVarSubSprite->NextSiblingElement("subsprite");
- }
-
-
- //create profession config
- sprite.sheetIndex=atoi(sheetIndexStr);
+ sprite.set_by_xml(elemVariant, defaultFile);
CreatureConfiguration cre( professionID, customStr , cresex, crespec, sprite, shadow);
//add a copy to known creatures
pushCreatureConfig(knownCreatures, gameID, cre);
elemVariant = elemVariant->NextSiblingElement("variant");
}
- //create default config
- sprite.fileIndex = defaultFile;
- baseShadow;
sheetIndexStr = elemCreature->Attribute("sheetIndex");
- sprite.animFrames = ALL_FRAMES;
- const char* spriteColorStr = elemCreature->Attribute("color");
- if (spriteColorStr == NULL || spriteColorStr[0] == 0)
- {
- sprite.shadeBy = ShadeNone;
- }
- else
- {
- sprite.shadeBy = getShadeType(spriteColorStr);
- }
-
- // do custom colors
- const char* spriteRedStr = elemCreature->Attribute("red");
- if (spriteRedStr == NULL || spriteRedStr[0] == 0)
- {
- red = 255;
- }
- else red=atoi(spriteRedStr);
- const char* spriteGreenStr = elemCreature->Attribute("green");
- if (spriteGreenStr == NULL || spriteGreenStr[0] == 0)
- {
- green = 255;
- }
- else green=atoi(spriteGreenStr);
- const char* spriteBlueStr = elemCreature->Attribute("blue");
- if (spriteBlueStr == NULL || spriteBlueStr[0] == 0)
- {
- blue = 255;
- }
- else blue=atoi(spriteBlueStr);
-
- sprite.shadeColor = al_map_rgb(red, green, blue);
-
- //do bodyparts
- const char* bodyPartStr = elemCreature->Attribute("bodypart");
- //clear old bodypart string
- memset(sprite.bodyPart, 0, sizeof(sprite.bodyPart));
- //copy new, if found
- if (bodyPartStr != NULL && bodyPartStr[0] != 0)
- {
- strcpy(sprite.bodyPart, bodyPartStr);
- }
- //subsprites
- sprite.subSprites.clear();
- TiXmlElement* elemSubSprite = elemCreature->FirstChildElement("subsprite");
- while(elemSubSprite)
- {
- const char* subSpriteIndexStr = elemSubSprite->Attribute("sheetIndex");
- if (subSpriteIndexStr == NULL || subSpriteIndexStr[0] == 0)
- {
- contentError("Invalid Subsprite definition",elemSubSprite);
- break; //nothing to work with
- }
- // make a base sprite
- t_subSprite subSprite;
- subSprite.sheetIndex=atoi(subSpriteIndexStr);
- subSprite.fileIndex=sprite.fileIndex; //should be the same file as the main sprite by default.
-
- //do custom colors
- const char* subSpriteRedStr = elemSubSprite->Attribute("red");
- if (subSpriteRedStr == NULL || subSpriteRedStr[0] == 0)
- {
- red = 255;
- }
- else red=atoi(subSpriteRedStr);
- const char* subSpriteGreenStr = elemSubSprite->Attribute("green");
- if (subSpriteGreenStr == NULL || subSpriteGreenStr[0] == 0)
- {
- green = 255;
- }
- else green=atoi(subSpriteGreenStr);
- const char* subSpriteBlueStr = elemSubSprite->Attribute("blue");
- if (subSpriteBlueStr == NULL || subSpriteBlueStr[0] == 0)
- {
- blue = 255;
- }
- else blue=atoi(subSpriteBlueStr);
- subSprite.shadeColor = al_map_rgb(red, green, blue);
-
- //decide what the sprite should be shaded by.
- const char* subSpriteColorStr = elemSubSprite->Attribute("color");
- if (subSpriteColorStr == NULL || subSpriteColorStr[0] == 0)
- {
- subSprite.shadeBy = ShadeNone;
- }
- else
- {
- subSprite.shadeBy = getShadeType(subSpriteColorStr);
- }
-
- //do bodyparts
- const char* subBodyPartStr = elemSubSprite->Attribute("bodypart");
- //clear old bodypart string
- memset(subSprite.bodyPart, 0, sizeof(sprite.bodyPart));
- //copy new, if found
- if (subBodyPartStr != NULL && subBodyPartStr[0] != 0)
- {
- strcpy(subSprite.bodyPart, subBodyPartStr);
- }
-
- // check for local file definitions
- const char* subfilename = elemSubSprite->Attribute("file");
- if (subfilename != NULL && subfilename[0] != 0)
- {
- subSprite.fileIndex = loadConfigImgFile((char*)subfilename,elemSubSprite);
- }
- sprite.subSprites.push_back(subSprite);
- elemSubSprite = elemSubSprite->NextSiblingElement("subsprite");
- }
if (sheetIndexStr)
{
- sprite.sheetIndex = atoi( sheetIndexStr );
+ sprite.set_by_xml(elemCreature, basefile);
CreatureConfiguration cre( INVALID_INDEX, NULL, eCreatureSex_NA, eCSC_Any, sprite, baseShadow);
//add a copy to known creatures
pushCreatureConfig(knownCreatures, gameID, cre);