summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being.cpp15
-rw-r--r--src/being.h9
-rw-r--r--src/gui/char_select.cpp4
-rw-r--r--src/player.cpp2
-rw-r--r--src/resources/colordb.cpp2
5 files changed, 25 insertions, 7 deletions
diff --git a/src/being.cpp b/src/being.cpp
index db8b18e6..7c884218 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -38,6 +38,7 @@
#include "text.h"
#include "resources/resourcemanager.h"
+#include "resources/itemdb.h"
#include "resources/imageset.h"
#include "resources/iteminfo.h"
@@ -52,6 +53,7 @@
#define BEING_EFFECTS_FILE "effects.xml"
int Being::instances = 0;
+int Being::mNumberOfHairstyles = 1;
ImageSet *Being::emotionSet = NULL;
static const int X_SPEECH_OFFSET = 18;
@@ -90,6 +92,17 @@ Being::Being(int id, int job, Map *map):
ResourceManager *rm = ResourceManager::getInstance();
emotionSet = rm->getImageSet("graphics/gui/emotions.png", 30, 32);
if (!emotionSet) logger->error("Unable to load emotions!");
+
+ // Hairstyles are encoded as negative numbers. Count how far negative we can go.
+ int hairstyles = 1;
+ while (ItemDB::get(-hairstyles).getSprite(0) != "error.xml")
+ {
+ hairstyles++;
+ }
+ mNumberOfHairstyles = hairstyles;
+ if (mNumberOfHairstyles == 0)
+ mNumberOfHairstyles = 1; // No hair style -> no hair
+
}
instances++;
@@ -149,7 +162,7 @@ void Being::setPath(const Path &path)
void Being::setHairStyle(int style, int color)
{
- mHairStyle = style < 0 ? mHairStyle : style % NR_HAIR_STYLES;
+ mHairStyle = style < 0 ? mHairStyle : style % mNumberOfHairstyles;
mHairColor = color;
}
diff --git a/src/being.h b/src/being.h
index a2d5e5a7..b0c5b49e 100644
--- a/src/being.h
+++ b/src/being.h
@@ -38,8 +38,6 @@
#include "resources/colordb.h"
-#define NR_HAIR_STYLES 10
-
#define FIRST_IGNORE_EMOTE 14
class AnimatedSprite;
@@ -200,6 +198,11 @@ class Being : public Sprite
{ return mHairStyle; }
/**
+ * Get the number of hairstyles implemented
+ */
+ static int getNumOfHairstyles() { return mNumberOfHairstyles; }
+
+ /**
* Sets the hair style and color for this being.
*/
virtual void setHairStyle(int style, int color);
@@ -398,6 +401,8 @@ class Being : public Sprite
/** Engine-related infos about weapon. */
const ItemInfo* mEquippedWeapon;
+ static int mNumberOfHairstyles; /** Number of hair styles in use */
+
Path mPath;
std::string mSpeech;
Text *mText;
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index b83f98de..ca4d8608 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -261,7 +261,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
printf("%d\n", numberOfHairColors);
- mPlayer->setHairStyle(rand() % NR_HAIR_STYLES, rand() % numberOfHairColors);
+ mPlayer->setHairStyle(rand() % mPlayer->getNumOfHairstyles(), rand() % numberOfHairColors);
mNameField = new TextField("");
mNameLabel = new gcn::Label("Name:");
@@ -352,7 +352,7 @@ CharCreateDialog::action(const gcn::ActionEvent &event)
mPlayer->setHairStyle(mPlayer->getHairStyle() + 1, mPlayer->getHairColor());
}
else if (event.getId() == "prevstyle") {
- mPlayer->setHairStyle(mPlayer->getHairStyle() + NR_HAIR_STYLES - 1, mPlayer->getHairColor());
+ mPlayer->setHairStyle(mPlayer->getHairStyle() + mPlayer->getNumOfHairstyles() - 1, mPlayer->getHairColor());
}
}
diff --git a/src/player.cpp b/src/player.cpp
index 37badcdc..c9d1e683 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -159,7 +159,7 @@ void Player::setGender(int gender)
void Player::setHairStyle(int style, int color)
{
- style = style < 0 ? mHairStyle : style % NR_HAIR_STYLES;
+ style = style < 0 ? mHairStyle : style % mNumberOfHairstyles;
if (style == mHairStyle && color == mHairColor) return;
Being::setHairStyle(style, color);
diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp
index caa1fbda..26ba298d 100644
--- a/src/resources/colordb.cpp
+++ b/src/resources/colordb.cpp
@@ -35,7 +35,7 @@ namespace
{
ColorDB::Colors mColors;
bool mLoaded = false;
- std::string mFail = "";
+ std::string mFail = "#ffffff";
}
void ColorDB::load()