2
0
mateuszb 15 жил өмнө
parent
commit
d3bf011270

+ 4 - 1
client/CPlayerInterface.cpp

@@ -821,7 +821,10 @@ void CPlayerInterface::battleAttack(BattleAttack *ba)
 		int shift = 0;
 		if(ba->counter() && BattleInfo::mutualPosition(curAction->destinationTile, attacker->position) < 0)
 		{
-			if( BattleInfo::mutualPosition(curAction->destinationTile + 1, attacker->position) >= 0 )
+			int distp = BattleInfo::getDistance(curAction->destinationTile + 1, attacker->position);
+			int distm = BattleInfo::getDistance(curAction->destinationTile - 1, attacker->position);
+
+			if( distp < distm )
 				shift = 1;
 			else
 				shift = -1;

+ 8 - 3
lib/CGameState.cpp

@@ -3636,9 +3636,7 @@ si8 BattleInfo::hasDistancePenalty( int stackID, int destHex )
 	{
 		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;
+			int distance = BattleInfo::getDistance(hex, stack->position);
 
 			//I hope it's approximately correct
 			return distance > 10 && !stack->hasBonusOfType(Bonus::NO_DISTANCE_PENALTY);
@@ -3721,6 +3719,13 @@ void BattleInfo::getBonuses(BonusList &out, const CSelector &selector, const CBo
 	}
 }
 
+si8 BattleInfo::getDistance( int hex1, int hex2 )
+{
+	int xDst = std::abs(hex1 % BFIELD_WIDTH - hex2 % BFIELD_WIDTH),
+		yDst = std::abs(hex1 / BFIELD_WIDTH - hex2 / BFIELD_WIDTH);
+	return std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2;
+}
+
 int3 CPath::startPos() const
 {
 	return nodes[nodes.size()-1].coord;

+ 1 - 0
lib/CGameState.h

@@ -207,6 +207,7 @@ struct DLL_EXPORT BattleInfo : public CBonusSystemNode
 	bool isStackBlocked(int ID); //returns true if there is neighboring enemy stack
 	static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
 	static std::vector<int> neighbouringTiles(int hex);
+	static si8 getDistance(int hex1, int hex2); //returns distance between given hexes
 	ui32 calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky); //charge - number of hexes travelled before attack (for champion's jousting)
 	std::pair<ui32, ui32> calculateDmgRange(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky); //charge - number of hexes travelled before attack (for champion's jousting); returns pair <min dmg, max dmg>
 	void calculateCasualties(std::map<ui32,si32> *casualties) const; //casualties are array of maps size 2 (attacker, defeneder), maps are (crid => amount)