mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 03:18:18 +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) {
|
||||
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
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -163,24 +163,30 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
|
||||
}
|
||||
|
||||
var friendBonusText = "When Friends: ".tr()
|
||||
val friendBonuses = viewingCiv.getEraObject().friendBonus[otherCiv.cityStateType.name]
|
||||
if (friendBonuses != null) {
|
||||
friendBonusText += 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) {
|
||||
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()
|
||||
val eraInfo = viewingCiv.getEraObject()
|
||||
val friendBonuses =
|
||||
if (eraInfo == null) null
|
||||
else eraInfo.friendBonus[otherCiv.cityStateType.name]
|
||||
friendBonusText +=
|
||||
if (friendBonuses != null) {
|
||||
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"
|
||||
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: "
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user