mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-10 02:47:24 +07:00
Fixed bugs that prevented picking Gold and Science as city constructions
This commit is contained in:
parent
9c576d6bdc
commit
a1995a3e37
@ -70,6 +70,10 @@ class CityConstructions {
|
||||
return GameBasics.Buildings[constructionName]!!
|
||||
else if (GameBasics.Units.containsKey(constructionName))
|
||||
return GameBasics.Units[constructionName]!!
|
||||
else{
|
||||
val special = getSpecialConstructions().firstOrNull{it.name==constructionName}
|
||||
if(special!=null) return special
|
||||
}
|
||||
|
||||
throw Exception("$constructionName is not a building or a unit!")
|
||||
}
|
||||
@ -83,6 +87,7 @@ class CityConstructions {
|
||||
|
||||
fun nextTurn(cityStats: Stats) {
|
||||
var construction = getConstruction(currentConstruction)
|
||||
if(construction is SpecialConstruction) return
|
||||
|
||||
// Let's try to remove the building from the city, and see if we can still build it (we need to remove because of wonders etc.)
|
||||
val saveCurrentConstruction = currentConstruction
|
||||
@ -151,4 +156,18 @@ class CityConstructions {
|
||||
fun chooseNextConstruction() {
|
||||
Automation().chooseNextConstruction(this)
|
||||
}
|
||||
|
||||
fun getSpecialConstructions(): List<SpecialConstruction> {
|
||||
val science = object:SpecialConstruction("Science", "Convert production to science at a rate of 4 to 1"){
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return construction.cityInfo.civInfo.tech.isResearched("Education")
|
||||
}
|
||||
}
|
||||
val gold = object:SpecialConstruction("Gold", "Convert production to gold at a rate of 4 to 1"){
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return construction.cityInfo.civInfo.tech.isResearched("Currency")
|
||||
}
|
||||
}
|
||||
return listOf(science,gold)
|
||||
}
|
||||
} // for json parsing, we need to have a default constructor
|
@ -37,15 +37,17 @@ class CityStats {
|
||||
}
|
||||
|
||||
|
||||
private fun getStatsFromProduction(): Stats {
|
||||
private fun getStatsFromProduction(production:Float): Stats {
|
||||
val stats = Stats()
|
||||
|
||||
if ("Gold" == cityInfo.cityConstructions.currentConstruction) stats.gold += stats.production / 4
|
||||
if ("Science" == cityInfo.cityConstructions.currentConstruction) {
|
||||
var scienceProduced = stats.production / 4
|
||||
if (cityInfo.civInfo.buildingUniques.contains("ScienceConversionIncrease")) scienceProduced *= 1.33f
|
||||
if (cityInfo.civInfo.policies.isAdopted("Rationalism")) scienceProduced *= 1.33f
|
||||
stats.science += scienceProduced
|
||||
when(cityInfo.cityConstructions.currentConstruction) {
|
||||
"Gold" -> stats.gold += production / 4
|
||||
"Science" -> {
|
||||
var scienceProduced = production / 4
|
||||
if (cityInfo.civInfo.buildingUniques.contains("ScienceConversionIncrease")) scienceProduced *= 1.33f
|
||||
if (cityInfo.civInfo.policies.isAdopted("Rationalism")) scienceProduced *= 1.33f
|
||||
stats.science += scienceProduced
|
||||
}
|
||||
}
|
||||
return stats
|
||||
}
|
||||
@ -208,7 +210,9 @@ class CityStats {
|
||||
for (stat in baseStatList.values) stats.add(stat)
|
||||
stats.production *= 1 + statPercentBonuses.production / 100 // So they get bonuses for production and gold/science
|
||||
|
||||
stats.add(getStatsFromProduction())
|
||||
val statsFromProduction = getStatsFromProduction(stats.production)
|
||||
stats.add(statsFromProduction)
|
||||
baseStatList["Construction"] = statsFromProduction
|
||||
|
||||
|
||||
stats.gold *= 1 + statPercentBonuses.gold / 100
|
||||
|
@ -1,10 +1,47 @@
|
||||
package com.unciv.logic.city
|
||||
|
||||
import com.unciv.models.gamebasics.ICivilopedia
|
||||
import com.unciv.models.stats.INamed
|
||||
|
||||
interface IConstruction : INamed {
|
||||
interface IConstruction : INamed, ICivilopedia {
|
||||
fun getProductionCost(adoptedPolicies: HashSet<String>): Int
|
||||
fun getGoldCost(adoptedPolicies: HashSet<String>): Int
|
||||
fun isBuildable(construction: CityConstructions): Boolean
|
||||
fun postBuildEvent(construction: CityConstructions) // Yes I'm hilarious.
|
||||
}
|
||||
|
||||
|
||||
|
||||
open class SpecialConstruction(override var name: String, override val description: String) : IConstruction{
|
||||
|
||||
fun getSpecialConstructions(): List<SpecialConstruction> {
|
||||
val science = object:SpecialConstruction("Science", "Convert production to science at a rate of 4 to 1"){
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return construction.cityInfo.civInfo.tech.isResearched("Education")
|
||||
}
|
||||
}
|
||||
val gold = object:SpecialConstruction("Gold", "Convert production to gold at a rate of 4 to 1"){
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return construction.cityInfo.civInfo.tech.isResearched("Currency")
|
||||
}
|
||||
}
|
||||
return listOf(science,gold)
|
||||
}
|
||||
|
||||
override fun getProductionCost(adoptedPolicies: HashSet<String>): Int {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun getGoldCost(adoptedPolicies: HashSet<String>): Int {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun postBuildEvent(construction: CityConstructions) {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import com.unciv.models.stats.Stats
|
||||
import com.unciv.ui.VictoryScreen
|
||||
import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
||||
|
||||
class Building : NamedStats(), IConstruction, ICivilopedia {
|
||||
class Building : NamedStats(), IConstruction{
|
||||
private lateinit var baseDescription: String
|
||||
override val description: String
|
||||
get() = getDescription(false, hashSetOf())
|
||||
|
@ -4,8 +4,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.models.gamebasics.Building
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.city.SpecialConstruction
|
||||
import com.unciv.models.gamebasics.Building
|
||||
import com.unciv.ui.pickerscreens.ConstructionPickerScreen
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
@ -57,7 +58,8 @@ class CityStatsTable(val cityScreen: CityScreen) : Table(){
|
||||
|
||||
// https://forums.civfanatics.com/threads/rush-buying-formula.393892/
|
||||
val construction = city.cityConstructions.getCurrentConstruction()
|
||||
if (!(construction is Building && construction.isWonder)) {
|
||||
if (construction !is SpecialConstruction &&
|
||||
!(construction is Building && construction.isWonder)) {
|
||||
row()
|
||||
val buildingGoldCost = construction.getGoldCost(city.civInfo.policies.getAdoptedPolicies())
|
||||
val buildingBuyButton = TextButton("Buy for \r\n$buildingGoldCost gold", CameraStageBaseScreen.skin)
|
||||
|
@ -6,14 +6,13 @@ import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.cityscreen.CityScreen
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
|
||||
class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
||||
private var selectedProduction: String? = null
|
||||
|
||||
private fun getProductionButton(production: String, buttonText: String,
|
||||
description: String?, rightSideButtonText: String): TextButton {
|
||||
val productionTextButton = TextButton(buttonText, CameraStageBaseScreen.skin)
|
||||
val productionTextButton = TextButton(buttonText, skin)
|
||||
productionTextButton.addClickListener {
|
||||
selectedProduction = production
|
||||
pick(rightSideButtonText)
|
||||
@ -63,13 +62,10 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
||||
unit.getDescription(true), "Train " + unit.name))
|
||||
}
|
||||
|
||||
if (civInfo.tech.isResearched("Education"))
|
||||
specials.addActor(getProductionButton("Science", "Produce Science",
|
||||
"Convert production to science at a rate of 4 to 1", "Produce Science"))
|
||||
|
||||
if (civInfo.tech.isResearched("Currency"))
|
||||
specials.addActor(getProductionButton("Gold", "Produce Gold",
|
||||
"Convert production to gold at a rate of 4 to 1", "Produce Gold"))
|
||||
for(specialConstruction in cityConstructions.getSpecialConstructions().filter { it.isBuildable(cityConstructions) }){
|
||||
specials.addActor(getProductionButton(specialConstruction.name, "Produce ${specialConstruction.name}",
|
||||
specialConstruction.description, "Produce ${specialConstruction.name}"))
|
||||
}
|
||||
|
||||
topTable.add(units)
|
||||
topTable.add(regularBuildings)
|
||||
|
@ -6,7 +6,6 @@ import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
@ -64,7 +63,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
|
||||
widget = allTiles
|
||||
setFillParent(true)
|
||||
setOrigin(Align.center)
|
||||
setOrigin(worldScreen.stage.width/2,worldScreen.stage.height/2)
|
||||
setSize(worldScreen.stage.width, worldScreen.stage.height)
|
||||
addListener(object : ActorGestureListener() {
|
||||
var lastScale = 1f
|
||||
|
Loading…
Reference in New Issue
Block a user