From 0511372fe8d0fcfce0852a153044cae070ed177e Mon Sep 17 00:00:00 2001 From: OptimizedForDensity <105244635+OptimizedForDensity@users.noreply.github.com> Date: Sat, 9 Jul 2022 15:50:53 -0400 Subject: [PATCH] Stop automate production setting from automating other players' production in MP (#7351) * Fix automate production option in multiplayer * More explicit condition --- core/src/com/unciv/logic/GameInfo.kt | 12 +++++++----- .../unciv/logic/automation/ConstructionAutomation.kt | 3 --- core/src/com/unciv/logic/city/CityConstructions.kt | 8 +++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index a3b631cc13..67b4f043fd 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -243,7 +243,7 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion var currentPlayerIndex = civilizations.indexOf(thisPlayer) - fun switchTurn() { + fun endTurn() { thisPlayer.endTurn() currentPlayerIndex = (currentPlayerIndex + 1) % civilizations.size if (currentPlayerIndex == 0) { @@ -252,14 +252,13 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion debug("Starting simulation of turn %s", turns) } thisPlayer = civilizations[currentPlayerIndex] - thisPlayer.startTurn() } //check is important or else switchTurn //would skip a turn if an AI civ calls nextTurn //this happens when resigning a multiplayer game if (thisPlayer.isPlayerCivilization()) { - switchTurn() + endTurn() } while (thisPlayer.playerType == PlayerType.AI @@ -269,6 +268,7 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion // we'll want to skip over their turn || gameParameters.isOnlineMultiplayer && (thisPlayer.isDefeated() || thisPlayer.isSpectator() && thisPlayer.playerId != UncivGame.Current.settings.multiplayer.userId) ) { + thisPlayer.startTurn() if (!thisPlayer.isDefeated() || thisPlayer.isBarbarian()) { NextTurnAutomation.automateCivMoves(thisPlayer) @@ -283,7 +283,7 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion break } } - switchTurn() + endTurn() } if (turns == UncivGame.Current.simulateUntilTurnForDebug) UncivGame.Current.simulateUntilTurnForDebug = 0 @@ -291,6 +291,7 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion currentTurnStartTime = System.currentTimeMillis() currentPlayer = thisPlayer.civName currentPlayerCiv = getCivilization(currentPlayer) + thisPlayer.startTurn() if (currentPlayerCiv.isSpectator()) currentPlayerCiv.popupAlerts.clear() // no popups for spectators if (turns % 10 == 0) //todo measuring actual play time might be nicer @@ -510,8 +511,9 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion /** We remove constructions from the queue that aren't defined in the ruleset. * This can lead to situations where the city is puppeted and had its construction removed, and there's no way to user-set it * So for cities like those, we'll auto-set the construction + * Also set construction for human players who have automate production turned on */ - if (cityInfo.isPuppet && cityInfo.cityConstructions.constructionQueue.isEmpty()) + if (cityInfo.cityConstructions.constructionQueue.isEmpty()) cityInfo.cityConstructions.chooseNextConstruction() // We also remove resources that the city may be demanding but are no longer in the ruleset diff --git a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt index 8fb761bd5a..dd54385558 100644 --- a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt +++ b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt @@ -60,9 +60,6 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ fun chooseNextConstruction() { - if (!UncivGame.Current.settings.autoAssignCityProduction - && civInfo.playerType == PlayerType.Human && !cityInfo.isPuppet) - return if (cityConstructions.getCurrentConstruction() !is PerpetualConstruction) return // don't want to be stuck on these forever addFoodBuildingChoice() diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 808e92d09d..e054850645 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -9,6 +9,7 @@ import com.unciv.logic.civilization.NotificationIcon import com.unciv.logic.civilization.PopupAlert import com.unciv.logic.map.MapUnit import com.unciv.logic.map.TileInfo +import com.unciv.logic.multiplayer.isUsersTurn import com.unciv.models.ruleset.Building import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.unique.LocalUniqueCache @@ -584,7 +585,12 @@ class CityConstructions : IsPartOfGameInfoSerialization { && (getConstruction(currentConstructionFromQueue) !is PerpetualConstruction || currentConstructionIsUserSet)) return } - ConstructionAutomation(this).chooseNextConstruction() + val isCurrentPlayersTurn = cityInfo.civInfo.gameInfo.isUsersTurn() + || !cityInfo.civInfo.gameInfo.gameParameters.isOnlineMultiplayer + if ((UncivGame.Current.settings.autoAssignCityProduction && isCurrentPlayersTurn) // only automate if the active human player has the setting to automate production + || !cityInfo.civInfo.isPlayerCivilization() || cityInfo.isPuppet) { + ConstructionAutomation(this).chooseNextConstruction() + } /** Support for [UniqueType.CreatesOneImprovement] - if an Improvement-creating Building was auto-queued, auto-choose a tile: */ val building = getCurrentConstruction() as? Building ?: return