mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-05 21:11:35 +07:00
AI now move units closer to enemy first in wartime (#9967)
This commit is contained in:
parent
88741f95e9
commit
c8de5a7de3
@ -20,6 +20,7 @@ import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||
import com.unciv.logic.civilization.managers.ReligionState
|
||||
import com.unciv.logic.map.BFS
|
||||
import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import com.unciv.logic.trade.Trade
|
||||
import com.unciv.logic.trade.TradeEvaluation
|
||||
@ -1019,17 +1020,22 @@ object NextTurnAutomation {
|
||||
|
||||
|
||||
private fun automateUnits(civInfo: Civilization) {
|
||||
val sortedUnits = civInfo.units.getCivUnits().sortedBy { unit ->
|
||||
when {
|
||||
unit.baseUnit.isAirUnit() -> 2
|
||||
unit.baseUnit.isRanged() -> 3
|
||||
unit.baseUnit.isMelee() -> 4
|
||||
unit.isGreatPersonOfType("War") -> 5 // Generals move after military units
|
||||
else -> 1 // Civilian
|
||||
}
|
||||
}
|
||||
val isAtWar = civInfo.isAtWar()
|
||||
val sortedUnits = civInfo.units.getCivUnits().sortedBy { unit -> getUnitPriority(unit, isAtWar) }
|
||||
for (unit in sortedUnits) UnitAutomation.automateUnitMoves(unit)
|
||||
}
|
||||
|
||||
private fun getUnitPriority(unit: MapUnit, isAtWar: Boolean): Int {
|
||||
if (unit.isCivilian() && !unit.isGreatPersonOfType("War")) return 1 // Civilian
|
||||
if (unit.baseUnit.isAirUnit()) return 2
|
||||
val distance = if (!isAtWar) 0 else unit.getDistanceToEnemyUnit(6)
|
||||
return (distance ?: 5) + when {
|
||||
unit.baseUnit.isRanged() -> 2
|
||||
unit.baseUnit.isMelee() -> 3
|
||||
unit.isGreatPersonOfType("War") -> 100 // Generals move after military units
|
||||
else -> 1
|
||||
}
|
||||
}
|
||||
|
||||
private fun automateCityBombardment(civInfo: Civilization) {
|
||||
for (city in civInfo.cities) UnitAutomation.tryBombardEnemy(city)
|
||||
|
@ -442,6 +442,14 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
fun isGreatPerson() = baseUnit.isGreatPerson()
|
||||
fun isGreatPersonOfType(type: String) = baseUnit.isGreatPersonOfType(type)
|
||||
|
||||
fun getDistanceToEnemyUnit(maxDist: Int): Int? {
|
||||
for (i in 1..maxDist) {
|
||||
if (currentTile.getTilesAtDistance(i).any {it.militaryUnit != null
|
||||
&& it.militaryUnit!!.civ.isAtWarWith(civ) })
|
||||
return i
|
||||
}
|
||||
return null
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region state-changing functions
|
||||
|
Loading…
Reference in New Issue
Block a user