mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-23 22:30:18 +07:00
Added option to choose map generation type
This commit is contained in:
@ -13,7 +13,7 @@ class GameStarter(){
|
|||||||
fun startNewGame(newGameParameters: NewGameScreen.NewGameParameters): GameInfo {
|
fun startNewGame(newGameParameters: NewGameScreen.NewGameParameters): GameInfo {
|
||||||
val gameInfo = 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
|
gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class UnCivGame : Game() {
|
|||||||
* This exists so that when debugging we can see the entire map.
|
* This exists so that when debugging we can see the entire map.
|
||||||
* Remember to turn this to false before commit and upload!
|
* Remember to turn this to false before commit and upload!
|
||||||
*/
|
*/
|
||||||
val viewEntireMapForDebug = true
|
val viewEntireMapForDebug = false
|
||||||
|
|
||||||
lateinit var worldScreen: WorldScreen
|
lateinit var worldScreen: WorldScreen
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import com.unciv.logic.GameInfo
|
|||||||
import com.unciv.logic.HexMath
|
import com.unciv.logic.HexMath
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
|
import com.unciv.ui.NewGameScreen
|
||||||
|
|
||||||
class TileMap {
|
class TileMap {
|
||||||
|
|
||||||
@ -30,12 +31,21 @@ class TileMap {
|
|||||||
get() = tileList
|
get() = tileList
|
||||||
|
|
||||||
|
|
||||||
constructor(distance: Int) {
|
constructor(distance: Int, mapType: NewGameScreen.NewGameParameters.MapType) {
|
||||||
// tileList.addAll(AlexanderRandomMapGenerator().generateMap(distance,0.75f).values)
|
val map:HashMap<String,TileInfo>
|
||||||
tileList.addAll(PerlinNoiseRandomMapGenerator().generateMap(distance).values)
|
|
||||||
|
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()
|
setTransients()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
operator fun contains(vector: Vector2): Boolean {
|
operator fun contains(vector: Vector2): Boolean {
|
||||||
val arrayXIndex = vector.x.toInt()-leftX
|
val arrayXIndex = vector.x.toInt()-leftX
|
||||||
if(arrayXIndex<0 || arrayXIndex>=tileMatrix.size) return false
|
if(arrayXIndex<0 || arrayXIndex>=tileMatrix.size) return false
|
||||||
|
@ -18,10 +18,15 @@ import kotlin.concurrent.thread
|
|||||||
class NewGameScreen: PickerScreen(){
|
class NewGameScreen: PickerScreen(){
|
||||||
|
|
||||||
class NewGameParameters{
|
class NewGameParameters{
|
||||||
|
enum class MapType{
|
||||||
|
LandOnly,
|
||||||
|
WithWater
|
||||||
|
}
|
||||||
var difficulty="Prince"
|
var difficulty="Prince"
|
||||||
var nation="Babylon"
|
var nation="Babylon"
|
||||||
var mapRadius=20
|
var mapRadius=20
|
||||||
var numberOfEnemies=3
|
var numberOfEnemies=3
|
||||||
|
var mapType=MapType.LandOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
val newGameParameters=NewGameParameters()
|
val newGameParameters=NewGameParameters()
|
||||||
@ -102,10 +107,10 @@ class NewGameScreen: PickerScreen(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getOptionsTable(): Table {
|
private fun getOptionsTable(): Table {
|
||||||
val table = Table()
|
val newGameOptionsTable = Table()
|
||||||
table.skin = skin
|
newGameOptionsTable.skin = skin
|
||||||
|
|
||||||
table.add("{World size}:".tr())
|
newGameOptionsTable.add("{World size}:".tr())
|
||||||
val worldSizeToRadius = LinkedHashMap<String, Int>()
|
val worldSizeToRadius = LinkedHashMap<String, Int>()
|
||||||
worldSizeToRadius["Small"] = 10
|
worldSizeToRadius["Small"] = 10
|
||||||
worldSizeToRadius["Medium"] = 20
|
worldSizeToRadius["Medium"] = 20
|
||||||
@ -117,10 +122,10 @@ class NewGameScreen: PickerScreen(){
|
|||||||
newGameParameters.mapRadius = worldSizeToRadius[worldSizeSelectBox.selected.value]!!
|
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<Int>(skin)
|
val enemiesSelectBox = SelectBox<Int>(skin)
|
||||||
val enemiesArray = Array<Int>()
|
val enemiesArray = Array<Int>()
|
||||||
(1..5).forEach { enemiesArray.add(it) }
|
(1..5).forEach { enemiesArray.add(it) }
|
||||||
@ -132,14 +137,21 @@ class NewGameScreen: PickerScreen(){
|
|||||||
newGameParameters.numberOfEnemies = enemiesSelectBox.selected
|
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)
|
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.enable()
|
||||||
rightSideButton.setText("Start game!".tr())
|
rightSideButton.setText("Start game!".tr())
|
||||||
rightSideButton.onClick {
|
rightSideButton.onClick {
|
||||||
@ -152,8 +164,9 @@ class NewGameScreen: PickerScreen(){
|
|||||||
newGame = GameStarter().startNewGame(newGameParameters)
|
newGame = GameStarter().startNewGame(newGameParameters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
table.pack()
|
|
||||||
return table
|
newGameOptionsTable.pack()
|
||||||
|
return newGameOptionsTable
|
||||||
}
|
}
|
||||||
|
|
||||||
var newGame:GameInfo?=null
|
var newGame:GameInfo?=null
|
||||||
|
Reference in New Issue
Block a user