Stop automate production setting from automating other players' production in MP (#7351)

* Fix automate production option in multiplayer

* More explicit condition
This commit is contained in:
OptimizedForDensity 2022-07-09 15:50:53 -04:00 committed by GitHub
parent aab49e7295
commit 0511372fe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 9 deletions

View File

@ -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

View File

@ -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()

View File

@ -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