Rudimentary AI control over goldPercentConvertedToScience (#6221)

This commit is contained in:
SomeTroglodyte
2022-02-24 13:36:41 +01:00
committed by GitHub
parent 6babefd3ae
commit 261e09e336
2 changed files with 21 additions and 1 deletions

View File

@ -71,6 +71,21 @@ object NextTurnAutomation {
tryVoteForDiplomaticVictory(civInfo)
}
fun automateGoldToSciencePercentage(civInfo: CivilizationInfo) {
// Don't let the AI run blindly with the default convert-gold-to-science ratio if that option is enabled
val estimatedIncome = civInfo.statsForNextTurn.gold.toInt()
val projectedGold = civInfo.gold + estimatedIncome
// TODO: some cleverness, this is just wild guessing.
val pissPoor = civInfo.tech.era.baseUnitBuyCost
val stinkingRich = civInfo.tech.era.startingGold * 10 + civInfo.cities.size * 2 * pissPoor
val maxPercent = 0.8f
civInfo.tech.goldPercentConvertedToScience = when {
civInfo.gold <= 0 -> 0f
projectedGold <= pissPoor -> 0f
else -> ((projectedGold - pissPoor) * maxPercent / stinkingRich).coerceAtMost(maxPercent)
}
}
private fun respondToTradeRequests(civInfo: CivilizationInfo) {
for (tradeRequest in civInfo.tradeRequests.toList()) {
val otherCiv = civInfo.gameInfo.getCivilization(tradeRequest.requestingCiv)

View File

@ -5,6 +5,7 @@ import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.GameInfo
import com.unciv.logic.UncivShowableException
import com.unciv.logic.automation.NextTurnAutomation
import com.unciv.logic.automation.WorkerAutomation
import com.unciv.logic.city.CityInfo
import com.unciv.logic.civilization.RuinsManager.RuinsManager
@ -792,6 +793,10 @@ class CivilizationInfo {
attacksSinceTurnStart.clear()
updateStatsForNextTurn() // for things that change when turn passes e.g. golden age, city state influence
// Do this after updateStatsForNextTurn but before cities.startTurn
if (playerType == PlayerType.AI && gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.convertGoldToScience))
NextTurnAutomation.automateGoldToSciencePercentage(this)
// Generate great people at the start of the turn,
// so they won't be generated out in the open and vulnerable to enemy attacks before you can control them
if (cities.isNotEmpty()) { //if no city available, addGreatPerson will throw exception