shape
This commit is contained in:
@@ -13,6 +13,7 @@ import engine.Enum;
|
|||||||
import engine.Enum.GameObjectType;
|
import engine.Enum.GameObjectType;
|
||||||
import engine.devcmd.AbstractDevCmd;
|
import engine.devcmd.AbstractDevCmd;
|
||||||
import engine.gameManager.PowersManager;
|
import engine.gameManager.PowersManager;
|
||||||
|
import engine.math.Vector3fImmutable;
|
||||||
import engine.mobileAI.MobAI;
|
import engine.mobileAI.MobAI;
|
||||||
import engine.objects.AbstractGameObject;
|
import engine.objects.AbstractGameObject;
|
||||||
import engine.objects.Mob;
|
import engine.objects.Mob;
|
||||||
@@ -151,7 +152,11 @@ public class aiInfoCmd extends AbstractDevCmd {
|
|||||||
output += outlawUUID + newline;
|
output += outlawUUID + newline;
|
||||||
}
|
}
|
||||||
output += "Walking: " + ((Mob) target).isMoving() + newline;
|
output += "Walking: " + ((Mob) target).isMoving() + newline;
|
||||||
output += "Destination: " + ((Mob) target).destination;
|
output += "Destination: " + ((Mob) target).destination + newline;
|
||||||
|
output += "NavPath: " + newline;
|
||||||
|
for(Vector3fImmutable point : ((Mob) target).navPath){
|
||||||
|
output += "(" + ((Mob) target).navPath.indexOf(point) + ")(" +((Mob) target).loc.distanceSquared2D(point) + ") "+ point + newline;
|
||||||
|
}
|
||||||
|
|
||||||
throwbackInfo(playerCharacter, output);
|
throwbackInfo(playerCharacter, output);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package engine.gameManager;
|
package engine.gameManager;
|
||||||
|
|
||||||
|
import engine.Enum;
|
||||||
import engine.math.Vector3fImmutable;
|
import engine.math.Vector3fImmutable;
|
||||||
|
import engine.net.client.msg.MoveToPointMsg;
|
||||||
import engine.objects.*;
|
import engine.objects.*;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.geom.Path2D;
|
import java.awt.geom.Path2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -15,9 +15,26 @@ public class NavigationManager {
|
|||||||
|
|
||||||
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal) {
|
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal) {
|
||||||
try {
|
try {
|
||||||
ArrayList<Vector3fImmutable> path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc));
|
ArrayList<Vector3fImmutable> path = getPath(character.loc, goal);//getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc));
|
||||||
if (path.isEmpty() || path.size() < 2) {
|
if (path.isEmpty()) {
|
||||||
character.destination = goal;
|
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);
|
||||||
|
}
|
||||||
return; //no points to walk to
|
return; //no points to walk to
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,17 +49,14 @@ public class NavigationManager {
|
|||||||
public static ArrayList<Vector3fImmutable> getOptimizedPath(ArrayList<Vector3fImmutable> startToGoal, ArrayList<Vector3fImmutable> goalToStart) {
|
public static ArrayList<Vector3fImmutable> getOptimizedPath(ArrayList<Vector3fImmutable> startToGoal, ArrayList<Vector3fImmutable> goalToStart) {
|
||||||
ArrayList<Vector3fImmutable> optimalPath = new ArrayList<>();
|
ArrayList<Vector3fImmutable> optimalPath = new ArrayList<>();
|
||||||
optimalPath.add(startToGoal.get(0));
|
optimalPath.add(startToGoal.get(0));
|
||||||
for(Vector3fImmutable point : startToGoal)
|
for (Vector3fImmutable point : startToGoal) {
|
||||||
{
|
if (goalToStart.contains(point) && !optimalPath.contains(point)) {
|
||||||
if(!goalToStart.contains(point))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
optimalPath.add(point);
|
optimalPath.add(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
//optimize the path to its smallest possible amount of points
|
}
|
||||||
|
|
||||||
|
//optimize the path to its smallest possible amount of points
|
||||||
|
|
||||||
|
|
||||||
return optimalPath;
|
return optimalPath;
|
||||||
@@ -54,8 +68,7 @@ public class NavigationManager {
|
|||||||
Vector3fImmutable current = start;
|
Vector3fImmutable current = start;
|
||||||
boolean obstructed = false;
|
boolean obstructed = false;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (current.distanceSquared(goal) > 9 && count < 250)
|
while (current.distanceSquared(goal) > 9 && count < 250) {
|
||||||
{
|
|
||||||
//gather the 8 cells around the player
|
//gather the 8 cells around the player
|
||||||
ArrayList<Vector3fImmutable> surroundingCells = new ArrayList<>();
|
ArrayList<Vector3fImmutable> surroundingCells = new ArrayList<>();
|
||||||
surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, 0)));
|
surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, 0)));
|
||||||
@@ -67,8 +80,7 @@ public class NavigationManager {
|
|||||||
surroundingCells.add(current.add(new Vector3fImmutable(-cellGap, 0, cellGap)));
|
surroundingCells.add(current.add(new Vector3fImmutable(-cellGap, 0, cellGap)));
|
||||||
surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, -cellGap)));
|
surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, -cellGap)));
|
||||||
Vector3fImmutable cheapest = new Vector3fImmutable(Vector3fImmutable.ZERO);
|
Vector3fImmutable cheapest = new Vector3fImmutable(Vector3fImmutable.ZERO);
|
||||||
for (Vector3fImmutable point : surroundingCells)
|
for (Vector3fImmutable point : surroundingCells) {
|
||||||
{
|
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
if (path.contains(point))
|
if (path.contains(point))
|
||||||
@@ -90,11 +102,16 @@ public class NavigationManager {
|
|||||||
} else {
|
} else {
|
||||||
ArrayList<Vector3fImmutable> goalPath = new ArrayList<>();
|
ArrayList<Vector3fImmutable> goalPath = new ArrayList<>();
|
||||||
goalPath.add(start);
|
goalPath.add(start);
|
||||||
|
goalPath.add(start.moveTowards(goal,32));
|
||||||
goalPath.add(goal);
|
goalPath.add(goal);
|
||||||
return goalPath; //if the path isn't obstructed we can walk directly from start to the goal
|
return goalPath; //if the path isn't obstructed we can walk directly from start to the goal
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static float getCost(Vector3fImmutable point, Vector3fImmutable start, Vector3fImmutable goal) {
|
public static float getCost(Vector3fImmutable point, Vector3fImmutable start, Vector3fImmutable goal) {
|
||||||
float gCost = start.distanceSquared(point);
|
float gCost = start.distanceSquared(point);
|
||||||
float hCost = goal.distanceSquared(point);
|
float hCost = goal.distanceSquared(point);
|
||||||
@@ -105,18 +122,16 @@ public class NavigationManager {
|
|||||||
|
|
||||||
Building building = BuildingManager.getBuildingAtLocation(point);
|
Building building = BuildingManager.getBuildingAtLocation(point);
|
||||||
if(building != null) {
|
if(building != null) {
|
||||||
|
for (Path2D.Float mesh : building.meshes) {
|
||||||
|
if (mesh.contains(point.x,point.z)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (Regions region : building.getBounds().getRegions()) {
|
for (Regions region : building.getBounds().getRegions()) {
|
||||||
if (region.isPointInPolygon(point))
|
if (region.isPointInPolygon(point))
|
||||||
if (Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height
|
if (Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
boolean pointBlocked = false;
|
|
||||||
for (Path2D.Float mesh : building.meshes) {
|
|
||||||
if (mesh.contains((double)point.x,(double)point.z)) {
|
|
||||||
pointBlocked = true;
|
|
||||||
}
|
|
||||||
return pointBlocked;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -914,7 +914,7 @@ public class MobAI {
|
|||||||
switch (mob.getCombatTarget().getObjectType()) {
|
switch (mob.getCombatTarget().getObjectType()) {
|
||||||
case PlayerCharacter:
|
case PlayerCharacter:
|
||||||
case Mob:
|
case Mob:
|
||||||
mob.destination = GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget());
|
mob.destination = mob.combatTarget.loc;//GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget());
|
||||||
aiMove(mob, false,mob.getRange() + 1);
|
aiMove(mob, false,mob.getRange() + 1);
|
||||||
break;
|
break;
|
||||||
case Building:
|
case Building:
|
||||||
@@ -1345,18 +1345,16 @@ public class MobAI {
|
|||||||
|
|
||||||
public static void aiMove(Mob mob, boolean isWalking, float offset) {
|
public static void aiMove(Mob mob, boolean isWalking, float offset) {
|
||||||
|
|
||||||
if(mob.navPath.size() < 1){
|
if(mob.navPath.isEmpty() || mob.navPath.size() == 1){
|
||||||
NavigationManager.pathfind(mob,mob.destination);
|
NavigationManager.pathfind(mob,mob.destination);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(mob.navPath.get(mob.navPath.size() -1).distanceSquared(mob.destination) > 100){ // goal has moved by at least 10 units, recalculate
|
if(mob.isMoving()) {
|
||||||
NavigationManager.pathfind(mob,mob.destination);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(mob.isMoving())
|
|
||||||
return;
|
|
||||||
Vector3fImmutable PathPoint = mob.navPath.get(0);
|
Vector3fImmutable PathPoint = mob.navPath.get(0);
|
||||||
if(mob.loc.distanceSquared(mob.navPath.get(0)) < 25) {
|
if(mob.loc.distanceSquared(mob.destination) > mob.loc.distanceSquared2D(mob.destination)) {
|
||||||
mob.navPath.remove(0);
|
mob.navPath.remove(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1372,7 +1370,7 @@ public class MobAI {
|
|||||||
if(offset > 0){
|
if(offset > 0){
|
||||||
PathPoint= Vector3fImmutable.getRandomPointInCircle(PathPoint, offset);
|
PathPoint= Vector3fImmutable.getRandomPointInCircle(PathPoint, offset);
|
||||||
}
|
}
|
||||||
|
mob.endLoc = PathPoint;
|
||||||
|
|
||||||
MoveToPointMsg msg = new MoveToPointMsg();
|
MoveToPointMsg msg = new MoveToPointMsg();
|
||||||
|
|
||||||
@@ -1380,10 +1378,19 @@ public class MobAI {
|
|||||||
msg.setSourceID(mob.getObjectUUID());
|
msg.setSourceID(mob.getObjectUUID());
|
||||||
msg.setStartCoord(mob.loc);
|
msg.setStartCoord(mob.loc);
|
||||||
msg.setEndCoord(PathPoint);
|
msg.setEndCoord(PathPoint);
|
||||||
|
Regions region = Regions.getRegionAtLocation(PathPoint);
|
||||||
|
if(region != null){
|
||||||
|
msg.setInBuildingFloor(region.room);
|
||||||
|
msg.setInBuilding(region.level);
|
||||||
|
msg.setStartLocType(0);
|
||||||
|
msg.setInBuildingUUID(region.parentBuildingID);
|
||||||
|
} else{
|
||||||
msg.setInBuildingFloor(-1);
|
msg.setInBuildingFloor(-1);
|
||||||
msg.setInBuilding(-1);
|
msg.setInBuilding(-1);
|
||||||
msg.setStartLocType(0);
|
msg.setStartLocType(0);
|
||||||
msg.setInBuildingUUID(0);
|
msg.setInBuildingUUID(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -841,11 +841,6 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
|
|||||||
if(this.getObjectType().equals(GameObjectType.Mob)){
|
if(this.getObjectType().equals(GameObjectType.Mob)){
|
||||||
if(this.destination.equals(Vector3fImmutable.ZERO))
|
if(this.destination.equals(Vector3fImmutable.ZERO))
|
||||||
return false;
|
return false;
|
||||||
if(this.loc.distanceSquared(this.destination) < 3){
|
|
||||||
this.stopMovement(this.loc);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user