mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 22:06:05 -04:00
DiplomacyManager.flagsCountdown is now a Hashmap<String, Int> because of deserialization bullshit
Solved a silly bug in the Diplomacy overview
This commit is contained in:
parent
c8ea9f1a27
commit
2b8946f5e7
@ -155,7 +155,7 @@ class NextTurnAutomation{
|
||||
// B. have a way for the AI to keep track of the "pending offers" - see DiplomacyManager.resourcesFromTrade
|
||||
|
||||
for (otherCiv in knownCivs.filter { it.isPlayerCivilization() && !it.isAtWarWith(civInfo)
|
||||
&& !civInfo.getDiplomacyManager(it).flagsCountdown.containsKey(DiplomacyFlags.DeclinedLuxExchange)}) {
|
||||
&& !civInfo.getDiplomacyManager(it).flagsCountdown.containsKey(DiplomacyFlags.DeclinedLuxExchange.toString())}) {
|
||||
val trades = potentialLuxuryTrades(civInfo,otherCiv)
|
||||
for(trade in trades){
|
||||
val tradeRequest = TradeRequest(civInfo.civName, trade.reverse())
|
||||
@ -189,7 +189,7 @@ class NextTurnAutomation{
|
||||
val enemiesCiv = civInfo.diplomacy.filter{ it.value.diplomaticStatus == DiplomaticStatus.War }
|
||||
.map{ it.value.otherCiv() }
|
||||
.filterNot{ it == civInfo || it.isBarbarianCivilization() || it.cities.isEmpty() }
|
||||
.filter { !civInfo.getDiplomacyManager(it).flagsCountdown.containsKey(DiplomacyFlags.DeclinedPeace) }
|
||||
.filter { !civInfo.getDiplomacyManager(it).flagsCountdown.containsKey(DiplomacyFlags.DeclinedPeace.toString()) }
|
||||
|
||||
for (enemy in enemiesCiv) {
|
||||
val enemiesStrength = Automation().evaluteCombatStrength(enemy)
|
||||
|
@ -24,8 +24,10 @@ class DiplomacyManager() {
|
||||
lateinit var otherCivName:String
|
||||
var trades = ArrayList<Trade>()
|
||||
var diplomaticStatus = DiplomaticStatus.War
|
||||
/** Contains various flags (declared war, promised to not settle, declined luxury trade) and the number of turns in which they will expire */
|
||||
var flagsCountdown = HashMap<DiplomacyFlags,Int>()
|
||||
/** Contains various flags (declared war, promised to not settle, declined luxury trade) and the number of turns in which they will expire.
|
||||
* The JSON serialize/deserialize REFUSES to deserialize hashmap keys as Enums, so I'm forced to use strings instead =(
|
||||
* This is so sad Alexa play Despacito */
|
||||
var flagsCountdown = HashMap<String,Int>()
|
||||
|
||||
fun clone(): DiplomacyManager {
|
||||
val toReturn = DiplomacyManager()
|
||||
@ -104,13 +106,23 @@ class DiplomacyManager() {
|
||||
|
||||
// for performance reasons we don't want to call this every time we want to see if a unit can move through a tile
|
||||
fun updateHasOpenBorders(){
|
||||
hasOpenBorders=false
|
||||
for(trade in trades)
|
||||
for(offer in trade.theirOffers)
|
||||
if(offer.name=="Open Borders" && offer.duration > 0){
|
||||
hasOpenBorders=true
|
||||
return
|
||||
var newHasOpenBorders = false
|
||||
for(trade in trades) {
|
||||
for (offer in trade.theirOffers)
|
||||
if (offer.name == "Open Borders" && offer.duration > 0) {
|
||||
newHasOpenBorders = true
|
||||
break
|
||||
}
|
||||
if(newHasOpenBorders) break
|
||||
}
|
||||
|
||||
if(hasOpenBorders && !newHasOpenBorders){ // borders were closed, get out!
|
||||
for(unit in civInfo.getCivUnits().filter { it.currentTile.getOwner()?.civName== otherCivName }){
|
||||
unit.movementAlgs().teleportToClosestMoveableTile()
|
||||
}
|
||||
}
|
||||
|
||||
hasOpenBorders=newHasOpenBorders
|
||||
}
|
||||
|
||||
fun nextTurn(){
|
||||
@ -157,8 +169,8 @@ class DiplomacyManager() {
|
||||
otherCiv.popupAlerts.add(PopupAlert(AlertType.WarDeclaration,civInfo.civName))
|
||||
|
||||
/// AI won't propose peace for 10 turns
|
||||
flagsCountdown[DiplomacyFlags.DeclinedPeace]=10
|
||||
otherCiv.getDiplomacyManager(civInfo).flagsCountdown[DiplomacyFlags.DeclinedPeace]=10
|
||||
flagsCountdown[DiplomacyFlags.DeclinedPeace.toString()]=10
|
||||
otherCiv.getDiplomacyManager(civInfo).flagsCountdown[DiplomacyFlags.DeclinedPeace.toString()]=10
|
||||
}
|
||||
//endregion
|
||||
}
|
@ -285,7 +285,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
||||
}
|
||||
|
||||
|
||||
fun playerKnows(civ:CivilizationInfo) = civ.isPlayerCivilization() ||
|
||||
fun playerKnows(civ:CivilizationInfo) = civ==currentPlayerCivInfo ||
|
||||
currentPlayerCivInfo.diplomacy.containsKey(civ.civName)
|
||||
|
||||
fun createDiplomacyGroup(): Group {
|
||||
@ -293,8 +293,8 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
||||
val groupSize = 500f
|
||||
val group = Group()
|
||||
group.setSize(groupSize,groupSize)
|
||||
val civGroups = HashMap<CivilizationInfo,Actor>()
|
||||
for(i in 0 until relevantCivs.size){
|
||||
val civGroups = HashMap<String, Actor>()
|
||||
for(i in 0..relevantCivs.lastIndex){
|
||||
val civ = relevantCivs[i]
|
||||
|
||||
|
||||
@ -324,15 +324,15 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
||||
civGroup.center(group)
|
||||
civGroup.moveBy(vector.x*groupSize/3, vector.y*groupSize/3)
|
||||
|
||||
civGroups[civ]=civGroup
|
||||
civGroups[civ.civName]=civGroup
|
||||
group.addActor(civGroup)
|
||||
}
|
||||
|
||||
|
||||
for(civ in relevantCivs.filter { playerKnows(it) && !it.isDefeated() })
|
||||
for(diplomacy in civ.diplomacy.values.filter { !it.otherCiv().isBarbarianCivilization() && playerKnows(it.otherCiv()) && !it.otherCiv().isDefeated()}){
|
||||
val civGroup = civGroups[civ]!!
|
||||
val otherCivGroup = civGroups[diplomacy.otherCiv()]!!
|
||||
val civGroup = civGroups[civ.civName]!!
|
||||
val otherCivGroup = civGroups[diplomacy.otherCivName]!!
|
||||
|
||||
val statusLine = ImageGetter.getLine(civGroup.x+civGroup.width/2,civGroup.y+civGroup.height/2,
|
||||
otherCivGroup.x+otherCivGroup.width/2,otherCivGroup.y+otherCivGroup.height/2,3f)
|
||||
|
@ -58,11 +58,12 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
|
||||
addButton("Not this time.".tr()){
|
||||
currentPlayerCiv.tradeRequests.remove(tradeRequest)
|
||||
|
||||
val flagsCountdown = requestingCiv.getDiplomacyManager(currentPlayerCiv).flagsCountdown
|
||||
if(trade.ourOffers.all { it.type==TradeType.Luxury_Resource } && trade.theirOffers.all { it.type==TradeType.Luxury_Resource })
|
||||
requestingCiv.getDiplomacyManager(currentPlayerCiv).flagsCountdown[DiplomacyFlags.DeclinedLuxExchange]=20 // offer again in 20 turns
|
||||
flagsCountdown[DiplomacyFlags.DeclinedLuxExchange.toString()]=20 // offer again in 20 turns
|
||||
|
||||
if(trade.ourOffers.any{ it.type==TradeType.Treaty && it.name=="Peace Treaty" })
|
||||
requestingCiv.getDiplomacyManager(currentPlayerCiv).flagsCountdown[DiplomacyFlags.DeclinedPeace]=5 // offer again in 20 turns
|
||||
flagsCountdown[DiplomacyFlags.DeclinedPeace.toString()]=5 // offer again in 20 turns
|
||||
|
||||
remove()
|
||||
worldScreen.shouldUpdate=true
|
||||
|
Loading…
x
Reference in New Issue
Block a user