From 2e8934af176803479bf6a03b28895e9ab0ddbc8e Mon Sep 17 00:00:00 2001 From: SimonCeder <63475501+SimonCeder@users.noreply.github.com> Date: Thu, 23 Sep 2021 10:31:36 +0200 Subject: [PATCH] Newly Allied city states declare war on your enemies, even unmet ones (#5298) * new allies dow, unmet civs meet first and then dow * no gifts for bad people --- .../logic/civilization/CityStateFunctions.kt | 11 ++++++++ .../logic/civilization/CivilizationInfo.kt | 9 ++++--- .../diplomacy/DiplomacyManager.kt | 27 +++++++++++++------ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/CityStateFunctions.kt b/core/src/com/unciv/logic/civilization/CityStateFunctions.kt index 30825d8c1d..eb0a3a6143 100644 --- a/core/src/com/unciv/logic/civilization/CityStateFunctions.kt +++ b/core/src/com/unciv/logic/civilization/CityStateFunctions.kt @@ -226,6 +226,17 @@ class CityStateFunctions(val civInfo: CivilizationInfo) { newAllyCiv.updateDetailedCivResources() for (unique in newAllyCiv.getMatchingUniques("Can spend Gold to annex or puppet a City-State that has been your ally for [] turns.")) newAllyCiv.getDiplomacyManager(civInfo.civName).setFlag(DiplomacyFlags.MarriageCooldown, unique.params[0].toInt()) + + // Join the wars of our new ally - loop through all civs they are at war with + for (newEnemy in civInfo.gameInfo.civilizations.filter { it.isAtWarWith(newAllyCiv) && it.isAlive() } ) { + if (civInfo.knows(newEnemy) && !civInfo.isAtWarWith(newEnemy)) + civInfo.getDiplomacyManager(newEnemy).declareWar() + else if (!civInfo.knows(newEnemy)) { + // We have to meet first + civInfo.makeCivilizationsMeet(newEnemy, warOnContact = true) + civInfo.getDiplomacyManager(newEnemy).declareWar() + } + } } if (oldAllyName != null) { val oldAllyCiv = civInfo.gameInfo.getCivilization(oldAllyName) diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index b3640505c1..130139a970 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -450,12 +450,12 @@ class CivilizationInfo { return baseUnit } - fun makeCivilizationsMeet(otherCiv: CivilizationInfo) { - meetCiv(otherCiv) - otherCiv.meetCiv(this) + fun makeCivilizationsMeet(otherCiv: CivilizationInfo, warOnContact: Boolean = false) { + meetCiv(otherCiv, warOnContact) + otherCiv.meetCiv(this, warOnContact) } - private fun meetCiv(otherCiv: CivilizationInfo) { + private fun meetCiv(otherCiv: CivilizationInfo, warOnContact: Boolean = false) { diplomacy[otherCiv.civName] = DiplomacyManager(this, otherCiv.civName) .apply { diplomaticStatus = DiplomaticStatus.Peace } @@ -465,6 +465,7 @@ class CivilizationInfo { UncivGame.Current.settings.addCompletedTutorialTask("Meet another civilization") if (!(isCityState() && otherCiv.isMajorCiv())) return + if (warOnContact || otherCiv.isMinorCivAggressor()) return // No gift if they are bad people, or we are just about to be at war val cityStateLocation = if (cities.isEmpty()) null else getCapital().location diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index 6d16db8858..b1ecfb46fb 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -675,21 +675,32 @@ class DiplomacyManager() { } otherCivDiplomacy.removeFlag(DiplomacyFlags.ResearchAgreement) + // Go through our city state allies. if (!civInfo.isCityState()) { for (thirdCiv in civInfo.getKnownCivs()) { - if (thirdCiv.isCityState() && thirdCiv.getAllyCiv() == civInfo.civName - && thirdCiv.knows(otherCiv) - && thirdCiv.getDiplomacyManager(otherCiv).canDeclareWar()) { - thirdCiv.getDiplomacyManager(otherCiv).declareWar() + if (thirdCiv.isCityState() && thirdCiv.getAllyCiv() == civInfo.civName) { + if (thirdCiv.knows(otherCiv) && !thirdCiv.isAtWarWith(otherCiv)) + thirdCiv.getDiplomacyManager(otherCiv).declareWar() + else if (!thirdCiv.knows(otherCiv)) { + // Our city state ally has not met them yet, so they have to meet first + thirdCiv.makeCivilizationsMeet(otherCiv, warOnContact = true) + thirdCiv.getDiplomacyManager(otherCiv).declareWar() + } } } } + + // Go through their city state allies. if (!otherCiv.isCityState()) { for (thirdCiv in otherCiv.getKnownCivs()) { - if (thirdCiv.isCityState() && thirdCiv.getAllyCiv() == otherCiv.civName - && thirdCiv.knows(civInfo) - && thirdCiv.getDiplomacyManager(civInfo).canDeclareWar()) { - thirdCiv.getDiplomacyManager(civInfo).declareWar() + if (thirdCiv.isCityState() && thirdCiv.getAllyCiv() == otherCiv.civName) { + if (thirdCiv.knows(civInfo) && !thirdCiv.isAtWarWith(civInfo)) + thirdCiv.getDiplomacyManager(civInfo).declareWar() + else if (!thirdCiv.knows(civInfo)) { + // Their city state ally has not met us yet, so we have to meet first + thirdCiv.makeCivilizationsMeet(civInfo, warOnContact = true) + thirdCiv.getDiplomacyManager(civInfo).declareWar() + } } } }