mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-10 12:51:16 +07:00
Save city focus as string, to allow changes in available city focuses without breaking games (#10794)
This commit is contained in:
parent
5f8d2ce340
commit
b56a168e86
@ -44,7 +44,7 @@ object Automation {
|
||||
val zeroFoodFocuses = setOf(CityFocus.CultureFocus, CityFocus.FaithFocus, CityFocus.GoldFocus,
|
||||
CityFocus.HappinessFocus, CityFocus.ProductionFocus, CityFocus.ScienceFocus)
|
||||
private fun rankStatsForCityWork(stats: Stats, city: City, cityStats: Stats, specialist: Boolean, localUniqueCache: LocalUniqueCache): Float {
|
||||
val cityAIFocus = city.cityAIFocus
|
||||
val cityAIFocus = city.getCityFocus()
|
||||
val yieldStats = stats.clone()
|
||||
|
||||
if (specialist) {
|
||||
|
@ -87,7 +87,13 @@ class City : IsPartOfGameInfoSerialization {
|
||||
var hasSoldBuildingThisTurn = false
|
||||
var isPuppet = false
|
||||
var updateCitizens = false // flag so that on startTurn() the Governor reassigns Citizens
|
||||
var cityAIFocus: CityFocus = CityFocus.NoFocus
|
||||
|
||||
var cityAIFocus: String = CityFocus.NoFocus.name
|
||||
fun getCityFocus() = CityFocus.values().firstOrNull { it.name == cityAIFocus } ?: CityFocus.NoFocus
|
||||
fun setCityFocus(cityFocus: CityFocus){ cityAIFocus = cityFocus.name }
|
||||
|
||||
|
||||
|
||||
var avoidGrowth: Boolean = false
|
||||
@Transient var currentGPPBonus: Int = 0 // temporary variable saved for rankSpecialist()
|
||||
|
||||
|
@ -32,7 +32,7 @@ class CityTurnManager(val city: City) {
|
||||
nextTurnFlags()
|
||||
|
||||
if (city.isPuppet) {
|
||||
city.cityAIFocus = CityFocus.GoldFocus
|
||||
city.setCityFocus(CityFocus.GoldFocus)
|
||||
city.reassignAllPopulation()
|
||||
} else if (city.updateCitizens) {
|
||||
city.reassignPopulation() // includes cityStats.update
|
||||
|
@ -66,16 +66,16 @@ class CitizenManagementTable(val cityScreen: CityScreen) : Table(BaseScreen.skin
|
||||
cell.touchable = Touchable.enabled
|
||||
// Note the binding here only works when visible, so the main one is on CityStatsTable.miniStatsTable
|
||||
// If we bind both, both are executed - so only add the one here that re-applies the current focus
|
||||
val binding = if (city.cityAIFocus == focus) focus.binding else KeyboardBinding.None
|
||||
val binding = if (city.getCityFocus() == focus) focus.binding else KeyboardBinding.None
|
||||
cell.onActivation(binding = binding) {
|
||||
city.cityAIFocus = focus
|
||||
city.setCityFocus(focus)
|
||||
city.reassignPopulation()
|
||||
cityScreen.update()
|
||||
}
|
||||
}
|
||||
cell.background = BaseScreen.skinStrings.getUiBackground(
|
||||
"CityScreen/CitizenManagementTable/FocusCell",
|
||||
tintColor = if (city.cityAIFocus == focus) colorSelected else colorButton
|
||||
tintColor = if (city.getCityFocus() == focus) colorSelected else colorButton
|
||||
)
|
||||
add(cell).growX().pad(3f)
|
||||
if (newRow) // every 2 make new row
|
||||
|
@ -85,7 +85,7 @@ class CityStatsTable(private val cityScreen: CityScreen) : Table() {
|
||||
if (stat == Stat.Faith && !city.civ.gameInfo.isReligionEnabled()) continue
|
||||
val icon = Table()
|
||||
val focus = CityFocus.safeValueOf(stat)
|
||||
val toggledFocus = if (focus == city.cityAIFocus) {
|
||||
val toggledFocus = if (focus == city.getCityFocus()) {
|
||||
icon.add(ImageGetter.getStatIcon(stat.name).surroundWithCircle(27f, false, color = selected))
|
||||
CityFocus.NoFocus
|
||||
} else {
|
||||
@ -94,7 +94,7 @@ class CityStatsTable(private val cityScreen: CityScreen) : Table() {
|
||||
}
|
||||
if (cityScreen.canCityBeChanged()) {
|
||||
icon.onActivation(binding = toggledFocus.binding) {
|
||||
city.cityAIFocus = toggledFocus
|
||||
city.setCityFocus(toggledFocus)
|
||||
city.reassignPopulation()
|
||||
cityScreen.update()
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ class CityPopulationManagerTest {
|
||||
@Test
|
||||
fun `should automatically assign new pop to best job according to city focus`() {
|
||||
// given
|
||||
city.cityAIFocus = CityFocus.GoldFocus
|
||||
city.setCityFocus(CityFocus.GoldFocus)
|
||||
city.workedTiles.clear()
|
||||
city.workedTiles.add(Vector2(-1f, 0f))
|
||||
city.lockedTiles.add(Vector2(-1f, 0f)) // force the first pop to work on a specific tile to avoid being reassigned
|
||||
@ -253,7 +253,7 @@ class CityPopulationManagerTest {
|
||||
@Test
|
||||
fun `should automatically assign new pop to best job with specialists`() {
|
||||
// given
|
||||
city.cityAIFocus = CityFocus.GoldFocus
|
||||
city.setCityFocus(CityFocus.GoldFocus)
|
||||
city.workedTiles.clear()
|
||||
city.workedTiles.add(Vector2(-1f, 0f))
|
||||
city.lockedTiles.add(Vector2(-1f, 0f)) // force the first pop to work on a specific tile to avoid being reassigned
|
||||
|
Loading…
Reference in New Issue
Block a user