summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/action.cpp13
-rw-r--r--src/resources/action.h6
-rw-r--r--src/resources/animation.cpp14
-rw-r--r--src/resources/animation.h8
-rw-r--r--src/resources/dye.cpp2
-rw-r--r--src/resources/emotedb.cpp1
-rw-r--r--src/resources/emotedb.h1
-rw-r--r--src/resources/image.cpp18
-rw-r--r--src/resources/specialdb.cpp1
-rw-r--r--src/resources/spritedef.cpp22
-rw-r--r--src/resources/spritedef.h7
11 files changed, 83 insertions, 10 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp
index e1f88ecb7..6c799cdfa 100644
--- a/src/resources/action.cpp
+++ b/src/resources/action.cpp
@@ -69,3 +69,16 @@ void Action::setAnimation(int direction, Animation *animation)
{
mAnimations[direction] = animation;
}
+
+void Action::setLastFrameDelay(int delay)
+{
+ AnimationIter it = mAnimations.begin();
+ AnimationIter it_end = mAnimations.end();
+ for (; it != it_end; ++ it)
+ {
+ Animation *animation = (*it).second;
+ if (!animation)
+ continue;
+ animation->setLastFrameDelay(delay);
+ }
+}
diff --git a/src/resources/action.h b/src/resources/action.h
index 3951cc02c..f9c5da75b 100644
--- a/src/resources/action.h
+++ b/src/resources/action.h
@@ -29,6 +29,7 @@
class Animation;
+
/**
* An action consists of several animations, one for each direction.
*/
@@ -49,9 +50,12 @@ class Action
void setNumber(unsigned n)
{ mNumber = n; }
+ void setLastFrameDelay(int delay);
+
protected:
typedef std::map<int, Animation*> Animations;
- typedef Animations::iterator AnimationIterator;
+ typedef Animations::iterator AnimationIter;
+
Animations mAnimations;
unsigned mNumber;
};
diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp
index 1c1da6ca5..388c1301e 100644
--- a/src/resources/animation.cpp
+++ b/src/resources/animation.cpp
@@ -69,3 +69,17 @@ void Animation::addGoto(std::string name, int rand)
Frame frame = { nullptr, 0, 0, 0, rand, Frame::GOTO, name };
mFrames.push_back(frame);
}
+
+void Animation::setLastFrameDelay(int delay)
+{
+ FramesRevIter it = mFrames.rbegin();
+ FramesRevIter it_end = mFrames.rend();
+ for (; it != it_end; ++ it)
+ {
+ if ((*it).type == Frame::ANIMATION && (*it).image)
+ {
+ (*it).delay = delay;
+ break;
+ }
+ }
+}
diff --git a/src/resources/animation.h b/src/resources/animation.h
index 33bfd76e9..53e9adbea 100644
--- a/src/resources/animation.h
+++ b/src/resources/animation.h
@@ -102,13 +102,19 @@ class Animation
void addGoto(std::string name, int rand);
+ void setLastFrameDelay(int delay);
+
/**
* Determines whether the given animation frame is a terminator.
*/
static bool isTerminator(const Frame &phase);
protected:
- std::vector<Frame> mFrames;
+ typedef std::vector<Frame> Frames;
+ typedef Frames::iterator FramesIter;
+ typedef Frames::reverse_iterator FramesRevIter;
+
+ Frames mFrames;
int mDuration;
};
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 6800c5170..eec5916c4 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -309,7 +309,7 @@ void Dye::instantiate(std::string &target, const std::string &palettes)
{
s << palettes.substr(pal_pos);
s << target.substr(next_pos);
- pal_pos = std::string::npos;
+ //pal_pos = std::string::npos;
break;
}
s << palettes.substr(pal_pos, pal_next_pos - pal_pos);
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index d6c01af6d..4fe036528 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -1,6 +1,7 @@
/*
* Emote database
* Copyright (C) 2009 Aethyra Development Team
+ * Copyright (C) 2011-2012 The ManaPlus developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h
index 94d97a872..f739b1ed0 100644
--- a/src/resources/emotedb.h
+++ b/src/resources/emotedb.h
@@ -1,6 +1,7 @@
/*
* Emote database
* Copyright (C) 2009 Aethyra Development Team
+ * Copyright (C) 2011-2012 The ManaPlus developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 0ac11f114..1e2bd6b51 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -885,10 +885,20 @@ SubImage::SubImage(Image *parent, SDL_Surface *image,
mBounds.y = static_cast<short>(y);
mBounds.w = static_cast<Uint16>(width);
mBounds.h = static_cast<Uint16>(height);
- mInternalBounds.x = mParent->mBounds.x;
- mInternalBounds.y = mParent->mBounds.y;
- mInternalBounds.w = mParent->mBounds.w;
- mInternalBounds.h = mParent->mBounds.h;
+ if (mParent)
+ {
+ mInternalBounds.x = mParent->mBounds.x;
+ mInternalBounds.y = mParent->mBounds.y;
+ mInternalBounds.w = mParent->mBounds.w;
+ mInternalBounds.h = mParent->mBounds.h;
+ }
+ else
+ {
+ mInternalBounds.x = 0;
+ mInternalBounds.y = 0;
+ mInternalBounds.w = 1;
+ mInternalBounds.h = 1;
+ }
mUseAlphaCache = false;
}
diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp
index 664d2c73d..50ea773bc 100644
--- a/src/resources/specialdb.cpp
+++ b/src/resources/specialdb.cpp
@@ -129,5 +129,4 @@ SpecialInfo *SpecialDB::get(int id)
return nullptr;
else
return i->second;
- return nullptr;
}
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 0d9b95f6f..02b46f1cf 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -36,6 +36,7 @@
#include "debug.h"
SpriteReference *SpriteReference::Empty = nullptr;
+extern int serverVersion;
Action *SpriteDef::getAction(std::string action, unsigned num) const
{
@@ -99,13 +100,30 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant)
def->mProcessedFiles.insert(animationFile);
def->loadSprite(rootNode, variant, palettes);
def->substituteActions();
+ if (serverVersion < 1)
+ def->fixDeadAction();
return def;
}
+void SpriteDef::fixDeadAction()
+{
+ ActionsIter it = mActions.begin();
+ ActionsIter it_end = mActions.end();
+ for (; it != it_end; ++ it)
+ {
+ ActionMap *d = (*it).second;
+ if (!d)
+ continue;
+ ActionMap::iterator i = d->find("dead");
+ if (i != d->end() && i->second)
+ (i->second)->setLastFrameDelay(0);
+ }
+}
+
void SpriteDef::substituteAction(std::string complete, std::string with)
{
- Actions::const_iterator it = mActions.begin();
- Actions::const_iterator it_end = mActions.end();
+ ActionsConstIter it = mActions.begin();
+ ActionsConstIter it_end = mActions.end();
for (; it != it_end; ++ it)
{
ActionMap *d = (*it).second;
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index 0490bdcb3..e167cf188 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -176,6 +176,11 @@ class SpriteDef : public Resource
void substituteActions();
/**
+ * Fix bad timeout in last dead action frame
+ */
+ void fixDeadAction();
+
+ /**
* When there are no animations defined for the action "complete", its
* animations become a copy of those of the action "with".
*/
@@ -185,6 +190,8 @@ class SpriteDef : public Resource
typedef ImageSets::iterator ImageSetIterator;
typedef std::map<std::string, Action*> ActionMap;
typedef std::map<unsigned, ActionMap*> Actions;
+ typedef Actions::const_iterator ActionsConstIter;
+ typedef Actions::iterator ActionsIter;
ImageSets mImageSets;
Actions mActions;