You now see your own Diplomacy screen when in multiplayer, and not that of the current player

This commit is contained in:
Yair Morgenstern 2019-09-04 20:12:13 +03:00
parent 6b2b8fae38
commit 59cb9f972c
7 changed files with 34 additions and 38 deletions

View File

@ -251,7 +251,7 @@
EnemyCity: [ EnemyCity: [
[ [
"You have encoutered an enemy city!", "You have encountered an enemy city!",
"Cities can be conquered by reducing their health to 1,", "Cities can be conquered by reducing their health to 1,",
" and entering the city with a melee unit.", " and entering the city with a melee unit.",
"Since cities heal each turn, it is best to attack with ranged units" "Since cities heal each turn, it is best to attack with ranged units"

View File

@ -87,7 +87,7 @@ class TileMap {
// Only once we add the unit to the civ we can activate addPromotion, because it will try to update civ viewable tiles // Only once we add the unit to the civ we can activate addPromotion, because it will try to update civ viewable tiles
for(promotion in unit.baseUnit.promotions) for(promotion in unit.baseUnit.promotions)
unit.promotions.addPromotion(promotion,true) unit.promotions.addPromotion(promotion, true)
// And update civ stats, since the new unit changes both unit upkeep and resource consumption // And update civ stats, since the new unit changes both unit upkeep and resource consumption
civInfo.updateStatsForNextTurn() civInfo.updateStatsForNextTurn()

View File

@ -15,7 +15,7 @@ class UnitPromotions{
fun xpForNextPromotion() = (numberOfPromotions+1)*10 fun xpForNextPromotion() = (numberOfPromotions+1)*10
fun canBePromoted() = XP >= xpForNextPromotion() fun canBePromoted() = XP >= xpForNextPromotion()
fun addPromotion(promotionName:String, isFree:Boolean = false, updateViewableTiles:Boolean=true){ fun addPromotion(promotionName: String, isFree: Boolean = false){
if (!isFree) { if (!isFree) {
XP -= xpForNextPromotion() XP -= xpForNextPromotion()
numberOfPromotions++ numberOfPromotions++
@ -29,7 +29,6 @@ class UnitPromotions{
// Since some units get promotions upon construction, they will get the addPromotion from the unit.postBuildEvent // Since some units get promotions upon construction, they will get the addPromotion from the unit.postBuildEvent
// upon creation, BEFORE they are assigned to a tile, so the updateViewableTiles() would crash. // upon creation, BEFORE they are assigned to a tile, so the updateViewableTiles() would crash.
// So, if the addPromotion was triggered from there, simply don't update // So, if the addPromotion was triggered from there, simply don't update
// if(updateViewableTiles)
unit.updateViewableTiles() // some promotions/uniques give the unit bonus sight unit.updateViewableTiles() // some promotions/uniques give the unit bonus sight
} }

View File

@ -23,7 +23,7 @@ import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
import kotlin.math.roundToInt import kotlin.math.roundToInt
class DiplomacyScreen:CameraStageBaseScreen() { class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
val leftSideTable = Table().apply { defaults().pad(10f) } val leftSideTable = Table().apply { defaults().pad(10f) }
val rightSideTable = Table() val rightSideTable = Table()
@ -53,15 +53,14 @@ class DiplomacyScreen:CameraStageBaseScreen() {
private fun updateLeftSideTable() { private fun updateLeftSideTable() {
leftSideTable.clear() leftSideTable.clear()
val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization()
for (civ in UnCivGame.Current.gameInfo.civilizations for (civ in UnCivGame.Current.gameInfo.civilizations
.filterNot { it.isDefeated() || it == currentPlayerCiv || it.isBarbarian() }) { .filterNot { it.isDefeated() || it == viewingCiv || it.isBarbarian() }) {
if (!currentPlayerCiv.knows(civ)) continue if (!viewingCiv.knows(civ)) continue
val civIndicator = ImageGetter.getNationIndicator(civ.nation,100f) val civIndicator = ImageGetter.getNationIndicator(civ.nation,100f)
val relationship = ImageGetter.getCircle() val relationship = ImageGetter.getCircle()
if(currentPlayerCiv.isAtWarWith(civ)) relationship.color = Color.RED if(viewingCiv.isAtWarWith(civ)) relationship.color = Color.RED
else relationship.color = Color.GREEN else relationship.color = Color.GREEN
relationship.setSize(30f,30f) relationship.setSize(30f,30f)
civIndicator.addActor(relationship) civIndicator.addActor(relationship)
@ -90,8 +89,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
private fun getCityStateDiplomacyTable(otherCiv: CivilizationInfo): Table { private fun getCityStateDiplomacyTable(otherCiv: CivilizationInfo): Table {
val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(viewingCiv)
val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(currentPlayerCiv)
val diplomacyTable = Table() val diplomacyTable = Table()
diplomacyTable.defaults().pad(10f) diplomacyTable.defaults().pad(10f)
@ -102,7 +100,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
diplomacyTable.add(getRelationshipTable(otherCivDiplomacyManager)).row() diplomacyTable.add(getRelationshipTable(otherCivDiplomacyManager)).row()
val friendBonusText = when (otherCiv.getCityStateType()) { val friendBonusText = when (otherCiv.getCityStateType()) {
CityStateType.Cultured -> "Provides [" + (3 * (currentPlayerCiv.getEra().ordinal + 1)).toString() + "] culture at [30] Influence" CityStateType.Cultured -> "Provides [" + (3 * (viewingCiv.getEra().ordinal + 1)).toString() + "] culture at [30] Influence"
CityStateType.Maritime -> "Provides 3 food in capital and 1 food in other cities at [30] Influence" CityStateType.Maritime -> "Provides 3 food in capital and 1 food in other cities at [30] Influence"
CityStateType.Mercantile -> "Provides 3 happiness at [30] Influence" CityStateType.Mercantile -> "Provides 3 happiness at [30] Influence"
CityStateType.Militaristic -> "Provides land units every 20 turns at [30] Influence" CityStateType.Militaristic -> "Provides land units every 20 turns at [30] Influence"
@ -124,19 +122,19 @@ class DiplomacyScreen:CameraStageBaseScreen() {
val influenceAmount = giftAmount / 10 val influenceAmount = giftAmount / 10
val giftButton = TextButton("Gift [$giftAmount] gold (+[$influenceAmount] influence)".tr(), skin) val giftButton = TextButton("Gift [$giftAmount] gold (+[$influenceAmount] influence)".tr(), skin)
giftButton.onClick { giftButton.onClick {
currentPlayerCiv.giveGoldGift(otherCiv, giftAmount) viewingCiv.giveGoldGift(otherCiv, giftAmount)
updateRightSide(otherCiv) updateRightSide(otherCiv)
} }
diplomacyTable.add(giftButton).row() diplomacyTable.add(giftButton).row()
if (currentPlayerCiv.gold < giftAmount || isNotPlayersTurn()) giftButton.disable() if (viewingCiv.gold < giftAmount || isNotPlayersTurn()) giftButton.disable()
val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv) val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
if (currentPlayerCiv.isAtWarWith(otherCiv)) { if (viewingCiv.isAtWarWith(otherCiv)) {
val peaceButton = TextButton("Negotiate Peace".tr(), skin) val peaceButton = TextButton("Negotiate Peace".tr(), skin)
peaceButton.onClick { peaceButton.onClick {
YesNoPopupTable("Peace with [${otherCiv.civName}]?".tr(), { YesNoPopupTable("Peace with [${otherCiv.civName}]?".tr(), {
val tradeLogic = TradeLogic(currentPlayerCiv, otherCiv) val tradeLogic = TradeLogic(viewingCiv, otherCiv)
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30))
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30))
tradeLogic.acceptTrade() tradeLogic.acceptTrade()
@ -155,8 +153,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
} }
private fun getMajorCivDiplomacyTable(otherCiv: CivilizationInfo): Table { private fun getMajorCivDiplomacyTable(otherCiv: CivilizationInfo): Table {
val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(viewingCiv)
val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(currentPlayerCiv)
val diplomacyTable = Table() val diplomacyTable = Table()
diplomacyTable.defaults().pad(10f) diplomacyTable.defaults().pad(10f)
@ -169,7 +166,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
diplomacyTable.add(translatedNation.neutralHello.toLabel()).row() diplomacyTable.add(translatedNation.neutralHello.toLabel()).row()
diplomacyTable.addSeparator() diplomacyTable.addSeparator()
if(!currentPlayerCiv.isAtWarWith(otherCiv)) { if(!viewingCiv.isAtWarWith(otherCiv)) {
val tradeButton = TextButton("Trade".tr(), skin) val tradeButton = TextButton("Trade".tr(), skin)
tradeButton.onClick { setTrade(otherCiv) } tradeButton.onClick { setTrade(otherCiv) }
diplomacyTable.add(tradeButton).row() diplomacyTable.add(tradeButton).row()
@ -190,11 +187,11 @@ class DiplomacyScreen:CameraStageBaseScreen() {
diplomacyTable.add(negotiatePeaceButton).row() diplomacyTable.add(negotiatePeaceButton).row()
} }
val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv) val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
if (!currentPlayerCiv.isAtWarWith(otherCiv)) { if (!viewingCiv.isAtWarWith(otherCiv)) {
if(otherCivDiplomacyManager.relationshipLevel() > RelationshipLevel.Neutral if(otherCivDiplomacyManager.relationshipLevel() > RelationshipLevel.Neutral
&& !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship) && !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)
&& !diplomacyManager.hasFlag(DiplomacyFlags.Denunceation)){ && !diplomacyManager.hasFlag(DiplomacyFlags.Denunceation)){
@ -226,7 +223,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
val demandsButton = TextButton("Demands".tr(),skin) val demandsButton = TextButton("Demands".tr(),skin)
demandsButton.onClick { demandsButton.onClick {
rightSideTable.clear() rightSideTable.clear()
rightSideTable.add(getDemandsTable(currentPlayerCiv,otherCiv)) rightSideTable.add(getDemandsTable(viewingCiv,otherCiv))
} }
diplomacyTable.add(demandsButton).row() diplomacyTable.add(demandsButton).row()
if(isNotPlayersTurn()) demandsButton.disable() if(isNotPlayersTurn()) demandsButton.disable()
@ -270,15 +267,15 @@ class DiplomacyScreen:CameraStageBaseScreen() {
return diplomacyModifiersTable return diplomacyModifiersTable
} }
private fun getDemandsTable(currentPlayerCiv: CivilizationInfo, otherCiv: CivilizationInfo): Table { private fun getDemandsTable(viewingCiv: CivilizationInfo, otherCiv: CivilizationInfo): Table {
val demandsTable = Table() val demandsTable = Table()
demandsTable.defaults().pad(10f) demandsTable.defaults().pad(10f)
val dontSettleCitiesButton = TextButton("Please don't settle new cities near us.".tr(),skin) val dontSettleCitiesButton = TextButton("Please don't settle new cities near us.".tr(),skin)
if(otherCiv.popupAlerts.any { it.type==AlertType.DemandToStopSettlingCitiesNear && it.value==currentPlayerCiv.civName }) if(otherCiv.popupAlerts.any { it.type==AlertType.DemandToStopSettlingCitiesNear && it.value==viewingCiv.civName })
dontSettleCitiesButton.disable() dontSettleCitiesButton.disable()
dontSettleCitiesButton.onClick { dontSettleCitiesButton.onClick {
otherCiv.popupAlerts.add(PopupAlert(AlertType.DemandToStopSettlingCitiesNear, currentPlayerCiv.civName)) otherCiv.popupAlerts.add(PopupAlert(AlertType.DemandToStopSettlingCitiesNear, viewingCiv.civName))
dontSettleCitiesButton.disable() dontSettleCitiesButton.disable()
} }
demandsTable.add(dontSettleCitiesButton).row() demandsTable.add(dontSettleCitiesButton).row()

View File

@ -15,8 +15,8 @@ import kotlin.math.max
class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
init{ init{
val currentPlayerCiv = worldScreen.viewingCiv val viewingCiv = worldScreen.viewingCiv
val tradeRequest = currentPlayerCiv.tradeRequests.first() val tradeRequest = viewingCiv.tradeRequests.first()
val requestingCiv = worldScreen.gameInfo.getCivilization(tradeRequest.requestingCiv) val requestingCiv = worldScreen.gameInfo.getCivilization(tradeRequest.requestingCiv)
val translatedNation = requestingCiv.getTranslatedNation() val translatedNation = requestingCiv.getTranslatedNation()
@ -39,10 +39,10 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
addGoodSizedLabel(translatedNation.tradeRequest).colspan(columns).row() addGoodSizedLabel(translatedNation.tradeRequest).colspan(columns).row()
addButton("Sounds good!"){ addButton("Sounds good!"){
val tradeLogic = TradeLogic(currentPlayerCiv, requestingCiv) val tradeLogic = TradeLogic(viewingCiv, requestingCiv)
tradeLogic.currentTrade.set(trade) tradeLogic.currentTrade.set(trade)
tradeLogic.acceptTrade() tradeLogic.acceptTrade()
currentPlayerCiv.tradeRequests.remove(tradeRequest) viewingCiv.tradeRequests.remove(tradeRequest)
close() close()
PopupTable(worldScreen).apply { PopupTable(worldScreen).apply {
add(otherCivLeaderName.toLabel()).colspan(2) add(otherCivLeaderName.toLabel()).colspan(2)
@ -56,12 +56,12 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
} }
open() open()
} }
requestingCiv.addNotification("[${currentPlayerCiv.civName}] has accepted your trade request", Color.GOLD) requestingCiv.addNotification("[${viewingCiv.civName}] has accepted your trade request", Color.GOLD)
} }
addButton("Not this time.".tr()){ addButton("Not this time.".tr()){
currentPlayerCiv.tradeRequests.remove(tradeRequest) viewingCiv.tradeRequests.remove(tradeRequest)
val diplomacyManager = requestingCiv.getDiplomacyManager(currentPlayerCiv) val diplomacyManager = requestingCiv.getDiplomacyManager(viewingCiv)
if(trade.ourOffers.all { it.type==TradeType.Luxury_Resource } && trade.theirOffers.all { it.type==TradeType.Luxury_Resource }) if(trade.ourOffers.all { it.type==TradeType.Luxury_Resource } && trade.theirOffers.all { it.type==TradeType.Luxury_Resource })
diplomacyManager.setFlag(DiplomacyFlags.DeclinedLuxExchange,20) // offer again in 20 turns diplomacyManager.setFlag(DiplomacyFlags.DeclinedLuxExchange,20) // offer again in 20 turns
@ -69,15 +69,15 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
diplomacyManager.setFlag(DiplomacyFlags.DeclinedPeace,5) diplomacyManager.setFlag(DiplomacyFlags.DeclinedPeace,5)
close() close()
requestingCiv.addNotification("[${currentPlayerCiv.civName}] has denied your trade request", Color.GOLD) requestingCiv.addNotification("[${viewingCiv.civName}] has denied your trade request", Color.GOLD)
worldScreen.shouldUpdate=true worldScreen.shouldUpdate=true
} }
addButton("How about something else...".tr()){ addButton("How about something else...".tr()){
currentPlayerCiv.tradeRequests.remove(tradeRequest) viewingCiv.tradeRequests.remove(tradeRequest)
close() close()
val diplomacyScreen= DiplomacyScreen() val diplomacyScreen= DiplomacyScreen(viewingCiv)
val tradeTable = diplomacyScreen.setTrade(requestingCiv) val tradeTable = diplomacyScreen.setTrade(requestingCiv)
tradeTable.tradeLogic.currentTrade.set(trade) tradeTable.tradeLogic.currentTrade.set(trade)
tradeTable.offerColumnsTable.update() tradeTable.offerColumnsTable.update()

View File

@ -231,7 +231,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
.any()) { .any()) {
displayTutorials("OtherCivEncountered") displayTutorials("OtherCivEncountered")
val btn = TextButton("Diplomacy".tr(), skin) val btn = TextButton("Diplomacy".tr(), skin)
btn.onClick { UnCivGame.Current.screen = DiplomacyScreen() } btn.onClick { UnCivGame.Current.screen = DiplomacyScreen(viewingCiv) }
btn.label.setFontSize(30) btn.label.setFontSize(30)
btn.labelCell.pad(10f) btn.labelCell.pad(10f)
diplomacyButtonWrapper.add(btn) diplomacyButtonWrapper.add(btn)

View File

@ -96,7 +96,7 @@ class UnitActions {
for(promotion in unit.baseUnit.promotions) for(promotion in unit.baseUnit.promotions)
if(promotion !in newunit.promotions.promotions) if(promotion !in newunit.promotions.promotions)
newunit.promotions.addPromotion(promotion,true) newunit.promotions.addPromotion(promotion, true)
newunit.updateUniques() newunit.updateUniques()
newunit.updateViewableTiles() newunit.updateViewableTiles()