From 365cb6f1b910e4fffc2217e247b8e92481d4f54a Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 15 Aug 2019 10:43:15 +0300 Subject: [PATCH] Nation changed to transient in CivInfo --- core/src/com/unciv/GameStarter.kt | 10 +++--- core/src/com/unciv/logic/GameInfo.kt | 14 ++++----- .../logic/automation/NextTurnAutomation.kt | 2 +- .../unciv/logic/automation/UnitAutomation.kt | 8 ++--- core/src/com/unciv/logic/battle/Battle.kt | 14 ++++----- .../com/unciv/logic/battle/BattleDamage.kt | 8 ++--- .../unciv/logic/city/CityExpansionManager.kt | 2 +- core/src/com/unciv/logic/city/CityInfo.kt | 6 ++-- core/src/com/unciv/logic/city/CityStats.kt | 10 +++--- .../unciv/logic/civilization/CivInfoStats.kt | 2 +- .../civilization/CivInfoTransientUpdater.kt | 4 +-- .../logic/civilization/CivilizationInfo.kt | 31 ++++++++++++------- .../unciv/logic/civilization/TechManager.kt | 2 +- core/src/com/unciv/logic/map/MapUnit.kt | 6 ++-- core/src/com/unciv/logic/map/TileInfo.kt | 2 +- .../src/com/unciv/models/gamebasics/Nation.kt | 2 ++ core/src/com/unciv/ui/EmpireOverviewScreen.kt | 16 +++++----- core/src/com/unciv/ui/VictoryScreen.kt | 2 +- .../ui/newgamescreen/PlayerPickerTable.kt | 6 ++-- .../src/com/unciv/ui/tilegroups/CityButton.kt | 12 +++---- core/src/com/unciv/ui/tilegroups/TileGroup.kt | 2 +- .../src/com/unciv/ui/trade/DiplomacyScreen.kt | 4 +-- core/src/com/unciv/ui/utils/UnitGroup.kt | 4 +-- core/src/com/unciv/ui/worldscreen/Minimap.kt | 4 +-- .../unciv/ui/worldscreen/PlayerReadyScreen.kt | 4 +-- .../com/unciv/ui/worldscreen/WorldScreen.kt | 4 +-- 26 files changed, 97 insertions(+), 84 deletions(-) diff --git a/core/src/com/unciv/GameStarter.kt b/core/src/com/unciv/GameStarter.kt index 47209230..ba59ba3c 100644 --- a/core/src/com/unciv/GameStarter.kt +++ b/core/src/com/unciv/GameStarter.kt @@ -83,7 +83,7 @@ class GameStarter{ gameInfo.setTransients() // needs to be before placeBarbarianUnit because it depends on the tilemap having its gameinfo set - for (civInfo in gameInfo.civilizations.filter {!it.isBarbarianCivilization() && !it.isPlayerCivilization()}) { + for (civInfo in gameInfo.civilizations.filter {!it.isBarbarian() && !it.isPlayerCivilization()}) { for (tech in gameInfo.getDifficulty().aiFreeTechs) civInfo.tech.addTechnology(tech) } @@ -92,10 +92,10 @@ class GameStarter{ val startingLocations = getStartingLocations( - gameInfo.civilizations.filter { !it.isBarbarianCivilization() }, + gameInfo.civilizations.filter { !it.isBarbarian() }, gameInfo.tileMap) - for (civ in gameInfo.civilizations.filter { !it.isBarbarianCivilization() }) { + for (civ in gameInfo.civilizations.filter { !it.isBarbarian() }) { val startingLocation = startingLocations[civ]!! civ.placeUnitNearTile(startingLocation.position, Constants.settler) @@ -133,7 +133,7 @@ class GameStarter{ val civsOrderedByAvailableLocations = civs.sortedBy {civ -> when { tilesWithStartingLocations.any { it.improvement=="StartingLocation "+civ.civName } -> 1 // harshest requirements - civ.getNation().startBias.isNotEmpty() -> 2 // less harsh + civ.nation.startBias.isNotEmpty() -> 2 // less harsh else -> 3 } // no requirements } @@ -146,7 +146,7 @@ class GameStarter{ if (freeTiles.isEmpty()) break // we failed to get all the starting locations with this minimum distance var preferredTiles = freeTiles.toList() - for (startBias in civ.getNation().startBias) { + for (startBias in civ.nation.startBias) { if (startBias.startsWith("Avoid ")) { val tileToAvoid = startBias.removePrefix("Avoid ") preferredTiles = preferredTiles.filter { it.baseTerrain != tileToAvoid && it.terrainFeature != tileToAvoid } diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index a056ecf5..bd8975d6 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -127,7 +127,7 @@ class GameInfo { fun placeBarbarianEncampment(existingEncampments: List): TileInfo? { // Barbarians will only spawn in places that no one can see - val allViewableTiles = civilizations.filterNot { it.isBarbarianCivilization() } + val allViewableTiles = civilizations.filterNot { it.isBarbarian() } .flatMap { it.viewableTiles }.toHashSet() val tilesWithin3ofExistingEncampment = existingEncampments.flatMap { it.getTilesInDistance(3) } val viableTiles = tileMap.values.filter { @@ -146,7 +146,7 @@ class GameInfo { // if we don't make this into a separate list then the retain() will happen on the Tech keys, // which effectively removes those techs from the game and causes all sorts of problems val allResearchedTechs = GameBasics.Technologies.keys.toMutableList() - for (civ in civilizations.filter { !it.isBarbarianCivilization() && !it.isDefeated() }) { + for (civ in civilizations.filter { !it.isBarbarian() && !it.isDefeated() }) { allResearchedTechs.retainAll(civ.tech.techsResearched) } val barbarianCiv = getBarbarianCivilization() @@ -209,13 +209,13 @@ class GameInfo { } } - for (civInfo in civilizations) { - civInfo.setTransients() - for(unit in civInfo.getCivUnits()) - unit.updateViewableTiles() // this needs to be done after all the units are assigned to their civs and all other transients are set - } + for (civInfo in civilizations) civInfo.setNationTransient() + for (civInfo in civilizations) civInfo.setTransients() for (civInfo in civilizations){ + for(unit in civInfo.getCivUnits()) + unit.updateViewableTiles() // this needs to be done after all the units are assigned to their civs and all other transients are set + // Since this depends on the cities of ALL civilizations, // we need to wait until we've set the transients of all the cities before we can run this. // Hence why it's not in CivInfo.setTransients(). diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index 5ce05fef..e4898680 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -306,7 +306,7 @@ class NextTurnAutomation{ val ourCombatStrength = Automation().evaluteCombatStrength(civInfo) val enemiesCiv = civInfo.diplomacy.filter { it.value.diplomaticStatus == DiplomaticStatus.War } .map { it.value.otherCiv() } - .filterNot { it == civInfo || it.isBarbarianCivilization() || it.cities.isEmpty() } + .filterNot { it == civInfo || it.isBarbarian() || it.cities.isEmpty() } .filter { !civInfo.getDiplomacyManager(it).hasFlag(DiplomacyFlags.DeclinedPeace) } for (enemy in enemiesCiv) { diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index adf38e7c..cd220ec7 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -48,7 +48,7 @@ class UnitAutomation{ val unitActions = UnitActions().getUnitActions(unit,UnCivGame.Current.worldScreen) var unitDistanceToTiles = unit.movement.getDistanceToTiles() - if(unit.civInfo.isBarbarianCivilization() && + if(unit.civInfo.isBarbarian() && unit.currentTile.improvement==Constants.barbarianEncampment && unit.type.isLandUnit()) { if(unit.canFortify()) unit.fortify() return // stay in the encampment @@ -75,7 +75,7 @@ class UnitAutomation{ if (tryAttackNearbyEnemy(unit)) return // Barbarians try to pillage improvements if no targets reachable - if (unit.civInfo.isBarbarianCivilization() && tryPillageImprovement(unit, unitDistanceToTiles)) return + if (unit.civInfo.isBarbarian() && tryPillageImprovement(unit, unitDistanceToTiles)) return if (tryGarrisoningUnit(unit)) return @@ -95,12 +95,12 @@ class UnitAutomation{ if(tryExplore(unit,unitDistanceToTiles)) return // Barbarians just wander all over the place - if(unit.civInfo.isBarbarianCivilization()) + if(unit.civInfo.isBarbarian()) wander(unit,unitDistanceToTiles) } private fun tryHeadTowardsEncampment(unit: MapUnit): Boolean { - if(unit.civInfo.isBarbarianCivilization()) return false + if(unit.civInfo.isBarbarian()) return false val knownEncampments = unit.civInfo.gameInfo.tileMap.values.asSequence() .filter { it.improvement==Constants.barbarianEncampment && unit.civInfo.exploredTiles.contains(it.position) } val cities = unit.civInfo.cities diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 949339f1..d28d5534 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -104,9 +104,9 @@ class Battle(val gameInfo:GameInfo) { // German unique - needs to be checked before we try to move to the enemy tile, since the encampment disappears after we move in - if(defender.isDefeated() && defender.getCivInfo().isBarbarianCivilization() + if(defender.isDefeated() && defender.getCivInfo().isBarbarian() && attackedTile.improvement==Constants.barbarianEncampment - && attacker.getCivInfo().getNation().unique== "67% chance to earn 25 Gold and recruit a Barbarian unit from a conquered encampment, -25% land units maintenance." + && attacker.getCivInfo().nation.unique== "67% chance to earn 25 Gold and recruit a Barbarian unit from a conquered encampment, -25% land units maintenance." && Random().nextDouble() > 0.67){ attacker.getCivInfo().placeUnitNearTile(attackedTile.position, defender.getName()) attacker.getCivInfo().gold += 25 @@ -115,7 +115,7 @@ class Battle(val gameInfo:GameInfo) { // Similarly, Ottoman unique if(defender.isDefeated() && defender.getUnitType().isWaterUnit() && attacker.isMelee() && attacker.getUnitType().isWaterUnit() - && attacker.getCivInfo().getNation().unique== "Pay only one third the usual cost for naval unit maintenance. Melee naval units have a 1/3 chance to capture defeated naval units." + && attacker.getCivInfo().nation.unique== "Pay only one third the usual cost for naval unit maintenance. Melee naval units have a 1/3 chance to capture defeated naval units." && Random().nextDouble() > 0.33){ attacker.getCivInfo().placeUnitNearTile(attackedTile.position, defender.getName()) } @@ -165,7 +165,7 @@ class Battle(val gameInfo:GameInfo) { // Add culture when defeating a barbarian when Honor policy is adopted (can be either attacker or defender!) fun tryGetCultureFromHonor(civUnit:ICombatant, barbarianUnit:ICombatant){ if(barbarianUnit.isDefeated() && barbarianUnit is MapUnitCombatant - && barbarianUnit.getCivInfo().isBarbarianCivilization() + && barbarianUnit.getCivInfo().isBarbarian() && civUnit.getCivInfo().policies.isAdopted("Honor")) civUnit.getCivInfo().policies.storedCulture += max(barbarianUnit.unit.baseUnit.strength,barbarianUnit.unit.baseUnit.rangedStrength) @@ -185,13 +185,13 @@ class Battle(val gameInfo:GameInfo) { // XP! fun addXp(thisCombatant:ICombatant, amount:Int, otherCombatant:ICombatant){ if(thisCombatant !is MapUnitCombatant) return - if(thisCombatant.unit.promotions.totalXpProduced() >= 30 && otherCombatant.getCivInfo().isBarbarianCivilization()) + if(thisCombatant.unit.promotions.totalXpProduced() >= 30 && otherCombatant.getCivInfo().isBarbarian()) return var amountToAdd = amount if(thisCombatant.getCivInfo().policies.isAdopted("Military Tradition")) amountToAdd = (amountToAdd * 1.5f).toInt() thisCombatant.unit.promotions.XP += amountToAdd - if(thisCombatant.getCivInfo().getNation().unique + if(thisCombatant.getCivInfo().nation.unique == "Great general provides double combat bonus, and spawns 50% faster") amountToAdd = (amountToAdd * 1.5f).toInt() if(thisCombatant.unit.hasUnique("Combat very likely to create Great Generals")) @@ -274,7 +274,7 @@ class Battle(val gameInfo:GameInfo) { } fun captureCivilianUnit(attacker: ICombatant, defender: ICombatant){ - if(attacker.getCivInfo().isBarbarianCivilization() + if(attacker.getCivInfo().isBarbarian() || (attacker.getCivInfo().isCityState() && defender.getName()==Constants.settler)){ defender.takeDamage(100) return diff --git a/core/src/com/unciv/logic/battle/BattleDamage.kt b/core/src/com/unciv/logic/battle/BattleDamage.kt index 899b5dbb..2a607df9 100644 --- a/core/src/com/unciv/logic/battle/BattleDamage.kt +++ b/core/src/com/unciv/logic/battle/BattleDamage.kt @@ -66,7 +66,7 @@ class BattleDamage{ val requiredResource = combatant.unit.baseUnit.requiredResource if(requiredResource!=null && combatant.getCivInfo().getCivResourcesByName()[requiredResource]!!<0 - && !combatant.getCivInfo().isBarbarianCivilization()){ + && !combatant.getCivInfo().isBarbarian()){ modifiers["Missing resource"]=-0.25f } @@ -76,14 +76,14 @@ class BattleDamage{ .filter {it.civilianUnit?.civInfo == combatant.unit.civInfo} .map {it.civilianUnit} if (nearbyCivUnits.any { it!!.hasUnique("Bonus for units in 2 tile radius 15%") }) { - modifiers["Great General"]= if (combatant.unit.civInfo.getNation().unique == + modifiers["Great General"]= if (combatant.unit.civInfo.nation.unique == "Great general provides double combat bonus, and spawns 50% faster") 0.3f else 0.15f } } } - if (combatant.getCivInfo().policies.isAdopted("Honor") && enemy.getCivInfo().isBarbarianCivilization()) + if (combatant.getCivInfo().policies.isAdopted("Honor") && enemy.getCivInfo().isBarbarian()) modifiers["vs Barbarians"] = 0.25f return modifiers @@ -202,7 +202,7 @@ class BattleDamage{ private fun getHealthDependantDamageRatio(combatant: ICombatant): Float { if (combatant.getUnitType() == UnitType.City - || combatant.getCivInfo().getNation().unique == "Units fight as though they were at full strength even when damaged") + || combatant.getCivInfo().nation.unique == "Units fight as though they were at full strength even when damaged") return 1f return 1/2f + combatant.getHealth()/200f // Each point of health reduces damage dealt by 0.5% } diff --git a/core/src/com/unciv/logic/city/CityExpansionManager.kt b/core/src/com/unciv/logic/city/CityExpansionManager.kt index 5dd317a7..b6ea29d0 100644 --- a/core/src/com/unciv/logic/city/CityExpansionManager.kt +++ b/core/src/com/unciv/logic/city/CityExpansionManager.kt @@ -54,7 +54,7 @@ class CityExpansionManager { if(cityInfo.containsBuildingUnique("Culture and Gold costs of acquiring new tiles reduced by 25% in this city")) cost *= 0.75 // Specialty of Krepost - if(cityInfo.civInfo.getNation().unique=="All land military units have +1 sight, 50% discount when purchasing tiles") + if(cityInfo.civInfo.nation.unique=="All land military units have +1 sight, 50% discount when purchasing tiles") cost /= 2 return cost.toInt() } diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 53a14fd8..bb05e217 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -117,10 +117,10 @@ class CityInfo { if(resource.resourceType == ResourceType.Strategic){ amountToAdd = 2 if(civInfo.policies.isAdopted("Facism")) amountToAdd*=2 - if(civInfo.getNation().unique=="Strategic Resources provide +1 Production, and Horses, Iron and Uranium Resources provide double quantity" + if(civInfo.nation.unique=="Strategic Resources provide +1 Production, and Horses, Iron and Uranium Resources provide double quantity" && resource.name in listOf("Horses","Iron","Uranium")) amountToAdd *= 2 - if(resource.name=="Oil" && civInfo.getNation().unique=="+1 Gold from each Trade Route, Oil resources provide double quantity") + if(resource.name=="Oil" && civInfo.nation.unique=="+1 Gold from each Trade Route, Oil resources provide double quantity") amountToAdd *= 2 } if(resource.resourceType == ResourceType.Luxury @@ -156,7 +156,7 @@ class CityInfo { stats["Buildings"] = buildingStats for(entry in stats){ - if(civInfo.getNation().unique=="Receive free Great Scientist when you discover Writing, Earn Great Scientists 50% faster") + if(civInfo.nation.unique=="Receive free Great Scientist when you discover Writing, Earn Great Scientists 50% faster") entry.value.science *= 1.5f if (civInfo.policies.isAdopted("Entrepreneurship")) entry.value.gold *= 1.25f diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index 13ccd2fd..73415c34 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -44,7 +44,7 @@ class CityStats { if (!cityInfo.isCapital() && cityInfo.isConnectedToCapital()) { val civInfo = cityInfo.civInfo var goldFromTradeRoute = civInfo.getCapital().population.population * 0.15 + cityInfo.population.population * 1.1 - 1 // Calculated by http://civilization.wikia.com/wiki/Trade_route_(Civ5) - if (civInfo.getNation().unique == "+1 Gold from each Trade Route, Oil resources provide double quantity") goldFromTradeRoute += 1 + if (civInfo.nation.unique == "+1 Gold from each Trade Route, Oil resources provide double quantity") goldFromTradeRoute += 1 if (civInfo.policies.isAdopted("Trade Unions")) goldFromTradeRoute += 2 if (civInfo.containsBuildingUnique("Gold from all trade routes +25%")) goldFromTradeRoute *= 1.25 // Machu Pichu speciality stats.gold += goldFromTradeRoute.toFloat() @@ -121,7 +121,7 @@ class CityStats { private fun getStatsFromNationUnique(): Stats { val stats = Stats() - val civUnique = cityInfo.civInfo.getNation().unique + val civUnique = cityInfo.civInfo.nation.unique if (civUnique == "+2 Culture per turn from cities before discovering Steam Power") stats.culture += 2 @@ -145,7 +145,7 @@ class CityStats { private fun getStatPercentBonusesFromNationUnique(): Stats { val stats = Stats() - val civUnique = cityInfo.civInfo.getNation().unique + val civUnique = cityInfo.civInfo.nation.unique val currentConstruction = cityInfo.cityConstructions.getCurrentConstruction() if (civUnique == "+25% Production towards any buildings that already exist in the Capital" && currentConstruction is Building @@ -181,7 +181,7 @@ class CityStats { unhappinessModifier *= civInfo.gameInfo.getDifficulty().aiUnhappinessModifier var unhappinessFromCity = -3f - if (civInfo.getNation().unique == "Unhappiness from number of Cities doubled, Unhappiness from number of Citizens halved.") + if (civInfo.nation.unique == "Unhappiness from number of Cities doubled, Unhappiness from number of Citizens halved.") unhappinessFromCity *= 2f//doubled for the Indian newHappinessList["Cities"] = unhappinessFromCity * unhappinessModifier @@ -193,7 +193,7 @@ class CityStats { unhappinessFromCitizens *= 0.9f if (civInfo.policies.isAdopted("Meritocracy")) unhappinessFromCitizens *= 0.95f - if (civInfo.getNation().unique == "Unhappiness from number of Cities doubled, Unhappiness from number of Citizens halved.") + if (civInfo.nation.unique == "Unhappiness from number of Cities doubled, Unhappiness from number of Citizens halved.") unhappinessFromCitizens *= 0.5f //halved for the Indian newHappinessList["Population"] = -unhappinessFromCitizens * unhappinessModifier diff --git a/core/src/com/unciv/logic/civilization/CivInfoStats.kt b/core/src/com/unciv/logic/civilization/CivInfoStats.kt index 6b14ef4a..d63135f1 100644 --- a/core/src/com/unciv/logic/civilization/CivInfoStats.kt +++ b/core/src/com/unciv/logic/civilization/CivInfoStats.kt @@ -20,7 +20,7 @@ class CivInfoStats(val civInfo: CivilizationInfo){ if(civInfo.policies.isAdopted("Oligarchy")) unitsToPayFor = unitsToPayFor.filterNot { it.getTile().isCityCenter() } var numberOfUnitsToPayFor = max(0f, unitsToPayFor.count().toFloat() - freeUnits) - if(civInfo.getNation().unique=="67% chance to earn 25 Gold and recruit a Barbarian unit from a conquered encampment, -25% land units maintenance."){ + if(civInfo.nation.unique=="67% chance to earn 25 Gold and recruit a Barbarian unit from a conquered encampment, -25% land units maintenance."){ val numberOfUnitsWithDiscount = min(numberOfUnitsToPayFor, unitsToPayFor.count { it.type.isLandUnit() }.toFloat()) numberOfUnitsToPayFor -= 0.25f * numberOfUnitsWithDiscount } diff --git a/core/src/com/unciv/logic/civilization/CivInfoTransientUpdater.kt b/core/src/com/unciv/logic/civilization/CivInfoTransientUpdater.kt index 9249cb7f..961f2718 100644 --- a/core/src/com/unciv/logic/civilization/CivInfoTransientUpdater.kt +++ b/core/src/com/unciv/logic/civilization/CivInfoTransientUpdater.kt @@ -52,8 +52,8 @@ class CivInfoTransientUpdater(val civInfo: CivilizationInfo){ for(unit in tile.getUnits()) viewedCivs+=unit.civInfo } - if(!civInfo.isBarbarianCivilization()) { - for (otherCiv in viewedCivs.filterNot { it == civInfo || it.isBarbarianCivilization() }) + if(!civInfo.isBarbarian()) { + for (otherCiv in viewedCivs.filterNot { it == civInfo || it.isBarbarian() }) if (!civInfo.diplomacy.containsKey(otherCiv.civName)) { civInfo.meetCivilization(otherCiv) civInfo.addNotification("We have encountered [${otherCiv.civName}]!".tr(), null, Color.GOLD) diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 4afe73a9..9db3cc5d 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -24,6 +24,7 @@ import kotlin.math.roundToInt class CivilizationInfo { @Transient lateinit var gameInfo: GameInfo + @Transient lateinit var nation:Nation /** * We never add or remove from here directly, could cause comodification problems. * Instead, we create a copy list with the change, and replace this list. @@ -99,14 +100,13 @@ class CivilizationInfo { return GameBasics.Difficulties["Chieftain"]!! } - fun getNation() = GameBasics.Nations[civName]!! fun getTranslatedNation(): Nation { val language = UnCivGame.Current.settings.language.replace(" ","_") - if(!Gdx.files.internal("jsons/Nations_$language.json").exists()) return getNation() + if(!Gdx.files.internal("jsons/Nations_$language.json").exists()) return nation val translatedNation = GameBasics.getFromJson(Array::class.java, "Nations_$language") .firstOrNull { it.name==civName} if(translatedNation==null) // this language's trnslation doesn't contain this nation yet, - return getNation() // default to english + return nation // default to english return translatedNation } @@ -119,15 +119,15 @@ class CivilizationInfo { fun getCapital()=cities.first { it.isCapital() } fun isPlayerCivilization() = playerType==PlayerType.Human fun isCurrentPlayer() = gameInfo.getCurrentPlayerCivilization()==this - fun isBarbarianCivilization() = civName=="Barbarians" - fun isCityState(): Boolean = getNation().isCityState() - fun getCityStateType(): CityStateType = getNation().cityStateType!! - fun isMajorCiv() = !isBarbarianCivilization() && !isCityState() + fun isBarbarian() = nation.isBarbarian() + fun isCityState(): Boolean = nation.isCityState() + fun getCityStateType(): CityStateType = nation.cityStateType!! + fun isMajorCiv() = nation.isMajorCiv() fun victoryType(): VictoryType { if(gameInfo.gameParameters.victoryTypes.size==1) return gameInfo.gameParameters.victoryTypes.first() // That is the most relevant one - val victoryType = getNation().preferredVictoryType + val victoryType = nation.preferredVictoryType if(gameInfo.gameParameters.victoryTypes.contains(victoryType)) return victoryType else return VictoryType.Neutral } @@ -249,7 +249,7 @@ class CivilizationInfo { } fun isAtWarWith(otherCiv:CivilizationInfo): Boolean { - if(otherCiv.isBarbarianCivilization() || isBarbarianCivilization()) return true + if(otherCiv.isBarbarian() || isBarbarian()) return true if(!diplomacy.containsKey(otherCiv.civName)) // not encountered yet return false return getDiplomacyManager(otherCiv).diplomaticStatus == DiplomaticStatus.War @@ -269,6 +269,15 @@ class CivilizationInfo { //endregion //region state-changing functions + + /** This is separate because the REGULAR setTransients updates the viewable ties, + * and the updateViewableTiles tries to meet civs... + * And if they civs on't yet know who they are then they don;t know if they're barbarians =\ + * */ + fun setNationTransient(){ + nation = GameBasics.Nations[civName]!! + } + fun setTransients() { goldenAges.civInfo = this policies.civInfo = this @@ -276,7 +285,7 @@ class CivilizationInfo { policies.numberOfAdoptedPolicies = policies.adoptedPolicies.count { !it.endsWith("Complete") } if(citiesCreated==0 && cities.any()) - citiesCreated = cities.filter { it.name in getNation().cities }.count() + citiesCreated = cities.filter { it.name in nation.cities }.count() tech.civInfo = this tech.setTransients() @@ -329,7 +338,7 @@ class CivilizationInfo { policies.endTurn(nextTurnStats.culture.toInt()) // disband units until there are none left OR the gold values are normal - if(!isBarbarianCivilization() && gold < -100 && nextTurnStats.gold.toInt() < 0) { + if(!isBarbarian() && gold < -100 && nextTurnStats.gold.toInt() < 0) { for (i in 1 until (gold / -100)) { var civMilitaryUnits = getCivUnits().filter { !it.type.isCivilian() } if (civMilitaryUnits.isNotEmpty()) { diff --git a/core/src/com/unciv/logic/civilization/TechManager.kt b/core/src/com/unciv/logic/civilization/TechManager.kt index 97ab1f0d..43c4935e 100644 --- a/core/src/com/unciv/logic/civilization/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/TechManager.kt @@ -161,7 +161,7 @@ class TechManager { city.cityConstructions.currentConstruction = currentConstructionUnit.upgradesTo!! } - if(techName=="Writing" && civInfo.getNation().unique=="Receive free Great Scientist when you discover Writing, Earn Great Scientists 50% faster" + if(techName=="Writing" && civInfo.nation.unique=="Receive free Great Scientist when you discover Writing, Earn Great Scientists 50% faster" && civInfo.cities.any()) civInfo.addGreatPerson("Great Scientist") } diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 22cd2cc1..7f95fc7f 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -91,7 +91,7 @@ class MapUnit { && civInfo.containsBuildingUnique("All military naval units receive +1 movement and +1 sight")) movement += 1 - if(type.isWaterUnit() && civInfo.getNation().unique=="+2 movement for all naval units") + if(type.isWaterUnit() && civInfo.nation.unique=="+2 movement for all naval units") movement+=2 return movement @@ -133,7 +133,7 @@ class MapUnit { var visibilityRange = 2 visibilityRange += getUniques().count { it == "+1 Visibility Range" } if (hasUnique("Limited Visibility")) visibilityRange -= 1 - if (civInfo.getNation().unique == "All land military units have +1 sight, 50% discount when purchasing tiles") + if (civInfo.nation.unique == "All land military units have +1 sight, 50% discount when purchasing tiles") visibilityRange += 1 if (type.isWaterUnit() && !type.isCivilian() && civInfo.containsBuildingUnique("All military naval units receive +1 movement and +1 sight")) @@ -398,7 +398,7 @@ class MapUnit { fun moveThroughTile(tile: TileInfo){ if(tile.improvement==Constants.ancientRuins && civInfo.isMajorCiv()) getAncientRuinBonus(tile) - if(tile.improvement==Constants.barbarianEncampment && !civInfo.isBarbarianCivilization()) + if(tile.improvement==Constants.barbarianEncampment && !civInfo.isBarbarian()) clearEncampment(tile) currentTile = tile diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index bc20fd46..919eb1d7 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -155,7 +155,7 @@ open class TileInfo { stats.add(resource.getBuilding()!!.resourceBonusStats!!) // resource-specific building (eg forge, stable) bonus } if(resource.resourceType==ResourceType.Strategic - && observingCiv.getNation().unique=="Strategic Resources provide +1 Production, and Horses, Iron and Uranium Resources provide double quantity") + && observingCiv.nation.unique=="Strategic Resources provide +1 Production, and Horses, Iron and Uranium Resources provide double quantity") stats.production+=1 if(resource.name=="Oil" && city!=null && city.containsBuildingUnique("+2 Gold for each source of Oil and oasis")) diff --git a/core/src/com/unciv/models/gamebasics/Nation.kt b/core/src/com/unciv/models/gamebasics/Nation.kt index 336055e3..cfca9847 100644 --- a/core/src/com/unciv/models/gamebasics/Nation.kt +++ b/core/src/com/unciv/models/gamebasics/Nation.kt @@ -60,6 +60,8 @@ class Nation : INamed { } fun isCityState()= cityStateType != null + fun isMajorCiv() = !isBarbarian() && !isCityState() + fun isBarbarian() = name=="Barbarians" lateinit var cities: List } diff --git a/core/src/com/unciv/ui/EmpireOverviewScreen.kt b/core/src/com/unciv/ui/EmpireOverviewScreen.kt index 87e4bcdb..c7672ea3 100644 --- a/core/src/com/unciv/ui/EmpireOverviewScreen.kt +++ b/core/src/com/unciv/ui/EmpireOverviewScreen.kt @@ -122,12 +122,12 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){ private fun createOffersTable(civ: CivilizationInfo, offersList: TradeOffersList, numberOfOtherSidesOffers: Int): Table { val table = Table() table.defaults().pad(10f) - table.background = ImageGetter.getBackground(civ.getNation().getColor()) - table.add(civ.civName.toLabel().setFontColor(civ.getNation().getSecondaryColor())).row() + table.background = ImageGetter.getBackground(civ.nation.getColor()) + table.add(civ.civName.toLabel().setFontColor(civ.nation.getSecondaryColor())).row() table.addSeparator() for(offer in offersList){ val offerText = offer.getOfferText() - table.add(offerText.toLabel().setFontColor(civ.getNation().getSecondaryColor())).row() + table.add(offerText.toLabel().setFontColor(civ.nation.getSecondaryColor())).row() } for(i in 1..numberOfOtherSidesOffers - offersList.size) table.add("".toLabel()).row() // we want both sides of the general table to have the same number of rows @@ -329,7 +329,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){ currentPlayerCivInfo.diplomacy.containsKey(civ.civName) fun getDiplomacyGroup(): Group { - val relevantCivs = currentPlayerCivInfo.gameInfo.civilizations.filter { !it.isBarbarianCivilization() && !it.isCityState() } + val relevantCivs = currentPlayerCivInfo.gameInfo.civilizations.filter { !it.isBarbarian() && !it.isCityState() } val groupSize = 500f val group = Group() group.setSize(groupSize,groupSize) @@ -349,7 +349,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){ for(civ in relevantCivs.filter { playerKnows(it) && !it.isDefeated() }) for(diplomacy in civ.diplomacy.values. - filter { !it.otherCiv().isBarbarianCivilization() && !it.otherCiv().isCityState() + filter { !it.otherCiv().isBarbarian() && !it.otherCiv().isCityState() && playerKnows(it.otherCiv()) && !it.otherCiv().isDefeated()}){ val civGroup = civGroups[civ.civName]!! val otherCivGroup = civGroups[diplomacy.otherCivName]!! @@ -415,9 +415,9 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){ civGroup.background = civGroupBackground.tint(Color.LIGHT_GRAY) label.setFontColor(Color.BLACK) } else if (currentPlayer==civ || currentPlayer.knows(civ)) { - civGroup.add(ImageGetter.getNationIndicator(civ.getNation(), 30f)) - civGroup.background = civGroupBackground.tint(civ.getNation().getColor()) - label.setFontColor(civ.getNation().getSecondaryColor()) + civGroup.add(ImageGetter.getNationIndicator(civ.nation, 30f)) + civGroup.background = civGroupBackground.tint(civ.nation.getColor()) + label.setFontColor(civ.nation.getSecondaryColor()) } else { civGroup.background = civGroupBackground.tint(Color.DARK_GRAY) label.setText("???") diff --git a/core/src/com/unciv/ui/VictoryScreen.kt b/core/src/com/unciv/ui/VictoryScreen.kt index 970a7df2..9fff8806 100644 --- a/core/src/com/unciv/ui/VictoryScreen.kt +++ b/core/src/com/unciv/ui/VictoryScreen.kt @@ -135,7 +135,7 @@ class VictoryScreen : PickerScreen() { val table=Table() table.defaults().pad(5f) for (civ in playerCivInfo.gameInfo.civilizations) { - if (civ.isPlayerCivilization() || civ.isBarbarianCivilization() || civ.isCityState()) continue + if (civ.isCurrentPlayer() || !civ.isMajorCiv()) continue val civName = if (playerCivInfo.diplomacy.containsKey(civ.civName)) civ.civName else "???" diff --git a/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt b/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt index a224007e..37579600 100644 --- a/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt @@ -28,8 +28,10 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: playerListTable.clear() for (player in newGameParameters.players) playerListTable.add(getPlayerTable(player)).pad(10f).row() - playerListTable.add("+".toLabel().setFontSize(30).apply { this.setAlignment(Align.center) } - .setFontColor(Color.BLACK).surroundWithCircle(50f).onClick { newGameParameters.players.add(Player()); update() }) + if(newGameParameters.players.count() < GameBasics.Nations.values.count { it.isMajorCiv() }) { + playerListTable.add("+".toLabel().setFontSize(30).apply { this.setAlignment(Align.center) } + .setFontColor(Color.BLACK).surroundWithCircle(50f).onClick { newGameParameters.players.add(Player()); update() }) + } } fun getPlayerTable(player: Player): Table { diff --git a/core/src/com/unciv/ui/tilegroups/CityButton.kt b/core/src/com/unciv/ui/tilegroups/CityButton.kt index c9750bfa..54c69c91 100644 --- a/core/src/com/unciv/ui/tilegroups/CityButton.kt +++ b/core/src/com/unciv/ui/tilegroups/CityButton.kt @@ -45,10 +45,10 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski private fun addAirUnitTable() { if (!tileGroup.tileInfo.airUnits.isNotEmpty()) return - val secondarycolor = city.civInfo.getNation().getSecondaryColor() + val secondarycolor = city.civInfo.nation.getSecondaryColor() val airUnitTable = Table().apply { defaults().pad(5f) } airUnitTable.background = ImageGetter.getDrawable("OtherIcons/civTableBackground") - .tint(city.civInfo.getNation().getColor()) + .tint(city.civInfo.nation.getColor()) val aircraftImage = ImageGetter.getImage("OtherIcons/Aircraft") aircraftImage.color = secondarycolor airUnitTable.add(aircraftImage).size(15f) @@ -89,11 +89,11 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski } private fun getIconTable(): Table { - val secondaryColor = city.civInfo.getNation().getSecondaryColor() + val secondaryColor = city.civInfo.nation.getSecondaryColor() val iconTable = Table() iconTable.touchable=Touchable.enabled iconTable.background = ImageGetter.getDrawable("OtherIcons/civTableBackground") - .tint(city.civInfo.getNation().getColor()) + .tint(city.civInfo.nation.getColor()) if (city.resistanceCounter > 0) { val resistanceImage = ImageGetter.getImage("StatIcons/Resistance") @@ -128,7 +128,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski if (UnCivGame.Current.viewEntireMapForDebug || city.civInfo.isCurrentPlayer()) iconTable.add(getConstructionGroup(city.cityConstructions)).padRight(10f) else if (city.civInfo.isMajorCiv()) { - val nationIcon = ImageGetter.getNationIcon(city.civInfo.getNation().name) + val nationIcon = ImageGetter.getNationIcon(city.civInfo.nation.name) nationIcon.color = secondaryColor iconTable.add(nationIcon).size(20f).padRight(10f) } @@ -170,7 +170,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski group.addActor(circle) group.addActor(image) - val secondaryColor = cityConstructions.cityInfo.civInfo.getNation().getSecondaryColor() + val secondaryColor = cityConstructions.cityInfo.civInfo.nation.getSecondaryColor() val cityCurrentConstruction = cityConstructions.getCurrentConstruction() if(cityCurrentConstruction !is SpecialConstruction) { val turnsToConstruction = cityConstructions.turnsToConstruction(cityCurrentConstruction.name) diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index fecc557e..443b6460 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -269,7 +269,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) previousTileOwner = tileOwner if (tileOwner == null) return - val civColor = tileInfo.getOwner()!!.getNation().getColor() + val civColor = tileInfo.getOwner()!!.nation.getColor() for (neighbor in tileInfo.neighbors) { val neighborOwner = neighbor.getOwner() if (neighborOwner == tileOwner && borderImages.containsKey(neighbor)) // the neighbor used to not belong to us, but now it's ours diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index 05852a96..1e84b0fd 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -55,10 +55,10 @@ class DiplomacyScreen:CameraStageBaseScreen() { leftSideTable.clear() val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() for (civ in UnCivGame.Current.gameInfo.civilizations - .filterNot { it.isDefeated() || it == currentPlayerCiv || it.isBarbarianCivilization() }) { + .filterNot { it.isDefeated() || it == currentPlayerCiv || it.isBarbarian() }) { if (!currentPlayerCiv.knows(civ)) continue - val civIndicator = ImageGetter.getNationIndicator(civ.getNation(),100f) + val civIndicator = ImageGetter.getNationIndicator(civ.nation,100f) val relationship = ImageGetter.getCircle() if(currentPlayerCiv.isAtWarWith(civ)) relationship.color = Color.RED diff --git a/core/src/com/unciv/ui/utils/UnitGroup.kt b/core/src/com/unciv/ui/utils/UnitGroup.kt index 6771125e..81018359 100644 --- a/core/src/com/unciv/ui/utils/UnitGroup.kt +++ b/core/src/com/unciv/ui/utils/UnitGroup.kt @@ -11,12 +11,12 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() { var blackSpinningCircle:Image?=null init { - val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.getNation().getSecondaryColor()) + val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.nation.getSecondaryColor()) .apply { setSize(size * 0.75f, size * 0.75f) } val background = getBackgroundImageForUnit(unit) background.apply { - this.color = unit.civInfo.getNation().getColor() + this.color = unit.civInfo.nation.getColor() setSize(size, size) } setSize(size, size) diff --git a/core/src/com/unciv/ui/worldscreen/Minimap.kt b/core/src/com/unciv/ui/worldscreen/Minimap.kt index 0e527510..8166e370 100644 --- a/core/src/com/unciv/ui/worldscreen/Minimap.kt +++ b/core/src/com/unciv/ui/worldscreen/Minimap.kt @@ -78,9 +78,9 @@ class Minimap(val tileMapHolder: TileMapHolder) : ScrollPane(null){ if (!(UnCivGame.Current.viewEntireMapForDebug || cloneCivilization.exploredTiles.contains(tileInfo.position))) hex.color = Color.DARK_GRAY else if (tileInfo.isCityCenter() && !tileInfo.isWater) - hex.color = tileInfo.getOwner()!!.getNation().getSecondaryColor() + hex.color = tileInfo.getOwner()!!.nation.getSecondaryColor() else if (tileInfo.getCity() != null && !tileInfo.isWater) - hex.color = tileInfo.getOwner()!!.getNation().getColor() + hex.color = tileInfo.getOwner()!!.nation.getColor() else hex.color = tileInfo.getBaseTerrain().getColor().lerp(Color.GRAY, 0.5f) } } diff --git a/core/src/com/unciv/ui/worldscreen/PlayerReadyScreen.kt b/core/src/com/unciv/ui/worldscreen/PlayerReadyScreen.kt index 1ed538b9..24431ea1 100644 --- a/core/src/com/unciv/ui/worldscreen/PlayerReadyScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/PlayerReadyScreen.kt @@ -10,10 +10,10 @@ class PlayerReadyScreen(currentPlayerCiv: CivilizationInfo) : CameraStageBaseScr init { val table= Table() table.touchable= Touchable.enabled - table.background= ImageGetter.getBackground(currentPlayerCiv.getNation().getColor()) + table.background= ImageGetter.getBackground(currentPlayerCiv.nation.getColor()) table.add("[$currentPlayerCiv] ready?".toLabel().setFontSize(24) - .setFontColor(currentPlayerCiv.getNation().getSecondaryColor())) + .setFontColor(currentPlayerCiv.nation.getSecondaryColor())) table.onClick { UnCivGame.Current.worldScreen = WorldScreen(currentPlayerCiv) diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 25f1512b..65e401f8 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -182,7 +182,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { private fun updateDiplomacyButton(civInfo: CivilizationInfo) { diplomacyButtonWrapper.clear() if(civInfo.getKnownCivs() - .filterNot { it.isDefeated() || it==viewingCiv || it.isBarbarianCivilization() } + .filterNot { it.isDefeated() || it==viewingCiv || it.isBarbarian() } .any()) { displayTutorials("OtherCivEncountered") val btn = TextButton("Diplomacy".tr(), skin) @@ -355,7 +355,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { val shownTutorials = UnCivGame.Current.settings.tutorialsShown displayTutorials("NextTurn") if("BarbarianEncountered" !in shownTutorials - && viewingCiv.viewableTiles.any { it.getUnits().any { unit -> unit.civInfo.isBarbarianCivilization() } }) + && viewingCiv.viewableTiles.any { it.getUnits().any { unit -> unit.civInfo.isBarbarian() } }) displayTutorials("BarbarianEncountered") if(viewingCiv.cities.size > 2) displayTutorials("SecondCity") if(viewingCiv.getHappiness() < 5) displayTutorials("HappinessGettingLow")