From 2768042700b636a18d78eaeeab90bb59ca4c74d8 Mon Sep 17 00:00:00 2001 From: Oskar Niesen Date: Sat, 30 Dec 2023 12:49:57 -0600 Subject: [PATCH] AI focuses city-state gold gifting (#10836) * AI prioritises gifting gold to city-states with more influence invested * AI only gives smaller city-state gold gifts if it already has influence * AI prioritises gifting gold to city-states with the investment quest * Only UseGoldAutomation includes valuing if the city-state has a quest --- .../automation/civilization/NextTurnAutomation.kt | 15 ++++++++++++--- .../automation/civilization/UseGoldAutomation.kt | 10 ++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt index 3c2e514637..f72b5054fa 100644 --- a/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt @@ -118,7 +118,7 @@ object NextTurnAutomation { civInfo.popupAlerts.clear() // AIs don't care about popups. } - internal fun valueCityStateAlliance(civInfo: Civilization, cityState: Civilization): Int { + internal fun valueCityStateAlliance(civInfo: Civilization, cityState: Civilization, includeQuests: Boolean = false): Int { var value = 0 if (civInfo.wantsToFocusOn(Victory.Focus.Culture) && cityState.cityStateFunctions.canProvideStat(Stat.Culture)) { @@ -150,8 +150,12 @@ object NextTurnAutomation { if (!cityState.isAlive() || cityState.cities.isEmpty() || civInfo.cities.isEmpty()) return value + + // The more we have invested into the city-state the more the alliance is worth + val ourInfluence = cityState.getDiplomacyManager(civInfo).getInfluence().toInt() + value += ourInfluence / 10 - if (civInfo.gold < 100) { + if (civInfo.gold < 100 && ourInfluence < 30) { // Consider bullying for cash value -= 5 } @@ -159,7 +163,7 @@ object NextTurnAutomation { if (cityState.getAllyCiv() != null && cityState.getAllyCiv() != civInfo.civName) { // easier not to compete if a third civ has this locked down val thirdCivInfluence = cityState.getDiplomacyManager(cityState.getAllyCiv()!!).getInfluence().toInt() - value -= (thirdCivInfluence - 60) / 10 + value -= (thirdCivInfluence - 30) / 10 } // Bonus for luxury resources we can get from them @@ -167,6 +171,11 @@ object NextTurnAutomation { it.resource.resourceType == ResourceType.Luxury && it.resource !in civInfo.detailedCivResources.map { supply -> supply.resource } } + + if (includeQuests) { + // Investing is better if there is an investment bonus quest active. + value += (cityState.questManager.getInvestmentMultiplier(civInfo.civName) * 10).toInt() - 10 + } return value } diff --git a/core/src/com/unciv/logic/automation/civilization/UseGoldAutomation.kt b/core/src/com/unciv/logic/automation/civilization/UseGoldAutomation.kt index 3e30ac2d70..77e4e94ba6 100644 --- a/core/src/com/unciv/logic/automation/civilization/UseGoldAutomation.kt +++ b/core/src/com/unciv/logic/automation/civilization/UseGoldAutomation.kt @@ -61,7 +61,7 @@ object UseGoldAutomation { if (civ.gold < 250 || knownCityStates.none()) return val cityState = knownCityStates .filter { it.getAllyCiv() != civ.civName } - .associateWith { NextTurnAutomation.valueCityStateAlliance(civ, it) } + .associateWith { NextTurnAutomation.valueCityStateAlliance(civ, it, true) } .maxByOrNull { it.value }?.takeIf { it.value > 0 }?.key if (cityState != null) { tryGainInfluence(civ, cityState) @@ -164,12 +164,14 @@ object UseGoldAutomation { } private fun tryGainInfluence(civInfo: Civilization, cityState: Civilization) { - if (civInfo.gold < 250) return // save up - if (cityState.getDiplomacyManager(civInfo).getInfluence() < 20) { + if (civInfo.gold < 250) return // Save up + if (cityState.getDiplomacyManager(civInfo).getInfluence() >= 20 + && civInfo.gold < 500) { + // Only make a small investment if we have a bit of influence already to build off of so we don't waste our money cityState.cityStateFunctions.receiveGoldGift(civInfo, 250) return } - if (civInfo.gold < 500) return // it's not worth it to invest now, wait until you have enough for 2 + if (civInfo.gold < 500) return // It's not worth it to invest now, wait until you have enough for 2 cityState.cityStateFunctions.receiveGoldGift(civInfo, 500) return }