summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-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
5 files changed, 33 insertions, 29 deletions
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