Browse Source

shape

hull4
FatBoy-DOTC 1 year ago
parent
commit
f94648c5dd
  1. 7
      src/engine/devcmd/cmds/aiInfoCmd.java
  2. 69
      src/engine/gameManager/NavigationManager.java
  3. 31
      src/engine/mobileAI/MobAI.java
  4. 5
      src/engine/objects/AbstractCharacter.java

7
src/engine/devcmd/cmds/aiInfoCmd.java

@ -13,6 +13,7 @@ import engine.Enum; @@ -13,6 +13,7 @@ import engine.Enum;
import engine.Enum.GameObjectType;
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.PowersManager;
import engine.math.Vector3fImmutable;
import engine.mobileAI.MobAI;
import engine.objects.AbstractGameObject;
import engine.objects.Mob;
@ -151,7 +152,11 @@ public class aiInfoCmd extends AbstractDevCmd { @@ -151,7 +152,11 @@ public class aiInfoCmd extends AbstractDevCmd {
output += outlawUUID + 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);
}

69
src/engine/gameManager/NavigationManager.java

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
package engine.gameManager;
import engine.Enum;
import engine.math.Vector3fImmutable;
import engine.net.client.msg.MoveToPointMsg;
import engine.objects.*;
import java.awt.*;
import java.awt.geom.Path2D;
import java.util.ArrayList;
@ -13,18 +13,35 @@ public class NavigationManager { @@ -13,18 +13,35 @@ public class NavigationManager {
private static final int cellGap = 1;
private static final int stepHeight = 2;
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal) {
try {
ArrayList<Vector3fImmutable> path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc));
if (path.isEmpty() || path.size() < 2) {
character.destination = goal;
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);
}
return; //no points to walk to
}
//character.destination = path.get(1);
character.navPath = path;
} catch(Exception e){
} catch (Exception e) {
//something failed
}
}
@ -32,19 +49,16 @@ public class NavigationManager { @@ -32,19 +49,16 @@ public class NavigationManager {
public static ArrayList<Vector3fImmutable> getOptimizedPath(ArrayList<Vector3fImmutable> startToGoal, ArrayList<Vector3fImmutable> goalToStart) {
ArrayList<Vector3fImmutable> optimalPath = new ArrayList<>();
optimalPath.add(startToGoal.get(0));
for(Vector3fImmutable point : startToGoal)
{
if(!goalToStart.contains(point))
{
continue;
for (Vector3fImmutable point : startToGoal) {
if (goalToStart.contains(point) && !optimalPath.contains(point)) {
optimalPath.add(point);
}
optimalPath.add(point);
}
//optimize the path to its smallest possible amount of points
return optimalPath;
}
@ -54,8 +68,7 @@ public class NavigationManager { @@ -54,8 +68,7 @@ public class NavigationManager {
Vector3fImmutable current = start;
boolean obstructed = false;
int count = 0;
while (current.distanceSquared(goal) > 9 && count < 250)
{
while (current.distanceSquared(goal) > 9 && count < 250) {
//gather the 8 cells around the player
ArrayList<Vector3fImmutable> surroundingCells = new ArrayList<>();
surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, 0)));
@ -67,8 +80,7 @@ public class NavigationManager { @@ -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)));
Vector3fImmutable cheapest = new Vector3fImmutable(Vector3fImmutable.ZERO);
for (Vector3fImmutable point : surroundingCells)
{
for (Vector3fImmutable point : surroundingCells) {
count++;
if (path.contains(point))
@ -85,16 +97,21 @@ public class NavigationManager { @@ -85,16 +97,21 @@ public class NavigationManager {
current = cheapest;
path.add(cheapest);
}
if(obstructed) {
if (obstructed) {
return path;
}else {
} else {
ArrayList<Vector3fImmutable> goalPath = new ArrayList<>();
goalPath.add(start);
goalPath.add(start.moveTowards(goal,32));
goalPath.add(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) {
float gCost = start.distanceSquared(point);
float hCost = goal.distanceSquared(point);
@ -105,18 +122,16 @@ public class NavigationManager { @@ -105,18 +122,16 @@ public class NavigationManager {
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;
}
boolean pointBlocked = false;
for (Path2D.Float mesh : building.meshes) {
if (mesh.contains((double)point.x,(double)point.z)) {
pointBlocked = true;
}
return pointBlocked;
}
}
return false;
}

31
src/engine/mobileAI/MobAI.java

@ -914,7 +914,7 @@ public class MobAI { @@ -914,7 +914,7 @@ public class MobAI {
switch (mob.getCombatTarget().getObjectType()) {
case PlayerCharacter:
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);
break;
case Building:
@ -1345,18 +1345,16 @@ public class MobAI { @@ -1345,18 +1345,16 @@ public class MobAI {
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);
return;
}
if(mob.navPath.get(mob.navPath.size() -1).distanceSquared(mob.destination) > 100){ // goal has moved by at least 10 units, recalculate
NavigationManager.pathfind(mob,mob.destination);
if(mob.isMoving()) {
return;
}
if(mob.isMoving())
return;
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);
return;
}
@ -1372,7 +1370,7 @@ public class MobAI { @@ -1372,7 +1370,7 @@ public class MobAI {
if(offset > 0){
PathPoint= Vector3fImmutable.getRandomPointInCircle(PathPoint, offset);
}
mob.endLoc = PathPoint;
MoveToPointMsg msg = new MoveToPointMsg();
@ -1380,10 +1378,19 @@ public class MobAI { @@ -1380,10 +1378,19 @@ public class MobAI {
msg.setSourceID(mob.getObjectUUID());
msg.setStartCoord(mob.loc);
msg.setEndCoord(PathPoint);
msg.setInBuildingFloor(-1);
msg.setInBuilding(-1);
msg.setStartLocType(0);
msg.setInBuildingUUID(0);
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.setInBuilding(-1);
msg.setStartLocType(0);
msg.setInBuildingUUID(0);
}
try {

5
src/engine/objects/AbstractCharacter.java

@ -841,11 +841,6 @@ public abstract class AbstractCharacter extends AbstractWorldObject { @@ -841,11 +841,6 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
if(this.getObjectType().equals(GameObjectType.Mob)){
if(this.destination.equals(Vector3fImmutable.ZERO))
return false;
if(this.loc.distanceSquared(this.destination) < 3){
this.stopMovement(this.loc);
return false;
}
}
return true;
}

Loading…
Cancel
Save