mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-23 21:29:13 +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
|
//T is battle::Unit descendant
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T * takeOneUnit(std::vector<const T*> & allUnits, const int turn, int8_t & sideThatLastMoved, int phase)
|
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)
|
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)
|
if(returnedUnit == nullptr || currentUnitInitiative > returnedUnitInitiative)
|
||||||
{
|
{
|
||||||
returnedUnit = currentUnit;
|
returnedUnit = currentUnit;
|
||||||
@ -400,8 +402,8 @@ const T * takeOneUnit(std::vector<const T*> & allUnits, const int turn, int8_t &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case battle::WAIT_MORALE: // Slower first, higher slot first
|
case BattlePhases::WAIT_MORALE: // Slower first, higher slot first
|
||||||
case battle::WAIT:
|
case BattlePhases::WAIT:
|
||||||
if(returnedUnit == nullptr || currentUnitInitiative < returnedUnitInitiative)
|
if(returnedUnit == nullptr || currentUnitInitiative < returnedUnitInitiative)
|
||||||
{
|
{
|
||||||
returnedUnit = currentUnit;
|
returnedUnit = currentUnit;
|
||||||
@ -452,12 +454,8 @@ void CBattleInfoCallback::battleGetTurnOrder(std::vector<battle::Units> & turns,
|
|||||||
|
|
||||||
turns.emplace_back();
|
turns.emplace_back();
|
||||||
|
|
||||||
// We'll split creatures with remaining movement to 4 buckets
|
// We'll split creatures with remaining movement to 4 buckets (SIEGE, NORMAL, WAIT_MORALE, WAIT)
|
||||||
// [0] SIEGE - turrets/catapult,
|
std::array<battle::Units, BattlePhases::NUMBER_OF_PHASES> phases; // Access using BattlePhases enum
|
||||||
// [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
|
|
||||||
|
|
||||||
const battle::Unit * activeUnit = battleActiveUnit();
|
const battle::Unit * activeUnit = battleActiveUnit();
|
||||||
|
|
||||||
@ -503,17 +501,17 @@ void CBattleInfoCallback::battleGetTurnOrder(std::vector<battle::Units> & turns,
|
|||||||
phases[unitPhase].push_back(unit);
|
phases[unitPhase].push_back(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::sort(phases[battle::SIEGE], CMP_stack(battle::SIEGE, actualTurn, sideThatLastMoved));
|
boost::sort(phases[BattlePhases::SIEGE], CMP_stack(BattlePhases::SIEGE, actualTurn, sideThatLastMoved));
|
||||||
std::copy(phases[battle::SIEGE].begin(), phases[battle::SIEGE].end(), std::back_inserter(turns.back()));
|
std::copy(phases[BattlePhases::SIEGE].begin(), phases[BattlePhases::SIEGE].end(), std::back_inserter(turns.back()));
|
||||||
|
|
||||||
if(turnsIsFull())
|
if(turnsIsFull())
|
||||||
return;
|
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));
|
boost::sort(phases[phase], CMP_stack(phase, actualTurn, sideThatLastMoved));
|
||||||
|
|
||||||
int phase = battle::NORMAL;
|
uint8_t phase = BattlePhases::NORMAL;
|
||||||
while(!turnsIsFull() && phase < battle::MAX_NO_OF_PHASES)
|
while(!turnsIsFull() && phase < BattlePhases::NUMBER_OF_PHASES)
|
||||||
{
|
{
|
||||||
const battle::Unit * currentUnit = nullptr;
|
const battle::Unit * currentUnit = nullptr;
|
||||||
if(phases[phase].empty())
|
if(phases[phase].empty())
|
||||||
|
@ -609,22 +609,22 @@ bool CUnitState::waited(int turn) const
|
|||||||
return false;
|
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(turn <= 0 && waited()) //consider waiting state only for ongoing round
|
||||||
{
|
{
|
||||||
if(hadMorale)
|
if(hadMorale)
|
||||||
return battle::WAIT_MORALE;
|
return BattlePhases::WAIT_MORALE;
|
||||||
else
|
else
|
||||||
return battle::WAIT;
|
return BattlePhases::WAIT;
|
||||||
}
|
}
|
||||||
else if(creatureIndex() == CreatureID::CATAPULT || isTurret()) //catapult and turrets are first
|
else if(creatureIndex() == CreatureID::CATAPULT || isTurret()) //catapult and turrets are first
|
||||||
{
|
{
|
||||||
return battle::SIEGE;
|
return BattlePhases::SIEGE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return battle::NORMAL;
|
return BattlePhases::NORMAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ public:
|
|||||||
std::shared_ptr<Unit> acquire() const override;
|
std::shared_ptr<Unit> acquire() const override;
|
||||||
std::shared_ptr<CUnitState> acquireState() 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;
|
int getTotalAttacks(bool ranged) const override;
|
||||||
|
|
||||||
|
@ -26,14 +26,17 @@ class JsonSerializeFormat;
|
|||||||
namespace battle
|
namespace battle
|
||||||
{
|
{
|
||||||
|
|
||||||
enum BattlePhases
|
namespace BattlePhases
|
||||||
{
|
{
|
||||||
SIEGE, // [0] - turrets/catapult,
|
enum Type
|
||||||
NORMAL, // [1] - normal (unmoved) creatures, other war machines,
|
{
|
||||||
WAIT_MORALE, // [2] - waited creatures that had morale,
|
SIEGE, // turrets/catapult,
|
||||||
WAIT, // [3] - rest of waited creatures
|
NORMAL, // normal (unmoved) creatures, other war machines,
|
||||||
MAX_NO_OF_PHASES // [4] - number of phases.
|
WAIT_MORALE, // waited creatures that had morale,
|
||||||
|
WAIT, // rest of waited creatures
|
||||||
|
NUMBER_OF_PHASES // number of phases.
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
class CUnitState;
|
class CUnitState;
|
||||||
|
|
||||||
@ -89,7 +92,7 @@ public:
|
|||||||
virtual std::shared_ptr<Unit> acquire() const = 0;
|
virtual std::shared_ptr<Unit> acquire() const = 0;
|
||||||
virtual std::shared_ptr<CUnitState> acquireState() 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;
|
virtual std::string getDescription() const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user