Skip to content

Commit

Permalink
Google play-able
Browse files Browse the repository at this point in the history
Units with no turns left are now grayed out
Added culture pool to cities and tiles being added to cities when pool fills
Changed tile icon order and placing of resource icon
  • Loading branch information
yairm210 committed Nov 25, 2017
1 parent a6ae959 commit d125c6b
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 55 deletions.
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:icon="@drawable/uncivicon"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<activity
Expand Down
Binary file added android/android-release.apk
Binary file not shown.
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ android {
exclude 'META-INF/robovm/ios/robovm.xml'
}
defaultConfig {
applicationId "com.mygdx.game"
applicationId "com.unciv.game"
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionCode 3
versionName "1.0"
}
buildTypes {
Expand Down Expand Up @@ -79,7 +79,7 @@ task run(type: Exec) {
}

def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.mygdx.game/AndroidLauncher'
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.unciv.game/AndroidLauncher'
}

// sets up the Android Eclipse project, using the old Ant based build.
Expand Down
Binary file added android/res/drawable-hdpi/uncivicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/res/drawable-mdpi/uncivicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/res/drawable-xhdpi/uncivicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/res/drawable-xxhdpi/uncivicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/res/drawable-xxxhdpi/uncivicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ allprojects {
apply plugin: "eclipse"
apply plugin: "idea"

version = '1.0'
version = '1.0.1'
ext {
appName = "my-gdx-game"
appName = "unciv-game"
gdxVersion = '1.9.6'
roboVMVersion = '2.3.1'
box2DLightsVersion = '1.4'
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/unciv/civinfo/CityBuildings.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean CanBuild(final Building building)
if(IsBuilt(building.Name)) return false;
// if (building.Name.equals("Worker") || building.Name.equals("Settler")) return false;
if(building.ResourceRequired) {
boolean containsResourceWithImprovement = GetCity().GetCityTiles()
boolean containsResourceWithImprovement = GetCity().getCityTiles()
.any(new Predicate<TileInfo>() {
@Override
public boolean evaluate(TileInfo tile) {
Expand Down
104 changes: 83 additions & 21 deletions core/src/com/unciv/civinfo/CityInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
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;
public String Name;

public CityBuildings cityBuildings;
public CityPopulation cityPopulation;
public int cultureStored;
private int tilesClaimed;


public LinqCollection<Vector2> CityTileLocations = new LinqCollection<Vector2>();

public LinqCollection<TileInfo> GetCityTiles(){
public LinqCollection<TileInfo> getCityTiles(){
return CityTileLocations.select(new com.unciv.models.LinqCollection.Func<Vector2, TileInfo>() {
@Override
public TileInfo GetBy(Vector2 arg0) {
Expand All @@ -27,13 +33,23 @@ public TileInfo GetBy(Vector2 arg0) {
});
}

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);
Expand All @@ -45,36 +61,36 @@ public CityInfo(CivilizationInfo civInfo, Vector2 cityLocation) {
CityTileLocations.add(vector);
}

AutoAssignWorker();
autoAssignWorker();
civInfo.Cities.add(this);
}

public ArrayList<String> GetLuxuryResources() {
ArrayList<String> getLuxuryResources() {
ArrayList<String> LuxuryResources = new ArrayList<String>();
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<TileInfo>() {
private int getWorkingPopulation() {
return getCityTiles().count(new Predicate<TileInfo>() {
@Override
public boolean evaluate(TileInfo arg0) {
return arg0.IsWorked;
}
});
}

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() {
Expand All @@ -85,39 +101,72 @@ public FullStats getCityStats() {
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());

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();
}
}

private void addNewTile(){
cultureStored -= getCultureToNextTile();
tilesClaimed++;
LinqCollection<Vector2> possibleNewTileVectors = new LinqCollection<Vector2>();
for (TileInfo tile : getCityTiles())
for (Vector2 vector : HexMath.GetAdjacentVectors(tile.Position))
if(!CityTileLocations.contains(vector) && !possibleNewTileVectors.contains(vector))
possibleNewTileVectors.add(vector);

LinqCollection<TileInfo> possibleNewTiles = new LinqCollection<TileInfo>();
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);
}

public void AutoAssignWorker() {
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();

Expand All @@ -129,4 +178,17 @@ public void AutoAssignWorker() {
}
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;
}
}
5 changes: 2 additions & 3 deletions core/src/com/unciv/civinfo/CivilizationInfo.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -47,7 +46,7 @@ public void NextTurn()//out boolean displayTech)
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;

Expand All @@ -61,7 +60,7 @@ public CivStats GetStatsForNextTurn() {
HashSet<String> LuxuryResources = new HashSet<String>();
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

Expand Down
9 changes: 5 additions & 4 deletions core/src/com/unciv/civinfo/TileMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;

Expand Down Expand Up @@ -58,11 +59,11 @@ public boolean evaluate(TileResource arg0) {

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;

Expand All @@ -77,7 +78,7 @@ public boolean evaluate(TileResource arg0) {

public LinqCollection<TileInfo> values(){return tiles.linqValues();}

public TileResource GetRandomResource(LinqCollection<TileResource> resources, final String resourceType) {
public TileResource GetRandomResource(LinqCollection<TileResource> resources, final ResourceType resourceType) {
return resources.where(new Predicate<TileResource>() {
@Override
public boolean evaluate(TileResource arg0) {
Expand Down
9 changes: 4 additions & 5 deletions core/src/com/unciv/game/CityScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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;
Expand Down Expand Up @@ -135,13 +134,13 @@ public void clicked(InputEvent event, float x, float y) {
}
});

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();
}
Expand Down Expand Up @@ -204,8 +203,8 @@ private void updateCityTable() {
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);
Expand Down
18 changes: 12 additions & 6 deletions core/src/com/unciv/game/TileGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -46,29 +46,35 @@ void update() {
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);
}

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) {
unitImage.remove();
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){
Expand Down
Loading

0 comments on commit d125c6b

Please sign in to comment.