mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -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 rangedUnits = mutableListOf<MapUnit>()
|
||||||
val meleeUnits = mutableListOf<MapUnit>()
|
val meleeUnits = mutableListOf<MapUnit>()
|
||||||
val civilianUnits = mutableListOf<MapUnit>()
|
val civilianUnits = mutableListOf<MapUnit>()
|
||||||
|
val generals = mutableListOf<MapUnit>()
|
||||||
|
|
||||||
for (unit in civInfo.getCivUnits()) {
|
for (unit in civInfo.getCivUnits()) {
|
||||||
if (unit.promotions.canBePromoted()) {
|
if (unit.promotions.canBePromoted()) {
|
||||||
@ -101,10 +102,10 @@ class NextTurnAutomation{
|
|||||||
unit.promotions.addPromotion(availablePromotions.getRandom().name)
|
unit.promotions.addPromotion(availablePromotions.getRandom().name)
|
||||||
}
|
}
|
||||||
|
|
||||||
val unitType = unit.type
|
|
||||||
when {
|
when {
|
||||||
unitType.isRanged() -> rangedUnits.add(unit)
|
unit.type.isRanged() -> rangedUnits.add(unit)
|
||||||
unitType.isMelee() -> meleeUnits.add(unit)
|
unit.type.isMelee() -> meleeUnits.add(unit)
|
||||||
|
unit.name == "Great General" -> generals.add(unit) //generals move after military units
|
||||||
else -> civilianUnits.add(unit)
|
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 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 rangedUnits) UnitAutomation().automateUnitMoves(unit)
|
||||||
for (unit in meleeUnits) UnitAutomation().automateUnitMoves(unit)
|
for (unit in meleeUnits) UnitAutomation().automateUnitMoves(unit)
|
||||||
|
for (unit in generals) UnitAutomation().automateUnitMoves(unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reassignWorkedTiles(civInfo: CivilizationInfo) {
|
private fun reassignWorkedTiles(civInfo: CivilizationInfo) {
|
||||||
|
@ -400,19 +400,23 @@ class SpecificUnitAutomation{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun automateGeneral(unit: MapUnit){
|
fun automateGeneral(unit: MapUnit){
|
||||||
|
//try to follow nearby units. Do not garrison in city if possible
|
||||||
val militantToCompany = unit.civInfo.getCivUnits()
|
val militantToCompany = unit.civInfo.getCivUnits()
|
||||||
.firstOrNull { val tile = it.currentTile
|
.firstOrNull { val tile = it.currentTile
|
||||||
it.type.isLandUnit() && it.getMaxMovement() <= 2.0f && tile.civilianUnit==null
|
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) {
|
if(militantToCompany!=null) {
|
||||||
unit.movementAlgs().headTowards(militantToCompany.currentTile)
|
unit.movementAlgs().headTowards(militantToCompany.currentTile)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val cityToGarison = unit.civInfo.cities.filter {it.getCenterTile().civilianUnit == null}
|
//if no unit to follow, take refuge in city.
|
||||||
.minBy { it.getCenterTile().arialDistanceTo(unit.currentTile) }
|
val cityToGarison = unit.civInfo.cities.map {it.getCenterTile()}
|
||||||
|
.filter {it.civilianUnit == null && unit.canMoveTo(it)}
|
||||||
|
.minBy { it.arialDistanceTo(unit.currentTile) }
|
||||||
if (cityToGarison != null) {
|
if (cityToGarison != null) {
|
||||||
unit.movementAlgs().headTowards(cityToGarison.getCenterTile())
|
unit.movementAlgs().headTowards(cityToGarison)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user