diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/imageloader.cpp | 4 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 116 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 19 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 6 | ||||
-rw-r--r-- | src/resources/resource.cpp | 2 |
5 files changed, 103 insertions, 44 deletions
diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index c63d33c00..72a839573 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -29,8 +29,6 @@ #include <guichan/sdl/sdlpixel.hpp> -#include <cassert> - #include "debug.h" #ifdef free @@ -79,12 +77,10 @@ int ProxyImage::getHeight() const return mImage->mBounds.h; else return 0; -// return mSDLImage ? mSDLImage->h : mImage->getHeight(); } gcn::Color ProxyImage::getPixel(int x, int y) { - assert(mSDLImage); return gcn::SDLgetPixel(mSDLImage, x, y); } diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index e60127997..733c12958 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -36,8 +36,6 @@ #include <libxml/tree.h> -#include <cassert> - #include "debug.h" namespace @@ -435,7 +433,8 @@ void ItemDB::unload() bool ItemDB::exists(int id) { - assert(mLoaded); + if (!mLoaded) + return false; ItemInfos::const_iterator i = mItemInfos.find(id); @@ -444,7 +443,8 @@ bool ItemDB::exists(int id) const ItemInfo &ItemDB::get(int id) { - assert(mLoaded); + if (!mLoaded) + load(); ItemInfos::const_iterator i = mItemInfos.find(id); @@ -459,7 +459,8 @@ const ItemInfo &ItemDB::get(int id) const ItemInfo &ItemDB::get(const std::string &name) { - assert(mLoaded); + if (!mLoaded) + load(); NamedItemInfos::const_iterator i = mNamedItemInfos.find(normalize(name)); @@ -560,6 +561,10 @@ int parseDirectionName(std::string name) id = DIRECTION_RIGHT; else if (name == "downright" || name == "rightdown") id = DIRECTION_DOWNRIGHT; + else if (name == "downall") + id = -2; + else if (name == "upall") + id = -3; return id; } @@ -593,7 +598,7 @@ void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) else { logger->log("ItemDB: Ignoring unknown sound event '%s'", - event.c_str()); + event.c_str()); } } @@ -624,21 +629,100 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) std::string removeSprite = XML::getProperty(replaceNode, "sprite", ""); int direction = parseDirectionName(XML::getProperty( replaceNode, "direction", "all")); - std::map<int, int> *mapList = itemInfo->addReplaceSprite( - parseSpriteName(removeSprite), direction); - - if (!mapList) - return; itemInfo->setRemoveSprites(); - for_each_xml_child_node(itemNode, replaceNode) + switch (direction) { - if (xmlStrEqual(itemNode->name, BAD_CAST "item")) + case -1: { - int from = XML::getProperty(itemNode, "from", 0); - int to = XML::getProperty(itemNode, "to", 1); - (*mapList)[from] = to; + 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); + for (int f = 0; f < 9; f ++) + { + std::map<int, int> *mapList + = itemInfo->addReplaceSprite( + parseSpriteName(removeSprite), f); + if (!mapList) + continue; + (*mapList)[from] = to; + } + } + } + break; + } + case -2: + { + 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); + std::map<int, int> *mapList = itemInfo->addReplaceSprite( + parseSpriteName(removeSprite), DIRECTION_DOWN); + if (mapList) + (*mapList)[from] = to; + + mapList = itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_DOWNLEFT); + if (mapList) + (*mapList)[from] = to; + + mapList = itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_DOWNRIGHT); + if (mapList) + (*mapList)[from] = to; + } + } + break; + } + case -3: + { + 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); + std::map<int, int> *mapList = itemInfo->addReplaceSprite( + parseSpriteName(removeSprite), DIRECTION_UP); + if (mapList) + (*mapList)[from] = to; + + mapList = itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_UPLEFT); + if (mapList) + (*mapList)[from] = to; + + mapList = itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_UPRIGHT); + if (mapList) + (*mapList)[from] = to; + } + } + break; + } + default: + { + std::map<int, int> *mapList = itemInfo->addReplaceSprite( + parseSpriteName(removeSprite), direction); + if (!mapList) + return; + 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; + } + } + break; } } } diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 56cfc01f6..fb4b8ed5e 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -144,25 +144,6 @@ const std::string &ItemInfo::getSound(EquipmentSoundEvent event) const std::map<int, int> *ItemInfo::addReplaceSprite(int sprite, int direction) { - if (direction == -1) - { - SpriteToItemMap *spMap = new SpriteToItemMap(); - for (int f = 0; f < 9; f ++) - { - if (!mSpriteToItemReplaceMap[f]) - { - mSpriteToItemReplaceMap[f] = spMap; - direction = f; - } - } - if (direction >= 0) - mSpriteToItemReplaceList.push_back(spMap); - else - delete spMap; - if (direction == -1) - direction = 1; - } - if (direction < 0 || direction >= 9) return 0; diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 70c45054f..685d415ff 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -37,7 +37,6 @@ #include "utils/stringutils.h" #include "utils/xml.h" -#include <cassert> #include <iostream> #include <zlib.h> @@ -110,7 +109,8 @@ int inflateMemory(unsigned char *in, unsigned int inLength, } ret = inflate(&strm, Z_NO_FLUSH); - assert(ret != Z_STREAM_ERROR); + if (ret == Z_STREAM_ERROR) + return ret; switch (ret) { @@ -140,7 +140,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, } } while (ret != Z_STREAM_END); - assert(strm.avail_in == 0); +// assert(strm.avail_in == 0); outLength = bufferSize - strm.avail_out; (void) inflateEnd(&strm); diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index b180712c1..552af06ec 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -27,8 +27,6 @@ #include "resources/resourcemanager.h" -#include <cassert> - #include "debug.h" Resource::~Resource() |