Unit pathfinding

This commit is contained in:
Anuken
2022-02-09 17:13:02 -05:00
parent a24a94d0b0
commit fa79c5e93a
23 changed files with 841 additions and 151 deletions

View File

@@ -200,18 +200,18 @@ public class SectorDamage{
boolean found = false;
if(field != null && field.weights != null){
int[][] weights = field.weights;
int[] weights = field.weights;
int count = 0;
Tile current = start;
while(count < world.width() * world.height()){
while(count < weights.length){
int minCost = Integer.MAX_VALUE;
int cx = current.x, cy = current.y;
for(Point2 p : Geometry.d4){
int nx = cx + p.x, ny = cy + p.y;
int nx = cx + p.x, ny = cy + p.y, packed = world.packArray(nx, ny);
Tile other = world.tile(nx, ny);
if(other != null && weights[nx][ny] < minCost && weights[nx][ny] != -1){
minCost = weights[nx][ny];
if(other != null && weights[packed] < minCost && weights[packed] != -1){
minCost = weights[packed];
current = other;
}
}