mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 23:10:39 -04:00
Invalid trade requests (e.g. giving a city that isn't yours anymore or resources you no longer own) are discarded at the beginning of the civ's turn
This commit is contained in:
parent
7603d3c839
commit
9e0ba99c0a
@ -184,7 +184,7 @@
|
|||||||
Simplified_Chinese:"我们遇到了城邦--[name]!"
|
Simplified_Chinese:"我们遇到了城邦--[name]!"
|
||||||
Russian:"Мы обнаружили город-государство [name]!"
|
Russian:"Мы обнаружили город-государство [name]!"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Friendship declaration flavor texts
|
// Friendship declaration flavor texts
|
||||||
"Declare Friendship ([numberOfTurns] turns)":{
|
"Declare Friendship ([numberOfTurns] turns)":{
|
||||||
Italian:"Dichiarazione di Amicizia ([numberOfTurns] turni)"
|
Italian:"Dichiarazione di Amicizia ([numberOfTurns] turni)"
|
||||||
|
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.app"
|
applicationId "com.unciv.app"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 295
|
versionCode 296
|
||||||
versionName "3.0.2"
|
versionName "3.0.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Had to add this crap for Travis to build, it wanted to sign the app
|
// Had to add this crap for Travis to build, it wanted to sign the app
|
||||||
|
@ -12,6 +12,7 @@ import com.unciv.logic.civilization.diplomacy.DiplomacyManager
|
|||||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||||
import com.unciv.logic.map.MapUnit
|
import com.unciv.logic.map.MapUnit
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
|
import com.unciv.logic.trade.TradeEvaluation
|
||||||
import com.unciv.logic.trade.TradeRequest
|
import com.unciv.logic.trade.TradeRequest
|
||||||
import com.unciv.models.gamebasics.*
|
import com.unciv.models.gamebasics.*
|
||||||
import com.unciv.models.gamebasics.tech.TechEra
|
import com.unciv.models.gamebasics.tech.TechEra
|
||||||
@ -56,6 +57,8 @@ class CivilizationInfo {
|
|||||||
var diplomacy = HashMap<String, DiplomacyManager>()
|
var diplomacy = HashMap<String, DiplomacyManager>()
|
||||||
var notifications = ArrayList<Notification>()
|
var notifications = ArrayList<Notification>()
|
||||||
val popupAlerts = ArrayList<PopupAlert>()
|
val popupAlerts = ArrayList<PopupAlert>()
|
||||||
|
|
||||||
|
//** for trades here, ourOffers is the current civ's offers, and theirOffers is what the requesting civ offers */
|
||||||
val tradeRequests = ArrayList<TradeRequest>()
|
val tradeRequests = ArrayList<TradeRequest>()
|
||||||
|
|
||||||
// if we only use lists, and change the list each time the cities are changed,
|
// if we only use lists, and change the list each time the cities are changed,
|
||||||
@ -332,6 +335,14 @@ class CivilizationInfo {
|
|||||||
for (city in cities) city.startTurn()
|
for (city in cities) city.startTurn()
|
||||||
|
|
||||||
getCivUnits().toList().forEach { it.startTurn() }
|
getCivUnits().toList().forEach { it.startTurn() }
|
||||||
|
|
||||||
|
for(tradeRequest in tradeRequests.toList()) { // remove trade requests where one of the sides can no longer supply
|
||||||
|
val offeringCiv = gameInfo.getCivilization(tradeRequest.requestingCiv)
|
||||||
|
if (offeringCiv.isDefeated() || !TradeEvaluation().isTradeValid(tradeRequest.trade,this, offeringCiv)) {
|
||||||
|
tradeRequests.remove(tradeRequest)
|
||||||
|
offeringCiv.addNotification("Our proposed trade is no longer relevant!", Color.GOLD)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun endTurn() {
|
fun endTurn() {
|
||||||
|
@ -11,6 +11,38 @@ import kotlin.math.min
|
|||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
class TradeEvaluation{
|
class TradeEvaluation{
|
||||||
|
|
||||||
|
fun isTradeValid(trade:Trade, offerer:CivilizationInfo, tradePartner: CivilizationInfo): Boolean {
|
||||||
|
for(offer in trade.ourOffers)
|
||||||
|
if(!isOfferValid(offer,offerer))
|
||||||
|
return false
|
||||||
|
for(offer in trade.theirOffers)
|
||||||
|
if(!isOfferValid(offer,tradePartner))
|
||||||
|
return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isOfferValid(tradeOffer: TradeOffer, offerer:CivilizationInfo): Boolean {
|
||||||
|
|
||||||
|
fun hasResource(tradeOffer: TradeOffer): Boolean {
|
||||||
|
val resourcesByName = offerer.getCivResourcesByName()
|
||||||
|
return resourcesByName.containsKey(tradeOffer.name) && resourcesByName[tradeOffer.name]!! >= tradeOffer.amount
|
||||||
|
}
|
||||||
|
|
||||||
|
when(tradeOffer.type){
|
||||||
|
TradeType.Gold -> return true // even if they go negative it's okay
|
||||||
|
TradeType.Gold_Per_Turn -> return true // even if they go negative it's okay
|
||||||
|
TradeType.Treaty -> return true
|
||||||
|
TradeType.Agreement -> return true
|
||||||
|
TradeType.Luxury_Resource -> return hasResource(tradeOffer)
|
||||||
|
TradeType.Strategic_Resource -> return hasResource(tradeOffer)
|
||||||
|
TradeType.Technology -> return true
|
||||||
|
TradeType.Introduction -> return true
|
||||||
|
TradeType.WarDeclaration -> return true
|
||||||
|
TradeType.City -> return offerer.cities.any { it.name==tradeOffer.name }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun isTradeAcceptable(trade: Trade, evaluator: CivilizationInfo, tradePartner: CivilizationInfo): Boolean {
|
fun isTradeAcceptable(trade: Trade, evaluator: CivilizationInfo, tradePartner: CivilizationInfo): Boolean {
|
||||||
var sumOfTheirOffers = trade.theirOffers.asSequence()
|
var sumOfTheirOffers = trade.theirOffers.asSequence()
|
||||||
.filter { it.type!= TradeType.Treaty } // since treaties should only be evaluated once for 2 sides
|
.filter { it.type!= TradeType.Treaty } // since treaties should only be evaluated once for 2 sides
|
||||||
|
Loading…
x
Reference in New Issue
Block a user