diff --git a/core/src/com/unciv/logic/automation/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/WorkerAutomation.kt index 1dd74fe301..f71d2dc900 100644 --- a/core/src/com/unciv/logic/automation/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/WorkerAutomation.kt @@ -109,9 +109,7 @@ class WorkerAutomation(val unit: MapUnit) { // which is why we DON'T calculate this for every possible tile in the radius, // but only for the tile that's about to be chosen. val selectedTile = workableTiles.firstOrNull{ - unit.movementAlgs() - .getShortestPath(workableTiles.first()) - .isNotEmpty()} + unit.movementAlgs().canReach(it) } if (selectedTile != null && getPriority(selectedTile, unit.civInfo)>1 diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 05257bfc68..bed1da1209 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -24,14 +24,6 @@ class UnitAction(var name: String, var canAct:Boolean, var action:()->Unit){ class UnitActions { - private fun constructImprovementAndDestroyUnit(unit:MapUnit, improvementName: String): () -> Unit { - return { - unit.getTile().improvement = improvementName - unit.destroy() - } - } - - fun getUnitActions(unit:MapUnit,worldScreen: WorldScreen): List { val tile = unit.getTile() val unitTable = worldScreen.bottomBar.unitTable @@ -75,7 +67,15 @@ class UnitActions { while (upgradedUnit.obsoleteTech!=null && unit.civInfo.tech.isResearched(upgradedUnit.obsoleteTech!!)) upgradedUnit = upgradedUnit.getUpgradeUnit(unit.civInfo) - if (upgradedUnit.isBuildable(unit.civInfo)) { + // We need to remove the unit from the civ for this check, + // because if the unit requires, say, horses, and so does its upgrade, + // and the civ currently has 0 horses, + // if we don;t remove the unit before the check it's return false! + unit.civInfo.removeUnit(unit) + val canUpgrade = upgradedUnit.isBuildable(unit.civInfo) + unit.civInfo.addUnit(unit) + + if (canUpgrade) { var goldCostOfUpgrade = (upgradedUnit.cost - unit.baseUnit().cost) * 2 + 10 if (unit.civInfo.policies.isAdopted("Professional Army")) goldCostOfUpgrade = (goldCostOfUpgrade * 0.66f).toInt() actionList += UnitAction("Upgrade to [${upgradedUnit.name}] ([$goldCostOfUpgrade] gold)", @@ -148,8 +148,12 @@ class UnitActions { for(unique in unit.getUniques().filter { it.startsWith("Can build improvement: ") }){ val improvementName = unique.replace("Can build improvement: ","") actionList += UnitAction("Create [$improvementName]", - unit.currentMovement != 0f && !tile.isCityCenter(), - constructImprovementAndDestroyUnit(unit, improvementName)).sound("chimes") + unit.currentMovement != 0f && !tile.isCityCenter() + ) { + unit.getTile().terrainFeature=null // remove forest/jungle/marsh + unit.getTile().improvement = improvementName + unit.destroy() + }.sound("chimes") }