From fe116c52a7fafc3ad61d14263dd60bc8e7acecdd Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 6 Dec 2009 17:40:37 +0100 Subject: Made the Being timer accessors const --- src/game-server/being.cpp | 16 +++++++--------- src/game-server/being.hpp | 29 ++++++++++++++++++----------- 2 files changed, 25 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index fe0190de..a85cc974 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -440,20 +440,18 @@ void Being::setTimerHard(TimerID id, int value) mTimers[id] = value; } -int Being::getTimer(TimerID id) +int Being::getTimer(TimerID id) const { - Timers::iterator i = mTimers.find(id); - if (i == mTimers.end()) return -1; - return i->second; + Timers::const_iterator i = mTimers.find(id); + return (i == mTimers.end()) ? -1 : i->second; } -bool Being::isTimerRunning(TimerID id) +bool Being::isTimerRunning(TimerID id) const { - return (getTimer(id) > 0); + return getTimer(id) > 0; } -bool Being::isTimerJustFinished(TimerID id) +bool Being::isTimerJustFinished(TimerID id) const { - return (getTimer(id) == 0); + return getTimer(id) == 0; } - diff --git a/src/game-server/being.hpp b/src/game-server/being.hpp index 5335d37a..d0ca4be3 100644 --- a/src/game-server/being.hpp +++ b/src/game-server/being.hpp @@ -54,8 +54,6 @@ enum TimerID T_B_HP_REGEN // time until hp is regenerated again }; -typedef std::map Timers; - /** * Methods of damage calculation */ @@ -127,7 +125,6 @@ typedef std::vector Hits; class Being : public Actor { public: - /** * Moves enum for beings and actors for others players vision. * WARNING: Has to be in sync with the same enum in the Being class @@ -339,7 +336,7 @@ class Being : public Actor /** * Get Target */ - Being* getTarget() const + Being *getTarget() const { return mTarget; } /** @@ -357,15 +354,24 @@ class Being : public Actor Being *mTarget; Point mOld; /**< Old coordinates. */ Point mDst; /**< Target coordinates. */ + + /** Sets timer unless already higher. */ + void setTimerSoft(TimerID id, int value); + /** - * Timer stuff - */ - void setTimerSoft(TimerID id, int value); /**< sets timer unless already higher */ - void setTimerHard(TimerID id, int value); /**< sets timer even when already higher (when in doubt this one is faster)*/ - int getTimer(TimerID id); /**< returns number of ticks left on the timer */ - bool isTimerRunning(TimerID id); /**< true when timer exists and is > 0 */ - bool isTimerJustFinished(TimerID id); /**< true during the tick where the timer reaches 0 */ + * Sets timer even when already higher (when in doubt this one is + * faster) + */ + void setTimerHard(TimerID id, int value); + + /** Returns number of ticks left on the timer */ + int getTimer(TimerID id) const; + + /** Returns whether timer exists and is > 0 */ + bool isTimerRunning(TimerID id) const; + /** Returns whether the timer reached 0 in this tick */ + bool isTimerJustFinished(TimerID id) const; private: Being(const Being &rhs); @@ -379,6 +385,7 @@ class Being : public Actor Hits mHitsTaken; /**< List of punches taken since last update. */ AttributeModifiers mModifiers; /**< Currently modified attributes. */ + typedef std::map Timers; Timers mTimers; }; -- cgit v1.2.3-70-g09d2