From 6370f0ac02ce821f4d3d51fcc13badc8410ecd2b Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 2 Aug 2021 23:26:14 +0300 Subject: [PATCH] Solved super rare edge-case where units try to attack over hidden tiles that they can't actually move through --- core/src/com/unciv/logic/battle/Battle.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index f92b81bce5..2284f13fdd 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -25,6 +25,15 @@ object Battle { fun moveAndAttack(attacker: ICombatant, attackableTile: AttackableTile) { if (attacker is MapUnitCombatant) { attacker.unit.movement.moveToTile(attackableTile.tileToAttackFrom) + /** You might ask: When can this possibly happen? + * We always receive an AttackableTile, which means that it was returned from getAttackableTiles! + * The answer is: when crossing a HIDDEN TILE. + * When calculating movement distance, we assume that a hidden tile is 1 movement point, + * which can lead to EXCEEDINGLY RARE edge cases where you think + * that you can attack a tile by passing through a hidden tile, + * but the hidden tile is actually IMPASSIBLE so you stop halfway! + */ + if (attacker.getTile() != attackableTile.tileToAttackFrom) return if (attacker.unit.hasUnique("Must set up to ranged attack") && attacker.unit.action != Constants.unitActionSetUp) { attacker.unit.action = Constants.unitActionSetUp attacker.unit.useMovementPoints(1f)