diff --git a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt index 724831a09173e..e002998b5c6ea 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt @@ -626,90 +626,110 @@ class CityStateFunctions(val civInfo: Civilization) { } } // Others might become wary! - if (attacker.isMinorCivAggressor()) { - for (cityState in civInfo.gameInfo.getAliveCityStates()) { - if (cityState == civInfo) // Must be a different minor - continue - if (cityState.getAllyCiv() == attacker.civName) // Must not be allied to the attacker - continue - if (!cityState.knows(attacker)) // Must have met - continue - if (cityState.questManager.wantsDead(civInfo.civName)) // Must not want us dead - continue - - var probability: Int - if (attacker.isMinorCivWarmonger()) { - // High probability if very aggressive - probability = when (cityState.getProximity(attacker)) { - Proximity.Neighbors -> 100 - Proximity.Close -> 75 - Proximity.Far -> 50 - Proximity.Distant -> 25 - else -> 0 - } - } else { - // Lower probability if only somewhat aggressive - probability = when (cityState.getProximity(attacker)) { - Proximity.Neighbors -> 50 - Proximity.Close -> 20 - else -> 0 - } - } + if (attacker.isMinorCivAggressor()) makeOtherCityStatesWaryOfAttacker(attacker) + + triggerProtectorCivs(attacker) - // Higher probability if already at war - if (cityState.isAtWarWith(attacker)) - probability += 50 + // Even if we aren't *technically* protectors, we *can* still be pissed you attacked our allies + triggerAllyCivs(attacker) - if (Random.Default.nextInt(100) <= probability) { - cityState.getDiplomacyManager(attacker)!!.becomeWary() + // Set up war with major pseudo-quest + civInfo.questManager.wasAttackedBy(attacker) + civInfo.getDiplomacyManager(attacker)!!.setFlag(DiplomacyFlags.RecentlyAttacked, 2) // Reminder to ask for unit gifts in 2 turns + } + + private fun makeOtherCityStatesWaryOfAttacker(attacker: Civilization) { + for (cityState in civInfo.gameInfo.getAliveCityStates()) { + if (cityState == civInfo) // Must be a different minor + continue + if (cityState.getAllyCiv() == attacker.civName) // Must not be allied to the attacker + continue + if (!cityState.knows(attacker)) // Must have met + continue + if (cityState.questManager.wantsDead(civInfo.civName)) // Must not want us dead + continue + + var probability: Int = if (attacker.isMinorCivWarmonger()) { + // High probability if very aggressive + when (cityState.getProximity(attacker)) { + Proximity.Neighbors -> 100 + Proximity.Close -> 75 + Proximity.Far -> 50 + Proximity.Distant -> 25 + else -> 0 + } + } else { + // Lower probability if only somewhat aggressive + when (cityState.getProximity(attacker)) { + Proximity.Neighbors -> 50 + Proximity.Close -> 20 + else -> 0 } } + + // Higher probability if already at war + if (cityState.isAtWarWith(attacker)) + probability += 50 + + if (Random.nextInt(100) <= probability) { + cityState.getDiplomacyManager(attacker)!!.becomeWary() + } } + } + private fun triggerProtectorCivs(attacker: Civilization) { for (protector in civInfo.cityStateFunctions.getProtectorCivs()) { val protectorDiplomacy = protector.getDiplomacyManager(attacker) ?: continue // Who? if (protectorDiplomacy.hasModifier(DiplomaticModifiers.AttackedProtectedMinor) - && protectorDiplomacy.getFlag(DiplomacyFlags.RememberAttackedProtectedMinor) > 50) - protectorDiplomacy.addModifier(DiplomaticModifiers.AttackedProtectedMinor, -15f) // Penalty less severe for second offence + && protectorDiplomacy.getFlag(DiplomacyFlags.RememberAttackedProtectedMinor) > 50 + ) + protectorDiplomacy.addModifier( + DiplomaticModifiers.AttackedProtectedMinor, + -15f + ) // Penalty less severe for second offence else protectorDiplomacy.addModifier(DiplomaticModifiers.AttackedProtectedMinor, -20f) protectorDiplomacy.setFlag(DiplomacyFlags.RememberAttackedProtectedMinor, 75) // Reset their memory if (protector.playerType != PlayerType.Human) // Humans can have their own emotions - attacker.addNotification("[${protector.civName}] is upset that you attacked [${civInfo.civName}], whom they have pledged to protect!", - NotificationCategory.Diplomacy, NotificationIcon.Diplomacy, protector.civName) + attacker.addNotification( + "[${protector.civName}] is upset that you attacked [${civInfo.civName}], whom they have pledged to protect!", + NotificationCategory.Diplomacy, NotificationIcon.Diplomacy, protector.civName + ) else // Let humans choose who to side with protector.popupAlerts.add( PopupAlert( AlertType.AttackedProtectedMinor, - attacker.civName + "@" + civInfo.civName) + attacker.civName + "@" + civInfo.civName + ) ) // we need to pass both civs as argument, hence the horrible chimera } + } - // Even if we aren't *technically* protectors, we *can* still be pissed you attacked our allies* + private fun triggerAllyCivs(attacker: Civilization) { val allyCivName = civInfo.getAllyCiv() val allyCiv = if (allyCivName != null) civInfo.gameInfo.getCivilization(allyCivName) else null - if (allyCiv != null && allyCiv !in civInfo.cityStateFunctions.getProtectorCivs() && allyCiv.knows(attacker)){ + if (allyCiv != null && allyCiv !in civInfo.cityStateFunctions.getProtectorCivs() && allyCiv.knows(attacker)) { val allyDiplomacy = allyCiv.getDiplomacyManager(attacker)!! // Less than if we were protectors allyDiplomacy.addModifier(DiplomaticModifiers.AttackedAlliedMinor, -10f) if (allyCiv.playerType != PlayerType.Human) // Humans can have their own emotions - attacker.addNotification("[${allyCiv.civName}] is upset that you attacked [${civInfo.civName}], whom they are allied with!", - NotificationCategory.Diplomacy, NotificationIcon.Diplomacy, allyCiv.civName) + attacker.addNotification( + "[${allyCiv.civName}] is upset that you attacked [${civInfo.civName}], whom they are allied with!", + NotificationCategory.Diplomacy, NotificationIcon.Diplomacy, allyCiv.civName + ) else // Let humans choose who to side with allyCiv.popupAlerts.add( PopupAlert( AlertType.AttackedAllyMinor, - attacker.civName + "@" + civInfo.civName) + attacker.civName + "@" + civInfo.civName + ) ) } - - // Set up war with major pseudo-quest - civInfo.questManager.wasAttackedBy(attacker) - civInfo.getDiplomacyManager(attacker)!!.setFlag(DiplomacyFlags.RecentlyAttacked, 2) // Reminder to ask for unit gifts in 2 turns } + /** A city state was destroyed. Its protectors are going to be upset! */ fun cityStateDestroyed(attacker: Civilization) { if (!civInfo.isCityState) return // What are we doing here?