Add pangaea map type. Add options.
This commit is contained in:
parent
c18b64f10f
commit
5496a5e640
4 changed files with 105 additions and 25 deletions
|
@ -57,7 +57,7 @@
|
|||
{
|
||||
name:"Fish",
|
||||
resourceType:"Bonus",
|
||||
terrainsCanBeFoundOn:["Coast"],
|
||||
terrainsCanBeFoundOn:["Coast", "Lakes"],
|
||||
food:1,
|
||||
improvement:"Fishing Boats",
|
||||
improvementStats:{food:1},
|
||||
|
|
|
@ -10,18 +10,34 @@ import com.unciv.ui.utils.getRandom
|
|||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.pow
|
||||
|
||||
class CelluarAutomataRandomMapGenerator:SeedRandomMapGenerator() {
|
||||
internal val landProb = 0.55f
|
||||
internal val numSmooth = 4
|
||||
enum class MapType {
|
||||
Perlin,
|
||||
Default,
|
||||
Pangaea,
|
||||
}
|
||||
|
||||
class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
|
||||
var landProb = 0.55f
|
||||
var numSmooth = 4
|
||||
var mapType = MapType.Default
|
||||
|
||||
constructor(type: MapType): this() {
|
||||
mapType = type
|
||||
if (mapType < MapType.Default) {
|
||||
mapType = MapType.Default
|
||||
}
|
||||
}
|
||||
|
||||
override fun generateMap(distance: Int): HashMap<String, TileInfo> {
|
||||
val mapVectors = HexMath().getVectorsInDistance(Vector2.Zero, distance)
|
||||
val landscape = HashMap<Vector2, TerrainType>()
|
||||
|
||||
//init
|
||||
for (vector in mapVectors)
|
||||
for (vector in mapVectors) {
|
||||
landscape[vector] = generateInitTerrain(vector, distance)
|
||||
}
|
||||
|
||||
//smooth
|
||||
for (loop in 0..numSmooth) {
|
||||
|
@ -62,13 +78,18 @@ class CelluarAutomataRandomMapGenerator:SeedRandomMapGenerator() {
|
|||
}
|
||||
|
||||
private fun generateInitTerrain(vector: Vector2, distance: Int): TerrainType {
|
||||
var type = TerrainType.Land
|
||||
if (HexMath().getDistance(Vector2.Zero, vector) > 0.9f * distance)
|
||||
type = if (Random().nextDouble() < 0.1) TerrainType.Land else TerrainType.Water
|
||||
else if (HexMath().getDistance(Vector2.Zero, vector) > 0.85f * distance)
|
||||
type = if (Random().nextDouble() < 0.2) TerrainType.Land else TerrainType.Water
|
||||
else
|
||||
type = if (Random().nextDouble() < landProb) TerrainType.Land else TerrainType.Water
|
||||
var type: TerrainType
|
||||
if (mapType == MapType.Pangaea) {
|
||||
val distanceFactor = (HexMath().getDistance(Vector2.Zero, vector) * 1.8 / distance).toFloat()
|
||||
type = if (Random().nextDouble() < landProb.pow(distanceFactor)) TerrainType.Land else TerrainType.Water
|
||||
} else { //default
|
||||
if (HexMath().getDistance(Vector2.Zero, vector) > 0.9f * distance)
|
||||
type = if (Random().nextDouble() < 0.1) TerrainType.Land else TerrainType.Water
|
||||
else if (HexMath().getDistance(Vector2.Zero, vector) > 0.85f * distance)
|
||||
type = if (Random().nextDouble() < 0.2) TerrainType.Land else TerrainType.Water
|
||||
else
|
||||
type = if (Random().nextDouble() < landProb) TerrainType.Land else TerrainType.Water
|
||||
}
|
||||
return type
|
||||
}
|
||||
|
||||
|
@ -81,6 +102,54 @@ class CelluarAutomataRandomMapGenerator:SeedRandomMapGenerator() {
|
|||
tile.baseTerrain = "Ocean"
|
||||
return tile
|
||||
}
|
||||
|
||||
override fun setWaterTiles(map: HashMap<String, TileInfo>) {
|
||||
//define lakes
|
||||
var waterTiles = map.values.filter { it.isWater() }.map { it.position }
|
||||
var tilesInArea = ArrayList<Vector2>()
|
||||
var tilesToCheck = ArrayList<Vector2>()
|
||||
while (waterTiles.isNotEmpty()) {
|
||||
val tile = waterTiles.getRandom()
|
||||
tilesInArea.add(tile)
|
||||
tilesToCheck.add(tile)
|
||||
waterTiles -= tile
|
||||
|
||||
while (tilesToCheck.isNotEmpty()) {
|
||||
val tileChecking = tilesToCheck.getRandom()
|
||||
for (vector in HexMath().getVectorsAtDistance(tileChecking,1).filter { !tilesInArea.contains(it) and waterTiles.contains(it) }) {
|
||||
tilesInArea.add(vector)
|
||||
tilesToCheck.add(vector)
|
||||
waterTiles -= vector
|
||||
}
|
||||
tilesToCheck.remove(tileChecking)
|
||||
}
|
||||
|
||||
if (tilesInArea.size <= 10) {
|
||||
for (vector in tilesInArea) {
|
||||
map[vector.toString()]!!.baseTerrain = "Lakes"
|
||||
}
|
||||
}
|
||||
tilesInArea.clear()
|
||||
}
|
||||
|
||||
//Coasts
|
||||
for (tile in map.values.filter { it.baseTerrain == "Ocean" }) {
|
||||
if (HexMath().getVectorsInDistance(tile.position,2).any { hasLandTile(map,it) }) {
|
||||
tile.baseTerrain = "Coast"
|
||||
tile.setTransients()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun randomizeTile(tileInfo: TileInfo, map: HashMap<String, TileInfo>){
|
||||
if(tileInfo.getBaseTerrain().type==TerrainType.Land && Math.random()<0.05f){
|
||||
tileInfo.baseTerrain = "Mountain"
|
||||
tileInfo.setTransients()
|
||||
}
|
||||
addRandomTerrainFeature(tileInfo)
|
||||
addRandomResourceToTile(tileInfo)
|
||||
maybeAddAncientRuins(tileInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -349,11 +418,11 @@ open class RandomMapGenerator {
|
|||
}
|
||||
|
||||
|
||||
private fun hasLandTile(map: HashMap<String, TileInfo>, vector: Vector2): Boolean {
|
||||
fun hasLandTile(map: HashMap<String, TileInfo>, vector: Vector2): Boolean {
|
||||
return map.containsKey(vector.toString()) && map[vector.toString()]!!.getBaseTerrain().type == TerrainType.Land
|
||||
}
|
||||
|
||||
fun setWaterTiles(map: HashMap<String, TileInfo>) {
|
||||
open fun setWaterTiles(map: HashMap<String, TileInfo>) {
|
||||
for (tile in map.values.filter { it.baseTerrain == "Ocean" }) {
|
||||
if (HexMath().getVectorsInDistance(tile.position,2).any { hasLandTile(map,it) }) {
|
||||
tile.baseTerrain = "Coast"
|
||||
|
@ -362,7 +431,7 @@ open class RandomMapGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
fun randomizeTile(tileInfo: TileInfo, map: HashMap<String, TileInfo>){
|
||||
open fun randomizeTile(tileInfo: TileInfo, map: HashMap<String, TileInfo>){
|
||||
if(tileInfo.getBaseTerrain().type==TerrainType.Land && Math.random()<0.05f){
|
||||
tileInfo.baseTerrain = "Mountain"
|
||||
tileInfo.setTransients()
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.unciv.logic.map
|
|||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.HexMath
|
||||
import com.unciv.logic.map.MapType
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.NewGameScreen
|
||||
|
@ -31,13 +32,13 @@ class TileMap {
|
|||
get() = tileList
|
||||
|
||||
|
||||
constructor(distance: Int, mapType: NewGameScreen.NewGameParameters.MapType) {
|
||||
constructor(distance: Int, mapType: MapType) {
|
||||
val map:HashMap<String,TileInfo>
|
||||
|
||||
if(mapType==NewGameScreen.NewGameParameters.MapType.WithWater)
|
||||
map = CelluarAutomataRandomMapGenerator().generateMap(distance)
|
||||
|
||||
else map = SeedRandomMapGenerator().generateMap(distance,0f)
|
||||
if(mapType==MapType.Perlin)
|
||||
map = PerlinNoiseRandomMapGenerator().generateMap(distance)
|
||||
else
|
||||
map = CelluarAutomataRandomMapGenerator(mapType).generateMap(distance)
|
||||
|
||||
tileList.addAll(map.values)
|
||||
// tileList.addAll(AlexanderRandomMapGenerator().generateMap(distance,0.8f).values)
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
|||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.GameStarter
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.map.MapType
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.Nation
|
||||
import com.unciv.models.gamebasics.Translations
|
||||
|
@ -20,15 +21,11 @@ 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.WithWater
|
||||
var mapType=MapType.Perlin
|
||||
}
|
||||
|
||||
val newGameParameters=NewGameParameters()
|
||||
|
@ -123,6 +120,19 @@ class NewGameScreen: PickerScreen(){
|
|||
val newGameOptionsTable = Table()
|
||||
newGameOptionsTable.skin = skin
|
||||
|
||||
newGameOptionsTable.add("{Map type}:".tr())
|
||||
val mapTypes = LinkedHashMap<String, MapType>()
|
||||
for (type in MapType.values()) {
|
||||
mapTypes[type.toString()] = type
|
||||
}
|
||||
val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, "Perlin", skin)
|
||||
mapTypeSelectBox.addListener(object : ChangeListener() {
|
||||
override fun changed(event: ChangeEvent?, actor: Actor?) {
|
||||
newGameParameters.mapType = mapTypes[mapTypeSelectBox.selected.value]!!
|
||||
}
|
||||
})
|
||||
newGameOptionsTable.add(mapTypeSelectBox).pad(10f).row()
|
||||
|
||||
newGameOptionsTable.add("{World size}:".tr())
|
||||
val worldSizeToRadius = LinkedHashMap<String, Int>()
|
||||
worldSizeToRadius["Tiny"] = 10
|
||||
|
|
Loading…
Reference in a new issue