mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Can't trade resources from other trades or city-states (#5252)
* can't trade resources from city-states * display untradeable sources in trade screen * Update template.properties template string * Update Swedish.properties * Spelling, better buttons
This commit is contained in:
parent
98f14523ed
commit
0bb565fdc6
@ -246,6 +246,8 @@ Our items = Våra artiklar
|
||||
Our trade offer = Vårat handelserbjudande
|
||||
[otherCiv]'s trade offer = [otherCiv]s handelserbjudande
|
||||
[otherCiv]'s items = [otherCiv]s artiklar
|
||||
+[amount] untradable copy = +[amount] ohandelsbar kopia
|
||||
+[amount] untradable copies = +[amount] ohandelsbara kopior
|
||||
Pleasure doing business with you! = Angenämt att göra affärer med er!
|
||||
I think not. = Jag skulle inte tro det.
|
||||
That is acceptable. = Det är godtagbart.
|
||||
|
@ -247,6 +247,8 @@ Our items =
|
||||
Our trade offer =
|
||||
[otherCiv]'s trade offer =
|
||||
[otherCiv]'s items =
|
||||
+[amount] untradable copy =
|
||||
+[amount] untradable copies =
|
||||
Pleasure doing business with you! =
|
||||
I think not. =
|
||||
That is acceptable. =
|
||||
|
@ -272,8 +272,24 @@ class CivilizationInfo {
|
||||
|
||||
fun getCivResources(): ResourceSupplyList {
|
||||
val newResourceSupplyList = ResourceSupplyList()
|
||||
for (resourceSupply in detailedCivResources)
|
||||
for (resourceSupply in detailedCivResources) {
|
||||
newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, "All")
|
||||
}
|
||||
return newResourceSupplyList
|
||||
}
|
||||
|
||||
// Preserves some origins for resources so we can separate them for trades
|
||||
fun getCivResourcesWithOriginsForTrade(): ResourceSupplyList {
|
||||
val newResourceSupplyList = ResourceSupplyList()
|
||||
for (resourceSupply in detailedCivResources) {
|
||||
// If we got it from another trade or from a CS, preserve the origin
|
||||
if ((resourceSupply.origin == "City-States" || resourceSupply.origin == "Trade") && resourceSupply.amount > 0) {
|
||||
newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, resourceSupply.origin)
|
||||
newResourceSupplyList.add(resourceSupply.resource, 0, "Tradable") // Still add an empty "tradable" entry so it shows up in the list
|
||||
}
|
||||
else
|
||||
newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, "Tradable")
|
||||
}
|
||||
return newResourceSupplyList
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,9 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
|
||||
offers.add(TradeOffer(Constants.openBorders, TradeType.Agreement))
|
||||
}
|
||||
|
||||
for (entry in civInfo.getCivResources()
|
||||
.filterNot { it.resource.resourceType == ResourceType.Bonus }) {
|
||||
for (entry in civInfo.getCivResourcesWithOriginsForTrade()
|
||||
.filterNot { it.resource.resourceType == ResourceType.Bonus }
|
||||
.filter { it.origin == "Tradable" } ) {
|
||||
val resourceTradeType = if (entry.resource.resourceType == ResourceType.Luxury) TradeType.Luxury_Resource
|
||||
else TradeType.Strategic_Resource
|
||||
offers.add(TradeOffer(entry.resource.name, resourceTradeType, entry.amount))
|
||||
|
@ -6,6 +6,7 @@ import com.unciv.models.metadata.GameSpeed
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.utils.Fonts
|
||||
import com.unciv.logic.trade.TradeType.TradeTypeNumberType
|
||||
import com.unciv.models.ruleset.tile.ResourceSupply
|
||||
|
||||
data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, var duration: Int = -1) {
|
||||
|
||||
@ -35,7 +36,7 @@ data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, v
|
||||
&& offer.amount == amount
|
||||
}
|
||||
|
||||
fun getOfferText(): String {
|
||||
fun getOfferText(untradable: Int = 0): String {
|
||||
var offerText = when(type){
|
||||
TradeType.WarDeclaration -> "Declare war on [$name]"
|
||||
TradeType.Introduction -> "Introduction to [$name]"
|
||||
@ -48,6 +49,12 @@ data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, v
|
||||
|
||||
if (duration > 0) offerText += "\n" + duration + Fonts.turn
|
||||
|
||||
if (untradable == 1) {
|
||||
offerText += "\n" + "+[${untradable}] untradable copy".tr()
|
||||
} else if (untradable > 1) {
|
||||
offerText += "\n" + "+[${untradable}] untradable copies".tr()
|
||||
}
|
||||
|
||||
return offerText
|
||||
}
|
||||
}
|
||||
|
@ -71,10 +71,12 @@ class OfferColumnsTable(private val tradeLogic: TradeLogic, val screen: Diplomac
|
||||
fun update() {
|
||||
val ourFilteredOffers = tradeLogic.ourAvailableOffers.without(tradeLogic.currentTrade.ourOffers)
|
||||
val theirFilteredOffers = tradeLogic.theirAvailableOffers.without(tradeLogic.currentTrade.theirOffers)
|
||||
ourAvailableOffersTable.update(ourFilteredOffers, tradeLogic.theirAvailableOffers)
|
||||
val ourUntradables = tradeLogic.ourCivilization.getCivResourcesWithOriginsForTrade().filterNot { it.origin == "Tradable" }
|
||||
val theirUntradables = tradeLogic.otherCivilization.getCivResourcesWithOriginsForTrade().filterNot { it.origin == "Tradable" }
|
||||
ourAvailableOffersTable.update(ourFilteredOffers, tradeLogic.theirAvailableOffers, ourUntradables)
|
||||
ourOffersTable.update(tradeLogic.currentTrade.ourOffers, tradeLogic.theirAvailableOffers)
|
||||
theirOffersTable.update(tradeLogic.currentTrade.theirOffers, tradeLogic.ourAvailableOffers)
|
||||
theirAvailableOffersTable.update(theirFilteredOffers, tradeLogic.ourAvailableOffers)
|
||||
theirAvailableOffersTable.update(theirFilteredOffers, tradeLogic.ourAvailableOffers, theirUntradables)
|
||||
}
|
||||
|
||||
private fun openGoldSelectionPopup(offer: TradeOffer, ourOffers: TradeOffersList, maxGold: Int) {
|
||||
|
@ -8,6 +8,7 @@ import com.unciv.logic.trade.TradeOffer
|
||||
import com.unciv.logic.trade.TradeOffersList
|
||||
import com.unciv.logic.trade.TradeType
|
||||
import com.unciv.logic.trade.TradeType.*
|
||||
import com.unciv.models.ruleset.tile.ResourceSupply
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.utils.*
|
||||
import kotlin.math.min
|
||||
@ -30,8 +31,9 @@ class OffersListScroll(
|
||||
/**
|
||||
* @param offersToDisplay The offers which should be displayed as buttons
|
||||
* @param otherOffers The list of other side's offers to compare with whether these offers are unique
|
||||
* @param untradableOffers Things we got from sources that we can't trade on, displayed for completeness
|
||||
*/
|
||||
fun update(offersToDisplay:TradeOffersList, otherOffers: TradeOffersList) {
|
||||
fun update(offersToDisplay:TradeOffersList, otherOffers: TradeOffersList, untradableOffers: List<ResourceSupply> = emptyList()) {
|
||||
table.clear()
|
||||
expanderTabs.clear()
|
||||
|
||||
@ -64,7 +66,7 @@ class OffersListScroll(
|
||||
}
|
||||
|
||||
for (offer in offersOfType) {
|
||||
val tradeButton = offer.getOfferText().toTextButton()
|
||||
val tradeButton = offer.getOfferText(untradableOffers.filter { it.resource.name == offer.name }.sumOf { it.amount }).toTextButton()
|
||||
val amountPerClick =
|
||||
if (offer.type == Gold) 50
|
||||
else 1
|
||||
@ -86,7 +88,8 @@ class OffersListScroll(
|
||||
|
||||
if (expanderTabs.containsKey(offerType))
|
||||
expanderTabs[offerType]!!.innerTable.add(tradeButton).row()
|
||||
else table.add(tradeButton).row()
|
||||
else
|
||||
table.add(tradeButton).row()
|
||||
}
|
||||
}
|
||||
actor = table
|
||||
|
Loading…
x
Reference in New Issue
Block a user