2017-06-24 15:51:07 +02:00
|
|
|
/*
|
|
|
|
* CBattleInfoEssentials.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 "CBattleInfoEssentials.h"
|
2017-06-29 01:02:05 +02:00
|
|
|
#include "../CStack.h"
|
2017-06-24 15:51:07 +02:00
|
|
|
#include "BattleInfo.h"
|
2017-06-29 01:02:05 +02:00
|
|
|
#include "../NetPacks.h"
|
|
|
|
#include "../mapObjects/CGTownInstance.h"
|
2017-06-24 15:51:07 +02:00
|
|
|
|
|
|
|
ETerrainType CBattleInfoEssentials::battleTerrainType() const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(ETerrainType::WRONG);
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getTerrainType();
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BFieldType CBattleInfoEssentials::battleGetBattlefieldType() const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(BFieldType::NONE);
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getBattlefieldType();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t CBattleInfoEssentials::battleGetEnchanterCounter(ui8 side) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(0);
|
|
|
|
return getBattle()->getEnchanterCounter(side);
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
std::vector<std::shared_ptr<const CObstacleInstance>> CBattleInfoEssentials::battleGetAllObstacles(boost::optional<BattlePerspective::BattlePerspective> perspective) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
|
|
|
std::vector<std::shared_ptr<const CObstacleInstance> > ret;
|
|
|
|
RETURN_IF_NOT_BATTLE(ret);
|
|
|
|
|
|
|
|
if(!perspective)
|
|
|
|
{
|
|
|
|
//if no particular perspective request, use default one
|
2017-08-05 15:09:29 +02:00
|
|
|
perspective = boost::make_optional(battleGetMySide());
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!!player && *perspective != battleGetMySide())
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
logGlobal->error("Unauthorized obstacles access attempt!");
|
|
|
|
return ret;
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(auto obstacle : getBattle()->getAllObstacles())
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(battleIsObstacleVisibleForSide(*(obstacle.get()), *perspective))
|
|
|
|
ret.push_back(obstacle);
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::shared_ptr<const CObstacleInstance> CBattleInfoEssentials::battleGetObstacleByID(uint32_t ID) const
|
|
|
|
{
|
|
|
|
std::shared_ptr<const CObstacleInstance> ret;
|
|
|
|
|
|
|
|
RETURN_IF_NOT_BATTLE(std::shared_ptr<const CObstacleInstance>());
|
|
|
|
|
|
|
|
for(auto obstacle : getBattle()->getAllObstacles())
|
|
|
|
{
|
|
|
|
if(obstacle->uniqueID == ID)
|
|
|
|
return obstacle;
|
|
|
|
}
|
|
|
|
|
|
|
|
logGlobal->error("Invalid obstacle ID %d", ID);
|
|
|
|
return std::shared_ptr<const CObstacleInstance>();
|
|
|
|
}
|
|
|
|
|
2017-06-24 15:51:07 +02:00
|
|
|
bool CBattleInfoEssentials::battleIsObstacleVisibleForSide(const CObstacleInstance & coi, BattlePerspective::BattlePerspective side) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
|
|
|
return side == BattlePerspective::ALL_KNOWING || coi.visibleForSide(side, battleHasNativeStack(side));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBattleInfoEssentials::battleHasNativeStack(ui8 side) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
|
|
|
|
2017-06-26 18:50:35 +02:00
|
|
|
for(const CStack * s : battleGetAllStacks())
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(s->side == side && s->getCreature()->isItNativeTerrain(getBattle()->getTerrainType()))
|
2017-06-24 15:51:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
TStacks CBattleInfoEssentials::battleGetAllStacks(bool includeTurrets) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
|
|
|
return battleGetStacksIf([=](const CStack * s)
|
|
|
|
{
|
|
|
|
return !s->isGhost() && (includeTurrets || !s->isTurret());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TStacks CBattleInfoEssentials::battleGetStacksIf(TStackFilter predicate) const
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
RETURN_IF_NOT_BATTLE(TStacks());
|
|
|
|
return getBattle()->getStacksIf(predicate);
|
|
|
|
}
|
2017-06-24 15:51:07 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
battle::Units CBattleInfoEssentials::battleGetUnitsIf(battle::UnitFilter predicate) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(battle::Units());
|
|
|
|
return getBattle()->getUnitsIf(predicate);
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const battle::Unit * CBattleInfoEssentials::battleGetUnitByID(uint32_t ID) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
RETURN_IF_NOT_BATTLE(nullptr);
|
|
|
|
|
|
|
|
//TODO: consider using map ID -> Unit
|
|
|
|
|
|
|
|
auto ret = battleGetUnitsIf([=](const battle::Unit * unit)
|
|
|
|
{
|
|
|
|
return unit->unitId() == ID;
|
2017-06-24 15:51:07 +02:00
|
|
|
});
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
if(ret.empty())
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return ret[0];
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const battle::Unit * CBattleInfoEssentials::battleActiveUnit() const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
RETURN_IF_NOT_BATTLE(nullptr);
|
|
|
|
auto id = getBattle()->getActiveStackID();
|
|
|
|
if(id >= 0)
|
|
|
|
return battleGetUnitByID(static_cast<uint32_t>(id));
|
|
|
|
else
|
|
|
|
return nullptr;
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
uint32_t CBattleInfoEssentials::battleNextUnitId() const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->nextUnitId();
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CGTownInstance * CBattleInfoEssentials::battleGetDefendedTown() const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(nullptr);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
return getBattle()->getDefendedTown();
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BattlePerspective::BattlePerspective CBattleInfoEssentials::battleGetMySide() const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(BattlePerspective::INVALID);
|
|
|
|
if(!player || player.get().isSpectator())
|
|
|
|
return BattlePerspective::ALL_KNOWING;
|
2017-07-20 06:08:49 +02:00
|
|
|
if(*player == getBattle()->getSidePlayer(BattleSide::ATTACKER))
|
2017-06-24 15:51:07 +02:00
|
|
|
return BattlePerspective::LEFT_SIDE;
|
2017-07-20 06:08:49 +02:00
|
|
|
if(*player == getBattle()->getSidePlayer(BattleSide::DEFENDER))
|
2017-06-24 15:51:07 +02:00
|
|
|
return BattlePerspective::RIGHT_SIDE;
|
|
|
|
|
2017-08-12 13:36:04 +02:00
|
|
|
logGlobal->error("Cannot find player %s in battle!", player->getStr());
|
2017-06-24 15:51:07 +02:00
|
|
|
return BattlePerspective::INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CStack* CBattleInfoEssentials::battleGetStackByID(int ID, bool onlyAlive) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(nullptr);
|
|
|
|
|
|
|
|
auto stacks = battleGetStacksIf([=](const CStack * s)
|
|
|
|
{
|
|
|
|
return s->ID == ID && (!onlyAlive || s->alive());
|
|
|
|
});
|
|
|
|
|
|
|
|
if(stacks.empty())
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return stacks[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBattleInfoEssentials::battleDoWeKnowAbout(ui8 side) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
|
|
|
auto p = battleGetMySide();
|
2017-06-26 18:50:35 +02:00
|
|
|
return p == BattlePerspective::ALL_KNOWING || p == side;
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
si8 CBattleInfoEssentials::battleTacticDist() const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(0);
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getTacticDist();
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
si8 CBattleInfoEssentials::battleGetTacticsSide() const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(-1);
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getTacticsSide();
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance * CBattleInfoEssentials::battleGetFightingHero(ui8 side) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(nullptr);
|
|
|
|
if(side > 1)
|
|
|
|
{
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("FIXME: %s wrong argument!", __FUNCTION__);
|
2017-06-24 15:51:07 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!battleDoWeKnowAbout(side))
|
|
|
|
{
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("FIXME: %s access check ", __FUNCTION__);
|
2017-06-24 15:51:07 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getSideHero(side);
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CArmedInstance * CBattleInfoEssentials::battleGetArmyObject(ui8 side) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(nullptr);
|
|
|
|
if(side > 1)
|
|
|
|
{
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("FIXME: %s wrong argument!", __FUNCTION__);
|
2017-06-24 15:51:07 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if(!battleDoWeKnowAbout(side))
|
|
|
|
{
|
2017-08-12 14:43:41 +02:00
|
|
|
logGlobal->error("FIXME: %s access check!", __FUNCTION__);
|
2017-06-24 15:51:07 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getSideArmy(side);
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-06-26 18:50:35 +02:00
|
|
|
InfoAboutHero CBattleInfoEssentials::battleGetHeroInfo(ui8 side) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
auto hero = getBattle()->getSideHero(side);
|
2017-06-24 15:51:07 +02:00
|
|
|
if(!hero)
|
|
|
|
{
|
2017-08-12 14:43:41 +02:00
|
|
|
logGlobal->warn("%s: side %d does not have hero!", __FUNCTION__, static_cast<int>(side));
|
2017-06-24 15:51:07 +02:00
|
|
|
return InfoAboutHero();
|
|
|
|
}
|
|
|
|
InfoAboutHero::EInfoLevel infoLevel = battleDoWeKnowAbout(side) ? InfoAboutHero::EInfoLevel::DETAILED : InfoAboutHero::EInfoLevel::BASIC;
|
|
|
|
return InfoAboutHero(hero, infoLevel);
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
uint32_t CBattleInfoEssentials::battleCastSpells(ui8 side) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(-1);
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getCastSpells(side);
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const IBonusBearer * CBattleInfoEssentials::getBattleNode() const
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->asBearer();
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CBattleInfoEssentials::battleCanFlee(PlayerColor player) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
2017-07-01 10:34:00 +02:00
|
|
|
const auto side = playerToSide(player);
|
|
|
|
if(!side)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const CGHeroInstance *myHero = battleGetFightingHero(side.get());
|
2017-06-24 15:51:07 +02:00
|
|
|
|
|
|
|
//current player have no hero
|
|
|
|
if(!myHero)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//eg. one of heroes is wearing shakles of war
|
|
|
|
if(myHero->hasBonusOfType(Bonus::BATTLE_NO_FLEEING))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//we are besieged defender
|
2017-07-01 10:34:00 +02:00
|
|
|
if(side.get() == BattleSide::DEFENDER && battleGetSiegeLevel())
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
|
|
|
auto town = battleGetDefendedTown();
|
|
|
|
if(!town->hasBuilt(BuildingID::ESCAPE_TUNNEL, ETownType::STRONGHOLD))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-01 10:34:00 +02:00
|
|
|
BattleSideOpt CBattleInfoEssentials::playerToSide(PlayerColor player) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-01 10:34:00 +02:00
|
|
|
RETURN_IF_NOT_BATTLE(boost::none);
|
2017-06-24 15:51:07 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(getBattle()->getSidePlayer(BattleSide::ATTACKER) == player)
|
|
|
|
return BattleSideOpt(BattleSide::ATTACKER);
|
|
|
|
|
|
|
|
if(getBattle()->getSidePlayer(BattleSide::DEFENDER) == player)
|
|
|
|
return BattleSideOpt(BattleSide::DEFENDER);
|
|
|
|
|
|
|
|
logGlobal->warn("Cannot find side for player %s", player.getStr());
|
|
|
|
|
|
|
|
return boost::none;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerColor CBattleInfoEssentials::sideToPlayer(ui8 side) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(PlayerColor::CANNOT_DETERMINE);
|
|
|
|
return getBattle()->getSidePlayer(side);
|
2017-07-01 10:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ui8 CBattleInfoEssentials::otherSide(ui8 side) const
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(side == BattleSide::ATTACKER)
|
2017-07-01 10:34:00 +02:00
|
|
|
return BattleSide::DEFENDER;
|
|
|
|
else
|
|
|
|
return BattleSide::ATTACKER;
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
PlayerColor CBattleInfoEssentials::otherPlayer(PlayerColor player) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(PlayerColor::CANNOT_DETERMINE);
|
|
|
|
|
|
|
|
auto side = playerToSide(player);
|
|
|
|
if(!side)
|
|
|
|
return PlayerColor::CANNOT_DETERMINE;
|
|
|
|
|
|
|
|
return getBattle()->getSidePlayer(otherSide(side.get()));
|
|
|
|
}
|
|
|
|
|
2017-06-24 15:51:07 +02:00
|
|
|
bool CBattleInfoEssentials::playerHasAccessToHeroInfo(PlayerColor player, const CGHeroInstance * h) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
2017-07-01 10:34:00 +02:00
|
|
|
const auto side = playerToSide(player);
|
|
|
|
if(side)
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
auto opponentSide = otherSide(side.get());
|
|
|
|
if(getBattle()->getSideHero(opponentSide) == h)
|
2017-06-24 15:51:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui8 CBattleInfoEssentials::battleGetSiegeLevel() const
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
RETURN_IF_NOT_BATTLE(CGTownInstance::NONE);
|
|
|
|
return getBattle()->getDefendedTown() ? getBattle()->getDefendedTown()->fortLevel() : CGTownInstance::NONE;
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CBattleInfoEssentials::battleCanSurrender(PlayerColor player) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
2017-07-01 10:34:00 +02:00
|
|
|
const auto side = playerToSide(player);
|
|
|
|
if(!side)
|
|
|
|
return false;
|
|
|
|
bool iAmSiegeDefender = (side.get() == BattleSide::DEFENDER && battleGetSiegeLevel());
|
2017-06-24 15:51:07 +02:00
|
|
|
//conditions like for fleeing (except escape tunnel presence) + enemy must have a hero
|
2017-07-01 10:34:00 +02:00
|
|
|
return battleCanFlee(player) && !iAmSiegeDefender && battleHasHero(otherSide(side.get()));
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CBattleInfoEssentials::battleHasHero(ui8 side) const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getSideHero(side) != nullptr;
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
si8 CBattleInfoEssentials::battleGetWallState(int partOfWall) const
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
RETURN_IF_NOT_BATTLE(EWallState::NONE);
|
|
|
|
if(battleGetSiegeLevel() == CGTownInstance::NONE)
|
2017-06-24 15:51:07 +02:00
|
|
|
return EWallState::NONE;
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getWallState(partOfWall);
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EGateState CBattleInfoEssentials::battleGetGateState() const
|
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(EGateState::NONE);
|
2017-07-20 06:08:49 +02:00
|
|
|
if(battleGetSiegeLevel() == CGTownInstance::NONE)
|
2017-06-24 15:51:07 +02:00
|
|
|
return EGateState::NONE;
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getGateState();
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
PlayerColor CBattleInfoEssentials::battleGetOwner(const battle::Unit * unit) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(PlayerColor::CANNOT_DETERMINE);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
PlayerColor initialOwner = getBattle()->getSidePlayer(unit->unitSide());
|
|
|
|
|
|
|
|
static CSelector selector = Selector::type(Bonus::HYPNOTIZED);
|
|
|
|
static std::string cachingString = "type_103s-1";
|
|
|
|
|
|
|
|
if(unit->hasBonus(selector, cachingString))
|
|
|
|
return otherPlayer(initialOwner);
|
2017-06-24 15:51:07 +02:00
|
|
|
else
|
2017-07-20 06:08:49 +02:00
|
|
|
return initialOwner;
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const CGHeroInstance * CBattleInfoEssentials::battleGetOwnerHero(const battle::Unit * unit) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(nullptr);
|
2017-07-20 06:08:49 +02:00
|
|
|
const auto side = playerToSide(battleGetOwner(unit));
|
2017-07-01 10:34:00 +02:00
|
|
|
if(!side)
|
|
|
|
return nullptr;
|
2017-07-20 06:08:49 +02:00
|
|
|
return getBattle()->getSideHero(side.get());
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool CBattleInfoEssentials::battleMatchOwner(const battle::Unit * attacker, const battle::Unit * defender, const boost::logic::tribool positivness) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
|
|
|
if(boost::logic::indeterminate(positivness))
|
|
|
|
return true;
|
2017-07-20 06:08:49 +02:00
|
|
|
else if(attacker->unitId() == defender->unitId())
|
2019-01-24 16:48:38 +02:00
|
|
|
return (bool)positivness;
|
2017-07-09 15:55:10 +02:00
|
|
|
else
|
|
|
|
return battleMatchOwner(battleGetOwner(attacker), defender, positivness);
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool CBattleInfoEssentials::battleMatchOwner(const PlayerColor & attacker, const battle::Unit * defender, const boost::logic::tribool positivness) const
|
2017-07-09 15:55:10 +02:00
|
|
|
{
|
|
|
|
RETURN_IF_NOT_BATTLE(false);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
PlayerColor initialOwner = getBattle()->getSidePlayer(defender->unitSide());
|
|
|
|
|
2019-03-20 21:58:15 +02:00
|
|
|
return boost::logic::indeterminate(positivness) || (attacker == initialOwner) == (bool)positivness;
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|