Fix seige units finding targets bug.

This commit is contained in:
Duan Tao 2019-01-23 21:10:25 +08:00
parent 0e5c1843fe
commit 0f1221e033
3 changed files with 7 additions and 3 deletions

View file

@ -146,6 +146,7 @@ class UnitAutomation{
val tilesWithEnemies = unit.civInfo.viewableTiles val tilesWithEnemies = unit.civInfo.viewableTiles
.filter { containsAttackableEnemy(it, MapUnitCombatant(unit)) } .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 rangeOfAttack = unit.getRange()
val attackableTiles = ArrayList<AttackableTile>() val attackableTiles = ArrayList<AttackableTile>()
@ -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! // 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 // Silly floats, basically
val tilesToAttackFrom = unitDistanceToTiles.asSequence() val tilesToAttackFrom = unitDistanceToTiles.asSequence()
.filter { unit.currentMovement - it.value >= minMovementBeforeAttack } .filter { unit.currentMovement - it.value >= minMovBeforeSetup }
.map { it.key } .map { it.key }
.filter { unit.canMoveTo(it) || it==unit.getTile() } .filter { unit.canMoveTo(it) || it==unit.getTile() }
@ -534,4 +535,4 @@ class SpecificUnitAutomation{
} }
} }

View file

@ -185,7 +185,6 @@ class MapUnit {
if(currentMovement==0f) return false if(currentMovement==0f) return false
if(attacksThisTurn>0 && !hasUnique("1 additional attack per turn")) return false if(attacksThisTurn>0 && !hasUnique("1 additional attack per turn")) return false
if(attacksThisTurn>1) return false if(attacksThisTurn>1) return false
if(hasUnique("Must set up to ranged attack") && action != "Set Up") return false
return true return true
} }

View file

@ -153,6 +153,10 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
attackButton.onClick { attackButton.onClick {
if (attacker is MapUnitCombatant) { if (attacker is MapUnitCombatant) {
attacker.unit.moveToTile(attackableEnemy!!.tileToAttackFrom) 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) battle.attack(attacker, defender)
worldScreen.shouldUpdate=true worldScreen.shouldUpdate=true