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
|
this.location = cityLocation
|
||||||
civInfo.cities.add(this)
|
civInfo.cities = civInfo.cities.toMutableList().apply { add(this@CityInfo) }
|
||||||
if(civInfo == civInfo.gameInfo.getPlayerCivilization())
|
if(civInfo == civInfo.gameInfo.getPlayerCivilization())
|
||||||
civInfo.addNotification("$name {has been founded}!", cityLocation, Color.PURPLE)
|
civInfo.addNotification("$name {has been founded}!", cityLocation, Color.PURPLE)
|
||||||
if (civInfo.policies.isAdopted("Legalism") && civInfo.cities.size <= 4) cityConstructions.addCultureBuilding()
|
if (civInfo.policies.isAdopted("Legalism") && civInfo.cities.size <= 4) cityConstructions.addCultureBuilding()
|
||||||
|
@ -184,14 +184,14 @@ class CityInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destroyCity() {
|
fun destroyCity() {
|
||||||
civInfo.cities.remove(this)
|
civInfo.cities = civInfo.cities.toMutableList().apply { remove(this@CityInfo) }
|
||||||
getTiles().forEach { expansion.relinquishOwnership(it) }
|
getTiles().forEach { expansion.relinquishOwnership(it) }
|
||||||
getCenterTile().improvement="City ruins"
|
getCenterTile().improvement="City ruins"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun moveToCiv(newCivInfo: CivilizationInfo){
|
fun moveToCiv(newCivInfo: CivilizationInfo){
|
||||||
civInfo.cities.remove(this)
|
civInfo.cities = civInfo.cities.toMutableList().apply { remove(this@CityInfo) }
|
||||||
newCivInfo.cities.add(this)
|
newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(this@CityInfo) }
|
||||||
civInfo = newCivInfo
|
civInfo = newCivInfo
|
||||||
|
|
||||||
// now that the tiles have changed, we need to reassign population
|
// now that the tiles have changed, we need to reassign population
|
||||||
|
|
|
@ -35,7 +35,11 @@ class CivilizationInfo {
|
||||||
var greatPeople = GreatPersonManager()
|
var greatPeople = GreatPersonManager()
|
||||||
var scienceVictory = ScienceVictoryManager()
|
var scienceVictory = ScienceVictoryManager()
|
||||||
var diplomacy = HashMap<String,DiplomacyManager>()
|
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>()
|
var exploredTiles = HashSet<Vector2>()
|
||||||
|
|
||||||
constructor()
|
constructor()
|
||||||
|
@ -58,7 +62,7 @@ class CivilizationInfo {
|
||||||
toReturn.greatPeople=greatPeople.clone()
|
toReturn.greatPeople=greatPeople.clone()
|
||||||
toReturn.scienceVictory = scienceVictory.clone()
|
toReturn.scienceVictory = scienceVictory.clone()
|
||||||
toReturn.diplomacy.putAll(diplomacy.values.map { it.clone() }.associateBy { it.otherCivName })
|
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)
|
toReturn.exploredTiles.addAll(exploredTiles)
|
||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue