Ver código fonte

Merge pull request #340 from dydzio0614/navalbattlefieldfix2

Add proper handling for ship-to-ship battlefield
ArseniyShestakov 8 anos atrás
pai
commit
77ca27b90b
2 arquivos alterados com 26 adições e 1 exclusões
  1. 6 1
      lib/battle/BattleInfo.cpp
  2. 20 0
      lib/battle/CBattleInfoCallback.cpp

+ 6 - 1
lib/battle/BattleInfo.cpp

@@ -352,6 +352,7 @@ BattleInfo * BattleInfo::setupBattle(int3 tile, ETerrainType terrain, BFieldType
 			catch(RangeGenerator::ExhaustedPossibilities &)
 			{
 				//silently ignore, if we can't place absolute obstacle, we'll go with the usual ones
+				logGlobal->debug("RangeGenerator::ExhaustedPossibilities exception occured - cannot place absolute obstacle");
 			}
 		}
 
@@ -359,7 +360,8 @@ BattleInfo * BattleInfo::setupBattle(int3 tile, ETerrainType terrain, BFieldType
 		try
 		{
 			while(tilesToBlock > 0)
-			{
+			{				
+				auto tileAccessibility = curB->getAccesibility();
 				const int obid = obidgen.getSuchNumber(appropriateUsualObstacle);
 				const CObstacleInfo &obi = VLC->heroh->obstacles[obid];
 
@@ -376,6 +378,8 @@ BattleInfo * BattleInfo::setupBattle(int3 tile, ETerrainType terrain, BFieldType
 
 					for(BattleHex blocked : obi.getBlocked(pos))
 					{
+						if(tileAccessibility[blocked] == EAccessibility::UNAVAILABLE) //for ship-to-ship battlefield - exclude hardcoded unavailable tiles
+							return false;
 						if(vstd::contains(blockedTiles, blocked))
 							return false;
 						int x = blocked.getX();
@@ -401,6 +405,7 @@ BattleInfo * BattleInfo::setupBattle(int3 tile, ETerrainType terrain, BFieldType
 		}
 		catch(RangeGenerator::ExhaustedPossibilities &)
 		{
+			logGlobal->debug("RangeGenerator::ExhaustedPossibilities exception occured - cannot place usual obstacle");
 		}
 	}
 

+ 20 - 0
lib/battle/CBattleInfoCallback.cpp

@@ -855,6 +855,26 @@ AccessibilityInfo CBattleInfoCallback::getAccesibility() const
 		ret[BattleHex(0, y)] = EAccessibility::SIDE_COLUMN;
 	}
 
+	//special battlefields with logically unavailable tiles
+	std::vector<BattleHex> impassableHexes;
+	if(battleGetBattlefieldType().num == BFieldType::SHIP_TO_SHIP)
+	{	
+		impassableHexes = 
+		{ 
+			6, 7, 8, 9,
+			24, 25, 26, 
+			58, 59, 60,
+			75, 76, 77,
+			92, 93, 94,
+			109, 110, 111,
+			126, 127, 128,
+			159, 160, 161, 162, 163,
+			176, 177, 178, 179, 180
+		};
+	}	
+	for(auto hex : impassableHexes)
+		ret[hex] = EAccessibility::UNAVAILABLE;
+
 	//gate -> should be before stacks
 	if(battleGetSiegeLevel() > 0)
 	{