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 }){
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]

View File

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