Browse Source

CBattleInfoEssentials: add battleIsGatePassable()

This is a helper to check if gate is passable now or not.
Konstantin 2 years ago
parent
commit
03eb997137

+ 4 - 5
lib/battle/CBattleInfoCallback.cpp

@@ -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;
 }

+ 9 - 0
lib/battle/CBattleInfoEssentials.cpp

@@ -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);

+ 1 - 0
lib/battle/CBattleInfoEssentials.h

@@ -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 :)