All AI units that don't have a speciific target to attack will head towards the closest hostile city

This commit is contained in:
Yair Morgenstern
2018-07-03 16:37:20 +03:00
parent 9b59494a47
commit de6e3f9ec8

View File

@ -1,6 +1,7 @@
package com.unciv.logic.automation
import com.unciv.UnCivGame
import com.unciv.logic.HexMath
import com.unciv.logic.battle.Battle
import com.unciv.logic.battle.BattleDamage
import com.unciv.logic.battle.MapUnitCombatant
@ -146,6 +147,22 @@ class UnitAutomation{
return
}
// Focus all units without a specific target on the enemy city closest to one of our cities
val enemyCities = unit.civInfo.exploredTiles.map { unit.civInfo.gameInfo.tileMap[it] }
.filter { it.isCityCenter() && it.getOwner()!=unit.civInfo }
if(enemyCities.isNotEmpty() && unit.civInfo.cities.isNotEmpty()) {
val closestReachableEnemyCity = enemyCities
.filter { unit.movementAlgs().canReach(it) }
.minBy { city ->
unit.civInfo.cities.map { HexMath().getDistance(city.position, it.getCenterTile().position) }.min()!!
}
if (closestReachableEnemyCity != null) {
unit.movementAlgs().headTowards(closestReachableEnemyCity)
return
}
}
// else, go to a random space
randomWalk(unit)
// if both failed, then... there aren't any reachable tiles. Which is possible.