mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 16:28:40 +07:00
Diplomacy screen, declaring war, no entering frienly enemy territory
This commit is contained in:
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.game"
|
applicationId "com.unciv.game"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 110
|
versionCode 111
|
||||||
versionName "2.6.11"
|
versionName "2.7.0"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -266,7 +266,9 @@ class CivilizationInfo {
|
|||||||
for(otherCiv in viewedCivs)
|
for(otherCiv in viewedCivs)
|
||||||
if(!diplomacy.containsKey(otherCiv.civName)){
|
if(!diplomacy.containsKey(otherCiv.civName)){
|
||||||
diplomacy[otherCiv.civName] = DiplomacyManager(this@CivilizationInfo,otherCiv.civName)
|
diplomacy[otherCiv.civName] = DiplomacyManager(this@CivilizationInfo,otherCiv.civName)
|
||||||
|
.apply { diplomaticStatus = DiplomaticStatus.Peace }
|
||||||
otherCiv.diplomacy[civName] = DiplomacyManager(otherCiv,civName)
|
otherCiv.diplomacy[civName] = DiplomacyManager(otherCiv,civName)
|
||||||
|
.apply { diplomaticStatus = DiplomaticStatus.Peace }
|
||||||
addNotification("We have encountered ["+otherCiv.civName+"]!".tr(),null, Color.GOLD)
|
addNotification("We have encountered ["+otherCiv.civName+"]!".tr(),null, Color.GOLD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,4 +84,11 @@ class DiplomacyManager() {
|
|||||||
diplomaticStatus = DiplomaticStatus.War
|
diplomaticStatus = DiplomaticStatus.War
|
||||||
otherCiv().diplomacy[civInfo.civName]!!.diplomaticStatus = DiplomaticStatus.War
|
otherCiv().diplomacy[civInfo.civName]!!.diplomaticStatus = DiplomaticStatus.War
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun turnsToPeaceTreaty(): Int {
|
||||||
|
for(trade in trades)
|
||||||
|
for(offer in trade.ourOffers)
|
||||||
|
if(offer.name=="Peace Treaty") return offer.duration
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
@ -36,9 +36,13 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
|||||||
for (tileToCheck in tilesToCheck)
|
for (tileToCheck in tilesToCheck)
|
||||||
for (neighbor in tileToCheck.neighbors) {
|
for (neighbor in tileToCheck.neighbors) {
|
||||||
var totalDistanceToTile:Float
|
var totalDistanceToTile:Float
|
||||||
if ((neighbor.getOwner() != unit.civInfo && neighbor.isCityCenter())// Enemy city,
|
val neighborOwner = neighbor.getOwner()
|
||||||
|| neighbor.getUnits().isNotEmpty() && neighbor.getUnits().first().civInfo!=unit.civInfo) // Enemy unit
|
val isOwnedByEnemy = neighborOwner!=null && neighborOwner!=unit.civInfo
|
||||||
totalDistanceToTile = unitMovement // can't move through it - we'll be "stuck" there
|
if ((isOwnedByEnemy && neighbor.isCityCenter())// Enemy city,
|
||||||
|
|| (neighbor.getUnits().isNotEmpty() && neighbor.getUnits().first().civInfo!=unit.civInfo) // Enemy unit
|
||||||
|
|| (isOwnedByEnemy && !unit.civInfo.canEnterTiles(neighborOwner!!))
|
||||||
|
)
|
||||||
|
continue // Can't go here!
|
||||||
|
|
||||||
else {
|
else {
|
||||||
val distanceBetweenTiles = getMovementCostBetweenAdjacentTiles(tileToCheck, neighbor)
|
val distanceBetweenTiles = getMovementCostBetweenAdjacentTiles(tileToCheck, neighbor)
|
||||||
|
@ -19,8 +19,8 @@ class TradeLogic(val otherCivilization: CivilizationInfo){
|
|||||||
|
|
||||||
fun getAvailableOffers(civInfo: CivilizationInfo, otherCivilization: CivilizationInfo): TradeOffersList {
|
fun getAvailableOffers(civInfo: CivilizationInfo, otherCivilization: CivilizationInfo): TradeOffersList {
|
||||||
val offers = TradeOffersList()
|
val offers = TradeOffersList()
|
||||||
// if(civInfo.isAtWarWith(otherCivilization))
|
if(civInfo.isAtWarWith(otherCivilization))
|
||||||
// offers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20, 1))
|
offers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20, 1))
|
||||||
for(entry in civInfo.getCivResources().filterNot { it.key.resourceType == ResourceType.Bonus }) {
|
for(entry in civInfo.getCivResources().filterNot { it.key.resourceType == ResourceType.Bonus }) {
|
||||||
val resourceTradeType = if(entry.key.resourceType== ResourceType.Luxury) TradeType.Luxury_Resource
|
val resourceTradeType = if(entry.key.resourceType== ResourceType.Luxury) TradeType.Luxury_Resource
|
||||||
else TradeType.Strategic_Resource
|
else TradeType.Strategic_Resource
|
||||||
|
71
core/src/com/unciv/ui/trade/DiplomacyScreen.kt
Normal file
71
core/src/com/unciv/ui/trade/DiplomacyScreen.kt
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package com.unciv.ui.trade
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.SplitPane
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
|
import com.unciv.UnCivGame
|
||||||
|
import com.unciv.ui.utils.*
|
||||||
|
|
||||||
|
class DiplomacyScreen():CameraStageBaseScreen(){
|
||||||
|
|
||||||
|
val leftSideTable = Table().apply { defaults().pad(10f) }
|
||||||
|
val rightSideTable = Table()
|
||||||
|
|
||||||
|
init{
|
||||||
|
val splitPane = SplitPane(leftSideTable,rightSideTable,false, skin)
|
||||||
|
splitPane.setSplitAmount(0.2f)
|
||||||
|
|
||||||
|
updateLeftSideTable()
|
||||||
|
|
||||||
|
splitPane.setFillParent(true)
|
||||||
|
stage.addActor(splitPane)
|
||||||
|
|
||||||
|
|
||||||
|
val closeButton = TextButton("Close".tr(), skin)
|
||||||
|
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
|
||||||
|
closeButton.y = stage.height - closeButton.height - 10
|
||||||
|
closeButton.x = 10f
|
||||||
|
stage.addActor(closeButton) // This must come after the split pane so it will be above, that the button will be clickable
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateLeftSideTable() {
|
||||||
|
leftSideTable.clear()
|
||||||
|
val playerCiv = UnCivGame.Current.gameInfo.getPlayerCivilization()
|
||||||
|
for (civ in UnCivGame.Current.gameInfo.civilizations
|
||||||
|
.filterNot { it.isDefeated() || it.isPlayerCivilization() || it.isBarbarianCivilization() }) {
|
||||||
|
if (!playerCiv.diplomacy.containsKey(civ.civName)) continue
|
||||||
|
val civDiplomacy = playerCiv.diplomacy[civ.civName]!!
|
||||||
|
|
||||||
|
val civTable = Table().apply { background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) }
|
||||||
|
civTable.pad(10f)
|
||||||
|
civTable.defaults().pad(10f)
|
||||||
|
val peaceWarStatus = civDiplomacy.diplomaticStatus.toString()
|
||||||
|
civTable.add(Label(civ.civName.tr() + " ({$peaceWarStatus})".tr(), skin).apply { setFont(22); setFontColor(Color.WHITE) }).row()
|
||||||
|
|
||||||
|
val tradeButton = TextButton("Trade".tr(), skin)
|
||||||
|
tradeButton.addClickListener {
|
||||||
|
rightSideTable.clear()
|
||||||
|
rightSideTable.add(TradeTable(civ, stage){updateLeftSideTable()})
|
||||||
|
}
|
||||||
|
civTable.add(tradeButton).row()
|
||||||
|
|
||||||
|
if (!playerCiv.isAtWarWith(civ)) {
|
||||||
|
val declareWarButton = TextButton("Declare war".tr(), skin)
|
||||||
|
val turnsToPeaceTreaty = civDiplomacy.turnsToPeaceTreaty()
|
||||||
|
if(turnsToPeaceTreaty>0){
|
||||||
|
declareWarButton.disable()
|
||||||
|
declareWarButton.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty)")
|
||||||
|
}
|
||||||
|
declareWarButton.addClickListener {
|
||||||
|
civDiplomacy.declareWar()
|
||||||
|
updateLeftSideTable()
|
||||||
|
}
|
||||||
|
civTable.add(declareWarButton).row()
|
||||||
|
}
|
||||||
|
|
||||||
|
leftSideTable.add(civTable).row()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,56 +0,0 @@
|
|||||||
package com.unciv.ui.trade
|
|
||||||
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.SplitPane
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
|
||||||
import com.unciv.UnCivGame
|
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
|
||||||
import com.unciv.ui.utils.addClickListener
|
|
||||||
import com.unciv.ui.utils.center
|
|
||||||
import com.unciv.ui.utils.tr
|
|
||||||
|
|
||||||
class DiplomacyScreen():CameraStageBaseScreen(){
|
|
||||||
init{
|
|
||||||
val rightSideTable = Table()
|
|
||||||
val leftSideTable = Table()
|
|
||||||
val splitPane = SplitPane(rightSideTable,leftSideTable,false, skin)
|
|
||||||
splitPane.setSplitAmount(0.2f)
|
|
||||||
|
|
||||||
val playerCiv = UnCivGame.Current.gameInfo.getPlayerCivilization()
|
|
||||||
for(civ in UnCivGame.Current.gameInfo.civilizations
|
|
||||||
.filterNot { it.isDefeated() || it.isPlayerCivilization() || it.isBarbarianCivilization() }){
|
|
||||||
if(!playerCiv.diplomacy.containsKey(civ.civName)) continue
|
|
||||||
val tb = TextButton("Trade with [${civ.civName}]".tr(),skin)
|
|
||||||
tb.addClickListener { leftSideTable.clear(); leftSideTable.add(TradeTable(civ,stage)) }
|
|
||||||
rightSideTable.add(tb).pad(10f).row()
|
|
||||||
}
|
|
||||||
splitPane.setFillParent(true)
|
|
||||||
stage.addActor(splitPane)
|
|
||||||
|
|
||||||
|
|
||||||
val closeButton = TextButton("Close".tr(), skin)
|
|
||||||
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
|
|
||||||
closeButton.y = stage.height - closeButton.height - 5
|
|
||||||
stage.addActor(closeButton) // This must come after the split pane so it will be above, that the button will be clickable
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TradeScreen(otherCivilization: CivilizationInfo) : CameraStageBaseScreen(){
|
|
||||||
|
|
||||||
init {
|
|
||||||
val closeButton = TextButton("Close".tr(), skin)
|
|
||||||
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
|
|
||||||
closeButton.y = stage.height - closeButton.height - 5
|
|
||||||
stage.addActor(closeButton)
|
|
||||||
|
|
||||||
|
|
||||||
val generalTable = TradeTable(otherCivilization, stage)
|
|
||||||
generalTable.center(stage)
|
|
||||||
|
|
||||||
stage.addActor(generalTable)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@ import com.unciv.ui.utils.CameraStageBaseScreen
|
|||||||
import com.unciv.ui.utils.addClickListener
|
import com.unciv.ui.utils.addClickListener
|
||||||
import com.unciv.ui.utils.tr
|
import com.unciv.ui.utils.tr
|
||||||
|
|
||||||
class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage): Table(CameraStageBaseScreen.skin){
|
class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage, onTradeComplete: () -> Unit): Table(CameraStageBaseScreen.skin){
|
||||||
var tradeLogic = TradeLogic(otherCivilization)
|
var tradeLogic = TradeLogic(otherCivilization)
|
||||||
var offerColumnsTable = OfferColumnsTable(tradeLogic, stage) { onChange() }
|
var offerColumnsTable = OfferColumnsTable(tradeLogic, stage) { onChange() }
|
||||||
var offerColumnsTableWrapper = Table() // This is so that after a trade has been traded, we can switch out the offers to start anew - this is the easiest way
|
var offerColumnsTableWrapper = Table() // This is so that after a trade has been traded, we can switch out the offers to start anew - this is the easiest way
|
||||||
@ -46,6 +46,7 @@ class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage): Table(C
|
|||||||
offerColumnsTableWrapper.clear()
|
offerColumnsTableWrapper.clear()
|
||||||
offerColumnsTableWrapper.add(offerColumnsTable)
|
offerColumnsTableWrapper.add(offerColumnsTable)
|
||||||
tradeText.setText("Pleasure doing business with you!".tr())
|
tradeText.setText("Pleasure doing business with you!".tr())
|
||||||
|
onTradeComplete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user