Diplomacy screen, declaring war, no entering frienly enemy territory

This commit is contained in:
Yair Morgenstern 2018-08-02 21:21:30 +03:00
parent bf9e06445c
commit 215310b413
8 changed files with 93 additions and 64 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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
}
}

View File

@ -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)

View File

@ -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

View 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()
}
}
}

View File

@ -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)
}
}

View File

@ -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()
}
}