summaryrefslogtreecommitdiff
path: root/src/game-server/being.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-27 00:18:31 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-04-14 12:21:58 +0200
commit387a04cf3c38e19fd8050e39d0f219e5f07257fd (patch)
tree0dbdeb2679a5c58303b6e48766bee7fa4520a174 /src/game-server/being.cpp
parentdcd66debbe519403d3b8f7bf30313fbdee71fe6c (diff)
downloadmanaserv-387a04cf3c38e19fd8050e39d0f219e5f07257fd.tar.gz
manaserv-387a04cf3c38e19fd8050e39d0f219e5f07257fd.tar.bz2
manaserv-387a04cf3c38e19fd8050e39d0f219e5f07257fd.tar.xz
manaserv-387a04cf3c38e19fd8050e39d0f219e5f07257fd.zip
Introduced a Timeout class for counting down without counting
The timeout remembers a reference point of time against which it can check how much time is remaining. Reviewed-by: Erik Schilling Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/game-server/being.cpp')
-rw-r--r--src/game-server/being.cpp49
1 files changed, 4 insertions, 45 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index bbe07828..8c2b08c7 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -126,8 +126,8 @@ int Being::damage(Actor * /* source */, const Damage &damage)
<< mAttributes.at(ATTR_MAX_HP).getModifiedAttribute());
setAttribute(ATTR_HP, HP.getBase() - HPloss);
// No HP regen after being hit if this is set.
- setTimerSoft(T_B_HP_REGEN,
- Configuration::getValue("game_hpRegenBreakAfterHit", 0));
+ mHealthRegenerationTimeout.setSoft(
+ Configuration::getValue("game_hpRegenBreakAfterHit", 0));
}
else
{
@@ -638,21 +638,14 @@ 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(ATTR_HP);
int newHP = oldHP;
int maxHP = getModifiedAttribute(ATTR_MAX_HP);
// Regenerate HP
- if (mAction != DEAD && !isTimerRunning(T_B_HP_REGEN))
+ if (mAction != DEAD && mHealthRegenerationTimeout.expired())
{
- setTimerHard(T_B_HP_REGEN, TICKS_PER_HP_REGENERATION);
+ mHealthRegenerationTimeout.set(TICKS_PER_HP_REGENERATION);
newHP += getModifiedAttribute(ATTR_HP_REGEN);
}
// Cap HP at maximum
@@ -710,40 +703,6 @@ void Being::inserted()
mOld = getPosition();
}
-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) const
-{
- Timers::const_iterator i = mTimers.find(id);
- return (i == mTimers.end()) ? -1 : i->second;
-}
-
-bool Being::isTimerRunning(TimerID id) const
-{
- return getTimer(id) > 0;
-}
-
-bool Being::isTimerJustFinished(TimerID id) const
-{
- return getTimer(id) == 0;
-}
-
void Being::setGender(BeingGender gender)
{
mGender = gender;