diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-02-12 17:02:17 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-02-12 17:02:17 +0200 |
commit | 992c2920f7e1940aa293e27cf4ea7ec23668a673 (patch) | |
tree | 4328076c6585a015433cb8bb763eab687da675bc /src | |
parent | 428770c113abf002e5cc0b79ae872db1f26cf283 (diff) | |
download | plus-992c2920f7e1940aa293e27cf4ea7ec23668a673.tar.gz plus-992c2920f7e1940aa293e27cf4ea7ec23668a673.tar.bz2 plus-992c2920f7e1940aa293e27cf4ea7ec23668a673.tar.xz plus-992c2920f7e1940aa293e27cf4ea7ec23668a673.zip |
Add items attribute what allow hide other sprites only by id.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 5 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 3 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 13 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 7 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 11 | ||||
-rw-r--r-- | src/utils/stringutils.h | 3 |
6 files changed, 41 insertions, 1 deletions
diff --git a/src/being.cpp b/src/being.cpp index 7851725d4..6d26f74a7 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -1901,7 +1901,10 @@ void Being::recalcSpritesOrder() const ItemInfo &info = ItemDB::get(id); if (info.getRemoveSprite() > 0) - mSpriteHide[info.getRemoveSprite()] = 1; + { + if (info.isRemoveSpriteId(mSpriteIDs[info.getRemoveSprite()])) + mSpriteHide[info.getRemoveSprite()] = 1; + } if (info.getDrawBefore() > 0) { diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 075104516..97a6ba1f4 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -205,6 +205,8 @@ 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", @@ -265,6 +267,7 @@ void ItemDB::load() 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) diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 300c6bd26..f65e0396a 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -24,6 +24,8 @@ #include "resources/itemdb.h" #include "configuration.h" +#include <set> + const std::string &ItemInfo::getSprite(Gender gender) const { if (mView) @@ -64,3 +66,14 @@ 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 +{ + if (!mRemoveSpriteIds.size() + || mRemoveSpriteIds.find(id) != mRemoveSpriteIds.end()) + { + return true; + } + + return false; +}
\ No newline at end of file diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 8dbef87b7..ba7866518 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -29,6 +29,7 @@ #include <map> #include <string> #include <vector> +#include <set> enum EquipmentSoundEvent { @@ -220,6 +221,11 @@ class ItemInfo void addTag(int tag) { mTags[tag] = 1; } + void setRemoveSpriteIds(std::set<int> ids) + { mRemoveSpriteIds = ids; } + + bool isRemoveSpriteId(int id) const; + protected: SpriteDisplay mDisplay; /**< Display info (like icon) */ std::string mName; @@ -234,6 +240,7 @@ class ItemInfo int mDrawAfter; int mDrawPriority; int mRemoveSprite; + std::set<int> mRemoveSpriteIds; // Equipment related members. /** Attack type, in case of weapon. diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index ffce9897e..99316ce32 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -364,3 +364,14 @@ std::string normalize(const std::string &name) std::string normalized = name; return toLower(trim(normalized)); } + +std::set<int> splitToIntSet(const std::string &text, char separator) +{ + std::set<int> tokens; + std::stringstream ss(text); + std::string item; + while(std::getline(ss, item, separator)) + tokens.insert(atoi(item.c_str())); + + return tokens; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 15d41380f..934c0f82d 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -25,6 +25,7 @@ #include <string> #include <sstream> #include <list> +#include <set> /** * Trims spaces off the end and the beginning of the given string. @@ -164,4 +165,6 @@ void replaceSpecialChars(std::string &text); */ std::string normalize(const std::string &name); +std::set<int> splitToIntSet(const std::string &text, char separator); + #endif // UTILS_STRINGUTILS_H |