From fa8e8a148d80e4fc0bfa2dfc506e1128ebcfdfef Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 30 Jul 2018 21:34:31 +0300 Subject: [PATCH] Can now trade technologies! AI assessment of luxury resources improved --- .../unciv/logic/map/UnitMovementAlgorithms.kt | 10 +++ core/src/com/unciv/ui/TradeScreen.kt | 65 ++++++++++++------- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index e0de338537..87c2ae677a 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -167,4 +167,14 @@ class UnitMovementAlgorithms(val unit:MapUnit) { throw Exception("We couldn't get the path between the two tiles") } +// fun moveToClosestMoveableTile(){ +// val unitCurrentTile = unit.getTile() +// var allowedTile:TileInfo? = null +// var distance=0 +// while(allowedTile==null){ +// distance++ +// allowedTile = tileMap.tilesat +// } +// } + } \ No newline at end of file diff --git a/core/src/com/unciv/ui/TradeScreen.kt b/core/src/com/unciv/ui/TradeScreen.kt index 8421254945..18c75d08ba 100644 --- a/core/src/com/unciv/ui/TradeScreen.kt +++ b/core/src/com/unciv/ui/TradeScreen.kt @@ -12,6 +12,7 @@ import com.unciv.logic.trade.TradeType import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tile.ResourceType import com.unciv.ui.utils.* +import kotlin.math.sqrt data class TradeOffer(var name:String, var type: TradeType, var duration:Int, var amount:Int) { @@ -78,25 +79,27 @@ class TradeScreen(val otherCivilization: CivilizationInfo) : CameraStageBaseScre otherCivilization.diplomacy[civInfo.civName]!!.trades.add(currentTrade.reverse()) // instant transfers - for(offer in currentTrade.theirOffers){ - if(offer.type== TradeType.Gold){ - civInfo.gold += offer.amount - otherCivilization.gold -= offer.amount - } - if(offer.type== TradeType.Technology){ - civInfo.tech.techsResearched.add(offer.name) - } - } - for(offer in currentTrade.ourOffers){ - if(offer.type== TradeType.Gold){ - civInfo.gold -= offer.amount - otherCivilization.gold += offer.amount - } - if(offer.type== TradeType.Technology){ - otherCivilization.tech.techsResearched.add(offer.name) + fun transfer(us: CivilizationInfo,them:CivilizationInfo, trade: Trade) { + for (offer in trade.theirOffers) { + if (offer.type == TradeType.Gold) { + us.gold += offer.amount + them.gold -= offer.amount + } + if (offer.type == TradeType.Technology) { + us.tech.techsResearched.add(offer.name) + } + if(offer.type==TradeType.City){ + val city = them.cities.first { it.name==offer.name } + us.cities.add(city) + them.cities.remove(city) + + } } } + transfer(civInfo,otherCivilization,currentTrade) + transfer(otherCivilization,civInfo,currentTrade.reverse()) + val newTradeScreen = TradeScreen(otherCivilization) newTradeScreen.tradeText.setText("Pleasure doing business with you!".tr()) UnCivGame.Current.screen = newTradeScreen @@ -147,6 +150,8 @@ class TradeScreen(val otherCivilization: CivilizationInfo) : CameraStageBaseScre } offers.add(TradeOffer("Gold".tr(), TradeType.Gold,0,civInfo.gold)) offers.add(TradeOffer("Gold per turn".tr(), TradeType.Gold_Per_Turn,30,civInfo.getStatsForNextTurn().gold.toInt())) +// for(city in civInfo.cities.filterNot { it.isCapital() }) +// offers.add(TradeOffer(city.name,TradeType.City,0,1)) return offers } @@ -161,14 +166,30 @@ class TradeScreen(val otherCivilization: CivilizationInfo) : CameraStageBaseScre TradeType.Gold -> return offer.amount TradeType.Gold_Per_Turn -> return offer.amount*offer.duration TradeType.Luxury_Resource -> { - var value = 350*offer.amount - if(!theirAvailableOffers.any { it.name==offer.name } && otherCivIsRecieving) // We want to take away their last luxury or give them one they don't have - value += 400 - return value + if(!otherCivIsRecieving){ // they're giving us + var value = 300*offer.amount + if(!theirAvailableOffers.any { it.name==offer.name }) // We want to take away their last luxury or give them one they don't have + value += 400 + return value + } + else{ + var value = 50*offer.amount // 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 + return value + } + } - TradeType.Technology -> return GameBasics.Technologies[offer.name]!!.cost // gold cost is science cost + TradeType.Technology -> return sqrt(GameBasics.Technologies[offer.name]!!.cost.toDouble()).toInt()*10 // gold cost is science cost TradeType.Strategic_Resource -> return 50 * offer.amount - // Dunno what this is? + TradeType.City -> { + val civ = if(otherCivIsRecieving) civInfo else otherCivilization + val city = civ.cities.first { it.name==offer.name } + val stats = city.cityStats.currentCityStats + val sumOfStats = stats.culture+stats.gold+stats.science+stats.production+stats.happiness+stats.food + return sumOfStats.toInt() * 10 + } + // Dunno what this is? else -> return 1000 } }