Browse Source

* #152 finally fixed (I hope)

mateuszb 15 năm trước cách đây
mục cha
commit
b15e8531b2
2 tập tin đã thay đổi với 34 bổ sung5 xóa
  1. 33 5
      lib/CGameState.cpp
  2. 1 0
      lib/CGameState.h

+ 33 - 5
lib/CGameState.cpp

@@ -785,6 +785,21 @@ bool CStack::doubleWide() const
 	return type->doubleWide;
 }
 
+int CStack::occupiedHex() const
+{
+	if (doubleWide())
+	{
+		if (attackerOwned)
+			return position - 1;
+		else
+			return position + 1;
+	} 
+	else
+	{
+		return -1;
+	}
+}
+
 CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, const CTown *town, std::map<ui32,CGHeroInstance *> &available, const CHeroClass *bannedClass /*= NULL*/) const
 {
 	CGHeroInstance *ret = NULL;
@@ -3617,12 +3632,25 @@ si8 BattleInfo::hasDistancePenalty( int stackID, int destHex )
 {
 	const CStack * stack = getStack(stackID);
 
-	int xDst = std::abs(destHex % BFIELD_WIDTH - stack->position % BFIELD_WIDTH),
-		yDst = std::abs(destHex / BFIELD_WIDTH - stack->position / BFIELD_WIDTH);
-	int distance = std::max(xDst, yDst) + std::min(xDst, yDst) - (std::max(xDst, yDst) + 1)/2;
+	struct HLP
+	{
+		static bool lowerAnalyze(const CStack * stack, int hex)
+		{
+			int xDst = std::abs(hex % BFIELD_WIDTH - stack->position % BFIELD_WIDTH),
+				yDst = std::abs(hex / BFIELD_WIDTH - stack->position / BFIELD_WIDTH);
+			int distance = std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2;
+
+			//I hope it's approximately correct
+			return distance > 10 && !stack->hasBonusOfType(Bonus::NO_DISTANCE_PENALTY);
+		}
+	};
+	const CStack * dstStack = getStackT(destHex, false);
 
-	//I hope it's approximately correct
-	return distance > 10 && !stack->hasBonusOfType(Bonus::NO_DISTANCE_PENALTY);
+	if (dstStack->doubleWide())
+		return HLP::lowerAnalyze(stack, destHex) && HLP::lowerAnalyze(stack, dstStack->occupiedHex());
+	else
+		return HLP::lowerAnalyze(stack, destHex);
+	
 }
 
 si8 BattleInfo::sameSideOfWall(int pos1, int pos2)

+ 1 - 0
lib/CGameState.h

@@ -262,6 +262,7 @@ public:
 	ui32 Speed(int turn = 0) const; //get speed of creature with all modificators
 
 	bool doubleWide() const;
+	int occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{