Added tests to ensure we don't miss translations in the future
This commit is contained in:
parent
809cd70f88
commit
fc4eb01be8
5 changed files with 137 additions and 57 deletions
|
@ -802,7 +802,7 @@
|
|||
outerColor:[102,0,0],
|
||||
innerColor:[255,102,102],
|
||||
uniqueName:"Seven Cities of Gold"
|
||||
unique:"100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it). Culture, Happiness and tile yelds from Natural Wonders doubled.",
|
||||
unique:"100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it). Culture, Happiness and tile yields from Natural Wonders doubled.",
|
||||
cities:["Madrid","Barcelona","Seville","Cordoba","Toledo","Santiago","Salamanca","Murcia","Valencia","Zaragoza","Pamplona",
|
||||
"Vitoria","Santander","Oviedo","Jaen","Logroño","Valladolid","Palma","Teruel","Almeria","Leon","Zamora","Mida",
|
||||
"Lugo","Alicante","Càdiz","Eiche","Alcorcon","Burgos","Vigo","Badajoz","La Coruña","Guadalquivir","Bilbao",
|
||||
|
|
|
@ -127,7 +127,7 @@ class CivInfoStats(val civInfo: CivilizationInfo){
|
|||
}
|
||||
|
||||
var happinessPerNaturalWonder = 1f
|
||||
if (civInfo.nation.unique == "100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it). Culture, Happiness and tile yelds from Natural Wonders doubled.")
|
||||
if (civInfo.nation.unique == "100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it). Culture, Happiness and tile yields from Natural Wonders doubled.")
|
||||
happinessPerNaturalWonder *= 2
|
||||
|
||||
statMap["Natural Wonders"] = happinessPerNaturalWonder * civInfo.naturalWonders.size
|
||||
|
|
|
@ -15,6 +15,45 @@ class CivInfoTransientUpdater(val civInfo: CivilizationInfo){
|
|||
|
||||
// This is a big performance
|
||||
fun updateViewableTiles() {
|
||||
setNewViewableTiles()
|
||||
|
||||
val newViewableInvisibleTiles = HashSet<TileInfo>()
|
||||
newViewableInvisibleTiles.addAll(civInfo.getCivUnits().asSequence()
|
||||
.filter { it.hasUnique("Can attack submarines") }
|
||||
.flatMap { it.viewableTiles.asSequence() })
|
||||
civInfo.viewableInvisibleUnitsTiles = newViewableInvisibleTiles
|
||||
|
||||
|
||||
// updating the viewable tiles also affects the explored tiles, obvs
|
||||
// So why don't we play switcharoo with the explored tiles as well?
|
||||
// Well, because it gets REALLY LARGE so it's a lot of memory space,
|
||||
// and we never actually iterate on the explored tiles (only check contains()),
|
||||
// so there's no fear of concurrency problems.
|
||||
val newlyExploredTiles = civInfo.viewableTiles.asSequence().map { it.position }
|
||||
.filterNot { civInfo.exploredTiles.contains(it) }
|
||||
civInfo.exploredTiles.addAll(newlyExploredTiles)
|
||||
|
||||
|
||||
val viewedCivs = HashSet<CivilizationInfo>()
|
||||
for (tile in civInfo.viewableTiles) {
|
||||
val tileOwner = tile.getOwner()
|
||||
if (tileOwner != null) viewedCivs += tileOwner
|
||||
for (unit in tile.getUnits()) viewedCivs += unit.civInfo
|
||||
}
|
||||
|
||||
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 + "]!", null, Color.GOLD)
|
||||
}
|
||||
}
|
||||
|
||||
discoverNaturalWonders()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setNewViewableTiles() {
|
||||
val newViewableTiles = HashSet<TileInfo>()
|
||||
|
||||
// There are a LOT of tiles usually.
|
||||
|
@ -22,9 +61,9 @@ class CivInfoTransientUpdater(val civInfo: CivilizationInfo){
|
|||
// Ans so, sequences to the rescue!
|
||||
val ownedTiles = civInfo.cities.asSequence().flatMap { it.getTiles().asSequence() }
|
||||
newViewableTiles.addAll(ownedTiles)
|
||||
val neighboringUnownedTiles = ownedTiles.flatMap { it.neighbors.asSequence().filter { it.getOwner()!=civInfo } }
|
||||
val neighboringUnownedTiles = ownedTiles.flatMap { it.neighbors.asSequence().filter { it.getOwner() != civInfo } }
|
||||
newViewableTiles.addAll(neighboringUnownedTiles)
|
||||
newViewableTiles.addAll(civInfo.getCivUnits().asSequence().flatMap { it.viewableTiles.asSequence()})
|
||||
newViewableTiles.addAll(civInfo.getCivUnits().asSequence().flatMap { it.viewableTiles.asSequence() })
|
||||
|
||||
if (!civInfo.isCityState()) {
|
||||
for (otherCiv in civInfo.getKnownCivs()) {
|
||||
|
@ -35,64 +74,37 @@ class CivInfoTransientUpdater(val civInfo: CivilizationInfo){
|
|||
}
|
||||
|
||||
civInfo.viewableTiles = newViewableTiles // to avoid concurrent modification problems
|
||||
}
|
||||
|
||||
val newViewableInvisibleTiles = HashSet<TileInfo>()
|
||||
newViewableInvisibleTiles.addAll(civInfo.getCivUnits().asSequence()
|
||||
.filter {it.hasUnique("Can attack submarines")}
|
||||
.flatMap {it.viewableTiles.asSequence()})
|
||||
civInfo.viewableInvisibleUnitsTiles = newViewableInvisibleTiles
|
||||
// updating the viewable tiles also affects the explored tiles, obvs
|
||||
|
||||
// So why don't we play switcharoo with the explored tiles as well?
|
||||
// Well, because it gets REALLY LARGE so it's a lot of memory space,
|
||||
// and we never actually iterate on the explored tiles (only check contains()),
|
||||
// so there's no fear of concurrency problems.
|
||||
val newlyExploredTiles = newViewableTiles.asSequence().map { it.position }
|
||||
.filterNot { civInfo.exploredTiles.contains(it) }
|
||||
civInfo.exploredTiles.addAll(newlyExploredTiles)
|
||||
|
||||
|
||||
val viewedCivs = HashSet<CivilizationInfo>()
|
||||
val viewedNaturalWonders = HashSet<TileInfo>()
|
||||
for(tile in civInfo.viewableTiles){
|
||||
val tileOwner = tile.getOwner()
|
||||
if(tileOwner!=null) viewedCivs+=tileOwner
|
||||
for(unit in tile.getUnits()) viewedCivs+=unit.civInfo
|
||||
if (tile.naturalWonder != null) viewedNaturalWonders += tile
|
||||
private fun discoverNaturalWonders() {
|
||||
val newlyViewedNaturalWonders = HashSet<TileInfo>()
|
||||
for (tile in civInfo.viewableTiles) {
|
||||
if (tile.naturalWonder != null && !civInfo.naturalWonders.contains(tile.naturalWonder!!))
|
||||
newlyViewedNaturalWonders += tile
|
||||
}
|
||||
|
||||
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+"]!", null, Color.GOLD)
|
||||
}
|
||||
for (tile in newlyViewedNaturalWonders) {
|
||||
civInfo.discoverNaturalWonder(tile.naturalWonder!!)
|
||||
civInfo.addNotification("We have discovered [" + tile.naturalWonder + "]!", tile.position, Color.GOLD)
|
||||
|
||||
var goldGained = 0
|
||||
val discoveredNaturalWonders = civInfo.gameInfo.civilizations.filter { it != civInfo }
|
||||
.flatMap { it.naturalWonders }
|
||||
if (tile.naturalWonder == "El Dorado" && !discoveredNaturalWonders.contains(tile.naturalWonder!!)) {
|
||||
goldGained += 500
|
||||
}
|
||||
|
||||
for (tile in viewedNaturalWonders) {
|
||||
if (!civInfo.naturalWonders.contains(tile.naturalWonder)) {
|
||||
civInfo.discoverNaturalWonder(tile.naturalWonder!!)
|
||||
civInfo.addNotification("We have discovered [" + tile.naturalWonder + "]!", tile.position, Color.GOLD)
|
||||
|
||||
var goldGained = 0
|
||||
val discoveredNaturalWonders = civInfo.gameInfo.civilizations.filter { it != civInfo }.flatMap { it.naturalWonders }
|
||||
if (tile.naturalWonder == "El Dorado" && !discoveredNaturalWonders.contains(tile.naturalWonder!!)) {
|
||||
goldGained += 500
|
||||
}
|
||||
|
||||
if (civInfo.nation.unique == "100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it). Culture, Happiness and tile yelds from Natural Wonders doubled.") {
|
||||
if (!discoveredNaturalWonders.contains(tile.naturalWonder!!))
|
||||
goldGained += 500
|
||||
else
|
||||
goldGained += 100
|
||||
}
|
||||
|
||||
if (goldGained > 0) {
|
||||
civInfo.gold += goldGained
|
||||
civInfo.addNotification("We have received " + goldGained + " Gold for discovering [" + tile.naturalWonder + "]", null, Color.GOLD)
|
||||
}
|
||||
}
|
||||
if (civInfo.nation.unique == "100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it). Culture, Happiness and tile yields from Natural Wonders doubled.") {
|
||||
if (!discoveredNaturalWonders.contains(tile.naturalWonder!!))
|
||||
goldGained += 500
|
||||
else goldGained += 100
|
||||
}
|
||||
|
||||
if (goldGained > 0) {
|
||||
civInfo.gold += goldGained
|
||||
civInfo.addNotification("We have received " + goldGained + " Gold for discovering [" + tile.naturalWonder + "]", null, Color.GOLD)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ open class TileInfo {
|
|||
stats.add(wonder)
|
||||
|
||||
// Spain doubles tile yield
|
||||
if (city != null && city.civInfo.nation.unique == "100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it). Culture, Happiness and tile yelds from Natural Wonders doubled.") {
|
||||
if (city != null && city.civInfo.nation.unique == "100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it). Culture, Happiness and tile yields from Natural Wonders doubled.") {
|
||||
stats.add(wonder)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,17 @@ package de.tomgrill.gdxtesting.examples;
|
|||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.unciv.models.ruleset.Building;
|
||||
import com.unciv.models.ruleset.Nation;
|
||||
import com.unciv.models.ruleset.Ruleset;
|
||||
import com.unciv.models.ruleset.tech.Technology;
|
||||
import com.unciv.models.ruleset.tile.TileImprovement;
|
||||
import com.unciv.models.ruleset.unit.BaseUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import de.tomgrill.gdxtesting.GdxTestRunner;
|
||||
|
@ -37,6 +42,22 @@ public class TranslationTests {
|
|||
allUnitsHaveTranslation);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allUnitUniquesHaveTranslation() {
|
||||
Set<String> strings = new HashSet<String>();
|
||||
for (BaseUnit unit : ruleSet.getUnits().values())
|
||||
for (String unique : unit.getUniques())
|
||||
if (!unique.startsWith("Bonus")
|
||||
&& !unique.startsWith("Penalty")
|
||||
&& !unique.contains("[")) // templates
|
||||
strings.add(unique);
|
||||
|
||||
Boolean allStringsHaveTranslation = allStringAreTranslated(strings);
|
||||
assertTrue(allStringsHaveTranslation);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allBuildingsHaveTranslation() {
|
||||
Boolean allBuildingsHaveTranslation = allStringAreTranslated(ruleSet.getBuildings().keySet());
|
||||
|
@ -44,6 +65,29 @@ public class TranslationTests {
|
|||
allBuildingsHaveTranslation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allBuildingUniquesHaveTranslation() {
|
||||
Set<String> strings = new HashSet<String>();
|
||||
for(Building building: ruleSet.getBuildings().values()){
|
||||
strings.addAll(building.getUniques());
|
||||
}
|
||||
Boolean allStringsHaveTranslation = allStringAreTranslated(strings);
|
||||
assertTrue(allStringsHaveTranslation);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allBuildingQuotesHaveTranslation() {
|
||||
Set<String> strings = new HashSet<String>();
|
||||
for(Building building: ruleSet.getBuildings().values()){
|
||||
if(building.getQuote().equals("")) continue;
|
||||
strings.add(building.getQuote());
|
||||
}
|
||||
Boolean allStringsHaveTranslation = allStringAreTranslated(strings);
|
||||
assertTrue(allStringsHaveTranslation);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allTerrainsHaveTranslation() {
|
||||
Set<String> strings = ruleSet.getTerrains().keySet();
|
||||
|
@ -60,6 +104,18 @@ public class TranslationTests {
|
|||
allStringsHaveTranslation);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allImprovementUniquesHaveTranslation() {
|
||||
Set<String> strings = new HashSet<String>();
|
||||
for(TileImprovement improvement: ruleSet.getTileImprovements().values()){
|
||||
strings.addAll(improvement.getUniques());
|
||||
}
|
||||
Boolean allStringsHaveTranslation = allStringAreTranslated(strings);
|
||||
assertTrue(allStringsHaveTranslation);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allTechnologiesHaveTranslation() {
|
||||
Set<String> strings = ruleSet.getTechnologies().keySet();
|
||||
|
@ -68,6 +124,18 @@ public class TranslationTests {
|
|||
allStringsHaveTranslation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allTechnologiesQuotesHaveTranslation() {
|
||||
Set<String> strings = new HashSet<String>();
|
||||
for(Technology tech : ruleSet.getTechnologies().values()){
|
||||
strings.add(tech.getQuote());
|
||||
}
|
||||
Boolean allStringsHaveTranslation = allStringAreTranslated(strings);
|
||||
assertTrue("This test will only pass when there is a translation for all technologies",
|
||||
allStringsHaveTranslation);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allPromotionsHaveTranslation() {
|
||||
Set<String> strings = ruleSet.getUnitPromotions().keySet();
|
||||
|
|
Loading…
Reference in a new issue