From 16106cae769f485908c15ac39d0e017167099a48 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 13 Dec 2008 15:51:25 +0100 Subject: Moved gender and hair style back to Being These properties should also apply to NPCs and possibly even monsters in the future. --- src/being.cpp | 9 +++++++++ src/being.h | 36 ++++++++++++++++++++++++++++++++++++ src/player.cpp | 10 +++------- src/player.h | 26 -------------------------- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/being.cpp b/src/being.cpp index a267d033..bade64b6 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -57,6 +57,9 @@ Being::Being(int id, int job, Map *map): mSpriteDirection(DIRECTION_DOWN), mDirection(DOWN), mMap(NULL), mEquippedWeapon(NULL), + mHairStyle(0), + mHairColor(0), + mGender(GENDER_UNSPECIFIED), mSpeechTime(0), mSprites(VECTOREND_SPRITE, NULL), mSpriteIDs(VECTOREND_SPRITE, 0), @@ -286,6 +289,12 @@ void Being::setPath(const Path &path) mPath = path; } +void Being::setHairStyle(int style, int color) +{ + mHairStyle = style < 0 ? mHairStyle : style % NR_HAIR_STYLES; + mHairColor = color < 0 ? mHairColor : color % NR_HAIR_COLORS; +} + void Being::setSprite(int slot, int id, const std::string &color) { assert(slot >= BASE_SPRITE && slot < VECTOREND_SPRITE); diff --git a/src/being.h b/src/being.h index bf11e3ed..cce5e99f 100644 --- a/src/being.h +++ b/src/being.h @@ -46,6 +46,12 @@ class ImageSet; class Particle; class SpeechBubble; +enum Gender { + GENDER_MALE = 0, + GENDER_FEMALE = 1, + GENDER_UNSPECIFIED = 2 +}; + class Being : public Sprite { public: @@ -173,6 +179,33 @@ class Being : public Sprite void setName(const std::string &name) { mName = name; } + /** + * Sets the gender for this being. + */ + virtual void setGender(Gender gender) { mGender = gender; } + + /** + * Gets the hair color for this being. + */ + int getHairColor() const + { return mHairColor; } + + /** + * Gets the hair style for this being. + */ + int getHairStyle() const + { return mHairStyle; } + + /** + * Sets the hair style and color for this being. + * + * NOTE: This method was necessary for convenience in the 0.0 client. + * It should be removed here since the server can provide the hair ID + * and coloring the same way it does for other equipment pieces. Then + * Being::setSprite can be used instead. + */ + virtual void setHairStyle(int style, int color); + /** * Sets visible equipments for this being. */ @@ -353,6 +386,9 @@ class Being : public Sprite Path mPath; std::string mSpeech; + int mHairStyle; + int mHairColor; + Gender mGender; Uint32 mSpeechTime; std::vector mSprites; diff --git a/src/player.cpp b/src/player.cpp index 648b330a..e24a2d8c 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -35,10 +35,7 @@ #include "gui/gui.h" Player::Player(int id, int job, Map *map): - Being(id, job, map), - mGender(GENDER_UNSPECIFIED), - mHairStyle(0), - mHairColor(0) + Being(id, job, map) { } @@ -67,7 +64,7 @@ void Player::setGender(Gender gender) { if (gender != mGender) { - mGender = gender; + Being::setGender(gender); /* Human base sprite. When implementing different races remove this * line and set the base sprite when setting the race of the player @@ -92,8 +89,7 @@ void Player::setHairStyle(int style, int color) color = color < 0 ? mHairColor : color % NR_HAIR_COLORS; if (style == mHairStyle && color == mHairColor) return; - mHairStyle = style; - mHairColor = color; + Being::setHairStyle(style, color); static char const *const colors[NR_HAIR_COLORS] = { diff --git a/src/player.h b/src/player.h index 068e3cf5..12f9d268 100644 --- a/src/player.h +++ b/src/player.h @@ -28,12 +28,6 @@ class Graphics; class Map; class Guild; -enum Gender { - GENDER_MALE = 0, - GENDER_FEMALE = 1, - GENDER_UNSPECIFIED = 2 -}; - /** * A player being. Players have their name drawn beneath them. This class also * implements player-specific loading of base sprite, hair sprite and equipment @@ -60,25 +54,8 @@ class Player : public Being */ void setGender(Gender); - /** - * Gets the hair color for this player. - */ - int getHairColor() const - { return mHairColor; } - - /** - * Gets the hair style for this player. - */ - int getHairStyle() const - { return mHairStyle; } - /** * Sets the hair style and color for this player. - * - * NOTE: This method was necessary for convenience in the 0.0 client. - * It should be removed here since the server can provide the hair ID - * and coloring the same way it does for other equipment pieces. Then - * Being::setSprite can be used instead. */ void setHairStyle(int style, int color); @@ -140,9 +117,6 @@ class Player : public Being std::map mGuilds; private: - Gender mGender; - Uint8 mHairStyle; - Uint8 mHairColor; bool mInParty; }; -- cgit v1.2.3-70-g09d2