mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
Some improvement on ai.
This commit is contained in:
parent
0e77d5b044
commit
6c51073112
@ -93,6 +93,7 @@ class NextTurnAutomation{
|
||||
val rangedUnits = mutableListOf<MapUnit>()
|
||||
val meleeUnits = mutableListOf<MapUnit>()
|
||||
val civilianUnits = mutableListOf<MapUnit>()
|
||||
val generals = mutableListOf<MapUnit>()
|
||||
|
||||
for (unit in civInfo.getCivUnits()) {
|
||||
if (unit.promotions.canBePromoted()) {
|
||||
@ -101,10 +102,10 @@ class NextTurnAutomation{
|
||||
unit.promotions.addPromotion(availablePromotions.getRandom().name)
|
||||
}
|
||||
|
||||
val unitType = unit.type
|
||||
when {
|
||||
unitType.isRanged() -> rangedUnits.add(unit)
|
||||
unitType.isMelee() -> meleeUnits.add(unit)
|
||||
unit.type.isRanged() -> rangedUnits.add(unit)
|
||||
unit.type.isMelee() -> meleeUnits.add(unit)
|
||||
unit.name == "Great General" -> generals.add(unit) //generals move after military units
|
||||
else -> civilianUnits.add(unit)
|
||||
}
|
||||
}
|
||||
@ -112,6 +113,7 @@ class NextTurnAutomation{
|
||||
for (unit in civilianUnits) UnitAutomation().automateUnitMoves(unit) // They move first so that combat units can accompany a settler
|
||||
for (unit in rangedUnits) UnitAutomation().automateUnitMoves(unit)
|
||||
for (unit in meleeUnits) UnitAutomation().automateUnitMoves(unit)
|
||||
for (unit in generals) UnitAutomation().automateUnitMoves(unit)
|
||||
}
|
||||
|
||||
private fun reassignWorkedTiles(civInfo: CivilizationInfo) {
|
||||
|
@ -400,19 +400,23 @@ class SpecificUnitAutomation{
|
||||
}
|
||||
|
||||
fun automateGeneral(unit: MapUnit){
|
||||
//try to follow nearby units. Do not garrison in city if possible
|
||||
val militantToCompany = unit.civInfo.getCivUnits()
|
||||
.firstOrNull { val tile = it.currentTile
|
||||
it.type.isLandUnit() && it.getMaxMovement() <= 2.0f && tile.civilianUnit==null
|
||||
&& unit.canMoveTo(tile) && unit.movementAlgs().canReach(tile) }
|
||||
&& unit.canMoveTo(tile) && unit.movementAlgs().canReach(tile) && !tile.isCityCenter() }
|
||||
|
||||
if(militantToCompany!=null) {
|
||||
unit.movementAlgs().headTowards(militantToCompany.currentTile)
|
||||
return
|
||||
}
|
||||
|
||||
val cityToGarison = unit.civInfo.cities.filter {it.getCenterTile().civilianUnit == null}
|
||||
.minBy { it.getCenterTile().arialDistanceTo(unit.currentTile) }
|
||||
//if no unit to follow, take refuge in city.
|
||||
val cityToGarison = unit.civInfo.cities.map {it.getCenterTile()}
|
||||
.filter {it.civilianUnit == null && unit.canMoveTo(it)}
|
||||
.minBy { it.arialDistanceTo(unit.currentTile) }
|
||||
if (cityToGarison != null) {
|
||||
unit.movementAlgs().headTowards(cityToGarison.getCenterTile())
|
||||
unit.movementAlgs().headTowards(cityToGarison)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user