Resolved #4960 - can now play as 2 separate civs with the same userId

This commit is contained in:
yairm210 2021-08-23 22:26:51 +03:00
parent 23cb4394a7
commit 6db92da52a
2 changed files with 21 additions and 7 deletions

View File

@ -82,7 +82,17 @@ class GameInfo {
fun getPlayerToViewAs(): CivilizationInfo {
if (!gameParameters.isOnlineMultiplayer) return currentPlayerCiv // non-online, play as human player
val userId = UncivGame.Current.settings.userId
if (civilizations.any { it.playerId == userId }) return civilizations.first { it.playerId == userId }
// Iterating on all civs, starting from the the current player, gives us the one that will have the next turn
// This allows multiple civs from the same UserID
if (civilizations.any { it.playerId == userId }) {
var civIndex = civilizations.map { it.civName }.indexOf(currentPlayer)
while (true) {
val civToCheck = civilizations[civIndex % civilizations.size]
if (civToCheck.playerId == userId) return civToCheck
civIndex++
}
}
else return getBarbarianCivilization()// you aren't anyone. How did you even get this game? Can you spectate?
}

View File

@ -332,7 +332,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
val latestGame = OnlineMultiplayer().tryDownloadGame(gameInfo.gameId)
// if we find it still isn't player's turn...nothing changed
if (viewingCiv.civName != latestGame.currentPlayer) {
if (viewingCiv.playerId != latestGame.getCurrentPlayerCivilization().playerId) {
Gdx.app.postRunnable { loadingGamePopup.close() }
shouldUpdate = true
return
@ -574,11 +574,15 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
game.gameInfo = gameInfo
val newWorldScreen = WorldScreen(gameInfo, gameInfo.getPlayerToViewAs())
newWorldScreen.mapHolder.scrollX = mapHolder.scrollX
newWorldScreen.mapHolder.scrollY = mapHolder.scrollY
newWorldScreen.mapHolder.scaleX = mapHolder.scaleX
newWorldScreen.mapHolder.scaleY = mapHolder.scaleY
newWorldScreen.mapHolder.updateVisualScroll()
// This is not the case if you have a multiplayer game where you play as 2 civs
if (newWorldScreen.viewingCiv.civName == viewingCiv.civName) {
newWorldScreen.mapHolder.scrollX = mapHolder.scrollX
newWorldScreen.mapHolder.scrollY = mapHolder.scrollY
newWorldScreen.mapHolder.scaleX = mapHolder.scaleX
newWorldScreen.mapHolder.scaleY = mapHolder.scaleY
newWorldScreen.mapHolder.updateVisualScroll()
}
newWorldScreen.selectedCiv = gameInfo.getCivilization(selectedCiv.civName)
newWorldScreen.fogOfWar = fogOfWar