summaryrefslogtreecommitdiff
path: root/src/resources/spritedef.cpp
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/resources/spritedef.cpp
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/resources/spritedef.cpp')
-rw-r--r--src/resources/spritedef.cpp117
1 files changed, 27 insertions, 90 deletions
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")