diff --git a/android/build.gradle b/android/build.gradle index 32351e41b0..4222e501b4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.game" minSdkVersion 14 targetSdkVersion 26 - versionCode 110 - versionName "2.6.11" + versionCode 111 + versionName "2.7.0" } buildTypes { release { diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index e7569538c0..74371ce6d1 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -266,7 +266,9 @@ class CivilizationInfo { for(otherCiv in viewedCivs) if(!diplomacy.containsKey(otherCiv.civName)){ diplomacy[otherCiv.civName] = DiplomacyManager(this@CivilizationInfo,otherCiv.civName) + .apply { diplomaticStatus = DiplomaticStatus.Peace } otherCiv.diplomacy[civName] = DiplomacyManager(otherCiv,civName) + .apply { diplomaticStatus = DiplomaticStatus.Peace } addNotification("We have encountered ["+otherCiv.civName+"]!".tr(),null, Color.GOLD) } diff --git a/core/src/com/unciv/logic/civilization/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/DiplomacyManager.kt index 495bdf6057..8f7d95a524 100644 --- a/core/src/com/unciv/logic/civilization/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/DiplomacyManager.kt @@ -84,4 +84,11 @@ class DiplomacyManager() { 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 + } } \ No newline at end of file diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index c98b12a4e1..536be8708e 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -36,9 +36,13 @@ class UnitMovementAlgorithms(val unit:MapUnit) { for (tileToCheck in tilesToCheck) for (neighbor in tileToCheck.neighbors) { var totalDistanceToTile:Float - if ((neighbor.getOwner() != unit.civInfo && neighbor.isCityCenter())// Enemy city, - || neighbor.getUnits().isNotEmpty() && neighbor.getUnits().first().civInfo!=unit.civInfo) // Enemy unit - totalDistanceToTile = unitMovement // can't move through it - we'll be "stuck" there + val neighborOwner = neighbor.getOwner() + val isOwnedByEnemy = neighborOwner!=null && neighborOwner!=unit.civInfo + 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 { val distanceBetweenTiles = getMovementCostBetweenAdjacentTiles(tileToCheck, neighbor) diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index 0bf38e5770..7804f7b7c7 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -19,8 +19,8 @@ class TradeLogic(val otherCivilization: CivilizationInfo){ fun getAvailableOffers(civInfo: CivilizationInfo, otherCivilization: CivilizationInfo): TradeOffersList { val offers = TradeOffersList() -// if(civInfo.isAtWarWith(otherCivilization)) -// offers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20, 1)) + if(civInfo.isAtWarWith(otherCivilization)) + offers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20, 1)) for(entry in civInfo.getCivResources().filterNot { it.key.resourceType == ResourceType.Bonus }) { val resourceTradeType = if(entry.key.resourceType== ResourceType.Luxury) TradeType.Luxury_Resource else TradeType.Strategic_Resource diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt new file mode 100644 index 0000000000..ac86496632 --- /dev/null +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -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() + } + } +} diff --git a/core/src/com/unciv/ui/trade/TradeScreen.kt b/core/src/com/unciv/ui/trade/TradeScreen.kt deleted file mode 100644 index 3918683588..0000000000 --- a/core/src/com/unciv/ui/trade/TradeScreen.kt +++ /dev/null @@ -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) - } - -} - - diff --git a/core/src/com/unciv/ui/trade/TradeTable.kt b/core/src/com/unciv/ui/trade/TradeTable.kt index 9f2a31db50..b72a74746a 100644 --- a/core/src/com/unciv/ui/trade/TradeTable.kt +++ b/core/src/com/unciv/ui/trade/TradeTable.kt @@ -10,7 +10,7 @@ import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.addClickListener 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 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 @@ -46,6 +46,7 @@ class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage): Table(C offerColumnsTableWrapper.clear() offerColumnsTableWrapper.add(offerColumnsTable) tradeText.setText("Pleasure doing business with you!".tr()) + onTradeComplete() } }