mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 03:23:17 -04:00
Resolved #12245 - Cannot have 2 research agreements at once due to counteroffers
This commit is contained in:
parent
f65f869836
commit
a905ddebcb
@ -42,11 +42,15 @@ object Constants {
|
||||
|
||||
const val barbarianEncampment = "Barbarian encampment"
|
||||
const val cityCenter = "City center"
|
||||
|
||||
|
||||
// Treaties
|
||||
const val peaceTreaty = "Peace Treaty"
|
||||
const val researchAgreement = "Research Agreement"
|
||||
const val openBorders = "Open Borders"
|
||||
const val defensivePact = "Defensive Pact"
|
||||
|
||||
// Agreements
|
||||
const val openBorders = "Open Borders"
|
||||
|
||||
/** Used as origin in StatMap or ResourceSupplyList, or the toggle button in DiplomacyOverviewTab */
|
||||
const val cityStates = "City-States"
|
||||
/** Used as origin in ResourceSupplyList */
|
||||
@ -105,7 +109,7 @@ object Constants {
|
||||
const val defaultSkin = "Minimal"
|
||||
|
||||
/**
|
||||
* Use this to determine whether a [MapUnit][com.unciv.logic.map.MapUnit]'s movement is exhausted
|
||||
* Use this to determine whether a [MapUnit][com.unciv.logic.map.mapunit.MapUnit]'s movement is exhausted
|
||||
* (currentMovement <= this) if and only if a fuzzy comparison is needed to account for Float rounding errors.
|
||||
* _Most_ checks do compare to 0!
|
||||
*/
|
||||
|
@ -117,7 +117,7 @@ object DiplomacyAutomation {
|
||||
&& it.hasUnique(UniqueType.EnablesOpenBorders)
|
||||
&& !civInfo.getDiplomacyManager(it)!!.hasOpenBorders
|
||||
&& !civInfo.getDiplomacyManager(it)!!.hasFlag(DiplomacyFlags.DeclinedOpenBorders)
|
||||
&& !isTradeBeingOffered(civInfo, it, Constants.openBorders)
|
||||
&& !areWeOfferingTrade(civInfo, it, Constants.openBorders)
|
||||
}.sortedByDescending { it.getDiplomacyManager(civInfo)!!.relationshipLevel() }.toList()
|
||||
|
||||
for (otherCiv in civsThatWeCanOpenBordersWith) {
|
||||
@ -159,7 +159,7 @@ object DiplomacyAutomation {
|
||||
.filter {
|
||||
civInfo.diplomacyFunctions.canSignResearchAgreementsWith(it)
|
||||
&& !civInfo.getDiplomacyManager(it)!!.hasFlag(DiplomacyFlags.DeclinedResearchAgreement)
|
||||
&& !isTradeBeingOffered(civInfo, it, Constants.researchAgreement)
|
||||
&& !areWeOfferingTrade(civInfo, it, Constants.researchAgreement)
|
||||
}
|
||||
.sortedByDescending { it.stats.statsForNextTurn.science }
|
||||
|
||||
@ -183,7 +183,7 @@ object DiplomacyAutomation {
|
||||
civInfo.diplomacyFunctions.canSignDefensivePactWith(it)
|
||||
&& !civInfo.getDiplomacyManager(it)!!.hasFlag(DiplomacyFlags.DeclinedDefensivePact)
|
||||
&& civInfo.getDiplomacyManager(it)!!.opinionOfOtherCiv() < 70f * civInfo.getPersonality().inverseModifierFocus(PersonalityValue.Aggressive, .2f)
|
||||
&& !isTradeBeingOffered(civInfo, it, Constants.defensivePact)
|
||||
&& !areWeOfferingTrade(civInfo, it, Constants.defensivePact)
|
||||
}
|
||||
|
||||
for (otherCiv in canSignDefensivePactCiv) {
|
||||
@ -370,10 +370,9 @@ object DiplomacyAutomation {
|
||||
}
|
||||
}
|
||||
|
||||
private fun isTradeBeingOffered(civInfo: Civilization, otherCiv: Civilization, offerName: String): Boolean {
|
||||
return civInfo.tradeRequests.filter { request -> request.requestingCiv == otherCiv.civName }
|
||||
.any { trade -> trade.trade.ourOffers.any { offer -> offer.name == offerName } }
|
||||
|| civInfo.tradeRequests.filter { request -> request.requestingCiv == otherCiv.civName }
|
||||
.any { trade -> trade.trade.theirOffers.any { offer -> offer.name == offerName } }
|
||||
private fun areWeOfferingTrade(civInfo: Civilization, otherCiv: Civilization, offerName: String): Boolean {
|
||||
return otherCiv.tradeRequests.filter { request -> request.requestingCiv == civInfo.civName }
|
||||
.any { trade -> trade.trade.ourOffers.any { offer -> offer.name == offerName }
|
||||
|| trade.trade.theirOffers.any { offer -> offer.name == offerName } }
|
||||
}
|
||||
}
|
||||
|
@ -54,10 +54,12 @@ object NextTurnAutomation {
|
||||
if (civInfo.gameInfo.isReligionEnabled()) {
|
||||
ReligionAutomation.spendFaithOnReligion(civInfo)
|
||||
}
|
||||
|
||||
DiplomacyAutomation.offerOpenBorders(civInfo)
|
||||
DiplomacyAutomation.offerResearchAgreement(civInfo)
|
||||
DiplomacyAutomation.offerDefensivePact(civInfo)
|
||||
TradeAutomation.exchangeLuxuries(civInfo)
|
||||
|
||||
issueRequests(civInfo)
|
||||
adoptPolicy(civInfo) // todo can take a second - why?
|
||||
freeUpSpaceResources(civInfo)
|
||||
|
@ -48,7 +48,16 @@ class TradeEvaluation {
|
||||
return when (tradeOffer.type) {
|
||||
TradeOfferType.Gold -> true // even if they go negative it's okay
|
||||
TradeOfferType.Gold_Per_Turn -> true // even if they go negative it's okay
|
||||
TradeOfferType.Treaty -> true
|
||||
TradeOfferType.Treaty -> {
|
||||
// Current automation should prevent these from being offered anyway,
|
||||
// these are a safeguard against future automation changes
|
||||
when (tradeOffer.name) {
|
||||
Constants.peaceTreaty -> offerer.isAtWarWith(tradePartner)
|
||||
Constants.researchAgreement -> !offerer.getDiplomacyManager(tradePartner)!!.hasFlag(DiplomacyFlags.ResearchAgreement)
|
||||
Constants.defensivePact -> !offerer.getDiplomacyManager(tradePartner)!!.hasFlag(DiplomacyFlags.DefensivePact)
|
||||
else -> true // potentional future treaties
|
||||
}
|
||||
}
|
||||
TradeOfferType.Agreement -> true
|
||||
TradeOfferType.Luxury_Resource -> hasResource(tradeOffer)
|
||||
TradeOfferType.Strategic_Resource -> hasResource(tradeOffer)
|
||||
|
Loading…
x
Reference in New Issue
Block a user