Replaced the List with MutableList to avoid creating new ones on adding/removing values (#2746)

This commit is contained in:
lyrjie 2020-06-20 23:10:02 +03:00 committed by GitHub
parent 835c0832e2
commit e18bfa0053
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -59,7 +59,7 @@ class MapGenerator(val ruleset: Ruleset) {
private fun spawnLakesAndCoasts(map: TileMap) {
//define lakes
var waterTiles = map.values.filter { it.isWater }
val waterTiles = map.values.filter { it.isWater }.toMutableList()
val tilesInArea = ArrayList<TileInfo>()
val tilesToCheck = ArrayList<TileInfo>()

View file

@ -10,11 +10,11 @@ class RiverGenerator(val randomness: MapGenerationRandomness){
val numberOfRivers = map.values.count { it.isLand } / 100
var optionalTiles = map.values
.filter { it.baseTerrain== Constants.mountain && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 }
.filter { it.baseTerrain== Constants.mountain && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 }.toMutableList()
if(optionalTiles.size < numberOfRivers)
optionalTiles += map.values.filter { it.baseTerrain== Constants.hill && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 }
optionalTiles.addAll(map.values.filter { it.baseTerrain== Constants.hill && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 })
if(optionalTiles.size < numberOfRivers)
optionalTiles = map.values.filter { it.isLand && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 }
optionalTiles = map.values.filter { it.isLand && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 }.toMutableList()
val riverStarts = randomness.chooseSpreadOutLocations(numberOfRivers, optionalTiles, 10)