2017-06-24 15:51:07 +02:00
|
|
|
/*
|
|
|
|
* CPlayerBattleCallback.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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-01 20:05:10 +02:00
|
|
|
#include "StdInc.h"
|
2017-06-24 15:51:07 +02:00
|
|
|
#include "CPlayerBattleCallback.h"
|
2017-06-29 01:02:05 +02:00
|
|
|
#include "../CStack.h"
|
2023-06-23 17:02:48 +02:00
|
|
|
#include "../gameState/InfoAboutArmy.h"
|
2023-08-30 21:07:02 +02:00
|
|
|
#include "../CGameInfoCallback.h"
|
2017-06-24 15:51:07 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-08-30 21:07:02 +02:00
|
|
|
CPlayerBattleCallback::CPlayerBattleCallback(const IBattleInfo * battle, PlayerColor player):
|
|
|
|
battle(battle),
|
|
|
|
player(player)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const IBattleInfo * CPlayerBattleCallback::getBattle() const
|
|
|
|
{
|
|
|
|
return battle;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<PlayerColor> CPlayerBattleCallback::getPlayerID() const
|
|
|
|
{
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
2017-06-24 15:51:07 +02:00
|
|
|
bool CPlayerBattleCallback::battleCanFlee() const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
|
|
|
ASSERT_IF_CALLED_WITH_PLAYER
|
2023-08-28 16:43:57 +02:00
|
|
|
return CBattleInfoEssentials::battleCanFlee(*getPlayerID());
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
TStacks CPlayerBattleCallback::battleGetStacks(EStackOwnership whose, bool onlyAlive) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
|
|
|
if(whose != MINE_AND_ENEMY)
|
|
|
|
{
|
|
|
|
ASSERT_IF_CALLED_WITH_PLAYER
|
|
|
|
}
|
|
|
|
|
|
|
|
return battleGetStacksIf([=](const CStack * s){
|
|
|
|
const bool ownerMatches = (whose == MINE_AND_ENEMY)
|
2023-08-28 16:43:57 +02:00
|
|
|
|| (whose == ONLY_MINE && s->unitOwner() == getPlayerID())
|
|
|
|
|| (whose == ONLY_ENEMY && s->unitOwner() != getPlayerID());
|
2017-06-24 15:51:07 +02:00
|
|
|
|
|
|
|
return ownerMatches && s->isValidTarget(!onlyAlive);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPlayerBattleCallback::battleGetSurrenderCost() const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(-3)
|
|
|
|
ASSERT_IF_CALLED_WITH_PLAYER
|
2023-08-28 16:43:57 +02:00
|
|
|
return CBattleInfoCallback::battleGetSurrenderCost(*getPlayerID());
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance * CPlayerBattleCallback::battleGetMyHero() const
|
|
|
|
{
|
|
|
|
return CBattleInfoEssentials::battleGetFightingHero(battleGetMySide());
|
|
|
|
}
|
|
|
|
|
|
|
|
InfoAboutHero CPlayerBattleCallback::battleGetEnemyHero() const
|
|
|
|
{
|
|
|
|
return battleGetHeroInfo(!battleGetMySide());
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|