summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-06-09 13:37:16 -0600
committerJared Adams <jaxad0127@gmail.com>2010-06-09 15:14:18 -0600
commit35e024b85a5448cba235fa400f9412fd4e289ec0 (patch)
tree58736ebdff483bf7db1398855e514a735ddf075e /src
parentec980b3c586fc64d02ad02f31497013908056d52 (diff)
downloadmana-35e024b85a5448cba235fa400f9412fd4e289ec0.tar.gz
mana-35e024b85a5448cba235fa400f9412fd4e289ec0.tar.bz2
mana-35e024b85a5448cba235fa400f9412fd4e289ec0.tar.xz
mana-35e024b85a5448cba235fa400f9412fd4e289ec0.zip
Fix dead Beings not being removed using tmwAthena
Rename mWalkTime to mActionTime in Being and have Being manage death. Reviewed-by: 4144
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp30
-rw-r--r--src/being.h17
-rw-r--r--src/beingmanager.cpp37
-rw-r--r--src/beingmanager.h6
-rw-r--r--src/gui/viewport.cpp4
-rw-r--r--src/localplayer.cpp2
-rw-r--r--src/net/tmwa/beinghandler.cpp4
7 files changed, 55 insertions, 45 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 6bef136b..0bf90558 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -22,6 +22,7 @@
#include "being.h"
#include "animatedsprite.h"
+#include "beingmanager.h"
#include "client.h"
#include "configuration.h"
#include "effectmanager.h"
@@ -50,6 +51,7 @@
#include "gui/userpalette.h"
#include "net/charhandler.h"
+#include "net/gamehandler.h"
#include "net/net.h"
#include "net/npchandler.h"
#include "net/playerhandler.h"
@@ -82,7 +84,7 @@ int Being::mNumberOfHairstyles = 1;
Being::Being(int id, Type type, int subtype, Map *map):
ActorSprite(id),
mInfo(BeingInfo::Unknown),
- mWalkTime(0),
+ mActionTime(0),
mEmotion(0), mEmotionTime(0),
mSpeechTime(0),
mAttackType(1),
@@ -250,7 +252,7 @@ void Being::setPath(const Path &path)
mAction != WALK && mAction != DEAD)
{
nextTile();
- mWalkTime = tick_time;
+ mActionTime = tick_time;
}
}
@@ -381,7 +383,7 @@ void Being::handleAttack(Being *victim, int damage, AttackType type)
if (Net::getNetworkType() == ServerInfo::TMWATHENA)
{
reset();
- mWalkTime = tick_time;
+ mActionTime = tick_time;
}
sound.playSfx(mInfo->getSound((damage > 0) ?
@@ -614,6 +616,9 @@ void Being::setAction(Action action, int attackType)
play(currentAction);
mAction = action;
}
+
+ if (currentAction != ACTION_WALK)
+ mActionTime = tick_time;
}
void Being::setDirection(Uint8 direction)
@@ -675,7 +680,7 @@ void Being::nextTile()
mX = pos.x;
mY = pos.y;
setAction(WALK);
- mWalkTime += (int)(mWalkSpeed.x / 10);
+ mActionTime += (int)(mWalkSpeed.x / 10);
}
int Being::getCollisionRadius() const
@@ -786,7 +791,7 @@ void Being::logic()
break;
case WALK:
- if ((int) ((get_elapsed_time(mWalkTime) * frameCount)
+ if ((int) ((get_elapsed_time(mActionTime) * frameCount)
/ getWalkSpeed().x) >= frameCount)
nextTile();
break;
@@ -795,7 +800,7 @@ void Being::logic()
int rotation = 0;
std::string particleEffect = "";
- int curFrame = (get_elapsed_time(mWalkTime) * frameCount)
+ int curFrame = (get_elapsed_time(mActionTime) * frameCount)
/ mAttackSpeed;
//attack particle effect
@@ -851,6 +856,15 @@ void Being::logic()
}
ActorSprite::logic();
+
+ int frameCount = getFrameCount();
+ if (frameCount < 10)
+ frameCount = 10;
+
+ if (!isAlive() && Net::getGameHandler()->removeDeadBeings() &&
+ (int) ((get_elapsed_time(mActionTime)
+ / getWalkSpeed().x) >= frameCount))
+ beingManager->scheduleDelete(this);
}
void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY)
@@ -932,9 +946,9 @@ int Being::getOffset(char pos, char neg) const
if (mMap)
{
offset = (pos == LEFT && neg == RIGHT) ?
- (int)((get_elapsed_time(mWalkTime)
+ (int)((get_elapsed_time(mActionTime)
* mMap->getTileWidth()) / mWalkSpeed.x) :
- (int)((get_elapsed_time(mWalkTime)
+ (int)((get_elapsed_time(mActionTime)
* mMap->getTileHeight()) / mWalkSpeed.y);
}
diff --git a/src/being.h b/src/being.h
index 4e7016c1..75bb6c22 100644
--- a/src/being.h
+++ b/src/being.h
@@ -121,19 +121,15 @@ class Being : public ActorSprite, public ConfigListener
void clearPath();
/**
- * Returns the walk time.
- * Used to know which frame to display and trigger
- * the next Tile step.
- * TODO: Used by eAthena only?
+ * Returns the time spent in the current action.
*/
- int getWalkTime() const { return mWalkTime; }
+ int getActionTime() const { return mActionTime; }
/**
- * Set the current WalkTime value.
- * TODO: Used by eAthena only?
+ * Set the current action time.
* @see Ea::BeingHandler that set it to tick time.
*/
- void setWalkTime(int walkTime) { mWalkTime = walkTime; }
+ void setActionTime(int actionTime) { mActionTime = actionTime; }
/**
* Makes this being take the next tile of its path.
@@ -510,10 +506,7 @@ class Being : public ActorSprite, public ConfigListener
BeingInfo *mInfo;
- /** Used to trigger the nextStep (walking on next Tile)
- * TODO: Used by eAthena only?
- */
- int mWalkTime;
+ int mActionTime; /**< Time spent in current action */
int mEmotion; /**< Currently showing emotion */
int mEmotionTime; /**< Time until emotion disappears */
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 79591ce6..b2a9f07b 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -25,9 +25,6 @@
#include "gui/viewport.h"
-#include "net/gamehandler.h"
-#include "net/net.h"
-
#include "utils/stringutils.h"
#include "utils/dtor.h"
@@ -83,6 +80,7 @@ Being *BeingManager::createBeing(int id, ActorSprite::Type type, int subtype)
void BeingManager::destroyBeing(Being *being)
{
mBeings.remove(being);
+ mDeleteBeings.remove(being);
viewport->clearHoverBeing(being);
delete being;
}
@@ -158,25 +156,18 @@ const Beings &BeingManager::getAll() const
void BeingManager::logic()
{
- Beings::iterator i = mBeings.begin();
- while (i != mBeings.end())
- {
- Being *being = (*i);
-
- being->logic();
+ Beings::iterator it, it_end;
+ for (it = mBeings.begin(), it_end = mBeings.end(); it != it_end; it++)
+ (*it)->logic();
- if (!being->isAlive() &&
- Net::getGameHandler()->removeDeadBeings() &&
- being->getCurrentFrame() >= 20)
- {
- delete being;
- i = mBeings.erase(i);
- }
- else
- {
- ++i;
- }
+ for (it = mDeleteBeings.begin(), it_end = mDeleteBeings.end();
+ it != it_end; it++)
+ {
+ mBeings.remove(*it);
+ delete *it;
}
+
+ mDeleteBeings.clear();
}
void BeingManager::clear()
@@ -189,6 +180,7 @@ void BeingManager::clear()
delete_all(mBeings);
mBeings.clear();
+ mDeleteBeings.clear();
if (player_node)
mBeings.push_back(player_node);
@@ -277,3 +269,8 @@ void BeingManager::updatePlayerNames()
++i;
}
}
+
+void BeingManager::scheduleDelete(Being *being)
+{
+ mDeleteBeings.push_back(being);
+}
diff --git a/src/beingmanager.h b/src/beingmanager.h
index 00575041..d4a39168 100644
--- a/src/beingmanager.h
+++ b/src/beingmanager.h
@@ -128,8 +128,14 @@ class BeingManager
void updatePlayerNames();
+ /**
+ * Destroys the given Being at the end of BeingManager::logic
+ */
+ void scheduleDelete(Being *being);
+
protected:
Beings mBeings;
+ Beings mDeleteBeings;
Map *mMap;
};
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 1c793cdd..3e1f2581 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -444,9 +444,9 @@ void Viewport::mouseDragged(gcn::MouseEvent &event)
}
else
{
- if (mLocalWalkTime != player_node->getWalkTime())
+ if (mLocalWalkTime != player_node->getActionTime())
{
- mLocalWalkTime = player_node->getWalkTime();
+ mLocalWalkTime = player_node->getActionTime();
int destX = (event.getX() + mPixelViewX + 16) /
mMap->getTileWidth();
int destY = (event.getY() + mPixelViewY + 16) /
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 7bf339c6..96062867 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -1010,7 +1010,7 @@ void LocalPlayer::attack(Being *target, bool keep)
setDirection(LEFT);
}
- mWalkTime = tick_time;
+ mActionTime = tick_time;
mTargetTime = tick_time;
}
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp
index d9caa719..0e89ad18 100644
--- a/src/net/tmwa/beinghandler.cpp
+++ b/src/net/tmwa/beinghandler.cpp
@@ -146,7 +146,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
if (msg.getId() == SMSG_BEING_VISIBLE)
{
dstBeing->clearPath();
- dstBeing->setWalkTime(tick_time);
+ dstBeing->setActionTime(tick_time);
dstBeing->setAction(Being::STAND);
}
@@ -615,7 +615,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
msg.readInt8(); // Lv
msg.readInt8(); // unknown
- dstBeing->setWalkTime(tick_time);
+ dstBeing->setActionTime(tick_time);
dstBeing->reset();
dstBeing->setStunMode(stunMode);