Fixed crashing bug where map generation would try to have rivers going off-map

This commit is contained in:
Yair Morgenstern 2020-06-01 01:31:38 +03:00
parent 22fd10498e
commit 9496c4523e
2 changed files with 11 additions and 10 deletions

View File

@ -52,13 +52,12 @@ class RiverGenerator(val randomness: MapGenerationRandomness){
while(getAdjacentTiles(riverCoordinate,map).none { it.isWater }){ while(getAdjacentTiles(riverCoordinate,map).none { it.isWater }){
val possibleCoordinates = riverCoordinate.getAdjacentPositions() val possibleCoordinates = riverCoordinate.getAdjacentPositions()
.filter { map.contains(it.position) }
if(possibleCoordinates.none()) return // end of the line if(possibleCoordinates.none()) return // end of the line
val newCoordinate = possibleCoordinates val newCoordinate = possibleCoordinates
// .sortedBy { numberOfConnectedRivers(it,map) }
.groupBy { getAdjacentTiles(it,map).map { it.aerialDistanceTo(endPosition) }.min()!! } .groupBy { getAdjacentTiles(it,map).map { it.aerialDistanceTo(endPosition) }.min()!! }
.minBy { it.key }!! .minBy { it.key }!!
.component2().random(randomness.RNG) .component2().random(randomness.RNG)
// .minBy { getAdjacentTiles(it,map).map { it.aerialDistanceTo(endPosition) }.min()!! }!!
// set new rivers in place // set new rivers in place
val riverCoordinateTile = map[riverCoordinate.position] val riverCoordinateTile = map[riverCoordinate.position]

View File

@ -110,14 +110,16 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
} }
} }
} catch (exception: Exception) { } catch (exception: Exception) {
val cantMakeThatMapPopup = Popup(this) Gdx.app.postRunnable {
cantMakeThatMapPopup.addGoodSizedLabel("It looks like we can't make a map with the parameters you requested!".tr()).row() val cantMakeThatMapPopup = Popup(this)
cantMakeThatMapPopup.addGoodSizedLabel("Maybe you put too many players into too small a map?".tr()).row() cantMakeThatMapPopup.addGoodSizedLabel("It looks like we can't make a map with the parameters you requested!".tr()).row()
cantMakeThatMapPopup.addCloseButton() cantMakeThatMapPopup.addGoodSizedLabel("Maybe you put too many players into too small a map?".tr()).row()
cantMakeThatMapPopup.open() cantMakeThatMapPopup.addCloseButton()
Gdx.input.inputProcessor = stage cantMakeThatMapPopup.open()
rightSideButton.enable() Gdx.input.inputProcessor = stage
rightSideButton.setText("Start game!".tr()) rightSideButton.enable()
rightSideButton.setText("Start game!".tr())
}
} }
Gdx.graphics.requestRendering() Gdx.graphics.requestRendering()
} }