Resolved #647 - Starting locations should not be on tiny Islands
This commit is contained in:
parent
7ce7c2da93
commit
8bf09420e0
2 changed files with 16 additions and 4 deletions
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.math.Vector2
|
|||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.logic.map.BFS
|
||||
import com.unciv.logic.map.MapType
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
|
@ -75,11 +76,21 @@ class GameStarter{
|
|||
}
|
||||
|
||||
fun getStartingLocations(numberOfPlayers:Int,tileMap: TileMap): Stack<TileInfo> {
|
||||
val landTiles = tileMap.values
|
||||
.filter { it.isLand() && !it.getBaseTerrain().impassable}
|
||||
var landTiles = tileMap.values
|
||||
.filter { it.isLand() && !it.getBaseTerrain().impassable }
|
||||
|
||||
val landTilesInBigEnoughGroup = ArrayList<TileInfo>()
|
||||
while(landTiles.any()){
|
||||
val bfs = BFS(landTiles.random()){it.isLand() && !it.getBaseTerrain().impassable}
|
||||
bfs.stepToEnd()
|
||||
val tilesInGroup = bfs.tilesReached.keys
|
||||
landTiles = landTiles.filter { it !in tilesInGroup }
|
||||
if(tilesInGroup.size > 20) // is this a good number? I dunno, but it's easy enough to change later on
|
||||
landTilesInBigEnoughGroup.addAll(tilesInGroup)
|
||||
}
|
||||
|
||||
for(minimumDistanceBetweenStartingLocations in tileMap.tileMatrix.size/2 downTo 0){
|
||||
val freeTiles = landTiles
|
||||
val freeTiles = landTilesInBigEnoughGroup
|
||||
.filter { vectorIsWithinNTilesOfEdge(it.position,min(3,minimumDistanceBetweenStartingLocations),tileMap)}
|
||||
.toMutableList()
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ package com.unciv.logic.map
|
|||
*/
|
||||
class BFS(val startingPoint: TileInfo, val predicate : (TileInfo) -> Boolean){
|
||||
var tilesToCheck = ArrayList<TileInfo>()
|
||||
val tilesReached = HashMap<TileInfo, TileInfo>() // each tile reached points to its parent tile, where we got to it from
|
||||
/** each tile reached points to its parent tile, where we got to it from */
|
||||
val tilesReached = HashMap<TileInfo, TileInfo>()
|
||||
|
||||
init{
|
||||
tilesToCheck.add(startingPoint)
|
||||
|
|
Loading…
Reference in a new issue