mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Kotlin 1.5 new warnings - the rest (#5151)
This commit is contained in:
parent
9ff8435a21
commit
8b210fb798
@ -208,7 +208,7 @@ object HexMath {
|
||||
val top = height / 2 - (x + y) / 2
|
||||
// kotlin's Int division rounds in different directions depending on sign! Thus 1 extra `-1`
|
||||
val bottom = (x + y - 1) / 2 + (height - 1) / 2
|
||||
return min(min(left, right), min(top, bottom))
|
||||
return minOf(left, right, top, bottom)
|
||||
} else {
|
||||
val radius = mapParameters.mapSize.radius
|
||||
if (mapParameters.worldWrap) {
|
||||
|
@ -170,7 +170,7 @@ object BattleDamage {
|
||||
} else if (attacker is CityCombatant) {
|
||||
if (attacker.city.getCenterTile().militaryUnit != null) {
|
||||
val garrisonBonus = attacker.city.getMatchingUniques("+[]% attacking strength for cities with garrisoned units")
|
||||
.sumBy { it.params[0].toInt() }
|
||||
.sumOf { it.params[0].toInt() }
|
||||
if (garrisonBonus != 0)
|
||||
modifiers["Garrisoned unit"] = garrisonBonus
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class CityCombatant(val city: CityInfo) : ICombatant {
|
||||
if (cityTile.militaryUnit != null)
|
||||
strength += cityTile.militaryUnit!!.baseUnit().strength * (cityTile.militaryUnit!!.health / 100f) * 0.2f
|
||||
|
||||
var buildingsStrength = city.cityConstructions.getBuiltBuildings().sumBy { it.cityStrength }.toFloat()
|
||||
var buildingsStrength = city.cityConstructions.getBuiltBuildings().sumOf { it.cityStrength }.toFloat()
|
||||
if (getCivInfo().hasUnique("Defensive buildings in all cities are 25% more effective"))
|
||||
buildingsStrength *= 1.25f
|
||||
strength += buildingsStrength
|
||||
|
@ -3,7 +3,6 @@ package com.unciv.logic.city
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.logic.battle.CityCombatant
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.GreatPersonManager
|
||||
import com.unciv.logic.civilization.ReligionState
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
@ -15,10 +14,7 @@ import com.unciv.models.ruleset.tile.ResourceSupplyList
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.translations.equalsPlaceholderText
|
||||
import com.unciv.models.translations.getPlaceholderParameters
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.collections.HashSet
|
||||
import kotlin.math.ceil
|
||||
@ -27,6 +23,7 @@ import kotlin.math.pow
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class CityInfo {
|
||||
@Suppress("JoinDeclarationAndAssignment")
|
||||
@Transient
|
||||
lateinit var civInfo: CivilizationInfo
|
||||
|
||||
@ -87,7 +84,7 @@ class CityInfo {
|
||||
this.civInfo = civInfo
|
||||
foundingCiv = civInfo.civName
|
||||
turnAcquired = civInfo.gameInfo.turns
|
||||
this.location = cityLocation
|
||||
location = cityLocation
|
||||
setTransients()
|
||||
|
||||
setNewCityName(civInfo)
|
||||
@ -248,10 +245,9 @@ class CityInfo {
|
||||
val indicatorBuildings = getRuleset().buildings.values
|
||||
.asSequence()
|
||||
.filter { it.uniques.contains("Indicates the capital city") }
|
||||
|
||||
|
||||
val civSpecificBuilding = indicatorBuildings.firstOrNull { it.uniqueTo == civInfo.civName }
|
||||
if (civSpecificBuilding != null) return civSpecificBuilding.name
|
||||
else return indicatorBuildings.first().name
|
||||
return civSpecificBuilding?.name ?: indicatorBuildings.first().name
|
||||
}
|
||||
|
||||
fun isConnectedToCapital(connectionTypePredicate: (Set<String>) -> Boolean = { true }): Boolean {
|
||||
@ -382,7 +378,7 @@ class CityInfo {
|
||||
buildingsCounter.add(building.greatPersonPoints)
|
||||
sourceToGPP["Buildings"] = buildingsCounter
|
||||
|
||||
for ((source, gppCounter) in sourceToGPP) {
|
||||
for ((_, gppCounter) in sourceToGPP) {
|
||||
for (unique in civInfo.getMatchingUniques("[] is earned []% faster")) {
|
||||
val unitName = unique.params[0]
|
||||
if (!gppCounter.containsKey(unitName)) continue
|
||||
@ -437,7 +433,7 @@ class CityInfo {
|
||||
}
|
||||
|
||||
internal fun getMaxHealth() =
|
||||
200 + cityConstructions.getBuiltBuildings().sumBy { it.cityHealth }
|
||||
200 + cityConstructions.getBuiltBuildings().sumOf { it.cityHealth }
|
||||
|
||||
override fun toString() = name // for debug
|
||||
//endregion
|
||||
@ -498,7 +494,7 @@ class CityInfo {
|
||||
if (isBeingRazed) {
|
||||
val removedPopulation =
|
||||
1 + civInfo.getMatchingUniques("Cities are razed [] times as fast")
|
||||
.sumBy { it.params[0].toInt() - 1 }
|
||||
.sumOf { it.params[0].toInt() - 1 }
|
||||
population.addPopulation(-1 * removedPopulation)
|
||||
if (population.population <= 0) {
|
||||
civInfo.addNotification(
|
||||
|
@ -20,7 +20,7 @@ import kotlin.random.Random
|
||||
/** Helper class for containing 200 lines of "how to move cities between civs" */
|
||||
class CityInfoConquestFunctions(val city: CityInfo){
|
||||
private val tileBasedRandom = Random(city.getCenterTile().position.toString().hashCode())
|
||||
|
||||
|
||||
private fun getGoldForCapturingCity(conqueringCiv: CivilizationInfo): Int {
|
||||
val baseGold = 20 + 10 * city.population.population + tileBasedRandom.nextInt(40)
|
||||
val turnModifier = max(0, min(50, city.civInfo.gameInfo.turns - city.turnAcquired)) / 50f
|
||||
@ -30,7 +30,7 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
val goldPlundered = baseGold * turnModifier * cityModifier * conqueringCivModifier
|
||||
return goldPlundered.toInt()
|
||||
}
|
||||
|
||||
|
||||
private fun destroyBuildingsOnCapture() {
|
||||
city.apply {
|
||||
for (building in cityConstructions.getBuiltBuildings()) {
|
||||
@ -47,7 +47,7 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Function for stuff that should happen on any capture, be it puppet, annex or liberate.
|
||||
* Stuff that should happen any time a city is moved between civs, so also when trading,
|
||||
* should go in `this.moveToCiv()`, which this function also calls.
|
||||
@ -59,11 +59,11 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
conqueringCiv.addNotification("Received [$goldPlundered] Gold for capturing [$name]", getCenterTile().position, NotificationIcon.Gold)
|
||||
|
||||
val reconqueredCityWhileStillInResistance = previousOwner == conqueringCiv.civName && resistanceCounter != 0
|
||||
|
||||
|
||||
this@CityInfoConquestFunctions.moveToCiv(receivingCiv)
|
||||
|
||||
destroyBuildingsOnCapture()
|
||||
|
||||
|
||||
Battle.destroyIfDefeated(conqueredCiv, conqueringCiv)
|
||||
|
||||
health = getMaxHealth() / 2 // I think that cities recover to half health when conquered?
|
||||
@ -80,9 +80,9 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
/** This happens when we either puppet OR annex, basically whenever we conquer a city and don't liberate it */
|
||||
fun puppetCity(conqueringCiv: CivilizationInfo) {
|
||||
// Gain gold for plundering city
|
||||
val goldPlundered = getGoldForCapturingCity(conqueringCiv)
|
||||
val goldPlundered = getGoldForCapturingCity(conqueringCiv) // todo: use this val
|
||||
city.apply {
|
||||
|
||||
|
||||
val oldCiv = civInfo
|
||||
|
||||
// must be before moving the city to the conquering civ,
|
||||
@ -90,7 +90,7 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
diplomaticRepercussionsForConqueringCity(oldCiv, conqueringCiv)
|
||||
|
||||
conquerCity(conqueringCiv, oldCiv, conqueringCiv)
|
||||
|
||||
|
||||
isPuppet = true
|
||||
cityStats.update()
|
||||
// The city could be producing something that puppets shouldn't, like units
|
||||
@ -111,7 +111,7 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
private fun diplomaticRepercussionsForConqueringCity(oldCiv: CivilizationInfo, conqueringCiv: CivilizationInfo) {
|
||||
val currentPopulation = city.population.population
|
||||
val percentageOfCivPopulationInThatCity = currentPopulation * 100f /
|
||||
oldCiv.cities.sumBy { it.population.population }
|
||||
oldCiv.cities.sumOf { it.population.population }
|
||||
val aggroGenerated = 10f + percentageOfCivPopulationInThatCity.roundToInt()
|
||||
|
||||
// How can you conquer a city but not know the civ you conquered it from?!
|
||||
@ -147,9 +147,9 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
diploManager.makePeace()
|
||||
|
||||
val oldCiv = civInfo
|
||||
|
||||
|
||||
diplomaticRepercussionsForLiberatingCity(conqueringCiv, oldCiv)
|
||||
|
||||
|
||||
conquerCity(conqueringCiv, oldCiv, foundingCiv)
|
||||
|
||||
if (foundingCiv.cities.size == 1) cityConstructions.addBuilding(capitalCityIndicator()) // Resurrection!
|
||||
@ -169,7 +169,7 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
private fun diplomaticRepercussionsForLiberatingCity(conqueringCiv: CivilizationInfo, conqueredCiv: CivilizationInfo) {
|
||||
val foundingCiv = conqueredCiv.gameInfo.civilizations.first { it.civName == city.foundingCiv }
|
||||
val percentageOfCivPopulationInThatCity = city.population.population *
|
||||
100f / (foundingCiv.cities.sumBy { it.population.population } + city.population.population)
|
||||
100f / (foundingCiv.cities.sumOf { it.population.population } + city.population.population)
|
||||
val respectForLiberatingOurCity = 10f + percentageOfCivPopulationInThatCity.roundToInt()
|
||||
|
||||
// In order to get "plus points" in Diplomacy, you have to establish diplomatic relations if you haven't yet
|
||||
@ -190,10 +190,10 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
}
|
||||
}
|
||||
|
||||
val otherCivsRespecForLiberating = (respectForLiberatingOurCity / 10).roundToInt().toFloat()
|
||||
val otherCivsRespectForLiberating = (respectForLiberatingOurCity / 10).roundToInt().toFloat()
|
||||
for (thirdPartyCiv in conqueringCiv.getKnownCivs().filter { it.isMajorCiv() && it != conqueredCiv }) {
|
||||
thirdPartyCiv.getDiplomacyManager(conqueringCiv)
|
||||
.addModifier(DiplomaticModifiers.LiberatedCity, otherCivsRespecForLiberating) // Cool, keep at at! =D
|
||||
.addModifier(DiplomaticModifiers.LiberatedCity, otherCivsRespectForLiberating) // Cool, keep at at! =D
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
cityConstructions.addBuilding(civEquivalentBuilding.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (civInfo.gameInfo.hasReligionEnabled()) religion.removeUnknownPantheons()
|
||||
|
||||
tryUpdateRoadStatus()
|
||||
@ -252,5 +252,4 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -223,24 +223,24 @@ class CityStats(val cityInfo: CityInfo) {
|
||||
val amountOfEffects = (cityInfo.population.population / unique.params[1].toInt()).toFloat()
|
||||
stats.add(unique.stats.times(amountOfEffects))
|
||||
}
|
||||
|
||||
|
||||
// "[stats] in cities with [amount] or more population
|
||||
if (unique.placeholderText == "[] in cities with [] or more population" && cityInfo.population.population >= unique.params[1].toInt())
|
||||
stats.add(unique.stats)
|
||||
|
||||
|
||||
// "[stats] in cities on [tileFilter] tiles"
|
||||
if (unique.placeholderText == "[] in cities on [] tiles" && cityInfo.getCenterTile().matchesTerrainFilter(unique.params[1]))
|
||||
stats.add(unique.stats)
|
||||
|
||||
|
||||
// "[stats] if this city has at least [amount] specialists"
|
||||
if (unique.placeholderText == "[] if this city has at least [] specialists" && cityInfo.population.getNumberOfSpecialists() >= unique.params[1].toInt())
|
||||
stats.add(unique.stats)
|
||||
|
||||
|
||||
// Deprecated since a very long time ago, moved here from another code section
|
||||
if (unique.placeholderText == "+2 Culture per turn from cities before discovering Steam Power" && !cityInfo.civInfo.tech.isResearched("Steam Power"))
|
||||
stats.culture += 2
|
||||
//
|
||||
|
||||
|
||||
if (unique.placeholderText == "[] per turn from cities before []" && !cityInfo.civInfo.hasTechOrPolicy(unique.params[1]))
|
||||
stats.add(unique.stats)
|
||||
}
|
||||
@ -378,7 +378,7 @@ class CityStats(val cityInfo: CityInfo) {
|
||||
for (unique in civInfo.getMatchingUniques("Specialists only produce []% of normal unhappiness"))
|
||||
unhappinessFromSpecialists *= (1f - unique.params[0].toFloat() / 100f)
|
||||
//
|
||||
|
||||
|
||||
for (unique in cityInfo.getMatchingUniques("[]% unhappiness from specialists []")) {
|
||||
if (cityInfo.matchesFilter(unique.params[1]))
|
||||
unhappinessFromSpecialists *= unique.params[0].toPercent()
|
||||
@ -394,12 +394,12 @@ class CityStats(val cityInfo: CityInfo) {
|
||||
// Deprecated since 3.16.11
|
||||
for (unique in civInfo.getMatchingUniques("Unhappiness from population decreased by []%"))
|
||||
unhappinessFromCitizens *= (1 - unique.params[0].toFloat() / 100)
|
||||
|
||||
|
||||
for (unique in civInfo.getMatchingUniques("Unhappiness from population decreased by []% []"))
|
||||
if (cityInfo.matchesFilter(unique.params[1]))
|
||||
unhappinessFromCitizens *= (1 - unique.params[0].toFloat() / 100)
|
||||
//
|
||||
|
||||
|
||||
for (unique in cityInfo.getMatchingUniques("[]% unhappiness from population []"))
|
||||
if (cityInfo.matchesFilter(unique.params[1]))
|
||||
unhappinessFromCitizens *= unique.params[0].toPercent()
|
||||
@ -520,7 +520,7 @@ class CityStats(val cityInfo: CityInfo) {
|
||||
|
||||
// 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(ModOptionsConstants.convertGoldToScience)) {
|
||||
val amountConverted = (newFinalStatList.values.sumByDouble { it.gold.toDouble() }
|
||||
val amountConverted = (newFinalStatList.values.sumOf { 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(science = amountConverted, gold = -amountConverted)
|
||||
@ -582,7 +582,7 @@ class CityStats(val cityInfo: CityInfo) {
|
||||
for (unique in cityInfo.civInfo.getMatchingUniques("-[]% food consumption by specialists"))
|
||||
foodEatenBySpecialists *= 1f - unique.params[0].toFloat() / 100f
|
||||
//
|
||||
|
||||
|
||||
for (unique in cityInfo.getMatchingUniques("[]% food consumption by specialists []"))
|
||||
if (cityInfo.matchesFilter(unique.params[1]))
|
||||
foodEatenBySpecialists *= unique.params[0].toPercent()
|
||||
|
@ -10,7 +10,6 @@ import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.translations.getPlaceholderParameters
|
||||
import com.unciv.models.translations.getPlaceholderText
|
||||
import com.unciv.ui.victoryscreen.RankingType
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.collections.LinkedHashMap
|
||||
import kotlin.math.max
|
||||
@ -281,14 +280,14 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
val bullyRange = max(5, civInfo.gameInfo.tileMap.tileMatrix.size / 10) // Longer range for larger maps
|
||||
val inRangeTiles = civInfo.getCapital().getCenterTile().getTilesInDistanceRange(1..bullyRange)
|
||||
val forceNearCity = inRangeTiles
|
||||
.sumBy { if (it.militaryUnit?.civInfo == demandingCiv)
|
||||
it.militaryUnit!!.getForceEvaluation()
|
||||
else 0
|
||||
.sumOf { if (it.militaryUnit?.civInfo == demandingCiv)
|
||||
it.militaryUnit!!.getForceEvaluation()
|
||||
else 0
|
||||
}
|
||||
val csForce = civInfo.getCapital().getForceEvaluation() + inRangeTiles
|
||||
.sumBy { if (it.militaryUnit?.civInfo == civInfo)
|
||||
it.militaryUnit!!.getForceEvaluation()
|
||||
else 0
|
||||
.sumOf { if (it.militaryUnit?.civInfo == civInfo)
|
||||
it.militaryUnit!!.getForceEvaluation()
|
||||
else 0
|
||||
}
|
||||
val forceRatio = forceNearCity.toFloat() / csForce.toFloat()
|
||||
|
||||
@ -337,9 +336,9 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
if (!civInfo.isCityState()) throw Exception("You can only demand workers from City-States!")
|
||||
|
||||
val buildableWorkerLikeUnits = civInfo.gameInfo.ruleSet.units.filter {
|
||||
it.value.uniqueObjects.any { it.placeholderText == Constants.canBuildImprovements }
|
||||
&& it.value.isBuildable(civInfo)
|
||||
it.value.uniqueObjects.any { unique -> unique.placeholderText == Constants.canBuildImprovements }
|
||||
&& it.value.isCivilian()
|
||||
&& it.value.isBuildable(civInfo)
|
||||
}
|
||||
if (buildableWorkerLikeUnits.isEmpty()) return // Bad luck?
|
||||
demandingCiv.placeUnitNearTile(civInfo.getCapital().location, buildableWorkerLikeUnits.keys.random())
|
||||
@ -356,7 +355,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
val allyBonuses = eraInfo.allyBonus[civInfo.cityStateType.name]
|
||||
if (allyBonuses != null) {
|
||||
// Defined city states in json
|
||||
val bonuses = allyBonuses + eraInfo!!.friendBonus[civInfo.cityStateType.name]!!
|
||||
val bonuses = allyBonuses + eraInfo.friendBonus[civInfo.cityStateType.name]!!
|
||||
for (bonus in bonuses) {
|
||||
if (statType == Stat.Happiness && bonus.getPlaceholderText() == "Provides [] Happiness")
|
||||
return true
|
||||
|
@ -74,7 +74,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
for (city in civInfo.cities) {
|
||||
for (tile in city.getTiles()) {
|
||||
if (tile.isCityCenter()) continue
|
||||
if (tile.roadStatus == RoadStatus.None) continue // Cheap checks before pricy checks
|
||||
if (tile.roadStatus == RoadStatus.None) continue // Cheap checks before pricey checks
|
||||
if (ignoredTileTypes.any { tile.matchesFilter(it, civInfo) }) continue
|
||||
|
||||
transportationUpkeep += tile.roadStatus.upkeep
|
||||
@ -193,7 +193,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
)// Leave at least 1
|
||||
statMap["Treasury deficit"] = Stats(science = scienceDeficit)
|
||||
}
|
||||
val goldDifferenceFromTrade = civInfo.diplomacy.values.sumBy { it.goldPerTurn() }
|
||||
val goldDifferenceFromTrade = civInfo.diplomacy.values.sumOf { it.goldPerTurn() }
|
||||
if (goldDifferenceFromTrade != 0)
|
||||
statMap["Trade"] = Stats(gold = goldDifferenceFromTrade.toFloat())
|
||||
|
||||
@ -218,7 +218,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
|
||||
val happinessBonusForCityStateProvidedLuxuries =
|
||||
civInfo.getMatchingUniques("Happiness from Luxury Resources gifted by City-States increased by []%")
|
||||
.sumBy { it.params[0].toInt() } / 100f
|
||||
.sumOf { it.params[0].toInt() } / 100f
|
||||
|
||||
val luxuriesProvidedByCityStates = civInfo.getKnownCivs().asSequence()
|
||||
.filter { it.isCityState() && it.getAllyCiv() == civInfo.civName }
|
||||
@ -240,7 +240,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
statMap["Traded Luxuries"] =
|
||||
luxuriesAllOfWhichAreTradedAway.count() * happinessPerUniqueLuxury *
|
||||
civInfo.getMatchingUniques("Retain []% of the happiness from a luxury after the last copy has been traded away")
|
||||
.sumBy { it.params[0].toInt() } / 100f
|
||||
.sumOf { it.params[0].toInt() } / 100f
|
||||
|
||||
for (city in civInfo.cities) {
|
||||
// There appears to be a concurrency problem? In concurrent thread in ConstructionsTable.getConstructionButtonDTOs
|
||||
|
@ -1,25 +1,21 @@
|
||||
package com.unciv.logic.civilization
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.UncivShowableException
|
||||
import com.unciv.logic.automation.NextTurnAutomation
|
||||
import com.unciv.logic.automation.WorkerAutomation
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.civilization.RuinsManager.RuinsManager
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomacyManager
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.UnitMovementAlgorithms
|
||||
import com.unciv.logic.trade.TradeEvaluation
|
||||
import com.unciv.logic.trade.TradeRequest
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.metadata.GameSpeed
|
||||
import com.unciv.models.ruleset.*
|
||||
import com.unciv.models.ruleset.tile.ResourceSupplyList
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
@ -27,16 +23,15 @@ import com.unciv.models.ruleset.tile.TileResource
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.models.translations.getPlaceholderParameters
|
||||
import com.unciv.models.translations.getPlaceholderText
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.utils.toPercent
|
||||
import com.unciv.ui.victoryscreen.RankingType
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.collections.LinkedHashMap
|
||||
import kotlin.math.*
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.sqrt
|
||||
|
||||
class CivilizationInfo {
|
||||
|
||||
@ -127,8 +122,8 @@ class CivilizationInfo {
|
||||
* If the counter reaches 0 at the end of a turn, it is removed immediately
|
||||
*/
|
||||
val temporaryUniques = ArrayList<Pair<Unique, Int>>()
|
||||
|
||||
/** Maps the name of the construction to the amount of times bouhgt */
|
||||
|
||||
/** Maps the name of the construction to the amount of times bought */
|
||||
val boughtConstructionsWithGloballyIncreasingPrice = HashMap<String, Int>()
|
||||
|
||||
// if we only use lists, and change the list each time the cities are changed,
|
||||
@ -386,7 +381,7 @@ class CivilizationInfo {
|
||||
meetCiv(otherCiv)
|
||||
otherCiv.meetCiv(this)
|
||||
}
|
||||
|
||||
|
||||
private fun meetCiv(otherCiv: CivilizationInfo) {
|
||||
diplomacy[otherCiv.civName] = DiplomacyManager(this, otherCiv.civName)
|
||||
.apply { diplomaticStatus = DiplomaticStatus.Peace }
|
||||
@ -501,11 +496,11 @@ class CivilizationInfo {
|
||||
|
||||
fun getStatForRanking(category: RankingType): Int {
|
||||
return when (category) {
|
||||
RankingType.Population -> cities.sumBy { it.population.population }
|
||||
RankingType.Population -> cities.sumOf { it.population.population }
|
||||
RankingType.Crop_Yield -> statsForNextTurn.food.roundToInt()
|
||||
RankingType.Production -> statsForNextTurn.production.roundToInt()
|
||||
RankingType.Gold -> gold
|
||||
RankingType.Territory -> cities.sumBy { it.tiles.size }
|
||||
RankingType.Territory -> cities.sumOf { it.tiles.size }
|
||||
RankingType.Force -> getMilitaryMight()
|
||||
RankingType.Happiness -> getHappiness()
|
||||
RankingType.Technologies -> tech.researchedTechnologies.size
|
||||
@ -540,7 +535,7 @@ class CivilizationInfo {
|
||||
return if (!gameInfo.hasReligionEnabled()) greatPeople.filter { !it.uniques.contains("Great Person - [Faith]")}.toHashSet()
|
||||
else greatPeople.toHashSet()
|
||||
}
|
||||
|
||||
|
||||
fun hasTechOrPolicy(techOrPolicyName: String) =
|
||||
tech.isResearched(techOrPolicyName) || policies.isAdopted(techOrPolicyName)
|
||||
|
||||
@ -710,9 +705,9 @@ class CivilizationInfo {
|
||||
|
||||
if (flagsCountdown[flag]!! > 0)
|
||||
flagsCountdown[flag] = flagsCountdown[flag]!! - 1
|
||||
|
||||
|
||||
if (flagsCountdown[flag]!! != 0) continue
|
||||
|
||||
|
||||
when (flag) {
|
||||
CivFlags.TurnsTillNextDiplomaticVote.name -> addFlag(CivFlags.ShowDiplomaticVotingResults.name, 1)
|
||||
CivFlags.ShouldResetDiplomaticVotes.name -> {
|
||||
@ -721,12 +716,12 @@ class CivilizationInfo {
|
||||
removeFlag(CivFlags.ShowDiplomaticVotingResults.name)
|
||||
}
|
||||
CivFlags.ShowDiplomaticVotingResults.name -> {
|
||||
|
||||
|
||||
if (gameInfo.civilizations.any { it.victoryManager.hasWon() } )
|
||||
// We have either already done this calculation, or it doesn't matter anymore,
|
||||
// so don't waste resources doing it
|
||||
continue
|
||||
|
||||
|
||||
addFlag(CivFlags.ShouldResetDiplomaticVotes.name, 1)
|
||||
}
|
||||
}
|
||||
@ -737,27 +732,27 @@ class CivilizationInfo {
|
||||
fun removeFlag(flag: String) { flagsCountdown.remove(flag) }
|
||||
|
||||
fun getTurnsBetweenDiplomaticVotings() = (15 * gameInfo.gameParameters.gameSpeed.modifier).toInt() // Dunno the exact calculation, hidden in Lua files
|
||||
|
||||
|
||||
fun getTurnsTillNextDiplomaticVote() = flagsCountdown[CivFlags.TurnsTillNextDiplomaticVote.name]
|
||||
|
||||
fun getRecentBullyingCountdown() = flagsCountdown[CivFlags.RecentlyBullied.name]
|
||||
|
||||
|
||||
fun mayVoteForDiplomaticVictory() =
|
||||
getTurnsTillNextDiplomaticVote() == 0
|
||||
&& civName !in gameInfo.diplomaticVictoryVotesCast.keys
|
||||
|
||||
|
||||
fun diplomaticVoteForCiv(chosenCivName: String?) {
|
||||
if (chosenCivName != null) gameInfo.diplomaticVictoryVotesCast[civName] = chosenCivName
|
||||
addFlag(CivFlags.TurnsTillNextDiplomaticVote.name, getTurnsBetweenDiplomaticVotings())
|
||||
}
|
||||
|
||||
|
||||
fun shouldShowDiplomaticVotingResults() =
|
||||
flagsCountdown[CivFlags.ShowDiplomaticVotingResults.name] == 0
|
||||
|
||||
|
||||
// Yes, this is the same function as above, but with a different use case so it has a different name.
|
||||
fun shouldCheckForDiplomaticVictory() =
|
||||
flagsCountdown[CivFlags.ShowDiplomaticVotingResults.name] == 0
|
||||
|
||||
|
||||
/** Modify gold by a given amount making sure it does neither overflow nor underflow.
|
||||
* @param delta the amount to add (can be negative)
|
||||
*/
|
||||
@ -781,7 +776,7 @@ class CivilizationInfo {
|
||||
// Happiness cannot be added as it is recalculated again, use a unique instead
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun getStatReserve(stat: Stat): Int {
|
||||
return when (stat) {
|
||||
Stat.Culture -> policies.storedCulture
|
||||
@ -842,7 +837,7 @@ class CivilizationInfo {
|
||||
val unit = getEquivalentUnit(unitName)
|
||||
val placedUnit = placeUnitNearTile(cityToAddTo.location, unit.name)
|
||||
// silently bail if no tile to place the unit is found
|
||||
if (placedUnit == null) return null
|
||||
?: return null
|
||||
if (unit.isGreatPerson()) {
|
||||
addNotification("A [${unit.name}] has been born in [${cityToAddTo.name}]!", placedUnit.getTile().position, unit.name)
|
||||
}
|
||||
@ -890,14 +885,14 @@ class CivilizationInfo {
|
||||
diplomacyManager.otherCiv().tradeRequests.remove(tradeRequest) // it would be really weird to get a trade request from a dead civ
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun getResearchAgreementCost(): Int {
|
||||
// https://forums.civfanatics.com/resources/research-agreements-bnw.25568/
|
||||
return (
|
||||
getEra().researchAgreementCost * gameInfo.gameParameters.gameSpeed.modifier
|
||||
).toInt()
|
||||
}
|
||||
|
||||
|
||||
//////////////////////// City State wrapper functions ////////////////////////
|
||||
/** Gain a random great person from the city state */
|
||||
private fun giveGreatPersonToPatron(receivingCiv: CivilizationInfo) {
|
||||
@ -950,7 +945,7 @@ class CivilizationInfo {
|
||||
fun threateningBarbarianKilledBy(otherCiv: CivilizationInfo) {
|
||||
cityStateFunctions.threateningBarbarianKilledBy(otherCiv)
|
||||
}
|
||||
|
||||
|
||||
fun getAllyCiv() = allyCivName
|
||||
fun setAllyCiv(newAllyName: String?) { allyCivName = newAllyName }
|
||||
|
||||
|
@ -116,9 +116,9 @@ class MapUnit {
|
||||
return if (religion == null) baseName
|
||||
else "$baseName ([${getReligionDisplayName()}])"
|
||||
}
|
||||
|
||||
|
||||
fun shortDisplayName(): String {
|
||||
return if (instanceName != null) "[$instanceName]"!!
|
||||
return if (instanceName != null) "[$instanceName]"
|
||||
else "[$name]"
|
||||
}
|
||||
|
||||
@ -133,15 +133,15 @@ class MapUnit {
|
||||
var promotions = UnitPromotions()
|
||||
var due: Boolean = true
|
||||
var isTransported: Boolean = false
|
||||
|
||||
|
||||
// Deprecated since 3.16.11
|
||||
@Deprecated("Deprecated since 3.16.11", replaceWith = ReplaceWith("abilityUsesLeft"))
|
||||
var abilityUsedCount: HashMap<String, Int> = hashMapOf()
|
||||
//
|
||||
|
||||
|
||||
var abilityUsesLeft: HashMap<String, Int> = hashMapOf()
|
||||
var maxAbilityUses: HashMap<String, Int> = hashMapOf()
|
||||
|
||||
|
||||
var religion: String? = null
|
||||
var religiousStrengthLost = 0
|
||||
|
||||
@ -181,7 +181,7 @@ class MapUnit {
|
||||
var movement =
|
||||
if (isEmbarked()) 2
|
||||
else baseUnit.movement
|
||||
|
||||
|
||||
movement += getMatchingUniques("[] Movement").sumOf { it.params[0].toInt() }
|
||||
|
||||
for (unique in civInfo.getMatchingUniques("+[] Movement for all [] units"))
|
||||
@ -224,7 +224,7 @@ class MapUnit {
|
||||
val baseUnit = baseUnit()
|
||||
uniques.addAll(baseUnit.uniqueObjects)
|
||||
uniques.addAll(type.uniqueObjects)
|
||||
|
||||
|
||||
for (promotion in promotions.promotions) {
|
||||
uniques.addAll(currentTile.tileMap.gameInfo.ruleSet.unitPromotions[promotion]!!.uniqueObjects)
|
||||
}
|
||||
@ -259,13 +259,13 @@ class MapUnit {
|
||||
for (promotion in newUnit.promotions.promotions)
|
||||
if (promotion !in promotions.promotions)
|
||||
promotions.addPromotion(promotion, isFree = true)
|
||||
|
||||
|
||||
newUnit.promotions = promotions.clone()
|
||||
|
||||
|
||||
newUnit.updateUniques()
|
||||
newUnit.updateVisibleTiles()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines this (land or sea) unit's current maximum vision range from unit properties, civ uniques and terrain.
|
||||
* @return Maximum distance of tiles this unit may possibly see
|
||||
@ -278,7 +278,7 @@ class MapUnit {
|
||||
|
||||
// TODO: This should be replaced with "Sight" like others, for naming consistency
|
||||
visibilityRange += getMatchingUniques("[] Visibility Range").sumOf { it.params[0].toInt() }
|
||||
|
||||
|
||||
if (hasUnique("Limited Visibility")) visibilityRange -= 1
|
||||
|
||||
|
||||
@ -315,7 +315,7 @@ class MapUnit {
|
||||
fun isSleepingUntilHealed() = isSleeping() && isActionUntilHealed()
|
||||
|
||||
fun isMoving() = action?.startsWith("moveTo") == true
|
||||
|
||||
|
||||
fun isAutomated() = action == UnitActionType.Automate.value
|
||||
fun isExploring() = action == UnitActionType.Explore.value
|
||||
fun isPreparingParadrop() = action == UnitActionType.Paradrop.value
|
||||
@ -344,10 +344,9 @@ class MapUnit {
|
||||
}
|
||||
|
||||
fun maxAttacksPerTurn(): Int {
|
||||
var maxAttacksPerTurn = 1 + getMatchingUniques("[] additional attacks per turn").sumOf { it.params[0].toInt() }
|
||||
return maxAttacksPerTurn
|
||||
return 1 + getMatchingUniques("[] additional attacks per turn").sumOf { it.params[0].toInt() }
|
||||
}
|
||||
|
||||
|
||||
fun canAttack(): Boolean {
|
||||
if (currentMovement == 0f) return false
|
||||
return attacksThisTurn < maxAttacksPerTurn()
|
||||
@ -359,7 +358,7 @@ class MapUnit {
|
||||
range += getMatchingUniques("[] Range").sumOf { it.params[0].toInt() }
|
||||
return range
|
||||
}
|
||||
|
||||
|
||||
fun getMaxMovementForAirUnits(): Int {
|
||||
return getRange() * 2
|
||||
}
|
||||
@ -458,16 +457,16 @@ class MapUnit {
|
||||
promotions.setTransients(this)
|
||||
baseUnit = ruleset.units[name]
|
||||
?: throw java.lang.Exception("Unit $name is not found!")
|
||||
|
||||
|
||||
// "Religion Spread" ability deprecated since 3.16.7, replaced with "Spread Religion"
|
||||
if ("Religion Spread" in abilityUsedCount) {
|
||||
abilityUsedCount[Constants.spreadReligionAbilityCount] = abilityUsedCount["Religion Spread"]!!
|
||||
abilityUsedCount.remove("Religion Spread")
|
||||
}
|
||||
//
|
||||
|
||||
|
||||
updateUniques()
|
||||
|
||||
|
||||
// abilityUsedCount deprecated since 3.16.11, this is replacement code
|
||||
if (abilityUsedCount.isNotEmpty()) {
|
||||
for (ability in abilityUsedCount) {
|
||||
@ -480,7 +479,7 @@ class MapUnit {
|
||||
abilityUsedCount.clear()
|
||||
}
|
||||
//
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun useMovementPoints(amount: Float) {
|
||||
@ -600,7 +599,7 @@ class MapUnit {
|
||||
if (amountToHealBy == 0 && !(hasUnique("May heal outside of friendly territory") && !getTile().isFriendlyTerritory(civInfo))) return
|
||||
|
||||
amountToHealBy += getMatchingUniques("[] HP when healing").sumOf { it.params[0].toInt() }
|
||||
|
||||
|
||||
val maxAdjacentHealingBonus = currentTile.getTilesInDistance(1)
|
||||
.flatMap { it.getUnits().asSequence() }.map { it.adjacentHealingBonus() }.maxOrNull()
|
||||
if (maxAdjacentHealingBonus != null)
|
||||
@ -627,17 +626,17 @@ class MapUnit {
|
||||
isFriendlyTerritory -> 15 // Allied territory
|
||||
else -> 5 // Enemy territory
|
||||
}
|
||||
|
||||
|
||||
val mayHeal = healing > 0 || (tileInfo.isWater && hasUnique("May heal outside of friendly territory"))
|
||||
if (!mayHeal) return healing
|
||||
|
||||
|
||||
|
||||
for (unique in getMatchingUniques("[] HP when healing in [] tiles")) {
|
||||
if (tileInfo.matchesFilter(unique.params[1], civInfo)) {
|
||||
healing += unique.params[0].toInt()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val healingCity = tileInfo.getTilesInDistance(1).firstOrNull {
|
||||
it.isCityCenter() && it.getCity()!!.getMatchingUniques("[] Units adjacent to this city heal [] HP per turn when healing").any()
|
||||
}?.getCity()
|
||||
@ -863,7 +862,7 @@ class MapUnit {
|
||||
if (currentTile.aerialDistanceTo(attackedTile) > baseUnit.interceptRange) return false
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
fun canIntercept(): Boolean {
|
||||
if (interceptChance() == 0) return false
|
||||
val maxAttacksPerTurn = 1 +
|
||||
@ -987,17 +986,17 @@ class MapUnit {
|
||||
val matchingUniques = getMatchingUniques(Constants.canBuildImprovements)
|
||||
return matchingUniques.any { improvement.matchesFilter(it.params[0]) || tile.matchesTerrainFilter(it.params[0]) }
|
||||
}
|
||||
|
||||
|
||||
fun getReligionDisplayName(): String? {
|
||||
if (religion == null) return null
|
||||
return civInfo.gameInfo.religions[religion]!!.getReligionDisplayName()
|
||||
}
|
||||
|
||||
|
||||
fun religiousActionsUnitCanDo(): Sequence<String> {
|
||||
return getMatchingUniques("Can [] [] times")
|
||||
.map { it.params[0] }
|
||||
}
|
||||
|
||||
|
||||
fun canDoReligiousAction(action: String): Boolean {
|
||||
return getMatchingUniques("Can [] [] times").any { it.params[0] == action }
|
||||
}
|
||||
@ -1030,10 +1029,10 @@ class MapUnit {
|
||||
for (unique in civInfo.getMatchingUniques("[]% Spread Religion Strength for [] units"))
|
||||
if (matchesFilter(unique.params[0]))
|
||||
pressureAdded *= unique.params[0].toPercent()
|
||||
|
||||
|
||||
return pressureAdded.toInt()
|
||||
}
|
||||
|
||||
|
||||
fun getActionString(action: String): String {
|
||||
val maxActionUses = maxAbilityUses[action]
|
||||
if (abilityUsesLeft[action] == null) return "0/0" // Something went wrong
|
||||
|
@ -34,7 +34,7 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
||||
// Could have old specialist values of "gold", "science" etc - change them to the new specialist names
|
||||
val counter = Counter<String>()
|
||||
for ((entry, amount) in specialistSlots!!) {
|
||||
val equivalentStat = Stat.values().firstOrNull { it.name.toLowerCase(Locale.ENGLISH) == entry }
|
||||
val equivalentStat = Stat.values().firstOrNull { it.name.lowercase() == entry }
|
||||
|
||||
if (equivalentStat != null)
|
||||
counter[Specialist.specialistNameByStat(equivalentStat)] = amount
|
||||
|
@ -415,11 +415,11 @@ class Ruleset {
|
||||
fun getPrereqTree(technologyName: String): Set<String> {
|
||||
if (prereqsHashMap.containsKey(technologyName)) return prereqsHashMap[technologyName]!!
|
||||
val technology = technologies[technologyName]
|
||||
if (technology == null) return emptySet()
|
||||
?: return emptySet()
|
||||
val techHashSet = HashSet<String>()
|
||||
techHashSet += technology.prerequisites
|
||||
for (prereq in technology.prerequisites)
|
||||
techHashSet += getPrereqTree(prereq)
|
||||
for (prerequisite in technology.prerequisites)
|
||||
techHashSet += getPrereqTree(prerequisite)
|
||||
prereqsHashMap[technologyName] = techHashSet
|
||||
return techHashSet
|
||||
}
|
||||
|
@ -9,7 +9,13 @@ import com.unciv.ui.tilegroups.TileGroup
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class TileGroupMap<T: TileGroup>(tileGroups: Collection<T>, private val leftAndRightPadding: Float, private val topAndBottomPadding: Float, worldWrap: Boolean = false, tileGroupsToUnwrap: Collection<T>? = null): Group(){
|
||||
class TileGroupMap<T: TileGroup>(
|
||||
tileGroups: Collection<T>,
|
||||
private val leftAndRightPadding: Float,
|
||||
private val topAndBottomPadding: Float,
|
||||
worldWrap: Boolean = false,
|
||||
tileGroupsToUnwrap: Collection<T>? = null
|
||||
): Group() {
|
||||
var topX = -Float.MAX_VALUE
|
||||
var topY = -Float.MAX_VALUE
|
||||
var bottomX = Float.MAX_VALUE
|
||||
@ -17,17 +23,18 @@ class TileGroupMap<T: TileGroup>(tileGroups: Collection<T>, private val leftAndR
|
||||
private val groupSize = 50
|
||||
private val mirrorTileGroups = HashMap<TileInfo, Pair<T, T>>()
|
||||
|
||||
init{
|
||||
init {
|
||||
if (worldWrap) {
|
||||
for(tileGroup in tileGroups) {
|
||||
for (tileGroup in tileGroups) {
|
||||
@Suppress("UNCHECKED_CAST") // T is constrained such that casting these TileGroup clones to T should be OK
|
||||
mirrorTileGroups[tileGroup.tileInfo] = Pair(tileGroup.clone() as T, tileGroup.clone() as T)
|
||||
}
|
||||
}
|
||||
|
||||
for(tileGroup in tileGroups) {
|
||||
val positionalVector = if (tileGroupsToUnwrap != null && tileGroupsToUnwrap.contains(tileGroup)){
|
||||
for (tileGroup in tileGroups) {
|
||||
val positionalVector = if (tileGroupsToUnwrap != null && tileGroupsToUnwrap.contains(tileGroup)) {
|
||||
HexMath.hex2WorldCoords(
|
||||
tileGroup.tileInfo.tileMap.getUnWrappedPosition(tileGroup.tileInfo.position)
|
||||
tileGroup.tileInfo.tileMap.getUnWrappedPosition(tileGroup.tileInfo.position)
|
||||
)
|
||||
} else {
|
||||
HexMath.hex2WorldCoords(tileGroup.tileInfo.position)
|
||||
@ -80,7 +87,7 @@ class TileGroupMap<T: TileGroup>(tileGroups: Collection<T>, private val leftAndR
|
||||
val circleCrosshairFogLayers = ArrayList<Group>()
|
||||
|
||||
// Apparently the sortedByDescending is kinda memory-intensive because it needs to sort ALL the tiles
|
||||
for(group in tileGroups.sortedByDescending { it.tileInfo.position.x + it.tileInfo.position.y }){
|
||||
for (group in tileGroups.sortedByDescending { it.tileInfo.position.x + it.tileInfo.position.y }) {
|
||||
// now, we steal the subgroups from all the tilegroups, that's how we form layers!
|
||||
baseLayers.add(group.baseLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
featureLayers.add(group.terrainFeatureLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
@ -90,8 +97,8 @@ class TileGroupMap<T: TileGroup>(tileGroups: Collection<T>, private val leftAndR
|
||||
cityButtonLayers.add(group.cityButtonLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
circleCrosshairFogLayers.add(group.circleCrosshairFogLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
|
||||
if (worldWrap){
|
||||
for (mirrorTile in mirrorTileGroups[group.tileInfo]!!.toList()){
|
||||
if (worldWrap) {
|
||||
for (mirrorTile in mirrorTileGroups[group.tileInfo]!!.toList()) {
|
||||
baseLayers.add(mirrorTile.baseLayerGroup.apply { setPosition(mirrorTile.x,mirrorTile.y) })
|
||||
featureLayers.add(mirrorTile.terrainFeatureLayerGroup.apply { setPosition(mirrorTile.x,mirrorTile.y) })
|
||||
miscLayers.add(mirrorTile.miscLayerGroup.apply { setPosition(mirrorTile.x,mirrorTile.y) })
|
||||
@ -102,20 +109,20 @@ class TileGroupMap<T: TileGroup>(tileGroups: Collection<T>, private val leftAndR
|
||||
}
|
||||
}
|
||||
}
|
||||
for(group in baseLayers) addActor(group)
|
||||
for(group in featureLayers) addActor(group)
|
||||
for(group in miscLayers) addActor(group)
|
||||
for(group in circleCrosshairFogLayers) addActor(group)
|
||||
for(group in tileGroups) addActor(group) // The above layers are for the visual layers, this is for the clickability of the tile
|
||||
if (worldWrap){
|
||||
for (mirrorTiles in mirrorTileGroups.values){
|
||||
for (group in baseLayers) addActor(group)
|
||||
for (group in featureLayers) addActor(group)
|
||||
for (group in miscLayers) addActor(group)
|
||||
for (group in circleCrosshairFogLayers) addActor(group)
|
||||
for (group in tileGroups) addActor(group) // The above layers are for the visual layers, this is for the clickability of the tile
|
||||
if (worldWrap) {
|
||||
for (mirrorTiles in mirrorTileGroups.values) {
|
||||
addActor(mirrorTiles.first)
|
||||
addActor(mirrorTiles.second)
|
||||
}
|
||||
}
|
||||
for(group in unitLayers) addActor(group) // Aaand units above everything else.
|
||||
for(group in unitImageLayers) addActor(group) // This is so the individual textures for the units are rendered together
|
||||
for(group in cityButtonLayers) addActor(group) // city buttons + clickability
|
||||
for (group in unitLayers) addActor(group) // Aaand units above everything else.
|
||||
for (group in unitImageLayers) addActor(group) // This is so the individual textures for the units are rendered together
|
||||
for (group in cityButtonLayers) addActor(group) // city buttons + clickability
|
||||
|
||||
|
||||
// there are tiles "below the zero",
|
||||
|
@ -87,11 +87,11 @@ class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val
|
||||
.minWidth(iconSize) //we need the min width so we can align the different tables
|
||||
|
||||
cityInfoTableTotal.add("Total".toLabel())
|
||||
cityInfoTableTotal.add(viewingPlayer.cities.sumBy { it.population.population }.toString().toLabel()).myAlign(Align.center)
|
||||
cityInfoTableTotal.add(viewingPlayer.cities.sumOf { it.population.population }.toString().toLabel()).myAlign(Align.center)
|
||||
for (column in columnsNames.filter { it.isStat() }) {
|
||||
val stat = Stat.valueOf(column)
|
||||
if (stat == Stat.Food || stat == Stat.Production) cityInfoTableTotal.add() // an intended empty space
|
||||
else cityInfoTableTotal.add(viewingPlayer.cities.sumBy { getStatOfCity(it, stat) }.toLabel()).myAlign(Align.center)
|
||||
else cityInfoTableTotal.add(viewingPlayer.cities.sumOf { getStatOfCity(it, stat) }.toLabel()).myAlign(Align.center)
|
||||
}
|
||||
cityInfoTableTotal.pack()
|
||||
|
||||
@ -111,7 +111,7 @@ class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val
|
||||
private fun getStatOfCity(cityInfo: CityInfo, stat: Stat): Int {
|
||||
return if (stat == Stat.Happiness)
|
||||
cityInfo.cityStats.happinessList.values.sum().roundToInt()
|
||||
else cityInfo.cityStats.currentCityStats.get(stat).roundToInt()
|
||||
else cityInfo.cityStats.currentCityStats[stat].roundToInt()
|
||||
}
|
||||
|
||||
private fun fillCitiesTable(citiesTable: Table, sortType: String, descending: Boolean) {
|
||||
|
@ -16,8 +16,7 @@ class ResourcesOverviewTable (
|
||||
viewingPlayer: CivilizationInfo,
|
||||
overviewScreen: EmpireOverviewScreen
|
||||
) : Table() {
|
||||
//val game = overviewScreen.game
|
||||
|
||||
|
||||
init {
|
||||
defaults().pad(10f)
|
||||
|
||||
@ -79,7 +78,7 @@ class ResourcesOverviewTable (
|
||||
|
||||
add("Total".toLabel())
|
||||
for (resource in resources) {
|
||||
val sum = resourceDrilldown.filter { it.resource == resource }.sumBy { it.amount }
|
||||
val sum = resourceDrilldown.filter { it.resource == resource }.sumOf { it.amount }
|
||||
add(sum.toLabel())
|
||||
}
|
||||
}
|
||||
|
@ -104,14 +104,14 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
||||
if (!erasNamesToColumns[era]!!.contains(columnNumber)) erasNamesToColumns[era]!!.add(columnNumber)
|
||||
}
|
||||
var i = 0
|
||||
for ((era, columns) in erasNamesToColumns) {
|
||||
val columnSpan = columns.size
|
||||
for ((era, eraColumns) in erasNamesToColumns) {
|
||||
val columnSpan = eraColumns.size
|
||||
val color = if (i % 2 == 0) Color.BLUE else Color.FIREBRICK
|
||||
i++
|
||||
techTable.add(era.toLabel().addBorder(2f, color)).fill().colspan(columnSpan)
|
||||
}
|
||||
|
||||
for (rowIndex in 0..rows - 1) {
|
||||
for (rowIndex in 0 until rows) {
|
||||
techTable.row().pad(5f).padRight(40f)
|
||||
|
||||
for (columnIndex in techMatrix.indices) {
|
||||
@ -206,13 +206,13 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectTechnology(tech: Technology?, center: Boolean = false, switchfromWorldScreen: Boolean = true) {
|
||||
private fun selectTechnology(tech: Technology?, center: Boolean = false, switchFromWorldScreen: Boolean = true) {
|
||||
|
||||
val previousSelectedTech = selectedTech
|
||||
selectedTech = tech
|
||||
descriptionLabel.setText(tech?.getDescription(civInfo.gameInfo.ruleSet))
|
||||
|
||||
if (!switchfromWorldScreen)
|
||||
if (!switchFromWorldScreen)
|
||||
return
|
||||
|
||||
if (tech == null)
|
||||
@ -264,8 +264,8 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
||||
}
|
||||
|
||||
private fun getTechProgressLabel(techs: List<String>): String {
|
||||
val progress = techs.sumBy { tech -> civTech.researchOfTech(tech) }
|
||||
val techCost = techs.sumBy { tech -> civInfo.tech.costOfTech(tech) }
|
||||
val progress = techs.sumOf { tech -> civTech.researchOfTech(tech) }
|
||||
val techCost = techs.sumOf { tech -> civInfo.tech.costOfTech(tech) }
|
||||
return "(${progress}/${techCost})"
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user