From d3a4952fefe4261c654ffd5b901e9b08b459f595 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 12 Nov 2018 09:47:43 +0200 Subject: [PATCH] AI will only pay for extra luxuries if it can trade them away --- android/build.gradle | 4 ++-- core/src/com/unciv/logic/trade/TradeLogic.kt | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 38c46979..6ae6f9c4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.game" minSdkVersion 14 targetSdkVersion 26 - versionCode 157 - versionName "2.9.9" + versionCode 158 + versionName "2.9.10" } buildTypes { release { diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index 4d98f793..91a9836b 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -6,6 +6,7 @@ import com.unciv.logic.civilization.DiplomaticStatus import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tile.ResourceType import com.unciv.ui.utils.tr +import kotlin.math.min import kotlin.math.sqrt class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: CivilizationInfo){ @@ -64,12 +65,22 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci return value } else{ - var value = 50*offer.amount // they'll buy at 50 each only, and that's so they can trade it away + val civsWhoWillTradeUsForTheLux = ourCivilization.diplomacy.values.map { it.civInfo } + .filter { it!= otherCivilization } + .filter { it.getCivResources().keys.none { it.name==offer.name } } //they don't have + val ourResourceNames = ourCivilization.getCivResources().map { it.key.name } + val civsWithLuxToTrade = civsWhoWillTradeUsForTheLux.filter { + it.getCivResources().any { + it.value > 1 && it.key.resourceType == ResourceType.Luxury //they have a lux we don't and will be willing to trade it + && !ourResourceNames.contains(it.key.name) + } + } + + var value = 50*min(offer.amount,civsWithLuxToTrade.size) // they'll buy at 50 each only, and that's so they can trade it away if(!theirAvailableOffers.any { it.name==offer.name }) - value+=250 // only if they're lacking will they buy the first one at 300 + value+=300 // only if they're lacking will they buy the first one at 300 return value } - } TradeType.Technology -> return sqrt(GameBasics.Technologies[offer.name]!!.cost.toDouble()).toInt()*10 TradeType.Strategic_Resource -> {