From 9496c4523edad3b7fdaab97adc25193a1006ee4a Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 1 Jun 2020 01:31:38 +0300 Subject: [PATCH] Fixed crashing bug where map generation would try to have rivers going off-map --- .../logic/map/mapgenerator/RiverGenerator.kt | 3 +-- .../unciv/ui/newgamescreen/NewGameScreen.kt | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/src/com/unciv/logic/map/mapgenerator/RiverGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/RiverGenerator.kt index 9f65f66d3e..97b2d17a81 100644 --- a/core/src/com/unciv/logic/map/mapgenerator/RiverGenerator.kt +++ b/core/src/com/unciv/logic/map/mapgenerator/RiverGenerator.kt @@ -52,13 +52,12 @@ class RiverGenerator(val randomness: MapGenerationRandomness){ while(getAdjacentTiles(riverCoordinate,map).none { it.isWater }){ val possibleCoordinates = riverCoordinate.getAdjacentPositions() + .filter { map.contains(it.position) } if(possibleCoordinates.none()) return // end of the line val newCoordinate = possibleCoordinates -// .sortedBy { numberOfConnectedRivers(it,map) } .groupBy { getAdjacentTiles(it,map).map { it.aerialDistanceTo(endPosition) }.min()!! } .minBy { it.key }!! .component2().random(randomness.RNG) -// .minBy { getAdjacentTiles(it,map).map { it.aerialDistanceTo(endPosition) }.min()!! }!! // set new rivers in place val riverCoordinateTile = map[riverCoordinate.position] diff --git a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt index d74a486622..5997c96f76 100644 --- a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt +++ b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt @@ -110,14 +110,16 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe } } } catch (exception: Exception) { - val cantMakeThatMapPopup = Popup(this) - cantMakeThatMapPopup.addGoodSizedLabel("It looks like we can't make a map with the parameters you requested!".tr()).row() - cantMakeThatMapPopup.addGoodSizedLabel("Maybe you put too many players into too small a map?".tr()).row() - cantMakeThatMapPopup.addCloseButton() - cantMakeThatMapPopup.open() - Gdx.input.inputProcessor = stage - rightSideButton.enable() - rightSideButton.setText("Start game!".tr()) + Gdx.app.postRunnable { + val cantMakeThatMapPopup = Popup(this) + cantMakeThatMapPopup.addGoodSizedLabel("It looks like we can't make a map with the parameters you requested!".tr()).row() + cantMakeThatMapPopup.addGoodSizedLabel("Maybe you put too many players into too small a map?".tr()).row() + cantMakeThatMapPopup.addCloseButton() + cantMakeThatMapPopup.open() + Gdx.input.inputProcessor = stage + rightSideButton.enable() + rightSideButton.setText("Start game!".tr()) + } } Gdx.graphics.requestRendering() }