From d0a59889c4b2b75cb90d58bc44205198503f1bb3 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 28 Dec 2020 19:32:28 +0200 Subject: [PATCH] Can now choose construction to work on even when worker has no movement points, since it won't advance unless he does --- .../unciv/ui/worldscreen/unit/UnitActions.kt | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index d4afcf5e08..e2c8e765f8 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -81,12 +81,12 @@ object UnitActions { else "Do you really want to disband this unit?".tr() YesNoPopup(disbandText, { unit.disband(); worldScreen.shouldUpdate = true }).open() } - }.takeIf {unit.currentMovement > 0} ) + }.takeIf { unit.currentMovement > 0 }) } private fun addCreateWaterImprovements(unit: MapUnit, actionList: ArrayList) { val waterImprovementAction = getWaterImprovementAction(unit) - if(waterImprovementAction!=null) actionList += waterImprovementAction + if (waterImprovementAction != null) actionList += waterImprovementAction } fun getWaterImprovementAction(unit: MapUnit): UnitAction? { @@ -104,7 +104,7 @@ object UnitActions { action = { tile.improvement = improvement unit.destroy() - }.takeIf {unit.currentMovement > 0}) + }.takeIf { unit.currentMovement > 0 }) } return null } @@ -115,7 +115,7 @@ object UnitActions { && tile.roadStatus == RoadStatus.None && tile.improvementInProgress != "Road" && tile.isLand - && (improvement.techRequired==null || unit.civInfo.tech.isResearched(improvement.techRequired!!))) + && (improvement.techRequired == null || unit.civInfo.tech.isResearched(improvement.techRequired!!))) actionList += UnitAction( type = UnitActionType.ConstructRoad, action = { @@ -129,7 +129,7 @@ object UnitActions { if (getFoundCityAction != null) actionList += getFoundCityAction } - fun getFoundCityAction(unit:MapUnit, tile: TileInfo): UnitAction? { + fun getFoundCityAction(unit: MapUnit, tile: TileInfo): UnitAction? { if (!unit.hasUnique("Founds a new city") || tile.isWater) return null return UnitAction( type = UnitActionType.FoundCity, @@ -168,7 +168,7 @@ object UnitActions { private fun addPillageAction(unit: MapUnit, actionList: ArrayList, worldScreen: WorldScreen) { val pillageAction = getPillageAction(unit) if (pillageAction == null) return - if(pillageAction.action==null) + if (pillageAction.action == null) actionList += UnitAction(UnitActionType.Pillage, action = null) else actionList += UnitAction(type = UnitActionType.Pillage) { if (!worldScreen.hasOpenPopups()) { @@ -192,11 +192,11 @@ object UnitActions { tile.turnsToImprovement = 2 } tile.improvement = null - if (tile.resource!=null) tile.getOwner()?.updateDetailedCivResources() // this might take away a resource + if (tile.resource != null) tile.getOwner()?.updateDetailedCivResources() // this might take away a resource val freePillage = unit.hasUnique("No movement cost to pillage") || (unit.type.isMelee() && unit.civInfo.hasUnique("Melee units pay no movement cost to pillage")) - if(!freePillage) unit.useMovementPoints(1f) + if (!freePillage) unit.useMovementPoints(1f) unit.healBy(25) @@ -210,7 +210,7 @@ object UnitActions { type = UnitActionType.Explore, action = { unit.action = Constants.unitActionExplore - if(unit.currentMovement>0) UnitAutomation.automatedExplore(unit) + if (unit.currentMovement > 0) UnitAutomation.automatedExplore(unit) }) } else { actionList += UnitAction( @@ -222,7 +222,7 @@ object UnitActions { private fun addUnitUpgradeAction(unit: MapUnit, actionList: ArrayList) { val upgradeAction = getUpgradeAction(unit) - if(upgradeAction!=null) actionList += upgradeAction + if (upgradeAction != null) actionList += upgradeAction } fun getUpgradeAction(unit: MapUnit): UnitAction? { @@ -275,11 +275,11 @@ object UnitActions { }.takeIf { unit.currentMovement > 0 }) } - if(unit.isEmbarked()) return + if (unit.isEmbarked()) return - val canConstruct =unit.currentMovement > 0 - && !tile.isCityCenter() - && unit.civInfo.gameInfo.ruleSet.tileImprovements.values.any { tile.canBuildImprovement(it, unit.civInfo) } + val canConstruct = !tile.isCityCenter() + && unit.civInfo.gameInfo.ruleSet.tileImprovements.values + .any { tile.canBuildImprovement(it, unit.civInfo) } actionList += UnitAction( type = UnitActionType.ConstructImprovement, isCurrentAction = unit.currentTile.hasImprovementInProgress(), @@ -358,7 +358,7 @@ object UnitActions { val finalActions = ArrayList() for (unique in unit.getMatchingUniques("Can construct []")) { val improvementName = unique.params[0] - finalActions += UnitAction( + finalActions += UnitAction( type = UnitActionType.Create, title = "Create [$improvementName]", uncivSound = UncivSound.Chimes, @@ -379,12 +379,14 @@ object UnitActions { } addGoldPerGreatPersonUsage(unit.civInfo) unit.destroy() - }.takeIf { unit.currentMovement > 0f && !tile.isWater && - !tile.isCityCenter() && !tile.isImpassible() && - tile.improvement != improvementName && - // citadel can be built only next to or within own borders - (improvementName != Constants.citadel || - tile.neighbors.any { it.getOwner() == unit.civInfo })}) + }.takeIf { + unit.currentMovement > 0f && !tile.isWater && + !tile.isCityCenter() && !tile.isImpassible() && + tile.improvement != improvementName && + // citadel can be built only next to or within own borders + (improvementName != Constants.citadel || + tile.neighbors.any { it.getOwner() == unit.civInfo }) + }) } return finalActions } @@ -403,7 +405,7 @@ object UnitActions { val otherCiv = tile.getOwner() if (otherCiv != null) { // decrease relations for -10 pt/tile - if(!otherCiv.knows(unit.civInfo)) otherCiv.meetCivilization(unit.civInfo) + if (!otherCiv.knows(unit.civInfo)) otherCiv.meetCivilization(unit.civInfo) otherCiv.getDiplomacyManager(unit.civInfo).addModifier(DiplomaticModifiers.StealingTerritory, -10f) notifications.add(otherCiv) } @@ -482,4 +484,4 @@ object UnitActions { // Can't pillage friendly tiles, just like you can't attack them - it's an 'act of war' thing return tileOwner == null || tileOwner == unit.civInfo || unit.civInfo.isAtWarWith(tileOwner) } -} +} \ No newline at end of file