From 3515b0f6bd1ab0cf23a81c63dc7ecdd9546c5202 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 10 Aug 2018 11:35:56 +0300 Subject: [PATCH] Added instructions to deal with situations where the game has crashed but we've noticed it --- android/assets/jsons/Tutorials_English.json | 10 ++++++++++ core/src/com/unciv/GameSettings.kt | 1 + .../unciv/logic/automation/UnitAutomation.kt | 3 ++- .../com/unciv/ui/worldscreen/WorldScreen.kt | 18 +++++++++++++++--- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/android/assets/jsons/Tutorials_English.json b/android/assets/jsons/Tutorials_English.json index e325eaad57..99f91692c9 100644 --- a/android/assets/jsons/Tutorials_English.json +++ b/android/assets/jsons/Tutorials_English.json @@ -258,6 +258,16 @@ ] ] + GameCrashed: [ + [ + "Oh no! It looks like something went DISASTROUSLY wrong!", + "This is ABSOLUTELY not supposed to happen!", + "Please send me (yairm210@hotmail.com) an email with the game information", + " (menu -> save game -> copy game info -> paste into email)", + " and I'll try to fix it as fast as I can!" + ] + ] + } diff --git a/core/src/com/unciv/GameSettings.kt b/core/src/com/unciv/GameSettings.kt index 95dbb36bb4..b48d2ff239 100644 --- a/core/src/com/unciv/GameSettings.kt +++ b/core/src/com/unciv/GameSettings.kt @@ -8,6 +8,7 @@ class GameSettings { var language: String = "English" var resolution: String = "1050x700" var tutorialsShown = ArrayList() + var hasCrashedRecently = false fun save(){ GameSaver().setGeneralSettings(this) diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index eed898d6e7..729ab81e02 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -107,11 +107,12 @@ class UnitAutomation{ // The >0.1 (instead of >0) solves a bug where you've moved 2/3 road tiles, // you come to move a third (distance is less that remaining movements), // and then later we round it off to a whole. - // So the poor unit thought it could attack from the tile, but when it comes to do so it has no moveement points! + // So the poor unit thought it could attack from the tile, but when it comes to do so it has no movement points! // Silly floats, basically val tilesToAttackFrom = distanceToTiles.filter { unit.currentMovement - it.value > 0.1 } .map { it.key } .filter { unit.canMoveTo(it) || it==unit.getTile() } + for(reachableTile in tilesToAttackFrom){ // tiles we'll still have energy after we reach there val tilesInAttackRange = if (unit.hasUnique("Indirect fire")) reachableTile.getTilesInDistance(rangeOfAttack) else reachableTile.getViewableTiles(rangeOfAttack) diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 7699294e44..d0db355f9a 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -85,6 +85,13 @@ class WorldScreen : CameraStageBaseScreen() { fun update() { kotlin.concurrent.thread { civInfo.happiness = civInfo.getHappinessForNextTurn().values.sum().toInt() } + if(UnCivGame.Current.settings.hasCrashedRecently){ + displayTutorials("GameCrashed") + UnCivGame.Current.settings.tutorialsShown.remove("GameCrashed") + UnCivGame.Current.settings.hasCrashedRecently=false + UnCivGame.Current.settings.save() + } + if (UnCivGame.Current.settings.tutorialsShown.contains("CityEntered")) { displayTutorials("AfterCityEntered") } @@ -169,8 +176,14 @@ class WorldScreen : CameraStageBaseScreen() { nextTurnButton.setText("Working...".tr()) kotlin.concurrent.thread { - game.gameInfo.nextTurn() - GameSaver().saveGame(game.gameInfo, "Autosave") + try { + game.gameInfo.nextTurn() + GameSaver().saveGame(game.gameInfo, "Autosave") + } + catch (ex:Exception){ + UnCivGame.Current.settings.hasCrashedRecently=true + UnCivGame.Current.settings.save() + } // If we put this BEFORE the save game, then we try to save the game... // but the main thread does other stuff, including showing tutorials which guess what? Changes the game data @@ -202,7 +215,6 @@ class WorldScreen : CameraStageBaseScreen() { // otherwise images will not load properly! update() - displayTutorials("NextTurn") if("BarbarianEncountered" !in UnCivGame.Current.settings.tutorialsShown && civInfo.getViewableTiles().any { it.getUnits().any { unit -> unit.civInfo.isBarbarianCivilization() } })