From e267a7a6be9e55ae709736fde2ec6fe688e0c944 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 17 May 2018 10:43:45 +0300 Subject: [PATCH] Civs no longer spam settlers beyond what they can afford --- core/src/com/unciv/logic/automation/Automation.kt | 8 ++++---- core/src/com/unciv/logic/map/MapUnit.kt | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index 18ad5fb383..2e31beaf86 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -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 } diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index f169fb4f6c..c6ee92f50f 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -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 + } } \ No newline at end of file