2023-11-05 10:45:35 -06:00
|
|
|
package engine.mobileAI.utilities;
|
2023-11-14 21:44:17 -06:00
|
|
|
import engine.gameManager.ZoneManager;
|
2023-11-14 20:54:29 -06:00
|
|
|
import engine.math.Vector2f;
|
2023-11-14 21:44:17 -06:00
|
|
|
import engine.math.Vector3fImmutable;
|
2023-11-14 20:54:29 -06:00
|
|
|
import engine.objects.Building;
|
2023-11-05 10:45:35 -06:00
|
|
|
import engine.objects.Regions;
|
2023-11-14 21:44:17 -06:00
|
|
|
import engine.objects.Zone;
|
|
|
|
|
import org.pmw.tinylog.Logger;
|
2023-11-14 20:54:29 -06:00
|
|
|
|
2023-11-14 21:44:17 -06:00
|
|
|
import java.awt.geom.Path2D;
|
2023-11-05 10:45:35 -06:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
public class PathingUtilities {
|
2023-11-14 20:54:29 -06:00
|
|
|
public static class Node {
|
|
|
|
|
public Vector2f location;
|
|
|
|
|
public ArrayList<Node> neighbors;
|
|
|
|
|
public Regions region;
|
|
|
|
|
public Building parentBuilding;
|
|
|
|
|
|
|
|
|
|
public Node(Vector2f loc, Regions reg, Building parent){
|
|
|
|
|
this.location = loc;
|
|
|
|
|
this.region = reg;
|
|
|
|
|
this.parentBuilding = parent;
|
2023-11-14 21:21:49 -06:00
|
|
|
this.neighbors = new ArrayList<>();
|
2023-11-05 10:45:35 -06:00
|
|
|
}
|
2023-11-14 21:44:17 -06:00
|
|
|
public ArrayList<Node> getNeighbors(){
|
|
|
|
|
if(neighbors.size() == 0){
|
|
|
|
|
Zone zone = ZoneManager.findSmallestZone(new Vector3fImmutable(this.location.x,0,this.location.y));
|
|
|
|
|
if(zone == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
for(Node potentialNeighbor : zone.navNodes){
|
|
|
|
|
for (Path2D.Float obstacle : zone.navObstacles) {
|
|
|
|
|
if (!this.equals(potentialNeighbor) && !obstacle.intersects(this.location.x, this.location.y, potentialNeighbor.location.x, potentialNeighbor.location.y) && this.location.distance(potentialNeighbor.location) < 65) {
|
|
|
|
|
this.neighbors.add(potentialNeighbor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this.neighbors;
|
|
|
|
|
}
|
2023-11-05 10:45:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|