summaryrefslogtreecommitdiff
path: root/src/game-server/being.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-12-05 18:38:28 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2009-12-05 19:01:54 +0100
commitef1c2e60facf32f9f55a7bf8dcfb59f7654f18cc (patch)
treed16da8b202681e721276dd899c4d3f4c65fbc026 /src/game-server/being.cpp
parent6f0a9c556b099c0658fb3a826593a81194efae27 (diff)
downloadmanaserv-ef1c2e60facf32f9f55a7bf8dcfb59f7654f18cc.tar.gz
manaserv-ef1c2e60facf32f9f55a7bf8dcfb59f7654f18cc.tar.bz2
manaserv-ef1c2e60facf32f9f55a7bf8dcfb59f7654f18cc.tar.xz
manaserv-ef1c2e60facf32f9f55a7bf8dcfb59f7654f18cc.zip
(refactoring) Replaced various differen tick counting constructs in the being classes with a common timer infrastructure
Diffstat (limited to 'src/game-server/being.cpp')
-rw-r--r--src/game-server/being.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index de7ac69f..fe0190de 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -36,8 +36,7 @@ Being::Being(ThingType type):
mAction(STAND),
mTarget(NULL),
mSpeed(0),
- mDirection(0),
- mHpRegenTimer(0)
+ mDirection(0)
{
Attribute attr = { 0, 0 };
mAttributes.resize(NB_BEING_ATTRIBUTES + CHAR_ATTR_NB, attr);
@@ -356,14 +355,20 @@ void Being::setStatusEffectTime(int id, int time)
void Being::update()
{
+ //update timers
+ for (Timers::iterator i = mTimers.begin(); i != mTimers.end(); i++)
+ {
+ if (i->second > -1) i->second--;
+ }
+
int oldHP = getModifiedAttribute(BASE_ATTR_HP);
int newHP = oldHP;
int maxHP = getAttribute(BASE_ATTR_HP);
// Regenerate HP
- if (mAction != DEAD && ++mHpRegenTimer >= TICKS_PER_HP_REGENERATION)
+ if (mAction != DEAD && !isTimerRunning(T_B_HP_REGEN))
{
- mHpRegenTimer = 0;
+ setTimerHard(T_B_HP_REGEN, TICKS_PER_HP_REGENERATION);
newHP += getModifiedAttribute(BASE_ATTR_HP_REGEN);
}
// Cap HP at maximum
@@ -416,3 +421,39 @@ void Being::update()
died();
}
}
+
+void Being::setTimerSoft(TimerID id, int value)
+{
+ Timers::iterator i = mTimers.find(id);
+ if (i == mTimers.end())
+ {
+ mTimers[id] = value;
+ }
+ else if (i->second < value)
+ {
+ i->second = value;
+ }
+}
+
+void Being::setTimerHard(TimerID id, int value)
+{
+ mTimers[id] = value;
+}
+
+int Being::getTimer(TimerID id)
+{
+ Timers::iterator i = mTimers.find(id);
+ if (i == mTimers.end()) return -1;
+ return i->second;
+}
+
+bool Being::isTimerRunning(TimerID id)
+{
+ return (getTimer(id) > 0);
+}
+
+bool Being::isTimerJustFinished(TimerID id)
+{
+ return (getTimer(id) == 0);
+}
+