From 7efc71bd2883a8ab849c95a454b2abe1d546eac6 Mon Sep 17 00:00:00 2001 From: Oskar Niesen Date: Sun, 28 Jan 2024 03:06:04 -0600 Subject: [PATCH] Fixed spies errors (#11031) --- core/src/com/unciv/logic/battle/Battle.kt | 13 +------------ .../logic/city/managers/CityConquestFunctions.kt | 4 ++-- .../unciv/logic/city/managers/CityTurnManager.kt | 1 + .../logic/civilization/managers/EspionageManager.kt | 2 +- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 377d29f713..efcacf628c 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -526,18 +526,7 @@ object Battle { if (civilianUnit != null) BattleUnitCapture.captureCivilianUnit(attacker, MapUnitCombatant(civilianUnit!!), checkDefeat = false) for (airUnit in airUnits.toList()) airUnit.destroy() } - - // Move all spies in the city - if (attackerCiv.gameInfo.isEspionageEnabled()) { - for (civ in attackerCiv.gameInfo.civilizations.filter { it.isMajorCiv() }) { - for (spy in civ.espionageManager.spyList) { - if (spy.getLocation() == city) { - spy.moveTo(null) - } - } - } - } - + val stateForConditionals = StateForConditionals(civInfo = attackerCiv, city=city, unit = attacker.unit, ourCombatant = attacker, attackedTile = city.getCenterTile()) for (unique in attacker.getMatchingUniques(UniqueType.CaptureCityPlunder, stateForConditionals, true)) { attackerCiv.addStat( diff --git a/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt b/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt index 9ae3d8ce9d..d6a34937f6 100644 --- a/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt +++ b/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt @@ -79,6 +79,8 @@ class CityConquestFunctions(val city: City) { * should go in `this.moveToCiv()`, which is called by `this.conquerCity()`. */ private fun conquerCity(conqueringCiv: Civilization, conqueredCiv: Civilization, receivingCiv: Civilization) { + city.espionage.removeAllPresentSpies(SpyFleeReason.CityCaptured) + val goldPlundered = getGoldForCapturingCity(conqueringCiv) conqueringCiv.addGold(goldPlundered) conqueringCiv.addNotification("Received [$goldPlundered] Gold for capturing [${city.name}]", @@ -105,8 +107,6 @@ class CityConquestFunctions(val city: City) { // reconquering or liberating city in resistance so eliminate it city.removeFlag(CityFlags.Resistance) } - - city.espionage.removeAllPresentSpies(SpyFleeReason.CityCaptured) } diff --git a/core/src/com/unciv/logic/city/managers/CityTurnManager.kt b/core/src/com/unciv/logic/city/managers/CityTurnManager.kt index d1e13a332b..5a36d83552 100644 --- a/core/src/com/unciv/logic/city/managers/CityTurnManager.kt +++ b/core/src/com/unciv/logic/city/managers/CityTurnManager.kt @@ -125,6 +125,7 @@ class CityTurnManager(val city: City) { city.population.addPopulation(-1 * removedPopulation) if (city.population.population <= 0) { + city.espionage.removeAllPresentSpies(SpyFleeReason.CityCaptured) city.civ.addNotification( "[${city.name}] has been razed to the ground!", city.location, NotificationCategory.General, diff --git a/core/src/com/unciv/logic/civilization/managers/EspionageManager.kt b/core/src/com/unciv/logic/civilization/managers/EspionageManager.kt index 996f26df73..bf7e332190 100644 --- a/core/src/com/unciv/logic/civilization/managers/EspionageManager.kt +++ b/core/src/com/unciv/logic/civilization/managers/EspionageManager.kt @@ -29,7 +29,7 @@ class EspionageManager : IsPartOfGameInfoSerialization { } fun endTurn() { - for (spy in spyList) + for (spy in spyList.toList()) spy.endTurn() }