mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 22:06:05 -04:00
Rearrange code for pruchasing stuff.
This commit is contained in:
parent
fa8c948c04
commit
a141cb1f1c
@ -22,11 +22,23 @@ class NextTurnAutomation{
|
|||||||
exchangeLuxuries(civInfo)
|
exchangeLuxuries(civInfo)
|
||||||
declareWar(civInfo)
|
declareWar(civInfo)
|
||||||
automateCityBombardment(civInfo)
|
automateCityBombardment(civInfo)
|
||||||
|
buyBuildingOrUnit(civInfo)
|
||||||
automateUnits(civInfo)
|
automateUnits(civInfo)
|
||||||
reassignWorkedTiles(civInfo)
|
reassignWorkedTiles(civInfo)
|
||||||
trainSettler(civInfo)
|
trainSettler(civInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buyBuildingOrUnit(civInfo: CivilizationInfo) {
|
||||||
|
//allow ai spending money to purchase building & unit. Buying staff has slightly lower priority than buying tech.
|
||||||
|
for (city in civInfo.cities.sortedByDescending{ it.population.population }) {
|
||||||
|
val construction = city.cityConstructions.getCurrentConstruction()
|
||||||
|
if (construction.canBePurchased()
|
||||||
|
&& city.civInfo.gold / 3 >= construction.getGoldCost(civInfo.policies.getAdoptedPolicies()) ) {
|
||||||
|
city.cityConstructions.purchaseBuilding(construction.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun exchangeTechs(civInfo: CivilizationInfo) {
|
private fun exchangeTechs(civInfo: CivilizationInfo) {
|
||||||
val otherCivList = civInfo.diplomacy.values.map { it.otherCiv() }.
|
val otherCivList = civInfo.diplomacy.values.map { it.otherCiv() }.
|
||||||
filter { it.playerType == PlayerType.AI && !it.isBarbarianCivilization() }.
|
filter { it.playerType == PlayerType.AI && !it.isBarbarianCivilization() }.
|
||||||
@ -51,7 +63,7 @@ class NextTurnAutomation{
|
|||||||
tradeLogic.currentTrade.theirOffers.add(theirOffer)
|
tradeLogic.currentTrade.theirOffers.add(theirOffer)
|
||||||
} else {
|
} else {
|
||||||
//try to buy tech with money, not spending more than 1/3 of treasury
|
//try to buy tech with money, not spending more than 1/3 of treasury
|
||||||
if (ourGold / 3 >= theirValue)
|
if (ourGold / 2 >= theirValue)
|
||||||
{
|
{
|
||||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer("Gold".tr(), TradeType.Gold, 0, theirValue))
|
tradeLogic.currentTrade.ourOffers.add(TradeOffer("Gold".tr(), TradeType.Gold, 0, theirValue))
|
||||||
tradeLogic.currentTrade.theirOffers.add(theirOffer)
|
tradeLogic.currentTrade.theirOffers.add(theirOffer)
|
||||||
@ -73,10 +85,14 @@ class NextTurnAutomation{
|
|||||||
val costs = techsGroups.keys.sorted()
|
val costs = techsGroups.keys.sorted()
|
||||||
|
|
||||||
val tech: Technology
|
val tech: Technology
|
||||||
if (techsGroups[costs[0]]!!.size == 1 || costs.size == 1) {
|
val techsCheapest = techsGroups[costs[0]]!!
|
||||||
tech = techsGroups[costs[0]]!!.getRandom()
|
//Do not consider advanced techs if only one tech left in cheapest groupe
|
||||||
|
if (techsCheapest.size == 1 || costs.size == 1) {
|
||||||
|
tech = techsCheapest.getRandom()
|
||||||
} else {
|
} else {
|
||||||
tech = (techsGroups[costs[0]]!! + techsGroups[costs[1]]!!).getRandom()
|
//Choose randomly between cheapest and second cheapest groupe
|
||||||
|
val techsAdvanced = techsGroups[costs[1]]!!
|
||||||
|
tech = (techsCheapest + techsAdvanced).getRandom()
|
||||||
}
|
}
|
||||||
civInfo.tech.techsToResearch.add(tech.name)
|
civInfo.tech.techsToResearch.add(tech.name)
|
||||||
}
|
}
|
||||||
@ -199,4 +215,4 @@ class NextTurnAutomation{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -126,11 +126,6 @@ class CityConstructions {
|
|||||||
inProgressConstructions[currentConstruction] = inProgressConstructions[currentConstruction]!! + productionToAdd
|
inProgressConstructions[currentConstruction] = inProgressConstructions[currentConstruction]!! + productionToAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
fun canBePruchasedWithGold(construction: IConstruction): Boolean {
|
|
||||||
return construction !is SpecialConstruction &&
|
|
||||||
!(construction is Building && construction.isWonder)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun nextTurn(cityStats: Stats) {
|
fun nextTurn(cityStats: Stats) {
|
||||||
var construction = getConstruction(currentConstruction)
|
var construction = getConstruction(currentConstruction)
|
||||||
if(construction is SpecialConstruction) return
|
if(construction is SpecialConstruction) return
|
||||||
@ -150,14 +145,6 @@ class CityConstructions {
|
|||||||
val productionCost = construction.getProductionCost(cityInfo.civInfo.policies.adoptedPolicies)
|
val productionCost = construction.getProductionCost(cityInfo.civInfo.policies.adoptedPolicies)
|
||||||
if (inProgressConstructions[currentConstruction]!! >= productionCost) {
|
if (inProgressConstructions[currentConstruction]!! >= productionCost) {
|
||||||
constructionComplete(construction)
|
constructionComplete(construction)
|
||||||
|
|
||||||
//allow ai spending money to purchase building & unit. Buying staff has slightly lower priority than buying tech.
|
|
||||||
while (cityInfo.civInfo.playerType == PlayerType.AI
|
|
||||||
&& cityInfo.population.population >= 5
|
|
||||||
&& canBePruchasedWithGold(getConstruction(currentConstruction))
|
|
||||||
&& cityInfo.civInfo.gold / 5 >= getConstruction(currentConstruction).getGoldCost(cityInfo.civInfo.policies.getAdoptedPolicies()) ) {
|
|
||||||
purchaseBuilding(currentConstruction)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ interface IConstruction : INamed, ICivilopedia {
|
|||||||
fun getGoldCost(adoptedPolicies: HashSet<String>): Int
|
fun getGoldCost(adoptedPolicies: HashSet<String>): Int
|
||||||
fun isBuildable(construction: CityConstructions): Boolean
|
fun isBuildable(construction: CityConstructions): Boolean
|
||||||
fun postBuildEvent(construction: CityConstructions) // Yes I'm hilarious.
|
fun postBuildEvent(construction: CityConstructions) // Yes I'm hilarious.
|
||||||
|
fun canBePurchased(): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -35,6 +36,9 @@ open class SpecialConstruction(override var name: String, override val descripti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun canBePurchased(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
override fun getProductionCost(adoptedPolicies: HashSet<String>): Int {
|
override fun getProductionCost(adoptedPolicies: HashSet<String>): Int {
|
||||||
throw Exception("Impossible!")
|
throw Exception("Impossible!")
|
||||||
|
@ -91,7 +91,7 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TradeType.Technology -> return sqrt(GameBasics.Technologies[offer.name]!!.cost.toDouble()).toInt()*10
|
TradeType.Technology -> return sqrt(GameBasics.Technologies[offer.name]!!.cost.toDouble()).toInt()*20
|
||||||
TradeType.Strategic_Resource -> {
|
TradeType.Strategic_Resource -> {
|
||||||
if(otherCivIsRecieving) {
|
if(otherCivIsRecieving) {
|
||||||
val resources = ourCivilization.getCivResourcesByName()
|
val resources = ourCivilization.getCivResourcesByName()
|
||||||
@ -211,4 +211,4 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
|
|||||||
transferTrade(ourCivilization,otherCivilization,currentTrade)
|
transferTrade(ourCivilization,otherCivilization,currentTrade)
|
||||||
transferTrade(otherCivilization,ourCivilization,currentTrade.reverse())
|
transferTrade(otherCivilization,ourCivilization,currentTrade.reverse())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,6 +149,9 @@ class Building : NamedStats(), IConstruction{
|
|||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun canBePurchased(): Boolean {
|
||||||
|
return !isWonder
|
||||||
|
}
|
||||||
|
|
||||||
override fun getProductionCost(adoptedPolicies: HashSet<String>): Int {
|
override fun getProductionCost(adoptedPolicies: HashSet<String>): Int {
|
||||||
return if (!isWonder && culture != 0f && adoptedPolicies.contains("Piety")) (cost * 0.85).toInt()
|
return if (!isWonder && culture != 0f && adoptedPolicies.contains("Piety")) (cost * 0.85).toInt()
|
||||||
|
@ -81,6 +81,10 @@ class BaseUnit : INamed, IConstruction, ICivilopedia {
|
|||||||
return unit
|
return unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun canBePurchased(): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override fun getProductionCost(adoptedPolicies: HashSet<String>): Int = cost
|
override fun getProductionCost(adoptedPolicies: HashSet<String>): Int = cost
|
||||||
|
|
||||||
override fun getGoldCost(adoptedPolicies: HashSet<String>): Int {
|
override fun getGoldCost(adoptedPolicies: HashSet<String>): Int {
|
||||||
|
@ -8,7 +8,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.city.IConstruction
|
|
||||||
import com.unciv.logic.city.SpecialConstruction
|
import com.unciv.logic.city.SpecialConstruction
|
||||||
import com.unciv.models.gamebasics.Building
|
import com.unciv.models.gamebasics.Building
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
@ -124,7 +123,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
|
|
||||||
row()
|
row()
|
||||||
val purchaseConstructionButton: TextButton
|
val purchaseConstructionButton: TextButton
|
||||||
if (city.cityConstructions.canBePruchasedWithGold(construction)) {
|
if (construction.canBePurchased()) {
|
||||||
val buildingGoldCost = construction.getGoldCost(city.civInfo.policies.getAdoptedPolicies())
|
val buildingGoldCost = construction.getGoldCost(city.civInfo.policies.getAdoptedPolicies())
|
||||||
purchaseConstructionButton = TextButton("Buy for [$buildingGoldCost] gold".tr(), CameraStageBaseScreen.skin)
|
purchaseConstructionButton = TextButton("Buy for [$buildingGoldCost] gold".tr(), CameraStageBaseScreen.skin)
|
||||||
purchaseConstructionButton.onClick("coin") {
|
purchaseConstructionButton.onClick("coin") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user