mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
refactor BattleFlowProcessor
This commit is contained in:
@@ -342,6 +342,21 @@ void BattleFlowProcessor::activateNextStack(const CBattleInfoCallback & battle)
|
||||
|
||||
bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & battle, const CStack * next)
|
||||
{
|
||||
bool actionPerformed = tryActivateMoralePenalty(battle, next) || tryActivateBerserkPenalty(battle, next) || tryAutomaticActionOfWarMachines(battle, next);
|
||||
|
||||
if (!actionPerformed) {
|
||||
stackTurnTrigger(battle, next); //various effects
|
||||
|
||||
if(next->fear)
|
||||
{
|
||||
makeStackDoNothing(battle, next); //end immediately if stack was affected by fear
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return actionPerformed;
|
||||
}
|
||||
|
||||
bool BattleFlowProcessor::tryActivateMoralePenalty(const CBattleInfoCallback & battle, const CStack * next) {
|
||||
// check for bad morale => freeze
|
||||
int nextStackMorale = next->moraleVal();
|
||||
if(!next->hadMorale && !next->waited() && nextStackMorale < 0)
|
||||
@@ -359,7 +374,10 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BattleFlowProcessor::tryActivateBerserkPenalty(const CBattleInfoCallback & battle, const CStack * next) {
|
||||
if (next->hasBonusOfType(BonusType::ATTACKS_NEAREST_CREATURE)) //while in berserk
|
||||
{
|
||||
logGlobal->trace("Handle Berserk effect");
|
||||
@@ -383,7 +401,14 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BattleFlowProcessor::tryAutomaticActionOfWarMachines(const CBattleInfoCallback & battle, const CStack * next) {
|
||||
return tryMakeAutomaticActionOfBallistaOrTowers(battle, next) || tryMakeAutomaticActionOfCatapult(battle, next) || tryMakeAutomaticActionOfFirstAidTent(battle, next);
|
||||
}
|
||||
|
||||
bool BattleFlowProcessor::tryMakeAutomaticActionOfBallistaOrTowers(const CBattleInfoCallback & battle, const CStack * next) {
|
||||
const CGHeroInstance * curOwner = battle.battleGetOwnerHero(next);
|
||||
const CreatureID stackCreatureId = next->unitType()->getId();
|
||||
|
||||
@@ -449,7 +474,11 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BattleFlowProcessor::tryMakeAutomaticActionOfCatapult(const CBattleInfoCallback & battle, const CStack * next) {
|
||||
const CGHeroInstance * curOwner = battle.battleGetOwnerHero(next);
|
||||
if (next->unitType()->getId() == CreatureID::CATAPULT)
|
||||
{
|
||||
const auto & attackableBattleHexes = battle.getAttackableBattleHexes();
|
||||
@@ -471,7 +500,11 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BattleFlowProcessor::tryMakeAutomaticActionOfFirstAidTent(const CBattleInfoCallback & battle, const CStack * next) {
|
||||
const CGHeroInstance * curOwner = battle.battleGetOwnerHero(next);
|
||||
if (next->unitType()->getId() == CreatureID::FIRST_AID_TENT)
|
||||
{
|
||||
TStacks possibleStacks = battle.battleGetStacksIf([&next](const CStack * s)
|
||||
@@ -500,17 +533,10 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
stackTurnTrigger(battle, next); //various effects
|
||||
|
||||
if(next->fear)
|
||||
{
|
||||
makeStackDoNothing(battle, next); //end immediately if stack was affected by fear
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool BattleFlowProcessor::rollGoodMorale(const CBattleInfoCallback & battle, const CStack * next)
|
||||
{
|
||||
//check for good morale
|
||||
@@ -539,7 +565,7 @@ bool BattleFlowProcessor::rollGoodMorale(const CBattleInfoCallback & battle, con
|
||||
return false;
|
||||
}
|
||||
|
||||
void BattleFlowProcessor::onActionMade(const CBattleInfoCallback & battle, const BattleAction &ba)
|
||||
void BattleFlowProcessor::onActionMade(const CBattleInfoCallback & battle, const BattleAction &ba) //here
|
||||
{
|
||||
const auto * actedStack = battle.battleGetStackByID(ba.stackNumber, false);
|
||||
const auto * activeStack = battle.battleActiveUnit();
|
||||
|
||||
@@ -38,6 +38,12 @@ class BattleFlowProcessor : boost::noncopyable
|
||||
|
||||
bool rollGoodMorale(const CBattleInfoCallback & battle, const CStack * stack);
|
||||
bool tryMakeAutomaticAction(const CBattleInfoCallback & battle, const CStack * stack);
|
||||
bool tryActivateMoralePenalty(const CBattleInfoCallback & battle, const CStack * stack);
|
||||
bool tryActivateBerserkPenalty(const CBattleInfoCallback & battle, const CStack * stack);
|
||||
bool tryAutomaticActionOfWarMachines(const CBattleInfoCallback & battle, const CStack * stack);
|
||||
bool tryMakeAutomaticActionOfBallistaOrTowers(const CBattleInfoCallback & battle, const CStack * stack);
|
||||
bool tryMakeAutomaticActionOfCatapult(const CBattleInfoCallback & battle, const CStack * stack);
|
||||
bool tryMakeAutomaticActionOfFirstAidTent(const CBattleInfoCallback & battle, const CStack * stack);
|
||||
|
||||
void summonGuardiansHelper(const CBattleInfoCallback & battle, BattleHexArray & output, const BattleHex & targetPosition, BattleSide side, bool targetIsTwoHex);
|
||||
void trySummonGuardians(const CBattleInfoCallback & battle, const CStack * stack);
|
||||
@@ -54,6 +60,7 @@ class BattleFlowProcessor : boost::noncopyable
|
||||
void makeStackDoNothing(const CBattleInfoCallback & battle, const CStack * next);
|
||||
bool makeAutomaticAction(const CBattleInfoCallback & battle, const CStack * stack, const BattleAction & ba); //used when action is taken by stack without volition of player (eg. unguided catapult attack)
|
||||
|
||||
|
||||
public:
|
||||
explicit BattleFlowProcessor(BattleProcessor * owner, CGameHandler * newGameHandler);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user