mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Fix bugs and crashes (#5245)
* Fixed crash when liberating city-states * Fixed crash & building duplication from 'legalism' policy (cherry picked from commit b0dff6a71cc71d3692af30ac34adfd10fdf9e19b)
This commit is contained in:
parent
f9e0c39021
commit
b73b81a313
@ -87,10 +87,10 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
|||||||
|
|
||||||
val reconqueredCityWhileStillInResistance = previousOwner == conqueringCiv.civName && resistanceCounter != 0
|
val reconqueredCityWhileStillInResistance = previousOwner == conqueringCiv.civName && resistanceCounter != 0
|
||||||
|
|
||||||
this@CityInfoConquestFunctions.moveToCiv(receivingCiv)
|
|
||||||
|
|
||||||
destroyBuildingsOnCapture()
|
destroyBuildingsOnCapture()
|
||||||
|
|
||||||
|
this@CityInfoConquestFunctions.moveToCiv(receivingCiv)
|
||||||
|
|
||||||
Battle.destroyIfDefeated(conqueredCiv, conqueringCiv)
|
Battle.destroyIfDefeated(conqueredCiv, conqueringCiv)
|
||||||
|
|
||||||
health = getMaxHealth() / 2 // I think that cities recover to half health when conquered?
|
health = getMaxHealth() / 2 // I think that cities recover to half health when conquered?
|
||||||
|
@ -153,9 +153,12 @@ class CityStats(val cityInfo: CityInfo) {
|
|||||||
stats.add(getStatPercentBonusesFromUniques(currentConstruction, cityInfo.civInfo.nation.uniqueObjects.asSequence()))
|
stats.add(getStatPercentBonusesFromUniques(currentConstruction, cityInfo.civInfo.nation.uniqueObjects.asSequence()))
|
||||||
|
|
||||||
if (currentConstruction is Building
|
if (currentConstruction is Building
|
||||||
|
&& cityInfo.civInfo.cities.isNotEmpty()
|
||||||
&& cityInfo.civInfo.getCapital().cityConstructions.builtBuildings.contains(currentConstruction.name)
|
&& cityInfo.civInfo.getCapital().cityConstructions.builtBuildings.contains(currentConstruction.name)
|
||||||
&& cityInfo.civInfo.hasUnique("+25% Production towards any buildings that already exist in the Capital"))
|
&& cityInfo.civInfo.hasUnique("+25% Production towards any buildings that already exist in the Capital")
|
||||||
|
) {
|
||||||
stats.production += 25f
|
stats.production += 25f
|
||||||
|
}
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,17 @@ class CivConstructions() {
|
|||||||
private val freeBuildings: HashMap<String, HashSet<String>> = hashMapOf()
|
private val freeBuildings: HashMap<String, HashSet<String>> = hashMapOf()
|
||||||
|
|
||||||
// Maps stats to the cities that have received a building of that stat
|
// Maps stats to the cities that have received a building of that stat
|
||||||
// Android Studio says an EnumMap would be better, but that thing isn't serializable.
|
// We can't use an enum instead of a string, due to the inability of the JSON-parser
|
||||||
// I don't know how to suppress that hint :(
|
// to function properly and forcing this to be an `HashMap<String, HashSet<String>>`
|
||||||
private val freeStatBuildingsProvided: HashMap<Stat, HashSet<String>> = hashMapOf()
|
// when loading, even if this wasn't the original type, leading to run-time errors.
|
||||||
|
private val freeStatBuildingsProvided: HashMap<String, HashSet<String>> = hashMapOf()
|
||||||
|
|
||||||
// Maps buildings to the cities that have received that building
|
// Maps buildings to the cities that have received that building
|
||||||
private val freeSpecificBuildingsProvided: HashMap<String, HashSet<String>> = hashMapOf()
|
private val freeSpecificBuildingsProvided: HashMap<String, HashSet<String>> = hashMapOf()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
for (stat in Stat.values()) {
|
for (stat in Stat.values()) {
|
||||||
freeStatBuildingsProvided[stat] = hashSetOf()
|
freeStatBuildingsProvided[stat.name] = hashSetOf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ class CivConstructions() {
|
|||||||
|
|
||||||
if (civInfo.policies.cultureBuildingsAdded.isNotEmpty()) {
|
if (civInfo.policies.cultureBuildingsAdded.isNotEmpty()) {
|
||||||
for ((cityId, building) in civInfo.policies.cultureBuildingsAdded) {
|
for ((cityId, building) in civInfo.policies.cultureBuildingsAdded) {
|
||||||
freeStatBuildingsProvided[Stat.Culture]!!.add(cityId)
|
freeStatBuildingsProvided[Stat.Culture.name]!!.add(cityId)
|
||||||
|
|
||||||
if (cityId !in freeBuildings)
|
if (cityId !in freeBuildings)
|
||||||
freeBuildings[cityId] = hashSetOf()
|
freeBuildings[cityId] = hashSetOf()
|
||||||
@ -126,11 +127,11 @@ class CivConstructions() {
|
|||||||
|
|
||||||
private fun addFreeStatBuildings(stat: Stat, amount: Int) {
|
private fun addFreeStatBuildings(stat: Stat, amount: Int) {
|
||||||
for (city in civInfo.cities.take(amount)) {
|
for (city in civInfo.cities.take(amount)) {
|
||||||
if (freeStatBuildingsProvided[stat]!!.contains(city.id) || !city.cityConstructions.hasBuildableStatBuildings(stat)) continue
|
if (freeStatBuildingsProvided[stat.name]!!.contains(city.id) || !city.cityConstructions.hasBuildableStatBuildings(stat)) continue
|
||||||
|
|
||||||
val builtBuilding = city.cityConstructions.addCheapestBuildableStatBuilding(stat)
|
val builtBuilding = city.cityConstructions.addCheapestBuildableStatBuilding(stat)
|
||||||
if (builtBuilding != null) {
|
if (builtBuilding != null) {
|
||||||
freeStatBuildingsProvided[stat]!!.add(city.id)
|
freeStatBuildingsProvided[stat.name]!!.add(city.id)
|
||||||
addFreeBuilding(city.id, builtBuilding)
|
addFreeBuilding(city.id, builtBuilding)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user