diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-02-14 03:54:55 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-02-14 23:52:45 +0200 |
commit | 3805d1384894a33ecb09e4852d47afb04ddb0687 (patch) | |
tree | 840b5920d912576554e0e11e67794a726d4a9c4f /src/resources | |
parent | 36ccecd553539955929f1ce535b8925533922e4e (diff) | |
download | manaverse-3805d1384894a33ecb09e4852d47afb04ddb0687.tar.gz manaverse-3805d1384894a33ecb09e4852d47afb04ddb0687.tar.bz2 manaverse-3805d1384894a33ecb09e4852d47afb04ddb0687.tar.xz manaverse-3805d1384894a33ecb09e4852d47afb04ddb0687.zip |
Replace sprites functionality (need support in client data).
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/itemdb.cpp | 26 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 17 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 29 |
3 files changed, 49 insertions, 23 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 00987ff9d..ce2ec40a2 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -50,6 +50,7 @@ namespace static void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); static void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); static void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node); +static void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode); static int parseSpriteName(std::string &name); static char const *const fields[][2] = @@ -205,8 +206,6 @@ void ItemDB::load() std::string drawBefore = XML::getProperty(node, "drawBefore", ""); std::string drawAfter = XML::getProperty(node, "drawAfter", ""); std::string removeSprite = XML::getProperty(node, "removeSprite", ""); - std::string removeSpriteIds = XML::getProperty(node, "removeSpriteIds", ""); - std::set<int> rSprites = splitToIntSet(removeSpriteIds, ','); std::string tags[3]; tags[0] = XML::getProperty(node, "tag", @@ -266,8 +265,6 @@ void ItemDB::load() itemInfo->setDrawBefore(parseSpriteName(drawBefore)); itemInfo->setDrawAfter(parseSpriteName(drawAfter)); itemInfo->setDrawPriority(drawPriority); - itemInfo->setRemoveSprite(parseSpriteName(removeSprite)); - itemInfo->setRemoveSpriteIds(rSprites); std::string effect; for (int i = 0; i < int(sizeof(fields) / sizeof(fields[0])); ++i) @@ -313,6 +310,10 @@ void ItemDB::load() { loadFloorSprite(&display, itemChild); } + else if (xmlStrEqual(itemChild->name, BAD_CAST "replace")) + { + loadReplaceSprite(itemInfo, itemChild); + } } itemInfo->setDisplay(display); @@ -554,3 +555,20 @@ void loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode) } } } + +void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) +{ + std::string removeSprite = XML::getProperty(replaceNode, "sprite", ""); + std::map<int,int> &mapList = itemInfo->addReplaceSprite(parseSpriteName(removeSprite)); + itemInfo->setRemoveSprites(); + + for_each_xml_child_node(itemNode, replaceNode) + { + if (xmlStrEqual(itemNode->name, BAD_CAST "item")) + { + int from = XML::getProperty(itemNode, "from", 0); + int to = XML::getProperty(itemNode, "to", 1); + mapList[from] = to; + } + } +} diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index f65e0396a..c2d3aafef 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -25,6 +25,7 @@ #include "configuration.h" #include <set> +#include <map> const std::string &ItemInfo::getSprite(Gender gender) const { @@ -67,13 +68,15 @@ const std::string &ItemInfo::getSound(EquipmentSoundEvent event) const return i == mSounds.end() ? empty : i->second[rand() % i->second.size()]; } -bool ItemInfo::isRemoveSpriteId(int id) const +std::map<int,int> &ItemInfo::addReplaceSprite(int sprite) { - if (!mRemoveSpriteIds.size() - || mRemoveSpriteIds.find(id) != mRemoveSpriteIds.end()) + std::map<int, std::map<int, int> >::iterator it + = mSpriteToItemReplaceMap.find(sprite); + if (it == mSpriteToItemReplaceMap.end()) { - return true; + std::map<int, int> tmp; + mSpriteToItemReplaceMap[sprite] = tmp; + it = mSpriteToItemReplaceMap.find(sprite); } - - return false; -}
\ No newline at end of file + return it->second; +} diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index ba7866518..28f4b2e35 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -108,7 +108,7 @@ class ItemInfo mDrawBefore(-1), mDrawAfter(-1), mDrawPriority(0), - mRemoveSprite(0), + mIsRemoveSprites(false), mAttackAction(SpriteAction::INVALID), mAttackRange(0) { @@ -209,22 +209,26 @@ class ItemInfo void setDrawPriority(int n) { mDrawPriority = n; } - int getRemoveSprite() const - { return mRemoveSprite; } - - void setRemoveSprite(int n) - { mRemoveSprite = n; } - std::map<int, int> getTags() const { return mTags; } void addTag(int tag) { mTags[tag] = 1; } - void setRemoveSpriteIds(std::set<int> ids) - { mRemoveSpriteIds = ids; } + void setRemoveSprites() + { mIsRemoveSprites = true; } + + bool isRemoveSprites() const + { return mIsRemoveSprites; } + + bool isRemoveItemId(int id) const; + + int getReplaceToSpriteId(int id) const; + + std::map<int,int> &addReplaceSprite(int sprite); - bool isRemoveSpriteId(int id) const; + std::map<int, std::map<int, int> > getSpriteToItemReplaceMap() const + { return mSpriteToItemReplaceMap; } protected: SpriteDisplay mDisplay; /**< Display info (like icon) */ @@ -239,8 +243,9 @@ class ItemInfo int mDrawBefore; int mDrawAfter; int mDrawPriority; - int mRemoveSprite; - std::set<int> mRemoveSpriteIds; + bool mIsRemoveSprites; + // sprite, <itemfrom, itemto> + std::map<int, std::map<int, int> > mSpriteToItemReplaceMap; // Equipment related members. /** Attack type, in case of weapon. |