Reassign workers when resistance ends or improvement created (#9212)

This commit is contained in:
SomeTroglodyte
2023-04-19 10:34:31 +02:00
committed by GitHub
parent 85c0f71f2a
commit 52f26ed9d3
5 changed files with 16 additions and 17 deletions

View File

@ -156,6 +156,7 @@ class CityInfoConquestFunctions(val city: City){
fun annexCity() { fun annexCity() {
city.isPuppet = false city.isPuppet = false
city.cityConstructions.inProgressConstructions.clear() // undo all progress of the previous civ on units etc. city.cityConstructions.inProgressConstructions.clear() // undo all progress of the previous civ on units etc.
if (!city.isInResistance()) city.updateCitizens = true
city.cityStats.update() city.cityStats.update()
GUI.setUpdateWorldOnNextRender() GUI.setUpdateWorldOnNextRender()
} }

View File

@ -19,22 +19,23 @@ class CityTurnManager(val city: City) {
city.cityConstructions.constructIfEnough() city.cityConstructions.constructIfEnough()
city.cityConstructions.addFreeBuildings() city.cityConstructions.addFreeBuildings()
city.cityStats.update()
city.tryUpdateRoadStatus() city.tryUpdateRoadStatus()
city.attackedThisTurn = false 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) { if (city.isPuppet) {
city.cityAIFocus = CityFocus.GoldFocus city.cityAIFocus = CityFocus.GoldFocus
city.reassignAllPopulation() city.reassignAllPopulation()
} else if (city.updateCitizens) { } else if (city.updateCitizens) {
city.reassignPopulation() city.reassignPopulation() // includes cityStats.update
city.updateCitizens = false city.updateCitizens = false
} } else
city.cityStats.update()
// 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()
// Seed resource demand countdown // Seed resource demand countdown
if (city.demandedResource == "" && !city.hasFlag(CityFlags.ResourceDemand)) { if (city.demandedResource == "" && !city.hasFlag(CityFlags.ResourceDemand)) {
@ -74,6 +75,7 @@ class CityTurnManager(val city: City) {
demandNewResource() demandNewResource()
} }
CityFlags.Resistance.name -> { CityFlags.Resistance.name -> {
city.updateCitizens = true
city.civ.addNotification( city.civ.addNotification(
"The resistance in [${city.name}] has ended!", "The resistance in [${city.name}] has ended!",
city.location, NotificationCategory.General, "StatIcons/Resistance") city.location, NotificationCategory.General, "StatIcons/Resistance")

View File

@ -208,9 +208,8 @@ class UnitTurnManager(val unit: MapUnit) {
tile.improvementInProgress == RoadStatus.Railroad.name -> tile.addRoad(RoadStatus.Railroad, unit.civ) tile.improvementInProgress == RoadStatus.Railroad.name -> tile.addRoad(RoadStatus.Railroad, unit.civ)
tile.improvementInProgress == Constants.repair -> tile.setRepaired() tile.improvementInProgress == Constants.repair -> tile.setRepaired()
else -> { else -> {
val improvement = unit.civ.gameInfo.ruleset.tileImprovements[tile.improvementInProgress]!!
improvement.handleImprovementCompletion(unit)
tile.changeImprovement(tile.improvementInProgress) tile.changeImprovement(tile.improvementInProgress)
tile.getTileImprovement()!!.handleImprovementCompletion(unit)
} }
} }

View File

@ -80,6 +80,7 @@ class TileImprovement : RulesetStatsObject() {
if (tile.resource != null) { if (tile.resource != null) {
val city = builder.getTile().getCity() val city = builder.getTile().getCity()
if (city != null) { if (city != null) {
city.updateCitizens = true
city.cityStats.update() city.cityStats.update()
city.civ.cache.updateCivResources() city.civ.cache.updateCivResources()
} }

View File

@ -159,12 +159,8 @@ object UnitActions {
return UnitAction(UnitActionType.Create, "Create [$improvementName]", return UnitAction(UnitActionType.Create, "Create [$improvementName]",
action = { action = {
tile.changeImprovement(improvementName) tile.changeImprovement(improvementName)
val city = tile.getCity() tile.getTileImprovement()!!.handleImprovementCompletion(unit)
if (city != null) { unit.destroy() // Modders may wish for a nondestructive way, but that should be another Unique
city.cityStats.update()
city.civ.cache.updateCivResources()
}
unit.destroy()
}.takeIf { unit.currentMovement > 0 }) }.takeIf { unit.currentMovement > 0 })
} }
@ -502,7 +498,7 @@ object UnitActions {
unitTile.stopWorkingOnImprovement() unitTile.stopWorkingOnImprovement()
improvement.handleImprovementCompletion(unit) 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() unit.civ.cache.updateViewableTiles()
if (unique.type == UniqueType.ConstructImprovementConsumingUnit) unit.consume() if (unique.type == UniqueType.ConstructImprovementConsumingUnit) unit.consume()