Merge 469e1ce2983c8bad3463ea3f226e1670eb3f5236 into d51ef24c205b6b05330b3c4d7ce79c402db44447

This commit is contained in:
EmperorPinguin 2025-09-18 13:09:14 +00:00 committed by GitHub
commit cb1c168ea1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ import com.unciv.logic.civilization.Civilization
import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.civilization.diplomacy.RelationshipLevel
import com.unciv.models.Spy import com.unciv.models.Spy
import com.unciv.models.SpyAction import com.unciv.models.SpyAction
import com.unciv.ui.screens.victoryscreen.RankingType
import kotlin.random.Random import kotlin.random.Random
class EspionageAutomation(val civInfo: Civilization) { class EspionageAutomation(val civInfo: Civilization) {
@ -26,23 +27,23 @@ class EspionageAutomation(val civInfo: Civilization) {
val spies = civInfo.espionageManager.spyList val spies = civInfo.espionageManager.spyList
val spiesToMove = spies.filter { it.isAlive() && !it.isDoingWork() } val spiesToMove = spies.filter { it.isAlive() && !it.isDoingWork() }
for (spy in spiesToMove) { for (spy in spiesToMove) {
val randomSeed = spies.size + spies.indexOf(spy) + civInfo.gameInfo.turns val spyIsMaxPromoted = spy.rank == civInfo.gameInfo.ruleset.modOptions.constants.maxSpyRank
val randomAction = Random(randomSeed).nextInt(10) val techRank = civInfo.gameInfo.getAliveMajorCivs().sortedByDescending { it.getStatForRanking(RankingType.Technologies) }.indexOf(civInfo)
// Try each operation based on the random value and the success rate // Try each operation based on the random value and the success rate
// If an operation was not successfull try the next one // If an operation was not successfull try the next one
val capital = civInfo.getCapital() val capital = civInfo.getCapital()
when { when {
spyIsMaxPromoted && automateSpyRigElection(spy) -> continue // Other spies can still be ranked up via stealing or counterspying
techRank != 0 && automateSpyStealTech(spy) -> continue // If we're tech leader, we'll soon run out of stealable techs, if we haven't already
capital != null && spies.none { it.getCityOrNull() == capital } -> { capital != null && spies.none { it.getCityOrNull() == capital } -> {
spy.moveTo(capital) spy.moveTo(capital) // Place in capital before choosing based on science output, as capital is visible via embassies
continue continue
} }
randomAction <= 7 && automateSpyStealTech(spy) -> continue automateSpyCounterIntelligence(spy) -> continue
randomAction <= 9 && automateSpyRigElection(spy) -> continue
automateSpyCounterInteligence(spy) -> continue
// We might have been doing counter intelligence and wanted to look for something better // We might have been doing counter intelligence and wanted to look for something better
spy.isDoingWork() -> continue spy.isDoingWork() -> continue
// Retry initial operations one more time, without the randomAction check // Retry initial operations one more time, without the check
automateSpyStealTech(spy) -> continue automateSpyStealTech(spy) -> continue
automateSpyRigElection(spy) -> continue automateSpyRigElection(spy) -> continue
} }
@ -78,13 +79,11 @@ class EspionageAutomation(val civInfo: Civilization) {
spy.moveTo(cityToMoveTo) spy.moveTo(cityToMoveTo)
return cityToMoveTo != null return cityToMoveTo != null
} }
/** /**
* Moves the spy to a random city of ours * Moves the spy to a random city of ours
*/ */
private fun automateSpyCounterInteligence(spy: Spy): Boolean { private fun automateSpyCounterIntelligence(spy: Spy): Boolean {
val cityToMoveTo = civInfo.cities.filter { spy.canMoveTo(it) } val cityToMoveTo = civInfo.cities.filter { spy.canMoveTo(it) }
.maxByOrNull { it.cityStats.currentCityStats.science } .maxByOrNull { it.cityStats.currentCityStats.science }
if (cityToMoveTo == null) return false if (cityToMoveTo == null) return false