Added diplomatic introductions to trade

This commit is contained in:
Yair Morgenstern 2018-09-17 19:54:16 +03:00
parent 75bfc04adb
commit 4b0aca4ef0
5 changed files with 23 additions and 6 deletions

View file

@ -196,16 +196,20 @@ 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 }
meetCivilization(otherCiv)
addNotification("We have encountered [${otherCiv.civName}]!".tr(),null, Color.GOLD)
}
return viewablePositions.distinct()
}
fun meetCivilization(otherCiv: CivilizationInfo) {
diplomacy[otherCiv.civName] = DiplomacyManager(this, otherCiv.civName)
.apply { diplomaticStatus = DiplomaticStatus.Peace }
otherCiv.diplomacy[civName] = DiplomacyManager(otherCiv, civName)
.apply { diplomaticStatus = DiplomaticStatus.Peace }
}
override fun toString(): String {return civName} // for debug
fun isDefeated()= cities.isEmpty() && !getCivUnits().any{it.name=="Settler"}

View file

@ -17,7 +17,7 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
fun getAvailableOffers(civInfo: CivilizationInfo, otherCivilization: CivilizationInfo): TradeOffersList {
val offers = TradeOffersList()
if(civInfo.isAtWarWith(otherCivilization))
offers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20, 1))
offers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20, 0))
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
@ -32,6 +32,13 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
offers.add(TradeOffer("Gold per turn".tr(), TradeType.Gold_Per_Turn, 30, civInfo.getStatsForNextTurn().gold.toInt()))
for(city in civInfo.cities.filterNot { it.isCapital() })
offers.add(TradeOffer(city.name, TradeType.City, 0, 1))
val civsWeKnowAndTheyDont = civInfo.diplomacy.values.map { it.otherCiv() }
.filter { !otherCivilization.diplomacy.containsKey(it.civName) && it != otherCivilization }
for(thirdCiv in civsWeKnowAndTheyDont){
offers.add(TradeOffer("Introduction to " + thirdCiv.civName, TradeType.Introduction, 0,1))
}
return offers
}
@ -76,6 +83,7 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
return evaluatePeaceCostForThem() // Since it will be evaluated twice, once when they evaluate our offer and once when they evaluate theirs
else return 1000
}
TradeType.Introduction -> return 250
// Dunno what this is?
else -> return 1000
}
@ -127,6 +135,9 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
unit.movementAlgs().teleportToClosestMoveableTile()
}
}
if(offer.type==TradeType.Introduction)
us.meetCivilization(us.gameInfo.civilizations
.first { it.civName==offer.name.split(" ")[2] })
}
}

View file

@ -7,5 +7,6 @@ enum class TradeType{
Luxury_Resource,
Strategic_Resource,
Technology,
Introduction,
City
}

View file

@ -24,7 +24,7 @@ class OffersList(val offers: TradeOffersList, val correspondingOffers: TradeOffe
table.clear()
for(offer in offers.sortedBy { it.type }) {
var buttonText = offer.name.tr()
if(offer.type !in listOf(TradeType.Technology, TradeType.City)) buttonText+=" ("+offer.amount+")"
if(offer.type !in listOf(TradeType.Technology, TradeType.City, TradeType.Introduction)) buttonText+=" ("+offer.amount+")"
if(offer.duration>1) buttonText+="\n"+offer.duration+" {turns}".tr()
val tb = TextButton(buttonText, CameraStageBaseScreen.skin)
val amountPerClick =

View file

@ -48,6 +48,7 @@ class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage, onTradeC
offerColumnsTableWrapper.add(offerColumnsTable)
tradeText.setText("Pleasure doing business with you!".tr())
onTradeComplete()
tradeText.setText("Offer trade".tr())
}
}