Some improvement on ai.

This commit is contained in:
Duan Tao 2018-12-27 11:44:30 +08:00
parent 0e77d5b044
commit 6c51073112
2 changed files with 13 additions and 7 deletions

View File

@ -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) {

View File

@ -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