Pathfinding fixes

This commit is contained in:
Anuken
2023-09-25 12:23:46 -04:00
parent d8535c4d03
commit 7536bbfeb0
7 changed files with 98 additions and 317 deletions

View File

@@ -20,22 +20,18 @@ public class Units{
private static final Rect hitrect = new Rect();
private static Unit result;
private static float cdist, cpriority;
private static boolean boolResult;
private static int intResult;
private static Building buildResult;
//prevents allocations in anyEntities
private static boolean anyEntityGround;
private static float aeX, aeY, aeW, aeH;
private static final Cons<Unit> anyEntityLambda = unit -> {
if(boolResult) return;
private static final Boolf<Unit> anyEntityLambda = unit -> {
if((unit.isGrounded() && !unit.type.allowLegStep) == anyEntityGround){
unit.hitboxTile(hitrect);
if(hitrect.overlaps(aeX, aeY, aeW, aeH)){
boolResult = true;
}
return hitrect.overlaps(aeX, aeY, aeW, aeH);
}
return false;
};
@Remote(called = Loc.server)
@@ -162,31 +158,26 @@ public class Units{
}
public static boolean anyEntities(float x, float y, float width, float height, boolean ground){
boolResult = false;
anyEntityGround = ground;
aeX = x;
aeY = y;
aeW = width;
aeH = height;
nearby(x, y, width, height, anyEntityLambda);
return boolResult;
return nearbyCheck(x, y, width, height, anyEntityLambda);
}
/** Note that this checks the tile hitbox, not the standard hitbox. */
public static boolean anyEntities(float x, float y, float width, float height, Boolf<Unit> check){
boolResult = false;
nearby(x, y, width, height, unit -> {
if(boolResult) return;
return nearbyCheck(x, y, width, height, unit -> {
if(check.get(unit)){
unit.hitboxTile(hitrect);
if(hitrect.overlaps(x, y, width, height)){
boolResult = true;
}
return hitrect.overlaps(x, y, width, height);
}
return false;
});
return boolResult;
}
/** Returns the nearest damaged tile. */
@@ -428,6 +419,14 @@ public class Units{
Groups.unit.intersect(x, y, width, height, cons);
}
/**
* Iterates over all units in a rectangle.
* @return whether a unit was found.
* */
public static boolean nearbyCheck(float x, float y, float width, float height, Boolf<Unit> cons){
return Groups.unit.intersect(x, y, width, height, cons);
}
/** Iterates over all units in a rectangle. */
public static void nearby(Rect rect, Cons<Unit> cons){
nearby(rect.x, rect.y, rect.width, rect.height, cons);