mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-09 10:29:02 +07:00
Implemented line-of-sight according to terrain
This commit is contained in:
parent
45111d89e0
commit
63f24db67b
@ -21,8 +21,8 @@ android {
|
||||
applicationId "com.unciv.game"
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 25
|
||||
versionCode 18
|
||||
versionName "1.0"
|
||||
versionCode 19
|
||||
versionName "1.1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@ -76,7 +76,7 @@ public class CivilizationTech{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class MapUnit{
|
||||
return tile.improvement==null
|
||||
&& tile.canBuildImprovement(GameBasics.TileImprovements.get(chooseImprovement(tile)))
|
||||
&& tile.hasViewableResource()
|
||||
&& CivilizationInfo.current().tileMap.getTilesAtDistance(tile.position,1).any(new Predicate<TileInfo>() {
|
||||
&& tile.getNeighbors().any(new Predicate<TileInfo>() {
|
||||
@Override
|
||||
public boolean evaluate(TileInfo arg0) {
|
||||
return arg0.owner!=null;
|
||||
|
@ -167,4 +167,8 @@ public class TileInfo
|
||||
otherTile.unit = unit;
|
||||
unit = null;
|
||||
}
|
||||
|
||||
public LinqCollection<TileInfo> getNeighbors(){
|
||||
return CivilizationInfo.current().tileMap.getTilesAtDistance(position,1);
|
||||
}
|
||||
}
|
@ -124,17 +124,6 @@ public class TileMap{
|
||||
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>();
|
||||
@ -183,5 +172,33 @@ public class TileMap{
|
||||
}).unit = GameBasics.Units.get(unit).getMapUnit(); // And if there's none, then kill me.
|
||||
}
|
||||
|
||||
public int getTileHeight(TileInfo tileInfo){
|
||||
int height=0;
|
||||
if(new LinqCollection<String>("Forest","Jungle").contains(tileInfo.terrainFeature)) height+=1;
|
||||
if("Hill".equals(tileInfo.baseTerrain)) height+=2;
|
||||
return height;
|
||||
}
|
||||
|
||||
public LinqCollection<TileInfo> getViewableTiles(Vector2 position, int sightDistance){
|
||||
final LinqCollection<TileInfo> tiles = getTilesInDistance(position,1);
|
||||
if(get(position).baseTerrain.equals("Hill")) sightDistance+=1;
|
||||
for (int i = 0; i <= sightDistance; i++) {
|
||||
LinqCollection<TileInfo> tilesForLayer = new LinqCollection<TileInfo>();
|
||||
for (final TileInfo tile : getTilesAtDistance(position, i))
|
||||
if (tile.getNeighbors().any(new Predicate<TileInfo>() {
|
||||
@Override
|
||||
public boolean evaluate(TileInfo arg0) {
|
||||
if (!tiles.contains(arg0))
|
||||
return false; // Basically, if there's a viewable neighbor which is either flatlands, or I'm taller than him
|
||||
int tileHeight = getTileHeight(arg0);
|
||||
return tileHeight == 0 || getTileHeight(tile) > tileHeight;
|
||||
}
|
||||
})) tilesForLayer.add(tile);
|
||||
tiles.addAll(tilesForLayer);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ public class TileGroup extends Group {
|
||||
}
|
||||
|
||||
if(tileInfo.roadStatus != RoadStatus.None){
|
||||
for (TileInfo neighbor : CivilizationInfo.current().tileMap.getTilesAtDistance(tileInfo.position,1)) {
|
||||
for (TileInfo neighbor : tileInfo.getNeighbors()) {
|
||||
if (neighbor.roadStatus == RoadStatus.None) continue;
|
||||
if (!roadImages.containsKey(neighbor.position.toString())) {
|
||||
Image image = ImageGetter.getImage(ImageGetter.WhiteDot);
|
||||
|
@ -701,8 +701,8 @@ public class WorldScreen extends CameraStageBaseScreen {
|
||||
return arg0.unit != null;
|
||||
}
|
||||
}))
|
||||
for (Vector2 vector : HexMath.GetVectorsInDistance(tile.position, 2))
|
||||
ViewableVectorStrings.add(vector.toString());
|
||||
for (TileInfo tileInfo : game.civInfo.tileMap.getViewableTiles(tile.position,2))
|
||||
ViewableVectorStrings.add(tileInfo.position.toString());
|
||||
|
||||
for (String string : ViewableVectorStrings)
|
||||
if (tileGroups.containsKey(string))
|
||||
|
Loading…
Reference in New Issue
Block a user