BodyMotionFindBase.java
package com.hypixel.hytale.server.npc.corecomponents.movement;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.math.random.RandomExtra;
import com.hypixel.hytale.math.util.MathUtil;
import com.hypixel.hytale.math.util.TrigMathUtil;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.server.npc.NPCPlugin;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.corecomponents.BodyMotionBase;
import com.hypixel.hytale.server.npc.corecomponents.movement.builders.BuilderBodyMotionFindBase;
import com.hypixel.hytale.server.npc.movement.NavState;
import com.hypixel.hytale.server.npc.movement.Steering;
import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
import com.hypixel.hytale.server.npc.movement.controllers.ProbeMoveData;
import com.hypixel.hytale.server.npc.movement.steeringforces.SteeringForceWithTarget;
import com.hypixel.hytale.server.npc.navigation.AStarBase;
import com.hypixel.hytale.server.npc.navigation.AStarDebugBase;
import com.hypixel.hytale.server.npc.navigation.AStarEvaluator;
import com.hypixel.hytale.server.npc.navigation.AStarNode;
import com.hypixel.hytale.server.npc.navigation.AStarNodePoolProvider;
com.hypixel.hytale.server.npc.navigation.AStarNodePoolProviderSimple;
com.hypixel.hytale.server.npc.navigation.PathFollower;
com.hypixel.hytale.server.npc.role.Role;
com.hypixel.hytale.server.npc.role.RoleDebugFlags;
com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
java.util.EnumSet;
java.util.function.Supplier;
java.util.logging.Level;
javax.annotation.Nonnull;
javax.annotation.Nullable;
<T > {
nodesPerTick;
useBestPath;
throttleDelayMin;
throttleDelayMax;
throttleIgnoreCount;
useSteering;
usePathfinder;
skipSteering;
minPathLength;
minPathLengthSquared;
canSkipSteering;
isAvoidingBlockDamage;
isRelaxedMoveConstraints;
desiredAltitudeWeight;
dbgStatus;
dbgProfile;
dbgMaps;
dbgOpens;
dbgPath;
dbgRebuild;
dbgNodes;
dbgStay;
dbgMotionState;
T aStar;
AStarDebugBase aStarDebug;
();
();
AStarNodePoolProvider sharedNodePoolProvider;
throttleCount;
throttleTime;
targetDeltaSquared;
wasSteering;
throttleDelay;
passedWaypoint;
wasAvoidingBlockDamage;
dbgDisplayString;
StringBuilder debugString;
{
(builderBodyMotionFindBase);
.aStar = aStar;
.aStarDebug = aStar.createDebugHelper(HytaleLogger.forEnclosingClass());
.useBestPath = builderBodyMotionFindBase.getUseBestPath(support);
.nodesPerTick = builderBodyMotionFindBase.getNodesPerTick(support);
.usePathfinder = builderBodyMotionFindBase.isUsePathfinder(support);
.useSteering = builderBodyMotionFindBase.isUseSteering(support);
.skipSteering = builderBodyMotionFindBase.isSkipSteering(support);
.canSkipSteering = .skipSteering || .usePathfinder;
.minPathLength = builderBodyMotionFindBase.getMinPathLength(support);
.minPathLengthSquared = .minPathLength * .minPathLength;
[] throttleDelayRange = builderBodyMotionFindBase.getThrottleDelayRange(support);
.throttleDelayMin = throttleDelayRange[];
.throttleDelayMax = throttleDelayRange[];
.throttleIgnoreCount = builderBodyMotionFindBase.getThrottleIgnoreCount(support);
.isRelaxedMoveConstraints = builderBodyMotionFindBase.isRelaxedMoveConstraints(support);
.isAvoidingBlockDamage = builderBodyMotionFindBase.isAvoidingBlockDamage(support);
.desiredAltitudeWeight = builderBodyMotionFindBase.getDesiredAltitudeWeight(support);
.probeMoveData.setRelaxedMoveConstraints(.isRelaxedMoveConstraints);
.pathFollower.setPathSmoothing(builderBodyMotionFindBase.getPathSmoothing(support));
.pathFollower.setRelativeSpeed(builderBodyMotionFindBase.getRelativeSpeed(support));
.pathFollower.setRelativeSpeedWaypoint(builderBodyMotionFindBase.getRelativeSpeedWaypoint(support));
.pathFollower.setWaypointRadius(builderBodyMotionFindBase.getWaypointRadius(support));
.pathFollower.setRejectionWeight(builderBodyMotionFindBase.getRejectionWeight(support));
.pathFollower.setBlendHeading(builderBodyMotionFindBase.getBlendHeading(support));
.aStar.setMaxPathLength(builderBodyMotionFindBase.getMaxPathLength(support));
.aStar.setOpenNodesLimit(builderBodyMotionFindBase.getMaxOpenNodes(support));
.aStar.setTotalNodesLimit(builderBodyMotionFindBase.getMaxTotalNodes(support));
.aStar.setCanMoveDiagonal(builderBodyMotionFindBase.isDiagonalMoves(support));
.aStar.setOptimizedBuildPath(builderBodyMotionFindBase.isBuildOptimisedPath(support));
EnumSet<DebugFlags> debugFlags = builderBodyMotionFindBase.getParsedDebugFlags();
.dbgRebuild = debugFlags.contains(BodyMotionFindBase.DebugFlags.Rebuild);
.dbgNodes = debugFlags.contains(BodyMotionFindBase.DebugFlags.Nodes);
.dbgProfile = debugFlags.contains(BodyMotionFindBase.DebugFlags.Profile);
.dbgPath = debugFlags.contains(BodyMotionFindBase.DebugFlags.Path);
.dbgOpens = debugFlags.contains(BodyMotionFindBase.DebugFlags.Opens);
.dbgMaps = debugFlags.contains(BodyMotionFindBase.DebugFlags.Maps);
.dbgStatus = debugFlags.contains(BodyMotionFindBase.DebugFlags.Status);
.dbgStay = debugFlags.contains(BodyMotionFindBase.DebugFlags.Stay);
.dbgMotionState = debugFlags.contains(BodyMotionFindBase.DebugFlags.Motion);
.dbgDisplayString = ;
.pathFollower.setDebugNodes(.dbgNodes);
}
{
(TransformComponent)componentAccessor.getComponent(ref, TransformComponent.getComponentType());
transformComponent != ;
role.getActiveMotionController();
.sharedNodePoolProvider = (AStarNodePoolProvider)componentAccessor.getResource(AStarNodePoolProviderSimple.getResourceType());
.dbgDisplayString = role.getDebugSupport().getDebugFlags().contains(RoleDebugFlags.Pathfinder);
.setNavStateInit(activeMotionController);
.wasSteering = ;
.wasAvoidingBlockDamage = .isAvoidingBlockDamage && activeMotionController.isAvoidingBlockDamage();
.aStar.setStartPosition(transformComponent.getPosition());
}
{
.pathFollower.clearPath();
.aStar.clearPath();
}
{
desiredSteering.clear();
role.getActiveMotionController();
(TransformComponent)componentAccessor.getComponent(ref, TransformComponent.getComponentType());
transformComponent != ;
transformComponent.getPosition();
(!.canComputeMotion(ref, role, infoProvider, componentAccessor)) {
.setNavStateAborted(activeMotionController);
.wasSteering = ;
;
} {
(!.isAvoidingBlockDamage) {
activeMotionController.setAvoidingBlockDamage();
}
activeMotionController.setRelaxedMoveConstraints(.isRelaxedMoveConstraints);
.probeMoveData.setAvoidingBlockDamage(activeMotionController.isAvoidingBlockDamage());
(.isGoalReached(ref, activeMotionController, position, componentAccessor)) {
.setNavStateAtGoal(role.getActiveMotionController());
.wasSteering = ;
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
;
} {
(.throttleCount > .throttleIgnoreCount) {
.throttleTime += dt;
}
.throttleDelay -= dt;
(.throttleDelay > ) {
.wasSteering = ;
(!.mustAbortThrottling(activeMotionController, ref)) {
.onThrottling(activeMotionController, ref, desiredSteering, componentAccessor);
.setNavStateThrottling(activeMotionController);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
;
}
.resetThrottleCount();
}
!activeMotionController.isObstructed();
(.passedWaypoint && .pathFollower.getCurrentWaypoint() != && .useSteering && unobstructed) {
(.canSwitchToSteering(ref, activeMotionController, componentAccessor)) {
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
.forceRecomputePath(activeMotionController);
.wasSteering = ;
}
.passedWaypoint = ;
}
(.pathFollower.getCurrentWaypoint() == && !.aStar.isComputing() && .useSteering) {
(unobstructed && (.wasSteering || !.canSkipSteering || !.shouldSkipSteering(ref, activeMotionController, position, componentAccessor)) && .computeSteering(ref, role, position, desiredSteering, componentAccessor)) {
.setNavStateSteering(role.getActiveMotionController());
.onSteering(activeMotionController, ref, componentAccessor);
.wasSteering = ;
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
;
}
(!.usePathfinder) {
.setNavStateBlocked(role.getActiveMotionController());
.wasSteering = ;
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
;
}
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
.forceRecomputePath(activeMotionController);
}
.wasSteering = ;
.mustRecomputePath(activeMotionController);
activeMotionController.isForceRecomputePath();
(mustRecomputePath || forceRecomputePath) {
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log(, mustRecomputePath, forceRecomputePath);
}
.forceRecomputePath(activeMotionController);
}
(.pathFollower.getCurrentWaypoint() != ) {
.updatePathFollower(ref, position, activeMotionController, componentAccessor);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
}
(.pathFollower.pathInFinalStage() && activeMotionController.canAct(ref, componentAccessor)) {
(.pathFollower.getCurrentWaypoint() == ) {
(.aStar.getPath() != ) {
.setPath(ref, position, activeMotionController, componentAccessor);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
} (!.aStar.isComputing()) {
(unobstructed && (!.canSkipSteering || !.shouldSkipSteering(ref, activeMotionController, position, componentAccessor))) {
.setNavStateSteering(activeMotionController);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
;
}
(.shouldDeferPathComputation(activeMotionController, position, componentAccessor)) {
.onDeferring(activeMotionController, ref, desiredSteering, componentAccessor);
.setNavStateDeferred(activeMotionController);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
;
}
(!.startPathFinder(ref, position, role, activeMotionController, componentAccessor)) {
.onNoPathFound(activeMotionController);
.setNavStateAborted(activeMotionController);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
;
}
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
}
} (.pathFollower.isWaypointFrozen()) {
.aStar.clearPath();
.pathFollower.getCurrentWaypointPosition();
(targetPosition.distanceSquaredTo(position) < ) {
.pathFollower.setWaypointFrozen();
(.canSkipSteering && .shouldSkipSteering(ref, activeMotionController, targetPosition, componentAccessor)) {
.startPathFinder(ref, position, role, activeMotionController, componentAccessor);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
} (.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
}
}
}
(.aStar.isComputing() && .continuePathFinder(ref, activeMotionController, componentAccessor)) {
(.pathFollower.getCurrentWaypoint() == ) {
.setNavStateComputing(activeMotionController);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
;
}
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
}
(.pathFollower.getCurrentWaypoint() == ) {
(.aStar.getPath() == ) {
.setNavStateThrottling(activeMotionController);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
;
}
.setPath(ref, position, activeMotionController, componentAccessor);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
}
(activeMotionController.canAct(ref, componentAccessor) && !.dbgStay) {
.pathFollower.executePath(position, activeMotionController, desiredSteering);
(.dbgMotionState) {
((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.INFO).every()).log();
}
}
.setNavStateFollowing(activeMotionController);
;
}
}
}
;
{
(.dbgProfile) {
System.nanoTime();
AStarBase. .startComputePath(ref, role, activeMotionController, position, componentAccessor);
(progress == AStarBase.Progress.COMPUTING) {
progress = .aStar.computePath(ref, activeMotionController, .probeMoveData, , componentAccessor);
}
time = System.nanoTime() - time;
NPCPlugin.get().getLogger().at(Level.INFO).log(, progress.toString(), time / );
(progress != AStarBase.Progress.ACCOMPLISHED) {
;
}
(.dbgPath) {
.aStarDebug.dumpPath();
.aStarDebug.dumpMap(, activeMotionController);
}
} {
AStarBase. .startComputePath(ref, role, activeMotionController, position, componentAccessor);
(progress != AStarBase.Progress.COMPUTING) {
(.dbgStatus) {
NPCPlugin.get().getLogger().at(Level.INFO).log(, progress.toString());
}
;
}
}
;
}
{
AStarBase. .aStar.computePath(ref, activeMotionController, .probeMoveData, .nodesPerTick, componentAccessor);
(progress == AStarBase.Progress.COMPUTING) {
.setNavStateComputing(activeMotionController);
(.dbgOpens) {
.aStarDebug.dumpOpens(activeMotionController);
}
(.dbgMaps) {
.aStarDebug.dumpMap(, activeMotionController);
}
;
} {
(progress == AStarBase.Progress.ACCOMPLISHED) {
.resetThrottleCount();
} (.useBestPath) {
.findBestPath(.aStar, activeMotionController);
++.throttleCount;
(.aStar.getPath() != ) {
progress = AStarBase.Progress.ACCOMPLISHED;
}
}
(progress != AStarBase.Progress.ACCOMPLISHED) {
(.dbgStatus) {
NPCPlugin.get().getLogger().at(Level.INFO).log(, progress.toString());
}
.aStar.clearPath();
.onNoPathFound(activeMotionController);
;
} {
.aStar.getEndPosition().distanceSquaredTo(.aStar.getPosition());
(pathLengthSquared < .minPathLengthSquared) {
(.dbgStatus) {
NPCPlugin.get().getLogger().at(Level.INFO).log(, Math.sqrt(pathLengthSquared));
}
.aStar.clearPath();
.onNoPathFound(activeMotionController);
;
} {
(.dbgPath) {
.aStarDebug.dumpPath();
}
(.dbgPath || .dbgMaps) {
.aStarDebug.dumpMap(, activeMotionController);
}
;
}
}
}
}
{
(!.pathFollower.updateCurrentTarget(position, activeMotionController)) {
;
} {
(.pathFollower.shouldSmoothPath()) {
.passedWaypoint = ;
.pathFollower.smoothPath(ref, position, activeMotionController, .probeMoveData, componentAccessor);
}
;
}
}
{
;
}
{
!.useSteering;
}
{
;
}
{
role.getActiveMotionController();
!motionController.is2D() && desiredAltitudeWeight > ;
approachDesiredHeight && motionController.getDesiredVerticalRange(ref, componentAccessor).isWithinRange();
(withinRange) {
steeringForce.setComponentSelector(role.getActiveMotionController().getPlanarComponentSelector());
} {
steeringForce.setComponentSelector(role.getActiveMotionController().getComponentSelector());
}
(!steeringForce.compute(desiredSteering)) {
;
} {
desiredSteering.scaleTranslation(.getRelativeSpeed());
(approachDesiredHeight && !withinRange) {
MotionController. motionController.getDesiredVerticalRange(ref, componentAccessor);
(desiredAltitudeRange.current > desiredAltitudeRange.max) {
desiredSteering.setY(-.computeDesiredYTranslation(desiredSteering, motionController.getMaxSinkAngle(), desiredAltitudeWeight));
} (desiredAltitudeRange.current < desiredAltitudeRange.min) {
desiredSteering.setY(.computeDesiredYTranslation(desiredSteering, motionController.getMaxClimbAngle(), desiredAltitudeWeight));
}
}
motionController.requireDepthProbing();
;
}
}
{
desiredSteering.getX();
desiredSteering.getZ();
Math.sqrt(dirX * dirX + dirZ * dirZ);
length * ()TrigMathUtil.sin(()maxAngle * desiredAltitudeWeight);
}
{
.aStar.clearPath();
}
{
}
{
}
{
}
{
}
{
;
}
;
{
(reset) {
.resetThrottleCount();
.targetDeltaSquared = ;
.forceRecomputePath(activeMotionController);
}
activeMotionController.setNavState(state, .throttleTime, .targetDeltaSquared);
(.dbgDisplayString) {
(.debugString == ) {
.debugString = ();
}
.debugString.append(label).append().append(.throttleCount).append().append(()MathUtil.floor(.throttleTime * ) / );
.decorateDebugString(.debugString);
activeMotionController.getRole().getDebugSupport().setDisplayPathfinderString(.debugString.toString());
.debugString.setLength();
}
}
{
}
{
.setNavState(NavState.INIT, , , motionController);
}
{
.setNavState(NavState.PROGRESSING, , , motionController);
}
{
.setNavState(NavState.DEFER, , , motionController);
}
{
.setNavState(NavState.AT_GOAL, , , motionController);
}
{
.setNavState(NavState.PROGRESSING, , , motionController);
}
{
.setNavState(NavState.PROGRESSING, , , motionController);
}
{
.setNavState(NavState.BLOCKED, , , motionController);
}
{
.setNavState(NavState.ABORTED, , , motionController);
}
{
(.throttleDelay <= && .throttleDelayMax > && .throttleCount > .throttleIgnoreCount) {
.throttleDelay = RandomExtra.randomRange(.throttleDelayMin, .throttleDelayMax);
}
.setNavState(NavState.PROGRESSING, , , motionController);
}
{
.aStar.getPath();
.pathFollower.setPath(aStarPath, position);
.passedWaypoint = ;
.updatePathFollower(ref, position, activeMotionController, componentAccessor);
}
{
.throttleTime = ;
.throttleCount = ;
.throttleDelay = ;
}
AStarBase.Progress {
.aStar.initComputePath(ref, position, , activeMotionController, .probeMoveData, .sharedNodePoolProvider, componentAccessor);
}
{
;
}
{
;
}
{
(.dbgRebuild) {
;
} (activeMotionController.isObstructed()) {
(.dbgStatus) {
NPCPlugin.get().getLogger().at(Level.INFO).log();
}
.onBlockedPath();
;
} {
activeMotionController.isAvoidingBlockDamage();
(.wasAvoidingBlockDamage != avoidingBlockDamage) {
.wasAvoidingBlockDamage = avoidingBlockDamage;
(.dbgStatus) {
NPCPlugin.get().getLogger().at(Level.INFO).log();
}
;
} {
;
}
}
}
{
.pathFollower.getRelativeSpeed();
}
{
.aStar.clearPath();
.pathFollower.clearPath();
}
<String> {
Opens(),
Maps(),
Path(),
Status(),
Rebuild(),
Profile(),
Nodes(),
Motion(),
Stay();
String description;
{
.description = description;
}
String {
.description;
}
}
}