mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-23 06:08:46 +07:00
Added gold-to-science conversion for Civ IV rules
This commit is contained in:
@ -450,11 +450,22 @@ class CityStats {
|
||||
val isUnhappy = cityInfo.civInfo.getHappiness() < 0
|
||||
for (entry in newFinalStatList.values) {
|
||||
entry.gold *= 1 + statPercentBonusesSum.gold / 100
|
||||
entry.science *= 1 + statPercentBonusesSum.science / 100
|
||||
entry.culture *= 1 + statPercentBonusesSum.culture / 100
|
||||
if (!isUnhappy) entry.food *= 1 + statPercentBonusesSum.food / 100 // Regular food bonus revoked when unhappy per https://forums.civfanatics.com/resources/complete-guide-to-happiness-vanilla.25584/
|
||||
}
|
||||
|
||||
// AFTER we've gotten all the gold stats figured out, only THEN do we plonk that gold into Science
|
||||
if (cityInfo.getRuleset().modOptions.uniques.contains("Can convert gold to science with sliders")) {
|
||||
val amountConverted = (newFinalStatList.values.sumByDouble { it.gold.toDouble() }
|
||||
* cityInfo.civInfo.tech.goldPercentConvertedToScience).toInt().toFloat()
|
||||
if (amountConverted > 0) // Don't want you converting negative gold to negative science yaknow
|
||||
newFinalStatList["Gold -> Science"] = Stats().apply { science = amountConverted; gold = -amountConverted }
|
||||
}
|
||||
for (entry in newFinalStatList.values) {
|
||||
entry.science *= 1 + statPercentBonusesSum.science / 100
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
/* Okay, food calculation is complicated.
|
||||
First we see how much food we generate. Then we apply production bonuses to it.
|
||||
|
@ -40,6 +40,9 @@ class TechManager {
|
||||
private var techsInProgress = HashMap<String, Int>()
|
||||
var overflowScience = 0
|
||||
|
||||
/** In civ IV, you can auto-convert a certain percentage of gold in cities to science */
|
||||
var goldPercentConvertedToScience = 0.6f
|
||||
|
||||
//region state-changing functions
|
||||
fun clone(): TechManager {
|
||||
val toReturn = TechManager()
|
||||
@ -50,6 +53,7 @@ class TechManager {
|
||||
toReturn.scienceOfLast8Turns = scienceOfLast8Turns.clone()
|
||||
toReturn.scienceFromResearchAgreements = scienceFromResearchAgreements
|
||||
toReturn.overflowScience = overflowScience
|
||||
toReturn.goldPercentConvertedToScience = goldPercentConvertedToScience
|
||||
return toReturn
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ class MapUnit {
|
||||
var currentMovement: Float = 0f
|
||||
var health:Int = 100
|
||||
|
||||
// todo: I see this is being serialized, should it be Transient?
|
||||
var mapUnitAction : MapUnitAction? = null
|
||||
|
||||
var action: String? // work, automation, fortifying, I dunno what.
|
||||
|
@ -9,7 +9,7 @@ import com.unciv.models.translations.tr
|
||||
class Promotion : INamed{
|
||||
override lateinit var name: String
|
||||
var prerequisites = listOf<String>()
|
||||
lateinit var effect:String
|
||||
var effect=""
|
||||
val unique:Unique by lazy { Unique(effect) }
|
||||
var unitTypes = listOf<String>() // The json parser wouldn't agree to deserialize this as a list of UnitTypes. =(
|
||||
|
||||
@ -19,11 +19,11 @@ class Promotion : INamed{
|
||||
stringBuilder.appendln(Translations.translateBonusOrPenalty(effect.tr()))
|
||||
|
||||
if(prerequisites.isNotEmpty()) {
|
||||
val prerequisitesString:ArrayList<String> = arrayListOf()
|
||||
for (i in prerequisites.filter { promotionsForUnitType.any { promotion -> promotion.name==it } }){
|
||||
val prerequisitesString: ArrayList<String> = arrayListOf()
|
||||
for (i in prerequisites.filter { promotionsForUnitType.any { promotion -> promotion.name == it } }) {
|
||||
prerequisitesString.add(i.tr())
|
||||
}
|
||||
stringBuilder.appendln("{Requires}: ".tr()+prerequisitesString.joinToString(" OR ".tr()))
|
||||
stringBuilder.appendln("{Requires}: ".tr() + prerequisitesString.joinToString(" OR ".tr()))
|
||||
}
|
||||
if(forCivilopedia){
|
||||
if (unitTypes.isNotEmpty()) {
|
||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Slider
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.Constants
|
||||
@ -26,6 +27,7 @@ class EmpireOverviewScreen(private var viewingPlayer:CivilizationInfo, defaultPa
|
||||
private val topTable = Table().apply { defaults().pad(10f) }
|
||||
private val centerTable = Table().apply { defaults().pad(5f) }
|
||||
|
||||
|
||||
init {
|
||||
onBackButtonClicked { game.setWorldScreen() }
|
||||
val clicks = HashMap<String,() -> Unit>()
|
||||
@ -46,20 +48,8 @@ class EmpireOverviewScreen(private var viewingPlayer:CivilizationInfo, defaultPa
|
||||
topTable.add(setCityInfoButton)
|
||||
|
||||
val setStatsInfoButton = "Stats".toTextButton()
|
||||
val setStats = {
|
||||
game.settings.addCompletedTutorialTask("See your stats breakdown")
|
||||
centerTable.clear()
|
||||
centerTable.add(ScrollPane(Table().apply {
|
||||
defaults().pad(40f)
|
||||
add(getHappinessTable()).top()
|
||||
add(getGoldTable()).top()
|
||||
add(getScienceTable()).top()
|
||||
add(getGreatPeopleTable()).top()
|
||||
}))
|
||||
centerTable.pack()
|
||||
}
|
||||
clicks["Stats"] = setStats
|
||||
setStatsInfoButton.onClick(setStats)
|
||||
clicks["Stats"] = {setStats()}
|
||||
setStatsInfoButton.onClick{setStats()}
|
||||
topTable.add(setStatsInfoButton)
|
||||
|
||||
val setCurrentTradesButton = "Trades".toTextButton()
|
||||
@ -150,6 +140,19 @@ class EmpireOverviewScreen(private var viewingPlayer:CivilizationInfo, defaultPa
|
||||
stage.addActor(table)
|
||||
}
|
||||
|
||||
private fun setStats() {
|
||||
game.settings.addCompletedTutorialTask("See your stats breakdown")
|
||||
centerTable.clear()
|
||||
centerTable.add(ScrollPane(Table().apply {
|
||||
defaults().pad(40f)
|
||||
add(getHappinessTable()).top()
|
||||
add(getGoldTable()).top()
|
||||
add(getScienceTable()).top()
|
||||
add(getGreatPeopleTable()).top()
|
||||
}))
|
||||
centerTable.pack()
|
||||
}
|
||||
|
||||
private fun getTradesTable(): Table {
|
||||
val tradesTable = Table().apply { defaults().pad(10f) }
|
||||
val diplomacies = viewingPlayer.diplomacy.values.filter { it.trades.isNotEmpty() }
|
||||
@ -221,19 +224,36 @@ class EmpireOverviewScreen(private var viewingPlayer:CivilizationInfo, defaultPa
|
||||
val goldTable = Table(skin)
|
||||
goldTable.defaults().pad(5f)
|
||||
val goldHeader = Table(skin)
|
||||
goldHeader.add(ImageGetter.getStatIcon("Gold")).pad(5f,0f,5f,12f).size(20f)
|
||||
goldHeader.add(ImageGetter.getStatIcon("Gold")).pad(5f, 0f, 5f, 12f).size(20f)
|
||||
goldHeader.add("Gold".toLabel(fontSize = 24)).padTop(5f)
|
||||
goldTable.add(goldHeader).colspan(2).row()
|
||||
goldTable.addSeparator()
|
||||
var total=0f
|
||||
var total = 0f
|
||||
for (entry in viewingPlayer.stats().getStatMapForNextTurn()) {
|
||||
if(entry.value.gold==0f) continue
|
||||
if (entry.value.gold == 0f) continue
|
||||
goldTable.add(entry.key.tr())
|
||||
goldTable.add(entry.value.gold.roundToInt().toString()).right().row()
|
||||
total += entry.value.gold
|
||||
}
|
||||
goldTable.add("Total".tr())
|
||||
goldTable.add(total.roundToInt().toString()).right()
|
||||
|
||||
if(viewingPlayer.gameInfo.ruleSet.modOptions.uniques.contains("Can convert gold to science with sliders")) {
|
||||
goldTable.addSeparator()
|
||||
val sliderTable = Table()
|
||||
sliderTable.add("Convert gold to science".toLabel()).row()
|
||||
val slider = Slider(0f, 1f, 0.1f, false, skin)
|
||||
slider.value = viewingPlayer.tech.goldPercentConvertedToScience
|
||||
|
||||
slider.onChange {
|
||||
viewingPlayer.tech.goldPercentConvertedToScience = slider.value
|
||||
viewingPlayer.cities.forEach { it.cityStats.update() }
|
||||
setStats()
|
||||
}
|
||||
sliderTable.add(slider)
|
||||
goldTable.add(sliderTable).colspan(2)
|
||||
}
|
||||
|
||||
goldTable.pack()
|
||||
return goldTable
|
||||
}
|
||||
|
Reference in New Issue
Block a user