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/being.cpp | |
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/being.cpp')
-rw-r--r-- | src/being.cpp | 75 |
1 files changed, 23 insertions, 52 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() |