mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-30 07:21:34 -04:00
Years per turn improvement (#2607)
* Year issue fix * Clean up and try * real good update * udf
This commit is contained in:
parent
8877c18f31
commit
67f7e67f55
@ -1,4 +1,5 @@
|
||||
[
|
||||
|
||||
{
|
||||
"name": "Farm",
|
||||
"terrainsCanBeBuiltOn": ["Plains","Grassland","Desert","Flood plains"],
|
||||
|
@ -25,7 +25,6 @@ class TileImprovement : NamedStats() {
|
||||
|
||||
val turnsToBuild: Int = 0 // This is the base cost.
|
||||
|
||||
|
||||
fun getTurnsToBuild(civInfo: CivilizationInfo): Int {
|
||||
var realTurnsToBuild = turnsToBuild.toFloat() * civInfo.gameInfo.gameParameters.gameSpeed.modifier
|
||||
if (civInfo.containsBuildingUnique("Worker construction increased 25%"))
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.ui.worldscreen
|
||||
|
||||
import com.badlogic.gdx.Game
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
@ -7,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.metadata.GameSpeed
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.models.translations.tr
|
||||
@ -16,9 +18,11 @@ import com.unciv.ui.pickerscreens.TechPickerScreen
|
||||
import com.unciv.ui.utils.*
|
||||
import com.unciv.ui.victoryscreen.VictoryScreen
|
||||
import com.unciv.ui.worldscreen.mainmenu.WorldScreenMenuPopup
|
||||
import java.time.Year
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
||||
|
||||
@ -30,6 +34,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
||||
private val resourceLabels = HashMap<String, Label>()
|
||||
private val resourceImages = HashMap<String, Actor>()
|
||||
private val happinessImage = Group()
|
||||
|
||||
// These are all to improve performance IE reduce update time (was 150 ms on my phone, which is a lot!)
|
||||
private val malcontentColor = Color.valueOf("ef5350")
|
||||
private val happinessColor = colorFromRGB(92, 194, 77)
|
||||
@ -139,18 +144,21 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
||||
else resourceLabels[resource.name]!!.setText(civResources.first { it.resource == resource }.amount.toString())
|
||||
}
|
||||
|
||||
val marathon = listOf<YearsToTurn>(YearsToTurn(100, 15.0), YearsToTurn(400, 10.0), YearsToTurn(570, 5.0), YearsToTurn(771, 2.0), YearsToTurn(900, 1.0), YearsToTurn(1000, 0.5), YearsToTurn(1500, 0.25))
|
||||
val epic = listOf<YearsToTurn>(YearsToTurn(140, 25.0), YearsToTurn(230, 15.0), YearsToTurn(270, 10.0), YearsToTurn(360, 5.0), YearsToTurn(430, 2.0), YearsToTurn(530, 1.0), YearsToTurn(1500, 0.5))
|
||||
val standard = listOf<YearsToTurn>(YearsToTurn(75, 40.0), YearsToTurn(135, 25.0), YearsToTurn(160, 15.0), YearsToTurn(211, 10.0), YearsToTurn(270, 5.0), YearsToTurn(315, 2.0), YearsToTurn(440, 1.0))
|
||||
val quick = listOf<YearsToTurn>(YearsToTurn(50, 60.0), YearsToTurn(80, 40.0), YearsToTurn(100, 25.0), YearsToTurn(130, 15.0), YearsToTurn(155, 10.0), YearsToTurn(195, 5.0), YearsToTurn(260, 2.0))
|
||||
|
||||
val turns = civInfo.gameInfo.turns
|
||||
val year = when{
|
||||
turns<=75 -> -4000+turns*40
|
||||
turns<=135 -> -1000+(turns-75)*25
|
||||
turns<=160 -> 500+(turns-135)*20
|
||||
turns<=210 -> 1000+(turns-160)*10
|
||||
turns<=270 -> 1500+(turns-210)*5
|
||||
turns<=320 -> 1800+(turns-270)*2
|
||||
turns<=440 -> 1900+(turns-320)
|
||||
else -> 2020+(turns-440)/2
|
||||
val gameSpeed: List<YearsToTurn> = when (civInfo.gameInfo.gameParameters.gameSpeed) {
|
||||
GameSpeed.Marathon -> marathon
|
||||
GameSpeed.Epic -> epic
|
||||
GameSpeed.Standard -> standard
|
||||
GameSpeed.Quick -> quick
|
||||
}
|
||||
|
||||
val year = getYear(gameSpeed, turns).toInt()
|
||||
|
||||
val yearText = "[" + abs(year) + "] " + if (year < 0) "BC" else "AD"
|
||||
turnsLabel.setText("Turn".tr() + " " + civInfo.gameInfo.turns + " | " + yearText.tr())
|
||||
turnsLabel.onClick { worldScreen.game.setScreen(VictoryScreen(worldScreen)) }
|
||||
@ -196,4 +204,21 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
||||
return happinessText
|
||||
}
|
||||
|
||||
private class YearsToTurn(val toTurn: Int, val yearInterval: Double) // enum class with lists for each value group potentially more efficient?
|
||||
|
||||
|
||||
|
||||
private fun getYear(speed: List<YearsToTurn>, turn: Int): Float {
|
||||
var year: Float = -4000f
|
||||
var i: Int = 0;
|
||||
var yearsPerTurn: Float
|
||||
// if macros are ever added to kotlin, this is one hell of a place for em'
|
||||
while (i < turn) {
|
||||
yearsPerTurn = speed.firstOrNull { turn < it.toTurn }?.yearInterval?.toFloat() ?: 0.5f
|
||||
year += yearsPerTurn;
|
||||
++i;
|
||||
}
|
||||
|
||||
return year
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user