region work
This commit is contained in:
@@ -13,6 +13,7 @@ import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.Enum.ModType;
|
||||
import engine.Enum.SourceType;
|
||||
import engine.InterestManagement.Terrain;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.MovementManager;
|
||||
@@ -32,7 +33,7 @@ import static engine.math.FastMath.sqrt;
|
||||
|
||||
public class MovementUtilities {
|
||||
private static final int cellGap = 1;
|
||||
private static final int stepHeight = 2;
|
||||
private static final int stepHeight = 3;
|
||||
|
||||
public static boolean inRangeOfBindLocation(Mob agent) {
|
||||
|
||||
@@ -227,26 +228,26 @@ public class MovementUtilities {
|
||||
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);
|
||||
ArrayList<Regions> entrances = new ArrayList<>();
|
||||
for (Regions region : building.getBounds().getRegions()) {
|
||||
if (region.exit && region.level == 0)
|
||||
entrances.add(region);
|
||||
}
|
||||
Regions cheapest = null;
|
||||
for(Regions entrance : entrances){
|
||||
if(cheapest == null) {
|
||||
cheapest = entrance;
|
||||
continue;
|
||||
}
|
||||
if(getCost(new Vector3fImmutable(entrance.center),character.loc,goal) < getCost(new Vector3fImmutable(cheapest.center),character.loc,goal))
|
||||
cheapest = entrance;
|
||||
}
|
||||
//if(character.region == null && Regions.getRegionAtLocation(goal) != null) {//mover not inside a building
|
||||
// Building building = BuildingManager.getBuildingAtLocation(goal);
|
||||
// ArrayList<Regions> entrances = new ArrayList<>();
|
||||
//for (Regions region : building.getBounds().getRegions()) {
|
||||
// if (region.exit && region.level == 0)
|
||||
// entrances.add(region);
|
||||
//}
|
||||
// Regions cheapest = null;
|
||||
// for(Regions entrance : entrances){
|
||||
// if(cheapest == null) {
|
||||
// cheapest = entrance;
|
||||
// continue;
|
||||
// }
|
||||
// if(getCost(new Vector3fImmutable(entrance.center),character.loc,goal) < getCost(new Vector3fImmutable(cheapest.center),character.loc,goal))
|
||||
// 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));
|
||||
if (path.isEmpty()) {
|
||||
@@ -305,10 +306,17 @@ public class MovementUtilities {
|
||||
obstructed = true;
|
||||
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)
|
||||
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))
|
||||
cheapest = point;
|
||||
|
||||
Reference in New Issue
Block a user