diff --git a/core/src/com/unciv/civinfo/CityBuildings.java b/core/src/com/unciv/civinfo/CityBuildings.java index 20f0e8da..8b0e49e5 100644 --- a/core/src/com/unciv/civinfo/CityBuildings.java +++ b/core/src/com/unciv/civinfo/CityBuildings.java @@ -25,64 +25,64 @@ public class CityBuildings cityLocation = cityInfo.cityLocation; } - public LinqCollection BuiltBuildings = new LinqCollection(); - public HashMap InProgressBuildings = new HashMap(); - public String CurrentBuilding = Worker; // default starting building! + public LinqCollection builtBuildings = new LinqCollection(); + public HashMap inProgressBuildings = new HashMap(); + public String currentBuilding = Worker; // default starting building! - public CityInfo GetCity(){return UnCivGame.Current.civInfo.tileMap.get(cityLocation).getCity(); } - public boolean IsBuilt(String buildingName) { return BuiltBuildings.contains(buildingName); } - public boolean IsBuilding(String buildingName) { return CurrentBuilding.equals(buildingName); } + public CityInfo getCity(){return UnCivGame.Current.civInfo.tileMap.get(cityLocation).getCity(); } + public boolean isBuilt(String buildingName) { return builtBuildings.contains(buildingName); } + public boolean isBuilding(String buildingName) { return currentBuilding.equals(buildingName); } - Building GetGameBuilding(String buildingName) { return GameBasics.Buildings.get(buildingName); } - public LinqCollection GetBuiltBuildings(){ return BuiltBuildings.select(new LinqCollection.Func() { + Building getGameBuilding(String buildingName) { return GameBasics.Buildings.get(buildingName); } + public LinqCollection getBuiltBuildings(){ return builtBuildings.select(new LinqCollection.Func() { @Override public Building GetBy(String arg0) { - return GetGameBuilding(arg0); + return getGameBuilding(arg0); } }); } - public void NextTurn(int ProductionProduced) + public void nextTurn(int ProductionProduced) { - if (CurrentBuilding == null) return; - if (!InProgressBuildings.containsKey(CurrentBuilding)) InProgressBuildings.put(CurrentBuilding, 0); - InProgressBuildings.put(CurrentBuilding, InProgressBuildings.get(CurrentBuilding) + ProductionProduced); + if (currentBuilding == null) return; + if (!inProgressBuildings.containsKey(currentBuilding)) inProgressBuildings.put(currentBuilding, 0); + inProgressBuildings.put(currentBuilding, inProgressBuildings.get(currentBuilding) + ProductionProduced); - if (InProgressBuildings.get(CurrentBuilding) >= GetGameBuilding(CurrentBuilding).cost) + if (inProgressBuildings.get(currentBuilding) >= getGameBuilding(currentBuilding).cost) { - if (CurrentBuilding.equals(Worker) || CurrentBuilding.equals(Settler)) - UnCivGame.Current.civInfo.tileMap.get(cityLocation).unit = new Unit(CurrentBuilding,2); + if (currentBuilding.equals(Worker) || currentBuilding.equals(Settler)) + UnCivGame.Current.civInfo.tileMap.get(cityLocation).unit = new Unit(currentBuilding,2); else { - BuiltBuildings.add(CurrentBuilding); - Building gameBuilding = GetGameBuilding(CurrentBuilding); - if (gameBuilding.providesFreeBuilding != null && !BuiltBuildings.contains(gameBuilding.providesFreeBuilding)) - BuiltBuildings.add(gameBuilding.providesFreeBuilding); + builtBuildings.add(currentBuilding); + Building gameBuilding = getGameBuilding(currentBuilding); + if (gameBuilding.providesFreeBuilding != null && !builtBuildings.contains(gameBuilding.providesFreeBuilding)) + builtBuildings.add(gameBuilding.providesFreeBuilding); if (gameBuilding.freeTechs != 0) UnCivGame.Current.civInfo.tech.FreeTechs += gameBuilding.freeTechs; } - InProgressBuildings.remove(CurrentBuilding); + inProgressBuildings.remove(currentBuilding); // Choose next building to build - CurrentBuilding = GetBuildableBuildings().first(new Predicate() { + currentBuilding = getBuildableBuildings().first(new Predicate() { @Override public boolean evaluate(String arg0) { if(arg0.equals(Settler) || arg0.equals(Worker)) return false; - return !BuiltBuildings.contains(arg0); + return !builtBuildings.contains(arg0); } }); - if (CurrentBuilding == null) CurrentBuilding = Worker; + if (currentBuilding == null) currentBuilding = Worker; } } - public boolean CanBuild(final Building building) + public boolean canBuild(final Building building) { CivilizationInfo civInfo = UnCivGame.Current.civInfo; - if(IsBuilt(building.name)) return false; + if(isBuilt(building.name)) return false; // if (building.name.equals("Worker") || building.name.equals("Settler")) return false; if(building.resourceRequired) { - boolean containsResourceWithImprovement = GetCity().getTilesInRange() + boolean containsResourceWithImprovement = getCity().getTilesInRange() .any(new Predicate() { @Override public boolean evaluate(TileInfo tile) { @@ -100,27 +100,27 @@ public class CityBuildings @Override public boolean evaluate(CityInfo arg0) { CityBuildings CB = arg0.cityBuildings; - return CB.IsBuilding(building.name) || CB.IsBuilt(building.name); + return CB.isBuilding(building.name) || CB.isBuilt(building.name); } }) ) return false; - if (building.requiredBuilding != null && !IsBuilt(building.requiredBuilding)) return false; + if (building.requiredBuilding != null && !isBuilt(building.requiredBuilding)) return false; if (building.requiredBuildingInAllCities != null || civInfo.cities.any(new Predicate() { @Override public boolean evaluate(CityInfo arg0) { - return arg0.cityBuildings.IsBuilt(building.requiredBuildingInAllCities); + return arg0.cityBuildings.isBuilt(building.requiredBuildingInAllCities); } }) ) return false; return true; } - public com.unciv.models.LinqCollection GetBuildableBuildings() + public LinqCollection getBuildableBuildings() { - return new com.unciv.models.LinqCollection(GameBasics.Buildings.values()) + return new LinqCollection(GameBasics.Buildings.values()) .where(new Predicate() { @Override - public boolean evaluate(Building arg0) { return CanBuild(arg0); } + public boolean evaluate(Building arg0) { return canBuild(arg0); } }) .select(new com.unciv.models.LinqCollection.Func() { @Override @@ -130,12 +130,12 @@ public class CityBuildings }); } - public FullStats GetStats() + public FullStats getStats() { FullStats stats = new FullStats(); - for (String building : BuiltBuildings) + for (String building : builtBuildings) { - Building gameBuilding = GetGameBuilding(building); + Building gameBuilding = getGameBuilding(building); stats.add(gameBuilding); //if (gameBuilding.GetFlatBonusStats != null) stats.add(gameBuilding.GetFlatBonusStats(cityInfo)); stats.gold -= gameBuilding.maintainance; @@ -143,14 +143,14 @@ public class CityBuildings return stats; } - public int TurnsToBuilding(String buildingName) + public int turnsToBuilding(String buildingName) { int workDone = 0; - if (InProgressBuildings.containsKey(buildingName)) workDone = InProgressBuildings.get(buildingName); - float workLeft = GetGameBuilding(buildingName).cost - workDone; // needs to be float so that we get the cieling properly ;) + if (inProgressBuildings.containsKey(buildingName)) workDone = inProgressBuildings.get(buildingName); + float workLeft = getGameBuilding(buildingName).cost - workDone; // needs to be float so that we get the cieling properly ;) - FullStats cityStats = GetCity().getCityStats(); - int production = cityStats.production; + FullStats cityStats = getCity().getCityStats(); + int production = Math.round(cityStats.production); if (buildingName.equals(Settler)) production += cityStats.food; return (int) Math.ceil(workLeft / production); diff --git a/core/src/com/unciv/civinfo/CityInfo.java b/core/src/com/unciv/civinfo/CityInfo.java index 276877bb..e926ddef 100644 --- a/core/src/com/unciv/civinfo/CityInfo.java +++ b/core/src/com/unciv/civinfo/CityInfo.java @@ -2,6 +2,7 @@ package com.unciv.civinfo; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Predicate; +import com.unciv.game.CivilopediaScreen; import com.unciv.game.UnCivGame; import com.unciv.models.LinqCollection; import com.unciv.models.gamebasics.ResourceType; @@ -21,6 +22,7 @@ public class CityInfo { private TileMap getTileMap(){return UnCivGame.Current.civInfo.tileMap; } + public TileInfo getTile(){return getTileMap().get(cityLocation);} public LinqCollection getTilesInRange(){ return getTileMap().getTilesInDistance(cityLocation,3).where(new Predicate() { @Override @@ -55,8 +57,9 @@ public class CityInfo { for(TileInfo tileInfo : civInfo.tileMap.getTilesInDistance(cityLocation,1)) { tileInfo.owner = civInfo.civName; } - civInfo.tileMap.get(cityLocation).workingCity = this.name; + getTile().workingCity = this.name; + getTile().roadStatus = RoadStatus.Railroad; autoAssignWorker(); civInfo.cities.add(this); @@ -91,10 +94,8 @@ public class CityInfo { } public FullStats getCityStats() { - FullStats stats = new FullStats() {{ - happiness = -3 - cityPopulation.Population; // -3 happiness per city and -3 per population - }}; - + FullStats stats = new FullStats(); + stats.happiness = -3 - cityPopulation.Population; // -3 happiness per city and -3 per population stats.science += cityPopulation.Population; // Working ppl @@ -106,7 +107,11 @@ public class CityInfo { stats.production += getFreePopulation(); stats.food -= cityPopulation.Population * 2; - stats.add(cityBuildings.GetStats()); + if(!isCapital() && isConnectedToCapital()) // Calculated by http://civilization.wikia.com/wiki/Trade_route_(Civ5) + stats.gold+= CivilizationInfo.current().getCapital().cityPopulation.Population * 0.15 + + cityPopulation.Population * 1.1 - 1; + + stats.add(cityBuildings.getStats()); return stats; } @@ -114,14 +119,14 @@ public class CityInfo { void nextTurn() { FullStats stats = getCityStats(); - if (cityBuildings.CurrentBuilding.equals(CityBuildings.Settler) && stats.food > 0) { + if (cityBuildings.currentBuilding.equals(CityBuildings.Settler) && stats.food > 0) { stats.production += stats.food; stats.food = 0; } - if (cityPopulation.NextTurn(stats.food)) autoAssignWorker(); + if (cityPopulation.NextTurn(Math.round(stats.food))) autoAssignWorker(); - cityBuildings.NextTurn(stats.production); + cityBuildings.nextTurn(Math.round(stats.production)); cultureStored+=stats.culture; if(cultureStored>=getCultureToNextTile()){ @@ -186,4 +191,25 @@ public class CityInfo { if(tile.improvement ==null) rank+=0.5; // improvement potential! return rank; } + + private boolean isCapital(){ return CivilizationInfo.current().getCapital() == this; } + + private boolean isConnectedToCapital(){ + TileInfo capitalTile = CivilizationInfo.current().getCapital().getTile(); + LinqCollection tilesReached = new LinqCollection(); + LinqCollection tilesToCheck = new LinqCollection(); + tilesToCheck.add(getTile()); + while(!tilesToCheck.isEmpty()){ + LinqCollection newTiles = new LinqCollection(); + for(TileInfo tile : tilesToCheck) + for (TileInfo maybeNewTile : getTileMap().getTilesInDistance(tile.position,1)) + if(!tilesReached.contains(maybeNewTile) && !tilesToCheck.contains(maybeNewTile) && !newTiles.contains(maybeNewTile)) + newTiles.add(maybeNewTile); + + if(newTiles.contains(capitalTile)) return true; + tilesReached.addAll(tilesToCheck); + tilesToCheck = newTiles; + } + return false; + } } \ No newline at end of file diff --git a/core/src/com/unciv/civinfo/CivilizationInfo.java b/core/src/com/unciv/civinfo/CivilizationInfo.java index 9a5c2b40..9a2b7be1 100644 --- a/core/src/com/unciv/civinfo/CivilizationInfo.java +++ b/core/src/com/unciv/civinfo/CivilizationInfo.java @@ -1,6 +1,7 @@ package com.unciv.civinfo; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.utils.Predicate; import com.unciv.game.UnCivGame; import com.unciv.models.LinqCollection; import com.unciv.models.gamebasics.GameBasics; @@ -40,14 +41,23 @@ public class CivilizationInfo { public void addCity(Vector2 location){ CityInfo city = new CityInfo(this,location); - if(cities.size()==1) city.cityBuildings.BuiltBuildings.add("Palace"); + if(cities.size()==1) city.cityBuildings.builtBuildings.add("Palace"); + } + + public CityInfo getCapital(){ + return cities.first(new Predicate() { + @Override + public boolean evaluate(CityInfo arg0) { + return arg0.cityBuildings.isBuilt("Palace"); + } + }); } public void nextTurn()//out boolean displayTech) { CivStats nextTurnStats = getStatsForNextTurn(); civStats.add(nextTurnStats); - if(cities.size() > 0) tech.NextTurn(nextTurnStats.science); + if(cities.size() > 0) tech.NextTurn((int)nextTurnStats.science); for (CityInfo city : cities) city.nextTurn(); diff --git a/core/src/com/unciv/civinfo/RoadStatus.java b/core/src/com/unciv/civinfo/RoadStatus.java new file mode 100644 index 00000000..76402d35 --- /dev/null +++ b/core/src/com/unciv/civinfo/RoadStatus.java @@ -0,0 +1,7 @@ +package com.unciv.civinfo; + +public enum RoadStatus{ + None, + Road, + Railroad +} diff --git a/core/src/com/unciv/civinfo/TileInfo.java b/core/src/com/unciv/civinfo/TileInfo.java index 54d6814c..b0d7df67 100644 --- a/core/src/com/unciv/civinfo/TileInfo.java +++ b/core/src/com/unciv/civinfo/TileInfo.java @@ -9,12 +9,6 @@ import com.unciv.models.gamebasics.TileImprovement; import com.unciv.models.gamebasics.TileResource; import com.unciv.models.stats.FullStats; -enum RoadStatus{ - None, - Road, - Railroad -} - public class TileInfo { public Unit unit; @@ -70,7 +64,7 @@ public class TileInfo if (hasViewableResource()) { stats.add(resource); - if(resource.building !=null && City!=null && City.cityBuildings.IsBuilt(resource.building)) + if(resource.building !=null && City!=null && City.cityBuildings.isBuilt(resource.building)) { stats.add(resource.GetBuilding().resourceBonusStats); } @@ -100,6 +94,12 @@ public class TileInfo if (improvement.techRequired != null && !isResearched(improvement.techRequired)) return false; if (improvement.terrainsCanBeBuiltOn.contains(topTerrain.name)) return true; if (topTerrain.unbuildable) return false; + + if(improvement.name.equals(this.improvement)) return false; + + if(improvement.name.equals("Road") && this.roadStatus== RoadStatus.None) return true; + if(improvement.name.equals("Railroad") && this.roadStatus != RoadStatus.Railroad) return true; + return resource != null && getTileResource().improvement.equals(improvement.name); } @@ -123,8 +123,8 @@ public class TileInfo if(turnsToImprovement == 0) { if (improvementInProgress.startsWith("Remove")) terrainFeature = null; - else if(improvement.equals("Road")) roadStatus = RoadStatus.Road; - else if(improvement.equals("Railroad")) roadStatus = RoadStatus.Railroad; + else if(improvementInProgress.equals("Road")) roadStatus = RoadStatus.Road; + else if(improvementInProgress.equals("Railroad")) roadStatus = RoadStatus.Railroad; else improvement = improvementInProgress; improvementInProgress = null; @@ -135,6 +135,7 @@ public class TileInfo StringBuilder SB = new StringBuilder(this.baseTerrain); if (terrainFeature != null) SB.append(",\r\n" + terrainFeature); if (hasViewableResource()) SB.append(",\r\n" + resource); + if(roadStatus!= RoadStatus.None) SB.append(",\r\n" + roadStatus); if (improvement != null) SB.append(",\r\n" + improvement); if (improvementInProgress != null) SB.append(",\r\n" + improvementInProgress +" in "+this.turnsToImprovement +" turns"); if(unit !=null) SB.append(",\r\n" + unit.Name+ "("+ unit.CurrentMovement+"/"+ unit.MaxMovement+")"); diff --git a/core/src/com/unciv/civinfo/TileMap.java b/core/src/com/unciv/civinfo/TileMap.java index 1e0c4958..4f48ea29 100644 --- a/core/src/com/unciv/civinfo/TileMap.java +++ b/core/src/com/unciv/civinfo/TileMap.java @@ -11,6 +11,8 @@ import com.unciv.models.gamebasics.Terrain; import com.unciv.models.gamebasics.TerrainType; import com.unciv.models.gamebasics.TileResource; +import java.util.function.Function; + public class TileMap{ private LinqHashMap tiles = new LinqHashMap(); @@ -86,7 +88,7 @@ public class TileMap{ public LinqCollection values(){return tiles.linqValues();} - public TileResource GetRandomResource(LinqCollection resources, final ResourceType resourceType) { + TileResource GetRandomResource(LinqCollection resources, final ResourceType resourceType) { return resources.where(new Predicate() { @Override public boolean evaluate(TileResource arg0) { @@ -95,4 +97,5 @@ public class TileMap{ }).getRandom(); } + } diff --git a/core/src/com/unciv/game/CityScreen.java b/core/src/com/unciv/game/CityScreen.java index 78babc3d..9f793de5 100644 --- a/core/src/com/unciv/game/CityScreen.java +++ b/core/src/com/unciv/game/CityScreen.java @@ -198,11 +198,13 @@ public class CityScreen extends CameraStageBaseScreen { CityStatsTable.row(); HashMap CityStatsValues = new LinkedHashMap(); - CityStatsValues.put("production",stats.production +""); - CityStatsValues.put("food",stats.food +" ("+cityInfo.cityPopulation.FoodStored+"/"+cityInfo.cityPopulation.FoodToNextPopulation()+")"); - CityStatsValues.put("gold",stats.gold +""); - CityStatsValues.put("science",stats.science +""); - CityStatsValues.put("culture",stats.culture +" ("+cityInfo.cultureStored+"/"+cityInfo.getCultureToNextTile()+")"); + CityStatsValues.put("production",Math.round(stats.production) +""); + CityStatsValues.put("food",Math.round(stats.food) + +" ("+cityInfo.cityPopulation.FoodStored+"/"+cityInfo.cityPopulation.FoodToNextPopulation()+")"); + CityStatsValues.put("gold",Math.round(stats.gold) +""); + CityStatsValues.put("science",Math.round(stats.science) +""); + CityStatsValues.put("culture",Math.round(stats.culture) + +" ("+cityInfo.cultureStored+"/"+cityInfo.getCultureToNextTile()+")"); CityStatsValues.put("Population",cityInfo.getFreePopulation()+"/"+cityInfo.cityPopulation.Population); for(String key : CityStatsValues.keySet()){ @@ -211,11 +213,11 @@ public class CityScreen extends CameraStageBaseScreen { CityStatsTable.row(); } - String CurrentBuilding = game.civInfo.getCurrentCity().cityBuildings.CurrentBuilding; + String CurrentBuilding = game.civInfo.getCurrentCity().cityBuildings.currentBuilding; String BuildingText = "Pick building"; if(CurrentBuilding != null) BuildingText = CurrentBuilding+"\r\n" - +cityInfo.cityBuildings.TurnsToBuilding(CurrentBuilding)+" turns"; + +cityInfo.cityBuildings.turnsToBuilding(CurrentBuilding)+" turns"; TextButton buildingPickButton = new TextButton(BuildingText,skin); buildingPickButton.addListener(new ClickListener(){ @Override @@ -249,17 +251,17 @@ public class CityScreen extends CameraStageBaseScreen { TileTable.add(new Label(selectedTile.toString(),skin)).colspan(2); TileTable.row(); - HashMap TileStatsValues = new HashMap(); - TileStatsValues.put("production",stats.production +""); - TileStatsValues.put("food",stats.food +""); - TileStatsValues.put("gold",stats.gold +""); - TileStatsValues.put("science",stats.science +""); - TileStatsValues.put("culture",stats.culture +""); + HashMap TileStatsValues = new HashMap(); + TileStatsValues.put("production",stats.production); + TileStatsValues.put("food",stats.food); + TileStatsValues.put("gold",stats.gold); + TileStatsValues.put("science",stats.science); + TileStatsValues.put("culture",stats.culture); for(String key : TileStatsValues.keySet()){ - if(TileStatsValues.get(key).equals("0")) continue; // this tile gives nothing of this stat, so why even display it? + if(TileStatsValues.get(key) == 0) continue; // this tile gives nothing of this stat, so why even display it? TileTable.add(ImageGetter.getStatIcon(key)).align(Align.right); - TileTable.add(new Label(TileStatsValues.get(key),skin)).align(Align.left); + TileTable.add(new Label(Math.round(TileStatsValues.get(key))+"",skin)).align(Align.left); TileTable.row(); } diff --git a/core/src/com/unciv/game/HexMath.java b/core/src/com/unciv/game/HexMath.java index 9f120bd2..d07e3a30 100644 --- a/core/src/com/unciv/game/HexMath.java +++ b/core/src/com/unciv/game/HexMath.java @@ -8,6 +8,7 @@ import java.util.HashSet; public class HexMath { + public static Vector2 GetVectorForAngle(float angle) { return new Vector2((float)Math.sin(angle), (float) Math.cos(angle)); diff --git a/core/src/com/unciv/game/TileGroup.java b/core/src/com/unciv/game/TileGroup.java index a03beb3a..13cfb7a5 100644 --- a/core/src/com/unciv/game/TileGroup.java +++ b/core/src/com/unciv/game/TileGroup.java @@ -1,11 +1,16 @@ package com.unciv.game; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.ui.Container; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.unciv.civinfo.CivilizationInfo; +import com.unciv.civinfo.RoadStatus; import com.unciv.civinfo.TileInfo; +import com.unciv.models.LinqCollection; +import com.unciv.models.LinqHashMap; public class TileGroup extends Group { Image terrainImage; @@ -13,6 +18,7 @@ public class TileGroup extends Group { Image unitImage; Image improvementImage; Image populationImage; + LinqHashMap roadImages = new LinqHashMap(); Image hexagon; Container cityButton; @@ -80,5 +86,28 @@ public class TileGroup extends Group { if(tileInfo.workingCity !=null) populationImage.setColor(Color.WHITE); else populationImage.setColor(Color.GRAY); } + + if(tileInfo.roadStatus != RoadStatus.None){ + for (TileInfo neighbor : CivilizationInfo.current().tileMap.getTilesInDistance(tileInfo.position,1)) { + if (neighbor == tileInfo || neighbor.roadStatus == RoadStatus.None) continue; + if (roadImages.containsKey(neighbor.position.toString())) continue; + + Image image = ImageGetter.getImageByFilename("TerrainIcons/road.png"); + roadImages.put(neighbor.position.toString(), image); + + Vector2 relativeHexPosition = tileInfo.position.cpy().sub(neighbor.position); + Vector2 relativeWorldPosition = HexMath.Hex2WorldCoords(relativeHexPosition); + + // This is some crazy voodoo magic so I'll explain. + image.moveBy(25, 25); // Move road to center of tile + // in addTiles, we set the position of groups by relative world position *0.8*groupSize, where groupSize = 50 + // Here, we want to have the roads start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25. + image.moveBy(-relativeWorldPosition.x * 0.8f * 25, -relativeWorldPosition.y * 0.8f * 25); + image.setSize(10, 2); + addActor(image); + image.setOrigin(0, 1); // This is so that the rotation is calculated from the middle of the road and not the edge + image.setRotation((float) (180 / Math.PI * Math.atan2(relativeWorldPosition.y, relativeWorldPosition.x))); + } + } } } diff --git a/core/src/com/unciv/game/WorldScreen.java b/core/src/com/unciv/game/WorldScreen.java index ed44a637..7f8a7113 100644 --- a/core/src/com/unciv/game/WorldScreen.java +++ b/core/src/com/unciv/game/WorldScreen.java @@ -162,11 +162,12 @@ public class WorldScreen extends CameraStageBaseScreen { CivStats nextTurnStats = game.civInfo.getStatsForNextTurn(); - CivTable.add(new Label("gold: " + currentStats.gold + "(" +(nextTurnStats.gold >0?"+":"") + nextTurnStats.gold +")", skin)); + CivTable.add(new Label("gold: " + Math.round(currentStats.gold) + + "(" +(nextTurnStats.gold >0?"+":"") + Math.round(nextTurnStats.gold) +")", skin)); - CivTable.add(new Label("science: +" + nextTurnStats.science, skin)); - CivTable.add(new Label("happiness: " + nextTurnStats.happiness, skin)); - CivTable.add(new Label("culture: " + currentStats.culture + "(+" + nextTurnStats.culture +")", skin)); + CivTable.add(new Label("science: +" + Math.round(nextTurnStats.science), skin)); + CivTable.add(new Label("happiness: " + Math.round(nextTurnStats.happiness), skin)); + CivTable.add(new Label("culture: " + Math.round(currentStats.culture) + "(+" + Math.round(nextTurnStats.culture) +")", skin)); CivTable.pack(); @@ -290,20 +291,22 @@ public class WorldScreen extends CameraStageBaseScreen { TileTable.add(new Label(selectedTile.toString(),skin)).colspan(2); TileTable.row(); - HashMap TileStatsValues = new HashMap(); - TileStatsValues.put("production",stats.production +""); - TileStatsValues.put("food",stats.food +""); - TileStatsValues.put("gold",stats.gold +""); - TileStatsValues.put("science",stats.science +""); - TileStatsValues.put("culture",stats.culture +""); + + HashMap TileStatsValues = new HashMap(); + TileStatsValues.put("production",stats.production); + TileStatsValues.put("food",stats.food); + TileStatsValues.put("gold",stats.gold); + TileStatsValues.put("science",stats.science); + TileStatsValues.put("culture",stats.culture); for(String key : TileStatsValues.keySet()){ - if(TileStatsValues.get(key).equals("0")) continue; // this tile gives nothing of this stat, so why even display it? + if(TileStatsValues.get(key) == 0) continue; // this tile gives nothing of this stat, so why even display it? TileTable.add(ImageGetter.getStatIcon(key)).align(Align.right); - TileTable.add(new Label(TileStatsValues.get(key),skin)).align(Align.left); + TileTable.add(new Label(Math.round(TileStatsValues.get(key))+"",skin)).align(Align.left); TileTable.row(); } + if(selectedTile.unit !=null){ TextButton moveUnitButton = new TextButton("Move to", skin); if(unitTile == selectedTile) moveUnitButton = new TextButton("Stop movement",skin); @@ -342,6 +345,7 @@ public class WorldScreen extends CameraStageBaseScreen { @Override public void clicked(InputEvent event, float x, float y) { game.civInfo.addCity(selectedTile.position); + if(unitTile==selectedTile) unitTile = null; // The settler was in the middle of moving and we then founded a city with it selectedTile.unit = null; // Remove settler! update(); } @@ -374,7 +378,7 @@ public class WorldScreen extends CameraStageBaseScreen { dispose(); } }); - if(selectedTile.unit.CurrentMovement==0 || + if(selectedTile.unit.CurrentMovement==0 || selectedTile.isCityCenter() || !GameBasics.TileImprovements.linqValues().any(new Predicate() { @Override public boolean evaluate(TileImprovement arg0) { diff --git a/core/src/com/unciv/game/WorldTileGroup.java b/core/src/com/unciv/game/WorldTileGroup.java index bf22af25..dfc2328c 100644 --- a/core/src/com/unciv/game/WorldTileGroup.java +++ b/core/src/com/unciv/game/WorldTileGroup.java @@ -57,18 +57,19 @@ public class WorldTileGroup extends TileGroup { }); addActor(cityButton); - setZIndex(getParent().getChildren().size); + setZIndex(getParent().getChildren().size); // so this tile is rendered over neighboing tiles } String cityButtonText = city.name +" ("+city.cityPopulation.Population+")" - + "\r\n" + city.cityBuildings.CurrentBuilding + " in " - + city.cityBuildings.TurnsToBuilding(city.cityBuildings.CurrentBuilding); + + "\r\n" + city.cityBuildings.currentBuilding + " in " + + city.cityBuildings.turnsToBuilding(city.cityBuildings.currentBuilding); TextButton button = cityButton.getActor(); button.setText(cityButtonText); button.setSize(button.getPrefWidth(), button.getPrefHeight()); cityButton.setPosition((getWidth() - cityButton.getWidth()) / 2, getHeight() * 0.9f); + cityButton.setZIndex(cityButton.getParent().getChildren().size); // so city button is rendere over oeverything else in this tile } } diff --git a/core/src/com/unciv/game/pickerscreens/BuildingPickerScreen.java b/core/src/com/unciv/game/pickerscreens/BuildingPickerScreen.java index b938de3c..62afe516 100644 --- a/core/src/com/unciv/game/pickerscreens/BuildingPickerScreen.java +++ b/core/src/com/unciv/game/pickerscreens/BuildingPickerScreen.java @@ -30,7 +30,7 @@ public class BuildingPickerScreen extends PickerScreen { rightSideButton.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { - game.civInfo.getCurrentCity().cityBuildings.CurrentBuilding = selectedBuilding.name; + game.civInfo.getCurrentCity().cityBuildings.currentBuilding = selectedBuilding.name; game.setScreen(new CityScreen(game)); dispose(); } @@ -40,8 +40,8 @@ public class BuildingPickerScreen extends PickerScreen { CityBuildings cityBuildings = game.civInfo.getCurrentCity().cityBuildings; for(final Building building : GameBasics.Buildings.values()) { - if(!cityBuildings.CanBuild(building)) continue; - TextButton TB = new TextButton(building.name +"\r\n"+cityBuildings.TurnsToBuilding(building.name)+" turns", skin); + if(!cityBuildings.canBuild(building)) continue; + TextButton TB = new TextButton(building.name +"\r\n"+cityBuildings.turnsToBuilding(building.name)+" turns", skin); TB.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { diff --git a/core/src/com/unciv/models/stats/CivStats.java b/core/src/com/unciv/models/stats/CivStats.java index eead7d52..331625cb 100644 --- a/core/src/com/unciv/models/stats/CivStats.java +++ b/core/src/com/unciv/models/stats/CivStats.java @@ -1,10 +1,10 @@ package com.unciv.models.stats; public class CivStats { - public int gold = 0; - public int science = 0; - public int culture = 0; - public int happiness = 0; + public float gold = 0; + public float science = 0; + public float culture = 0; + public float happiness = 0; public void add(CivStats other) { gold += other.gold; diff --git a/core/src/com/unciv/models/stats/FullStats.java b/core/src/com/unciv/models/stats/FullStats.java index f1a26fbe..a861b529 100644 --- a/core/src/com/unciv/models/stats/FullStats.java +++ b/core/src/com/unciv/models/stats/FullStats.java @@ -1,9 +1,11 @@ package com.unciv.models.stats; +import java.text.DecimalFormat; + public class FullStats extends CivStats // also used for hex stats, since it's basically the same { - public int production = 0; - public int food = 0; + public float production = 0; + public float food = 0; public FullStats() { } @@ -21,8 +23,8 @@ public class FullStats extends CivStats // also used for hex stats, since it's b production +=other.production; } - public String display(int value, String name){ - return ", " + (value>0 ? "+" : "") + value + " "+name; + public String display(float value, String name){ + return ", " + (value>0 ? "+" : "") + Math.round(value) + " "+name; } public String toString() {