From 9ad027b848d82d1088e79823a17de7b32f29b8e9 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 12 Oct 2018 14:19:05 +0300 Subject: [PATCH] Added option to choose map generation type --- core/src/com/unciv/GameStarter.kt | 2 +- core/src/com/unciv/UnCivGame.kt | 2 +- core/src/com/unciv/logic/map/TileMap.kt | 16 +++++++++--- core/src/com/unciv/ui/NewGameScreen.kt | 33 +++++++++++++++++-------- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/core/src/com/unciv/GameStarter.kt b/core/src/com/unciv/GameStarter.kt index 355f4b0c10..b59a7bd3ef 100644 --- a/core/src/com/unciv/GameStarter.kt +++ b/core/src/com/unciv/GameStarter.kt @@ -13,7 +13,7 @@ class GameStarter(){ fun startNewGame(newGameParameters: NewGameScreen.NewGameParameters): GameInfo { val gameInfo = GameInfo() - gameInfo.tileMap = TileMap(newGameParameters.mapRadius) + gameInfo.tileMap = TileMap(newGameParameters.mapRadius, newGameParameters.mapType) gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map diff --git a/core/src/com/unciv/UnCivGame.kt b/core/src/com/unciv/UnCivGame.kt index a5774c93ec..b79f61ad9e 100644 --- a/core/src/com/unciv/UnCivGame.kt +++ b/core/src/com/unciv/UnCivGame.kt @@ -17,7 +17,7 @@ class UnCivGame : Game() { * This exists so that when debugging we can see the entire map. * Remember to turn this to false before commit and upload! */ - val viewEntireMapForDebug = true + val viewEntireMapForDebug = false lateinit var worldScreen: WorldScreen diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 91028e6879..29dd07cc8c 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -5,6 +5,7 @@ import com.unciv.logic.GameInfo import com.unciv.logic.HexMath import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.gamebasics.GameBasics +import com.unciv.ui.NewGameScreen class TileMap { @@ -30,12 +31,21 @@ class TileMap { get() = tileList - constructor(distance: Int) { -// tileList.addAll(AlexanderRandomMapGenerator().generateMap(distance,0.75f).values) - tileList.addAll(PerlinNoiseRandomMapGenerator().generateMap(distance).values) + constructor(distance: Int, mapType: NewGameScreen.NewGameParameters.MapType) { + val map:HashMap + + if(mapType==NewGameScreen.NewGameParameters.MapType.WithWater) + map = PerlinNoiseRandomMapGenerator().generateMap(distance) + + else map = SeedRandomMapGenerator().generateMap(distance,0f) + + tileList.addAll(map.values) +// tileList.addAll(AlexanderRandomMapGenerator().generateMap(distance,0.8f).values) + setTransients() } + operator fun contains(vector: Vector2): Boolean { val arrayXIndex = vector.x.toInt()-leftX if(arrayXIndex<0 || arrayXIndex>=tileMatrix.size) return false diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index 807d97dad6..22e3433157 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -18,10 +18,15 @@ import kotlin.concurrent.thread class NewGameScreen: PickerScreen(){ class NewGameParameters{ + enum class MapType{ + LandOnly, + WithWater + } var difficulty="Prince" var nation="Babylon" var mapRadius=20 var numberOfEnemies=3 + var mapType=MapType.LandOnly } val newGameParameters=NewGameParameters() @@ -102,10 +107,10 @@ class NewGameScreen: PickerScreen(){ } private fun getOptionsTable(): Table { - val table = Table() - table.skin = skin + val newGameOptionsTable = Table() + newGameOptionsTable.skin = skin - table.add("{World size}:".tr()) + newGameOptionsTable.add("{World size}:".tr()) val worldSizeToRadius = LinkedHashMap() worldSizeToRadius["Small"] = 10 worldSizeToRadius["Medium"] = 20 @@ -117,10 +122,10 @@ class NewGameScreen: PickerScreen(){ newGameParameters.mapRadius = worldSizeToRadius[worldSizeSelectBox.selected.value]!! } }) - table.add(worldSizeSelectBox).pad(10f).row() + newGameOptionsTable.add(worldSizeSelectBox).pad(10f).row() - table.add("{Number of enemies}:".tr()) + newGameOptionsTable.add("{Number of enemies}:".tr()) val enemiesSelectBox = SelectBox(skin) val enemiesArray = Array() (1..5).forEach { enemiesArray.add(it) } @@ -132,14 +137,21 @@ class NewGameScreen: PickerScreen(){ newGameParameters.numberOfEnemies = enemiesSelectBox.selected } }) - table.add(enemiesSelectBox).pad(10f).row() + newGameOptionsTable.add(enemiesSelectBox).pad(10f).row() - table.add("{Difficulty}:".tr()) + newGameOptionsTable.add("{Difficulty}:".tr()) val difficultySelectBox = TranslatedSelectBox(GameBasics.Difficulties.keys, newGameParameters.difficulty, skin) - table.add(difficultySelectBox).pad(10f).row() + newGameOptionsTable.add(difficultySelectBox).pad(10f).row() + val checkBox = CheckBox("Add water tiles \n(EXPERIMENTAL/WIP)",skin) + checkBox.onClick { + if(checkBox.isChecked) newGameParameters.mapType = NewGameParameters.MapType.WithWater + else newGameParameters.mapType = NewGameParameters.MapType.LandOnly + } + newGameOptionsTable.add(checkBox).row() + rightSideButton.enable() rightSideButton.setText("Start game!".tr()) rightSideButton.onClick { @@ -152,8 +164,9 @@ class NewGameScreen: PickerScreen(){ newGame = GameStarter().startNewGame(newGameParameters) } } - table.pack() - return table + + newGameOptionsTable.pack() + return newGameOptionsTable } var newGame:GameInfo?=null