From bf1182dd2caf2d2991f5ce539e2508071296faae Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Thu, 26 Oct 2023 21:12:11 -0500 Subject: [PATCH] avoidance revision --- .../mobileAI/utilities/MovementUtilities.java | 50 ++++++++++++++++--- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/src/engine/mobileAI/utilities/MovementUtilities.java b/src/engine/mobileAI/utilities/MovementUtilities.java index 6ec04955..c8ca5fac 100644 --- a/src/engine/mobileAI/utilities/MovementUtilities.java +++ b/src/engine/mobileAI/utilities/MovementUtilities.java @@ -299,9 +299,17 @@ private static final int cellGap = 4; } public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){ try { + + if(character.region == null && Regions.getRegionAtLocation(goal) != null) {//mover not inside a building + Building building = BuildingManager.getBuildingAtLocation(goal); + for (Regions region : building.getBounds().getRegions()) + if (region.exit && region.level == 0) + goal = new Vector3fImmutable(region.center.x, region.center.y, region.center.z); + } + ArrayList path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc)); if (path.isEmpty()) { - ((Mob) character).setDestination(character.loc); + ((Mob) character).destination = goal; return; //no points to walk to } @@ -344,10 +352,41 @@ private static final int cellGap = 4; surroundingCells.add(current.add(new Vector3fImmutable(0, 0, -cellGap))); surroundingCells.add(current.add(new Vector3fImmutable(-cellGap, 0, cellGap))); surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, -cellGap))); - Vector3fImmutable cheapest = new Vector3fImmutable(-10000, 0, -10000); + Vector3fImmutable cheapest = new Vector3fImmutable(Vector3fImmutable.ZERO); for (Vector3fImmutable point : surroundingCells) { count++; + + Building building = BuildingManager.getBuildingAtLocation(point); + if(building != null){ + float halfX = building.getBounds().getHalfExtents().x; + float halfY = building.getBounds().getHalfExtents().y; + ArrayList corners = new ArrayList<>(); + corners.add(building.loc.add(new Vector3fImmutable(halfX,0,-halfY))); + corners.add(building.loc.add(new Vector3fImmutable(halfX,0,halfY))); + corners.add(building.loc.subtract(new Vector3fImmutable(halfX,0,halfY))); + corners.add(building.loc.add(new Vector3fImmutable(-halfX,0,halfY))); + Vector3fImmutable cheapCorner = Vector3fImmutable.ZERO; + for(Vector3fImmutable corn : corners){ + if(Bounds.collide(building.getBounds(),point,corn)) + continue; + if(getCost(corn,start,goal) < getCost(cheapCorner,start,goal)) + cheapCorner = corn; + } + if(!cheapCorner.equals(Vector3fImmutable.ZERO)) + if (path.contains(cheapCorner)) { + continue; + }else { + path.add(cheapCorner); + current = cheapCorner; + continue; + } + + + if (path.contains(point)) + continue; + } + if (path.contains(point)) continue; @@ -361,6 +400,7 @@ private static final int cellGap = 4; continue; } + if (pointIsBlocked(point)) { obstructed = true; continue; @@ -413,10 +453,4 @@ private static final int cellGap = 4; return (end.x > mb.minX && end.x < mb.maxX && end.z > mb.minZ && end.z < mb.maxZ); } - private static void printToPlayers(Vector3fImmutable loc, String message){ - for(AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(loc, MBServerStatics.CHARACTER_LOAD_RANGE, MBServerStatics.MASK_PLAYER)){ - PlayerCharacter pc = (PlayerCharacter)awo; - ChatManager.chatSystemInfo(pc, message); - } - } }