diff --git a/core/src/com/unciv/logic/city/CityConstructions.java b/core/src/com/unciv/logic/city/CityConstructions.java index 25a2eb51..daa0a42e 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.java +++ b/core/src/com/unciv/logic/city/CityConstructions.java @@ -6,6 +6,7 @@ import com.unciv.models.gamebasics.Building; import com.unciv.models.gamebasics.GameBasics; import com.unciv.models.stats.FullStats; + import java.util.HashMap; diff --git a/core/src/com/unciv/logic/city/CityInfo.java b/core/src/com/unciv/logic/city/CityInfo.java index fce7ffc1..be18e293 100644 --- a/core/src/com/unciv/logic/city/CityInfo.java +++ b/core/src/com/unciv/logic/city/CityInfo.java @@ -140,18 +140,18 @@ public class CityInfo { } public FullStats getGreatPersonPoints(){ - FullStats greatPersonPoints = population.getSpecialists().multiply(3); + FullStats greatPersonPoints = population.getSpecialists().times(3); for(Building building : cityConstructions.getBuiltBuildings()) if(building.greatPersonPoints!=null) greatPersonPoints.add(building.greatPersonPoints); if(civInfo.getBuildingUniques().contains("GreatPersonGenerationIncrease")) - greatPersonPoints = greatPersonPoints.multiply(1.33f); + greatPersonPoints = greatPersonPoints.times(1.33f); if(civInfo.policies.isAdopted("Entrepreneurship")) greatPersonPoints.gold*=1.25; if(civInfo.policies.isAdopted("Freedom")) - greatPersonPoints = greatPersonPoints.multiply(1.25f); + greatPersonPoints = greatPersonPoints.times(1.25f); return greatPersonPoints; } diff --git a/core/src/com/unciv/logic/map/TileInfo.java b/core/src/com/unciv/logic/map/TileInfo.java index 86fa700a..fb5e00ae 100644 --- a/core/src/com/unciv/logic/map/TileInfo.java +++ b/core/src/com/unciv/logic/map/TileInfo.java @@ -68,11 +68,11 @@ public class TileInfo public FullStats getTileStats(CityInfo city, CivilizationInfo observingCiv) { - FullStats stats = new FullStats(getBaseTerrain()); + FullStats stats = getBaseTerrain().clone(); if(terrainFeature !=null){ Terrain terrainFeature = getTerrainFeature(); - if(terrainFeature.overrideStats) stats = new FullStats(terrainFeature); + if(terrainFeature.overrideStats) stats = terrainFeature.clone(); else stats.add(terrainFeature); } diff --git a/core/src/com/unciv/models/gamebasics/Building.java b/core/src/com/unciv/models/gamebasics/Building.java index f3ba8502..18fd30cd 100644 --- a/core/src/com/unciv/models/gamebasics/Building.java +++ b/core/src/com/unciv/models/gamebasics/Building.java @@ -47,7 +47,7 @@ public class Building extends NamedStats implements IConstruction, ICivilopedia public FullStats resourceBonusStats; public FullStats getStats(Linq adoptedPolicies){ - FullStats stats = new FullStats(this); + FullStats stats = this.clone(); if (adoptedPolicies.contains("Organized Religion") && new Linq("Monument","Temple","Monastery").contains(name)) stats.happiness+=1; diff --git a/core/src/com/unciv/models/gamebasics/Terrain.java b/core/src/com/unciv/models/gamebasics/Terrain.java index 8016b259..500de81c 100644 --- a/core/src/com/unciv/models/gamebasics/Terrain.java +++ b/core/src/com/unciv/models/gamebasics/Terrain.java @@ -1,6 +1,5 @@ package com.unciv.models.gamebasics; -import com.unciv.models.stats.FullStats; import com.unciv.models.stats.NamedStats; import java.util.Collection; @@ -36,7 +35,7 @@ public class Terrain extends NamedStats implements ICivilopedia { @Override public String getDescription() { - return ""+new FullStats(this); + return ""+this.clone(); } } diff --git a/core/src/com/unciv/models/gamebasics/TileImprovement.java b/core/src/com/unciv/models/gamebasics/TileImprovement.java index 43f48d17..455e138c 100644 --- a/core/src/com/unciv/models/gamebasics/TileImprovement.java +++ b/core/src/com/unciv/models/gamebasics/TileImprovement.java @@ -28,7 +28,7 @@ public class TileImprovement extends NamedStats implements ICivilopedia { @Override public String getDescription() { StringBuilder stringBuilder = new StringBuilder(); - if(!new FullStats(this).toString().isEmpty()) stringBuilder.append(new FullStats(this)+"\r\n"); + if(!this.clone().toString().isEmpty()) stringBuilder.append(this.clone()+"\r\n"); if(!terrainsCanBeBuiltOn.isEmpty()) stringBuilder.append("Can be built on " + StringUtils.join(", ", terrainsCanBeBuiltOn)); HashMap> statsToResourceNames = new HashMap>(); diff --git a/core/src/com/unciv/models/gamebasics/TileResource.java b/core/src/com/unciv/models/gamebasics/TileResource.java index 50be1859..59f73d26 100644 --- a/core/src/com/unciv/models/gamebasics/TileResource.java +++ b/core/src/com/unciv/models/gamebasics/TileResource.java @@ -22,7 +22,7 @@ public class TileResource extends NamedStats implements ICivilopedia { @Override public String getDescription() { StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(new FullStats(this)+"\r\n"); + stringBuilder.append(this.clone()+"\r\n"); stringBuilder.append("Can be found on " + com.unciv.models.gamebasics.StringUtils.join(", ", terrainsCanBeFoundOn)); stringBuilder.append("\r\n\r\nImproved by "+ improvement +"\r\n"); stringBuilder.append("\r\nBonus stats for improvement: "+ improvementStats +"\r\n"); diff --git a/core/src/com/unciv/models/stats/CivStats.java b/core/src/com/unciv/models/stats/CivStats.java deleted file mode 100644 index 331625cb..00000000 --- a/core/src/com/unciv/models/stats/CivStats.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.unciv.models.stats; - -public class CivStats { - public float gold = 0; - public float science = 0; - public float culture = 0; - public float happiness = 0; - - public void add(CivStats other) { - gold += other.gold; - science += other.science; - happiness += other.happiness; - culture += other.culture; - } -} diff --git a/core/src/com/unciv/models/stats/CivStats.kt b/core/src/com/unciv/models/stats/CivStats.kt new file mode 100644 index 00000000..e1fd92d0 --- /dev/null +++ b/core/src/com/unciv/models/stats/CivStats.kt @@ -0,0 +1,15 @@ +package com.unciv.models.stats + +open class CivStats { + @JvmField var gold = 0f + @JvmField var science = 0f + @JvmField var culture = 0f + @JvmField var happiness = 0f + + fun add(other: CivStats) { + gold += other.gold + science += other.science + happiness += other.happiness + culture += other.culture + } +} diff --git a/core/src/com/unciv/models/stats/FullStats.java b/core/src/com/unciv/models/stats/FullStats.java deleted file mode 100644 index 21a4ace0..00000000 --- a/core/src/com/unciv/models/stats/FullStats.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.unciv.models.stats; - -import java.util.HashMap; - -public class FullStats extends CivStats // also used for hex stats, since it's basically the same -{ - public float production = 0; - public float food = 0; - - public FullStats() { - } - - public FullStats(FullStats other){ - add(other); - } - - public void add(FullStats other){ - gold +=other.gold; - science +=other.science; - happiness +=other.happiness; - culture +=other.culture; - food +=other.food; - production +=other.production; - } - - public FullStats minus(){ - FullStats sub = new FullStats(); - sub.gold=-gold; - sub.science=-science; - sub.happiness=-happiness; - sub.culture=-culture; - sub.food=-food; - sub.production=-production; - return sub; - } - - public FullStats multiply(float number){ - FullStats mul = new FullStats(); - mul.gold=gold*number; - mul.science=science*number; - mul.happiness=happiness*number; - mul.culture=culture*number; - mul.food=food*number; - mul.production=production*number; - return mul; - } - - public String display(float value, String name){ - return ", " + (value>0 ? "+" : "") + Math.round(value) + " "+name; - } - - public String toString() { - StringBuilder valuableParts = new StringBuilder(); - if (production != 0) valuableParts.append(display(production,"Production")); - if (food != 0) valuableParts.append(display(food,"Food")); - if (gold != 0) valuableParts.append(display(gold,"Gold")); - if (science != 0) valuableParts.append(display(science,"Science")); - if (happiness != 0) valuableParts.append(display(happiness,"Happiness")); - if (culture != 0) valuableParts.append(display(culture,"Culture")); - if (valuableParts.length() == 0) return ""; - valuableParts.delete(0,1); - return valuableParts.toString(); - } - - public HashMap toDict(){ - HashMap dict = new HashMap(); - - dict.put("Production", (int) production); - dict.put("Food", (int) food); - dict.put("Gold", (int) gold); - dict.put("Science", (int) science); - dict.put("Culture", (int) culture); - return dict; - } - -} diff --git a/core/src/com/unciv/models/stats/FullStats.kt b/core/src/com/unciv/models/stats/FullStats.kt new file mode 100644 index 00000000..c968d538 --- /dev/null +++ b/core/src/com/unciv/models/stats/FullStats.kt @@ -0,0 +1,58 @@ +package com.unciv.models.stats + +import java.util.HashMap + + +open class FullStats : CivStats() +{ + @JvmField var production: Float = 0f + @JvmField var food: Float = 0f + + fun add(other: FullStats) { + production += other.production + food += other.food + super.add(other) + } + + fun clone():FullStats { + val FS = FullStats() + FS.add(this) + return FS + } + + fun getMinus(): FullStats { + val stats = FullStats() + stats.food = -food + stats.food = -food + stats.gold = -gold + stats.science = -science + stats.culture = -culture + stats.happiness = -happiness + return stats; + } + + operator fun times(number: Float): FullStats{ + val FS = FullStats() + FS.production = production * number + FS.food = food*number + FS.gold = gold*number + FS.science = science*number + FS.culture = culture*number + FS.happiness = happiness*number + return FS + } + + override fun toString(): String { + return toDict().filter{it.value!=0}.map{it.key+": "+it.value}.joinToString(",") + } + + fun toDict(): HashMap { + return hashMapOf("Production" to production.toInt(), + "Food" to food.toInt(), + "Gold" to gold.toInt(), + "Science" to science.toInt(), + "Culture" to culture.toInt() + ) + } + +} diff --git a/core/src/com/unciv/ui/cityscreen/BuildingsTable.java b/core/src/com/unciv/ui/cityscreen/BuildingsTable.java index 8559a546..425414ef 100644 --- a/core/src/com/unciv/ui/cityscreen/BuildingsTable.java +++ b/core/src/com/unciv/ui/cityscreen/BuildingsTable.java @@ -30,7 +30,7 @@ public class BuildingsTable extends Table { @Override public void clicked(InputEvent event, float x, float y) { CityInfo cityInfo = cityScreen.city; - if(isFilled) cityInfo.population.buildingsSpecialists.get(building).add(specialistType.minus()); //unassign + if(isFilled) cityInfo.population.buildingsSpecialists.get(building).add(specialistType.getMinus()); //unassign else if(cityInfo.population.getFreePopulation()==0) return; else { if(!cityInfo.population.buildingsSpecialists.containsKey(building))