1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/lib/battle/BattleStateInfoForRetreat.cpp
Ivan Savenko 2a05fbdd50 Unified handling of battle sides ID's
- Replaced BattleSide namespace-enum with enum class
- Merged two different BattleSide enum's into one
- Merged BattlePerspective enum into BattleSide enum
- Changed all places that use integers to represent battle side to use
BattleSide enum
- Added BattleSideArray convenience wrapper for std::array that is
always 2-elements in size and allows access to its elements using
BattleSide enum
2024-08-11 20:54:44 +00:00

58 lines
1.3 KiB
C++

/*
* BattleStateInfoForRetreat.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "BattleStateInfoForRetreat.h"
#include "Unit.h"
#include "CBattleInfoCallback.h"
#include "../CCreatureSet.h"
#include "../mapObjects/CGHeroInstance.h"
VCMI_LIB_NAMESPACE_BEGIN
BattleStateInfoForRetreat::BattleStateInfoForRetreat():
canFlee(false),
canSurrender(false),
isLastTurnBeforeDie(false),
ourHero(nullptr),
enemyHero(nullptr),
ourSide(BattleSide::NONE)
{
}
uint64_t getFightingStrength(const std::vector<const battle::Unit *> & stacks, const CGHeroInstance * hero = nullptr)
{
uint64_t result = 0;
for(const battle::Unit * stack : stacks)
{
result += stack->creatureId().toCreature()->getAIValue() * stack->getCount();
}
if(hero)
{
result = static_cast<uint64_t>(result * hero->getFightingStrength());
}
return result;
}
uint64_t BattleStateInfoForRetreat::getOurStrength() const
{
return getFightingStrength(ourStacks, ourHero);
}
uint64_t BattleStateInfoForRetreat::getEnemyStrength() const
{
return getFightingStrength(enemyStacks, enemyHero);
}
VCMI_LIB_NAMESPACE_END