summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-07-29 20:20:51 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-07-29 20:20:51 +0200
commitae898aa1a5175b2b08f7248e4cd89bf61bc8e4be (patch)
tree041646a78229772ae7bb55222659fc4826325c43 /src
parent2b1c0dcf269d617de1f6c203df547166661f089e (diff)
downloadmana-ae898aa1a5175b2b08f7248e4cd89bf61bc8e4be.tar.gz
mana-ae898aa1a5175b2b08f7248e4cd89bf61bc8e4be.tar.bz2
mana-ae898aa1a5175b2b08f7248e4cd89bf61bc8e4be.tar.xz
mana-ae898aa1a5175b2b08f7248e4cd89bf61bc8e4be.zip
Changed the items loading to handle a new 'attack-action' parameter.
The old behaviour was to load the weapon-type value and do many unnecessary checks and transformation on it: The weapon-type was transformed using hard-coded values into an integer enum value. The exact same thing was done on the opposite side in the animation files before comparing the two. As both data were string values, I simplified all of it by using the value taken in items.xml to call the corresponding action. This now also permit to set up new attack animation in items.xml and in the playerset.xml without having the need to modify the client code. Last but not least, the weapon-type value was used by both the skills and the actions and avoided the possibility to set up a definite action for a weapon-type. Note: The weapon-type parameter will become deprecated for the server in favor of a 'skill' parameter to reflect more it's actual use. This patch is the first step to fix Manasource issue: #157.
Diffstat (limited to 'src')
-rw-r--r--src/animatedsprite.cpp6
-rw-r--r--src/animatedsprite.h2
-rw-r--r--src/being.cpp40
-rw-r--r--src/being.h2
-rw-r--r--src/compoundsprite.cpp2
-rw-r--r--src/compoundsprite.h2
-rw-r--r--src/gui/skilldialog.h4
-rw-r--r--src/imagesprite.h2
-rw-r--r--src/localplayer.cpp8
-rw-r--r--src/net/tmwa/beinghandler.cpp2
-rw-r--r--src/resources/beinginfo.cpp4
-rw-r--r--src/resources/beinginfo.h6
-rw-r--r--src/resources/itemdb.cpp22
-rw-r--r--src/resources/iteminfo.cpp28
-rw-r--r--src/resources/iteminfo.h34
-rw-r--r--src/resources/monsterdb.cpp5
-rw-r--r--src/resources/spritedef.cpp117
-rw-r--r--src/resources/spritedef.h41
-rw-r--r--src/sprite.h2
-rw-r--r--src/statuseffect.cpp8
-rw-r--r--src/statuseffect.h4
21 files changed, 128 insertions, 213 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 9ddc001c..ec666d80 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -51,7 +51,7 @@ AnimatedSprite::AnimatedSprite(SpriteDef *sprite):
mSprite->incRef();
// Play the stand animation by default
- play(ACTION_STAND);
+ play(SpriteAction::STAND);
}
AnimatedSprite *AnimatedSprite::load(const std::string &filename, int variant)
@@ -81,7 +81,7 @@ bool AnimatedSprite::reset()
return ret;
}
-bool AnimatedSprite::play(SpriteAction spriteAction)
+bool AnimatedSprite::play(std::string spriteAction)
{
Action *action = mSprite->getAction(spriteAction);
if (!action)
@@ -122,7 +122,7 @@ bool AnimatedSprite::update(int time)
if (!updateCurrentAnimation(dt))
{
// Animation finished, reset to default
- play(ACTION_STAND);
+ play(SpriteAction::STAND);
}
// Make sure something actually changed
diff --git a/src/animatedsprite.h b/src/animatedsprite.h
index 67e9c7cb..bd39c267 100644
--- a/src/animatedsprite.h
+++ b/src/animatedsprite.h
@@ -56,7 +56,7 @@ class AnimatedSprite : public Sprite
bool reset();
- bool play(SpriteAction action);
+ bool play(std::string action);
bool update(int time);
diff --git a/src/being.cpp b/src/being.cpp
index 70ef55f9..e8007948 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -249,7 +249,7 @@ void Being::setPath(const Path &path)
mPath = path;
if ((Net::getNetworkType() == ServerInfo::TMWATHENA) &&
- mAction != WALK && mAction != DEAD)
+ mAction != MOVE && mAction != DEAD)
{
nextTile();
mActionTime = tick_time;
@@ -550,20 +550,23 @@ void Being::fireMissile(Being *victim, const std::string &particle)
void Being::setAction(Action action, int attackType)
{
- SpriteAction currentAction = ACTION_INVALID;
+ std::string currentAction = SpriteAction::INVALID;
switch (action)
{
- case WALK:
- currentAction = ACTION_WALK;
+ case MOVE:
+ currentAction = SpriteAction::MOVE;
+ // Note: When adding a run action,
+ // Differentiate walk and run with action name,
+ // while using only the ACTION_MOVE.
break;
case SIT:
- currentAction = ACTION_SIT;
+ currentAction = SpriteAction::SIT;
break;
case ATTACK:
if (mEquippedWeapon)
{
- currentAction = mEquippedWeapon->getWeaponAttackType();
+ currentAction = mEquippedWeapon->getAttackAction();
reset();
}
else
@@ -598,26 +601,27 @@ void Being::setAction(Action action, int attackType)
break;
case HURT:
- //currentAction = ACTION_HURT; // Buggy: makes the player stop
+ //currentAction = SpriteAction::HURT;// Buggy: makes the player stop
// attacking and unable to attack
- // again until he moves
+ // again until he moves.
+ // TODO: fix this!
break;
case DEAD:
- currentAction = ACTION_DEAD;
+ currentAction = SpriteAction::DEAD;
sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE));
break;
case STAND:
- currentAction = ACTION_STAND;
+ currentAction = SpriteAction::STAND;
break;
}
- if (currentAction != ACTION_INVALID)
+ if (currentAction != SpriteAction::INVALID)
{
play(currentAction);
mAction = action;
}
- if (currentAction != ACTION_WALK)
+ if (currentAction != SpriteAction::MOVE)
mActionTime = tick_time;
}
@@ -679,7 +683,7 @@ void Being::nextTile()
mX = pos.x;
mY = pos.y;
- setAction(WALK);
+ setAction(MOVE);
mActionTime += (int)(mWalkSpeed.x / 10);
}
@@ -743,8 +747,8 @@ void Being::logic()
else
setPosition(mPos + diff);
- if (mAction != WALK)
- setAction(WALK);
+ if (mAction != MOVE)
+ setAction(MOVE);
// Update the player sprite direction.
// N.B.: We only change this if the distance is more than one pixel.
@@ -773,7 +777,7 @@ void Being::logic()
// remove it and go to the next one.
mPath.pop_front();
}
- else if (mAction == WALK)
+ else if (mAction == MOVE)
{
setAction(STAND);
}
@@ -790,7 +794,7 @@ void Being::logic()
case HURT:
break;
- case WALK:
+ case MOVE:
if ((int) ((get_elapsed_time(mActionTime) * frameCount)
/ getWalkSpeed().x) >= frameCount)
nextTile();
@@ -941,7 +945,7 @@ void Being::drawSpeech(int offsetX, int offsetY)
int Being::getOffset(char pos, char neg) const
{
// Check whether we're walking in the requested direction
- if (mAction != WALK || !(mDirection & (pos | neg)))
+ if (mAction != MOVE || !(mDirection & (pos | neg)))
return 0;
int offset = 0;
diff --git a/src/being.h b/src/being.h
index f06fd2bc..07826a11 100644
--- a/src/being.h
+++ b/src/being.h
@@ -73,7 +73,7 @@ class Being : public ActorSprite, public ConfigListener
enum Action
{
STAND,
- WALK,
+ MOVE,
ATTACK,
SIT,
DEAD,
diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp
index d1c6cd57..293e170c 100644
--- a/src/compoundsprite.cpp
+++ b/src/compoundsprite.cpp
@@ -67,7 +67,7 @@ bool CompoundSprite::reset()
return ret;
}
-bool CompoundSprite::play(SpriteAction action)
+bool CompoundSprite::play(std::string action)
{
bool ret = false;
diff --git a/src/compoundsprite.h b/src/compoundsprite.h
index 38c38453..3b443219 100644
--- a/src/compoundsprite.h
+++ b/src/compoundsprite.h
@@ -36,7 +36,7 @@ public:
virtual bool reset();
- virtual bool play(SpriteAction action);
+ virtual bool play(std::string action);
virtual bool update(int time);
diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h
index 95f8ef25..764f9d51 100644
--- a/src/gui/skilldialog.h
+++ b/src/gui/skilldialog.h
@@ -19,8 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef SKILL_H
-#define SKILL_H
+#ifndef SKILLDIALOG_H
+#define SKILLDIALOG_H
#include "guichanfwd.h"
diff --git a/src/imagesprite.h b/src/imagesprite.h
index 8a195b8c..3a3678d9 100644
--- a/src/imagesprite.h
+++ b/src/imagesprite.h
@@ -37,7 +37,7 @@ public:
bool reset()
{ return false; }
- bool play(SpriteAction action)
+ bool play(std::string action)
{ return false; }
bool update(int time)
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 339ba42e..97694b7c 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -776,11 +776,11 @@ void LocalPlayer::setWalkingDir(int dir)
mWalkingDir = dir;
// If we're not already walking, start walking.
- if (mAction != WALK && dir)
+ if (mAction != MOVE && dir)
{
startWalking(dir);
}
- else if (mAction == WALK && (Net::getNetworkType() == ServerInfo::MANASERV))
+ else if (mAction == MOVE && (Net::getNetworkType() == ServerInfo::MANASERV))
{
nextTile(dir);
}
@@ -793,7 +793,7 @@ void LocalPlayer::startWalking(unsigned char dir)
if (!mMap || !dir)
return;
- if (mAction == WALK && !mPath.empty())
+ if (mAction == MOVE && !mPath.empty())
{
// Just finish the current action, otherwise we get out of sync
if (Net::getNetworkType() == ServerInfo::MANASERV)
@@ -848,7 +848,7 @@ void LocalPlayer::startWalking(unsigned char dir)
void LocalPlayer::stopWalking(bool sendToServer)
{
- if (mAction == WALK && mWalkingDir)
+ if (mAction == MOVE && mWalkingDir)
{
mWalkingDir = 0;
mLocalWalkTime = 0;
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp
index 8e6d81b3..543beec2 100644
--- a/src/net/tmwa/beinghandler.cpp
+++ b/src/net/tmwa/beinghandler.cpp
@@ -641,7 +641,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
x = msg.readInt16();
y = msg.readInt16();
dstBeing->setTileCoords(x, y);
- if (dstBeing->getCurrentAction() == Being::WALK)
+ if (dstBeing->getCurrentAction() == Being::MOVE)
dstBeing->setAction(Being::STAND);
}
}
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index c9447283..e8824391 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -90,13 +90,13 @@ const std::string &BeingInfo::getSound(SoundEvent event) const
const Attack *BeingInfo::getAttack(int type) const
{
- static Attack *empty = new Attack(ACTION_ATTACK, "", "");
+ static Attack *empty = new Attack(SpriteAction::ATTACK, "", "");
Attacks::const_iterator i = mAttacks.find(type);
return (i == mAttacks.end()) ? empty : (*i).second;
}
-void BeingInfo::addAttack(int id, SpriteAction action,
+void BeingInfo::addAttack(int id, std::string action,
const std::string &particleEffect,
const std::string &missileParticle)
{
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index 8485ac6c..52390976 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -32,11 +32,11 @@
#include <vector>
struct Attack {
- SpriteAction action;
+ std::string action;
std::string particleEffect;
std::string missileParticle;
- Attack(SpriteAction action, std::string particleEffect,
+ Attack(std::string action, std::string particleEffect,
std::string missileParticle)
{
this->action = action;
@@ -95,7 +95,7 @@ class BeingInfo
const std::string &getSound(SoundEvent event) const;
- void addAttack(int id, SpriteAction action,
+ void addAttack(int id, std::string action,
const std::string &particleEffect,
const std::string &missileParticle);
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index cbccc4cd..a8eed123 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -85,22 +85,6 @@ static ItemType itemTypeFromString(const std::string &name, int id = 0)
else return ITEM_UNUSABLE;
}
-static WeaponType weaponTypeFromString(const std::string &name)
-{
- if (name=="knife") return WPNTYPE_KNIFE;
- else if (name=="sword") return WPNTYPE_SWORD;
- else if (name=="polearm") return WPNTYPE_POLEARM;
- else if (name=="staff") return WPNTYPE_STAFF;
- else if (name=="whip") return WPNTYPE_WHIP;
- else if (name=="bow") return WPNTYPE_BOW;
- else if (name=="shooting") return WPNTYPE_SHOOTING;
- else if (name=="mace") return WPNTYPE_MACE;
- else if (name=="axe") return WPNTYPE_AXE;
- else if (name=="thrown") return WPNTYPE_THROWN;
-
- else return WPNTYPE_NONE;
-}
-
static std::string normalized(const std::string &name)
{
std::string normalized = name;
@@ -153,7 +137,7 @@ void ItemDB::load()
std::string name = XML::getProperty(node, "name", "");
std::string image = XML::getProperty(node, "image", "");
std::string description = XML::getProperty(node, "description", "");
- int weaponType = weaponTypeFromString(XML::getProperty(node, "weapon-type", ""));
+ std::string attackAction = XML::getProperty(node, "attack-action", "");
int attackRange = XML::getProperty(node, "attack-range", 0);
std::string missileParticle = XML::getProperty(node, "missile-particle", "");
@@ -167,7 +151,7 @@ void ItemDB::load()
itemInfo->setType(itemTypeFromString(typeStr));
itemInfo->setView(view);
itemInfo->setWeight(weight);
- itemInfo->setWeaponType(weaponType);
+ itemInfo->setAttackAction(attackAction);
itemInfo->setAttackRange(attackRange);
itemInfo->setMissileParticle(missileParticle);
@@ -231,7 +215,7 @@ void ItemDB::load()
}
}
- if (weaponType > 0)
+ if (!attackAction.empty())
if (attackRange == 0)
logger->log("ItemDB: Missing attack range from weapon %i!", id);
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 9c275f96..1cd3c546 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -41,30 +41,12 @@ const std::string &ItemInfo::getSprite(Gender gender) const
}
}
-void ItemInfo::setWeaponType(int type)
+void ItemInfo::setAttackAction(std::string attackAction)
{
- // See server item.hpp file for type values.
- switch (type)
- {
- case WPNTYPE_NONE:
- mWeaponAttackType = ACTION_DEFAULT;
- break;
- case WPNTYPE_KNIFE:
- case WPNTYPE_SWORD:
- mWeaponAttackType = ACTION_ATTACK_STAB;
- break;
- case WPNTYPE_THROWN:
- mWeaponAttackType = ACTION_ATTACK_THROW;
- break;
- case WPNTYPE_BOW:
- mWeaponAttackType = ACTION_ATTACK_BOW;
- break;
- case WPNTYPE_POLEARM:
- mWeaponAttackType = ACTION_ATTACK_SWING;
- break;
- default:
- mWeaponAttackType = ACTION_ATTACK;
- }
+ if (attackAction.empty())
+ mAttackAction = SpriteAction::ATTACK; // (Equal to unarmed animation)
+ else
+ mAttackAction = attackAction;
}
void ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename)
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index 1f27ae66..ac747e33 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -90,24 +90,6 @@ enum ItemType
};
/**
- * Enumeration of available weapon's types.
- */
-enum WeaponType
-{
- WPNTYPE_NONE = 0,
- WPNTYPE_KNIFE,
- WPNTYPE_SWORD,
- WPNTYPE_POLEARM,
- WPNTYPE_STAFF,
- WPNTYPE_WHIP,
- WPNTYPE_BOW,
- WPNTYPE_SHOOTING,
- WPNTYPE_MACE,
- WPNTYPE_AXE,
- WPNTYPE_THROWN
-};
-
-/**
* Defines a class for storing item infos. This includes information used when
* the item is equipped.
*/
@@ -122,7 +104,7 @@ class ItemInfo
mWeight(0),
mView(0),
mId(0),
- mWeaponAttackType(ACTION_DEFAULT)
+ mAttackAction(SpriteAction::INVALID)
{
}
@@ -180,15 +162,15 @@ class ItemInfo
const std::string &getSprite(Gender gender) const;
- void setWeaponType(int);
+ void setAttackAction(std::string attackAction);
// Handlers for seting and getting the string used for particles when attacking
void setMissileParticle(std::string s) { mMissileParticle = s; }
std::string getMissileParticle() const { return mMissileParticle; }
- SpriteAction getWeaponAttackType() const
- { return mWeaponAttackType; }
+ std::string getAttackAction() const
+ { return mAttackAction; }
int getAttackRange() const
{ return mAttackRange; }
@@ -211,8 +193,12 @@ class ItemInfo
int mView; /**< Item ID of how this item looks. */
int mId; /**< Item ID */
- // Equipment related members
- SpriteAction mWeaponAttackType; /**< Attack type, in case of weapon. */
+ // Equipment related members.
+ /** Attack type, in case of weapon.
+ * See SpriteAction in spritedef.h for more info.
+ * Attack action sub-types (bow, sword, ...) are defined in items.xml.
+ */
+ std::string mAttackAction;
int mAttackRange; /**< Attack range, will be zero if non weapon. */
// Particle to be shown when weapon attacks
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index ed062acf..6bc64a89 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -126,8 +126,9 @@ void MonsterDB::load()
const int id = XML::getProperty(spriteNode, "id", 0);
const std::string particleEffect = XML::getProperty(
spriteNode, "particle-effect", "");
- SpriteAction spriteAction = SpriteDef::makeSpriteAction(
- XML::getProperty(spriteNode, "action", "attack"));
+ const std::string spriteAction = XML::getProperty(spriteNode,
+ "action",
+ "attack");
const std::string missileParticle = XML::getProperty(
spriteNode, "missile-particle", "");
currentInfo->addAttack(id, spriteAction,
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 32fb5757..97c9ab48 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -39,13 +39,13 @@
SpriteReference *SpriteReference::Empty = new SpriteReference(
paths.getStringValue("spriteErrorFile"), 0);
-Action *SpriteDef::getAction(SpriteAction action) const
+Action *SpriteDef::getAction(std::string action) const
{
Actions::const_iterator i = mActions.find(action);
if (i == mActions.end())
{
- logger->log("Warning: no action \"%u\" defined!", action);
+ logger->log("Warning: no action \"%s\" defined!", action.c_str());
return NULL;
}
@@ -84,22 +84,29 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant)
return def;
}
+void SpriteDef::substituteAction(std::string complete, std::string with)
+{
+ if (mActions.find(complete) == mActions.end())
+ {
+ Actions::iterator i = mActions.find(with);
+ if (i != mActions.end())
+ {
+ mActions[complete] = i->second;
+ }
+ }
+}
+
void SpriteDef::substituteActions()
{
- substituteAction(ACTION_STAND, ACTION_DEFAULT);
- substituteAction(ACTION_WALK, ACTION_STAND);
- substituteAction(ACTION_WALK, ACTION_RUN);
- substituteAction(ACTION_ATTACK, ACTION_STAND);
- substituteAction(ACTION_ATTACK_SWING, ACTION_ATTACK);
- substituteAction(ACTION_ATTACK_STAB, ACTION_ATTACK_SWING);
- substituteAction(ACTION_ATTACK_BOW, ACTION_ATTACK_STAB);
- substituteAction(ACTION_ATTACK_THROW, ACTION_ATTACK_SWING);
- substituteAction(ACTION_CAST_MAGIC, ACTION_ATTACK_SWING);
- substituteAction(ACTION_USE_ITEM, ACTION_CAST_MAGIC);
- substituteAction(ACTION_SIT, ACTION_STAND);
- substituteAction(ACTION_SLEEP, ACTION_SIT);
- substituteAction(ACTION_HURT, ACTION_STAND);
- substituteAction(ACTION_DEAD, ACTION_HURT);
+ substituteAction(SpriteAction::STAND, SpriteAction::DEFAULT);
+ substituteAction(SpriteAction::MOVE, SpriteAction::STAND);
+ substituteAction(SpriteAction::ATTACK, SpriteAction::STAND);
+ substituteAction(SpriteAction::CAST_MAGIC, SpriteAction::ATTACK);
+ substituteAction(SpriteAction::USE_ITEM, SpriteAction::CAST_MAGIC);
+ substituteAction(SpriteAction::SIT, SpriteAction::STAND);
+ substituteAction(SpriteAction::SLEEP, SpriteAction::SIT);
+ substituteAction(SpriteAction::HURT, SpriteAction::STAND);
+ substituteAction(SpriteAction::DEAD, SpriteAction::HURT);
}
void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant,
@@ -171,20 +178,19 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset)
}
ImageSet *imageSet = si->second;
- SpriteAction actionType = makeSpriteAction(actionName);
- if (actionType == ACTION_INVALID)
+ if (actionName == SpriteAction::INVALID)
{
logger->log("Warning: Unknown action \"%s\" defined in %s",
actionName.c_str(), getIdPath().c_str());
return;
}
Action *action = new Action;
- mActions[actionType] = action;
+ mActions[actionName] = action;
// When first action set it as default direction
- if (mActions.empty())
+ if (mActions.size() == 1)
{
- mActions[ACTION_DEFAULT] = action;
+ mActions[SpriteAction::DEFAULT] = action;
}
// Load animations
@@ -297,18 +303,6 @@ void SpriteDef::includeSprite(xmlNodePtr includeNode)
loadSprite(rootNode, 0);
}
-void SpriteDef::substituteAction(SpriteAction complete, SpriteAction with)
-{
- if (mActions.find(complete) == mActions.end())
- {
- Actions::iterator i = mActions.find(with);
- if (i != mActions.end())
- {
- mActions[complete] = i->second;
- }
- }
-}
-
SpriteDef::~SpriteDef()
{
// Actions are shared, so ensure they are deleted only once.
@@ -332,63 +326,6 @@ SpriteDef::~SpriteDef()
}
}
-SpriteAction SpriteDef::makeSpriteAction(const std::string &action)
-{
- if (action.empty() || action == "default")
- return ACTION_DEFAULT;
-
- if (action == "stand")
- return ACTION_STAND;
- else if (action == "walk")
- return ACTION_WALK;
- else if (action == "run")
- return ACTION_RUN;
- else if (action == "attack")
- return ACTION_ATTACK;
- else if (action == "attack_swing")
- return ACTION_ATTACK_SWING;
- else if (action == "attack_stab")
- return ACTION_ATTACK_STAB;
- else if (action == "attack_bow")
- return ACTION_ATTACK_BOW;
- else if (action == "attack_throw")
- return ACTION_ATTACK_THROW;
- else if (action == "special0")
- return ACTION_SPECIAL_0;
- else if (action == "special1")
- return ACTION_SPECIAL_1;
- else if (action == "special2")
- return ACTION_SPECIAL_2;
- else if (action == "special3")
- return ACTION_SPECIAL_3;
- else if (action == "special4")
- return ACTION_SPECIAL_4;
- else if (action == "special5")
- return ACTION_SPECIAL_5;
- else if (action == "special6")
- return ACTION_SPECIAL_6;
- else if (action == "special7")
- return ACTION_SPECIAL_7;
- else if (action == "special8")
- return ACTION_SPECIAL_8;
- else if (action == "special9")
- return ACTION_SPECIAL_9;
- else if (action == "cast_magic")
- return ACTION_CAST_MAGIC;
- else if (action == "use_item")
- return ACTION_USE_ITEM;
- else if (action == "sit")
- return ACTION_SIT;
- else if (action == "sleep")
- return ACTION_SLEEP;
- else if (action == "hurt")
- return ACTION_HURT;
- else if (action == "dead")
- return ACTION_DEAD;
- else
- return ACTION_INVALID;
-}
-
SpriteDirection SpriteDef::makeSpriteDirection(const std::string &direction)
{
if (direction.empty() || direction == "default")
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index bc9ae45f..16b8c0c8 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -54,7 +54,7 @@ struct SpriteDisplay
};
typedef std::list<SpriteReference*>::const_iterator SpriteRefs;
-
+#if 0
enum SpriteAction
{
ACTION_DEFAULT = 0,
@@ -84,7 +84,33 @@ enum SpriteAction
ACTION_DEAD,
ACTION_INVALID
};
-
+#endif
+#if 1 // Aim to be reached
+/*
+ * Remember those are the main action.
+ * Action subtypes, e.g.: "attack_bow" are to be passed by items.xml after
+ * an ACTION_ATTACK call.
+ * Which special to be use to to be passed with the USE_SPECIAL call.
+ * Running, walking, ... is a sub-type of moving.
+ * ...
+ * Please don't add hard-coded subtypes here!
+ */
+namespace SpriteAction
+{
+ static const std::string DEFAULT = "stand";
+ static const std::string STAND = "stand";
+ static const std::string SIT = "sit";
+ static const std::string SLEEP = "sleep";
+ static const std::string DEAD = "dead";
+ static const std::string MOVE = "walk";
+ static const std::string ATTACK = "attack";
+ static const std::string HURT = "hurt";
+ static const std::string USE_SPECIAL = "special";
+ static const std::string CAST_MAGIC = "magic";
+ static const std::string USE_ITEM = "item";
+ static const std::string INVALID = "";
+};
+#endif
enum SpriteDirection
{
DIRECTION_DEFAULT = 0,
@@ -109,12 +135,7 @@ class SpriteDef : public Resource
/**
* Returns the specified action.
*/
- Action *getAction(SpriteAction action) const;
-
- /**
- * Converts a string into a SpriteAction enum.
- */
- static SpriteAction makeSpriteAction(const std::string &action);
+ Action *getAction(std::string action) const;
/**
* Converts a string into a SpriteDirection enum.
@@ -170,12 +191,12 @@ class SpriteDef : public Resource
* When there are no animations defined for the action "complete", its
* animations become a copy of those of the action "with".
*/
- void substituteAction(SpriteAction complete, SpriteAction with);
+ void substituteAction(std::string complete, std::string with);
typedef std::map<std::string, ImageSet*> ImageSets;
typedef ImageSets::iterator ImageSetIterator;
- typedef std::map<SpriteAction, Action*> Actions;
+ typedef std::map<std::string, Action*> Actions;
ImageSets mImageSets;
Actions mActions;
diff --git a/src/sprite.h b/src/sprite.h
index cce41f1d..38db8b41 100644
--- a/src/sprite.h
+++ b/src/sprite.h
@@ -43,7 +43,7 @@ class Sprite
*
* @returns true if the sprite changed, false otherwise
*/
- virtual bool play(SpriteAction action) = 0;
+ virtual bool play(std::string action) = 0;
/**
* Inform the animation of the passed time so that it can output the
diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp
index ed0edd78..0d8638fc 100644
--- a/src/statuseffect.cpp
+++ b/src/statuseffect.cpp
@@ -73,19 +73,19 @@ AnimatedSprite *StatusEffect::getIcon()
paths.getStringValue("sprites") + mIcon);
if (false && sprite)
{
- sprite->play(ACTION_DEFAULT);
+ sprite->play(SpriteAction::DEFAULT);
sprite->reset();
}
return sprite;
}
}
-SpriteAction StatusEffect::getAction()
+std::string StatusEffect::getAction()
{
if (mAction.empty())
- return ACTION_INVALID;
+ return SpriteAction::INVALID;
else
- return SpriteDef::makeSpriteAction(mAction);
+ return mAction;
}
diff --git a/src/statuseffect.h b/src/statuseffect.h
index fc0e7336..3f715a16 100644
--- a/src/statuseffect.h
+++ b/src/statuseffect.h
@@ -56,9 +56,9 @@ public:
AnimatedSprite *getIcon();
/**
- * Retrieves an action to perform, or ACTION_INVALID
+ * Retrieves an action to perform, or SpriteAction::INVALID
*/
- SpriteAction getAction();
+ std::string getAction();
/**
* Determines whether the particle effect should be restarted when the