Physics, pathfinding improvements

This commit is contained in:
Anuken
2018-10-10 11:29:34 -04:00
parent 6b4983537e
commit 05201d7012
6 changed files with 20 additions and 12 deletions

View File

@@ -155,9 +155,7 @@ public class BlockIndexer{
return ores.get(item, emptySet);
}
/**
* Find the closest ore block relative to a position.
*/
/**Find the closest ore block relative to a position.*/
public Tile findClosestOre(float xp, float yp, Item item){
Tile tile = Geometry.findClosest(xp, yp, world.indexer.getOrePositions(item));

View File

@@ -82,16 +82,12 @@ public class Pathfinder{
return target;
}
public float getDebugValue(int x, int y){
return paths[Team.blue.ordinal()].weights[x][y];
}
public float getValueforTeam(Team team, int x, int y){
return paths == null || team.ordinal() >= paths.length ? 0 : paths[team.ordinal()].weights[x][y];
}
private boolean passable(Tile tile, Team team){
return (!tile.solid() && !(tile.floor().isLiquid))
return (!tile.solid())
|| (tile.breakable() && (tile.target().getTeam() != team));
}
@@ -160,10 +156,10 @@ public class Pathfinder{
int dx = tile.x + point.x, dy = tile.y + point.y;
Tile other = world.tile(dx, dy);
if(other != null && (path.weights[dx][dy] > cost + 1 || path.searches[dx][dy] < path.search)
if(other != null && (path.weights[dx][dy] == Float.MAX_VALUE || path.searches[dx][dy] < path.search)
&& passable(other, team)){
path.frontier.addFirst(world.tile(dx, dy));
path.weights[dx][dy] = cost + other.cost / 2f;
path.weights[dx][dy] = cost + other.cost;
path.searches[dx][dy] = path.search;
}
}

View File

@@ -121,6 +121,15 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
return velocity;
}
@Override
public void move(float x, float y){
if(!isFlying()){
super.move(x, y);
}else{
moveBy(x, y);
}
}
@Override
public void writeSave(DataOutput stream) throws IOException{
writeSave(stream, false);

View File

@@ -23,7 +23,7 @@ public class BattleMission extends Mission{
@Override
public void generate(Generation gen){
int enemyX = gen.width-1-coreX, enemyY = gen.height-1-coreX;
//int enemyX = gen.width-1-coreX, enemyY = gen.height-1-coreX;
//generateCoreAt(gen, coreX, coreY, Team.blue);
//generateCoreAt(gen, enemyX, enemyY, Team.red);

View File

@@ -390,9 +390,14 @@ public class Tile implements PosTrait, TargetTrait{
cliffs |= (1 << (i * 2));
}
}
if(occluded){
cost += 1;
}
if(floor.isLiquid){
cost += 100f;
}
}
private void preChanged(){