summaryrefslogtreecommitdiff
path: root/src/resources/itemdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/itemdb.cpp')
-rw-r--r--src/resources/itemdb.cpp56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 3fdee021..a8eed123 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -47,6 +47,7 @@ namespace
// Forward declarations
static void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node);
static void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node);
+static void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node);
static char const *const fields[][2] =
{
@@ -84,22 +85,6 @@ static ItemType itemTypeFromString(const std::string &name, int id = 0)
else return ITEM_UNUSABLE;
}
-static WeaponType weaponTypeFromString(const std::string &name, int id = 0)
-{
- 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;
@@ -115,8 +100,8 @@ void ItemDB::load()
mUnknown = new ItemInfo;
mUnknown->setName(_("Unknown item"));
- mUnknown->setImageName("");
- std::string errFile = paths.getValue("spriteErrorFile", "error.xml");
+ mUnknown->setDisplay(SpriteDisplay());
+ std::string errFile = paths.getStringValue("spriteErrorFile");
mUnknown->setSprite(errFile, GENDER_MALE);
mUnknown->setSprite(errFile, GENDER_FEMALE);
@@ -152,19 +137,21 @@ 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", "");
+ SpriteDisplay display;
+ display.image = image;
+
ItemInfo *itemInfo = new ItemInfo;
itemInfo->setId(id);
- itemInfo->setImageName(image);
itemInfo->setName(name.empty() ? _("unnamed") : name);
itemInfo->setDescription(description);
itemInfo->setType(itemTypeFromString(typeStr));
itemInfo->setView(view);
itemInfo->setWeight(weight);
- itemInfo->setWeaponType(weaponType);
+ itemInfo->setAttackAction(attackAction);
itemInfo->setAttackRange(attackRange);
itemInfo->setMissileParticle(missileParticle);
@@ -204,8 +191,14 @@ void ItemDB::load()
{
loadSoundRef(itemInfo, itemChild);
}
+ else if (xmlStrEqual(itemChild->name, BAD_CAST "floor"))
+ {
+ loadFloorSprite(&display, itemChild);
+ }
}
+ itemInfo->setDisplay(display);
+
mItemInfos[id] = itemInfo;
if (!name.empty())
{
@@ -222,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);
@@ -336,3 +329,22 @@ void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node)
event.c_str());
}
}
+
+void loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode)
+{
+ for_each_xml_child_node(spriteNode, floorNode)
+ {
+ if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
+ {
+ SpriteReference *currentSprite = new SpriteReference;
+ currentSprite->sprite = (const char*)spriteNode->xmlChildrenNode->content;
+ currentSprite->variant = XML::getProperty(spriteNode, "variant", 0);
+ display->sprites.push_back(currentSprite);
+ }
+ else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
+ {
+ std::string particlefx = (const char*)spriteNode->xmlChildrenNode->content;
+ display->particles.push_back(particlefx);
+ }
+ }
+}