mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-12 08:49:22 +07:00
More reapply CityFocus on yield changes (#9459)
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.unciv.logic.city
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.GUI
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
import com.unciv.logic.city.managers.CityEspionageManager
|
||||
import com.unciv.logic.city.managers.CityExpansionManager
|
||||
@ -403,6 +404,10 @@ class City : IsPartOfGameInfoSerialization {
|
||||
reassignPopulation(resetLocked = true)
|
||||
}
|
||||
|
||||
/** Apply worked tiles optimization (aka CityFocus) - Expensive!
|
||||
*
|
||||
* If the next City.startTurn is soon enough, then use [reassignPopulationDeferred] instead.
|
||||
*/
|
||||
fun reassignPopulation(resetLocked: Boolean = false) {
|
||||
if (resetLocked) {
|
||||
workedTiles = hashSetOf()
|
||||
@ -412,9 +417,20 @@ class City : IsPartOfGameInfoSerialization {
|
||||
}
|
||||
if (!manualSpecialists)
|
||||
population.specialistAllocations.clear()
|
||||
updateCitizens = false
|
||||
population.autoAssignPopulation()
|
||||
}
|
||||
|
||||
/** Apply worked tiles optimization (aka CityFocus) -
|
||||
* immediately for a human player whoes turn it is (interactive),
|
||||
* or deferred to the next startTurn while nextTurn is running (for AI)
|
||||
* @see reassignPopulation
|
||||
*/
|
||||
fun reassignPopulationDeferred() {
|
||||
// TODO - is this the best (or even correct) way to detect "interactive" UI calls?
|
||||
if (GUI.isMyTurn() && GUI.getViewingPlayer() == civ) reassignPopulation()
|
||||
else updateCitizens = true
|
||||
}
|
||||
|
||||
fun destroyCity(overrideSafeties: Boolean = false) {
|
||||
// Original capitals and holy cities cannot be destroyed,
|
||||
|
@ -73,6 +73,9 @@ class CityExpansionManager : IsPartOfGameInfoSerialization {
|
||||
throw NotEnoughGoldToBuyTileException()
|
||||
city.civ.addGold(-goldCost)
|
||||
takeOwnership(tile)
|
||||
|
||||
// Reapply worked tiles optimization (aka CityFocus) - doing it here means AI profits too
|
||||
city.reassignPopulationDeferred()
|
||||
}
|
||||
|
||||
fun getGoldCostOfTile(tile: Tile): Int {
|
||||
|
@ -33,7 +33,6 @@ class CityTurnManager(val city: City) {
|
||||
city.reassignAllPopulation()
|
||||
} else if (city.updateCitizens) {
|
||||
city.reassignPopulation() // includes cityStats.update
|
||||
city.updateCitizens = false
|
||||
} else
|
||||
city.cityStats.update()
|
||||
|
||||
|
@ -883,7 +883,11 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
return
|
||||
// http://well-of-souls.com/civ/civ5_improvements.html says that naval improvements are destroyed upon pillage
|
||||
// and I can't find any other sources so I'll go with that
|
||||
if (!isLand) { changeImprovement(null); return }
|
||||
if (!isLand) {
|
||||
changeImprovement(null)
|
||||
owningCity?.reassignPopulationDeferred()
|
||||
return
|
||||
}
|
||||
|
||||
// Setting turnsToImprovement might interfere with UniqueType.CreatesOneImprovement
|
||||
improvementFunctions.removeCreatesOneImprovementMarker()
|
||||
@ -902,6 +906,8 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
else
|
||||
roadIsPillaged = true
|
||||
}
|
||||
|
||||
owningCity?.reassignPopulationDeferred()
|
||||
}
|
||||
|
||||
fun isPillaged(): Boolean {
|
||||
@ -915,6 +921,8 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
improvementIsPillaged = false
|
||||
else
|
||||
roadIsPillaged = false
|
||||
|
||||
owningCity?.reassignPopulationDeferred()
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user