summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-10-18 20:38:53 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-10-18 20:38:53 +0000
commit677e019013c8500c6dd6198d370178fc982a7a22 (patch)
treefa5030104d2dc989a6f69b0a1e424eecc597738d /src
parent7a4efbb335f5dae02f4ae033d47622acac865149 (diff)
downloadmana-677e019013c8500c6dd6198d370178fc982a7a22.tar.gz
mana-677e019013c8500c6dd6198d370178fc982a7a22.tar.bz2
mana-677e019013c8500c6dd6198d370178fc982a7a22.tar.xz
mana-677e019013c8500c6dd6198d370178fc982a7a22.zip
Added automatic generation of description strings for item effects.
Diffstat (limited to 'src')
-rw-r--r--src/resources/itemdb.cpp62
1 files changed, 39 insertions, 23 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 10fd2697..49632279 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -33,6 +33,8 @@
#include "../log.h"
#include "../utils/dtor.h"
+#include "../utils/gettext.h"
+#include "../utils/strprintf.h"
#include "../utils/xml.h"
namespace
@@ -46,6 +48,14 @@ namespace
static void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node);
static void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node);
+static char const *const fields[][2] =
+{
+ { "attack", N_("Attack %+d") },
+ { "defense", N_("Defense %+d") },
+ { "hp", N_("HP %+d") },
+ { "mp", N_("MP %+d") }
+};
+
void ItemDB::load()
{
if (mLoaded)
@@ -105,36 +115,42 @@ void ItemDB::load()
std::string name = XML::getProperty(node, "name", "");
std::string image = XML::getProperty(node, "image", "");
std::string description = XML::getProperty(node, "description", "");
- std::string effect = XML::getProperty(node, "effect", "");
int weaponType = XML::getProperty(node, "weapon_type", 0);
- if (id)
+ ItemInfo *itemInfo = new ItemInfo;
+ itemInfo->setImage(image);
+ itemInfo->setName(name.empty() ? "Unnamed" : name);
+ itemInfo->setDescription(description);
+ itemInfo->setType(type);
+ itemInfo->setView(view);
+ itemInfo->setWeight(weight);
+ itemInfo->setWeaponType(weaponType);
+
+ std::string effect;
+ for (int i = 0; i < int(sizeof(fields) / sizeof(fields[0])); ++i)
+ {
+ int value = XML::getProperty(node, fields[i][0], 0);
+ if (!value) continue;
+ if (!effect.empty()) effect += " / ";
+ effect += strprintf(gettext(fields[i][1]), value);
+ }
+ itemInfo->setEffect(effect);
+
+
+ for_each_xml_child_node(itemChild, node)
{
- ItemInfo *itemInfo = new ItemInfo();
- itemInfo->setImage(image);
- itemInfo->setName((name == "") ? "Unnamed" : name);
- itemInfo->setDescription(description);
- itemInfo->setEffect(effect);
- itemInfo->setType(type);
- itemInfo->setView(view);
- itemInfo->setWeight(weight);
- itemInfo->setWeaponType(weaponType);
-
- for_each_xml_child_node(itemChild, node)
+ if (xmlStrEqual(itemChild->name, BAD_CAST "sprite"))
{
- if (xmlStrEqual(itemChild->name, BAD_CAST "sprite"))
- {
- loadSpriteRef(itemInfo, itemChild);
- }
- else if (xmlStrEqual(itemChild->name, BAD_CAST "sound"))
- {
- loadSoundRef(itemInfo, itemChild);
- }
+ loadSpriteRef(itemInfo, itemChild);
+ }
+ else if (xmlStrEqual(itemChild->name, BAD_CAST "sound"))
+ {
+ loadSoundRef(itemInfo, itemChild);
}
-
- mItemInfos[id] = itemInfo;
}
+ mItemInfos[id] = itemInfo;
+
#define CHECK_PARAM(param, error_value) \
if (param == error_value) \
logger->log("ItemDB: Missing " #param " attribute for item %i!",id)