First Kotlin change - FullStats and CivStats
This commit is contained in:
parent
9253c40085
commit
49c0707be1
12 changed files with 84 additions and 102 deletions
|
@ -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;
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class Building extends NamedStats implements IConstruction, ICivilopedia
|
|||
public FullStats resourceBonusStats;
|
||||
|
||||
public FullStats getStats(Linq<String> adoptedPolicies){
|
||||
FullStats stats = new FullStats(this);
|
||||
FullStats stats = this.clone();
|
||||
if (adoptedPolicies.contains("Organized Religion") &&
|
||||
new Linq<String>("Monument","Temple","Monastery").contains(name))
|
||||
stats.happiness+=1;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String,ArrayList<String>> statsToResourceNames = new HashMap<String, ArrayList<String>>();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
15
core/src/com/unciv/models/stats/CivStats.kt
Normal file
15
core/src/com/unciv/models/stats/CivStats.kt
Normal file
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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<String,Integer> toDict(){
|
||||
HashMap<String,Integer> dict = new HashMap<String, Integer>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
58
core/src/com/unciv/models/stats/FullStats.kt
Normal file
58
core/src/com/unciv/models/stats/FullStats.kt
Normal file
|
@ -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<String, Int> {
|
||||
return hashMapOf("Production" to production.toInt(),
|
||||
"Food" to food.toInt(),
|
||||
"Gold" to gold.toInt(),
|
||||
"Science" to science.toInt(),
|
||||
"Culture" to culture.toInt()
|
||||
)
|
||||
}
|
||||
|
||||
}
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue