mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	2184 - fix battlefield corners unreachable for 2 hex units
This commit is contained in:
		| @@ -40,3 +40,42 @@ bool ReachabilityInfo::isReachable(BattleHex hex) const | ||||
| { | ||||
| 	return distances[hex] < INFINITE_DIST; | ||||
| } | ||||
|  | ||||
| int ReachabilityInfo::distToNearestNeighbour( | ||||
| 	const battle::Unit * attacker, | ||||
| 	const battle::Unit * defender, | ||||
| 	BattleHex * chosenHex) const | ||||
| { | ||||
| 	int ret = 1000000; | ||||
| 	auto defenderHexes = battle::Unit::getHexes( | ||||
| 		defender->getPosition(), | ||||
| 		defender->doubleWide(), | ||||
| 		defender->unitSide()); | ||||
|  | ||||
| 	std::vector<BattleHex> targetableHexes; | ||||
|  | ||||
| 	for(auto defenderHex : defenderHexes) | ||||
| 	{ | ||||
| 		vstd::concatenate(targetableHexes, battle::Unit::getHexes( | ||||
| 			defenderHex, | ||||
| 			attacker->doubleWide(), | ||||
| 			defender->unitSide())); | ||||
| 	} | ||||
|  | ||||
| 	vstd::removeDuplicates(targetableHexes); | ||||
|  | ||||
| 	for(auto targetableHex : targetableHexes) | ||||
| 	{ | ||||
| 		for(auto & n : targetableHex.neighbouringTiles()) | ||||
| 		{ | ||||
| 			if(distances[n] >= 0 && distances[n] < ret) | ||||
| 			{ | ||||
| 				ret = distances[n]; | ||||
| 				if(chosenHex) | ||||
| 					*chosenHex = n; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
|   | ||||
| @@ -43,6 +43,11 @@ struct DLL_LINKAGE ReachabilityInfo | ||||
| 	ReachabilityInfo(); | ||||
|  | ||||
| 	bool isReachable(BattleHex hex) const; | ||||
|  | ||||
| 	int distToNearestNeighbour( | ||||
| 		const battle::Unit * attacker, | ||||
| 		const battle::Unit * defender, | ||||
| 		BattleHex * chosenHex = nullptr) const; | ||||
| }; | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user