diff options
author | Fate <fate.tmw@googlemail.com> | 2008-11-01 23:45:48 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-12-13 16:06:17 +0100 |
commit | ba02a23b63bf0a1fde2194d163ead365d2a4fdf0 (patch) | |
tree | 3fbaa733e43b270395b20418f71211b9a5b1fed2 /src/being.cpp | |
parent | 16106cae769f485908c15ac39d0e017167099a48 (diff) | |
download | mana-client-ba02a23b63bf0a1fde2194d163ead365d2a4fdf0.tar.gz mana-client-ba02a23b63bf0a1fde2194d163ead365d2a4fdf0.tar.bz2 mana-client-ba02a23b63bf0a1fde2194d163ead365d2a4fdf0.tar.xz mana-client-ba02a23b63bf0a1fde2194d163ead365d2a4fdf0.zip |
* Use hair.xml to determine hair colours (#514)
* Auto-detect number of hair styles available (#514)
Conflicts:
ChangeLog
src/being.cpp
src/being.h
src/gui/char_select.cpp
(cherry picked from eAthena client)
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 94 |
1 files changed, 92 insertions, 2 deletions
diff --git a/src/being.cpp b/src/being.cpp index bade64b6..fbee967f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -31,6 +31,7 @@ #include "map.h" #include "particle.h" +#include "resources/itemdb.h" #include "resources/resourcemanager.h" #include "resources/imageset.h" #include "resources/iteminfo.h" @@ -40,11 +41,14 @@ #include "utils/dtor.h" #include "utils/tostring.h" +#include "utils/xml.h" namespace { const bool debug_movement = true; } +#define HAIR_FILE "hair.xml" + int Being::instances = 0; ImageSet *Being::emotionSet = NULL; @@ -291,8 +295,8 @@ void Being::setPath(const Path &path) void Being::setHairStyle(int style, int color) { - mHairStyle = style < 0 ? mHairStyle : style % NR_HAIR_STYLES; - mHairColor = color < 0 ? mHairColor : color % NR_HAIR_COLORS; + mHairStyle = style < 0 ? mHairStyle : style % getHairStylesNr(); + mHairColor = color < 0 ? mHairColor : color % getHairColorsNr(); } void Being::setSprite(int slot, int id, const std::string &color) @@ -605,3 +609,89 @@ int Being::getHeight() const return 0; } } + + + + +static int hairStylesNr; +static int hairColorsNr; +static std::vector<std::string> hairColors; + +static void +initializeHair(void); + +int +Being::getHairStylesNr(void) +{ + initializeHair(); + return hairStylesNr; +} + +int +Being::getHairColorsNr(void) +{ + initializeHair(); + return hairColorsNr; +} + +std::string +Being::getHairColor(int index) +{ + initializeHair(); + if (index < 0 || index >= hairColorsNr) + return "#000000"; + + return hairColors[index]; +} + +static bool hairInitialized = false; + +static void +initializeHair(void) +{ + 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; + + XML::Document doc(HAIR_FILE); + xmlNodePtr root = doc.rootNode(); + + if (!root || !xmlStrEqual(root->name, BAD_CAST "colors")) + { + logger->log("Error loading being hair configuration file"); + } else { + for_each_xml_child_node(node, root) + { + if (xmlStrEqual(node->name, BAD_CAST "color")) + { + int index = atoi(XML::getProperty(node, "id", "-1").c_str()); + std::string value = XML::getProperty(node, "value", ""); + + if (index >= 0 && value != "") { + if (index >= hairColorsNr) { + hairColorsNr = index + 1; + hairColors.resize(hairColorsNr, "#000000"); + } + hairColors[index] = value; + } + } + } + } // done initializing + + if (hairColorsNr == 0) { // No colours -> black only + hairColorsNr = 1; + hairColors.resize(hairColorsNr, "#000000"); + } + + hairInitialized = 1; +} |