Simplified research agreement logic

This commit is contained in:
Yair Morgenstern 2020-01-25 21:21:06 +02:00
parent 925f3267ad
commit 5a6b5e5db3
4 changed files with 25 additions and 33 deletions

View File

@ -313,7 +313,7 @@ class NextTurnAutomation{
}
private fun offerDeclarationOfFriendship(civInfo: CivilizationInfo) {
val canDeclareFriendshipCiv = civInfo.getKnownCivs()
val civsThatWeCanDeclareFriendshipWith = civInfo.getKnownCivs()
.asSequence()
.filter { it.isMajorCiv() }
.filter { !it.isAtWarWith(civInfo) }
@ -321,48 +321,37 @@ class NextTurnAutomation{
.filter { !civInfo.getDiplomacyManager(it).hasFlag(DiplomacyFlags.DeclarationOfFriendship) }
.filter { !civInfo.getDiplomacyManager(it).hasFlag(DiplomacyFlags.Denunceation) }
.sortedByDescending { it.getDiplomacyManager(civInfo).relationshipLevel() }
.toList()
for (civ in canDeclareFriendshipCiv) {
for (civ in civsThatWeCanDeclareFriendshipWith) {
// Default setting is 5, this will be changed according to different civ.
if ((1..10).random()<=5) civInfo.getDiplomacyManager(civ).signDeclarationOfFriendship()
else continue
if ((1..10).random()<=5)
civInfo.getDiplomacyManager(civ).signDeclarationOfFriendship()
}
}
private fun offerResearchAgreement(civInfo: CivilizationInfo) {
// if Civ has researched future tech, they will not want to sign RA.
if (civInfo.tech.getTechUniques().contains("Enables Research agreements")
&& civInfo.gold >= civInfo.goldCostOfSignResearchAgreement()
&& civInfo.gameInfo.ruleSet.technologies.values.any { !civInfo.tech.isResearched(it.name) && civInfo.tech.canBeResearched(it.name) }){
if (civInfo.canSignResearchAgreement()){
val canSignResearchAgreementCiv = civInfo.getKnownCivs()
.asSequence()
.filter { it.isMajorCiv() }
.filter { civInfo.getDiplomacyManager(it).hasFlag(DiplomacyFlags.DeclarationOfFriendship) }
.filter { !civInfo.getDiplomacyManager(it).hasFlag(DiplomacyFlags.ResearchAgreement) }
.filter { !it.getDiplomacyManager(civInfo).hasFlag(DiplomacyFlags.ResearchAgreement) }
.filter { it.tech.getTechUniques().contains("Enables Research agreements") }
.filter { it.gold >= civInfo.goldCostOfSignResearchAgreement() }
.filter { it.canSignResearchAgreement() }
.sortedByDescending { it.statsForNextTurn.science }
.toList()
val duration = when(civInfo.gameInfo.gameParameters.gameSpeed) {
GameSpeed.Quick -> 25
GameSpeed.Standard -> 30
GameSpeed.Epic -> 45
}
for (otherCiv in canSignResearchAgreementCiv) {
// if otherCiv has researched future tech, they will not want to sign RA.
if (otherCiv.gameInfo.ruleSet.technologies.values.none { !otherCiv.tech.isResearched(it.name) && otherCiv.tech.canBeResearched(it.name) })
continue
// Default setting is 5, this will be changed according to different civ.
if ((1..10).random()<=5
&& civInfo.gold >= civInfo.goldCostOfSignResearchAgreement()) {
if ((1..10).random()<=5) {
val tradeLogic = TradeLogic(civInfo, otherCiv)
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, duration, civInfo.goldCostOfSignResearchAgreement()))
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, duration, civInfo.goldCostOfSignResearchAgreement()))
if (otherCiv.isPlayerCivilization())
otherCiv.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse()))
// Default setting is 5, this will be changed according to different civ.
else if ((1..10).random()<=5) tradeLogic.acceptTrade()
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, duration, civInfo.getResearchAgreementCost()))
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, duration, civInfo.getResearchAgreementCost()))
otherCiv.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse()))
}
}
}

