Browse Source

region work

hull4
FatBoy-DOTC 1 year ago
parent
commit
7e54426c95
  1. 50
      src/engine/mobileAI/utilities/MovementUtilities.java

50
src/engine/mobileAI/utilities/MovementUtilities.java

@ -13,6 +13,7 @@ import engine.Enum;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
import engine.Enum.ModType; import engine.Enum.ModType;
import engine.Enum.SourceType; import engine.Enum.SourceType;
import engine.InterestManagement.Terrain;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.MovementManager; import engine.gameManager.MovementManager;
@ -32,7 +33,7 @@ import static engine.math.FastMath.sqrt;
public class MovementUtilities { public class MovementUtilities {
private static final int cellGap = 1; private static final int cellGap = 1;
private static final int stepHeight = 2; private static final int stepHeight = 3;
public static boolean inRangeOfBindLocation(Mob agent) { public static boolean inRangeOfBindLocation(Mob agent) {
@ -227,26 +228,26 @@ public class MovementUtilities {
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){ public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){
try { try {
if(character.region == null && Regions.getRegionAtLocation(goal) != null) {//mover not inside a building //if(character.region == null && Regions.getRegionAtLocation(goal) != null) {//mover not inside a building
Building building = BuildingManager.getBuildingAtLocation(goal); // Building building = BuildingManager.getBuildingAtLocation(goal);
ArrayList<Regions> entrances = new ArrayList<>(); // ArrayList<Regions> entrances = new ArrayList<>();
for (Regions region : building.getBounds().getRegions()) { //for (Regions region : building.getBounds().getRegions()) {
if (region.exit && region.level == 0) // if (region.exit && region.level == 0)
entrances.add(region); // entrances.add(region);
} //}
Regions cheapest = null; // Regions cheapest = null;
for(Regions entrance : entrances){ // for(Regions entrance : entrances){
if(cheapest == null) { // if(cheapest == null) {
cheapest = entrance; // cheapest = entrance;
continue; // continue;
} // }
if(getCost(new Vector3fImmutable(entrance.center),character.loc,goal) < getCost(new Vector3fImmutable(cheapest.center),character.loc,goal)) // if(getCost(new Vector3fImmutable(entrance.center),character.loc,goal) < getCost(new Vector3fImmutable(cheapest.center),character.loc,goal))
cheapest = entrance; // cheapest = entrance;
} // }
//
goal = new Vector3fImmutable(cheapest.center.x, cheapest.center.y, cheapest.center.z); // goal = new Vector3fImmutable(cheapest.center.x, cheapest.center.y, cheapest.center.z);
} //}
ArrayList<Vector3fImmutable> path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc)); ArrayList<Vector3fImmutable> path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc));
if (path.isEmpty()) { if (path.isEmpty()) {
@ -305,10 +306,17 @@ public class MovementUtilities {
obstructed = true; obstructed = true;
continue; continue;
} }
Building building = BuildingManager.getBuildingAtLocation(point);
Regions region = null;
if(building != null)
for(Regions reg : building.getBounds().getRegions())
if(reg.isPointInPolygon(point))
region = reg;
Regions region = Regions.getRegionAtLocation(point);
if(region != null) if(region != null)
point = new Vector3fImmutable(point.x,region.lerpY(point),point.z); // adjust the Y value of the point to the region height it is in point = new Vector3fImmutable(point.x,region.lerpY(point),point.z); // adjust the Y value of the point to the region height it is in
else
point = new Vector3fImmutable(point.x, Terrain.getWorldHeight(point),point.z);
if (getCost(cheapest, current, goal) > getCost(point, current, goal)) if (getCost(cheapest, current, goal) > getCost(point, current, goal))
cheapest = point; cheapest = point;

Loading…
Cancel
Save