Civs no longer spam settlers beyond what they can afford

This commit is contained in:
Yair Morgenstern 2018-05-17 10:43:45 +03:00
parent d3799a0c64
commit e267a7a6be
2 changed files with 10 additions and 5 deletions

View File

@ -62,12 +62,12 @@ class Automation {
}
private fun trainCombatUnit(city: CityInfo) {
val buildableUnits = city.cityConstructions.getConstructableUnits()
val combatUnits = city.cityConstructions.getConstructableUnits().filter { it.unitType != UnitType.Civilian }
val chosenUnit:Unit
if(city.civInfo.cities.any { it.getCenterTile().unit==null}
&& buildableUnits.any { it.unitType==UnitType.Archery }) // this is for city defence so get an archery unit if we can
chosenUnit = buildableUnits.filter { it.unitType==UnitType.Archery }.maxBy { it.cost }!!
else chosenUnit = buildableUnits.maxBy { it.cost }!!
&& combatUnits.any { it.unitType==UnitType.Archery }) // this is for city defence so get an archery unit if we can
chosenUnit = combatUnits.filter { it.unitType==UnitType.Archery }.maxBy { it.cost }!!
else chosenUnit = combatUnits.maxBy { it.cost }!!
city.cityConstructions.currentConstruction = chosenUnit.name
}

View File

@ -86,7 +86,8 @@ class MapUnit {
fun moveToTile(otherTile: TileInfo) {
val distanceToTiles = getDistanceToTiles()
if (!distanceToTiles.containsKey(otherTile)) throw Exception("You can't get there from here!")
if (!distanceToTiles.containsKey(otherTile))
throw Exception("You can't get there from here!")
if (otherTile.unit != null ) throw Exception("Tile already contains a unit!")
currentMovement -= distanceToTiles[otherTile]!!
@ -113,4 +114,8 @@ class MapUnit {
}
fun movementAlgs() = UnitMovementAlgorithms(this)
override fun toString(): String {
return name +" - "+owner
}
}