diff --git a/android/build.gradle b/android/build.gradle index 46688bd3..0a08b8cb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,7 +21,7 @@ android { applicationId "com.unciv.game" minSdkVersion 9 targetSdkVersion 25 - versionCode 13 + versionCode 14 versionName "0.9" } buildTypes { diff --git a/core/src/com/unciv/civinfo/CityInfo.java b/core/src/com/unciv/civinfo/CityInfo.java index a16a47a3..e1068c9c 100644 --- a/core/src/com/unciv/civinfo/CityInfo.java +++ b/core/src/com/unciv/civinfo/CityInfo.java @@ -60,7 +60,7 @@ public class CityInfo { this.cityLocation = cityLocation; civInfo.cities.add(this); cityConstructions = new CityConstructions(this); - if(civInfo.cities.size()==0) { + if(civInfo.cities.size()==1) { cityConstructions.builtBuildings.add("Palace"); cityConstructions.currentConstruction = "Worker"; // Default for first city only! } @@ -174,7 +174,8 @@ public class CityInfo { stats.culture+=population/2; FullStats statPercentBonuses = cityConstructions.getStatPercentBonuses(); - if(isCapital() || isConnectedToCapital(RoadStatus.Railroad)) statPercentBonuses.production += 25; + if( civInfo.tech.isResearched ("Combustion") && + (isCapital() || isConnectedToCapital(RoadStatus.Railroad))) statPercentBonuses.production += 25; if(civInfo.isGoldenAge()) statPercentBonuses.production+=20; IConstruction currentConstruction = cityConstructions.getCurrentConstruction(); if(currentConstruction instanceof Building && ((Building)currentConstruction).isWonder){ diff --git a/core/src/com/unciv/civinfo/CivilizationInfo.java b/core/src/com/unciv/civinfo/CivilizationInfo.java index 11d496cf..7b83efc0 100644 --- a/core/src/com/unciv/civinfo/CivilizationInfo.java +++ b/core/src/com/unciv/civinfo/CivilizationInfo.java @@ -90,7 +90,15 @@ public class CivilizationInfo { // 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 - for(TileInfo tile : tileMap.values()) tile.nextTurn(); + + // Here we need to filter out the tiles that don''t have units, because what happens if a unit in in tile 1, + // gets activated, and then moves to tile 2, which is activated later? Problem! + for(TileInfo tile : tileMap.values().where(new Predicate() { + @Override + public boolean evaluate(TileInfo arg0) { + return arg0.unit!=null; + } + })) tile.nextTurn(); if(isGoldenAge()) turnsLeftForCurrentGoldenAge--; diff --git a/core/src/com/unciv/civinfo/MapUnit.java b/core/src/com/unciv/civinfo/MapUnit.java index 52c32583..658053ab 100644 --- a/core/src/com/unciv/civinfo/MapUnit.java +++ b/core/src/com/unciv/civinfo/MapUnit.java @@ -1,5 +1,6 @@ package com.unciv.civinfo; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Predicate; import com.unciv.models.LinqCollection; import com.unciv.models.LinqHashMap; @@ -12,10 +13,20 @@ public class MapUnit{ public String action; // work, automation, fortifying, I dunno what. public void doAction(TileInfo tile){ + if(currentMovement==0) return; // We've already done stuff this turn, and can't do any more stuff + if(action!=null && action.startsWith("moveTo")){ + String[] destination = action.replace("moveTo ","").split(","); + Vector2 destinationVector = new Vector2(Integer.parseInt(destination[0]), Integer.parseInt(destination[1])); + TileInfo gotTo = headTowards(tile.position,destinationVector); + if(gotTo.position.equals(destinationVector)) action=null; + if(currentMovement!=0) doAction(gotTo); + return; + } if(name.equals("Worker") && tile.improvementInProgress!=null) workOnImprovement(tile); if ("automation".equals(action)) doAutomatedAction(tile); } + private void workOnImprovement(TileInfo tile){ tile.turnsToImprovement -= 1; if(tile.turnsToImprovement == 0) @@ -56,7 +67,7 @@ public class MapUnit{ // We'll search for a tile that needs our help in the reachable area LinqHashMap distanceToTiles = - CivilizationInfo.current().tileMap.getUnitDistanceToTiles(tile.position,currentMovement); + CivilizationInfo.current().tileMap.getDistanceToTilesWithinTurn(tile.position,currentMovement); TileInfo tileWithinDistance = new LinqCollection(distanceToTiles.keySet()).first(new Predicate() { @Override public boolean evaluate(TileInfo tile) { @@ -72,7 +83,6 @@ public class MapUnit{ // If not, then we don't know what to do. Oh well. } - private String chooseImprovement(final TileInfo tile){ if(tile.improvementInProgress!=null) return tile.improvementInProgress; if("Forest".equals(tile.terrainFeature)) return "Lumber mill"; @@ -86,4 +96,14 @@ public class MapUnit{ if(tile.baseTerrain.equals("Tundra")) return "Trading post"; return null; } + + public TileInfo headTowards(Vector2 origin, Vector2 destination){ + TileMap tileMap = CivilizationInfo.current().tileMap; + LinqCollection path = tileMap.getShortestPath(origin,destination,currentMovement,maxMovement); + + TileInfo destinationThisTurn = path.get(0); + float distanceToTile = tileMap.getDistanceToTilesWithinTurn(origin,currentMovement).get(destinationThisTurn); + tileMap.get(origin).moveUnitToTile(destinationThisTurn, distanceToTile); + return destinationThisTurn; + } } \ No newline at end of file diff --git a/core/src/com/unciv/civinfo/TileMap.java b/core/src/com/unciv/civinfo/TileMap.java index a4540e3a..b02333eb 100644 --- a/core/src/com/unciv/civinfo/TileMap.java +++ b/core/src/com/unciv/civinfo/TileMap.java @@ -84,7 +84,7 @@ public class TileMap{ return tiles; } - public LinqHashMap getUnitDistanceToTiles(Vector2 origin, float maximumMovement){ + public LinqHashMap getDistanceToTilesWithinTurn(Vector2 origin, float currentUnitMovement){ LinqHashMap distanceToTiles = new LinqHashMap(); distanceToTiles.put(get(origin), 0f); LinqCollection tilesToCheck = new LinqCollection(); @@ -102,8 +102,8 @@ public class TileMap{ float totalDistanceToTile = distanceToTiles.get(tileToCheck)+ distanceBetweenTiles; if (!distanceToTiles.containsKey(maybeUpdatedTile) || distanceToTiles.get(maybeUpdatedTile) > totalDistanceToTile) { - if(totalDistanceToTile getShortestPath(Vector2 origin, Vector2 destination, float currentMovement, int maxMovement){ + LinqCollection toCheck = new LinqCollection(get(origin)); + LinqHashMap parents = new LinqHashMap(); + parents.put(get(origin),null); + + for (int distance = 1; ; distance++) { + LinqCollection newToCheck = new LinqCollection(); + for (TileInfo ti : toCheck){ + for (TileInfo otherTile : getDistanceToTilesWithinTurn(ti.position, distance == 1 ? currentMovement : maxMovement).keySet()){ + if(parents.containsKey(otherTile) || otherTile.unit!=null) continue; // We cannot be faster than anything existing... + parents.put(otherTile,ti); + if(otherTile.position.equals(destination)){ + LinqCollection path = new LinqCollection(); + TileInfo current = otherTile; + while(parents.get(current)!=null){ + path.add(current); + current = parents.get(current); + } + return path.reverse(); + } + newToCheck.add(otherTile); + } + } + toCheck = newToCheck; + } + } + public LinqCollection values(){return tiles.linqValues();} TileResource GetRandomResource(LinqCollection resources, final ResourceType resourceType) { diff --git a/core/src/com/unciv/game/WorldScreen.java b/core/src/com/unciv/game/WorldScreen.java index b7cd2a11..5fb03263 100644 --- a/core/src/com/unciv/game/WorldScreen.java +++ b/core/src/com/unciv/game/WorldScreen.java @@ -314,12 +314,17 @@ public class WorldScreen extends CameraStageBaseScreen { public void clicked(InputEvent event, float x, float y) { selectedTile = tileInfo; if(unitTile != null && group.tileInfo.unit == null ) { - LinqHashMap distanceToTiles = game.civInfo.tileMap.getUnitDistanceToTiles(unitTile.position,unitTile.unit.currentMovement); + LinqHashMap distanceToTiles = game.civInfo.tileMap.getDistanceToTilesWithinTurn(unitTile.position,unitTile.unit.currentMovement); if(distanceToTiles.containsKey(selectedTile)) { unitTile.moveUnitToTile(group.tileInfo,distanceToTiles.get(selectedTile)); - unitTile = null; - selectedTile = group.tileInfo; } + else { + unitTile.unit.action="moveTo "+ ((int) selectedTile.position.x)+","+ ((int) selectedTile.position.y); + unitTile.unit.doAction(unitTile); + } + + unitTile = null; + selectedTile = group.tileInfo; } update(); @@ -425,7 +430,7 @@ public class WorldScreen extends CameraStageBaseScreen { // Set all tiles transparent except those in unit range for(TileGroup TG : tileGroups.linqValues()) TG.setColor(0,0,0,0.3f); - for(TileInfo tile : game.civInfo.tileMap.getUnitDistanceToTiles(unitTile.position,unitTile.unit.currentMovement).keySet()){ + for(TileInfo tile : game.civInfo.tileMap.getDistanceToTilesWithinTurn(unitTile.position,unitTile.unit.currentMovement).keySet()){ tileGroups.get(tile.position.toString()).setColor(Color.WHITE); } diff --git a/core/src/com/unciv/models/LinqCollection.java b/core/src/com/unciv/models/LinqCollection.java index aea35cfe..e9fca639 100644 --- a/core/src/com/unciv/models/LinqCollection.java +++ b/core/src/com/unciv/models/LinqCollection.java @@ -5,7 +5,9 @@ import com.badlogic.gdx.utils.Predicate; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; +import java.util.Stack; /** * Created by LENOVO on 10/20/2017. @@ -74,7 +76,9 @@ public class LinqCollection extends ArrayList { return newCollection; } - -} - - + public LinqCollection reverse(){ + LinqCollection newCol = new LinqCollection(this); + Collections.reverse(newCol); + return newCol; + } +} \ No newline at end of file