mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04: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.diplomacy.RelationshipLevel
|
||||||
import com.unciv.logic.civilization.managers.ReligionState
|
import com.unciv.logic.civilization.managers.ReligionState
|
||||||
import com.unciv.logic.map.BFS
|
import com.unciv.logic.map.BFS
|
||||||
|
import com.unciv.logic.map.mapunit.MapUnit
|
||||||
import com.unciv.logic.map.tile.Tile
|
import com.unciv.logic.map.tile.Tile
|
||||||
import com.unciv.logic.trade.Trade
|
import com.unciv.logic.trade.Trade
|
||||||
import com.unciv.logic.trade.TradeEvaluation
|
import com.unciv.logic.trade.TradeEvaluation
|
||||||
@ -1019,18 +1020,23 @@ object NextTurnAutomation {
|
|||||||
|
|
||||||
|
|
||||||
private fun automateUnits(civInfo: Civilization) {
|
private fun automateUnits(civInfo: Civilization) {
|
||||||
val sortedUnits = civInfo.units.getCivUnits().sortedBy { unit ->
|
val isAtWar = civInfo.isAtWar()
|
||||||
when {
|
val sortedUnits = civInfo.units.getCivUnits().sortedBy { unit -> getUnitPriority(unit, isAtWar) }
|
||||||
unit.baseUnit.isAirUnit() -> 2
|
|
||||||
unit.baseUnit.isRanged() -> 3
|
|
||||||
unit.baseUnit.isMelee() -> 4
|
|
||||||
unit.isGreatPersonOfType("War") -> 5 // Generals move after military units
|
|
||||||
else -> 1 // Civilian
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (unit in sortedUnits) UnitAutomation.automateUnitMoves(unit)
|
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) {
|
private fun automateCityBombardment(civInfo: Civilization) {
|
||||||
for (city in civInfo.cities) UnitAutomation.tryBombardEnemy(city)
|
for (city in civInfo.cities) UnitAutomation.tryBombardEnemy(city)
|
||||||
}
|
}
|
||||||
|
@ -442,6 +442,14 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
|||||||
fun isGreatPerson() = baseUnit.isGreatPerson()
|
fun isGreatPerson() = baseUnit.isGreatPerson()
|
||||||
fun isGreatPersonOfType(type: String) = baseUnit.isGreatPersonOfType(type)
|
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
|
//endregion
|
||||||
|
|
||||||
//region state-changing functions
|
//region state-changing functions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user