shape
This commit is contained in:
@@ -1345,14 +1345,14 @@ public class MobAI {
|
||||
|
||||
public static void aiMove(Mob mob, boolean isWalking, float offset) {
|
||||
|
||||
if(mob.navPath.isEmpty() || mob.navPath.size() == 1){
|
||||
NavigationManager.pathfind(mob,mob.destination);
|
||||
return;
|
||||
}
|
||||
if(mob.isMoving()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(mob.navPath.isEmpty()){
|
||||
NavigationManager.pathfind(mob,mob.destination);
|
||||
return;
|
||||
}
|
||||
Vector3fImmutable PathPoint = mob.navPath.get(0);
|
||||
if(mob.loc.distanceSquared(mob.destination) > mob.loc.distanceSquared2D(mob.destination)) {
|
||||
mob.navPath.remove(0);
|
||||
@@ -1393,6 +1393,46 @@ public class MobAI {
|
||||
|
||||
|
||||
|
||||
try {
|
||||
MovementManager.movement(msg, mob);
|
||||
} catch (MsgSendException e) {
|
||||
// TODO Figure out how we want to handle the msg send exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void directMove(Mob mob,boolean isWalking){
|
||||
//update our walk/run state.
|
||||
if (isWalking && !mob.isWalk()) {
|
||||
mob.setWalkMode(true);
|
||||
MovementManager.sendRWSSMsg(mob);
|
||||
} else if (!isWalking && mob.isWalk()) {
|
||||
mob.setWalkMode(false);
|
||||
MovementManager.sendRWSSMsg(mob);
|
||||
}
|
||||
mob.endLoc = mob.destination;
|
||||
|
||||
MoveToPointMsg msg = new MoveToPointMsg();
|
||||
|
||||
msg.setSourceType(Enum.GameObjectType.Mob.ordinal());
|
||||
msg.setSourceID(mob.getObjectUUID());
|
||||
msg.setStartCoord(mob.loc);
|
||||
msg.setEndCoord(mob.destination);
|
||||
Regions region = Regions.getRegionAtLocation(mob.destination);
|
||||
if(region != null){
|
||||
msg.setInBuildingFloor(region.room);
|
||||
msg.setInBuilding(region.level);
|
||||
msg.setStartLocType(0);
|
||||
msg.setInBuildingUUID(region.parentBuildingID);
|
||||
} else{
|
||||
msg.setInBuildingFloor(-1);
|
||||
msg.setInBuilding(-1);
|
||||
msg.setStartLocType(0);
|
||||
msg.setInBuildingUUID(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
MovementManager.movement(msg, mob);
|
||||
} catch (MsgSendException e) {
|
||||
|
||||
@@ -1,80 +1,22 @@
|
||||
package engine.mobileAI.utilities;
|
||||
import engine.math.Vector2f;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.Regions;
|
||||
import java.awt.geom.Area;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PathingUtilities {
|
||||
public static class Point {
|
||||
public int x;
|
||||
public int y;
|
||||
public Point previous;
|
||||
public static class Node {
|
||||
public Vector2f location;
|
||||
public ArrayList<Node> neighbors;
|
||||
public Regions region;
|
||||
public Building parentBuilding;
|
||||
|
||||
public Point(int x, int y, Point previous) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.previous = previous;
|
||||
public Node(Vector2f loc, Regions reg, Building parent){
|
||||
this.location = loc;
|
||||
this.region = reg;
|
||||
this.parentBuilding = parent;
|
||||
}
|
||||
|
||||
public Point offset(int ox, int oy) { return new Point(x + ox, y + oy, this); }
|
||||
}
|
||||
|
||||
public static boolean IsWalkable(Area navMesh, Point point) {
|
||||
if (navMesh.contains(point.x, point.y))
|
||||
return true;
|
||||
|
||||
Regions region = Regions.getRegionAtPoint(point);
|
||||
if (region != null) {
|
||||
return !(region.getHeightAtPoint(point) - point.y > 2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Point> FindNeighbors(Area navMesh, Point point) {
|
||||
ArrayList<Point> neighbors = new ArrayList<>();
|
||||
Point up = point.offset(0, 1);
|
||||
Point down = point.offset(0, -1);
|
||||
Point left = point.offset(-1, 0);
|
||||
Point right = point.offset(1, 0);
|
||||
if (IsWalkable(navMesh, up)) neighbors.add(up);
|
||||
if (IsWalkable(navMesh, down)) neighbors.add(down);
|
||||
if (IsWalkable(navMesh, left)) neighbors.add(left);
|
||||
if (IsWalkable(navMesh, right)) neighbors.add(right);
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
public static ArrayList<Point> FindPath(Area navMesh, Point start, Point end) {
|
||||
boolean finished = false;
|
||||
ArrayList<Point> used = new ArrayList<>();
|
||||
used.add(start);
|
||||
while (!finished) {
|
||||
ArrayList<Point> newOpen = new ArrayList<>();
|
||||
for(int i = 0; i < used.size(); ++i){
|
||||
Point point = used.get(i);
|
||||
for (Point neighbor : FindNeighbors(navMesh, point)) {
|
||||
if (!used.contains(neighbor) && !newOpen.contains(neighbor)) {
|
||||
newOpen.add(neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Point point : newOpen) {
|
||||
used.add(point);
|
||||
if (end.equals(point)) {
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!finished && newOpen.isEmpty())
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<Point> path = new ArrayList<>();
|
||||
Point point = used.get(used.size() - 1);
|
||||
while(point.previous != null) {
|
||||
path.add(0, point);
|
||||
point = point.previous;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user