AI now saves up money to use for purchasing city-state influence

This commit is contained in:
Yair Morgenstern 2019-06-20 20:40:23 +03:00
parent 2b3de8b78f
commit 5cf05cd7d9
4 changed files with 48 additions and 12 deletions

View File

@ -32,7 +32,7 @@ class NextTurnAutomation{
updateDiplomaticRelationship(civInfo)
declareWar(civInfo)
automateCityBombardment(civInfo)
buyBuildingOrUnit(civInfo)
useGold(civInfo)
automateUnits(civInfo)
reassignWorkedTiles(civInfo)
trainSettler(civInfo)
@ -51,9 +51,42 @@ class NextTurnAutomation{
}
}
private fun tryGainInfluence(civInfo: CivilizationInfo, cityState:CivilizationInfo){
if(civInfo.gold<250) return // save up
if(cityState.getDiplomacyManager(civInfo).influence<20){
civInfo.giveGoldGift(cityState,250)
return
}
if(civInfo.gold<500) return // it's not worth it to invest now, wait until you have enough for 2
civInfo.giveGoldGift(cityState,500)
return
}
/** allow AI to spend money to purchase city-state friendship, buildings & unit */
private fun useGold(civInfo: CivilizationInfo) {
if(civInfo.victoryType()==VictoryType.Cultural){
for(cityState in civInfo.gameInfo.civilizations
.filter { it.isCityState() && it.getCityStateType()==CityStateType.Cultured }){
val diploManager = cityState.getDiplomacyManager(civInfo)
if(diploManager.influence < 40){ // we want to gain influence with them
tryGainInfluence(civInfo,cityState)
return
}
}
}
if(civInfo.happiness < 5){
for(cityState in civInfo.gameInfo.civilizations
.filter { it.isCityState() && it.getCityStateType()==CityStateType.Mercantile }){
val diploManager = cityState.getDiplomacyManager(civInfo)
if(diploManager.influence < 40){ // we want to gain influence with them
tryGainInfluence(civInfo,cityState)
return
}
}
}
private fun buyBuildingOrUnit(civInfo: CivilizationInfo) {
//allow AI spending money to purchase building & unit
for (city in civInfo.cities.sortedByDescending{ it.population.population }) {
val construction = city.cityConstructions.getCurrentConstruction()
if (construction.canBePurchased()

View File

@ -599,5 +599,12 @@ class CivilizationInfo {
}
}
fun giveGoldGift(otherCiv: CivilizationInfo, giftAmount: Int) {
if(!otherCiv.isCityState()) throw Exception("You can only gain influence with city states!")
val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization()
currentPlayerCiv.gold -= giftAmount
otherCiv.getDiplomacyManager(currentPlayerCiv).influence += giftAmount/10
}
//endregion
}

View File

@ -58,7 +58,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val setCurrentTradesButton = TextButton("Trades".tr(),skin)
setCurrentTradesButton.onClick {
centerTable.clear()
centerTable.add(ScrollPane(getTradesTable())).height(stage.height*0.8f) // so it doesn't cover the naviagation buttons
centerTable.add(ScrollPane(getTradesTable())).height(stage.height*0.8f) // so it doesn't cover the navigation buttons
centerTable.pack()
}
topTable.add(setCurrentTradesButton)

View File

@ -85,13 +85,6 @@ class DiplomacyScreen:CameraStageBaseScreen() {
return tradeTable
}
fun giveGoldGift(otherCiv: CivilizationInfo, giftAmount: Int) {
if(!otherCiv.isCityState()) throw Exception("You can only gain influence with city states!")
val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization()
currentPlayerCiv.gold -= giftAmount
otherCiv.getDiplomacyManager(currentPlayerCiv).influence += giftAmount/10
updateRightSide(otherCiv)
}
private fun getCityStateDiplomacyTable(otherCiv: CivilizationInfo): Table {
@ -131,7 +124,10 @@ class DiplomacyScreen:CameraStageBaseScreen() {
val giftAmount = 250
val influenceAmount = giftAmount/10
val giftButton = TextButton("Gift [$giftAmount] gold (+[$influenceAmount] influence)".tr(), skin)
giftButton.onClick{ giveGoldGift(otherCiv,giftAmount ) }
giftButton.onClick{
currentPlayerCiv.giveGoldGift(otherCiv,giftAmount)
updateRightSide(otherCiv)
}
diplomacyTable.add(giftButton).row()
if (currentPlayerCiv.gold < giftAmount ) giftButton.disable()