mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 06:51:30 -04:00
AI now saves up money to use for purchasing city-state influence
This commit is contained in:
parent
2b3de8b78f
commit
5cf05cd7d9
@ -32,7 +32,7 @@ class NextTurnAutomation{
|
|||||||
updateDiplomaticRelationship(civInfo)
|
updateDiplomaticRelationship(civInfo)
|
||||||
declareWar(civInfo)
|
declareWar(civInfo)
|
||||||
automateCityBombardment(civInfo)
|
automateCityBombardment(civInfo)
|
||||||
buyBuildingOrUnit(civInfo)
|
useGold(civInfo)
|
||||||
automateUnits(civInfo)
|
automateUnits(civInfo)
|
||||||
reassignWorkedTiles(civInfo)
|
reassignWorkedTiles(civInfo)
|
||||||
trainSettler(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 }) {
|
for (city in civInfo.cities.sortedByDescending{ it.population.population }) {
|
||||||
val construction = city.cityConstructions.getCurrentConstruction()
|
val construction = city.cityConstructions.getCurrentConstruction()
|
||||||
if (construction.canBePurchased()
|
if (construction.canBePurchased()
|
||||||
|
@ -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
|
//endregion
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
|||||||
val setCurrentTradesButton = TextButton("Trades".tr(),skin)
|
val setCurrentTradesButton = TextButton("Trades".tr(),skin)
|
||||||
setCurrentTradesButton.onClick {
|
setCurrentTradesButton.onClick {
|
||||||
centerTable.clear()
|
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()
|
centerTable.pack()
|
||||||
}
|
}
|
||||||
topTable.add(setCurrentTradesButton)
|
topTable.add(setCurrentTradesButton)
|
||||||
|
@ -85,13 +85,6 @@ class DiplomacyScreen:CameraStageBaseScreen() {
|
|||||||
return tradeTable
|
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 {
|
private fun getCityStateDiplomacyTable(otherCiv: CivilizationInfo): Table {
|
||||||
@ -131,7 +124,10 @@ class DiplomacyScreen:CameraStageBaseScreen() {
|
|||||||
val giftAmount = 250
|
val giftAmount = 250
|
||||||
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{ giveGoldGift(otherCiv,giftAmount ) }
|
giftButton.onClick{
|
||||||
|
currentPlayerCiv.giveGoldGift(otherCiv,giftAmount)
|
||||||
|
updateRightSide(otherCiv)
|
||||||
|
}
|
||||||
diplomacyTable.add(giftButton).row()
|
diplomacyTable.add(giftButton).row()
|
||||||
if (currentPlayerCiv.gold < giftAmount ) giftButton.disable()
|
if (currentPlayerCiv.gold < giftAmount ) giftButton.disable()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user