Civ city list is now concurrency-proof
This commit is contained in:
parent
fdd9481535
commit
eb26a3f241
2 changed files with 10 additions and 6 deletions
|
@ -46,7 +46,7 @@ class CityInfo {
|
|||
}
|
||||
|
||||
this.location = cityLocation
|
||||
civInfo.cities.add(this)
|
||||
civInfo.cities = civInfo.cities.toMutableList().apply { add(this@CityInfo) }
|
||||
if(civInfo == civInfo.gameInfo.getPlayerCivilization())
|
||||
civInfo.addNotification("$name {has been founded}!", cityLocation, Color.PURPLE)
|
||||
if (civInfo.policies.isAdopted("Legalism") && civInfo.cities.size <= 4) cityConstructions.addCultureBuilding()
|
||||
|
@ -184,14 +184,14 @@ class CityInfo {
|
|||
}
|
||||
|
||||
fun destroyCity() {
|
||||
civInfo.cities.remove(this)
|
||||
civInfo.cities = civInfo.cities.toMutableList().apply { remove(this@CityInfo) }
|
||||
getTiles().forEach { expansion.relinquishOwnership(it) }
|
||||
getCenterTile().improvement="City ruins"
|
||||
}
|
||||
|
||||
fun moveToCiv(newCivInfo: CivilizationInfo){
|
||||
civInfo.cities.remove(this)
|
||||
newCivInfo.cities.add(this)
|
||||
civInfo.cities = civInfo.cities.toMutableList().apply { remove(this@CityInfo) }
|
||||
newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(this@CityInfo) }
|
||||
civInfo = newCivInfo
|
||||
|
||||
// now that the tiles have changed, we need to reassign population
|
||||
|
|
|
@ -35,7 +35,11 @@ class CivilizationInfo {
|
|||
var greatPeople = GreatPersonManager()
|
||||
var scienceVictory = ScienceVictoryManager()
|
||||
var diplomacy = HashMap<String,DiplomacyManager>()
|
||||
var cities = ArrayList<CityInfo>()
|
||||
|
||||
// if we only use lists, and change the list each time the cities are changed,
|
||||
// we won't get concurrent modification exceptions.
|
||||
// This is basically a way to ensure our lists are immutable.
|
||||
var cities = listOf<CityInfo>()
|
||||
var exploredTiles = HashSet<Vector2>()
|
||||
|
||||
constructor()
|
||||
|
@ -58,7 +62,7 @@ class CivilizationInfo {
|
|||
toReturn.greatPeople=greatPeople.clone()
|
||||
toReturn.scienceVictory = scienceVictory.clone()
|
||||
toReturn.diplomacy.putAll(diplomacy.values.map { it.clone() }.associateBy { it.otherCivName })
|
||||
toReturn.cities.addAll(cities.map { it.clone() })
|
||||
toReturn.cities = cities.map { it.clone() }
|
||||
toReturn.exploredTiles.addAll(exploredTiles)
|
||||
return toReturn
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue