diff --git a/android/assets/TerrainIcons/road.png b/android/assets/TerrainIcons/road.png new file mode 100644 index 00000000..caed4bfb Binary files /dev/null and b/android/assets/TerrainIcons/road.png differ diff --git a/android/assets/jsons/Terrains.json b/android/assets/jsons/Terrains.json index 6875778d..5ff09b6e 100644 --- a/android/assets/jsons/Terrains.json +++ b/android/assets/jsons/Terrains.json @@ -3,6 +3,7 @@ name:"Grassland", type:"BaseTerrain", food:2, + movementCost:1, rgb:"0,255,0" }, { @@ -10,17 +11,20 @@ type:"BaseTerrain", food:1, production:1, + movementCost:1, rgb:"240,180,135" }, { name:"Tundra", type:"BaseTerrain", food:1, + movementCost:1, rgb:"130,137,121" }, { name:"Desert", type:"BaseTerrain", + movementCost:1, rgb:"237,201,175" }, { @@ -35,6 +39,7 @@ name:"Hill", type:"BaseTerrain", production:2, + movementCost:2, rgb:"116,88,62" }, @@ -44,6 +49,7 @@ type:"TerrainFeature", production:1, food:1, + movementCost:2, overrideStats:true, unbuildable:true, occursOn:["Tundra","Plains","Grassland"], @@ -53,6 +59,7 @@ name:"Jungle", type:"TerrainFeature", food:2, + movementCost:2, overrideStats:true, unbuildable:true, occursOn:["Plains","Grassland"], @@ -62,6 +69,7 @@ name:"Marsh", type:"TerrainFeature", food:-1, + movementCost:2, unbuildable:true, occursOn:["Grassland"], removalTech: "Masonry" @@ -70,6 +78,7 @@ name:"Oasis", type:"TerrainFeature", food:3, + movementCost:1, unbuildable:true, occursOn:["Desert"] }, @@ -77,6 +86,7 @@ name:"Flood plains", type:"TerrainFeature", food:2, + movementCost:1, occursOn:["Desert"] } ] \ No newline at end of file diff --git a/core/src/com/unciv/civinfo/TileInfo.java b/core/src/com/unciv/civinfo/TileInfo.java index b0d7df67..b3c5dbfb 100644 --- a/core/src/com/unciv/civinfo/TileInfo.java +++ b/core/src/com/unciv/civinfo/TileInfo.java @@ -9,6 +9,9 @@ import com.unciv.models.gamebasics.TileImprovement; import com.unciv.models.gamebasics.TileResource; import com.unciv.models.stats.FullStats; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; + public class TileInfo { public Unit unit; @@ -138,7 +141,7 @@ public class TileInfo 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+")"); + if(unit !=null) SB.append(",\r\n" + unit.Name+ "("+ new DecimalFormat("0.#").format(unit.CurrentMovement)+"/"+ unit.MaxMovement+")"); return SB.toString(); } diff --git a/core/src/com/unciv/civinfo/TileMap.java b/core/src/com/unciv/civinfo/TileMap.java index 4f48ea29..fb4ba9b0 100644 --- a/core/src/com/unciv/civinfo/TileMap.java +++ b/core/src/com/unciv/civinfo/TileMap.java @@ -11,8 +11,6 @@ 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,6 +84,33 @@ public class TileMap{ return tiles; } + public LinqHashMap getDistanceToTiles(Vector2 origin, float maximumMovement){ + LinqHashMap distanceToTiles = new LinqHashMap(); + distanceToTiles.put(get(origin), 0f); + LinqCollection tilesToCheck = new LinqCollection(); + tilesToCheck.add(get(origin)); + while(!tilesToCheck.isEmpty()){ + LinqCollection updatedTiles = new LinqCollection(); + for(TileInfo tileToCheck : tilesToCheck) + for (TileInfo maybeUpdatedTile : getTilesInDistance(tileToCheck.position,1)) { + float distanceBetweenTiles = maybeUpdatedTile.getLastTerrain().movementCost; + if(tileToCheck.roadStatus!=RoadStatus.None && maybeUpdatedTile.roadStatus!=RoadStatus.None) distanceBetweenTiles = 1/3f; + if(tileToCheck.roadStatus==RoadStatus.Railroad && maybeUpdatedTile.roadStatus==RoadStatus.Railroad) distanceBetweenTiles = 1/10f; + float totalDistanceToTile = distanceToTiles.get(tileToCheck)+ distanceBetweenTiles; + if (!distanceToTiles.containsKey(maybeUpdatedTile) || distanceToTiles.get(maybeUpdatedTile) > totalDistanceToTile) { + + if(totalDistanceToTile values(){return tiles.linqValues();} TileResource GetRandomResource(LinqCollection resources, final ResourceType resourceType) { diff --git a/core/src/com/unciv/civinfo/Unit.java b/core/src/com/unciv/civinfo/Unit.java index d30f6895..e3a1f194 100644 --- a/core/src/com/unciv/civinfo/Unit.java +++ b/core/src/com/unciv/civinfo/Unit.java @@ -3,7 +3,7 @@ package com.unciv.civinfo; public class Unit{ public String Name; public int MaxMovement; - public int CurrentMovement; + public float CurrentMovement; public Unit(){} // for json parsing, we need to have a default constructor diff --git a/core/src/com/unciv/game/WorldScreen.java b/core/src/com/unciv/game/WorldScreen.java index 7f8a7113..99c96225 100644 --- a/core/src/com/unciv/game/WorldScreen.java +++ b/core/src/com/unciv/game/WorldScreen.java @@ -212,19 +212,21 @@ public class WorldScreen extends CameraStageBaseScreen { group.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { - selectedTile = tileInfo; - if(unitTile != null && group.tileInfo.unit == null ) { - int distance = HexMath.GetDistance(unitTile.position, group.tileInfo.position); - if (distance <= unitTile.unit.CurrentMovement) { - unitTile.unit.CurrentMovement -= distance; - group.tileInfo.unit = unitTile.unit; - unitTile.unit = null; - unitTile = null; - selectedTile = group.tileInfo; - } + selectedTile = tileInfo; + if(unitTile != null && group.tileInfo.unit == null ) { + LinqHashMap distanceToTiles = game.civInfo.tileMap.getDistanceToTiles(unitTile.position,unitTile.unit.CurrentMovement); + if(distanceToTiles.containsKey(selectedTile)) { + unitTile.unit.CurrentMovement -= distanceToTiles.get(selectedTile); + unitTile.unit.CurrentMovement = round(unitTile.unit.CurrentMovement,3); + if(unitTile.unit.CurrentMovement < 0.1) unitTile.unit.CurrentMovement=0; // silly floats which are "almost zero" + group.tileInfo.unit = unitTile.unit; + unitTile.unit = null; + unitTile = null; + selectedTile = group.tileInfo; } + } - update(); + update(); } }); @@ -327,10 +329,9 @@ 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(Vector2 vector : HexMath.GetVectorsInDistance(unitTile.position, unitTile.unit.CurrentMovement)){ - if(tileGroups.containsKey(vector.toString())) - tileGroups.get(vector.toString()).setColor(Color.WHITE); - } + for(TileInfo tile : game.civInfo.tileMap.getDistanceToTiles(unitTile.position,unitTile.unit.CurrentMovement).keySet()){ + tileGroups.get(tile.position.toString()).setColor(Color.WHITE); + } update(); } @@ -456,6 +457,10 @@ public class WorldScreen extends CameraStageBaseScreen { scrollPane.updateVisualScroll(); } + float round(float value, int scale){ + return (float) (Math.round(value * Math.pow(10, scale)) / Math.pow(10, scale)); + } + } diff --git a/core/src/com/unciv/models/gamebasics/Terrain.java b/core/src/com/unciv/models/gamebasics/Terrain.java index 7ed70453..8016b259 100644 --- a/core/src/com/unciv/models/gamebasics/Terrain.java +++ b/core/src/com/unciv/models/gamebasics/Terrain.java @@ -30,6 +30,7 @@ public class Terrain extends NamedStats implements ICivilopedia { *For terrain features - which technology alllows removal of this feature */ public String removalTech; + public int movementCost=1; public String rgb;