summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being.cpp7
-rw-r--r--src/being.h13
-rw-r--r--src/gui/char_select.cpp4
-rw-r--r--src/gui/char_select.h7
-rw-r--r--src/main.cpp10
-rw-r--r--src/net/beinghandler.cpp6
-rw-r--r--src/net/charserverhandler.cpp5
-rw-r--r--src/player.cpp20
-rw-r--r--src/player.h2
-rw-r--r--src/resources/itemdb.cpp8
-rw-r--r--src/resources/iteminfo.cpp2
-rw-r--r--src/resources/iteminfo.h6
12 files changed, 47 insertions, 43 deletions
diff --git a/src/being.cpp b/src/being.cpp
index f9c6296c..c04aeaa9 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -70,7 +70,7 @@ Being::Being(int id, int job, Map *map):
mMap(NULL),
mEquippedWeapon(NULL),
mHairStyle(1), mHairColor(0),
- mGender(2),
+ mGender(GENDER_UNSPECIFIED),
mSpeechTime(0),
mPx(0), mPy(0),
mStunMode(0),
@@ -669,9 +669,10 @@ static void initializeHair()
if (hairInitialized)
return;
- // Hairstyles are encoded as negative numbers. Count how far negative we can go.
+ // Hairstyles are encoded as negative numbers. Count how far negative we
+ // can go.
int hairstylesCtr = -1;
- while (ItemDB::get(hairstylesCtr).getSprite(0) != "error.xml")
+ while (ItemDB::get(hairstylesCtr).getSprite(GENDER_MALE) != "error.xml")
--hairstylesCtr;
hairStylesNr = -hairstylesCtr; // done.
diff --git a/src/being.h b/src/being.h
index 6319bd47..e70cdd09 100644
--- a/src/being.h
+++ b/src/being.h
@@ -47,9 +47,14 @@ class ImageSet;
class Particle;
class Text;
-
class StatusEffect;
+enum Gender {
+ GENDER_MALE = 0,
+ GENDER_FEMALE = 1,
+ GENDER_UNSPECIFIED = 2
+};
+
class Being : public Sprite
{
public:
@@ -193,12 +198,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.
@@ -418,7 +423,7 @@ class Being : public Sprite
Path mPath;
Text *mSpeech;
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 d951f12e..7c067eef 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -74,7 +74,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)
{
@@ -249,7 +249,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 0890bea9..22c247b6 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -26,6 +26,7 @@
#include "../guichanfwd.h"
#include "../lockedarray.h"
+#include "../being.h"
#include <guichan/actionlistener.hpp>
@@ -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 d99c1985..83686749 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -34,6 +34,9 @@
#include <libxml/parser.h>
+#ifdef WIN32
+#include <SDL_syswm.h>
+#endif
#ifndef WIN32
#include <cerrno>
#include <sys/stat.h>
@@ -83,10 +86,6 @@
#include "utils/dtor.h"
#include "utils/tostring.h"
-#ifdef WIN32
-#include <SDL_syswm.h>
-#endif
-
namespace {
Window *setupWindow = 0;
@@ -874,7 +873,8 @@ 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);
if (((CharSelectDialog*) currentDialog)->
selectByName(options.playername))
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp
index 9d91d988..c8d12499 100644
--- a/src/net/beinghandler.cpp
+++ b/src/net/beinghandler.cpp
@@ -141,7 +141,8 @@ void BeingHandler::handleMessage(MessageIn *msg)
msg->readInt16(); // manner
dstBeing->setStatusEffectBlock(32, msg->readInt16()); // opt3
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::BOTTOMCLOTHES_SPRITE, headBottom);
@@ -420,7 +421,8 @@ void BeingHandler::handleMessage(MessageIn *msg)
msg->readInt16(); // manner
dstBeing->setStatusEffectBlock(32, msg->readInt16()); // opt3
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 249995ee..df3f5ecf 100644
--- a/src/net/charserverhandler.cpp
+++ b/src/net/charserverhandler.cpp
@@ -176,10 +176,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/player.cpp b/src/player.cpp
index f43e54d5..f81c039c 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -105,25 +105,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 4676124c..268c77bb 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 c05d4604..8fd60110 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,12 +172,12 @@ 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 fb2c8ffe..201b8ca9 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -24,7 +24,7 @@
#include "itemdb.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);