Can now disable diplomatic relationship changes in a mod

This commit is contained in:
Yair Morgenstern 2020-08-20 16:38:14 +03:00
parent acf803de28
commit 42b5b3f16c
4 changed files with 45 additions and 27 deletions

View file

@ -11,6 +11,8 @@ import com.unciv.logic.civilization.diplomacy.RelationshipLevel
import com.unciv.logic.map.BFS
import com.unciv.logic.map.MapUnit
import com.unciv.logic.trade.*
import com.unciv.models.ruleset.ModOptions
import com.unciv.models.ruleset.ModOptionsConstants
import com.unciv.models.ruleset.VictoryType
import com.unciv.models.ruleset.tech.Technology
import com.unciv.models.translations.tr
@ -26,9 +28,11 @@ object NextTurnAutomation{
respondToTradeRequests(civInfo)
if(civInfo.isMajorCiv()) {
declareWar(civInfo)
if(!civInfo.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)) {
declareWar(civInfo)
// offerDeclarationOfFriendship(civInfo)
offerPeaceTreaty(civInfo)
offerPeaceTreaty(civInfo)
}
offerResearchAgreement(civInfo)
exchangeLuxuries(civInfo)
issueRequests(civInfo)

View file

@ -4,6 +4,7 @@ import com.unciv.Constants
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
import com.unciv.models.ruleset.ModOptionsConstants
import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.translations.tr
@ -52,7 +53,8 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
offers.add(TradeOffer(thirdCiv.civName, TradeType.Introduction))
}
if (!civInfo.isCityState() && !otherCivilization.isCityState()) {
if (!civInfo.isCityState() && !otherCivilization.isCityState()
&& !civInfo.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)) {
val civsWeBothKnow = otherCivsWeKnow
.filter { otherCivilization.diplomacy.containsKey(it.civName) }
val civsWeArentAtWarWith = civsWeBothKnow

View file

@ -19,11 +19,16 @@ import com.unciv.models.ruleset.unit.Promotion
import com.unciv.models.stats.INamed
import kotlin.collections.set
object ModOptionsConstants {
const val diplomaticRelationshipsCannotChange = "Diplomatic relationships cannot change"
}
class ModOptions {
var isBaseRuleset = false
var techsToRemove = HashSet<String>()
var buildingsToRemove = HashSet<String>()
var unitsToRemove = HashSet<String>()
var uniques = HashSet<String>()
}
class Ruleset {

View file

@ -17,6 +17,7 @@ import com.unciv.logic.civilization.diplomacy.RelationshipLevel
import com.unciv.logic.trade.TradeLogic
import com.unciv.logic.trade.TradeOffer
import com.unciv.logic.trade.TradeType
import com.unciv.models.ruleset.ModOptionsConstants
import com.unciv.models.translations.tr
import com.unciv.ui.utils.*
import kotlin.math.roundToInt
@ -146,26 +147,28 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
if (viewingCiv.isAtWarWith(otherCiv)) {
val peaceButton = "Negotiate Peace".toTextButton()
peaceButton.onClick {
YesNoPopup("Peace with [${otherCiv.civName}]?".tr(), {
val tradeLogic = TradeLogic(viewingCiv, otherCiv)
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty))
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty))
tradeLogic.acceptTrade()
updateLeftSideTable()
updateRightSide(otherCiv)
}, this).open()
if(!viewingCiv.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)) {
if (viewingCiv.isAtWarWith(otherCiv)) {
val peaceButton = "Negotiate Peace".toTextButton()
peaceButton.onClick {
YesNoPopup("Peace with [${otherCiv.civName}]?".tr(), {
val tradeLogic = TradeLogic(viewingCiv, otherCiv)
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty))
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty))
tradeLogic.acceptTrade()
updateLeftSideTable()
updateRightSide(otherCiv)
}, this).open()
}
diplomacyTable.add(peaceButton).row()
val cityStatesAlly = otherCiv.getAllyCiv()
val atWarWithItsAlly = viewingCiv.getKnownCivs().any { it.civName == cityStatesAlly && it.isAtWarWith(viewingCiv) }
if (isNotPlayersTurn() || atWarWithItsAlly) peaceButton.disable()
} else {
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv)
if (isNotPlayersTurn()) declareWarButton.disable()
diplomacyTable.add(declareWarButton).row()
}
diplomacyTable.add(peaceButton).row()
val cityStatesAlly = otherCiv.getAllyCiv()
val atWarWithItsAlly = viewingCiv.getKnownCivs().any { it.civName == cityStatesAlly && it.isAtWarWith(viewingCiv) }
if (isNotPlayersTurn() || atWarWithItsAlly) peaceButton.disable()
} else {
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv)
if (isNotPlayersTurn()) declareWarButton.disable()
diplomacyTable.add(declareWarButton).row()
}
return diplomacyTable
@ -184,6 +187,8 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
diplomacyTable.add(otherCiv.nation.neutralHello.toLabel()).row()
diplomacyTable.addSeparator()
val diplomaticRelationshipsCanChange = !viewingCiv.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)
if (!viewingCiv.isAtWarWith(otherCiv)) {
val tradeButton = "Trade".toTextButton()
tradeButton.onClick {
@ -195,7 +200,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
}
diplomacyTable.add(tradeButton).row()
if (isNotPlayersTurn()) tradeButton.disable()
} else {
} else if(diplomaticRelationshipsCanChange) {
val negotiatePeaceButton = "Negotiate Peace".toTextButton()
negotiatePeaceButton.onClick {
val tradeTable = setTrade(otherCiv)
@ -213,7 +218,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
if (!viewingCiv.isAtWarWith(otherCiv)) {
if(!diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)) {
if (!diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)) {
val declareFriendshipButton = "Offer Declaration of Friendship ([30] turns)".toTextButton()
declareFriendshipButton.onClick {
otherCiv.popupAlerts.add(PopupAlert(AlertType.DeclarationOfFriendship, viewingCiv.civName))
@ -260,9 +265,11 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
if (isNotPlayersTurn()) denounceButton.disable()
}
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv)
diplomacyTable.add(declareWarButton).row()
if (isNotPlayersTurn()) declareWarButton.disable()
if (diplomaticRelationshipsCanChange) {
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv)
diplomacyTable.add(declareWarButton).row()
if (isNotPlayersTurn()) declareWarButton.disable()
}
}
val demandsButton = "Demands".toTextButton()