shape
This commit is contained in:
@@ -20,6 +20,7 @@ import engine.jobs.UpgradeBuildingJob;
|
||||
import engine.math.Bounds;
|
||||
import engine.math.Vector2f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.mobileAI.utilities.PathingUtilities;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.ManageCityAssetsMsg;
|
||||
@@ -998,6 +999,29 @@ public enum BuildingManager {
|
||||
meshBound.lineTo(rotatedStart.x,rotatedStart.z);
|
||||
meshBound.closePath();
|
||||
building.meshes.add(meshBound);
|
||||
building.parentZone.navObstacles.add(meshBound);
|
||||
}
|
||||
//add navNodes to parent zone list
|
||||
float X = building.getBounds().getHalfExtents().x;
|
||||
float Y = building.getBounds().getHalfExtents().y;
|
||||
ArrayList<Vector2f> cornersAndFaces = new ArrayList<>();
|
||||
cornersAndFaces.add(new Vector2f(building.loc.x - X,building.loc.z - Y));
|
||||
cornersAndFaces.add(new Vector2f(building.loc.x + X,building.loc.z + Y));
|
||||
cornersAndFaces.add(new Vector2f(building.loc.x + X,building.loc.z - Y));
|
||||
cornersAndFaces.add(new Vector2f(building.loc.x - X,building.loc.z + Y));
|
||||
cornersAndFaces.add(new Vector2f(building.loc.x - X,building.loc.z));
|
||||
cornersAndFaces.add(new Vector2f(building.loc.x + X,building.loc.z));
|
||||
cornersAndFaces.add(new Vector2f(building.loc.x,building.loc.z - Y));
|
||||
cornersAndFaces.add(new Vector2f(building.loc.x,building.loc.z + Y));
|
||||
for(Vector2f point : cornersAndFaces){
|
||||
if(!NavigationManager.pointIsBlocked(new Vector3fImmutable(point.x,building.loc.y,point.y))){
|
||||
building.parentZone.navNodes.add(new PathingUtilities.Node(point,null,building));
|
||||
}
|
||||
}
|
||||
|
||||
//add region centers to the zones navNodes list
|
||||
for(Regions region : building.getBounds().getRegions()){
|
||||
building.parentZone.navNodes.add(new PathingUtilities.Node(new Vector2f(region.center.x,region.center.z),region,building));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package engine.gameManager;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.mobileAI.MobAI;
|
||||
import engine.net.client.msg.MoveToPointMsg;
|
||||
import engine.objects.*;
|
||||
import java.awt.geom.Path2D;
|
||||
@@ -14,31 +15,16 @@ public class NavigationManager {
|
||||
private static final int stepHeight = 2;
|
||||
|
||||
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal) {
|
||||
if(!pathBlocked(character.loc,goal)){
|
||||
character.destination = goal;
|
||||
MobAI.directMove((Mob)character,character.combatTarget != null);
|
||||
}
|
||||
try {
|
||||
ArrayList<Vector3fImmutable> path = getPath(character.loc, goal);//getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc));
|
||||
if (path.isEmpty()) {
|
||||
MoveToPointMsg msg = new MoveToPointMsg();
|
||||
|
||||
msg.setSourceType(Enum.GameObjectType.Mob.ordinal());
|
||||
msg.setSourceID(character.getObjectUUID());
|
||||
msg.setStartCoord(character.loc);
|
||||
msg.setEndCoord(goal);
|
||||
Regions region = Regions.getRegionAtLocation(goal);
|
||||
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);
|
||||
}
|
||||
MobAI.directMove((Mob)character,character.combatTarget != null);
|
||||
return; //no points to walk to
|
||||
}
|
||||
|
||||
//character.destination = path.get(1);
|
||||
character.navPath = path;
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -109,30 +95,43 @@ public class NavigationManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static float getCost(Vector3fImmutable point, Vector3fImmutable start, Vector3fImmutable goal) {
|
||||
float gCost = start.distanceSquared(point);
|
||||
float hCost = goal.distanceSquared(point);
|
||||
return gCost + hCost;
|
||||
}
|
||||
|
||||
public static boolean pointIsBlocked(Vector3fImmutable point) {
|
||||
|
||||
Building building = BuildingManager.getBuildingAtLocation(point);
|
||||
if(building != null) {
|
||||
for (Path2D.Float mesh : building.meshes) {
|
||||
if (mesh.contains(point.x,point.z)) {
|
||||
public static boolean pathBlocked(Vector3fImmutable start, Vector3fImmutable end){
|
||||
Zone zone = ZoneManager.findSmallestZone(start);
|
||||
if(zone != null) {
|
||||
for (Path2D.Float obstacle : zone.navObstacles)
|
||||
if(obstacle.intersects(start.x,start.z,end.x,end.z))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (Regions region : building.getBounds().getRegions()) {
|
||||
if (region.isPointInPolygon(point))
|
||||
if (Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean pointIsBlocked(Vector3fImmutable point) {
|
||||
Zone zone = ZoneManager.findSmallestZone(point);
|
||||
if(zone != null){
|
||||
for(Path2D.Float obstacle : zone.navObstacles)
|
||||
if (obstacle.contains(point.x,point.z)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Building building = BuildingManager.getBuildingAtLocation(point);
|
||||
//if(building != null) {
|
||||
//for (Path2D.Float mesh : building.meshes) {
|
||||
//if (mesh.contains(point.x,point.z)) {
|
||||
//return true;
|
||||
//}
|
||||
//}
|
||||
//for (Regions region : building.getBounds().getRegions()) {
|
||||
//if (region.isPointInPolygon(point))
|
||||
//if (Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height
|
||||
//return true;
|
||||
//}
|
||||
//}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user