// Copyright Epic Games, Inc. All Rights Reserved. // Modified version of Recast/Detour's source file // // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages // arising from the use of this software. // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it // freely, subject to the following restrictions: // 1. The origin of this software must not be misrepresented; you must not // claim that you wrote the original software. If you use this software // in a product, an acknowledgment in the product documentation would be // appreciated but is not required. // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. // #ifndef DETOURCROWD_H #define DETOURCROWD_H #include "Containers/Map.h" #include "CoreMinimal.h" #include "Detour/DetourLargeWorldCoordinates.h" #include "Detour/DetourNavMesh.h" #include "Detour/DetourNavMeshQuery.h" #include "DetourCrowd/DetourLocalBoundary.h" #include "DetourCrowd/DetourObstacleAvoidance.h" #include "DetourCrowd/DetourPathCorridor.h" #include "DetourCrowd/DetourPathQueue.h" #include "DetourCrowd/DetourSharedBoundary.h" #include "HAL/Platform.h" #include "Templates/SharedPointer.h" class FString; class dtProximityGrid; /// The maximum number of neighbors that a crowd agent can take into account /// for steering decisions. /// @ingroup crowd static const int DT_CROWDAGENT_MAX_NEIGHBOURS = 6; /// The maximum number of corners a crowd agent will look ahead in the path. /// This value is used for sizing the crowd agent corner buffers. /// Due to the behavior of the crowd manager, the actual number of useful /// corners will be one less than this number. /// @ingroup crowd static const int DT_CROWDAGENT_MAX_CORNERS = 4; /// The maximum number of crowd avoidance configurations supported by the /// crowd manager. /// @ingroup crowd /// @see dtObstacleAvoidanceParams, dtCrowd::setObstacleAvoidanceParams(), dtCrowd::getObstacleAvoidanceParams(), /// dtCrowdAgentParams::obstacleAvoidanceType static const int DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS = 8; /// UE: The maximum number of unique filters used by crowd agents static const int DT_CROWD_MAX_FILTERS = 16; /// Provides neighbor data for agents managed by the crowd. /// @ingroup crowd /// @see dtCrowdAgent::neis, dtCrowd struct dtCrowdNeighbour { int idx; ///< The index of the neighbor in the crowd. dtReal dist; ///< The distance between the current agent and the neighbor. }; /// The type of navigation mesh polygon the agent is currently traversing. /// @ingroup crowd enum CrowdAgentState { DT_CROWDAGENT_STATE_INVALID, ///< The agent is not in a valid state. DT_CROWDAGENT_STATE_WALKING, ///< The agent is traversing a normal navigation mesh polygon. DT_CROWDAGENT_STATE_OFFMESH, ///< The agent is traversing an off-mesh connection. DT_CROWDAGENT_STATE_WAITING, ///< [UE] The agent is waiting for external movement to finish }; /// Configuration parameters for a crowd agent. /// @ingroup crowd struct dtCrowdAgentParams { /// User defined data attached to the agent. void* userData; /// UE: special link filter used by this agent TSharedPtr linkFilter; dtReal radius; ///< Agent radius. [Limit: >= 0] dtReal height; ///< Agent height. [Limit: > 0] dtReal maxAcceleration; ///< Maximum allowed acceleration. [Limit: >= 0] dtReal maxSpeed; ///< Maximum allowed speed. [Limit: >= 0] /// Defines how close a collision element must be before it is considered for steering behaviors. [Limits: > 0] dtReal collisionQueryRange; dtReal pathOptimizationRange; ///< The path visibility optimization range. [Limit: > 0] /// How aggresive the agent manager should be at avoiding collisions with this agent. [Limit: >= 0] dtReal separationWeight; /// [UE] Mutliplier for avoidance velocities dtReal avoidanceQueryMultiplier; /// [UE] Groups flags attached to the agent unsigned int avoidanceGroup; /// [UE] Avoid agents when they group is matching mask unsigned int groupsToAvoid; /// [UE] Don't avoid agents when they group is matching mask unsigned int groupsToIgnore; /// Flags that impact steering behavior. (See: #UpdateFlags) unsigned short updateFlags; /// The index of the avoidance configuration to use for the agent. /// [Limits: 0 <= value <= #DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS] unsigned char obstacleAvoidanceType; /// UE: Id of navigation filter used by this agent /// [Limits: 0 <= value <= #DT_CROWD_MAX_FILTERS] unsigned char filter; }; enum MoveRequestState { DT_CROWDAGENT_TARGET_NONE = 0, DT_CROWDAGENT_TARGET_FAILED, DT_CROWDAGENT_TARGET_VALID, DT_CROWDAGENT_TARGET_REQUESTING, DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE, DT_CROWDAGENT_TARGET_WAITING_FOR_PATH, DT_CROWDAGENT_TARGET_VELOCITY, }; /// Represents an agent managed by a #dtCrowd object. /// @ingroup crowd struct dtCrowdAgent { /// The path corridor the agent is using. dtPathCorridor corridor; /// The local boundary data for the agent. dtLocalBoundary boundary; /// Time since the agent's path corridor was optimized. dtReal topologyOptTime; /// The known neighbors of the agent. dtCrowdNeighbour neis[DT_CROWDAGENT_MAX_NEIGHBOURS]; /// The desired speed. dtReal desiredSpeed; dtReal npos[3]; ///< The current agent position. [(x, y, z)] dtReal disp[3]; dtReal dvel[3]; ///< The desired velocity of the agent. [(x, y, z)] dtReal nvel[3]; dtReal vel[3]; ///< The actual velocity of the agent. [(x, y, z)] /// The agent's configuration parameters. dtCrowdAgentParams params; /// The local path corridor corners for the agent. (Staight path.) [(x, y, z) * #ncorners] dtReal cornerVerts[DT_CROWDAGENT_MAX_CORNERS*3]; /// The reference id of the polygon being entered at the corner. [(polyRef) * #ncorners] dtPolyRef cornerPolys[DT_CROWDAGENT_MAX_CORNERS]; dtReal targetReplanTime; ///