mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-19 21:10:12 +02:00
Enum is now in its own namespace, comments for enum values removed
Using Namespace Fix for linux compilation. NO_OF_PHASES renamed to NUMBER_OF_PHASES, removed duplicate phase documentation
This commit is contained in:
parent
7421fabf2c
commit
26bca26bd8
@ -355,6 +355,8 @@ battle::Units CBattleInfoCallback::battleAliveUnits(ui8 side) const
|
||||
});
|
||||
}
|
||||
|
||||
using namespace battle;
|
||||
|
||||
//T is battle::Unit descendant
|
||||
template <typename T>
|
||||
const T * takeOneUnit(std::vector<const T*> & allUnits, const int turn, int8_t & sideThatLastMoved, int phase)
|
||||
@ -378,7 +380,7 @@ const T * takeOneUnit(std::vector<const T*> & 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<const T*> & 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<battle::Units> & 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<battle::Units, battle::MAX_NO_OF_PHASES> phases; // Access using BattlePhases enum
|
||||
// We'll split creatures with remaining movement to 4 buckets (SIEGE, NORMAL, WAIT_MORALE, WAIT)
|
||||
std::array<battle::Units, BattlePhases::NUMBER_OF_PHASES> phases; // Access using BattlePhases enum
|
||||
|
||||
const battle::Unit * activeUnit = battleActiveUnit();
|
||||
|
||||
@ -503,17 +501,17 @@ void CBattleInfoCallback::battleGetTurnOrder(std::vector<battle::Units> & 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())
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ public:
|
||||
std::shared_ptr<Unit> acquire() const override;
|
||||
std::shared_ptr<CUnitState> acquireState() const override;
|
||||
|
||||
BattlePhases battleQueuePhase(int turn) const override;
|
||||
BattlePhases::Type battleQueuePhase(int turn) const override;
|
||||
|
||||
int getTotalAttacks(bool ranged) const override;
|
||||
|
||||
|
@ -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<Unit> acquire() const = 0;
|
||||
virtual std::shared_ptr<CUnitState> acquireState() const = 0;
|
||||
|
||||
virtual BattlePhases battleQueuePhase(int turn) const = 0;
|
||||
virtual BattlePhases::Type battleQueuePhase(int turn) const = 0;
|
||||
|
||||
virtual std::string getDescription() const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user