diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-03-11 14:30:23 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-03-11 14:30:23 -0600 |
commit | 2eb027b0f7a67706df68fe29e605c5be7fc1d5c9 (patch) | |
tree | 6d0803edbd5354afcef9440f087d2a228dd576d4 /src | |
parent | c2e4a7a70971355f1446bb01053af8a1da8c98e1 (diff) | |
download | mana-2eb027b0f7a67706df68fe29e605c5be7fc1d5c9.tar.gz mana-2eb027b0f7a67706df68fe29e605c5be7fc1d5c9.tar.bz2 mana-2eb027b0f7a67706df68fe29e605c5be7fc1d5c9.tar.xz mana-2eb027b0f7a67706df68fe29e605c5be7fc1d5c9.zip |
Remove some duplication in hair loading code
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 75 | ||||
-rw-r--r-- | src/being.h | 8 |
2 files changed, 29 insertions, 54 deletions
diff --git a/src/being.cpp b/src/being.cpp index 4d3bcfa0..bf49e852 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -58,7 +58,9 @@ #define BEING_EFFECTS_FILE "effects.xml" #define HAIR_FILE "hair.xml" +int Being::mNumberOfHairColors = 1; int Being::mNumberOfHairstyles = 1; +std::vector<std::string> Being::hairColors; std::vector<AnimatedSprite*> Being::emotionSet; static const int X_SPEECH_OFFSET = 18; @@ -750,58 +752,41 @@ void Being::internalTriggerEffect(int effectId, bool sfx, bool gfx) } } - - - -static int hairStylesNr; -static int hairColorsNr; -static std::vector<std::string> hairColors; - -static void initializeHair(); - -int Being::getHairStylesNr() +int Being::getHairStyleCount() { - initializeHair(); - return hairStylesNr; + return mNumberOfHairstyles; } -int Being::getHairColorsNr() +int Being::getHairColorCount() { - initializeHair(); - return hairColorsNr; + return mNumberOfHairColors; } std::string Being::getHairColor(int index) { - initializeHair(); - if (index < 0 || index >= hairColorsNr) + if (index < 0 || index >= mNumberOfHairColors) return "#000000"; return hairColors[index]; } -static bool hairInitialized = false; - -static void initializeHair() +void Being::initializeHair() { - if (hairInitialized) - return; - - // Hairstyles are encoded as negative numbers. Count how far negative we - // can go. - int hairstylesCtr = -1; - while (ItemDB::get(hairstylesCtr).getSprite(GENDER_MALE) != "error.xml") - --hairstylesCtr; - - hairStylesNr = -hairstylesCtr; // done. - if (hairStylesNr == 0) - hairStylesNr = 1; // No hair style -> no hair - - hairColorsNr = 0; + // Hairstyles are encoded as negative numbers. Count how far negative + // we can go. + int hairstyles = -1; + while (ItemDB::get(hairstyles).getSprite(GENDER_MALE) != "error.xml") + { + hairstyles--; + } + mNumberOfHairstyles = -hairstyles; XML::Document doc(HAIR_FILE); xmlNodePtr root = doc.rootNode(); + // Add an initial hair color + hairColors.resize(1, "#000000"); + if (!root || !xmlStrEqual(root->name, BAD_CAST "colors")) { logger->log("Error loading being hair configuration file"); @@ -814,22 +799,15 @@ static void initializeHair() std::string value = XML::getProperty(node, "value", ""); if (index >= 0 && !value.empty()) { - if (index >= hairColorsNr) { - hairColorsNr = index + 1; - hairColors.resize(hairColorsNr, "#000000"); + if (index >= mNumberOfHairColors) { + mNumberOfHairColors = index + 1; + hairColors.resize(mNumberOfHairColors, "#000000"); } hairColors[index] = value; } } } - } // done initializing - - if (hairColorsNr == 0) { // No colors -> black only - hairColorsNr = 1; - hairColors.resize(hairColorsNr, "#000000"); } - - hairInitialized = 1; } void Being::load() @@ -844,14 +822,7 @@ void Being::load() emotionSet.push_back(AnimatedSprite::load(file, variant)); } - // Hairstyles are encoded as negative numbers. Count how far negative - // we can go. - int hairstyles = 1; - while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml") - { - hairstyles++; - } - mNumberOfHairstyles = hairstyles; + initializeHair(); } void Being::cleanup() diff --git a/src/being.h b/src/being.h index 1987d5b8..754c163a 100644 --- a/src/being.h +++ b/src/being.h @@ -436,9 +436,9 @@ class Being : public Sprite // Target cursor being used by the being Image *mTargetCursor; - static int getHairColorsNr(); + static int getHairColorCount(); - static int getHairStylesNr(); + static int getHairStyleCount(); static std::string getHairColor(int index); @@ -501,6 +501,8 @@ class Being : public Sprite /** Engine-related infos about weapon. */ const ItemInfo* mEquippedWeapon; + static std::vector<std::string> hairColors; + static int mNumberOfHairColors; /** Number of hair colors in use */ static int mNumberOfHairstyles; /** Number of hair styles in use */ Path mPath; @@ -522,6 +524,8 @@ class Being : public Sprite ParticleList mChildParticleEffects; private: + static void initializeHair(); + /** * Calculates the offset in the given directions. * If walking in direction 'neg' the value is negated. |