浏览代码

Battles: better handling for walking double-wide creatures

Request opening of gate even if only second half of double-wide stack going to stop on it.
Arseniy Shestakov 9 年之前
父节点
当前提交
01b4d0ae01
共有 1 个文件被更改,包括 21 次插入10 次删除
  1. 21 10
      server/CGameHandler.cpp

+ 21 - 10
server/CGameHandler.cpp

@@ -1112,20 +1112,31 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
 		{
 			for(int i = path.first.size()-1; i >= 0; i--)
 			{
-				auto hex = path.first[i];
-				if(!openGateAtHex.isValid() && dbState != EDrawbridgeState::LOWERED)
+				auto needOpenGates = [&](BattleHex hex) -> bool
 				{
 					if(gs->curB->town->subID == ETownType::FORTRESS && hex == BattleHex::GATE_BRIDGE)
-					{
-						openGateAtHex = path.first[i+1];
-					}
+						return true;
 					if(hex == BattleHex::GATE_BRIDGE && i-1 >= 0 && path.first[i-1] == BattleHex::GATE_OUTER)
-					{
-						openGateAtHex = path.first[i+1];
-					}
+						return true;
 					else if(hex == BattleHex::GATE_OUTER || hex == BattleHex::GATE_INNER)
-					{
+						return true;
+
+					return false;
+				};
+
+				auto hex = path.first[i];
+				if(!openGateAtHex.isValid() && dbState != EDrawbridgeState::LOWERED)
+				{
+					if(needOpenGates(hex))
 						openGateAtHex = path.first[i+1];
+
+					//TODO we need find batter way to handle double-wide stacks
+					//currently if only second occupied stack part is standing on gate / bridge hex then stack will start to wait for bridge to lower before it's needed. Though this is just a visual bug.
+					if(curStack->doubleWide())
+					{
+						BattleHex otherHex = curStack->occupiedHex(hex);
+						if(otherHex.isValid() && needOpenGates(otherHex))
+							openGateAtHex = path.first[i+2];
 					}
 
 					//gate may be opened and then closed during stack movement, but not other way around
@@ -1250,7 +1261,7 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
 					}
 					else if(curStack->position == gateMayCloseAtHex)
 					{
-						openGateAtHex = BattleHex();
+						gateMayCloseAtHex = BattleHex();
 						updateDrawbridgeState();
 					}
 				}