mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
Fixes crashes from loading mods without an eras.json file (#4910)
This commit is contained in:
parent
c7265c79b6
commit
a4e61d65c2
@ -127,7 +127,7 @@ class CityStats {
|
|||||||
if (otherCiv.isCityState() && otherCiv.getDiplomacyManager(cityInfo.civInfo).relationshipLevel() >= RelationshipLevel.Friend) {
|
if (otherCiv.isCityState() && otherCiv.getDiplomacyManager(cityInfo.civInfo).relationshipLevel() >= RelationshipLevel.Friend) {
|
||||||
val eraInfo = cityInfo.civInfo.getEraObject()
|
val eraInfo = cityInfo.civInfo.getEraObject()
|
||||||
|
|
||||||
if (eraInfo.friendBonus[otherCiv.cityStateType.name] == null || eraInfo.allyBonus[otherCiv.cityStateType.name] == null) {
|
if (eraInfo == null || eraInfo.friendBonus[otherCiv.cityStateType.name] == null || eraInfo.allyBonus[otherCiv.cityStateType.name] == null) {
|
||||||
// Deprecated, assume Civ V values for compatibility
|
// Deprecated, assume Civ V values for compatibility
|
||||||
if (otherCiv.cityStateType == CityStateType.Maritime && otherCiv.getDiplomacyManager(cityInfo.civInfo).relationshipLevel() == RelationshipLevel.Ally)
|
if (otherCiv.cityStateType == CityStateType.Maritime && otherCiv.getDiplomacyManager(cityInfo.civInfo).relationshipLevel() == RelationshipLevel.Ally)
|
||||||
stats.food += 1
|
stats.food += 1
|
||||||
|
@ -86,11 +86,15 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
|||||||
for (otherCiv in civInfo.getKnownCivs()) {
|
for (otherCiv in civInfo.getKnownCivs()) {
|
||||||
if (otherCiv.isCityState() && otherCiv.getDiplomacyManager(civInfo.civName).relationshipLevel() >= RelationshipLevel.Friend) {
|
if (otherCiv.isCityState() && otherCiv.getDiplomacyManager(civInfo.civName).relationshipLevel() >= RelationshipLevel.Friend) {
|
||||||
val cityStateBonus = Stats()
|
val cityStateBonus = Stats()
|
||||||
|
val eraInfo = civInfo.getEraObject()
|
||||||
|
|
||||||
val relevantBonuses = if (otherCiv.getDiplomacyManager(civInfo.civName).relationshipLevel() == RelationshipLevel.Friend)
|
val relevantBonuses =
|
||||||
civInfo.getEraObject().friendBonus[otherCiv.cityStateType.name]
|
when {
|
||||||
else
|
eraInfo == null -> null
|
||||||
civInfo.getEraObject().allyBonus[otherCiv.cityStateType.name]
|
otherCiv.getDiplomacyManager(civInfo.civName).relationshipLevel() == RelationshipLevel.Friend ->
|
||||||
|
eraInfo.friendBonus[otherCiv.cityStateType.name]
|
||||||
|
else -> eraInfo.allyBonus[otherCiv.cityStateType.name]
|
||||||
|
}
|
||||||
|
|
||||||
if (relevantBonuses != null) {
|
if (relevantBonuses != null) {
|
||||||
for (bonus in relevantBonuses) {
|
for (bonus in relevantBonuses) {
|
||||||
@ -235,10 +239,15 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
|||||||
//From city-states
|
//From city-states
|
||||||
for (otherCiv in civInfo.getKnownCivs()) {
|
for (otherCiv in civInfo.getKnownCivs()) {
|
||||||
if (otherCiv.isCityState() && otherCiv.getDiplomacyManager(civInfo).relationshipLevel() >= RelationshipLevel.Friend) {
|
if (otherCiv.isCityState() && otherCiv.getDiplomacyManager(civInfo).relationshipLevel() >= RelationshipLevel.Friend) {
|
||||||
val relevantbonuses = if (otherCiv.getDiplomacyManager(civInfo).relationshipLevel() == RelationshipLevel.Friend)
|
val eraInfo = civInfo.getEraObject()
|
||||||
civInfo.getEraObject().friendBonus[otherCiv.cityStateType.name]
|
val relevantbonuses =
|
||||||
else
|
when {
|
||||||
civInfo.getEraObject().allyBonus[otherCiv.cityStateType.name]
|
eraInfo == null -> null
|
||||||
|
otherCiv.getDiplomacyManager(civInfo).relationshipLevel() == RelationshipLevel.Friend ->
|
||||||
|
eraInfo.friendBonus[otherCiv.cityStateType.name]
|
||||||
|
else ->
|
||||||
|
eraInfo.allyBonus[otherCiv.cityStateType.name]
|
||||||
|
}
|
||||||
|
|
||||||
if (relevantbonuses != null) {
|
if (relevantbonuses != null) {
|
||||||
for (bonus in relevantbonuses) {
|
for (bonus in relevantbonuses) {
|
||||||
|
@ -415,7 +415,7 @@ class CivilizationInfo {
|
|||||||
|
|
||||||
fun getEraNumber(): Int = gameInfo.ruleSet.getEraNumber(getEra())
|
fun getEraNumber(): Int = gameInfo.ruleSet.getEraNumber(getEra())
|
||||||
|
|
||||||
fun getEraObject(): Era = gameInfo.ruleSet.eras[getEra()]!!
|
fun getEraObject(): Era? = gameInfo.ruleSet.eras[getEra()]
|
||||||
|
|
||||||
fun isAtWarWith(otherCiv: CivilizationInfo): Boolean {
|
fun isAtWarWith(otherCiv: CivilizationInfo): Boolean {
|
||||||
if (otherCiv.civName == civName) return false // never at war with itself
|
if (otherCiv.civName == civName) return false // never at war with itself
|
||||||
|
@ -510,8 +510,14 @@ class DiplomacyManager() {
|
|||||||
if (relationshipLevel() < RelationshipLevel.Friend) {
|
if (relationshipLevel() < RelationshipLevel.Friend) {
|
||||||
if (hasFlag(DiplomacyFlags.ProvideMilitaryUnit)) removeFlag(DiplomacyFlags.ProvideMilitaryUnit)
|
if (hasFlag(DiplomacyFlags.ProvideMilitaryUnit)) removeFlag(DiplomacyFlags.ProvideMilitaryUnit)
|
||||||
} else {
|
} else {
|
||||||
val relevantBonuses = if (relationshipLevel() == RelationshipLevel.Friend) eraInfo.friendBonus[otherCiv().cityStateType.name]
|
val relevantBonuses =
|
||||||
else eraInfo.allyBonus[otherCiv().cityStateType.name]
|
when {
|
||||||
|
eraInfo == null -> null
|
||||||
|
relationshipLevel() == RelationshipLevel.Friend ->
|
||||||
|
eraInfo.friendBonus[otherCiv().cityStateType.name]
|
||||||
|
else -> eraInfo.allyBonus[otherCiv().cityStateType.name]
|
||||||
|
}
|
||||||
|
|
||||||
if (relevantBonuses == null && otherCiv().cityStateType == CityStateType.Militaristic) {
|
if (relevantBonuses == null && otherCiv().cityStateType == CityStateType.Militaristic) {
|
||||||
// Deprecated, assume Civ V values for compatibility
|
// Deprecated, assume Civ V values for compatibility
|
||||||
if (!hasFlag(DiplomacyFlags.ProvideMilitaryUnit) && relationshipLevel() == RelationshipLevel.Friend)
|
if (!hasFlag(DiplomacyFlags.ProvideMilitaryUnit) && relationshipLevel() == RelationshipLevel.Friend)
|
||||||
|
@ -163,24 +163,30 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var friendBonusText = "When Friends: ".tr()
|
var friendBonusText = "When Friends: ".tr()
|
||||||
val friendBonuses = viewingCiv.getEraObject().friendBonus[otherCiv.cityStateType.name]
|
val eraInfo = viewingCiv.getEraObject()
|
||||||
if (friendBonuses != null) {
|
val friendBonuses =
|
||||||
friendBonusText += friendBonuses.joinToString(separator = ", ") { it.tr() }
|
if (eraInfo == null) null
|
||||||
} else {
|
else eraInfo.friendBonus[otherCiv.cityStateType.name]
|
||||||
// Deprecated, assume Civ V values for compatibility
|
friendBonusText +=
|
||||||
val cultureBonus = if(viewingCiv.getEraNumber() in 0..1) "3" else if (viewingCiv.getEraNumber() in 2..3) "6" else "13"
|
if (friendBonuses != null) {
|
||||||
val happinessBonus = if(viewingCiv.getEraNumber() in 0..1) "2" else "3"
|
friendBonuses.joinToString(separator = ", ") { it.tr() }
|
||||||
friendBonusText += when (otherCiv.cityStateType) {
|
} else {
|
||||||
CityStateType.Militaristic -> "Provides military units every [20] turns".tr()
|
// Deprecated, assume Civ V values for compatibility
|
||||||
CityStateType.Cultured -> ("Provides [" + cultureBonus + "] [Culture] per turn").tr()
|
val cultureBonus = if(viewingCiv.getEraNumber() in 0..1) "3" else if (viewingCiv.getEraNumber() in 2..3) "6" else "13"
|
||||||
CityStateType.Mercantile -> ("Provides [" + happinessBonus + "] Happiness").tr()
|
val happinessBonus = if(viewingCiv.getEraNumber() in 0..1) "2" else "3"
|
||||||
CityStateType.Maritime -> "Provides [2] [Food] [in capital]".tr()
|
when (otherCiv.cityStateType) {
|
||||||
|
CityStateType.Militaristic -> "Provides military units every [20] turns".tr()
|
||||||
|
CityStateType.Cultured -> ("Provides [" + cultureBonus + "] [Culture] per turn").tr()
|
||||||
|
CityStateType.Mercantile -> ("Provides [" + happinessBonus + "] Happiness").tr()
|
||||||
|
CityStateType.Maritime -> "Provides [2] [Food] [in capital]".tr()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var allyBonusText = "When Allies: "
|
var allyBonusText = "When Allies: "
|
||||||
val allyBonuses = viewingCiv.getEraObject().allyBonus[otherCiv.cityStateType.name]
|
val allyBonuses =
|
||||||
|
if (eraInfo == null) null
|
||||||
|
else eraInfo.allyBonus[otherCiv.cityStateType.name]
|
||||||
if (allyBonuses != null) {
|
if (allyBonuses != null) {
|
||||||
allyBonusText += allyBonuses.joinToString(separator = ", ") { it.tr() }
|
allyBonusText += allyBonuses.joinToString(separator = ", ") { it.tr() }
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user