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

CBattleInfoEssentials: add battleIsGatePassable()

This is a helper to check if gate is passable now or not.
This commit is contained in:
Konstantin 2023-04-08 02:29:32 +03:00 committed by Konstantin P
parent 8397bd91fb
commit 03eb997137
3 changed files with 14 additions and 5 deletions

View File

@ -814,11 +814,10 @@ std::vector<std::shared_ptr<const CObstacleInstance>> CBattleInfoCallback::getAl
affectedObstacles.push_back(i);
}
for(auto hex : unit->getHexes())
if(hex == ESiegeHex::GATE_BRIDGE)
if(battleGetGateState() == EGateState::OPENED || battleGetGateState() == EGateState::DESTROYED)
for(int i=0; i<affectedObstacles.size(); i++)
if(affectedObstacles.at(i)->obstacleType == CObstacleInstance::MOAT)
affectedObstacles.erase(affectedObstacles.begin()+i);
if(hex == ESiegeHex::GATE_BRIDGE && battleIsGatePassable())
for(int i=0; i<affectedObstacles.size(); i++)
if(affectedObstacles.at(i)->obstacleType == CObstacleInstance::MOAT)
affectedObstacles.erase(affectedObstacles.begin()+i);
}
return affectedObstacles;
}

View File

@ -379,6 +379,15 @@ EGateState CBattleInfoEssentials::battleGetGateState() const
return getBattle()->getGateState();
}
bool CBattleInfoEssentials::battleIsGatePassable() const
{
RETURN_IF_NOT_BATTLE(true);
if(battleGetSiegeLevel() == CGTownInstance::NONE)
return true;
return battleGetGateState() == EGateState::OPENED || battleGetGateState() == EGateState::DESTROYED;
}
PlayerColor CBattleInfoEssentials::battleGetOwner(const battle::Unit * unit) const
{
RETURN_IF_NOT_BATTLE(PlayerColor::CANNOT_DETERMINE);

View File

@ -96,6 +96,7 @@ public:
// [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; returned value: 1 - intact, 2 - damaged, 3 - destroyed; 0 - no battle
EWallState battleGetWallState(EWallPart partOfWall) const;
EGateState battleGetGateState() const;
bool battleIsGatePassable() const;
//helpers
///returns all stacks, alive or dead or undead or mechanical :)