diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-24 22:10:02 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-24 22:10:02 +0100 |
commit | d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3 (patch) | |
tree | 081556c8fa27ce16372b1657e469ccd8587dd4e5 /src/resources | |
parent | f663f5bbb75b850ae22f451a22d112b6c62b2ad6 (diff) | |
download | mana-client-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.gz mana-client-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.bz2 mana-client-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.xz mana-client-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.zip |
Refactored the item loading in a more extensible and per protocol way.
This will greatly help into upgrading the need of
each protocol separately.
This is the first step to a new item and equipment system for manaserv.
A subclassing of the EquipmentWindow will be done in the next commit,
as requested by Thorbjorn.
Reviewed-by: Thorbjorn.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/itemdb.cpp | 568 | ||||
-rw-r--r-- | src/resources/itemdb.h | 152 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 142 |
3 files changed, 577 insertions, 285 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 435cdf96..2271abef 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -38,18 +38,7 @@ #include <cassert> -// Forward declarations -static char const *const fields[][2] = -{ - { "attack", N_("Attack %+d") }, - { "defense", N_("Defense %+d") }, - { "hp", N_("HP %+d") }, - { "mp", N_("MP %+d") } -}; - -static std::list<ItemDB::Stat> extraStats; - -void ItemDB::setStatsList(const std::list<Stat> &stats) +void setStatsList(const std::list<ItemStat> &stats) { extraStats = stats; } @@ -75,47 +64,136 @@ static ItemType itemTypeFromString(const std::string &name, int id = 0) else return ITEM_UNUSABLE; } -void ItemDB::load() +/* + * Common itemDB functions + */ + +bool ItemDB::exists(int id) { - if (mLoaded) - unload(); + assert(mLoaded); - logger->log("Initializing item database..."); + ItemInfos::const_iterator i = mItemInfos.find(id); - mUnknown = new ItemInfo; - mUnknown->mName = _("Unknown item"); - mUnknown->mDisplay = SpriteDisplay(); - std::string errFile = paths.getStringValue("spriteErrorFile"); - mUnknown->setSprite(errFile, GENDER_MALE); - mUnknown->setSprite(errFile, GENDER_FEMALE); + return i != mItemInfos.end(); +} - XML::Document doc(ITEMS_DB_FILE); - xmlNodePtr rootNode = doc.rootNode(); +const ItemInfo &ItemDB::get(int id) +{ + assert(mLoaded); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items")) + ItemInfos::const_iterator i = mItemInfos.find(id); + + if (i == mItemInfos.end()) { - logger->log("ItemDB: Error while loading " ITEMS_DB_FILE "!"); - return; + logger->log("ItemDB: Warning, unknown item ID# %d", id); + return *mUnknown; } - for_each_xml_child_node(node, rootNode) + return *(i->second); +} + +const ItemInfo &ItemDB::get(const std::string &name) +{ + assert(mLoaded); + + NamedItemInfos::const_iterator i = mNamedItemInfos.find(normalize(name)); + + if (i == mNamedItemInfos.end()) + { + if (!name.empty()) + { + logger->log("ItemDB: Warning, unknown item name \"%s\"", + name.c_str()); + } + return *mUnknown; + } + + return *(i->second); +} + +void ItemDB::loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) +{ + std::string gender = XML::getProperty(node, "gender", "unisex"); + std::string filename = (const char*) node->xmlChildrenNode->content; + + if (gender == "male" || gender == "unisex") + { + itemInfo->setSprite(filename, GENDER_MALE); + } + if (gender == "female" || gender == "unisex") + { + itemInfo->setSprite(filename, GENDER_FEMALE); + } +} + +void ItemDB::loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) +{ + std::string event = XML::getProperty(node, "event", ""); + std::string filename = (const char*) node->xmlChildrenNode->content; + + if (event == "hit") { + itemInfo->addSound(EQUIP_EVENT_HIT, filename); + } + else if (event == "strike") + { + itemInfo->addSound(EQUIP_EVENT_STRIKE, filename); + } + else + { + logger->log("ItemDB: Ignoring unknown sound event '%s'", + event.c_str()); + } +} + +void ItemDB::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); + } + } +} + +void ItemDB::unload() +{ + logger->log("Unloading item database..."); + + delete mUnknown; + mUnknown = NULL; + + delete_all(mItemInfos); + mItemInfos.clear(); + mNamedItemInfos.clear(); + mLoaded = false; +} + +void ItemDB::loadCommonRef(ItemInfo *itemInfo, xmlNodePtr node) +{ if (!xmlStrEqual(node->name, BAD_CAST "item")) - continue; + return; int id = XML::getProperty(node, "id", 0); if (!id) { - logger->log("ItemDB: Invalid or missing item ID in " + logger->log("ItemDB: Invalid or missing item Id in " ITEMS_DB_FILE "!"); - continue; + return; } else if (mItemInfos.find(id) != mItemInfos.end()) - logger->log("ItemDB: Redefinition of item ID %d", id); + logger->log("ItemDB: Redefinition of item Id %d", id); - std::string typeStr = XML::getProperty(node, "type", "other"); - int weight = XML::getProperty(node, "weight", 0); int view = XML::getProperty(node, "view", 0); std::string name = XML::getProperty(node, "name", ""); @@ -125,42 +203,26 @@ void ItemDB::load() int attackRange = XML::getProperty(node, "attack-range", 0); std::string missileParticle = XML::getProperty(node, "missile-particle", ""); + // Load Ta Item Type + std::string typeStr = XML::getProperty(node, "type", "other"); + itemInfo->mType = itemTypeFromString(typeStr); + + int weight = XML::getProperty(node, "weight", 0); + itemInfo->mWeight = weight > 0 ? weight : 0; + SpriteDisplay display; display.image = image; - ItemInfo *itemInfo = new ItemInfo; itemInfo->mId = id; - itemInfo->mName = name.empty() ? _("unnamed") : name; + itemInfo->mName = name; itemInfo->mDescription = description; - itemInfo->mType = itemTypeFromString(typeStr); - itemInfo->mActivatable = itemInfo->mType == ITEM_USABLE; - // Everything not unusable or usable is equippable by the old type system. - itemInfo->mEquippable = itemInfo->mType != ITEM_UNUSABLE - && itemInfo->mType != ITEM_USABLE; itemInfo->mView = view; itemInfo->mWeight = weight; itemInfo->setAttackAction(attackAction); itemInfo->mAttackRange = attackRange; itemInfo->setMissileParticle(missileParticle); - std::vector<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; - effect.push_back(strprintf(gettext(fields[i][1]), value)); - } - for (std::list<Stat>::iterator it = extraStats.begin(); - it != extraStats.end(); it++) - { - int value = XML::getProperty(node, it->tag.c_str(), 0); - if (!value) continue; - effect.push_back(strprintf(it->format.c_str(), value)); - } - std::string temp = XML::getProperty(node, "effect", ""); - if (!temp.empty()) - effect.push_back(temp); - + // Load <sprite>, <sound>, and <floor> for_each_xml_child_node(itemChild, node) { if (xmlStrEqual(itemChild->name, BAD_CAST "sprite")) @@ -179,13 +241,209 @@ void ItemDB::load() { loadFloorSprite(&display, itemChild); } - /* - * Begin new item definition code. Previous code is left in to - * maintain backwards compatibility. - * Exit here if tmwAthena. - */ - else if (Net::getNetworkType() == ServerInfo::TMWATHENA); - else if (xmlStrEqual(itemChild->name, BAD_CAST "equip")) + + } + + // If the item has got a floor image, we bind the good reference. + itemInfo->mDisplay = display; +} + +void ItemDB::addItem(ItemInfo *itemInfo) +{ + std::string itemName = itemInfo->mName; + itemInfo->mName = itemName.empty() ? _("unnamed") : itemName; + mItemInfos[itemInfo->mId] = itemInfo; + if (!itemName.empty()) + { + std::string temp = normalize(itemName); + + NamedItemInfos::const_iterator itr = mNamedItemInfos.find(temp); + if (itr == mNamedItemInfos.end()) + mNamedItemInfos[temp] = itemInfo; + else + logger->log("ItemDB: Duplicate name (%s) for item id %d found.", + temp.c_str(), itemInfo->mId); + + } +} + +template <class T> +static void checkParameter(int id, const T param, const T errorValue) +{ + if (param == errorValue) + { + std::stringstream errMsg; + errMsg << "ItemDB: Missing " << param << " attribute for item id " + << id << "!"; + logger->log(errMsg.str().c_str()); + } +} + +void ItemDB::checkItemInfo(ItemInfo* itemInfo) +{ + int id = itemInfo->mId; + if (!itemInfo->getAttackAction().empty()) + if (itemInfo->mAttackRange == 0) + logger->log("ItemDB: Missing attack range from weapon %i!", id); + + if (id >= 0) + { + checkParameter(id, itemInfo->mName, std::string("")); + checkParameter(id, itemInfo->mDescription, std::string("")); + checkParameter(id, itemInfo->mDisplay.image, std::string("")); + checkParameter(id, itemInfo->mWeight, 0); + } +} + +namespace TmwAthena { + +// Description fields used by TaItemDB *itemInfo->mEffect. + +static char const *const fields[][2] = +{ + { "attack", N_("Attack %+d") }, + { "defense", N_("Defense %+d") }, + { "hp", N_("HP %+d") }, + { "mp", N_("MP %+d") } +}; + +void TaItemDB::load() +{ + if (mLoaded) + unload(); + + logger->log("Initializing TmwAthena item database..."); + + mUnknown = new TaItemInfo; + mUnknown->mName = _("Unknown item"); + mUnknown->mDisplay = SpriteDisplay(); + std::string errFile = paths.getStringValue("spriteErrorFile"); + mUnknown->setSprite(errFile, GENDER_MALE); + mUnknown->setSprite(errFile, GENDER_FEMALE); + + XML::Document doc(ITEMS_DB_FILE); + xmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items")) + { + logger->error("ItemDB: Error while loading " ITEMS_DB_FILE "!"); + return; + } + + for_each_xml_child_node(node, rootNode) + { + TaItemInfo *itemInfo = new TaItemInfo; + + loadCommonRef(itemInfo, node); + + // Everything not unusable or usable is equippable by the Ta type system. + itemInfo->mEquippable = itemInfo->mType != ITEM_UNUSABLE + && itemInfo->mType != ITEM_USABLE; + + // Load nano description + std::vector<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; + effect.push_back(strprintf(gettext(fields[i][1]), value)); + } + for (std::list<ItemStat>::iterator it = extraStats.begin(); + it != extraStats.end(); it++) + { + int value = XML::getProperty(node, it->mTag.c_str(), 0); + if (!value) + continue; + effect.push_back(strprintf(it->mFormat.c_str(), value)); + } + std::string temp = XML::getProperty(node, "effect", ""); + if (!temp.empty()) + effect.push_back(temp); + + itemInfo->mEffect = effect; + + checkItemInfo(itemInfo); + + addItem(itemInfo); + } + + checkHairWeaponsRacesSpecialIds(); + + mLoaded = true; +} + +void TaItemDB::checkItemInfo(ItemInfo* itemInfo) +{ + ItemDB::checkItemInfo(itemInfo); + + // Check for unusable items? + //checkParameter(id, itemInfo->mType, 0); +} + +}; // namespace TmwAthena + +namespace ManaServ { + +static std::map<std::string, const char* > triggerTable; + +static void initTriggerTable() +{ + if (triggerTable.empty()) + { + // FIXME: This should ideally be softcoded via XML or similar. + logger->log("Initializing ManaServ trigger table..."); + triggerTable["existence"] = " when it is in the inventory"; + triggerTable["activation"] = " upon activation"; + triggerTable["equip"] = " upon successful equip"; + triggerTable["leave-inventory"] = " when it leaves the inventory"; + triggerTable["unequip"] = " when it is unequipped"; + triggerTable["equip-change"] = " when it changes the way it is equipped"; + } +} + +void ManaServItemDB::load() +{ + if (mLoaded) + unload(); + + // Initialize the trigger table for effect descriptions + initTriggerTable(); + + logger->log("Initializing ManaServ item database..."); + + mUnknown = new ManaServItemInfo; + mUnknown->mName = _("Unknown item"); + mUnknown->mDisplay = SpriteDisplay(); + std::string errFile = paths.getStringValue("spriteErrorFile"); + mUnknown->setSprite(errFile, GENDER_MALE); + mUnknown->setSprite(errFile, GENDER_FEMALE); + + XML::Document doc(ITEMS_DB_FILE); + xmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items")) + { + logger->log("ItemDB: Error while loading " ITEMS_DB_FILE "!"); + return; + } + + for_each_xml_child_node(node, rootNode) + { + ManaServItemInfo *itemInfo = new ManaServItemInfo; + + loadCommonRef(itemInfo, node); + + // We default eqippable and activatable to false as their actual value will be set + // within the <equip> and <effect> sub-nodes.. + itemInfo->mActivatable = false; + itemInfo->mEquippable = false; + + // Load <equip>, and <effect> sub nodes. + std::vector<std::string> effect; + for_each_xml_child_node(itemChild, node) + { + if (xmlStrEqual(itemChild->name, BAD_CAST "equip")) { // The fact that there is a way to equip is enough. // Discard any details, but mark the item as equippable. @@ -195,7 +453,8 @@ void ItemDB::load() { std::string trigger = XML::getProperty( itemChild, "trigger", ""); - if (trigger.empty()) { + if (trigger.empty()) + { logger->log("Found empty trigger effect label, skipping."); continue; } @@ -203,22 +462,12 @@ void ItemDB::load() if (trigger == "activation") itemInfo->mActivatable = true; - static std::map<std::string, const char* > triggerTable; - if (triggerTable.empty()) - { - // FIXME: This should ideally be softcoded via XML or similar. - triggerTable["existence"] = " when it is in the inventory"; - triggerTable["activation"] = " upon activation"; - triggerTable["equip"] = " upon successful equip"; - triggerTable["leave-inventory"] = " when it leaves the inventory"; - triggerTable["unequip"] = " when it is unequipped"; - triggerTable["equip-change"] = " when it changes the way it is equipped"; - } std::map<std::string, const char* >::const_iterator triggerLabel = triggerTable.find(trigger); if (triggerLabel == triggerTable.end()) { - logger->log("Warning: unknown trigger %s in item %d!", trigger.c_str(), id); + logger->log("Warning: unknown trigger %s in item %d!", + trigger.c_str(), itemInfo->mId); continue; } @@ -237,7 +486,7 @@ void ItemDB::load() logger->log("Warning: incomplete modifier definition, skipping."); continue; } - std::list<Stat>::const_iterator + std::list<ItemStat>::const_iterator it = extraStats.begin(), it_end = extraStats.end(); while (it != it_end && !(*it == attribute)) @@ -251,7 +500,7 @@ void ItemDB::load() strprintf(strprintf( duration ? strprintf("%%s%%s. This effect lasts %d ticks.", duration).c_str() - : "%s%s.", it->format.c_str(), triggerLabel->second).c_str(), value)); + : "%s%s.", it->mFormat.c_str(), triggerLabel->second).c_str(), value)); } else if (xmlStrEqual(effectChild->name, BAD_CAST "modifier")) effect.push_back(strprintf("Provides an autoattack%s.", @@ -264,159 +513,30 @@ void ItemDB::load() (const char*)effectChild->xmlChildrenNode->content); } } - } + // Set Item Type based on subnodes info + // TODO: Improve it once the itemTypes are loaded through xml + itemInfo->mType = ITEM_UNUSABLE; + if (itemInfo->mActivatable) + itemInfo->mType = ITEM_USABLE; + else if (itemInfo->mEquippable) + itemInfo->mType = ITEM_EQUIPMENT_TORSO; + } // end for_each_xml_child_node(itemChild, node) itemInfo->mEffect = effect; - itemInfo->mDisplay = display; - - mItemInfos[id] = itemInfo; - if (!name.empty()) - { - std::string temp = normalize(name); - - NamedItemInfos::const_iterator itr = mNamedItemInfos.find(temp); - if (itr == mNamedItemInfos.end()) - { - mNamedItemInfos[temp] = itemInfo; - } - else - { - logger->log("ItemDB: Duplicate name of item found item %d", id); - } - } - - if (!attackAction.empty()) - if (attackRange == 0) - logger->log("ItemDB: Missing attack range from weapon %i!", id); - -#define CHECK_PARAM(param, error_value) \ - if (param == error_value) \ - logger->log("ItemDB: Missing " #param " attribute for item %i!",id) - - if (id >= 0) - { - CHECK_PARAM(name, ""); - CHECK_PARAM(description, ""); - CHECK_PARAM(image, ""); - } - // CHECK_PARAM(effect, ""); - // CHECK_PARAM(type, 0); - // CHECK_PARAM(weight, 0); - // CHECK_PARAM(slot, 0); + checkItemInfo(itemInfo); -#undef CHECK_PARAM + addItem(itemInfo); } mLoaded = true; } -void ItemDB::unload() -{ - logger->log("Unloading item database..."); - - delete mUnknown; - mUnknown = NULL; - - delete_all(mItemInfos); - mItemInfos.clear(); - mNamedItemInfos.clear(); - mLoaded = false; -} - -bool ItemDB::exists(int id) -{ - assert(mLoaded); - - ItemInfos::const_iterator i = mItemInfos.find(id); - - return i != mItemInfos.end(); -} - -const ItemInfo &ItemDB::get(int id) -{ - assert(mLoaded); - - ItemInfos::const_iterator i = mItemInfos.find(id); - - if (i == mItemInfos.end()) - { - logger->log("ItemDB: Warning, unknown item ID# %d", id); - return *mUnknown; - } - - return *(i->second); -} - -const ItemInfo &ItemDB::get(const std::string &name) +void ManaServItemDB::checkItemInfo(ItemInfo* itemInfo) { - assert(mLoaded); - - NamedItemInfos::const_iterator i = mNamedItemInfos.find(normalize(name)); + ItemDB::checkItemInfo(itemInfo); - if (i == mNamedItemInfos.end()) - { - if (!name.empty()) - { - logger->log("ItemDB: Warning, unknown item name \"%s\"", - name.c_str()); - } - return *mUnknown; - } - - return *(i->second); + // Add specific Manaserv checks here } -void ItemDB::loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) -{ - std::string gender = XML::getProperty(node, "gender", "unisex"); - std::string filename = (const char*) node->xmlChildrenNode->content; - - if (gender == "male" || gender == "unisex") - { - itemInfo->setSprite(filename, GENDER_MALE); - } - if (gender == "female" || gender == "unisex") - { - itemInfo->setSprite(filename, GENDER_FEMALE); - } -} - -void ItemDB::loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) -{ - std::string event = XML::getProperty(node, "event", ""); - std::string filename = (const char*) node->xmlChildrenNode->content; - - if (event == "hit") - { - itemInfo->addSound(EQUIP_EVENT_HIT, filename); - } - else if (event == "strike") - { - itemInfo->addSound(EQUIP_EVENT_STRIKE, filename); - } - else - { - logger->log("ItemDB: Ignoring unknown sound event '%s'", - event.c_str()); - } -} - -void ItemDB::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); - } - } -} +}; // namespace ManaServ diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 9109898b..e80f2cd0 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -33,24 +33,59 @@ class ItemInfo; class SpriteDisplay; +// Used to make the compiler uderstand the iteminfo friendship. +namespace TmwAthena { class TaItemDB; }; +namespace ManaServ { class ManaServItemDB; }; + +/** + * Nano-description functions + */ +class ItemStat +{ + friend class ItemDB; + friend class TmwAthena::TaItemDB; + friend class ManaServ::ManaServItemDB; + + public: + ItemStat(const std::string &tag, + const std::string &format): + mTag(tag), mFormat(format) {} + + bool operator ==(std::string &name) const + { return mTag == name; } + + private: + std::string mTag; + std::string mFormat; +}; + +// Used to set nano-description +static std::list<ItemStat> extraStats; +void setStatsList(const std::list<ItemStat> &stats); + /** - * Item information database. + * Item information database generic definition. */ class ItemDB { public: - ItemDB() : mLoaded(false) { load(); } + ItemDB() : + mUnknown(0), + mLoaded(false) + {} + + ~ItemDB() + {} - ~ItemDB() { unload(); } /** * Loads the item data from <code>items.xml</code>. */ - void load(); + virtual void load() = 0; /** * Frees item data. */ - void unload(); + virtual void unload(); /** * Tells whether the item database is loaded. @@ -63,26 +98,42 @@ class ItemDB const ItemInfo &get(int id); const ItemInfo &get(const std::string &name); - class Stat - { - public: - Stat(const std::string &tag, - const std::string &format): - tag(tag), format(format) {} + protected: + /** + * Permits to load item definitions which are common + * for each protocols to avoid code duplication. + */ + void loadCommonRef(ItemInfo *itemInfo, xmlNodePtr node); - bool operator ==(std::string &name) const { return tag == name; } + /** + * Checks the items parameters consistency. + */ + virtual void checkItemInfo(ItemInfo* itemInfo); - private: - std::string tag; - std::string format; - friend class ItemDB; - }; + /** + * Register the item to mItemInfos and mNamedItemsInfos + */ + void addItem(ItemInfo *itemInfo); - void setStatsList(const std::list<Stat> &stats); + // Default unknown reference + ItemInfo *mUnknown; + + bool mLoaded; private: + /** + * Loads the sprite references contained in a <sprite> tag. + */ void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); - void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); + + /** + * Loads the sound references contained in a <sound> tag. + */ + void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); + + /** + * Loads the floor item references contained in a <floor> tag. + */ void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node); // Items database @@ -91,10 +142,69 @@ class ItemDB ItemInfos mItemInfos; NamedItemInfos mNamedItemInfos; - ItemInfo *mUnknown; - bool mLoaded; }; +namespace TmwAthena { + +class TaItemInfo; + +/** + * Item information database TmwAthena specific class. + */ +class TaItemDB: public ItemDB +{ + public: + TaItemDB() : ItemDB() + { load(); } + + ~TaItemDB() + { unload(); } + + /** + * Loads the item data from <code>items.xml</code>. + */ + void load(); + + private: + /** + * Check items id specific hard limits and log errors found. + * TODO: Do it. + */ + void checkHairWeaponsRacesSpecialIds() + {} + + void checkItemInfo(ItemInfo* itemInfo); +}; + +}; // namespace TmwAthena + +namespace ManaServ { + +class ManaServItemInfo; + +/** + * Item information database TmwAthena specific class. + */ +class ManaServItemDB: public ItemDB +{ + public: + ManaServItemDB() : ItemDB() + { load(); } + + ~ManaServItemDB() + { unload(); } + + /** + * Loads the item data from <code>items.xml</code>. + */ + void load(); + + private: + void checkItemInfo(ItemInfo* itemInfo); +}; + +}; // namespace ManaServ + extern ItemDB *itemDb; #endif diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 2ed27847..50633f71 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -36,38 +36,9 @@ enum EquipmentSoundEvent EQUIP_EVENT_HIT }; -enum EquipmentSlot -{ - // Equipment rules: - // 1 Brest equipment - EQUIP_TORSO_SLOT = 0, - // 1 arms equipment - EQUIP_ARMS_SLOT = 1, - // 1 head equipment - EQUIP_HEAD_SLOT = 2, - // 1 legs equipment - EQUIP_LEGS_SLOT = 3, - // 1 feet equipment - EQUIP_FEET_SLOT = 4, - // 2 rings - EQUIP_RING1_SLOT = 5, - EQUIP_RING2_SLOT = 6, - // 1 necklace - EQUIP_NECKLACE_SLOT = 7, - // Fight: - // 2 one-handed weapons - // or 1 two-handed weapon - // or 1 one-handed weapon + 1 shield. - EQUIP_FIGHT1_SLOT = 8, - EQUIP_FIGHT2_SLOT = 9, - // Projectile: - // this item does not amount to one, it only indicates the chosen projectile. - EQUIP_PROJECTILE_SLOT = 10 -}; - - /** * Enumeration of available Item types. + * TODO: Dynamise this using an xml. */ enum ItemType { @@ -89,12 +60,21 @@ enum ItemType ITEM_SPRITE_HAIR // 15 }; +// Used to make the compiler uderstand the iteminfo friendship. +namespace TmwAthena { class TaItemDB; }; +namespace ManaServ { class ManaServItemDB; }; + /** - * Defines a class for storing item infos. This includes information used when - * the item is equipped. + * Defines a class for storing generic item infos. + * Specialized version for one or another protocol are defined below. */ class ItemInfo { + friend class ItemDB; + friend void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); + friend class TmwAthena::TaItemDB; + friend class ManaServ::ManaServItemDB; + public: /** * Constructor. @@ -114,7 +94,8 @@ class ItemInfo const std::string &getName() const { return mName; } - std::string getParticleEffect() const { return mParticle; } + std::string getParticleEffect() const + { return mParticle; } const SpriteDisplay &getDisplay() const { return mDisplay; } @@ -122,7 +103,8 @@ class ItemInfo const std::string &getDescription() const { return mDescription; } - const std::vector<std::string> &getEffect() const { return mEffect; } + const std::vector<std::string> &getEffect() const + { return mEffect; } int getWeight() const { return mWeight; } @@ -132,9 +114,11 @@ class ItemInfo void setAttackAction(std::string attackAction); // Handlers for seting and getting the string used for particles when attacking - void setMissileParticle(std::string s) { mMissileParticle = s; } + void setMissileParticle(std::string s) + { mMissileParticle = s; } - std::string getMissileParticle() const { return mMissileParticle; } + std::string getMissileParticle() const + { return mMissileParticle; } std::string getAttackAction() const { return mAttackAction; } @@ -144,9 +128,14 @@ class ItemInfo const std::string &getSound(EquipmentSoundEvent event) const; - bool getEquippable() const { return mEquippable; } + bool getEquippable() const + { return mEquippable; } - bool getActivatable() const { return mActivatable; } + bool getActivatable() const + { return mActivatable; } + + ItemType getItemType() const + { return mType; } private: @@ -184,9 +173,82 @@ class ItemInfo /** Stores the names of sounds to be played at certain event. */ std::map< EquipmentSoundEvent, std::vector<std::string> > mSounds; +}; - friend class ItemDB; - friend void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); +/* + * TmwAthena specialization of the itemInfo for TmwAthena + */ +namespace TmwAthena { + +enum EquipmentSlot +{ + // Equipment rules: + // 1 Brest equipment + EQUIP_TORSO_SLOT = 0, + // 1 arms equipment + EQUIP_ARMS_SLOT = 1, + // 1 head equipment + EQUIP_HEAD_SLOT = 2, + // 1 legs equipment + EQUIP_LEGS_SLOT = 3, + // 1 feet equipment + EQUIP_FEET_SLOT = 4, + // 2 rings + EQUIP_RING1_SLOT = 5, + EQUIP_RING2_SLOT = 6, + // 1 necklace + EQUIP_NECKLACE_SLOT = 7, + // Fight: + // 2 one-handed weapons + // or 1 two-handed weapon + // or 1 one-handed weapon + 1 shield. + EQUIP_FIGHT1_SLOT = 8, + EQUIP_FIGHT2_SLOT = 9, + // Projectile: + // this item does not amount to one, it only indicates the chosen projectile. + EQUIP_PROJECTILE_SLOT = 10, + EQUIP_VECTOR_END = 11 }; +/** + * Defines a class for storing TmwAthena specific item infos. + * Specialized version for one or another protocol are defined below. + */ +class TaItemInfo: public ItemInfo +{ + friend class TaItemDB; + + public: + /** + * Constructor. + */ + TaItemInfo():ItemInfo() + {} + + // Declare TmwAthena Specific item info here +}; + +}; // namespace TmwAthena + +namespace ManaServ { + +/** + * Defines a class for storing Manaserv Specific item infos. + * Specialized version for one or another protocol are defined below. + */ +class ManaServItemInfo: public ItemInfo +{ + public: + /** + * Constructor. + */ + ManaServItemInfo():ItemInfo() + {} + + // Declare Manaserv Specific item info here +}; + + +}; // namespace ManaServ + #endif |