summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/itemdb.cpp32
-rw-r--r--src/resources/iteminfo.cpp110
-rw-r--r--src/resources/iteminfo.h36
-rw-r--r--src/resources/spritedef.h16
4 files changed, 154 insertions, 40 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 1260fab58..bee988510 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -56,6 +56,7 @@ 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 int parseDirectionName(std::string name);
static char const *const fields[][2] =
{
@@ -530,6 +531,29 @@ int parseSpriteName(std::string &name)
return id;
}
+int parseDirectionName(std::string name)
+{
+ int id = -1;
+ if (name == "down")
+ id = DIRECTION_DOWN;
+ else if (name == "downleft" || name == "leftdown")
+ id = DIRECTION_DOWNLEFT;
+ else if (name == "left")
+ id = DIRECTION_LEFT;
+ else if (name == "upleft" || name == "leftup")
+ id = DIRECTION_UPLEFT;
+ else if (name == "up")
+ id = DIRECTION_UP;
+ else if (name == "upright" || name == "rightup")
+ id = DIRECTION_UPRIGHT;
+ else if (name == "right")
+ id = DIRECTION_RIGHT;
+ else if (name == "downright" || name == "rightdown")
+ id = DIRECTION_DOWNRIGHT;
+
+ return id;
+}
+
void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node)
{
std::string gender = XML::getProperty(node, "gender", "unisex");
@@ -588,8 +612,10 @@ 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));
+ int direction = parseDirectionName(XML::getProperty(
+ replaceNode, "direction", "all"));
+ std::map<int, int> *mapList = itemInfo->addReplaceSprite(
+ parseSpriteName(removeSprite), direction);
itemInfo->setRemoveSprites();
@@ -599,7 +625,7 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode)
{
int from = XML::getProperty(itemNode, "from", 0);
int to = XML::getProperty(itemNode, "to", 1);
- mapList[from] = to;
+ (*mapList)[from] = to;
}
}
}
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 3eea45360..70c577da2 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -25,11 +25,62 @@
#include "resources/itemdb.h"
#include "configuration.h"
+#include "utils/dtor.h"
+
#include <set>
#include <map>
#include "debug.h"
+
+ItemInfo::ItemInfo(ItemInfo &info)
+{
+ mType = info.mType;
+ mWeight = info.mWeight;
+ mView = info.mView;
+ mId = info.mId;
+ mDrawBefore = info.mDrawBefore;
+ mDrawAfter = info.mDrawAfter;
+ mDrawPriority = info.mDrawPriority;
+ mIsRemoveSprites = info.mIsRemoveSprites;
+ mAttackAction = info.mAttackAction;
+ mAttackRange = info.mAttackRange;
+ mColors = info.mColors;
+ mColorList = info.mColorList;
+ mHitEffectId = info.mHitEffectId;
+ mCriticalHitEffectId = info.mCriticalHitEffectId;
+ for (int f = 0; f < 9; f ++)
+ mSpriteToItemReplaceMap[f] = 0;
+}
+
+ItemInfo::ItemInfo() :
+ mType(ITEM_UNUSABLE),
+ mWeight(0),
+ mView(0),
+ mId(0),
+ mDrawBefore(-1),
+ mDrawAfter(-1),
+ mDrawPriority(0),
+ mIsRemoveSprites(false),
+ mAttackAction(SpriteAction::INVALID),
+ mAttackRange(0),
+ mColors(0),
+ mColorList(""),
+ mHitEffectId(0),
+ mCriticalHitEffectId(0)
+{
+ for (int f = 0; f < 9; f ++)
+ mSpriteToItemReplaceMap[f] = 0;
+}
+
+ItemInfo::~ItemInfo()
+{
+ delete_all(mSpriteToItemReplaceList);
+ mSpriteToItemReplaceList.clear();
+ for (int f = 0;f < 9; f ++)
+ mSpriteToItemReplaceMap[f] = 0;
+}
+
const std::string &ItemInfo::getSprite(Gender gender) const
{
if (mView)
@@ -73,17 +124,45 @@ const std::string &ItemInfo::getSound(EquipmentSoundEvent event) const
return i->second.size() > 0 ? i->second[rand() % i->second.size()] : empty;
}
-std::map<int, int> &ItemInfo::addReplaceSprite(int sprite)
+std::map<int, int> *ItemInfo::addReplaceSprite(int sprite, int direction)
{
- std::map<int, std::map<int, int> >::iterator it
- = mSpriteToItemReplaceMap.find(sprite);
- if (it == mSpriteToItemReplaceMap.end())
+ 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 < 0 || direction >= 9)
+ return 0;
+
+ SpriteToItemMap *spMap = mSpriteToItemReplaceMap[direction];
+
+ if (!spMap)
+ {
+ spMap = new SpriteToItemMap();
+ mSpriteToItemReplaceMap[direction] = spMap;
+ mSpriteToItemReplaceList.push_back(spMap);
+ }
+
+ SpriteToItemMap::iterator it = spMap->find(sprite);
+ if (it == spMap->end())
{
std::map<int, int> tmp;
- mSpriteToItemReplaceMap[sprite] = tmp;
- it = mSpriteToItemReplaceMap.find(sprite);
+ (*mSpriteToItemReplaceMap[direction])[sprite] = tmp;
+ it = mSpriteToItemReplaceMap[direction]->find(sprite);
}
- return it->second;
+ return &it->second;
}
void ItemInfo::setColorsList(std::string name)
@@ -145,3 +224,20 @@ const std::string ItemInfo::replaceColors(std::string str,
return replaceAll(str, "%Color%", name);
}
+
+SpriteToItemMap *ItemInfo::getSpriteToItemReplaceMap(int direction) const
+{
+ if (direction < 0 || direction >= 9)
+ return 0;
+
+ SpriteToItemMap *spMap = mSpriteToItemReplaceMap[direction];
+ if (spMap)
+ return spMap;
+ if (direction == DIRECTION_UPLEFT || direction == DIRECTION_UPRIGHT)
+ return mSpriteToItemReplaceMap[DIRECTION_UP];
+
+ if (direction == DIRECTION_DOWNLEFT || direction == DIRECTION_DOWNRIGHT)
+ return mSpriteToItemReplaceMap[DIRECTION_DOWN];
+
+ return 0;
+}
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index d0a577f6d..b977a94ce 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -92,6 +92,9 @@ enum ItemType
ITEM_SPRITE_HAIR // 15
};
+// sprite, <itemfrom, itemto>
+typedef std::map<int, std::map<int, int> > SpriteToItemMap;
+
/**
* Defines a class for storing item infos. This includes information used when
* the item is equipped.
@@ -102,23 +105,11 @@ class ItemInfo
/**
* Constructor.
*/
- ItemInfo():
- mType(ITEM_UNUSABLE),
- mWeight(0),
- mView(0),
- mId(0),
- mDrawBefore(-1),
- mDrawAfter(-1),
- mDrawPriority(0),
- mIsRemoveSprites(false),
- mAttackAction(SpriteAction::INVALID),
- mAttackRange(0),
- mColors(0),
- mColorList(""),
- mHitEffectId(0),
- mCriticalHitEffectId(0)
- {
- }
+ ItemInfo();
+
+ ItemInfo(ItemInfo &info);
+
+ ~ItemInfo();
void setId(int id)
{ mId = id; }
@@ -253,10 +244,9 @@ class ItemInfo
int getReplaceToSpriteId(int id) const;
- std::map<int, int> &addReplaceSprite(int sprite);
+ std::map<int, int> *addReplaceSprite(int sprite, int direction);
- std::map<int, std::map<int, int> > getSpriteToItemReplaceMap() const
- { return mSpriteToItemReplaceMap; }
+ SpriteToItemMap *getSpriteToItemReplaceMap(int directions) const;
std::string getDyeString(int color) const;
@@ -285,8 +275,10 @@ class ItemInfo
int mDrawAfter;
int mDrawPriority;
bool mIsRemoveSprites;
- // sprite, <itemfrom, itemto>
- std::map<int, std::map<int, int> > mSpriteToItemReplaceMap;
+ // sprite, <itemfrom, itemto> [direction]
+ SpriteToItemMap *mSpriteToItemReplaceMap[9];
+
+ std::vector<SpriteToItemMap*> mSpriteToItemReplaceList;
// Equipment related members.
/** Attack type, in case of weapon.
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index 475ab2e25..8fa64e7b9 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -92,14 +92,14 @@ namespace SpriteAction
enum SpriteDirection
{
DIRECTION_DEFAULT = 0,
- DIRECTION_UP,
- DIRECTION_DOWN,
- DIRECTION_LEFT,
- DIRECTION_RIGHT,
- DIRECTION_UPLEFT,
- DIRECTION_UPRIGHT,
- DIRECTION_DOWNLEFT,
- DIRECTION_DOWNRIGHT,
+ DIRECTION_UP = 1,
+ DIRECTION_DOWN = 2,
+ DIRECTION_LEFT = 3,
+ DIRECTION_RIGHT = 4,
+ DIRECTION_UPLEFT = 5,
+ DIRECTION_UPRIGHT = 6,
+ DIRECTION_DOWNLEFT = 7,
+ DIRECTION_DOWNRIGHT = 8,
DIRECTION_INVALID
};