mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 03:23:17 -04:00
Added unit movement to further tiles
This commit is contained in:
parent
ab2b33318b
commit
befb0561b5
@ -21,7 +21,7 @@ android {
|
|||||||
applicationId "com.unciv.game"
|
applicationId "com.unciv.game"
|
||||||
minSdkVersion 9
|
minSdkVersion 9
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 13
|
versionCode 14
|
||||||
versionName "0.9"
|
versionName "0.9"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
@ -60,7 +60,7 @@ public class CityInfo {
|
|||||||
this.cityLocation = cityLocation;
|
this.cityLocation = cityLocation;
|
||||||
civInfo.cities.add(this);
|
civInfo.cities.add(this);
|
||||||
cityConstructions = new CityConstructions(this);
|
cityConstructions = new CityConstructions(this);
|
||||||
if(civInfo.cities.size()==0) {
|
if(civInfo.cities.size()==1) {
|
||||||
cityConstructions.builtBuildings.add("Palace");
|
cityConstructions.builtBuildings.add("Palace");
|
||||||
cityConstructions.currentConstruction = "Worker"; // Default for first city only!
|
cityConstructions.currentConstruction = "Worker"; // Default for first city only!
|
||||||
}
|
}
|
||||||
@ -174,7 +174,8 @@ public class CityInfo {
|
|||||||
stats.culture+=population/2;
|
stats.culture+=population/2;
|
||||||
|
|
||||||
FullStats statPercentBonuses = cityConstructions.getStatPercentBonuses();
|
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;
|
if(civInfo.isGoldenAge()) statPercentBonuses.production+=20;
|
||||||
IConstruction currentConstruction = cityConstructions.getCurrentConstruction();
|
IConstruction currentConstruction = cityConstructions.getCurrentConstruction();
|
||||||
if(currentConstruction instanceof Building && ((Building)currentConstruction).isWonder){
|
if(currentConstruction instanceof Building && ((Building)currentConstruction).isWonder){
|
||||||
|
@ -90,7 +90,15 @@ public class CivilizationInfo {
|
|||||||
|
|
||||||
// We need to update the stats after ALL the cities are done updating because
|
// 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
|
// 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<TileInfo>() {
|
||||||
|
@Override
|
||||||
|
public boolean evaluate(TileInfo arg0) {
|
||||||
|
return arg0.unit!=null;
|
||||||
|
}
|
||||||
|
})) tile.nextTurn();
|
||||||
|
|
||||||
if(isGoldenAge()) turnsLeftForCurrentGoldenAge--;
|
if(isGoldenAge()) turnsLeftForCurrentGoldenAge--;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.unciv.civinfo;
|
package com.unciv.civinfo;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.Predicate;
|
import com.badlogic.gdx.utils.Predicate;
|
||||||
import com.unciv.models.LinqCollection;
|
import com.unciv.models.LinqCollection;
|
||||||
import com.unciv.models.LinqHashMap;
|
import com.unciv.models.LinqHashMap;
|
||||||
@ -12,10 +13,20 @@ public class MapUnit{
|
|||||||
public String action; // work, automation, fortifying, I dunno what.
|
public String action; // work, automation, fortifying, I dunno what.
|
||||||
|
|
||||||
public void doAction(TileInfo tile){
|
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(name.equals("Worker") && tile.improvementInProgress!=null) workOnImprovement(tile);
|
||||||
if ("automation".equals(action)) doAutomatedAction(tile);
|
if ("automation".equals(action)) doAutomatedAction(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void workOnImprovement(TileInfo tile){
|
private void workOnImprovement(TileInfo tile){
|
||||||
tile.turnsToImprovement -= 1;
|
tile.turnsToImprovement -= 1;
|
||||||
if(tile.turnsToImprovement == 0)
|
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
|
// We'll search for a tile that needs our help in the reachable area
|
||||||
LinqHashMap<TileInfo, Float> distanceToTiles =
|
LinqHashMap<TileInfo, Float> distanceToTiles =
|
||||||
CivilizationInfo.current().tileMap.getUnitDistanceToTiles(tile.position,currentMovement);
|
CivilizationInfo.current().tileMap.getDistanceToTilesWithinTurn(tile.position,currentMovement);
|
||||||
TileInfo tileWithinDistance = new LinqCollection<TileInfo>(distanceToTiles.keySet()).first(new Predicate<TileInfo>() {
|
TileInfo tileWithinDistance = new LinqCollection<TileInfo>(distanceToTiles.keySet()).first(new Predicate<TileInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(TileInfo tile) {
|
public boolean evaluate(TileInfo tile) {
|
||||||
@ -72,7 +83,6 @@ public class MapUnit{
|
|||||||
// If not, then we don't know what to do. Oh well.
|
// If not, then we don't know what to do. Oh well.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String chooseImprovement(final TileInfo tile){
|
private String chooseImprovement(final TileInfo tile){
|
||||||
if(tile.improvementInProgress!=null) return tile.improvementInProgress;
|
if(tile.improvementInProgress!=null) return tile.improvementInProgress;
|
||||||
if("Forest".equals(tile.terrainFeature)) return "Lumber mill";
|
if("Forest".equals(tile.terrainFeature)) return "Lumber mill";
|
||||||
@ -86,4 +96,14 @@ public class MapUnit{
|
|||||||
if(tile.baseTerrain.equals("Tundra")) return "Trading post";
|
if(tile.baseTerrain.equals("Tundra")) return "Trading post";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TileInfo headTowards(Vector2 origin, Vector2 destination){
|
||||||
|
TileMap tileMap = CivilizationInfo.current().tileMap;
|
||||||
|
LinqCollection<TileInfo> 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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -84,7 +84,7 @@ public class TileMap{
|
|||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinqHashMap<TileInfo,Float> getUnitDistanceToTiles(Vector2 origin, float maximumMovement){
|
public LinqHashMap<TileInfo,Float> getDistanceToTilesWithinTurn(Vector2 origin, float currentUnitMovement){
|
||||||
LinqHashMap<TileInfo,Float> distanceToTiles = new LinqHashMap<TileInfo, Float>();
|
LinqHashMap<TileInfo,Float> distanceToTiles = new LinqHashMap<TileInfo, Float>();
|
||||||
distanceToTiles.put(get(origin), 0f);
|
distanceToTiles.put(get(origin), 0f);
|
||||||
LinqCollection<TileInfo> tilesToCheck = new LinqCollection<TileInfo>();
|
LinqCollection<TileInfo> tilesToCheck = new LinqCollection<TileInfo>();
|
||||||
@ -102,8 +102,8 @@ public class TileMap{
|
|||||||
float totalDistanceToTile = distanceToTiles.get(tileToCheck)+ distanceBetweenTiles;
|
float totalDistanceToTile = distanceToTiles.get(tileToCheck)+ distanceBetweenTiles;
|
||||||
if (!distanceToTiles.containsKey(maybeUpdatedTile) || distanceToTiles.get(maybeUpdatedTile) > totalDistanceToTile) {
|
if (!distanceToTiles.containsKey(maybeUpdatedTile) || distanceToTiles.get(maybeUpdatedTile) > totalDistanceToTile) {
|
||||||
|
|
||||||
if(totalDistanceToTile<maximumMovement) updatedTiles.add(maybeUpdatedTile);
|
if(totalDistanceToTile<currentUnitMovement) updatedTiles.add(maybeUpdatedTile);
|
||||||
else totalDistanceToTile = maximumMovement;
|
else totalDistanceToTile = currentUnitMovement;
|
||||||
distanceToTiles.put(maybeUpdatedTile,totalDistanceToTile);
|
distanceToTiles.put(maybeUpdatedTile,totalDistanceToTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +114,44 @@ public class TileMap{
|
|||||||
return distanceToTiles;
|
return distanceToTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class BfsInfo{
|
||||||
|
|
||||||
|
final TileInfo parent;
|
||||||
|
final int totalDistance;
|
||||||
|
|
||||||
|
public BfsInfo(TileInfo parent, int totalDistance) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.totalDistance = totalDistance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinqCollection<TileInfo> getShortestPath(Vector2 origin, Vector2 destination, float currentMovement, int maxMovement){
|
||||||
|
LinqCollection<TileInfo> toCheck = new LinqCollection<TileInfo>(get(origin));
|
||||||
|
LinqHashMap<TileInfo,TileInfo> parents = new LinqHashMap<TileInfo, TileInfo>();
|
||||||
|
parents.put(get(origin),null);
|
||||||
|
|
||||||
|
for (int distance = 1; ; distance++) {
|
||||||
|
LinqCollection<TileInfo> newToCheck = new LinqCollection<TileInfo>();
|
||||||
|
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<TileInfo> path = new LinqCollection<TileInfo>();
|
||||||
|
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<TileInfo> values(){return tiles.linqValues();}
|
public LinqCollection<TileInfo> values(){return tiles.linqValues();}
|
||||||
|
|
||||||
TileResource GetRandomResource(LinqCollection<TileResource> resources, final ResourceType resourceType) {
|
TileResource GetRandomResource(LinqCollection<TileResource> resources, final ResourceType resourceType) {
|
||||||
|
@ -314,12 +314,17 @@ public class WorldScreen extends CameraStageBaseScreen {
|
|||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
selectedTile = tileInfo;
|
selectedTile = tileInfo;
|
||||||
if(unitTile != null && group.tileInfo.unit == null ) {
|
if(unitTile != null && group.tileInfo.unit == null ) {
|
||||||
LinqHashMap<TileInfo, Float> distanceToTiles = game.civInfo.tileMap.getUnitDistanceToTiles(unitTile.position,unitTile.unit.currentMovement);
|
LinqHashMap<TileInfo, Float> distanceToTiles = game.civInfo.tileMap.getDistanceToTilesWithinTurn(unitTile.position,unitTile.unit.currentMovement);
|
||||||
if(distanceToTiles.containsKey(selectedTile)) {
|
if(distanceToTiles.containsKey(selectedTile)) {
|
||||||
unitTile.moveUnitToTile(group.tileInfo,distanceToTiles.get(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();
|
update();
|
||||||
@ -425,7 +430,7 @@ public class WorldScreen extends CameraStageBaseScreen {
|
|||||||
|
|
||||||
// Set all tiles transparent except those in unit range
|
// Set all tiles transparent except those in unit range
|
||||||
for(TileGroup TG : tileGroups.linqValues()) TG.setColor(0,0,0,0.3f);
|
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);
|
tileGroups.get(tile.position.toString()).setColor(Color.WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,9 @@ import com.badlogic.gdx.utils.Predicate;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by LENOVO on 10/20/2017.
|
* Created by LENOVO on 10/20/2017.
|
||||||
@ -74,7 +76,9 @@ public class LinqCollection <T> extends ArrayList<T> {
|
|||||||
return newCollection;
|
return newCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LinqCollection<T> reverse(){
|
||||||
}
|
LinqCollection<T> newCol = new LinqCollection<T>(this);
|
||||||
|
Collections.reverse(newCol);
|
||||||
|
return newCol;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user