mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-09 10:29:02 +07:00
Split CivInfo's responsibility into separate classes: Tech,Policy,GoldenAge,GreatPerson and ScienceVictory managers.
This commit is contained in:
parent
85ffcc58ee
commit
3bb849726a
@ -161,7 +161,7 @@ public class CityConstructions
|
||||
}
|
||||
|
||||
public void purchaseBuilding(String buildingName) {
|
||||
CivilizationInfo.current().civStats.gold -= getConstruction(buildingName).getGoldCost();
|
||||
CivilizationInfo.current().gold -= getConstruction(buildingName).getGoldCost();
|
||||
getConstruction(buildingName).postBuildEvent(this);
|
||||
if(currentConstruction.equals(buildingName)) chooseNextConstruction();
|
||||
getCity().updateCityStats();
|
||||
|
@ -56,7 +56,7 @@ public class CityInfo {
|
||||
// The second seems to be more based, so I'll go with that
|
||||
double a = 6*Math.pow(tilesClaimed+1.4813,1.3);
|
||||
if(CivilizationInfo.current().getBuildingUniques().contains("NewTileCostReduction")) a *= 0.75; //Speciality of Angkor Wat
|
||||
if(CivilizationInfo.current().policies.contains("Tradition")) a *= 0.75;
|
||||
if(CivilizationInfo.current().policies.isAdopted("Tradition")) a *= 0.75;
|
||||
return (int)Math.round(a);
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class CityInfo {
|
||||
civInfo.cities.add(this);
|
||||
CivilizationInfo.current().addNotification(name+" has been founded!",cityLocation);
|
||||
cityConstructions = new CityConstructions(this);
|
||||
if(civInfo.policies.contains("Legalism") && civInfo.cities.size() <= 4) cityConstructions.addCultureBuilding();
|
||||
if(civInfo.policies.isAdopted("Legalism") && civInfo.cities.size() <= 4) cityConstructions.addCultureBuilding();
|
||||
if(civInfo.cities.size()==1) {
|
||||
cityConstructions.builtBuildings.add("Palace");
|
||||
cityConstructions.currentConstruction = "Worker"; // Default for first city only!
|
||||
@ -147,8 +147,8 @@ public class CityInfo {
|
||||
stats.production+=specialists.production*2;
|
||||
stats.science+=specialists.science*3;
|
||||
stats.gold+=specialists.gold*2;
|
||||
if(civInfo.policies.contains("Commerce Complete")) stats.gold+=getNumberOfSpecialists();
|
||||
if(civInfo.policies.contains("Secularism")) stats.science+=getNumberOfSpecialists()*2;
|
||||
if(civInfo.policies.isAdopted("Commerce Complete")) stats.gold+=getNumberOfSpecialists();
|
||||
if(civInfo.policies.isAdopted("Secularism")) stats.science+=getNumberOfSpecialists()*2;
|
||||
|
||||
//idle ppl
|
||||
stats.production += getFreePopulation();
|
||||
@ -157,38 +157,38 @@ public class CityInfo {
|
||||
// Calculated by http://civilization.wikia.com/wiki/Trade_route_(Civ5)
|
||||
double goldFromTradeRoute = civInfo.getCapital().population * 0.15
|
||||
+ population * 1.1 - 1;
|
||||
if(civInfo.policies.contains("Trade Unions")) goldFromTradeRoute+=2;
|
||||
if(civInfo.policies.isAdopted("Trade Unions")) goldFromTradeRoute+=2;
|
||||
if(civInfo.getBuildingUniques().contains("TradeRouteGoldIncrease")) goldFromTradeRoute*=1.25; // Machu Pichu speciality
|
||||
stats.gold += goldFromTradeRoute;
|
||||
}
|
||||
|
||||
stats.add(cityConstructions.getStats());
|
||||
if(civInfo.policies.contains("Tradition") && isCapital())
|
||||
if(civInfo.policies.isAdopted("Tradition") && isCapital())
|
||||
stats.culture+=3;
|
||||
if(civInfo.policies.contains("Landed Elite") && isCapital())
|
||||
if(civInfo.policies.isAdopted("Landed Elite") && isCapital())
|
||||
stats.food+=2;
|
||||
if(CivilizationInfo.current().policies.contains("Tradition Complete"))
|
||||
if(CivilizationInfo.current().policies.isAdopted("Tradition Complete"))
|
||||
stats.food+=2;
|
||||
if(CivilizationInfo.current().policies.contains("Monarchy") && isCapital())
|
||||
if(CivilizationInfo.current().policies.isAdopted("Monarchy") && isCapital())
|
||||
stats.gold+=population/2;
|
||||
if(CivilizationInfo.current().policies.contains("Liberty"))
|
||||
if(CivilizationInfo.current().policies.isAdopted("Liberty"))
|
||||
stats.culture+=1;
|
||||
if(CivilizationInfo.current().policies.contains("Republic"))
|
||||
if(CivilizationInfo.current().policies.isAdopted("Republic"))
|
||||
stats.production+=1;
|
||||
if(CivilizationInfo.current().policies.contains("Universal Suffrage"))
|
||||
if(CivilizationInfo.current().policies.isAdopted("Universal Suffrage"))
|
||||
stats.production+=population/5;
|
||||
if(CivilizationInfo.current().policies.contains("Free Speech"))
|
||||
if(CivilizationInfo.current().policies.isAdopted("Free Speech"))
|
||||
stats.culture+=population/2;
|
||||
|
||||
FullStats statPercentBonuses = cityConstructions.getStatPercentBonuses();
|
||||
if( civInfo.tech.isResearched ("Combustion") &&
|
||||
(isCapital() || isConnectedToCapital(RoadStatus.Railroad))) statPercentBonuses.production += 25;
|
||||
if(civInfo.isGoldenAge()) statPercentBonuses.production+=20;
|
||||
if(civInfo.goldenAges.isGoldenAge()) statPercentBonuses.production+=20;
|
||||
IConstruction currentConstruction = cityConstructions.getCurrentConstruction();
|
||||
if(currentConstruction instanceof Building && ((Building)currentConstruction).isWonder){
|
||||
if(civInfo.getCivResources().containsKey(GameBasics.TileResources.get("Marble")))
|
||||
statPercentBonuses.production+=15;
|
||||
if(civInfo.policies.contains("Aristocracy"))
|
||||
if(civInfo.policies.isAdopted("Aristocracy"))
|
||||
statPercentBonuses.production+=15;
|
||||
}
|
||||
|
||||
@ -197,21 +197,21 @@ public class CityInfo {
|
||||
statPercentBonuses.science+=10;
|
||||
}
|
||||
|
||||
if(civInfo.policies.contains("Collective Rule") && isCapital()
|
||||
if(civInfo.policies.isAdopted("Collective Rule") && isCapital()
|
||||
&& "Settler".equals(cityConstructions.currentConstruction))
|
||||
statPercentBonuses.production+=50;
|
||||
if(civInfo.policies.contains("Republic") && currentConstruction instanceof Building)
|
||||
if(civInfo.policies.isAdopted("Republic") && currentConstruction instanceof Building)
|
||||
statPercentBonuses.production+=5;
|
||||
if(civInfo.policies.contains("Reformation") && cityConstructions.builtBuildings.any(new Predicate<String>() {
|
||||
if(civInfo.policies.isAdopted("Reformation") && cityConstructions.builtBuildings.any(new Predicate<String>() {
|
||||
@Override
|
||||
public boolean evaluate(String arg0) {
|
||||
return GameBasics.Buildings.get(arg0).isWonder;
|
||||
}
|
||||
}))
|
||||
statPercentBonuses.culture+=33;
|
||||
if(civInfo.policies.contains("Commerce") && isCapital())
|
||||
if(civInfo.policies.isAdopted("Commerce") && isCapital())
|
||||
statPercentBonuses.gold+=25;
|
||||
if(civInfo.policies.contains("Sovereignty") && civInfo.getHappinessForNextTurn() >= 0)
|
||||
if(civInfo.policies.isAdopted("Sovereignty") && civInfo.getHappinessForNextTurn() >= 0)
|
||||
statPercentBonuses.science+=15;
|
||||
|
||||
stats.production*=1+statPercentBonuses.production/100; // So they get bonuses for production and gold/science
|
||||
@ -220,7 +220,7 @@ public class CityInfo {
|
||||
float scienceProduced=stats.production/4;
|
||||
if (civInfo.getBuildingUniques().contains("ScienceConversionIncrease"))
|
||||
scienceProduced*=1.33;
|
||||
if(civInfo.policies.contains("Rationalism")) scienceProduced*=1.33;
|
||||
if(civInfo.policies.isAdopted("Rationalism")) scienceProduced*=1.33;
|
||||
stats.science += scienceProduced;
|
||||
}
|
||||
|
||||
@ -231,13 +231,13 @@ public class CityInfo {
|
||||
boolean isUnhappy = civInfo.getHappinessForNextTurn() < 0;
|
||||
if (!isUnhappy) stats.food*=1+statPercentBonuses.food/100; // Regular food bonus revoked when unhappy per https://forums.civfanatics.com/resources/complete-guide-to-happiness-vanilla.25584/
|
||||
stats.food -= population * 2; // Food reduced after the bonus
|
||||
if(CivilizationInfo.current().policies.contains("Civil Society"))
|
||||
if(CivilizationInfo.current().policies.isAdopted("Civil Society"))
|
||||
stats.food+=getNumberOfSpecialists();
|
||||
|
||||
if(isUnhappy) stats.food /= 4; // Reduce excess food to 1/4 per the same
|
||||
if(civInfo.policies.contains("Landed Elite") && isCapital())
|
||||
if(civInfo.policies.isAdopted("Landed Elite") && isCapital())
|
||||
stats.food*=1.1;
|
||||
if(CivilizationInfo.current().policies.contains("Tradition Complete"))
|
||||
if(CivilizationInfo.current().policies.isAdopted("Tradition Complete"))
|
||||
stats.food*=1.15;
|
||||
|
||||
stats.gold-= cityConstructions.getMaintainanceCosts(); // this is AFTER the bonus calculation!
|
||||
@ -249,18 +249,18 @@ public class CityInfo {
|
||||
// in order to determine how much food is produced in a city!
|
||||
float happiness = -3; // -3 happiness per city
|
||||
float unhappinessFromCitizens = population;
|
||||
if(civInfo.policies.contains("Democracy")) unhappinessFromCitizens-=getNumberOfSpecialists()*0.5f;
|
||||
if(civInfo.policies.isAdopted("Democracy")) unhappinessFromCitizens-=getNumberOfSpecialists()*0.5f;
|
||||
if(civInfo.getBuildingUniques().contains("CitizenUnhappinessDecreased"))
|
||||
unhappinessFromCitizens*=0.9;
|
||||
if(civInfo.policies.contains("Aristocracy"))
|
||||
if(civInfo.policies.isAdopted("Aristocracy"))
|
||||
unhappinessFromCitizens*=0.95;
|
||||
happiness-=unhappinessFromCitizens;
|
||||
|
||||
if(civInfo.policies.contains("Aristocracy"))
|
||||
if(civInfo.policies.isAdopted("Aristocracy"))
|
||||
happiness+=population/10;
|
||||
if(civInfo.policies.contains("Monarchy") && isCapital())
|
||||
if(civInfo.policies.isAdopted("Monarchy") && isCapital())
|
||||
happiness+=population/2;
|
||||
if(civInfo.policies.contains("Meritocracy") && isConnectedToCapital(RoadStatus.Road))
|
||||
if(civInfo.policies.isAdopted("Meritocracy") && isConnectedToCapital(RoadStatus.Road))
|
||||
happiness+=1;
|
||||
|
||||
happiness+=(int) cityConstructions.getStats().happiness;
|
||||
@ -413,9 +413,9 @@ public class CityInfo {
|
||||
float multiplier = 1;
|
||||
if(civInfo.getBuildingUniques().contains("GreatPersonGenerationIncrease"))
|
||||
greatPersonPoints = greatPersonPoints.multiply(1.33f);
|
||||
if(civInfo.policies.contains("Entrepreneurship"))
|
||||
if(civInfo.policies.isAdopted("Entrepreneurship"))
|
||||
greatPersonPoints.gold*=1.25;
|
||||
if(civInfo.policies.contains("Freedom"))
|
||||
if(civInfo.policies.isAdopted("Freedom"))
|
||||
greatPersonPoints = greatPersonPoints.multiply(1.25f);
|
||||
|
||||
return greatPersonPoints;
|
||||
|
@ -24,18 +24,16 @@ import java.util.Collection;
|
||||
public class CivilizationInfo {
|
||||
public static CivilizationInfo current(){ return UnCivGame.Current.civInfo; }
|
||||
|
||||
public CivStats civStats = new CivStats();
|
||||
//public CivStats civStats = new CivStats();
|
||||
public int gold = 0;
|
||||
public int baseHappiness = 15;
|
||||
public int numberOfGoldenAges=0;
|
||||
public int turnsLeftForCurrentGoldenAge=0;
|
||||
public int pointsForNextGreatPerson=100;
|
||||
public String civName = "Babylon";
|
||||
|
||||
public FullStats greatPersonPoints = new FullStats();
|
||||
|
||||
public CivilizationTech tech = new CivilizationTech();
|
||||
public CivilizationPolicies policies = new CivilizationPolicies();
|
||||
public int freePolicies=0;
|
||||
public TechManager tech = new TechManager();
|
||||
public PolicyManager policies = new PolicyManager();
|
||||
public GoldenAgeManager goldenAges = new GoldenAgeManager();
|
||||
public GreatPersonManager greatPeople = new GreatPersonManager();
|
||||
public int turns = 1;
|
||||
|
||||
public class Notification{
|
||||
@ -56,7 +54,7 @@ public class CivilizationInfo {
|
||||
public Linq<CityInfo> cities = new Linq<CityInfo>();
|
||||
|
||||
public TileMap tileMap = new TileMap(20);
|
||||
public ScienceVictory scienceVictory = new ScienceVictory();
|
||||
public ScienceVictoryManager scienceVictory = new ScienceVictoryManager();
|
||||
|
||||
public int currentCity =0; //index!
|
||||
|
||||
@ -83,28 +81,19 @@ public class CivilizationInfo {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isGoldenAge(){return turnsLeftForCurrentGoldenAge>0;}
|
||||
public int happinessRequiredForNextGoldenAge(){
|
||||
return (int) ((500+numberOfGoldenAges*250)*(1+cities.size()/100.0)); //https://forums.civfanatics.com/resources/complete-guide-to-happiness-vanilla.25584/
|
||||
}
|
||||
|
||||
public void nextTurn()
|
||||
{
|
||||
notifications.clear();
|
||||
CivStats nextTurnStats = getStatsForNextTurn();
|
||||
boolean couldAdoptPolicyBefore = canAdoptPolicy();
|
||||
civStats.add(nextTurnStats);
|
||||
if(!couldAdoptPolicyBefore && canAdoptPolicy())
|
||||
UnCivGame.Current.setScreen(new PolicyPickerScreen());
|
||||
policies.nextTurn(nextTurnStats.culture);
|
||||
|
||||
int happiness = getHappinessForNextTurn();
|
||||
if(!isGoldenAge() && happiness>0)
|
||||
civStats.happiness += happiness;
|
||||
|
||||
if(cities.size() > 0) tech.nextTurn((int)nextTurnStats.science);
|
||||
|
||||
for (CityInfo city : cities) city.nextTurn();
|
||||
greatPersonPointsForTurn();
|
||||
|
||||
greatPeople.greatPersonPointsForTurn();
|
||||
|
||||
// We need to update the stats after ALL the cities are done updating because
|
||||
// maybe one of them has a wonder that affects the stats of all the rest of the cities
|
||||
@ -118,57 +107,12 @@ public class CivilizationInfo {
|
||||
}
|
||||
})) tile.nextTurn();
|
||||
|
||||
if(isGoldenAge()) turnsLeftForCurrentGoldenAge--;
|
||||
|
||||
if(civStats.happiness > happinessRequiredForNextGoldenAge()){
|
||||
civStats.happiness-=happinessRequiredForNextGoldenAge();
|
||||
enterGoldenAge();
|
||||
numberOfGoldenAges++;
|
||||
}
|
||||
goldenAges.nextTurn(happiness);
|
||||
|
||||
for (CityInfo city : cities) city.updateCityStats();
|
||||
turns++;
|
||||
}
|
||||
|
||||
public void addGreatPerson(String unitName){ // This is also done by some wonders and social policies, remember
|
||||
tileMap.placeUnitNearTile(cities.get(0).cityLocation,unitName);
|
||||
addNotification("A "+unitName+" has been born!",cities.get(0).cityLocation);
|
||||
}
|
||||
|
||||
public void greatPersonPointsForTurn(){
|
||||
for(CityInfo city : cities)
|
||||
greatPersonPoints.add(city.getGreatPersonPoints());
|
||||
|
||||
if(greatPersonPoints.science>pointsForNextGreatPerson){
|
||||
greatPersonPoints.science-=pointsForNextGreatPerson;
|
||||
pointsForNextGreatPerson*=2;
|
||||
addGreatPerson("Great Scientist");
|
||||
}
|
||||
if(greatPersonPoints.production>pointsForNextGreatPerson){
|
||||
greatPersonPoints.production-=pointsForNextGreatPerson;
|
||||
pointsForNextGreatPerson*=2;
|
||||
addGreatPerson("Great Engineer");
|
||||
}
|
||||
if(greatPersonPoints.culture>pointsForNextGreatPerson){
|
||||
greatPersonPoints.culture-=pointsForNextGreatPerson;
|
||||
pointsForNextGreatPerson*=2;
|
||||
addGreatPerson("Great Artist");
|
||||
}
|
||||
if(greatPersonPoints.gold>pointsForNextGreatPerson){
|
||||
greatPersonPoints.gold-=pointsForNextGreatPerson;
|
||||
pointsForNextGreatPerson*=2;
|
||||
addGreatPerson("Great Merchant");
|
||||
}
|
||||
}
|
||||
|
||||
public void enterGoldenAge(){
|
||||
int turnsToGoldenAge = 10;
|
||||
if(getBuildingUniques().contains("GoldenAgeLengthIncrease")) turnsToGoldenAge*=1.5;
|
||||
if(policies.contains("Freedom Complete")) turnsToGoldenAge*=1.5;
|
||||
turnsLeftForCurrentGoldenAge += turnsToGoldenAge;
|
||||
addNotification("You have entered a golden age!",null);
|
||||
}
|
||||
|
||||
public CivStats getStatsForNextTurn() {
|
||||
CivStats statsForTurn = new CivStats();
|
||||
for (CityInfo city : cities) {
|
||||
@ -182,10 +126,10 @@ public class CivilizationInfo {
|
||||
if (tile.roadStatus == RoadStatus.Road) transportationUpkeep+=1;
|
||||
else if(tile.roadStatus == RoadStatus.Railroad) transportationUpkeep+=2;
|
||||
}
|
||||
if(policies.contains("Trade Unions")) transportationUpkeep *= 2/3f;
|
||||
if(policies.isAdopted("Trade Unions")) transportationUpkeep *= 2/3f;
|
||||
statsForTurn.gold -=transportationUpkeep;
|
||||
|
||||
if(policies.contains("Mandate Of Heaven"))
|
||||
if(policies.isAdopted("Mandate Of Heaven"))
|
||||
statsForTurn.culture+=getHappinessForNextTurn()/2;
|
||||
return statsForTurn;
|
||||
}
|
||||
@ -193,7 +137,7 @@ public class CivilizationInfo {
|
||||
public int getHappinessForNextTurn(){
|
||||
int happiness = baseHappiness;
|
||||
int happinessPerUniqueLuxury = 5;
|
||||
if(policies.contains("Protectionism")) happinessPerUniqueLuxury+=1;
|
||||
if(policies.isAdopted("Protectionism")) happinessPerUniqueLuxury+=1;
|
||||
happiness += new Linq<TileResource>(getCivResources().keySet()).count(new Predicate<TileResource>() {
|
||||
@Override
|
||||
public boolean evaluate(TileResource arg0) {
|
||||
@ -204,7 +148,7 @@ public class CivilizationInfo {
|
||||
happiness += city.getCityHappiness();
|
||||
}
|
||||
if(getBuildingUniques().contains("HappinessPerSocialPolicy"))
|
||||
happiness+=policies.count(new Predicate<String>() {
|
||||
happiness+=policies.getAdoptedPolicies().count(new Predicate<String>() {
|
||||
@Override
|
||||
public boolean evaluate(String arg0) {
|
||||
return !arg0.endsWith("Complete");
|
||||
@ -233,26 +177,5 @@ public class CivilizationInfo {
|
||||
}
|
||||
}).unique();
|
||||
}
|
||||
|
||||
public int getCultureNeededForNextPolicy(){
|
||||
// from https://forums.civfanatics.com/threads/the-number-crunching-thread.389702/
|
||||
int basicPolicies = policies.count(new Predicate<String>() {
|
||||
@Override
|
||||
public boolean evaluate(String arg0) {
|
||||
return !arg0.endsWith("Complete");
|
||||
}
|
||||
});
|
||||
double baseCost = 25+ Math.pow(basicPolicies*6,1.7);
|
||||
double cityModifier = 0.3*(cities.size()-1);
|
||||
if(policies.contains("Representation")) cityModifier *= 2/3f;
|
||||
int cost = (int) Math.round(baseCost*(1+cityModifier));
|
||||
if(policies.contains("Piety Complete")) cost*=0.9;
|
||||
if(getBuildingUniques().contains("PolicyCostReduction")) cost*=0.9;
|
||||
return cost-cost%5; // round down to nearest 5
|
||||
}
|
||||
|
||||
public boolean canAdoptPolicy(){
|
||||
return civStats.culture >= getCultureNeededForNextPolicy();
|
||||
}
|
||||
}
|
||||
|
||||
|
34
core/src/com/unciv/logic/civilization/GoldenAgeManager.java
Normal file
34
core/src/com/unciv/logic/civilization/GoldenAgeManager.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.unciv.logic.civilization;
|
||||
|
||||
public class GoldenAgeManager{
|
||||
public int storedHappiness=0;
|
||||
public int numberOfGoldenAges=0;
|
||||
public int turnsLeftForCurrentGoldenAge=0;
|
||||
|
||||
|
||||
public boolean isGoldenAge(){return turnsLeftForCurrentGoldenAge>0;}
|
||||
public int happinessRequiredForNextGoldenAge(){
|
||||
return (int) ((500+numberOfGoldenAges*250)*(1+CivilizationInfo.current().cities.size()/100.0)); //https://forums.civfanatics.com/resources/complete-guide-to-happiness-vanilla.25584/
|
||||
}
|
||||
|
||||
public void enterGoldenAge(){
|
||||
int turnsToGoldenAge = 10;
|
||||
CivilizationInfo civInfo = CivilizationInfo.current();
|
||||
if(civInfo.getBuildingUniques().contains("GoldenAgeLengthIncrease")) turnsToGoldenAge*=1.5;
|
||||
if(civInfo.policies.isAdopted("Freedom Complete")) turnsToGoldenAge*=1.5;
|
||||
turnsLeftForCurrentGoldenAge += turnsToGoldenAge;
|
||||
civInfo.addNotification("You have entered a golden age!",null);
|
||||
}
|
||||
|
||||
public void nextTurn(int happiness) {
|
||||
|
||||
if(happiness>0&& !isGoldenAge()) storedHappiness+=happiness;
|
||||
|
||||
if(isGoldenAge()) turnsLeftForCurrentGoldenAge--;
|
||||
else if(storedHappiness > happinessRequiredForNextGoldenAge()){
|
||||
storedHappiness -= happinessRequiredForNextGoldenAge();
|
||||
enterGoldenAge();
|
||||
numberOfGoldenAges++;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.unciv.logic.civilization;
|
||||
|
||||
import com.unciv.logic.city.CityInfo;
|
||||
import com.unciv.models.stats.FullStats;
|
||||
|
||||
public class GreatPersonManager{
|
||||
|
||||
public void addGreatPerson(String unitName){ // This is also done by some wonders and social policies, remember
|
||||
CivilizationInfo civInfo = CivilizationInfo.current();
|
||||
civInfo.tileMap.placeUnitNearTile(civInfo.getCapital().cityLocation,unitName);
|
||||
civInfo.addNotification("A "+unitName+" has been born!",civInfo.getCapital().cityLocation);
|
||||
}
|
||||
|
||||
public void greatPersonPointsForTurn(){
|
||||
for(CityInfo city : CivilizationInfo.current().cities)
|
||||
greatPersonPoints.add(city.getGreatPersonPoints());
|
||||
|
||||
if(greatPersonPoints.science>pointsForNextGreatPerson){
|
||||
greatPersonPoints.science-=pointsForNextGreatPerson;
|
||||
pointsForNextGreatPerson*=2;
|
||||
addGreatPerson("Great Scientist");
|
||||
}
|
||||
if(greatPersonPoints.production>pointsForNextGreatPerson){
|
||||
greatPersonPoints.production-=pointsForNextGreatPerson;
|
||||
pointsForNextGreatPerson*=2;
|
||||
addGreatPerson("Great Engineer");
|
||||
}
|
||||
if(greatPersonPoints.culture>pointsForNextGreatPerson){
|
||||
greatPersonPoints.culture-=pointsForNextGreatPerson;
|
||||
pointsForNextGreatPerson*=2;
|
||||
addGreatPerson("Great Artist");
|
||||
}
|
||||
if(greatPersonPoints.gold>pointsForNextGreatPerson){
|
||||
greatPersonPoints.gold-=pointsForNextGreatPerson;
|
||||
pointsForNextGreatPerson*=2;
|
||||
addGreatPerson("Great Merchant");
|
||||
}
|
||||
}
|
||||
|
||||
public int pointsForNextGreatPerson=100;
|
||||
|
||||
public FullStats greatPersonPoints = new FullStats();
|
||||
|
||||
}
|
@ -8,17 +8,48 @@ import com.unciv.models.gamebasics.PolicyBranch;
|
||||
import com.unciv.models.linq.Linq;
|
||||
import com.unciv.ui.UnCivGame;
|
||||
import com.unciv.ui.pickerscreens.GreatPersonPickerScreen;
|
||||
import com.unciv.ui.pickerscreens.PolicyPickerScreen;
|
||||
|
||||
|
||||
public class CivilizationPolicies extends Linq<String> {
|
||||
public class PolicyManager {
|
||||
|
||||
public int freePolicies=0;
|
||||
public int storedCulture=0;
|
||||
private Linq<String> adoptedPolicies = new Linq<String>();
|
||||
|
||||
public Linq<String> getAdoptedPolicies(){return adoptedPolicies.clone();}
|
||||
public boolean isAdopted(String policyName){return adoptedPolicies.contains(policyName);}
|
||||
|
||||
|
||||
public int getCultureNeededForNextPolicy(){
|
||||
// from https://forums.civfanatics.com/threads/the-number-crunching-thread.389702/
|
||||
int basicPolicies = adoptedPolicies.count(new Predicate<String>() {
|
||||
@Override
|
||||
public boolean evaluate(String arg0) {
|
||||
return !arg0.endsWith("Complete");
|
||||
}
|
||||
});
|
||||
double baseCost = 25+ Math.pow(basicPolicies*6,1.7);
|
||||
double cityModifier = 0.3*(CivilizationInfo.current().cities.size()-1);
|
||||
if(isAdopted("Representation")) cityModifier *= 2/3f;
|
||||
int cost = (int) Math.round(baseCost*(1+cityModifier));
|
||||
if(isAdopted("Piety Complete")) cost*=0.9;
|
||||
if(CivilizationInfo.current().getBuildingUniques().contains("PolicyCostReduction")) cost*=0.9;
|
||||
return cost-cost%5; // round down to nearest 5
|
||||
}
|
||||
|
||||
public boolean canAdoptPolicy(){
|
||||
return storedCulture >= getCultureNeededForNextPolicy();
|
||||
}
|
||||
|
||||
public void adopt(Policy policy){
|
||||
adoptedPolicies.add(policy.name);
|
||||
|
||||
PolicyBranch branch = GameBasics.PolicyBranches.get(policy.branch);
|
||||
int policiesCompleteInBranch = branch.policies.count(new Predicate<Policy>() {
|
||||
@Override
|
||||
public boolean evaluate(Policy arg0) {
|
||||
return contains(arg0.name);
|
||||
return isAdopted(arg0.name);
|
||||
}
|
||||
});
|
||||
|
||||
@ -32,7 +63,7 @@ public class CivilizationPolicies extends Linq<String> {
|
||||
CivilizationInfo.current().tileMap.
|
||||
placeUnitNearTile(CivilizationInfo.current().getCapital().cityLocation, "Worker");
|
||||
if (policy.name.equals("Representation") || policy.name.equals("Reformation"))
|
||||
CivilizationInfo.current().enterGoldenAge();
|
||||
CivilizationInfo.current().goldenAges.enterGoldenAge();
|
||||
|
||||
if (policy.name.equals("Scientific Revolution"))
|
||||
CivilizationInfo.current().tech.freeTechs+=2;
|
||||
@ -42,10 +73,17 @@ public class CivilizationPolicies extends Linq<String> {
|
||||
city.cityConstructions.addCultureBuilding();
|
||||
|
||||
if (policy.name.equals("Free Religion"))
|
||||
CivilizationInfo.current().freePolicies++;
|
||||
freePolicies++;
|
||||
|
||||
if (policy.name.equals("Liberty Complete"))
|
||||
UnCivGame.Current.setScreen(new GreatPersonPickerScreen());
|
||||
|
||||
}
|
||||
|
||||
public void nextTurn(float culture) {
|
||||
storedCulture+=culture;
|
||||
boolean couldAdoptPolicyBefore = canAdoptPolicy();
|
||||
if(!couldAdoptPolicyBefore && canAdoptPolicy())
|
||||
UnCivGame.Current.setScreen(new PolicyPickerScreen());
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package com.unciv.logic.civilization;
|
||||
|
||||
import com.unciv.models.linq.LinqCounter;
|
||||
|
||||
public class ScienceVictory{
|
||||
public class ScienceVictoryManager {
|
||||
public LinqCounter<String> requiredParts = new LinqCounter<String>(){
|
||||
{
|
||||
add("SS Booster",3);
|
@ -10,7 +10,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class CivilizationTech{
|
||||
public class TechManager {
|
||||
public int freeTechs = 0;
|
||||
|
||||
public HashSet<String> techsResearched = new HashSet<String>();
|
@ -84,10 +84,10 @@ public class TileInfo
|
||||
else stats.add(improvement); // basic improvement
|
||||
|
||||
if (isResearched(improvement.improvingTech)) stats.add(improvement.improvingTechStats); // eg Chemistry for mines
|
||||
if(improvement.name.equals("Trading post") && CivilizationInfo.current().policies.contains("Free Thought"))
|
||||
if(improvement.name.equals("Trading post") && CivilizationInfo.current().policies.isAdopted("Free Thought"))
|
||||
stats.science+=1;
|
||||
if(new Linq<String>("Academy","Landmark","Manufactory","Customs House").contains(improvement.name)
|
||||
&& CivilizationInfo.current().policies.contains("Freedom Complete"))
|
||||
&& CivilizationInfo.current().policies.isAdopted("Freedom Complete"))
|
||||
stats.add(improvement); // again, for the double effect
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ public class TileInfo
|
||||
|
||||
if("Jungle".equals(terrainFeature) && city!=null
|
||||
&& city.getBuildingUniques().contains("JunglesProvideScience")) stats.science+=2;
|
||||
if(stats.gold!=0 && CivilizationInfo.current().isGoldenAge())
|
||||
if(stats.gold!=0 && CivilizationInfo.current().goldenAges.isGoldenAge())
|
||||
stats.gold++;
|
||||
|
||||
return stats;
|
||||
|
@ -48,7 +48,7 @@ public class Building extends NamedStats implements IConstruction, ICivilopedia
|
||||
|
||||
public FullStats getStats(){
|
||||
FullStats stats = new FullStats(this);
|
||||
Linq<String> policies = CivilizationInfo.current().policies;
|
||||
Linq<String> policies = CivilizationInfo.current().policies.getAdoptedPolicies();
|
||||
if (policies.contains("Organized Religion") &&
|
||||
new Linq<String>("Monument","Temple","Monastery").contains(name))
|
||||
stats.happiness+=1;
|
||||
@ -134,15 +134,15 @@ public class Building extends NamedStats implements IConstruction, ICivilopedia
|
||||
|
||||
@Override
|
||||
public int getProductionCost() {
|
||||
if(!isWonder && culture!=0 && CivilizationInfo.current().policies.contains("Piety"))
|
||||
if(!isWonder && culture!=0 && CivilizationInfo.current().policies.isAdopted("Piety"))
|
||||
return (int) (cost*0.85);
|
||||
return cost;
|
||||
}
|
||||
|
||||
public int getGoldCost(){
|
||||
double cost = Math.pow(30 * getProductionCost(),0.75) * (1 + hurryCostModifier/100);
|
||||
if(CivilizationInfo.current().policies.contains("Mercantilism")) cost*=0.75;
|
||||
if(CivilizationInfo.current().policies.contains("Patronage")) cost*=0.5;
|
||||
if(CivilizationInfo.current().policies.isAdopted("Mercantilism")) cost*=0.75;
|
||||
if(CivilizationInfo.current().policies.isAdopted("Patronage")) cost*=0.5;
|
||||
return (int)( cost / 10 ) * 10;
|
||||
}
|
||||
|
||||
@ -214,14 +214,14 @@ public class Building extends NamedStats implements IConstruction, ICivilopedia
|
||||
if (providesFreeBuilding != null && !constructions.builtBuildings.contains(providesFreeBuilding))
|
||||
constructions.builtBuildings.add(providesFreeBuilding);
|
||||
if (freeTechs != 0) UnCivGame.Current.civInfo.tech.freeTechs += freeTechs;
|
||||
if("EmpireEntersGoldenAge".equals(unique)) CivilizationInfo.current().enterGoldenAge();
|
||||
if("FreeGreatArtistAppears".equals(unique)) CivilizationInfo.current().addGreatPerson("Great Artist");
|
||||
if("EmpireEntersGoldenAge".equals(unique)) CivilizationInfo.current().goldenAges.enterGoldenAge();
|
||||
if("FreeGreatArtistAppears".equals(unique)) CivilizationInfo.current().greatPeople.addGreatPerson("Great Artist");
|
||||
if("WorkerConstruction".equals(unique)){
|
||||
CivilizationInfo.current().tileMap.placeUnitNearTile(constructions.cityLocation,"Worker");
|
||||
CivilizationInfo.current().tileMap.placeUnitNearTile(constructions.cityLocation,"Worker");
|
||||
}
|
||||
if("FreeSocialPolicy".equals(unique)){
|
||||
CivilizationInfo.current().freePolicies++;
|
||||
CivilizationInfo.current().policies.freePolicies++;
|
||||
UnCivGame.Current.setScreen(new PolicyPickerScreen());
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class TileImprovement extends NamedStats implements ICivilopedia {
|
||||
float realTurnsToBuild = turnsToBuild;
|
||||
if(CivilizationInfo.current().getBuildingUniques().contains("WorkerConstruction"))
|
||||
realTurnsToBuild*=0.75;
|
||||
if(CivilizationInfo.current().policies.contains("Citizenship"))
|
||||
if(CivilizationInfo.current().policies.isAdopted("Citizenship"))
|
||||
realTurnsToBuild*=0.75;
|
||||
return Math.round(realTurnsToBuild);
|
||||
}
|
||||
|
@ -76,8 +76,12 @@ public class Linq<T> extends ArrayList<T> {
|
||||
}
|
||||
|
||||
public Linq<T> reverse(){
|
||||
Linq<T> newCol = new Linq<T>(this);
|
||||
Linq<T> newCol = clone();
|
||||
Collections.reverse(newCol);
|
||||
return newCol;
|
||||
}
|
||||
|
||||
public Linq<T> clone(){
|
||||
return new Linq<T>(this);
|
||||
}
|
||||
}
|
@ -387,7 +387,7 @@ public class CityScreen extends CameraStageBaseScreen {
|
||||
update();
|
||||
}
|
||||
});
|
||||
if(buildingGoldCost > game.civInfo.civStats.gold){
|
||||
if(buildingGoldCost > game.civInfo.gold){
|
||||
buildingBuyButton.setColor(Color.GRAY);
|
||||
buildingBuyButton.setTouchable(Touchable.disabled);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.unciv.ui;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen;
|
||||
@ -9,11 +10,12 @@ import com.unciv.ui.utils.CameraStageBaseScreen;
|
||||
public class VictoryScreen extends CameraStageBaseScreen{
|
||||
|
||||
public VictoryScreen() {
|
||||
Label label = new Label("Congrendulation!\r\nYou have won!!!!!",skin);
|
||||
label.setFontScale(5);
|
||||
label.setPosition((stage.getWidth()-label.getWidth())/2 , (stage.getHeight()-label.getHeight())/2 );
|
||||
stage.addActor(label);
|
||||
|
||||
Table table = new Table();
|
||||
Label label = new Label("A resounding victory!",skin);
|
||||
label.setFontScale(2);
|
||||
|
||||
table.add(label).pad(20).row();
|
||||
|
||||
TextButton newGameButton = new TextButton("New game!",skin);
|
||||
newGameButton.addListener(new ClickListener(){
|
||||
@ -22,7 +24,13 @@ public class VictoryScreen extends CameraStageBaseScreen{
|
||||
game.startNewGame();
|
||||
}
|
||||
});
|
||||
newGameButton.setPosition((stage.getWidth()-newGameButton.getWidth())/2 , 10);
|
||||
table.add(newGameButton).pad(20).row();
|
||||
|
||||
|
||||
table.pack();
|
||||
table.setPosition((stage.getWidth()-table.getWidth())/2 , (stage.getHeight()-table.getHeight())/2 );
|
||||
|
||||
stage.addActor(table);
|
||||
}
|
||||
|
||||
|
||||
|
@ -273,7 +273,6 @@ public class WorldScreen extends CameraStageBaseScreen {
|
||||
private void updateCivTable() {
|
||||
civTable.clear();
|
||||
civTable.row().pad(15);
|
||||
CivStats currentStats = game.civInfo.civStats;
|
||||
|
||||
TextButton CivilopediaButton = new TextButton("Menu", skin);
|
||||
CivilopediaButton.addListener(new ClickListener() {
|
||||
@ -291,7 +290,7 @@ public class WorldScreen extends CameraStageBaseScreen {
|
||||
|
||||
CivStats nextTurnStats = game.civInfo.getStatsForNextTurn();
|
||||
|
||||
civTable.add(new Label("Gold: " + Math.round(currentStats.gold)
|
||||
civTable.add(new Label("Gold: " + Math.round(game.civInfo.gold)
|
||||
+ "(" + (nextTurnStats.gold > 0 ? "+" : "") + Math.round(nextTurnStats.gold) + ")", skin));
|
||||
|
||||
Label scienceLabel = new Label("Science: +" + Math.round(nextTurnStats.science)
|
||||
@ -299,15 +298,15 @@ public class WorldScreen extends CameraStageBaseScreen {
|
||||
scienceLabel.setAlignment(Align.center);
|
||||
civTable.add(scienceLabel);
|
||||
String happinessText = "Happiness: " + Math.round(game.civInfo.getHappinessForNextTurn());
|
||||
if (game.civInfo.isGoldenAge())
|
||||
happinessText += "\r\n GOLDEN AGE (" + game.civInfo.turnsLeftForCurrentGoldenAge + ")";
|
||||
if (game.civInfo.goldenAges.isGoldenAge())
|
||||
happinessText += "\r\n GOLDEN AGE (" + game.civInfo.goldenAges.turnsLeftForCurrentGoldenAge + ")";
|
||||
else
|
||||
happinessText += "\r\n (" + (int) game.civInfo.civStats.happiness + "/" + game.civInfo.happinessRequiredForNextGoldenAge() + ")";
|
||||
happinessText += "\r\n (" + game.civInfo.goldenAges.storedHappiness + "/" + game.civInfo.goldenAges.happinessRequiredForNextGoldenAge() + ")";
|
||||
Label happinessLabel = new Label(happinessText, skin);
|
||||
happinessLabel.setAlignment(Align.center);
|
||||
civTable.add(happinessLabel);
|
||||
String cultureString = "Culture: " + "+" + Math.round(nextTurnStats.culture) + "\r\n"
|
||||
+ "(" + ((int) game.civInfo.civStats.culture) + "/" + game.civInfo.getCultureNeededForNextPolicy() + ")";
|
||||
+ "(" + game.civInfo.policies.storedCulture + "/" + game.civInfo.policies.getCultureNeededForNextPolicy() + ")";
|
||||
Label cultureLabel = new Label(cultureString, skin);
|
||||
cultureLabel.setAlignment(Align.center);
|
||||
civTable.add(cultureLabel);
|
||||
@ -592,7 +591,7 @@ public class WorldScreen extends CameraStageBaseScreen {
|
||||
new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
game.civInfo.enterGoldenAge();
|
||||
game.civInfo.goldenAges.enterGoldenAge();
|
||||
selectedTile.unit = null;// destroy!
|
||||
update();
|
||||
}
|
||||
@ -636,7 +635,7 @@ public class WorldScreen extends CameraStageBaseScreen {
|
||||
new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
game.civInfo.civStats.gold += 350; // + 50 * era_number - todo!
|
||||
game.civInfo.gold += 350; // + 50 * era_number - todo!
|
||||
selectedTile.unit = null; // destroy!
|
||||
update();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.badlogic.gdx.utils.Predicate;
|
||||
import com.unciv.logic.city.CityInfo;
|
||||
import com.unciv.logic.civilization.CivilizationInfo;
|
||||
import com.unciv.logic.civilization.PolicyManager;
|
||||
import com.unciv.models.linq.Linq;
|
||||
import com.unciv.models.gamebasics.GameBasics;
|
||||
import com.unciv.models.gamebasics.Policy;
|
||||
@ -23,6 +24,7 @@ public class PolicyPickerScreen extends PickerScreen {
|
||||
|
||||
public PolicyPickerScreen() {
|
||||
|
||||
final PolicyManager policies = game.civInfo.policies;
|
||||
Linq<String> tutorial = new Linq<String>();
|
||||
tutorial.add("Each turn, the culture you gain from all your " +
|
||||
"\r\n cities is added to your Civilization's culture." +
|
||||
@ -35,9 +37,9 @@ public class PolicyPickerScreen extends PickerScreen {
|
||||
"\r\n the cost of adopting another policy rises - so choose wisely!");
|
||||
displayTutorials("PolicyPickerScreen",tutorial);
|
||||
|
||||
rightSideButton.setText("Adopt policy\r\n(" + ((int) game.civInfo.civStats.culture) + "/" + game.civInfo.getCultureNeededForNextPolicy() + ")");
|
||||
rightSideButton.setText("Adopt policy\r\n(" + policies.storedCulture + "/" + policies.getCultureNeededForNextPolicy() + ")");
|
||||
|
||||
if(CivilizationInfo.current().freePolicies>0) {
|
||||
if(policies.freePolicies>0) {
|
||||
rightSideButton.setText("Adopt free policy");
|
||||
closeButton.setColor(Color.GRAY);
|
||||
closeButton.setTouchable(Touchable.disabled);
|
||||
@ -46,13 +48,10 @@ public class PolicyPickerScreen extends PickerScreen {
|
||||
rightSideButton.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if(game.civInfo.freePolicies>0) game.civInfo.freePolicies--;
|
||||
else game.civInfo.civStats.culture -= game.civInfo.getCultureNeededForNextPolicy();
|
||||
if(policies.freePolicies>0) policies.freePolicies--;
|
||||
else policies.storedCulture -= policies.getCultureNeededForNextPolicy();
|
||||
game.civInfo.policies.adopt(pickedPolicy);
|
||||
|
||||
if (pickedPolicy.name.equals(""))
|
||||
|
||||
|
||||
game.setScreen(new PolicyPickerScreen());
|
||||
}
|
||||
});
|
||||
@ -93,8 +92,9 @@ public class PolicyPickerScreen extends PickerScreen {
|
||||
}
|
||||
|
||||
public void pickPolicy(Policy policy) {
|
||||
if (game.civInfo.policies.contains(policy.name) || !game.civInfo.policies.containsAll(policy.requires)
|
||||
|| !game.civInfo.canAdoptPolicy()) {
|
||||
if (game.civInfo.policies.isAdopted(policy.name)
|
||||
|| !game.civInfo.policies.getAdoptedPolicies().containsAll(policy.requires)
|
||||
|| !game.civInfo.policies.canAdoptPolicy()) {
|
||||
rightSideButton.setTouchable(Touchable.disabled);
|
||||
rightSideButton.setColor(Color.GRAY);
|
||||
} else {
|
||||
@ -115,9 +115,9 @@ public class PolicyPickerScreen extends PickerScreen {
|
||||
toReturn.add(policyImage).size(30);
|
||||
} else toReturn = new TextButton(policy.name, skin);
|
||||
|
||||
if (game.civInfo.policies.contains(policy.name)) { // existing
|
||||
if (game.civInfo.policies.isAdopted(policy.name)) { // existing
|
||||
toReturn.setColor(Color.GREEN);
|
||||
} else if (!game.civInfo.policies.containsAll(policy.requires)) // non-available
|
||||
} else if (!game.civInfo.policies.getAdoptedPolicies().containsAll(policy.requires)) // non-available
|
||||
{
|
||||
toReturn.setColor(Color.GRAY);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.unciv.logic.civilization.CivilizationTech;
|
||||
import com.unciv.logic.civilization.TechManager;
|
||||
import com.unciv.models.linq.Linq;
|
||||
import com.unciv.models.gamebasics.GameBasics;
|
||||
import com.unciv.models.gamebasics.Technology;
|
||||
@ -20,7 +20,7 @@ public class TechPickerScreen extends PickerScreen {
|
||||
HashMap<String, TextButton> techNameToButton = new HashMap<String, TextButton>();
|
||||
boolean isFreeTechPick;
|
||||
Technology selectedTech;
|
||||
CivilizationTech civTech = game.civInfo.tech;
|
||||
TechManager civTech = game.civInfo.tech;
|
||||
ArrayList<String> techsToResearch = new ArrayList<String>(civTech.techsToResearch);
|
||||
|
||||
public TechPickerScreen(boolean freeTechPick){
|
||||
|
Loading…
Reference in New Issue
Block a user