diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 254acbcd..ce551e2d 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -6,7 +6,7 @@ () { @Override public boolean evaluate(TileInfo tile) { diff --git a/core/src/com/unciv/civinfo/CityInfo.java b/core/src/com/unciv/civinfo/CityInfo.java index cdaa3d14..c0ec08a3 100644 --- a/core/src/com/unciv/civinfo/CityInfo.java +++ b/core/src/com/unciv/civinfo/CityInfo.java @@ -5,9 +5,12 @@ import com.badlogic.gdx.utils.Predicate; import com.unciv.game.HexMath; import com.unciv.game.UnCivGame; import com.unciv.models.LinqCollection; +import com.unciv.models.gamebasics.ResourceType; +import com.unciv.models.gamebasics.TileResource; import com.unciv.models.stats.FullStats; import java.util.ArrayList; +import java.util.Comparator; public class CityInfo { public final Vector2 cityLocation; @@ -15,10 +18,13 @@ public class CityInfo { public CityBuildings cityBuildings; public CityPopulation cityPopulation; + public int cultureStored; + private int tilesClaimed; + public LinqCollection CityTileLocations = new LinqCollection(); - public LinqCollection GetCityTiles(){ + public LinqCollection getCityTiles(){ return CityTileLocations.select(new com.unciv.models.LinqCollection.Func() { @Override public TileInfo GetBy(Vector2 arg0) { @@ -27,13 +33,23 @@ public class CityInfo { }); } - String[] CityNames = new String[]{"Assur", "Ninveh", "Nimrud", "Kar-Tukuli-Ninurta", "Dur-Sharrukin"}; + private String[] CityNames = new String[]{"Assur", "Ninveh", "Nimrud", "Kar-Tukuli-Ninurta", "Dur-Sharrukin"}; public CityInfo(){ cityLocation = Vector2.Zero; } // for json parsing, we need to have a default constructor - public CityInfo(CivilizationInfo civInfo, Vector2 cityLocation) { + public int getCultureToNextTile(){ + // This one has conflicting sources - + // http://civilization.wikia.com/wiki/Mathematics_of_Civilization_V says it's 20+(10(t-1))^1.1 + // https://www.reddit.com/r/civ/comments/58rxkk/how_in_gods_name_do_borders_expand_in_civ_vi/ has it + // (per game XML files) at 6*(t+0.4813)^1.3 + // The second seems to be more based, so I'll go with that + double a = 6*Math.pow(tilesClaimed+1.4813,1.3); + return (int)Math.round(a); + } + + CityInfo(CivilizationInfo civInfo, Vector2 cityLocation) { Name = CityNames[civInfo.Cities.size()]; this.cityLocation = cityLocation; cityBuildings = new CityBuildings(this); @@ -45,23 +61,23 @@ public class CityInfo { CityTileLocations.add(vector); } - AutoAssignWorker(); + autoAssignWorker(); civInfo.Cities.add(this); } - public ArrayList GetLuxuryResources() { + ArrayList getLuxuryResources() { ArrayList LuxuryResources = new ArrayList(); - for (TileInfo tileInfo : GetCityTiles()) { + for (TileInfo tileInfo : getCityTiles()) { com.unciv.models.gamebasics.TileResource resource = tileInfo.GetTileResource(); - if (resource != null && resource.ResourceType.equals("Luxury") && resource.Improvement.equals(tileInfo.Improvement)) + if (resource != null && resource.ResourceType == ResourceType.Luxury && resource.Improvement.equals(tileInfo.Improvement)) LuxuryResources.add(tileInfo.Resource); } return LuxuryResources; } - public int GetWorkingPopulation() { - return GetCityTiles().count(new Predicate() { + private int getWorkingPopulation() { + return getCityTiles().count(new Predicate() { @Override public boolean evaluate(TileInfo arg0) { return arg0.IsWorked; @@ -69,12 +85,12 @@ public class CityInfo { }); } - public int GetFreePopulation() { - return cityPopulation.Population - GetWorkingPopulation(); + public int getFreePopulation() { + return cityPopulation.Population - getWorkingPopulation(); } - public boolean HasNonWorkingPopulation() { - return GetFreePopulation() > 0; + public boolean hasNonWorkingPopulation() { + return getFreePopulation() > 0; } public FullStats getCityStats() { @@ -85,11 +101,11 @@ public class CityInfo { stats.Science += cityPopulation.Population; // Working ppl - for (TileInfo cell : GetCityTiles()) { + for (TileInfo cell : getCityTiles()) { if (cell.IsWorked || cell.IsCityCenter()) stats.add(cell.GetTileStats()); } //idle ppl - stats.Production += GetFreePopulation(); + stats.Production += getFreePopulation(); stats.Food -= cityPopulation.Population * 2; stats.add(cityBuildings.GetStats()); @@ -97,27 +113,60 @@ public class CityInfo { return stats; } - public void NextTurn() { + 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(stats.Food)) autoAssignWorker(); cityBuildings.NextTurn(stats.Production); - for (TileInfo tileInfo : GetCityTiles()) { + for (TileInfo tileInfo : getCityTiles()) { tileInfo.NextTurn(); } + + cultureStored+=stats.Culture; + if(cultureStored>=getCultureToNextTile()){ + addNewTile(); + } } - public void AutoAssignWorker() { + private void addNewTile(){ + cultureStored -= getCultureToNextTile(); + tilesClaimed++; + LinqCollection possibleNewTileVectors = new LinqCollection(); + for (TileInfo tile : getCityTiles()) + for (Vector2 vector : HexMath.GetAdjacentVectors(tile.Position)) + if(!CityTileLocations.contains(vector) && !possibleNewTileVectors.contains(vector)) + possibleNewTileVectors.add(vector); + + LinqCollection possibleNewTiles = new LinqCollection(); + TileMap tileMap = UnCivGame.Current.civInfo.tileMap; + for (Vector2 vector : possibleNewTileVectors) + if(tileMap.contains(vector) && tileMap.get(vector).GetCity()==null) + possibleNewTiles.add(tileMap.get(vector)); + + TileInfo TileChosen=null; + double TileChosenRank=0; + for(TileInfo tile : possibleNewTiles){ + double rank = rankTile(tile); + if(rank>TileChosenRank){ + TileChosenRank = rank; + TileChosen = tile; + } + } + + CityTileLocations.add(TileChosen.Position); + } + + private void autoAssignWorker() { double maxValue = 0; TileInfo toWork = null; - for (TileInfo tileInfo : GetCityTiles()) { + for (TileInfo tileInfo : getCityTiles()) { if (tileInfo.IsWorked || tileInfo.IsCityCenter()) continue; FullStats stats = tileInfo.GetTileStats(); @@ -129,4 +178,17 @@ public class CityInfo { } toWork.IsWorked = true; } + + private double rankTile(TileInfo tile){ + FullStats stats = tile.GetTileStats(); + double rank=0; + if(stats.Food<2) rank+=stats.Food; + else rank += 2 + (stats.Food-2)/2; // 1 point for each food up to 2, from there on half a point + rank+=stats.Gold/2; + rank+=stats.Production; + rank+=stats.Science; + rank+=stats.Culture; + if(tile.Improvement==null) rank+=0.5; // Improvement potential! + return rank; + } } \ 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 9104d8c9..5e57df3a 100644 --- a/core/src/com/unciv/civinfo/CivilizationInfo.java +++ b/core/src/com/unciv/civinfo/CivilizationInfo.java @@ -1,7 +1,6 @@ package com.unciv.civinfo; import com.badlogic.gdx.math.Vector2; -import com.unciv.game.pickerscreens.GameSaver; import com.unciv.models.LinqCollection; import com.unciv.models.gamebasics.GameBasics; import com.unciv.models.stats.CivStats; @@ -47,7 +46,7 @@ public class CivilizationInfo { civStats.add(nextTurnStats); if(Cities.size() > 0) Tech.NextTurn(nextTurnStats.Science); - for (CityInfo city : Cities.as(CityInfo.class)) city.NextTurn(); + for (CityInfo city : Cities.as(CityInfo.class)) city.nextTurn(); for(TileInfo tile : tileMap.values()) if(tile.Unit!=null) tile.Unit.CurrentMovement = tile.Unit.MaxMovement; @@ -61,7 +60,7 @@ public class CivilizationInfo { HashSet LuxuryResources = new HashSet(); for (CityInfo city : Cities) { statsForTurn.add(city.getCityStats()); - LuxuryResources.addAll(city.GetLuxuryResources()); + LuxuryResources.addAll(city.getLuxuryResources()); } statsForTurn.Happiness += LuxuryResources.size() * 5; // 5 happiness for each unique luxury in civ diff --git a/core/src/com/unciv/civinfo/TileMap.java b/core/src/com/unciv/civinfo/TileMap.java index 73d37a95..662dce04 100644 --- a/core/src/com/unciv/civinfo/TileMap.java +++ b/core/src/com/unciv/civinfo/TileMap.java @@ -7,6 +7,7 @@ import com.unciv.game.HexMath; import com.unciv.models.LinqCollection; import com.unciv.models.LinqHashMap; import com.unciv.models.gamebasics.GameBasics; +import com.unciv.models.gamebasics.ResourceType; import com.unciv.models.gamebasics.Terrain; import com.unciv.models.gamebasics.TileResource; @@ -58,11 +59,11 @@ public class TileMap{ TileResource resource = null; if (Math.random() < 1 / 5f) { - resource = GetRandomResource(TileResources, "Bonus"); + resource = GetRandomResource(TileResources, ResourceType.Bonus); } else if (Math.random() < 1 / 7f) { - resource = GetRandomResource(TileResources, "Strategic"); + resource = GetRandomResource(TileResources, ResourceType.Strategic); } else if (Math.random() < 1 / 10f) { - resource = GetRandomResource(TileResources, "Luxury"); + resource = GetRandomResource(TileResources, ResourceType.Luxury); } if (resource != null) tileInfo.Resource = resource.Name; @@ -77,7 +78,7 @@ public class TileMap{ public LinqCollection values(){return tiles.linqValues();} - public TileResource GetRandomResource(LinqCollection resources, final String resourceType) { + public TileResource GetRandomResource(LinqCollection resources, final ResourceType resourceType) { return resources.where(new Predicate() { @Override public boolean evaluate(TileResource arg0) { diff --git a/core/src/com/unciv/game/CityScreen.java b/core/src/com/unciv/game/CityScreen.java index 608c39e0..abcc4d3d 100644 --- a/core/src/com/unciv/game/CityScreen.java +++ b/core/src/com/unciv/game/CityScreen.java @@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.InputEvent; -import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.Table; @@ -135,13 +134,13 @@ public class CityScreen extends CameraStageBaseScreen { } }); - if(!cityInfo.GetCityTiles().contains(tileInfo)) group.setColor(0,0,0,0.3f); + if(!cityInfo.getCityTiles().contains(tileInfo)) group.setColor(0,0,0,0.3f); else if(!tileInfo.IsCityCenter()) { group.addPopulationIcon(); group.populationImage.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { - if (cityInfo.GetFreePopulation() > 0 || tileInfo.IsWorked) + if (cityInfo.getFreePopulation() > 0 || tileInfo.IsWorked) tileInfo.IsWorked = !tileInfo.IsWorked; updateCityTable(); } @@ -204,8 +203,8 @@ public class CityScreen extends CameraStageBaseScreen { 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+""); - CityStatsValues.put("Population",cityInfo.GetFreePopulation()+"/"+cityInfo.cityPopulation.Population); + CityStatsValues.put("Culture",stats.Culture+" ("+cityInfo.cultureStored+"/"+cityInfo.getCultureToNextTile()+")"); + CityStatsValues.put("Population",cityInfo.getFreePopulation()+"/"+cityInfo.cityPopulation.Population); for(String key : CityStatsValues.keySet()){ CityStatsTable.add(ImageGetter.getStatIcon(key)).align(Align.right); diff --git a/core/src/com/unciv/game/TileGroup.java b/core/src/com/unciv/game/TileGroup.java index c479f8c4..2c61f631 100644 --- a/core/src/com/unciv/game/TileGroup.java +++ b/core/src/com/unciv/game/TileGroup.java @@ -28,10 +28,10 @@ public class TileGroup extends Group { addActor(terrainImage); } + void addPopulationIcon(){ populationImage = ImageGetter.getStatIcon("Population"); - populationImage.setAlign(Align.bottomRight); - populationImage.setX(terrainImage.getWidth()-populationImage.getWidth()); + populationImage.moveBy(0, terrainImage.getHeight()-populationImage.getHeight()); // top left addActor(populationImage); } @@ -46,8 +46,8 @@ public class TileGroup extends Group { if (tileInfo.HasViewableResource() && resourceImage == null) { // Need to add the resource image! String fileName = "ResourceIcons/" + tileInfo.Resource + "_(Civ5).png"; Image image = ImageGetter.getImageByFilename(fileName); - image.setScale(0.5f); - image.setOrigin(Align.topRight); + image.setSize(20,20); + image.moveBy(terrainImage.getWidth()-image.getWidth(), 0); // bottom right resourceImage = image; addActor(image); } @@ -55,7 +55,7 @@ public class TileGroup extends Group { if (tileInfo.Unit != null && unitImage == null) { unitImage = ImageGetter.getImageByFilename("StatIcons/" + tileInfo.Unit.Name + "_(Civ5).png"); addActor(unitImage); - unitImage.setSize(20, 20); + unitImage.setSize(20, 20); // not moved - is at bottom left } if (tileInfo.Unit == null && unitImage != null) { @@ -63,12 +63,18 @@ public class TileGroup extends Group { unitImage = null; } + if(unitImage!=null){ + if(tileInfo.Unit.CurrentMovement==0) unitImage.setColor(Color.GRAY); + else unitImage.setColor(Color.WHITE); + } + if (tileInfo.Improvement != null && improvementImage == null) { improvementImage = ImageGetter.getImageByFilename("ImprovementIcons/" + tileInfo.Improvement.replace(' ','_') + "_(Civ5).png"); addActor(improvementImage); improvementImage.setSize(20, 20); - improvementImage.moveBy(0, terrainImage.getHeight() - improvementImage.getHeight()); + improvementImage.moveBy(terrainImage.getWidth()-improvementImage.getWidth(), + terrainImage.getHeight() - improvementImage.getHeight()); // top right } if(populationImage!=null){ diff --git a/core/src/com/unciv/game/WorldScreen.java b/core/src/com/unciv/game/WorldScreen.java index 5eaaf784..8d18f5f0 100644 --- a/core/src/com/unciv/game/WorldScreen.java +++ b/core/src/com/unciv/game/WorldScreen.java @@ -55,7 +55,7 @@ public class WorldScreen extends CameraStageBaseScreen { stage.addActor(TileTable); Drawable tileTableBackground = new TextureRegionDrawable(new TextureRegion(new Texture("skin/tileTableBackground.png"))) - .tint(new Color(0x0040804f)); + .tint(new Color(0x004085bf)); tileTableBackground.setMinHeight(0); tileTableBackground.setMinWidth(0); TileTable.setBackground(tileTableBackground); @@ -63,7 +63,7 @@ public class WorldScreen extends CameraStageBaseScreen { TextureRegionDrawable civBackground = new TextureRegionDrawable(new TextureRegion(new Texture("skin/civTableBackground.png"))); // civBackground.tint(new Color(0x0040804f)); - CivTable.setBackground(civBackground.tint(new Color(0x0040804f))); + CivTable.setBackground(civBackground.tint(new Color(0x004085bf))); stage.addActor(CivTable); @@ -267,6 +267,7 @@ public class WorldScreen extends CameraStageBaseScreen { lastScale = scrollPane.getScaleX(); } float scale = (float) Math.sqrt(distance / initialDistance) * lastScale; + if(scale<1) return; scrollPane.setScale(scale); game.settings.tilesZoom = scale; } @@ -375,7 +376,8 @@ public class WorldScreen extends CameraStageBaseScreen { dispose(); } }); - if(!GameBasics.TileImprovements.linqValues().any(new Predicate() { + if(selectedTile.Unit.CurrentMovement==0 || + !GameBasics.TileImprovements.linqValues().any(new Predicate() { @Override public boolean evaluate(TileImprovement arg0) { return selectedTile.CanBuildImprovement(arg0); diff --git a/core/src/com/unciv/models/gamebasics/ResourceType.java b/core/src/com/unciv/models/gamebasics/ResourceType.java index 83bf7802..b128925a 100644 --- a/core/src/com/unciv/models/gamebasics/ResourceType.java +++ b/core/src/com/unciv/models/gamebasics/ResourceType.java @@ -1,8 +1,7 @@ package com.unciv.models.gamebasics; -/** - * Created by LENOVO on 11/25/2017. - */ - -class ResourceType { +public enum ResourceType{ + Luxury, + Strategic, + Bonus } diff --git a/core/src/com/unciv/models/gamebasics/TileResource.java b/core/src/com/unciv/models/gamebasics/TileResource.java index 999b8211..8af79ba7 100644 --- a/core/src/com/unciv/models/gamebasics/TileResource.java +++ b/core/src/com/unciv/models/gamebasics/TileResource.java @@ -6,7 +6,7 @@ import com.unciv.models.stats.FullStats; import java.util.Collection; public class TileResource extends NamedStats implements ICivilopedia { - public String ResourceType; + public ResourceType ResourceType; public Collection TerrainsCanBeFoundOn; public String Improvement; public FullStats ImprovementStats; diff --git a/keystore.jks b/keystore.jks new file mode 100644 index 00000000..cd06b651 Binary files /dev/null and b/keystore.jks differ