diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-02-22 19:58:29 +0000 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-01-05 20:36:46 -0700 |
commit | b6e7b6c6cb3ea26157e3a78713cc9621dc46b2d7 (patch) | |
tree | 67c3d0552af5661b3847ef7e397771bc101e0c7c | |
parent | 77db175ceabe8d05665191835d0250a927d93d32 (diff) | |
download | mana-client-b6e7b6c6cb3ea26157e3a78713cc9621dc46b2d7.tar.gz mana-client-b6e7b6c6cb3ea26157e3a78713cc9621dc46b2d7.tar.bz2 mana-client-b6e7b6c6cb3ea26157e3a78713cc9621dc46b2d7.tar.xz mana-client-b6e7b6c6cb3ea26157e3a78713cc9621dc46b2d7.zip |
Handling gender with an enum everywhere.
(cherry picked from mainline commit d3adc61aa4b4924f82d8cbc23bea26da7257da97)
Conflicts:
src/net/beinghandler.cpp
src/net/charserverhandler.cpp
src/player.cpp
src/player.h
-rw-r--r-- | src/being.cpp | 4 | ||||
-rw-r--r-- | src/being.h | 12 | ||||
-rw-r--r-- | src/gui/char_select.cpp | 4 | ||||
-rw-r--r-- | src/gui/char_select.h | 7 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 6 | ||||
-rw-r--r-- | src/net/charserverhandler.cpp | 5 | ||||
-rw-r--r-- | src/npc.cpp | 2 | ||||
-rw-r--r-- | src/npc.h | 2 | ||||
-rw-r--r-- | src/player.cpp | 20 | ||||
-rw-r--r-- | src/player.h | 2 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 8 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 2 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 6 |
14 files changed, 45 insertions, 39 deletions
diff --git a/src/being.cpp b/src/being.cpp index edacbc26..07895eb2 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -73,7 +73,7 @@ Being::Being(int id, int job, Map *map): mParticleEffects(config.getValue("particleeffects", 1)), mEquippedWeapon(NULL), mHairStyle(1), mHairColor(0), - mGender(2), + mGender(GENDER_UNSPECIFIED), mSpeechTime(0), mPx(0), mPy(0), mSprites(VECTOREND_SPRITE, NULL), @@ -95,7 +95,7 @@ Being::Being(int id, int job, Map *map): // Hairstyles are encoded as negative numbers. Count how far negative we can go. int hairstyles = 1; - while (ItemDB::get(-hairstyles).getSprite(0) != "error.xml") + while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml") { hairstyles++; } diff --git a/src/being.h b/src/being.h index ca051811..ccb1c4c4 100644 --- a/src/being.h +++ b/src/being.h @@ -70,6 +70,12 @@ struct PATH_NODE typedef std::list<PATH_NODE> Path; typedef Path::iterator PathIterator; +enum Gender { + GENDER_MALE = 0, + GENDER_FEMALE = 1, + GENDER_UNSPECIFIED = 2 +}; + class Being : public Sprite { public: @@ -222,12 +228,12 @@ class Being : public Sprite /** * Sets the gender of this being. */ - virtual void setGender(int gender) { mGender = gender; } + virtual void setGender(Gender gender) { mGender = gender; } /** * Gets the gender of this being. */ - int getGender() const { return mGender; } + Gender getGender() const { return mGender; } /** * Makes this being take the next step of his path. @@ -419,7 +425,7 @@ class Being : public Sprite std::string mSpeech; Text *mText; Uint16 mHairStyle, mHairColor; - Uint8 mGender; + Gender mGender; Uint32 mSpeechTime; Sint32 mPx, mPy; /**< Pixel coordinates */ Uint16 mStunMode; /**< Stun mode; zero if not stunned */ diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 53cc1e8d..6a52a745 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -73,7 +73,7 @@ void CharDeleteConfirm::action(const gcn::ActionEvent &event) CharSelectDialog::CharSelectDialog(Network *network, LockedArray<LocalPlayer*> *charInfo, - unsigned char gender): + Gender gender): Window("Select Character"), mNetwork(network), mCharInfo(charInfo), mGender(gender), mCharSelected(false) { @@ -248,7 +248,7 @@ bool CharSelectDialog::selectByName(const std::string &name) } CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, - unsigned char gender): + Gender gender): Window("Create Character", true, parent), mNetwork(network), mSlot(slot) { mPlayer = new Player(0, 0, NULL); diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 63630736..d592ce48 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -28,6 +28,7 @@ #include "../guichanfwd.h" #include "../lockedarray.h" +#include "../being.h" class LocalPlayer; class Network; @@ -48,7 +49,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener */ CharSelectDialog(Network *network, LockedArray<LocalPlayer*> *charInfo, - unsigned char gender); + Gender gender); void action(const gcn::ActionEvent &event); @@ -76,7 +77,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener PlayerBox *mPlayerBox; - unsigned char mGender; + Gender mGender; bool mCharSelected; /** @@ -102,7 +103,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener * Constructor. */ CharCreateDialog(Window *parent, int slot, Network *network, - unsigned char gender); + Gender gender); /** * Destructor. diff --git a/src/main.cpp b/src/main.cpp index 12789d80..7de3823f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -937,8 +937,10 @@ int main(int argc, char *argv[]) case CHAR_SELECT_STATE: logger->log("State: CHAR_SELECT"); currentDialog = new CharSelectDialog(network, &charInfo, - 1 - loginData.sex); + (loginData.sex == 0) ? + GENDER_FEMALE : GENDER_MALE); positionDialog(currentDialog, screenWidth, screenHeight); + if (((CharSelectDialog*) currentDialog)-> selectByName(options.playername)) options.chooseDefault = true; diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 4f525e8d..5b689266 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -137,7 +137,8 @@ void BeingHandler::handleMessage(MessageIn *msg) msg->readInt16(); // manner msg->readInt16(); // karma msg->readInt8(); // unknown - dstBeing->setGender(1 - msg->readInt8()); // gender + dstBeing->setGender( + (msg->readInt8() == 0) ? GENDER_FEMALE : GENDER_MALE); // Set these after the gender, as the sprites may be gender-specific dstBeing->setSprite(Being::BOTTOMCLOTHES_SPRITE, headBottom); @@ -404,7 +405,8 @@ void BeingHandler::handleMessage(MessageIn *msg) msg->readInt32(); // emblem msg->readInt16(); // manner msg->readInt8(); // karma - dstBeing->setGender(1 - msg->readInt8()); // gender + dstBeing->setGender( + (msg->readInt8() == 0) ? GENDER_FEMALE : GENDER_MALE); // Set these after the gender, as the sprites may be gender-specific dstBeing->setSprite(Being::WEAPON_SPRITE, weapon); diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 11754b6f..eb724630 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -187,10 +187,11 @@ void CharServerHandler::handleMessage(MessageIn *msg) } } -LocalPlayer* CharServerHandler::readPlayerData(MessageIn &msg, int &slot) +LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot) { LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL); - tempPlayer->setGender(1 - mLoginData->sex); + tempPlayer->setGender( + (mLoginData->sex == 0) ? GENDER_FEMALE : GENDER_MALE); tempPlayer->mCharId = msg.readInt32(); tempPlayer->setXp(msg.readInt32()); diff --git a/src/npc.cpp b/src/npc.cpp index 8dbbf83c..2aa15209 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -94,7 +94,7 @@ void NPC::setName(const std::string &name) Being::setName(displayName + " (NPC)"); } -void NPC::setGender(int gender) +void NPC::setGender(Gender gender) { Being::setGender(gender); } @@ -36,7 +36,7 @@ class NPC : public Player ~NPC(); void setName(const std::string &name); - void setGender(int gender); + void setGender(Gender gender); void setSprite(int slot, int id, std::string color); virtual Type diff --git a/src/player.cpp b/src/player.cpp index e6244bb5..47275c81 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -124,25 +124,17 @@ Player::flash(int time) } } -void Player::setGender(int gender) +void Player::setGender(Gender gender) { - // Players can only be male or female - if (gender > 1) - { - logger->log("Warning: unsupported gender %i, assuming male.", gender); - gender = 0; - } - - if (gender != mGender) { Being::setGender(gender); - setSprite(Being::BASE_SPRITE, -100); /* Human base sprite. When implementing - * different races remove this line - * and set the base sprite when setting - * the race of the player character. - */ + /* Human base sprite. When implementing different races remove this + * line and set the base sprite when setting the race of the player + * character. + */ + setSprite(Being::BASE_SPRITE, -100); // Reload all subsprites for (int i = 1; i < VECTOREND_SPRITE; i++) diff --git a/src/player.h b/src/player.h index c91ad3c2..97ff15d9 100644 --- a/src/player.h +++ b/src/player.h @@ -53,7 +53,7 @@ class Player : public Being getType() const; virtual void - setGender(int gender); + setGender(Gender gender); /** * Sets the hair style and color for this player. diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index f4ccc511..bca2b030 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -53,8 +53,8 @@ void ItemDB::load() mUnknown = new ItemInfo(); mUnknown->setName("Unknown item"); mUnknown->setImageName(""); - mUnknown->setSprite("error.xml", 0); - mUnknown->setSprite("error.xml", 1); + mUnknown->setSprite("error.xml", GENDER_MALE); + mUnknown->setSprite("error.xml", GENDER_FEMALE); XML::Document doc("items.xml"); xmlNodePtr rootNode = doc.rootNode(); @@ -172,11 +172,11 @@ void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) if (gender == "male" || gender == "unisex") { - itemInfo->setSprite(filename, 0); + itemInfo->setSprite(filename, GENDER_MALE); } if (gender == "female" || gender == "unisex") { - itemInfo->setSprite(filename, 1); + itemInfo->setSprite(filename, GENDER_FEMALE); } } diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 5daeafe6..6f669376 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -23,7 +23,7 @@ #include "iteminfo.h" const std::string& -ItemInfo::getSprite(int gender) const +ItemInfo::getSprite(Gender gender) const { if (mView) { diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 4678bc08..b7729d2c 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -28,6 +28,8 @@ #include "spritedef.h" +#include "../being.h" + enum EquipmentSoundEvent { EQUIP_EVENT_STRIKE, @@ -91,10 +93,10 @@ class ItemInfo void setView(int view) { mView = view; } - void setSprite(const std::string &animationFile, int gender) + void setSprite(const std::string &animationFile, Gender gender) { mAnimationFiles[gender] = animationFile; } - const std::string& getSprite(int gender) const; + const std::string& getSprite(Gender gender) const; void setWeaponType(int); |