Fixes crashes from loading mods without an eras.json file (#4910)

This commit is contained in:
Xander Lenstra 2021-08-19 19:44:11 +02:00 committed by GitHub
parent c7265c79b6
commit a4e61d65c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 26 deletions

View File

@ -127,7 +127,7 @@ class CityStats {
if (otherCiv.isCityState() && otherCiv.getDiplomacyManager(cityInfo.civInfo).relationshipLevel() >= RelationshipLevel.Friend) {
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
if (otherCiv.cityStateType == CityStateType.Maritime && otherCiv.getDiplomacyManager(cityInfo.civInfo).relationshipLevel() == RelationshipLevel.Ally)
stats.food += 1

View File

@ -86,11 +86,15 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
for (otherCiv in civInfo.getKnownCivs()) {
if (otherCiv.isCityState() && otherCiv.getDiplomacyManager(civInfo.civName).relationshipLevel() >= RelationshipLevel.Friend) {
val cityStateBonus = Stats()
val eraInfo = civInfo.getEraObject()
val relevantBonuses = if (otherCiv.getDiplomacyManager(civInfo.civName).relationshipLevel() == RelationshipLevel.Friend)
civInfo.getEraObject().friendBonus[otherCiv.cityStateType.name]
else
civInfo.getEraObject().allyBonus[otherCiv.cityStateType.name]
val relevantBonuses =
when {
eraInfo == null -> null
otherCiv.getDiplomacyManager(civInfo.civName).relationshipLevel() == RelationshipLevel.Friend ->
eraInfo.friendBonus[otherCiv.cityStateType.name]
else -> eraInfo.allyBonus[otherCiv.cityStateType.name]
}
if (relevantBonuses != null) {
for (bonus in relevantBonuses) {
@ -235,10 +239,15 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
//From city-states
for (otherCiv in civInfo.getKnownCivs()) {
if (otherCiv.isCityState() && otherCiv.getDiplomacyManager(civInfo).relationshipLevel() >= RelationshipLevel.Friend) {
val relevantbonuses = if (otherCiv.getDiplomacyManager(civInfo).relationshipLevel() == RelationshipLevel.Friend)
civInfo.getEraObject().friendBonus[otherCiv.cityStateType.name]
else
civInfo.getEraObject().allyBonus[otherCiv.cityStateType.name]
val eraInfo = civInfo.getEraObject()
val relevantbonuses =
when {
eraInfo == null -> null
otherCiv.getDiplomacyManager(civInfo).relationshipLevel() == RelationshipLevel.Friend ->
eraInfo.friendBonus[otherCiv.cityStateType.name]
else ->
eraInfo.allyBonus[otherCiv.cityStateType.name]
}
if (relevantbonuses != null) {
for (bonus in relevantbonuses) {

View File

@ -415,7 +415,7 @@ class CivilizationInfo {
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 {
if (otherCiv.civName == civName) return false // never at war with itself

View File

@ -510,8 +510,14 @@ class DiplomacyManager() {
if (relationshipLevel() < RelationshipLevel.Friend) {
if (hasFlag(DiplomacyFlags.ProvideMilitaryUnit)) removeFlag(DiplomacyFlags.ProvideMilitaryUnit)
} else {
val relevantBonuses = if (relationshipLevel() == RelationshipLevel.Friend) eraInfo.friendBonus[otherCiv().cityStateType.name]
else eraInfo.allyBonus[otherCiv().cityStateType.name]
val relevantBonuses =
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) {
// Deprecated, assume Civ V values for compatibility
if (!hasFlag(DiplomacyFlags.ProvideMilitaryUnit) && relationshipLevel() == RelationshipLevel.Friend)

View File

@ -163,14 +163,18 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
}
var friendBonusText = "When Friends: ".tr()
val friendBonuses = viewingCiv.getEraObject().friendBonus[otherCiv.cityStateType.name]
val eraInfo = viewingCiv.getEraObject()
val friendBonuses =
if (eraInfo == null) null
else eraInfo.friendBonus[otherCiv.cityStateType.name]
friendBonusText +=
if (friendBonuses != null) {
friendBonusText += friendBonuses.joinToString(separator = ", ") { it.tr() }
friendBonuses.joinToString(separator = ", ") { it.tr() }
} else {
// Deprecated, assume Civ V values for compatibility
val cultureBonus = if(viewingCiv.getEraNumber() in 0..1) "3" else if (viewingCiv.getEraNumber() in 2..3) "6" else "13"
val happinessBonus = if(viewingCiv.getEraNumber() in 0..1) "2" else "3"
friendBonusText += when (otherCiv.cityStateType) {
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()
@ -180,7 +184,9 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
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) {
allyBonusText += allyBonuses.joinToString(separator = ", ") { it.tr() }
} else {