diff --git a/lib/battle/CBattleInfoCallback.cpp b/lib/battle/CBattleInfoCallback.cpp index 59c6ecb9c..a48d59482 100644 --- a/lib/battle/CBattleInfoCallback.cpp +++ b/lib/battle/CBattleInfoCallback.cpp @@ -355,6 +355,8 @@ battle::Units CBattleInfoCallback::battleAliveUnits(ui8 side) const }); } +using namespace battle; + //T is battle::Unit descendant template const T * takeOneUnit(std::vector & allUnits, const int turn, int8_t & sideThatLastMoved, int phase) @@ -378,7 +380,7 @@ const T * takeOneUnit(std::vector & allUnits, const int turn, int8_t & switch(phase) { - case battle::NORMAL: // Faster first, attacker priority, higher slot first + case BattlePhases::NORMAL: // Faster first, attacker priority, higher slot first if(returnedUnit == nullptr || currentUnitInitiative > returnedUnitInitiative) { returnedUnit = currentUnit; @@ -400,8 +402,8 @@ const T * takeOneUnit(std::vector & allUnits, const int turn, int8_t & } } break; - case battle::WAIT_MORALE: // Slower first, higher slot first - case battle::WAIT: + case BattlePhases::WAIT_MORALE: // Slower first, higher slot first + case BattlePhases::WAIT: if(returnedUnit == nullptr || currentUnitInitiative < returnedUnitInitiative) { returnedUnit = currentUnit; @@ -452,12 +454,8 @@ void CBattleInfoCallback::battleGetTurnOrder(std::vector & turns, turns.emplace_back(); - // We'll split creatures with remaining movement to 4 buckets - // [0] SIEGE - turrets/catapult, - // [1] NORMAL - normal (unmoved) creatures, other war machines, - // [2] WAIT_MORALE - waited creatures that had morale, - // [3] WAIT - rest of waited creatures - std::array phases; // Access using BattlePhases enum + // We'll split creatures with remaining movement to 4 buckets (SIEGE, NORMAL, WAIT_MORALE, WAIT) + std::array phases; // Access using BattlePhases enum const battle::Unit * activeUnit = battleActiveUnit(); @@ -503,17 +501,17 @@ void CBattleInfoCallback::battleGetTurnOrder(std::vector & turns, phases[unitPhase].push_back(unit); } - boost::sort(phases[battle::SIEGE], CMP_stack(battle::SIEGE, actualTurn, sideThatLastMoved)); - std::copy(phases[battle::SIEGE].begin(), phases[battle::SIEGE].end(), std::back_inserter(turns.back())); + boost::sort(phases[BattlePhases::SIEGE], CMP_stack(BattlePhases::SIEGE, actualTurn, sideThatLastMoved)); + std::copy(phases[BattlePhases::SIEGE].begin(), phases[BattlePhases::SIEGE].end(), std::back_inserter(turns.back())); if(turnsIsFull()) return; - for(int phase = battle::NORMAL; phase < battle::MAX_NO_OF_PHASES; phase++) + for(uint8_t phase = BattlePhases::NORMAL; phase < BattlePhases::NUMBER_OF_PHASES; phase++) boost::sort(phases[phase], CMP_stack(phase, actualTurn, sideThatLastMoved)); - int phase = battle::NORMAL; - while(!turnsIsFull() && phase < battle::MAX_NO_OF_PHASES) + uint8_t phase = BattlePhases::NORMAL; + while(!turnsIsFull() && phase < BattlePhases::NUMBER_OF_PHASES) { const battle::Unit * currentUnit = nullptr; if(phases[phase].empty()) diff --git a/lib/battle/CUnitState.cpp b/lib/battle/CUnitState.cpp index e3bc59371..fdb17a179 100644 --- a/lib/battle/CUnitState.cpp +++ b/lib/battle/CUnitState.cpp @@ -609,22 +609,22 @@ bool CUnitState::waited(int turn) const return false; } -BattlePhases CUnitState::battleQueuePhase(int turn) const +BattlePhases::Type CUnitState::battleQueuePhase(int turn) const { if(turn <= 0 && waited()) //consider waiting state only for ongoing round { if(hadMorale) - return battle::WAIT_MORALE; + return BattlePhases::WAIT_MORALE; else - return battle::WAIT; + return BattlePhases::WAIT; } else if(creatureIndex() == CreatureID::CATAPULT || isTurret()) //catapult and turrets are first { - return battle::SIEGE; + return BattlePhases::SIEGE; } else { - return battle::NORMAL; + return BattlePhases::NORMAL; } } diff --git a/lib/battle/CUnitState.h b/lib/battle/CUnitState.h index 4a2271248..e4c03ee97 100644 --- a/lib/battle/CUnitState.h +++ b/lib/battle/CUnitState.h @@ -225,7 +225,7 @@ public: std::shared_ptr acquire() const override; std::shared_ptr acquireState() const override; - BattlePhases battleQueuePhase(int turn) const override; + BattlePhases::Type battleQueuePhase(int turn) const override; int getTotalAttacks(bool ranged) const override; diff --git a/lib/battle/Unit.h b/lib/battle/Unit.h index 4b831e4cc..5c0c75904 100644 --- a/lib/battle/Unit.h +++ b/lib/battle/Unit.h @@ -26,14 +26,17 @@ class JsonSerializeFormat; namespace battle { -enum BattlePhases +namespace BattlePhases { - SIEGE, // [0] - turrets/catapult, - NORMAL, // [1] - normal (unmoved) creatures, other war machines, - WAIT_MORALE, // [2] - waited creatures that had morale, - WAIT, // [3] - rest of waited creatures - MAX_NO_OF_PHASES // [4] - number of phases. -}; + enum Type + { + SIEGE, // turrets/catapult, + NORMAL, // normal (unmoved) creatures, other war machines, + WAIT_MORALE, // waited creatures that had morale, + WAIT, // rest of waited creatures + NUMBER_OF_PHASES // number of phases. + }; +} class CUnitState; @@ -89,7 +92,7 @@ public: virtual std::shared_ptr acquire() const = 0; virtual std::shared_ptr acquireState() const = 0; - virtual BattlePhases battleQueuePhase(int turn) const = 0; + virtual BattlePhases::Type battleQueuePhase(int turn) const = 0; virtual std::string getDescription() const;