From 2d12f1fa80cb7ca215630f6efa94169472138254 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 13 Dec 2017 21:24:51 +0200 Subject: [PATCH] Added golden ages! --- core/src/com/unciv/civinfo/CityBuildings.java | 3 ++- core/src/com/unciv/civinfo/CityInfo.java | 5 ++-- .../com/unciv/civinfo/CivilizationInfo.java | 26 +++++++++++++++++-- .../com/unciv/civinfo/CivilizationTech.java | 9 ++++--- core/src/com/unciv/civinfo/TileInfo.java | 3 +++ core/src/com/unciv/game/WorldScreen.java | 14 +++++++--- 6 files changed, 49 insertions(+), 11 deletions(-) diff --git a/core/src/com/unciv/civinfo/CityBuildings.java b/core/src/com/unciv/civinfo/CityBuildings.java index e84ea10022..845e6ff845 100644 --- a/core/src/com/unciv/civinfo/CityBuildings.java +++ b/core/src/com/unciv/civinfo/CityBuildings.java @@ -82,6 +82,7 @@ public class CityBuildings if (gameBuilding.providesFreeBuilding != null && !builtBuildings.contains(gameBuilding.providesFreeBuilding)) builtBuildings.add(gameBuilding.providesFreeBuilding); if (gameBuilding.freeTechs != 0) UnCivGame.Current.civInfo.tech.freeTechs += gameBuilding.freeTechs; + if("EmpireEntersGoldenAge".equals(gameBuilding.unique)) CivilizationInfo.current().enterGoldenAge(); } inProgressBuildings.remove(currentBuilding); @@ -168,7 +169,7 @@ public class CityBuildings @Override public boolean evaluate(Building arg0) { return canBuild(arg0); } }) - .select(new com.unciv.models.LinqCollection.Func() { + .select(new LinqCollection.Func() { @Override public String GetBy(Building arg0) { return arg0.name; diff --git a/core/src/com/unciv/civinfo/CityInfo.java b/core/src/com/unciv/civinfo/CityInfo.java index ff7b8d5b88..ddf9339a81 100644 --- a/core/src/com/unciv/civinfo/CityInfo.java +++ b/core/src/com/unciv/civinfo/CityInfo.java @@ -133,6 +133,7 @@ public class CityInfo { FullStats statPercentBonuses = cityBuildings.getStatPercentBonuses(); if(isCapital() || isConnectedToCapital(RoadStatus.Railroad)) statPercentBonuses.production += 25; + if(CivilizationInfo.current().isGoldenAge()) statPercentBonuses.production+=20; stats.food*=1+statPercentBonuses.food/100; stats.gold*=1+statPercentBonuses.gold/100; stats.production*=1+statPercentBonuses.production/100; @@ -145,9 +146,9 @@ public class CityInfo { this.cityStats = stats; } - public float getCityHappiness(){ // needs to be a separate function because we need to know the global happiness state + public int getCityHappiness(){ // needs to be a separate function because we need to know the global happiness state // in order to determine how much food is produced in a city! - float happiness = -3 - population; // -3 happiness per city and -1 per population + int happiness = -3 - population; // -3 happiness per city and -1 per population return happiness + (int)cityBuildings.getStats().happiness; } diff --git a/core/src/com/unciv/civinfo/CivilizationInfo.java b/core/src/com/unciv/civinfo/CivilizationInfo.java index 8c8a8b5e21..2090770ef3 100644 --- a/core/src/com/unciv/civinfo/CivilizationInfo.java +++ b/core/src/com/unciv/civinfo/CivilizationInfo.java @@ -22,6 +22,8 @@ public class CivilizationInfo { public CivStats civStats = new CivStats(); public int baseHappiness = 15; + public int numberOfGoldenAges=0; + public int turnsLeftForCurrentGoldenAge=0; public String civName = "Babylon"; public CivilizationTech tech = new CivilizationTech(); @@ -58,12 +60,20 @@ 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(); civStats.add(nextTurnStats); + if(!isGoldenAge()) + civStats.happiness += getHappinessForNextTurn(); + if(cities.size() > 0) tech.nextTurn((int)nextTurnStats.science); for (CityInfo city : cities) city.nextTurn(); @@ -71,7 +81,19 @@ public class CivilizationInfo { for(TileInfo tile : tileMap.values()) tile.nextTurn(); for (CityInfo city : cities) city.updateCityStats(); - turns += 1; + turns++; + if(isGoldenAge()) turnsLeftForCurrentGoldenAge--; + + if(civStats.happiness > happinessRequiredForNextGoldenAge()){ + enterGoldenAge(); + numberOfGoldenAges++; + } + } + + public void enterGoldenAge(){ + civStats.happiness-=happinessRequiredForNextGoldenAge(); + turnsLeftForCurrentGoldenAge = 10; + if(getBuildingUniques().contains("GoldenAgeLengthIncrease")) turnsLeftForCurrentGoldenAge*=1.5; } public CivStats getStatsForNextTurn() { @@ -79,7 +101,7 @@ public class CivilizationInfo { for (CityInfo city : cities) { statsForTurn.add(city.cityStats); } - statsForTurn.happiness = getHappinessForNextTurn(); + statsForTurn.happiness=0; return statsForTurn; } diff --git a/core/src/com/unciv/civinfo/CivilizationTech.java b/core/src/com/unciv/civinfo/CivilizationTech.java index 383f1dcc3b..677bea6d1c 100644 --- a/core/src/com/unciv/civinfo/CivilizationTech.java +++ b/core/src/com/unciv/civinfo/CivilizationTech.java @@ -41,9 +41,7 @@ public class CivilizationTech{ public void nextTurn(int scienceForNewTurn){ String CurrentTechnology = currentTechnology(); - if (!techsInProgress.containsKey(CurrentTechnology)) - techsInProgress.put(CurrentTechnology, 0); - techsInProgress.put(CurrentTechnology, techsInProgress.get(CurrentTechnology) + scienceForNewTurn); + techsInProgress.put(CurrentTechnology, researchOfTech(CurrentTechnology) + scienceForNewTurn); if (techsInProgress.get(CurrentTechnology) >= getCurrentTechnology().cost) // We finished it! { techsInProgress.remove(CurrentTechnology); @@ -53,4 +51,9 @@ public class CivilizationTech{ } } + public String getAmountResearchedText(){ + if(currentTechnology()==null) return ""; + return "("+researchOfTech(currentTechnology())+"/"+getCurrentTechnology().cost+")"; + } + } diff --git a/core/src/com/unciv/civinfo/TileInfo.java b/core/src/com/unciv/civinfo/TileInfo.java index 45f905b148..8e08f47df7 100644 --- a/core/src/com/unciv/civinfo/TileInfo.java +++ b/core/src/com/unciv/civinfo/TileInfo.java @@ -86,9 +86,12 @@ public class TileInfo if (stats.food < 2) stats.food = 2; if (stats.production < 1) stats.production = 1; } + if (stats.production < 0) stats.production = 0; if("Jungle".equals(terrainFeature) && city.getBuildingUniques().contains("JunglesProvideScience")) stats.science+=2; + if(stats.gold!=0 && CivilizationInfo.current().isGoldenAge()) + stats.gold++; return stats; } diff --git a/core/src/com/unciv/game/WorldScreen.java b/core/src/com/unciv/game/WorldScreen.java index 26b9caa0c8..ee94cade52 100644 --- a/core/src/com/unciv/game/WorldScreen.java +++ b/core/src/com/unciv/game/WorldScreen.java @@ -171,7 +171,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen { private void updateCivTable() { CivTable.clear(); - CivTable.row().pad(20); + CivTable.row().pad(15); CivStats currentStats = game.civInfo.civStats; TextButton CivilopediaButton = new TextButton("Menu",skin); @@ -193,8 +193,16 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen { CivTable.add(new Label("Gold: " + Math.round(currentStats.gold) + "(" +(nextTurnStats.gold >0?"+":"") + Math.round(nextTurnStats.gold) +")", skin)); - CivTable.add(new Label("Science: +" + Math.round(nextTurnStats.science), skin)); - CivTable.add(new Label("Happiness: " + Math.round(nextTurnStats.happiness), skin)); + Label scienceLabel = new Label("Science: +" + Math.round(nextTurnStats.science) + +"\r\n"+game.civInfo.tech.getAmountResearchedText(), skin); + 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+")"; + else happinessText+= "\r\n ("+(int)game.civInfo.civStats.happiness+"/"+game.civInfo.happinessRequiredForNextGoldenAge()+")"; + Label happinessLabel = new Label(happinessText, skin); + happinessLabel.setAlignment(Align.center); + CivTable.add(happinessLabel); CivTable.add(new Label("Culture: " + Math.round(currentStats.culture) + "(+" + Math.round(nextTurnStats.culture) +")", skin)); CivTable.pack();