M src/main/java/DBObjects/CityDB.java +77 -0
@@ 9,7 9,9 @@ import static com.ajtjp.gearCity.TimePre
import exceptions.CurrencyConversionException;
import java.text.DecimalFormat;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import DBObjects.CalculatedObjects.Interpolater;
import org.apache.log4j.Logger;
/**
@@ 71,6 73,13 @@ public class CityDB {
//TODO: Interpolation, exterpolation
//E.g. England has 1891, 1911, it will use 1891 for a long time...
+ /**
+ * Returns the unadjusted urban population of this city in a given year.
+ * If that isn't available, gives the figure for the most recent prior year available.
+ * TODO: Interpolation.
+ * @param year
+ * @return
+ */
public Integer getBaseUrbanPopulation(int year) {
if (populationByYear.containsKey(year)) {
return populationByYear.get(year);
@@ 228,6 237,74 @@ public class CityDB {
}
}
+ /**
+ * Formula: 50% based on motorways (not yet available)
+ * 30% based on year of game
+ * 20% based on urbanization level.
+ * This should result in nearly everyone wanting a car by the end, but it
+ * being much lower in the beginning
+ * Until motorways data is added, year/urbanization get a double share.
+ * @param year
+ * @return
+ */
+ public double getCalculatedInfrastructure(int year) {
+ //Part one: Gradual increase over the years
+ //In 2020, this will give a value of 1.0, in 1960 it will give 0.5, etc.
+ double infrastructureFromYear = (year - 1900) * (1/120);
+ //Part two: Urbanization
+ double urbanizationLevel = getUrbanizationLevel(year);
+
+ double score = (infrastructureFromYear * 30) + (urbanizationLevel * 20);
+ //Since motorways aren't available, just double the score
+ score *= 2;
+ return score;
+ }
+
+ /**
+ * Returns the calculated manufacturing level for a year.
+ * This is purely based on urbanization for now, theorizing that more urban
+ * populations = more factories = easier to build new factories.
+ * Eventually we may add buffs or debuffs to areas based on historical data.
+ * @param year
+ * @return
+ */
+ public int getManufacturingLevel(int year) {
+ double urbanizationLevel = getUrbanizationLevel(year);
+ return (int)(urbanizationLevel * 100);
+ }
+
+ public double getManufacturingGrowth(int year, int nextYear) {
+ double firstRate = getUrbanizationLevel(year);
+ double secondRate = getUrbanizationLevel(nextYear);
+ return Interpolater.CalculateAnnualizedChange(year, nextYear, firstRate, secondRate);
+ }
+
+ private double getUrbanizationLevel(int year) {
+ int regionPop = this.region.getPopulationInYear(year);
+ double regionalUrbanPop = 0; //for division purposes
+ List<CityDB> regionCities = this.region.getCitiesInRegion();
+ for (CityDB regionalCity : regionCities) {
+ regionalUrbanPop += regionalCity.getBaseUrbanPopulation(year);
+ }
+ //Scale: 0 = no urbanization. 1 = 75% or higher urbanization
+ double rawUrbanizationValue = regionalUrbanPop/regionPop;
+ double scaledValue = rawUrbanizationValue * (4/3);
+ scaledValue = Math.min(scaledValue, 1.0);
+ return scaledValue;
+ }
+
+ /**
+ * Super rough estimation of resources.
+ * Averages infrastructure and manufacturing.
+ * @param year
+ * @return
+ */
+ public double getResources(int year) {
+ double inf = this.getCalculatedInfrastructure(year);
+ double manu = this.getManufacturingLevel(year);
+ return (inf+manu)/2;
+ }
+
// public void get
public void setXMLID(int id) {
M src/main/java/com/ajtjp/gearCity/CityInfoFile/City.java +9 -6
@@ 46,13 46,13 @@ public class City {
this.pOPGROWTH = new POPGROWTH(city.getAnnualizedPopulationGrowthRateBetweenYears(xmlYear, nextXmlYear));
this.cAPITA = new CAPITA(city.getCalculatedGDPPerCapitaForYear(xmlYear)); //todo: add real value
this.eCOGROWTH = new ECOGROWTH(city.getCalculatedEcoGrowth(xmlYear, nextXmlYear));
- this.rESOURCES = new RESOURCES(1);
+ this.rESOURCES = new RESOURCES((int)city.getResources(xmlYear));
this.gAS = new GAS(1);
- this.iNF = new INF(50);
- this.sKILL = new SKILL(50);
- this.wAGE = new WAGE(20);
- this.mNFBASE = new MNFBASE(50);
- this.mANUGROWTH = new MANUGROWTH(1.01);
+ this.iNF = new INF((int)city.getCalculatedInfrastructure(xmlYear));
+ this.sKILL = new SKILL(city.getManufacturingLevel(xmlYear)); //todo: how to figure this out separately? education?
+ this.wAGE = new WAGE(city.getCalculatedGDPPerCapitaForYear(xmlYear)/12);
+ this.mNFBASE = new MNFBASE(city.getManufacturingLevel(xmlYear));
+ this.mANUGROWTH = new MANUGROWTH(city.getManufacturingGrowth(xmlYear, nextXmlYear));
//alignment is always the empty string
this.gOVERN = new GOVERN(1);
this.tAX = new TAX(1.3);
@@ 67,6 67,9 @@ public class City {
this.pIC = new PIC(city.getPicture() + ".dds");
}
if (city.getCountry().getName().equals("Portugal")) {
+ this.cORDS = new CORDS(city.getLongitude() + 0.1, city.getLatitude() - 0.2);
+ }
+ else if (city.getCountry().getName().equals("Spain")) {
this.cORDS = new CORDS(city.getLongitude(), city.getLatitude() - 0.2);
}
else {