summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-11-20 10:50:00 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-11-20 10:50:00 +0000
commit5a7abdafdac8f6ddd7972cadbc7e20563a0a29fc (patch)
tree95684590a32266b28f046475cfa1926c99f67e52
parentcf36850d2bdda67cb472d938ed58053a92fa6935 (diff)
downloadMana-5a7abdafdac8f6ddd7972cadbc7e20563a0a29fc.tar.gz
Mana-5a7abdafdac8f6ddd7972cadbc7e20563a0a29fc.tar.bz2
Mana-5a7abdafdac8f6ddd7972cadbc7e20563a0a29fc.tar.xz
Mana-5a7abdafdac8f6ddd7972cadbc7e20563a0a29fc.zip
Merged revisions 3629-3630 via svnmerge from
https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/trunk (but kept looks in Being class, since eAthena works that way) ........ r3629 | gmelquio | 2007-10-18 21:00:38 +0200 (Thu, 18 Oct 2007) | 1 line Removed player looks from generic beings. Prevented client termination on missing sprites. Merged weapon-type and attack-type fields for items. ........ r3630 | gmelquio | 2007-10-18 21:30:57 +0200 (Thu, 18 Oct 2007) | 1 line Fixed changelog message. ........
-rw-r--r--ChangeLog13
-rw-r--r--src/animatedsprite.cpp18
-rw-r--r--src/animatedsprite.h4
-rw-r--r--src/being.cpp6
-rw-r--r--src/being.h40
-rw-r--r--src/gui/char_select.cpp10
-rw-r--r--src/gui/char_select.h6
-rw-r--r--src/gui/minimap.cpp14
-rw-r--r--src/gui/viewport.cpp2
-rw-r--r--src/localplayer.cpp7
-rw-r--r--src/localplayer.h2
-rw-r--r--src/monster.cpp2
-rw-r--r--src/net/beinghandler.cpp4
-rw-r--r--src/net/charserverhandler.cpp2
-rw-r--r--src/npc.cpp2
-rw-r--r--src/player.cpp91
-rw-r--r--src/player.h10
-rw-r--r--src/resources/itemdb.cpp4
-rw-r--r--src/resources/iteminfo.cpp45
-rw-r--r--src/resources/iteminfo.h2
-rw-r--r--src/resources/resourcemanager.cpp7
-rw-r--r--src/resources/spritedef.cpp4
22 files changed, 146 insertions, 149 deletions
diff --git a/ChangeLog b/ChangeLog
index b9e8535e..6c480370 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -99,11 +99,22 @@
* src/resources/iteminfo.h, src/resources/itemdb.cpp: Removed unused
slot field.
+ * src/localplayer.cpp, src/localplayer.h: Removed specific type.
+ * src/gui/viewport.cpp, src/gui/minimap.cpp: Changed identification of
+ local player to a check of player_node.
+ * src/animatedsprite.cpp, src/animatedsprite.h, src/npc.cpp,
+ src/player.cpp, src/monster.cpp, src/resources/resourcemanager.cpp:
+ Prevented client from exiting on missing sprites.
+ * src/resources/spritedef.cpp: Added filename to fatal error messages.
+ * src/resources/iteminfo.cpp, src/resources/iteminfo.h,
+ src/resources/itemdb.cpp, data/items.xml: Merged weapon_type and
+ attacktype field.
2007-10-18 Philipp Sehmisch <tmw@crushnet.org>
* data/graphics/sprites/hairstyle7-male.png,
- data/graphics/sprites/hairstyle7-female.png; Readded hairstyle number 7.
+ data/graphics/sprites/hairstyle7-female.png: Readded hairstyle number
+ 7.
2007-10-18 Bjørn Lindeijer <bjorn@lindeijer.nl>
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index c1e89ff0..466779fd 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -54,20 +54,14 @@ AnimatedSprite::AnimatedSprite(SpriteDef *sprite):
play(ACTION_STAND);
}
-AnimatedSprite::AnimatedSprite(const std::string& filename, int variant):
- mDirection(DIRECTION_DOWN),
- mLastTime(0),
- mFrameIndex(0),
- mFrameTime(0),
- mAnimation(0),
- mFrame(0)
+AnimatedSprite *AnimatedSprite::load(const std::string& filename, int variant)
{
ResourceManager *resman = ResourceManager::getInstance();
- mSprite = resman->getSprite(filename, variant);
- assert(mSprite);
-
- // Play the stand animation by default
- play(ACTION_STAND);
+ SpriteDef *s = resman->getSprite(filename, variant);
+ if (!s) return NULL;
+ AnimatedSprite *as = new AnimatedSprite(s);
+ s->decRef();
+ return as;
}
AnimatedSprite::~AnimatedSprite()
diff --git a/src/animatedsprite.h b/src/animatedsprite.h
index d77d08f5..a1fbe7a0 100644
--- a/src/animatedsprite.h
+++ b/src/animatedsprite.h
@@ -46,13 +46,13 @@ class AnimatedSprite
AnimatedSprite(SpriteDef *sprite);
/**
- * A convenience constructor, which will request the sprite to animate
+ * An helper function, which will request the sprite to animate
* from the resource manager.
*
* @param filename the file of the sprite to animate
* @param variant the sprite variant
*/
- AnimatedSprite(const std::string& filename, int variant = 0);
+ static AnimatedSprite *load(std::string const &filename, int variant = 0);
/**
* Destructor.
diff --git a/src/being.cpp b/src/being.cpp
index bfd35e21..73c9ed62 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -44,7 +44,7 @@
int Being::instances = 0;
ImageSet *Being::emotionSet = NULL;
-Being::Being(Uint32 id, Uint16 job, Map *map):
+Being::Being(int id, int job, Map *map):
mJob(job),
mX(0), mY(0),
mAction(0),
@@ -58,7 +58,7 @@ Being::Being(Uint32 id, Uint16 job, Map *map):
mMap(NULL),
mEquippedWeapon(NULL),
mHairStyle(0), mHairColor(0),
- mSex(2),
+ mGender(2),
mSpeechTime(0),
mPx(0), mPy(0),
mSprites(VECTOREND_SPRITE, NULL),
@@ -147,7 +147,7 @@ Being::setHairStyle(Uint16 style)
}
void
-Being::setVisibleEquipment(Uint8 slot, int id)
+Being::setVisibleEquipment(int slot, int id)
{
mEquipmentSpriteIDs[slot] = id;
}
diff --git a/src/being.h b/src/being.h
index ff65bbef..6c123377 100644
--- a/src/being.h
+++ b/src/being.h
@@ -68,12 +68,14 @@ class Being : public Sprite
public:
enum Type {
UNKNOWN,
- LOCALPLAYER,
PLAYER,
NPC,
MONSTER
};
+ /**
+ * Action the being is currently performing.
+ */
enum Action {
STAND,
WALK,
@@ -123,7 +125,7 @@ class Being : public Sprite
/**
* Constructor.
*/
- Being(Uint32 id, Uint16 job, Map *map);
+ Being(int id, int job, Map *map);
/**
* Destructor.
@@ -175,7 +177,7 @@ class Being : public Sprite
/**
* Sets the name for the being.
*
- * @param text The name that should appear.
+ * @param name The name that should appear.
*/
void
setName(const std::string &name) { mName = name; }
@@ -208,19 +210,19 @@ class Being : public Sprite
* Sets visible equipments for this being.
*/
virtual void
- setVisibleEquipment(Uint8 slot, int id);
+ setVisibleEquipment(int slot, int id);
/**
- * Sets the sex for this being.
+ * Sets the gender of this being.
*/
virtual void
- setSex(Uint8 sex) { mSex = sex; }
+ setGender(int gender) { mGender = gender; }
/**
- * Gets the sex for this being.
+ * Gets the gender of this being.
*/
- Uint8
- getSex() const { return mSex; }
+ int
+ getGender() const { return mGender; }
/**
* Makes this being take the next step of his path.
@@ -308,7 +310,7 @@ class Being : public Sprite
* @see Sprite::draw(Graphics, int, int)
*/
virtual void
- draw(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) const;
+ draw(Graphics *graphics, int offsetX, int offsetY) const;
/**
* Returns the pixel X coordinate.
@@ -354,13 +356,13 @@ class Being : public Sprite
virtual Being::TargetCursorSize getTargetCursorSize() const
{ return TC_MEDIUM; }
- std::auto_ptr<Equipment> mEquipment;
-
/**
* Take control of a particle.
*/
void controlParticle(Particle *particle);
+ std::auto_ptr<Equipment> mEquipment;
+
protected:
/**
* Sets the new path for this being.
@@ -368,12 +370,6 @@ class Being : public Sprite
void setPath(const Path &path);
/**
- * Calculates the offset in the given directions.
- * If walking in direction 'neg' the value is negated.
- */
- int getOffset(char pos, char neg) const;
-
- /**
* Returns the sprite direction of this being.
*/
SpriteDirection getSpriteDirection() const;
@@ -391,7 +387,7 @@ class Being : public Sprite
Path mPath;
std::string mSpeech;
Uint16 mHairStyle, mHairColor;
- Uint8 mSex;
+ Uint8 mGender;
Uint32 mSpeechTime;
Sint32 mPx, mPy; /**< Pixel coordinates */
@@ -400,6 +396,12 @@ class Being : public Sprite
std::list<Particle *> mChildParticleEffects;
private:
+ /**
+ * Calculates the offset in the given directions.
+ * If walking in direction 'neg' the value is negated.
+ */
+ int getOffset(char pos, char neg) const;
+
static int instances; /**< Number of Being instances */
static ImageSet *emotionSet; /**< Emoticons used by beings */
};
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index fe260561..90dd53be 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -76,9 +76,9 @@ void CharDeleteConfirm::action(const gcn::ActionEvent &event)
CharSelectDialog::CharSelectDialog(Network *network,
LockedArray<LocalPlayer*> *charInfo,
- unsigned char sex):
+ unsigned char gender):
Window("Select Character"), mNetwork(network),
- mCharInfo(charInfo), mSex(sex), mCharSelected(false)
+ mCharInfo(charInfo), mGender(gender), mCharSelected(false)
{
mSelectButton = new Button("Ok", "ok", this);
mCancelButton = new Button("Cancel", "cancel", this);
@@ -153,7 +153,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
{
// Start new character dialog
CharCreateDialog *charCreateDialog =
- new CharCreateDialog(this, mCharInfo->getPos(), mNetwork, mSex);
+ new CharCreateDialog(this, mCharInfo->getPos(), mNetwork, mGender);
charServerHandler.setCharCreateDialog(charCreateDialog);
}
else if (event.getId() == "delete")
@@ -251,11 +251,11 @@ bool CharSelectDialog::selectByName(const std::string &name)
}
CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
- unsigned char sex):
+ unsigned char gender):
Window("Create Character", true, parent), mNetwork(network), mSlot(slot)
{
mPlayer = new Player(0, 0, NULL);
- mPlayer->setSex(sex);
+ mPlayer->setGender(gender);
mPlayer->setHairStyle(rand() % NR_HAIR_STYLES + 1);
mPlayer->setHairColor(rand() % NR_HAIR_COLORS + 1);
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index 00b1c51d..283ecf42 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -50,7 +50,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener
*/
CharSelectDialog(Network *network,
LockedArray<LocalPlayer*> *charInfo,
- unsigned char sex);
+ unsigned char gender);
void action(const gcn::ActionEvent &event);
@@ -78,7 +78,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener
PlayerBox *mPlayerBox;
- unsigned char mSex;
+ unsigned char mGender;
bool mCharSelected;
/**
@@ -104,7 +104,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener
* Constructor.
*/
CharCreateDialog(Window *parent, int slot, Network *network,
- unsigned char sex);
+ unsigned char gender);
/**
* Destructor.
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 2720225d..08560b840 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -26,6 +26,7 @@
#include "../being.h"
#include "../beingmanager.h"
#include "../graphics.h"
+#include "../localplayer.h"
#include "../resources/image.h"
@@ -82,15 +83,16 @@ void Minimap::draw(gcn::Graphics *graphics)
for (bi = beings.begin(); bi != beings.end(); bi++)
{
Being *being = (*bi);
- int dotSize = 1;
+ int dotSize = 2;
switch (being->getType()) {
- case Being::LOCALPLAYER:
- dotSize = 3;
- graphics->setColor(gcn::Color(209, 52, 61));
- break;
-
case Being::PLAYER:
+ if (being == player_node)
+ {
+ dotSize = 3;
+ graphics->setColor(gcn::Color(61, 209, 52));
+ break;
+ }
graphics->setColor(gcn::Color(61, 52, 209));
break;
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index a39db509..2c664176 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -369,7 +369,7 @@ Viewport::mousePressed(gcn::MouseEvent &event)
FloorItem *floorItem;
if ((being = beingManager->findBeing(tilex, tiley)) &&
- being->getType() != Being::LOCALPLAYER)
+ being != player_node)
{
mPopupMenu->showPopup(event.getX(), event.getY(), being);
return;
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 47ad5309..af047775 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -44,7 +44,7 @@ LocalPlayer *player_node = NULL;
LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
Player(id, job, map),
mAttackRange(0),
- mInventory(new Inventory()),
+ mInventory(new Inventory),
mXp(0),
mTarget(NULL), mPickUpTarget(NULL),
mTrading(false), mLastAction(-1)
@@ -106,11 +106,6 @@ void LocalPlayer::nextStep()
Player::nextStep();
}
-Being::Type LocalPlayer::getType() const
-{
- return LOCALPLAYER;
-}
-
void LocalPlayer::clearInventory()
{
mInventory->clear();
diff --git a/src/localplayer.h b/src/localplayer.h
index ab519185..21035378 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -72,8 +72,6 @@ class LocalPlayer : public Player
virtual void
drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) {};
- virtual Type getType() const;
-
void clearInventory();
void addInvItem(int id, int quantity, bool equipment);
void addInvItem(int index, int id, int quantity, bool equipment);
diff --git a/src/monster.cpp b/src/monster.cpp
index 230c72ad..40b36849 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -35,7 +35,7 @@
Monster::Monster(Uint32 id, Uint16 job, Map *map):
Being(id, job, map)
{
- mSprites[BASE_SPRITE] = new AnimatedSprite(
+ mSprites[BASE_SPRITE] = AnimatedSprite::load(
"graphics/sprites/" + MonsterDB::get(job - 1002).getSprite());
}
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp
index 2c643a16..74d1e2d1 100644
--- a/src/net/beinghandler.cpp
+++ b/src/net/beinghandler.cpp
@@ -131,7 +131,7 @@ void BeingHandler::handleMessage(MessageIn *msg)
msg->readInt16(); // manner
msg->readInt16(); // karma
msg->readInt8(); // unknown
- dstBeing->setSex(1 - msg->readInt8()); // sex
+ dstBeing->setGender(1 - msg->readInt8()); // gender
if (msg->getId() == SMSG_BEING_MOVE)
{
@@ -333,7 +333,7 @@ void BeingHandler::handleMessage(MessageIn *msg)
msg->readInt32(); // emblem
msg->readInt16(); // manner
msg->readInt8(); // karma
- dstBeing->setSex(1 - msg->readInt8()); // sex
+ dstBeing->setGender(1 - msg->readInt8()); // gender
dstBeing->setVisibleEquipment(
Being::BOTTOMCLOTHES_SPRITE, headBottom);
dstBeing->setVisibleEquipment(Being::HAT_SPRITE, headTop);
diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp
index a3f696c6..b25b0453 100644
--- a/src/net/charserverhandler.cpp
+++ b/src/net/charserverhandler.cpp
@@ -181,7 +181,7 @@ void CharServerHandler::handleMessage(MessageIn *msg)
LocalPlayer* CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
{
LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL);
- tempPlayer->setSex(1 - mLoginData->sex);
+ tempPlayer->setGender(1 - mLoginData->sex);
tempPlayer->mCharId = msg.readInt32();
tempPlayer->mTotalWeight = 0;
diff --git a/src/npc.cpp b/src/npc.cpp
index 8081770c..e490b3cf 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -36,7 +36,7 @@ NPC *current_npc = 0;
NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
Being(id, job, map), mNetwork(network)
{
- mSprites[BASE_SPRITE] = new AnimatedSprite("graphics/sprites/npc.xml",
+ mSprites[BASE_SPRITE] = AnimatedSprite::load("graphics/sprites/npc.xml",
job - 100);
}
diff --git a/src/player.cpp b/src/player.cpp
index 143bfc23..483bb726 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -26,6 +26,7 @@
#include "animatedsprite.h"
#include "game.h"
#include "graphics.h"
+#include "log.h"
#include "resources/itemdb.h"
#include "resources/iteminfo.h"
@@ -34,7 +35,7 @@
#include "gui/gui.h"
-Player::Player(Uint32 id, Uint16 job, Map *map):
+Player::Player(int id, int job, Map *map):
Being(id, job, map)
{
}
@@ -84,23 +85,30 @@ Player::drawName(Graphics *graphics, int offsetX, int offsetY)
graphics->drawText(mName, px + 15, py + 30, gcn::Graphics::CENTER);
}
-void
-Player::setSex(Uint8 sex)
+void Player::setGender(int gender)
{
- if (sex != mSex)
+ // Players can only be male or female
+ if (gender > 1)
+ {
+ logger->log("Warning: unsupported gender %i, assuming male.", gender);
+ gender = 0;
+ }
+
+ if (gender != mGender)
{
// Reload base sprite
AnimatedSprite *newBaseSprite;
- if (sex == 0)
+ if (gender == 0)
{
- newBaseSprite = new AnimatedSprite(
+ newBaseSprite = AnimatedSprite::load(
"graphics/sprites/player_male_base.xml");
}
else
{
- newBaseSprite = new AnimatedSprite(
+ newBaseSprite = AnimatedSprite::load(
"graphics/sprites/player_female_base.xml");
}
+
delete mSprites[BASE_SPRITE];
mSprites[BASE_SPRITE] = newBaseSprite;
@@ -109,34 +117,30 @@ Player::setSex(Uint8 sex)
{
if (i != HAIR_SPRITE && mEquipmentSpriteIDs.at(i) != 0)
{
- AnimatedSprite *newEqSprite = new AnimatedSprite(
+ AnimatedSprite *newEqSprite = AnimatedSprite::load(
"graphics/sprites/" + ItemDB::get(
- mEquipmentSpriteIDs.at(i)).getSprite(sex));
+ mEquipmentSpriteIDs.at(i)).getSprite(gender));
delete mSprites[i];
mSprites[i] = newEqSprite;
}
}
}
- Being::setSex(sex);
+ Being::setGender(gender);
}
-void
-Player::setHairColor(Uint16 color)
+void Player::setHairColor(int color)
{
if (color != mHairColor && mHairStyle > 0)
{
- std::string sex;
- if (mSex == 0)
- {
- sex = "-male";
- } else{
- sex = "-female";
- }
- AnimatedSprite *newHairSprite = new AnimatedSprite(
- "graphics/sprites/hairstyle" + toString(mHairStyle) + sex + ".xml",
- color - 1);
- newHairSprite->setDirection(getSpriteDirection());
+ const std::string hairStyle = toString(getHairStyle());
+ const std::string gender = (mGender == 0) ? "-male" : "-female";
+
+ AnimatedSprite *newHairSprite = AnimatedSprite::load(
+ "graphics/sprites/hairstyle" + hairStyle + gender + ".xml",
+ color - 1);
+ if (newHairSprite)
+ newHairSprite->setDirection(getSpriteDirection());
delete mSprites[HAIR_SPRITE];
mSprites[HAIR_SPRITE] = newHairSprite;
@@ -147,22 +151,18 @@ Player::setHairColor(Uint16 color)
Being::setHairColor(color);
}
-void
-Player::setHairStyle(Uint16 style)
+void Player::setHairStyle(int style)
{
if (style != mHairStyle && mHairColor > 0)
{
- std::string sex;
- if (mSex == 0)
- {
- sex = "-male";
- } else{
- sex = "-female";
- }
- AnimatedSprite *newHairSprite = new AnimatedSprite(
- "graphics/sprites/hairstyle" + toString(style) + sex + ".xml",
- mHairColor - 1);
- newHairSprite->setDirection(getSpriteDirection());
+ const std::string hairStyle = toString(style);
+ const std::string gender = (mGender == 0) ? "-male" : "-female";
+
+ AnimatedSprite *newHairSprite = AnimatedSprite::load(
+ "graphics/sprites/hairstyle" + hairStyle + gender + ".xml",
+ mHairColor - 1);
+ if (newHairSprite)
+ newHairSprite->setDirection(getSpriteDirection());
delete mSprites[HAIR_SPRITE];
mSprites[HAIR_SPRITE] = newHairSprite;
@@ -173,8 +173,7 @@ Player::setHairStyle(Uint16 style)
Being::setHairStyle(style);
}
-void
-Player::setVisibleEquipment(Uint8 slot, int id)
+void Player::setVisibleEquipment(int slot, int id)
{
// id = 0 means unequip
if (id == 0)
@@ -184,19 +183,11 @@ Player::setVisibleEquipment(Uint8 slot, int id)
}
else
{
- AnimatedSprite *equipmentSprite;
-
- if (mSex == 0)
- {
- equipmentSprite = new AnimatedSprite(
- "graphics/sprites/" + ItemDB::get(id).getSprite(0));
- }
- else {
- equipmentSprite = new AnimatedSprite(
- "graphics/sprites/" + ItemDB::get(id).getSprite(1));
- }
+ AnimatedSprite *equipmentSprite = AnimatedSprite::load(
+ "graphics/sprites/" + ItemDB::get(id).getSprite(mGender));
- equipmentSprite->setDirection(getSpriteDirection());
+ if (equipmentSprite)
+ equipmentSprite->setDirection(getSpriteDirection());
delete mSprites[slot];
mSprites[slot] = equipmentSprite;
diff --git a/src/player.h b/src/player.h
index a6bd557c..742ca465 100644
--- a/src/player.h
+++ b/src/player.h
@@ -37,7 +37,7 @@ class Map;
class Player : public Being
{
public:
- Player(Uint32 id, Uint16 job, Map *map);
+ Player(int id, int job, Map *map);
virtual void
logic();
@@ -49,16 +49,16 @@ class Player : public Being
drawName(Graphics *graphics, int offsetX, int offsetY);
virtual void
- setSex(Uint8 sex);
+ setGender(int gender);
virtual void
- setHairColor(Uint16 color);
+ setHairColor(int color);
virtual void
- setHairStyle(Uint16 style);
+ setHairStyle(int style);
virtual void
- setVisibleEquipment(Uint8 slot, int id);
+ setVisibleEquipment(int slot, int id);
};
#endif
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 636763fc..fb95a521 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -106,7 +106,7 @@ void ItemDB::load()
std::string image = XML::getProperty(node, "image", "");
std::string description = XML::getProperty(node, "description", "");
std::string effect = XML::getProperty(node, "effect", "");
- std::string attackType = XML::getProperty(node, "attacktype", "");
+ int weaponType = XML::getProperty(node, "weapon_type", 0);
if (id)
{
@@ -118,7 +118,7 @@ void ItemDB::load()
itemInfo->setType(type);
itemInfo->setView(view);
itemInfo->setWeight(weight);
- itemInfo->setAttackType(attackType);
+ itemInfo->setWeaponType(weaponType);
for_each_xml_child_node(itemChild, node)
{
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 3b32ec71..82c46e3c 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -71,32 +71,29 @@ ItemInfo::getSprite(int gender) const
}
}
-void
-ItemInfo::setAttackType(const std::string &attackType)
+void ItemInfo::setWeaponType(int type)
{
- if (attackType == "swing")
- {
- mAttackType = ACTION_ATTACK_SWING;
- }
- else if (attackType == "stab")
- {
- mAttackType = ACTION_ATTACK_STAB;
- }
- else if (attackType == "bow")
- {
- mAttackType = ACTION_ATTACK_BOW;
- }
- else if (attackType == "throw")
- {
- mAttackType = ACTION_ATTACK_THROW;
- }
- else if (attackType == "none")
- {
- mAttackType = ACTION_DEFAULT;
- }
- else
+ // See server item.hpp file for type values.
+ switch (type)
{
- mAttackType = ACTION_ATTACK;
+ case 0: // none
+ mAttackType = ACTION_DEFAULT;
+ break;
+ case 1: // knife
+ case 2: // sword
+ mAttackType = ACTION_ATTACK_STAB;
+ break;
+ case 8: // projectile
+ mAttackType = ACTION_ATTACK_THROW;
+ break;
+ case 10: // bow
+ mAttackType = ACTION_ATTACK_BOW;
+ break;
+ case 11: // sickle
+ mAttackType = ACTION_ATTACK_SWING;
+ break;
+ default:
+ mAttackType = ACTION_ATTACK;
}
}
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index b016f27b..b6fc922c 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -105,7 +105,7 @@ class ItemInfo
const std::string& getSprite(int gender) const;
- void setAttackType(const std::string &attackType);
+ void setWeaponType(int);
const SpriteAction getAttackType() const
{ return mAttackType; }
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 448e7f80..5e3f3bc7 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -275,6 +275,13 @@ ResourceManager::getSprite(const std::string &path, int variant)
return dynamic_cast<SpriteDef*>(resIter->second);
}
+ // FIXME: modify SpriteDef so that it gracefully fails on missing sprite.
+ if (!exists(path) || isDirectory(path))
+ {
+ logger->log("Failed to load file: %s", path.c_str());
+ return NULL;
+ }
+
SpriteDef *sprite = new SpriteDef(idPath, path, variant);
sprite->incRef();
mResources[idPath] = sprite;
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 1e7c102d..6eb2365b 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -75,13 +75,13 @@ SpriteDef::load(const std::string &animationFile, int variant)
if (!doc) {
logger->error(
- "Animation: Error while parsing animation definition file!");
+ "Animation: Error while parsing " + animationFile + " file!");
}
xmlNodePtr rootNode = xmlDocGetRootElement(doc);
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite")) {
logger->error(
- "Animation: this is not a valid animation definition file!");
+ "Animation: this is not a valid " + animationFile + " file!");
}
// Get the variant