From 0f1221e033e3f235b73107b767f657f83c9e6c6d Mon Sep 17 00:00:00 2001 From: Duan Tao Date: Wed, 23 Jan 2019 21:10:25 +0800 Subject: [PATCH] Fix seige units finding targets bug. --- core/src/com/unciv/logic/automation/UnitAutomation.kt | 5 +++-- core/src/com/unciv/logic/map/MapUnit.kt | 1 - core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index 8c3b1d83aa..52dab53de8 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -146,6 +146,7 @@ class UnitAutomation{ val tilesWithEnemies = unit.civInfo.viewableTiles .filter { containsAttackableEnemy(it, MapUnitCombatant(unit)) } + val minMovBeforeSetup = if (unit.hasUnique("Must set up to ranged attack") && unit.action != "Set Up" ) minMovementBeforeAttack+1.0f else minMovementBeforeAttack val rangeOfAttack = unit.getRange() val attackableTiles = ArrayList() @@ -155,7 +156,7 @@ class UnitAutomation{ // So the poor unit thought it could attack from the tile, but when it comes to do so it has no movement points! // Silly floats, basically val tilesToAttackFrom = unitDistanceToTiles.asSequence() - .filter { unit.currentMovement - it.value >= minMovementBeforeAttack } + .filter { unit.currentMovement - it.value >= minMovBeforeSetup } .map { it.key } .filter { unit.canMoveTo(it) || it==unit.getTile() } @@ -534,4 +535,4 @@ class SpecificUnitAutomation{ } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 9a4245dbbc..910e4f2891 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -185,7 +185,6 @@ class MapUnit { if(currentMovement==0f) return false if(attacksThisTurn>0 && !hasUnique("1 additional attack per turn")) return false if(attacksThisTurn>1) return false - if(hasUnique("Must set up to ranged attack") && action != "Set Up") return false return true } diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 950eeb352c..649d5b595a 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -153,6 +153,10 @@ class BattleTable(val worldScreen: WorldScreen): Table() { attackButton.onClick { if (attacker is MapUnitCombatant) { attacker.unit.moveToTile(attackableEnemy!!.tileToAttackFrom) + if (attacker.unit.hasUnique("Must set up to ranged attack") && attacker.unit.action != "Set Up") { + attacker.unit.action = "Set Up" + attacker.unit.useMovementPoints(1f) + } } battle.attack(attacker, defender) worldScreen.shouldUpdate=true