View File

@ -24,7 +24,6 @@ import com.unciv.models.ruleset.tile.ResourceSupplyList
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.stats.Stats
import com.unciv.models.translations.tr
import com.unciv.ui.VictoryScreen
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
@ -308,6 +307,14 @@ class CivilizationInfo {
else leaderName += " (" + "Human".tr() + " - " + "Multiplayer".tr() + ")"
return leaderName
}
fun canSignResearchAgreement(): Boolean {
if(!tech.getTechUniques().contains("Enables Research agreements")) return false
if(gold < getResearchAgreementCost()) return false
if (gameInfo.ruleSet.technologies.values
.none { tech.canBeResearched(it.name) && !tech.isResearched(it.name) }) return false
return true
}
//endregion
//region state-changing functions
@ -495,7 +502,7 @@ class CivilizationInfo {
updateStatsForNextTurn()
}
fun goldCostOfSignResearchAgreement(): Int {
fun getResearchAgreementCost(): Int {
// https://forums.civfanatics.com/resources/research-agreements-bnw.25568/
val basicGoldCostOfSignResearchAgreement = when(getEra()){
TechEra.Medieval, TechEra.Renaissance -> 250

View File

@ -542,5 +542,6 @@ class DiplomacyManager() {
otherCiv().addNotification("[${civInfo.civName}] refused to stop settling cities near us!", Color.MAROON)
}
//endregion
}

View File

@ -21,7 +21,6 @@ import com.unciv.logic.trade.TradeType
import com.unciv.models.metadata.GameSpeed
import com.unciv.models.translations.tr
import com.unciv.ui.utils.*
import com.unciv.ui.utils.YesNoPopup
import kotlin.math.roundToInt
class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
@ -233,12 +232,8 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
if(diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)
&& !diplomacyManager.hasFlag(DiplomacyFlags.ResearchAgreement)
&& !otherCivDiplomacyManager.hasFlag(DiplomacyFlags.ResearchAgreement)
&& viewingCiv.tech.getTechUniques().contains("Enables Research agreements")
&& otherCiv.tech.getTechUniques().contains("Enables Research agreements")
&& viewingCiv.gold >= viewingCiv.goldCostOfSignResearchAgreement()
&& otherCiv.gold >= viewingCiv.goldCostOfSignResearchAgreement()
&& viewingCiv.gameInfo.ruleSet.technologies.values.any { !viewingCiv.tech.isResearched(it.name) && viewingCiv.tech.canBeResearched(it.name) }
&& otherCiv.gameInfo.ruleSet.technologies.values.any { !otherCiv.tech.isResearched(it.name) && otherCiv.tech.canBeResearched(it.name) }){
&& viewingCiv.canSignResearchAgreement()
&& otherCiv.canSignResearchAgreement()){
val researchAgreementButton = TextButton("Research Agreement".tr(),skin)
researchAgreementButton.onClick {
val tradeTable = setTrade(otherCiv)
@ -247,8 +242,8 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
GameSpeed.Standard -> 30
GameSpeed.Epic -> 45
}
val researchAgreement = TradeOffer(Constants.researchAgreement, TradeType.Treaty, duration, viewingCiv.goldCostOfSignResearchAgreement())
val goldCostOfSignResearchAgreement = TradeOffer("Gold".tr(), TradeType.Gold, 0, -viewingCiv.goldCostOfSignResearchAgreement())
val researchAgreement = TradeOffer(Constants.researchAgreement, TradeType.Treaty, duration, viewingCiv.getResearchAgreementCost())
val goldCostOfSignResearchAgreement = TradeOffer("Gold".tr(), TradeType.Gold, 0, -viewingCiv.getResearchAgreementCost())
tradeTable.tradeLogic.currentTrade.theirOffers.add(researchAgreement)
tradeTable.tradeLogic.ourAvailableOffers.add(researchAgreement)
tradeTable.tradeLogic.ourAvailableOffers.add(goldCostOfSignResearchAgreement)