diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2011-03-14 00:05:26 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2011-03-15 22:53:50 +0100 |
commit | 24f2b307f089558276d1d526f1288d229af11678 (patch) | |
tree | 5fd694e5efda0939542340ba4e691e3374172345 | |
parent | 9f1078ec63298f6e7463125370d5645e0cc49f2b (diff) | |
download | manaserv-24f2b307f089558276d1d526f1288d229af11678.tar.gz manaserv-24f2b307f089558276d1d526f1288d229af11678.tar.bz2 manaserv-24f2b307f089558276d1d526f1288d229af11678.tar.xz manaserv-24f2b307f089558276d1d526f1288d229af11678.zip |
Some code style cleanups in AutoAttack class
-rw-r--r-- | src/game-server/autoattack.cpp | 24 | ||||
-rw-r--r-- | src/game-server/autoattack.h | 82 | ||||
-rw-r--r-- | src/game-server/monster.h | 2 |
3 files changed, 77 insertions, 31 deletions
diff --git a/src/game-server/autoattack.cpp b/src/game-server/autoattack.cpp index b8c8a165..d433b421 100644 --- a/src/game-server/autoattack.cpp +++ b/src/game-server/autoattack.cpp @@ -20,9 +20,9 @@ #include "autoattack.h" -void AutoAttacks::add(AutoAttack n) +void AutoAttacks::add(const AutoAttack &autoAttack) { - mAutoAttacks.push_back(n); + mAutoAttacks.push_back(autoAttack); // Slow, but safe. mAutoAttacks.sort(); } @@ -34,26 +34,38 @@ void AutoAttacks::clear() void AutoAttacks::stop() { - for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin(); it != mAutoAttacks.end(); ++it) + for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin(); + it != mAutoAttacks.end(); ++it) + { it->halt(); + } mActive = false; } void AutoAttacks::start() { - for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin(); it != mAutoAttacks.end(); ++it) + for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin(); + it != mAutoAttacks.end(); ++it) + { it->softReset(); + } mActive = true; } void AutoAttacks::tick(std::list<AutoAttack> *ret) { - for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin(); it != mAutoAttacks.end(); ++it) + for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin(); + it != mAutoAttacks.end(); ++it) + { if (it->tick()) { if (mActive) it->reset(); else it->halt(); - } else if (ret && it->isReady()) + } + else if (ret && it->isReady()) + { ret->push_back(*it); + } + } } diff --git a/src/game-server/autoattack.h b/src/game-server/autoattack.h index 8be5c608..2ce5c71d 100644 --- a/src/game-server/autoattack.h +++ b/src/game-server/autoattack.h @@ -27,7 +27,7 @@ /** * Methods of damage calculation */ -enum DMG_TY +enum DamageType { DAMAGE_PHYSICAL = 0, DAMAGE_MAGICAL, @@ -45,15 +45,25 @@ struct Damage unsigned short delta; /**< Additional damage when lucky. */ unsigned short cth; /**< Chance to hit. Opposes the evade attribute. */ unsigned char element; /**< Elemental damage. */ - DMG_TY type; /**< Damage type: Physical or magical? */ + DamageType type; /**< Damage type: Physical or magical? */ unsigned trueStrike : 1; /**< Override dodge calculation */ std::list<size_t> usedSkills; /**< Skills used by source (needed for exp calculation) */ unsigned short range; /**< Maximum distance that this attack can be used from */ - Damage(unsigned short base, unsigned short delta, unsigned short cth, - unsigned char element, DMG_TY type = DAMAGE_OTHER, + + Damage(unsigned short base, + unsigned short delta, + unsigned short cth, + unsigned char element, + DamageType type = DAMAGE_OTHER, unsigned short range = std::numeric_limits<unsigned short>::max()) - : base(base), delta(delta), cth(cth), element(element), type(type), - trueStrike(false), range(range) {} + : base(base) + , delta(delta) + , cth(cth) + , element(element) + , type(type) + , trueStrike(false) + , range(range) + {} }; /** @@ -64,34 +74,55 @@ class AutoAttack { public: AutoAttack(Damage &damage, unsigned int delay, unsigned int warmup) - : mDamage(damage), mTimer(0), mAspd(delay), - mWarmup(warmup && warmup < delay ? warmup : delay >> 2) {} + : mDamage(damage) + , mTimer(0) + , mAspd(delay) + , mWarmup(warmup && warmup < delay ? warmup : delay >> 2) + {} + unsigned short getTimer() const { return mTimer; } bool tick() { return mTimer ? !--mTimer : false; } void reset() { mTimer = mAspd; } - bool operator<(const AutoAttack &rhs) const - { return mTimer < rhs.getTimer(); } - bool isReady() const { return !(mTimer - mWarmup); } - void halt() { if (mTimer >= mWarmup) mTimer = 0; } void softReset() { if (mTimer >= mWarmup) mTimer = mAspd; } + void halt() { if (mTimer >= mWarmup) mTimer = 0; } + bool isReady() const { return !(mTimer - mWarmup); } + + bool operator<(const AutoAttack &rhs) const + { return mTimer < rhs.mTimer; } + const Damage &getDamage() const { return mDamage; } + private: Damage mDamage; + /** * Internal timer that is modified each tick. + * * When > warmup, the attack is warming up before a strike - * When = warmup, the attack triggers, dealing damage to the target *if* the target is still in range. - * (The attack is canceled when the target moves out of range before the attack can hit, there should be a trigger for scripts here too) - * (Should the character automatically persue when the target is still visible in this case?) - * When < warmup, the attack is cooling down after a strike. When in cooldown, the timer should not be soft-reset. - * When 0, the attack is inactive (the character is doing something other than attacking and the attack is not in cooldown) + * When = warmup, the attack triggers, dealing damage to the target + * *if* the target is still in range. + * (The attack is canceled when the target moves out of range before + * the attack can hit, there should be a trigger for scripts here + * too) + * (Should the character automatically persue when the target is still + * visible in this case?) + * When < warmup, the attack is cooling down after a strike. When in + * cooldown, the timer should not be soft-reset. + * When 0, the attack is inactive (the character is doing something + * other than attacking and the attack is not in cooldown) */ unsigned short mTimer; - unsigned short mAspd; // Value to reset the timer to (warmup + cooldown) + + /** + * Value to reset the timer to (warmup + cooldown) + */ + unsigned short mAspd; + /** * Pre-attack delay tick. * This MUST be smaller than or equal to the aspd! - * So the attack triggers where timer == warmup, having gone through aspd - warmup ticks. + * So the attack triggers where timer == warmup, having gone through + * aspd - warmup ticks. */ unsigned short mWarmup; }; @@ -102,19 +133,22 @@ class AutoAttack class AutoAttacks { public: - /** * Whether the being has at least one auto attack that is ready. */ - void add(AutoAttack n); + void add(const AutoAttack &); void clear(); // Wipe the list completely (used in place of remove for now; FIXME) void start(); void stop(); // If the character does some action other than attacking, reset all warmups (NOT cooldowns!) void tick(std::list<AutoAttack> *ret = 0); - private: - bool mActive; /**< Marks whether or not to keep auto-attacking. Cooldowns still need to be processed when false. */ - std::list < AutoAttack > mAutoAttacks; + private: + /** + * Marks whether or not to keep auto-attacking. Cooldowns still need + * to be processed when false. + */ + bool mActive; + std::list<AutoAttack> mAutoAttacks; }; #endif // AUTOATTACK_H diff --git a/src/game-server/monster.h b/src/game-server/monster.h index 3981604f..ff467167 100644 --- a/src/game-server/monster.h +++ b/src/game-server/monster.h @@ -53,7 +53,7 @@ struct MonsterAttack int priority; float damageFactor; int element; - DMG_TY type; + DamageType type; int preDelay; int aftDelay; int range; |