When picking random city states for a map, first priority now goes to city states with starting locations defined in the map

This commit is contained in:
Yair Morgenstern 2019-09-18 22:42:44 +03:00
parent 753efe5f47
commit 2def82c4a6

View file

@ -41,8 +41,15 @@ class GameStarter{
}
val cityStatesWithStartingLocations =
gameInfo.tileMap.values.filter { it.improvement!=null && it.improvement!!.startsWith("StartingLocation ") }
.map { it.improvement!!.replace("StartingLocation ","") }
val availableCityStatesNames = Stack<String>()
availableCityStatesNames.addAll(GameBasics.Nations.filter { it.value.isCityState() }.keys.shuffled())
// since we shuffle and then order by, we end up with all the city states with starting locations first in a random order,
// and then all the other city states in a random order! Because the sortedBy function is stable!
availableCityStatesNames.addAll(GameBasics.Nations.filter { it.value.isCityState() }.keys
.shuffled().sortedByDescending { it in cityStatesWithStartingLocations })
for (cityStateName in availableCityStatesNames.take(newGameParameters.numberOfCityStates)) {
val civ = CivilizationInfo(cityStateName)