From 52f26ed9d3db37ded2e79b1534b441a66d551ea7 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Wed, 19 Apr 2023 10:34:31 +0200 Subject: [PATCH] Reassign workers when resistance ends or improvement created (#9212) --- .../city/managers/CityInfoConquestFunctions.kt | 1 + .../logic/city/managers/CityTurnManager.kt | 18 ++++++++++-------- .../unciv/logic/map/mapunit/UnitTurnManager.kt | 3 +-- .../models/ruleset/tile/TileImprovement.kt | 1 + .../worldscreen/unit/actions/UnitActions.kt | 10 +++------- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/core/src/com/unciv/logic/city/managers/CityInfoConquestFunctions.kt b/core/src/com/unciv/logic/city/managers/CityInfoConquestFunctions.kt index 132c4c33fb..a0079a8026 100644 --- a/core/src/com/unciv/logic/city/managers/CityInfoConquestFunctions.kt +++ b/core/src/com/unciv/logic/city/managers/CityInfoConquestFunctions.kt @@ -156,6 +156,7 @@ class CityInfoConquestFunctions(val city: City){ fun annexCity() { city.isPuppet = false city.cityConstructions.inProgressConstructions.clear() // undo all progress of the previous civ on units etc. + if (!city.isInResistance()) city.updateCitizens = true city.cityStats.update() GUI.setUpdateWorldOnNextRender() } diff --git a/core/src/com/unciv/logic/city/managers/CityTurnManager.kt b/core/src/com/unciv/logic/city/managers/CityTurnManager.kt index 5372e5d840..bcccf1b22f 100644 --- a/core/src/com/unciv/logic/city/managers/CityTurnManager.kt +++ b/core/src/com/unciv/logic/city/managers/CityTurnManager.kt @@ -19,22 +19,23 @@ class CityTurnManager(val city: City) { city.cityConstructions.constructIfEnough() city.cityConstructions.addFreeBuildings() - city.cityStats.update() city.tryUpdateRoadStatus() city.attackedThisTurn = false + // The ordering is intentional - you get a turn without WLTKD even if you have the next resource already + // Also resolve end of resistance before updateCitizens + if (!city.hasFlag(CityFlags.WeLoveTheKing)) + tryWeLoveTheKing() + nextTurnFlags() + if (city.isPuppet) { city.cityAIFocus = CityFocus.GoldFocus city.reassignAllPopulation() } else if (city.updateCitizens) { - city.reassignPopulation() + city.reassignPopulation() // includes cityStats.update city.updateCitizens = false - } - - // The ordering is intentional - you get a turn without WLTKD even if you have the next resource already - if (!city.hasFlag(CityFlags.WeLoveTheKing)) - tryWeLoveTheKing() - nextTurnFlags() + } else + city.cityStats.update() // Seed resource demand countdown if (city.demandedResource == "" && !city.hasFlag(CityFlags.ResourceDemand)) { @@ -74,6 +75,7 @@ class CityTurnManager(val city: City) { demandNewResource() } CityFlags.Resistance.name -> { + city.updateCitizens = true city.civ.addNotification( "The resistance in [${city.name}] has ended!", city.location, NotificationCategory.General, "StatIcons/Resistance") diff --git a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt index 14d5867537..6767daadcc 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt @@ -208,9 +208,8 @@ class UnitTurnManager(val unit: MapUnit) { tile.improvementInProgress == RoadStatus.Railroad.name -> tile.addRoad(RoadStatus.Railroad, unit.civ) tile.improvementInProgress == Constants.repair -> tile.setRepaired() else -> { - val improvement = unit.civ.gameInfo.ruleset.tileImprovements[tile.improvementInProgress]!! - improvement.handleImprovementCompletion(unit) tile.changeImprovement(tile.improvementInProgress) + tile.getTileImprovement()!!.handleImprovementCompletion(unit) } } diff --git a/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt b/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt index 88481c1005..20e44801fe 100644 --- a/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt +++ b/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt @@ -80,6 +80,7 @@ class TileImprovement : RulesetStatsObject() { if (tile.resource != null) { val city = builder.getTile().getCity() if (city != null) { + city.updateCitizens = true city.cityStats.update() city.civ.cache.updateCivResources() } diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt index 1bc32058dd..f66bfc66a8 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt @@ -159,12 +159,8 @@ object UnitActions { return UnitAction(UnitActionType.Create, "Create [$improvementName]", action = { tile.changeImprovement(improvementName) - val city = tile.getCity() - if (city != null) { - city.cityStats.update() - city.civ.cache.updateCivResources() - } - unit.destroy() + tile.getTileImprovement()!!.handleImprovementCompletion(unit) + unit.destroy() // Modders may wish for a nondestructive way, but that should be another Unique }.takeIf { unit.currentMovement > 0 }) } @@ -502,7 +498,7 @@ object UnitActions { unitTile.stopWorkingOnImprovement() improvement.handleImprovementCompletion(unit) - // without this the world screen won't the improvement because it isn't the 'last seen improvement' + // without this the world screen won't show the improvement because it isn't the 'last seen improvement' unit.civ.cache.updateViewableTiles() if (unique.type == UniqueType.ConstructImprovementConsumingUnit) unit.consume()