1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

BattlePhases enum moved to Unit.h

This commit is contained in:
krs 2023-02-25 00:54:48 +02:00
parent 0373febe6f
commit 7421fabf2c
4 changed files with 30 additions and 38 deletions

View File

@ -355,15 +355,6 @@ battle::Units CBattleInfoCallback::battleAliveUnits(ui8 side) const
});
}
enum 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.
};
//T is battle::Unit descendant
template <typename T>
const T * takeOneUnit(std::vector<const T*> & allUnits, const int turn, int8_t & sideThatLastMoved, int phase)
@ -387,7 +378,7 @@ const T * takeOneUnit(std::vector<const T*> & allUnits, const int turn, int8_t &
switch(phase)
{
case NORMAL: // Faster first, attacker priority, higher slot first
case battle::NORMAL: // Faster first, attacker priority, higher slot first
if(returnedUnit == nullptr || currentUnitInitiative > returnedUnitInitiative)
{
returnedUnit = currentUnit;
@ -409,8 +400,8 @@ const T * takeOneUnit(std::vector<const T*> & allUnits, const int turn, int8_t &
}
}
break;
case WAIT_MORALE: // Slower first, higher slot first
case WAIT:
case battle::WAIT_MORALE: // Slower first, higher slot first
case battle::WAIT:
if(returnedUnit == nullptr || currentUnitInitiative < returnedUnitInitiative)
{
returnedUnit = currentUnit;
@ -462,11 +453,11 @@ void CBattleInfoCallback::battleGetTurnOrder(std::vector<battle::Units> & turns,
turns.emplace_back();
// We'll split creatures with remaining movement to 4 buckets
// [0] - turrets/catapult,
// [1] - normal (unmoved) creatures, other war machines,
// [2] - waited creatures that had morale,
// [3] - rest of waited creatures
std::array<battle::Units, MAX_NO_OF_PHASES> phases;
// [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
const battle::Unit * activeUnit = battleActiveUnit();
@ -512,17 +503,17 @@ void CBattleInfoCallback::battleGetTurnOrder(std::vector<battle::Units> & turns,
phases[unitPhase].push_back(unit);
}
boost::sort(phases[SIEGE], CMP_stack(SIEGE, actualTurn, sideThatLastMoved));
std::copy(phases[SIEGE].begin(), phases[SIEGE].end(), std::back_inserter(turns.back()));
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()));
if(turnsIsFull())
return;
for(int phase = NORMAL; phase < MAX_NO_OF_PHASES; phase++)
for(int phase = battle::NORMAL; phase < battle::MAX_NO_OF_PHASES; phase++)
boost::sort(phases[phase], CMP_stack(phase, actualTurn, sideThatLastMoved));
int phase = NORMAL;
while(!turnsIsFull() && phase < MAX_NO_OF_PHASES)
int phase = battle::NORMAL;
while(!turnsIsFull() && phase < battle::MAX_NO_OF_PHASES)
{
const battle::Unit * currentUnit = nullptr;
if(phases[phase].empty())

View File

@ -609,31 +609,22 @@ bool CUnitState::waited(int turn) const
return false;
}
int CUnitState::battleQueuePhase(int turn) const
BattlePhases CUnitState::battleQueuePhase(int turn) const
{
enum 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. Can be used in for loops.
};
if(turn <= 0 && waited()) //consider waiting state only for ongoing round
{
if(hadMorale)
return WAIT_MORALE;
return battle::WAIT_MORALE;
else
return WAIT;
return battle::WAIT;
}
else if(creatureIndex() == CreatureID::CATAPULT || isTurret()) //catapult and turrets are first
{
return SIEGE;
return battle::SIEGE;
}
else
{
return NORMAL;
return battle::NORMAL;
}
}

View File

@ -225,7 +225,7 @@ public:
std::shared_ptr<Unit> acquire() const override;
std::shared_ptr<CUnitState> acquireState() const override;
int battleQueuePhase(int turn) const override;
BattlePhases battleQueuePhase(int turn) const override;
int getTotalAttacks(bool ranged) const override;

View File

@ -25,6 +25,16 @@ class JsonSerializeFormat;
namespace battle
{
enum 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.
};
class CUnitState;
class DLL_LINKAGE Unit : public IUnitInfo, public spells::Caster, public virtual IBonusBearer
@ -79,7 +89,7 @@ public:
virtual std::shared_ptr<Unit> acquire() const = 0;
virtual std::shared_ptr<CUnitState> acquireState() const = 0;
virtual int battleQueuePhase(int turn) const = 0;
virtual BattlePhases battleQueuePhase(int turn) const = 0;
virtual std::string getDescription() const;