mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 13:49:54 +07:00
Code cleanup
This commit is contained in:
@ -16,7 +16,7 @@ import kotlin.random.Random
|
||||
|
||||
|
||||
class MapGenerator(val ruleset: Ruleset) {
|
||||
var randomness = MapGenerationRandomness()
|
||||
private var randomness = MapGenerationRandomness()
|
||||
|
||||
fun generateMap(mapParameters: MapParameters, seed: Long = System.currentTimeMillis()): TileMap {
|
||||
val mapRadius = mapParameters.size.radius
|
||||
@ -185,9 +185,11 @@ class MapGenerator(val ruleset: Ruleset) {
|
||||
var elevation = randomness.getPerlinNoise(tile, elevationSeed, scale = 2.0)
|
||||
elevation = abs(elevation).pow(1.0 - tileMap.mapParameters.elevationExponent.toDouble()) * elevation.sign
|
||||
|
||||
if (elevation <= 0.5) tile.baseTerrain = Constants.plains
|
||||
else if (elevation <= 0.7) tile.baseTerrain = Constants.hill
|
||||
else if (elevation <= 1.0) tile.baseTerrain = Constants.mountain
|
||||
when {
|
||||
elevation <= 0.5 -> tile.baseTerrain = Constants.plains
|
||||
elevation <= 0.7 -> tile.baseTerrain = Constants.hill
|
||||
elevation <= 1.0 -> tile.baseTerrain = Constants.mountain
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,6 +348,7 @@ class RiverCoordinate(val position: Vector2, val bottomRightOrLeft: BottomRightO
|
||||
enum class BottomRightOrLeft {
|
||||
/** 7 O'Clock of the tile */
|
||||
BottomLeft,
|
||||
|
||||
/** 5 O'Clock of the tile */
|
||||
BottomRight
|
||||
}
|
||||
@ -366,4 +369,3 @@ class RiverCoordinate(val position: Vector2, val bottomRightOrLeft: BottomRightO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
private fun createPerlin(tileMap: TileMap) {
|
||||
val elevationSeed = randomness.RNG.nextInt().toDouble()
|
||||
for (tile in tileMap.values) {
|
||||
var elevation = randomness.getPerlinNoise(tile, elevationSeed)
|
||||
val elevation = randomness.getPerlinNoise(tile, elevationSeed)
|
||||
spawnLandOrWater(tile, elevation, tileMap.mapParameters.waterThreshold.toDouble())
|
||||
}
|
||||
}
|
||||
@ -58,7 +58,7 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
private fun createArchipelago(tileMap: TileMap) {
|
||||
val elevationSeed = randomness.RNG.nextInt().toDouble()
|
||||
for (tile in tileMap.values) {
|
||||
var elevation = getRidgedPerlinNoise(tile, elevationSeed)
|
||||
val elevation = getRidgedPerlinNoise(tile, elevationSeed)
|
||||
spawnLandOrWater(tile, elevation, 0.25 + tileMap.mapParameters.waterThreshold.toDouble())
|
||||
}
|
||||
}
|
||||
@ -120,8 +120,6 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
|
||||
// region Cellular automata
|
||||
private fun generateLandCellularAutomata(tileMap: TileMap) {
|
||||
val mapRadius = tileMap.mapParameters.size.radius
|
||||
val mapType = tileMap.mapParameters.type
|
||||
val numSmooth = 4
|
||||
|
||||
//init
|
||||
|
@ -78,7 +78,8 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnBarringerCrater(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.barringerCrater]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.grassland }
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 2
|
||||
@ -94,7 +95,8 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnMountFuji(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.mountFuji]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.tundra }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.desert }
|
||||
@ -112,7 +114,8 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnGrandMesa(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.grandMesa]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.count { neighbor -> neighbor.isHill() } >= 2
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.grassland }
|
||||
@ -128,7 +131,8 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnGreatBarrierReef(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.greatBarrierReef]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& abs(it.latitude) > tileMap.maxLatitude * 0.1
|
||||
&& abs(it.latitude) < tileMap.maxLatitude * 0.7
|
||||
@ -136,15 +140,18 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
&& it.neighbors.any { neighbor ->
|
||||
neighbor.resource == null && neighbor.improvement == null
|
||||
&& wonder.occursOn.contains(neighbor.getLastTerrain().name)
|
||||
&& neighbor.neighbors.all{ it.isWater } }
|
||||
&& neighbor.neighbors.all { it.isWater }
|
||||
}
|
||||
}
|
||||
|
||||
val location = trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
if (location != null) {
|
||||
val location2 = location.neighbors
|
||||
.filter { it.resource == null && it.improvement == null
|
||||
.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.all{ it.isWater } }
|
||||
&& it.neighbors.all { it.isWater }
|
||||
}
|
||||
.toList().random()
|
||||
|
||||
location2.naturalWonder = wonder.name
|
||||
@ -159,7 +166,8 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnKrakatoa(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.krakatoa]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getBaseTerrain().name == Constants.coast }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getLastTerrain().name == Constants.ice }
|
||||
@ -185,7 +193,8 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnRockOfGibraltar(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.rockOfGibraltar]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getBaseTerrain().name == Constants.coast }
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } == 1
|
||||
@ -220,10 +229,12 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnOldFaithful(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.oldFaithful]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 4
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain ||
|
||||
&& it.neighbors.count { neighbor ->
|
||||
neighbor.getBaseTerrain().name == Constants.mountain ||
|
||||
neighbor.isHill()
|
||||
} >= 3
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.desert } <= 3
|
||||
@ -238,7 +249,8 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnCerroDePotosi(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.cerroDePotosi]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.isHill() }
|
||||
}
|
||||
@ -251,7 +263,8 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnElDorado(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.elDorado]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getLastTerrain().name == Constants.jungle }
|
||||
}
|
||||
@ -264,8 +277,10 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnFountainOfYouth(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.fountainOfYouth]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name) }
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
}
|
||||
|
@ -119,19 +119,20 @@ class BaseUnit : INamed, IConstruction {
|
||||
|| rejectionReason.startsWith("Consumes")
|
||||
}
|
||||
|
||||
fun getRejectionReason(construction: CityConstructions): String {
|
||||
if (unitType.isWaterUnit() && !construction.cityInfo.getCenterTile().isCoastalTile())
|
||||
fun getRejectionReason(cityConstructions: CityConstructions): String {
|
||||
if (unitType.isWaterUnit() && !cityConstructions.cityInfo.getCenterTile().isCoastalTile())
|
||||
return "Can only build water units in coastal cities"
|
||||
val civInfo = cityConstructions.cityInfo.civInfo
|
||||
for (unique in uniqueObjects.filter { it.placeholderText == "Not displayed as an available construction without []" }) {
|
||||
val filter = unique.params[0]
|
||||
if (filter in construction.cityInfo.civInfo.gameInfo.ruleSet.tileResources && !construction.cityInfo.civInfo.hasResource(filter)
|
||||
|| filter in construction.cityInfo.civInfo.gameInfo.ruleSet.buildings && !construction.containsBuildingOrEquivalent(filter))
|
||||
if (filter in civInfo.gameInfo.ruleSet.tileResources && !civInfo.hasResource(filter)
|
||||
|| filter in civInfo.gameInfo.ruleSet.buildings && !cityConstructions.containsBuildingOrEquivalent(filter))
|
||||
return "Should not be displayed"
|
||||
}
|
||||
val civRejectionReason = getRejectionReason(construction.cityInfo.civInfo)
|
||||
val civRejectionReason = getRejectionReason(civInfo)
|
||||
if (civRejectionReason != "") return civRejectionReason
|
||||
for (unique in uniqueObjects.filter { it.placeholderText == "Requires at least [] population" })
|
||||
if (unique.params[0].toInt() > construction.cityInfo.population.population)
|
||||
if (unique.params[0].toInt() > cityConstructions.cityInfo.population.population)
|
||||
return unique.text
|
||||
return ""
|
||||
}
|
||||
|
@ -1,21 +1,15 @@
|
||||
package com.unciv.ui.mapeditor
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.logic.MapSaver
|
||||
import com.unciv.logic.map.ScenarioMap
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.RulesetCache
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.newgamescreen.GameSetupInfo
|
||||
import com.unciv.ui.utils.*
|
||||
|
||||
@ -34,25 +28,6 @@ class MapEditorScreen(): CameraStageBaseScreen() {
|
||||
private val showHideEditorOptionsButton = ">".toTextButton()
|
||||
|
||||
|
||||
constructor(mapNameToLoad: String?) : this() {
|
||||
var mapToLoad = mapNameToLoad
|
||||
if (mapToLoad == null) {
|
||||
val existingSaves = MapSaver.getMaps()
|
||||
if (existingSaves.isNotEmpty())
|
||||
mapToLoad = existingSaves.first().name()
|
||||
}
|
||||
|
||||
if (mapToLoad != null) {
|
||||
mapName = mapToLoad
|
||||
scenarioName = mapToLoad
|
||||
tileMap = MapSaver.loadMap(mapName)
|
||||
}
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
constructor(mapFile:FileHandle):this()
|
||||
|
||||
constructor(map: TileMap) : this() {
|
||||
tileMap = map
|
||||
initialize()
|
||||
@ -178,24 +153,7 @@ class MapEditorScreen(): CameraStageBaseScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
fun hasScenario(): Boolean {
|
||||
return this.scenarioMap != null
|
||||
}
|
||||
}
|
||||
|
||||
class TranslatedSelectBox(values : Collection<String>, default:String, skin: Skin) : SelectBox<TranslatedSelectBox.TranslatedString>(skin) {
|
||||
class TranslatedString(val value: String) {
|
||||
val translation = value.tr()
|
||||
override fun toString() = translation
|
||||
}
|
||||
|
||||
init {
|
||||
val array = Array<TranslatedString>()
|
||||
values.forEach { array.add(TranslatedString(it)) }
|
||||
items = array
|
||||
val defaultItem = array.firstOrNull { it.value == default }
|
||||
selected = if (defaultItem != null) defaultItem else array.first()
|
||||
}
|
||||
fun hasScenario() = this.scenarioMap != null
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user