mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-21 21:30:20 +07:00
Solve CS placement clustering (#7783)
This commit is contained in:
@ -987,7 +987,7 @@ class MapRegions (val ruleset: Ruleset){
|
|||||||
if (!canPlaceMinorCiv(tile)) continue
|
if (!canPlaceMinorCiv(tile)) continue
|
||||||
val continent = tile.getContinent()
|
val continent = tile.getContinent()
|
||||||
if (continent in uninhabitedContinents) {
|
if (continent in uninhabitedContinents) {
|
||||||
if(tile.isCoastalTile())
|
if (tile.isCoastalTile())
|
||||||
uninhabitedCoastal.add(tile)
|
uninhabitedCoastal.add(tile)
|
||||||
else
|
else
|
||||||
uninhabitedHinterland.add(tile)
|
uninhabitedHinterland.add(tile)
|
||||||
@ -1031,17 +1031,17 @@ class MapRegions (val ruleset: Ruleset){
|
|||||||
it.assignedMinorCivs.add(civToAssign)
|
it.assignedMinorCivs.add(civToAssign)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// STILL unassigned civs??
|
// STILL unassigned civs??
|
||||||
if (unassignedCivs.isNotEmpty()) {
|
if (unassignedCivs.isNotEmpty()) {
|
||||||
// At this point there is at least for sure less remaining city states than regions
|
// At this point there is at least for sure less remaining city states than regions
|
||||||
// Sort regions by fertility and put extra city states in the worst ones.
|
// Sort regions by fertility and put extra city states in the worst ones.
|
||||||
val worstRegions = regions.sortedBy { it.totalFertility }.take(unassignedCivs.size)
|
val worstRegions = regions.sortedBy { it.totalFertility }.take(unassignedCivs.size)
|
||||||
worstRegions.forEach {
|
worstRegions.forEach {
|
||||||
val civToAssign = unassignedCivs.first()
|
val civToAssign = unassignedCivs.first()
|
||||||
unassignedCivs.remove(civToAssign)
|
unassignedCivs.remove(civToAssign)
|
||||||
it.assignedMinorCivs.add(civToAssign)
|
it.assignedMinorCivs.add(civToAssign)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1053,86 +1053,10 @@ class MapRegions (val ruleset: Ruleset){
|
|||||||
for (unplacedCiv in civAssignedToUninhabited) {
|
for (unplacedCiv in civAssignedToUninhabited) {
|
||||||
regions.random().assignedMinorCivs.add(unplacedCiv)
|
regions.random().assignedMinorCivs.add(unplacedCiv)
|
||||||
}
|
}
|
||||||
// Fallback lists for minor civs that can't be placed with any other method
|
|
||||||
val fallbackTiles = ArrayList<TileInfo>()
|
|
||||||
val fallbackMinors = ArrayList<CivilizationInfo>()
|
|
||||||
|
|
||||||
// Now place the ones assigned to specific regions.
|
// Now place the ones assigned to specific regions.
|
||||||
for (region in regions) {
|
for (region in regions) {
|
||||||
// Check the outer edges of the region, working inwards
|
tryPlaceMinorCivsInTiles(region.assignedMinorCivs, tileMap, region.tiles.toMutableList())
|
||||||
val section = Rectangle(region.rect)
|
|
||||||
val unprocessedTiles = ArrayList<TileInfo>()
|
|
||||||
val regionCoastal = ArrayList<TileInfo>()
|
|
||||||
val regionHinterland = ArrayList<TileInfo>()
|
|
||||||
while (section.width >= 4 && section.height >= 4 && region.assignedMinorCivs.isNotEmpty()) {
|
|
||||||
// Clear the tile lists
|
|
||||||
unprocessedTiles.clear()
|
|
||||||
regionCoastal.clear()
|
|
||||||
regionHinterland.clear()
|
|
||||||
if (section.height > section.width) {
|
|
||||||
// Check top and bottom
|
|
||||||
unprocessedTiles.addAll(
|
|
||||||
tileMap.getTilesInRectangle(
|
|
||||||
Rectangle(section.x, section.y, section.width, 1f),
|
|
||||||
evenQ = true)
|
|
||||||
)
|
|
||||||
unprocessedTiles.addAll(
|
|
||||||
tileMap.getTilesInRectangle(
|
|
||||||
Rectangle(section.x, section.y + section.height - 1, section.width, 1f),
|
|
||||||
evenQ = true)
|
|
||||||
)
|
|
||||||
// Narrow the remaining section
|
|
||||||
section.y += 1
|
|
||||||
section.height -= 2
|
|
||||||
} else {
|
|
||||||
// Check left and right
|
|
||||||
unprocessedTiles.addAll(
|
|
||||||
tileMap.getTilesInRectangle(
|
|
||||||
Rectangle(section.x, section.y, 1f, section.height),
|
|
||||||
evenQ = true)
|
|
||||||
)
|
|
||||||
unprocessedTiles.addAll(
|
|
||||||
tileMap.getTilesInRectangle(
|
|
||||||
Rectangle(section.x + section.width - 1, section.y, 1f, section.height),
|
|
||||||
evenQ = true)
|
|
||||||
)
|
|
||||||
// Narrow the remaining section
|
|
||||||
section.x += 1
|
|
||||||
section.width -= 2
|
|
||||||
}
|
|
||||||
// Now process the tiles
|
|
||||||
for (tile in unprocessedTiles) {
|
|
||||||
if (!canPlaceMinorCiv(tile)) continue
|
|
||||||
if (!usingArchipelagoRegions && tile.getContinent() != region.continentID) continue
|
|
||||||
if(tile.isCoastalTile())
|
|
||||||
regionCoastal.add(tile)
|
|
||||||
else
|
|
||||||
regionHinterland.add(tile)
|
|
||||||
}
|
|
||||||
// Now attempt to place as many minor civs as possible, trying coastal tiles first
|
|
||||||
tryPlaceMinorCivsInTiles(region.assignedMinorCivs, tileMap, regionCoastal)
|
|
||||||
tryPlaceMinorCivsInTiles(region.assignedMinorCivs, tileMap, regionHinterland)
|
|
||||||
}
|
|
||||||
// In case we went through the entire region without finding spots for all assigned civs
|
|
||||||
if(region.assignedMinorCivs.isNotEmpty()) {
|
|
||||||
fallbackMinors.addAll(region.assignedMinorCivs)
|
|
||||||
} else {
|
|
||||||
// If we did find spots for all civs, there might be more eligible tiles left in the region
|
|
||||||
// Add them to the fallback list
|
|
||||||
fallbackTiles.addAll(regionCoastal)
|
|
||||||
fallbackTiles.addAll(regionHinterland)
|
|
||||||
fallbackTiles.addAll(tileMap.getTilesInRectangle(section, evenQ = true)
|
|
||||||
.filter { canPlaceMinorCiv(it) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally attempt to place the fallback lists - the rest will be silently discarded
|
|
||||||
if (fallbackMinors.isNotEmpty()) {
|
|
||||||
// Throw in the uninhabited lists as well
|
|
||||||
fallbackTiles.addAll(uninhabitedCoastal)
|
|
||||||
fallbackTiles.addAll(uninhabitedHinterland)
|
|
||||||
tryPlaceMinorCivsInTiles(fallbackMinors, tileMap, fallbackTiles)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user