Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

751 lines
24 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef AI_NAVIGATOR_H
  8. #define AI_NAVIGATOR_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "simtimer.h"
  13. #include "ai_component.h"
  14. #include "ai_navgoaltype.h"
  15. #include "ai_navtype.h"
  16. #include "ai_motor.h"
  17. class CAI_BaseNPC;
  18. class CAI_Motor;
  19. class CAI_Route;
  20. class CAI_Path;
  21. class CAI_Pathfinder;
  22. class CAI_LocalNavigator;
  23. struct AI_Waypoint_t;
  24. class CAI_WaypointList;
  25. class CAI_Network;
  26. struct AIMoveTrace_t;
  27. struct AILocalMoveGoal_t;
  28. typedef int AI_TaskFailureCode_t;
  29. //-----------------------------------------------------------------------------
  30. // Debugging tools
  31. //-----------------------------------------------------------------------------
  32. #define DEBUG_AI_NAVIGATION 1
  33. #ifdef DEBUG_AI_NAVIGATION
  34. extern ConVar ai_debug_nav;
  35. #define DbgNav() ai_debug_nav.GetBool()
  36. #define DbgNavMsg( pAI, pszMsg ) \
  37. do \
  38. { \
  39. if (DbgNav()) \
  40. DevMsg( pAI, "[Nav] %s", static_cast<const char *>(pszMsg) ); \
  41. } while (0)
  42. #define DbgNavMsg1( pAI, pszMsg, a ) DbgNavMsg( pAI, CFmtStr(static_cast<const char *>(pszMsg), (a) ) )
  43. #define DbgNavMsg2( pAI, pszMsg, a, b ) DbgNavMsg( pAI, CFmtStr(static_cast<const char *>(pszMsg), (a), (b) ) )
  44. #else
  45. #define DbgNav() false
  46. #define DbgNavMsg( pAI, pszMsg ) ((void)0)
  47. #define DbgNavMsg1( pAI, pszMsg, a ) ((void)0)
  48. #define DbgNavMsg2( pAI, pszMsg, a, b ) ((void)0)
  49. #endif
  50. //-----------------------------------------------------------------------------
  51. // STRUCTURES & ENUMERATIONS
  52. //-----------------------------------------------------------------------------
  53. DECLARE_POINTER_HANDLE( AI_PathNode_t );
  54. //-------------------------------------
  55. // Purpose: Constants used to specify the properties of a requested navigation
  56. // goal.
  57. //-------------------------------------
  58. // Navigator should use the default or previously set tolerance
  59. const float AIN_DEF_TOLERANCE = -1.0;
  60. // Navigator should use the hull size as the tolerance
  61. const float AIN_HULL_TOLERANCE = -2.0;
  62. // Goal does not specify a new activity
  63. const Activity AIN_DEF_ACTIVITY = ACT_INVALID;
  64. // Goal has no target
  65. CBaseEntity * const AIN_NO_TARGET = NULL;
  66. // Goal does not specify a new target, use the existing one, if any
  67. CBaseEntity * const AIN_DEF_TARGET = (AIN_NO_TARGET + 1);
  68. // Goal does not specify a vector location
  69. extern const Vector AIN_NO_DEST;
  70. // Goal does not specify a node location
  71. #define AIN_NO_NODE ((AI_PathNode_t)-1)
  72. //-------------------------------------
  73. enum AI_NavGoalFlags_t
  74. {
  75. // While navigating, try to face the destination point
  76. AIN_YAW_TO_DEST = 0x01,
  77. // If I'm a goal of type GOALTYPE_TARGETENT, update my goal position every time I think
  78. AIN_UPDATE_TARGET_POS = 0x02,
  79. // If navigating on a designer placed path, don't use pathfinder between waypoints, just do it
  80. AIN_NO_PATHCORNER_PATHFINDING = 0x04,
  81. AIN_DEF_FLAGS = 0,
  82. };
  83. //-------------------------------------
  84. enum AI_NavSetGoalFlags_t
  85. {
  86. // Reset the navigator's navigation to the default state
  87. AIN_CLEAR_PREVIOUS_STATE = 0x01,
  88. // Clear out the target entity, while retaining other settings
  89. AIN_CLEAR_TARGET = 0x02,
  90. // If the navigate fails, return navigation to the default state
  91. AIN_DISCARD_IF_FAIL = 0x04,
  92. // Don't signal TaskFail() if the pathfind fails, just return the result
  93. AIN_NO_PATH_TASK_FAIL = 0x08,
  94. };
  95. //-------------------------------------
  96. enum AI_NpcBlockHandling_t
  97. {
  98. AISF_BLOCK,
  99. AISF_AVOID,
  100. AISF_IGNORE,
  101. };
  102. //-------------------------------------
  103. enum AI_NavPathProgress_t
  104. {
  105. AINPP_NO_CHANGE,
  106. AINPP_ADVANCED,
  107. AINPP_COMPLETE,
  108. AINPP_BLOCKED,
  109. };
  110. //-------------------------------------
  111. // Purpose: Describes a navigation request. The various constructors simply
  112. // allow ease of use in the common cases.
  113. //-------------------------------------
  114. struct AI_NavGoal_t
  115. {
  116. // Goal is unspecifed, or not a specific location
  117. AI_NavGoal_t( GoalType_t type = GOALTYPE_INVALID,
  118. Activity activity = AIN_DEF_ACTIVITY,
  119. float tolerance = AIN_DEF_TOLERANCE,
  120. unsigned flags = AIN_DEF_FLAGS,
  121. CBaseEntity * pTarget = AIN_DEF_TARGET);
  122. // Goal is a specific location, and GOALTYPE_LOCATION
  123. AI_NavGoal_t( const Vector &dest,
  124. Activity activity = AIN_DEF_ACTIVITY,
  125. float tolerance = AIN_DEF_TOLERANCE,
  126. unsigned flags = AIN_DEF_FLAGS,
  127. CBaseEntity * pTarget = AIN_DEF_TARGET);
  128. // Goal is a specific location and goal type
  129. AI_NavGoal_t( GoalType_t type,
  130. const Vector &dest,
  131. Activity activity = AIN_DEF_ACTIVITY,
  132. float tolerance = AIN_DEF_TOLERANCE,
  133. unsigned flags = AIN_DEF_FLAGS,
  134. CBaseEntity * pTarget = AIN_DEF_TARGET);
  135. // Goal is a specific node, and GOALTYPE_LOCATION
  136. AI_NavGoal_t( AI_PathNode_t destNode,
  137. Activity activity = AIN_DEF_ACTIVITY,
  138. float tolerance = AIN_DEF_TOLERANCE,
  139. unsigned flags = AIN_DEF_FLAGS,
  140. CBaseEntity * pTarget = AIN_DEF_TARGET);
  141. // Goal is a specific location and goal type
  142. AI_NavGoal_t( GoalType_t type,
  143. AI_PathNode_t destNode,
  144. Activity activity = AIN_DEF_ACTIVITY,
  145. float tolerance = AIN_DEF_TOLERANCE,
  146. unsigned flags = AIN_DEF_FLAGS,
  147. CBaseEntity * pTarget = AIN_DEF_TARGET);
  148. //----------------------------------
  149. // What type of goal is this
  150. GoalType_t type;
  151. // The destination, either as a vector, or as a path node
  152. Vector dest;
  153. AI_PathNode_t destNode;
  154. // The activity to use, or none if a previosly set activity should be used
  155. Activity activity;
  156. // The predicted activity used after arrival
  157. Activity arrivalActivity;
  158. int arrivalSequence;
  159. // The tolerance of success, or none if a previosly set tolerance should be used
  160. float tolerance;
  161. // How far to permit an initial simplification of path
  162. // (will use default if this value is less than the default)
  163. float maxInitialSimplificationDist;
  164. // Optional flags specifying
  165. unsigned flags;
  166. // The target of the navigation, primarily used to ignore the entity in hull and line traces
  167. CBaseEntity * pTarget;
  168. };
  169. //-------------------------------------
  170. // Purpose: Used to describe rules for advance on a (fly) path. There's nothing
  171. // specifically "flying" about it, other than it came from an attempte
  172. // to consolodate duplicated code in the various fliers. It may serve
  173. // a more general purpose in the future. The constructor takes those
  174. // arguments that can usually be specified just once (as in a
  175. // local static constructor)
  176. //-------------------------------------
  177. struct AI_ProgressFlyPathParams_t
  178. {
  179. AI_ProgressFlyPathParams_t( unsigned _collisionMask,
  180. float _strictPointTolerance = 32.0, float _blockTolerance = 0.0,
  181. float _waypointTolerance = 100, float _goalTolerance = 12,
  182. AI_NpcBlockHandling_t _blockHandling = AISF_BLOCK )
  183. : collisionMask( _collisionMask ),
  184. strictPointTolerance( _strictPointTolerance ),
  185. blockTolerance( _blockTolerance ),
  186. waypointTolerance( _waypointTolerance ),
  187. goalTolerance( _goalTolerance ),
  188. blockHandling( _blockHandling ),
  189. pTarget( NULL ),
  190. bTrySimplify( true )
  191. {
  192. }
  193. void SetCurrent( const CBaseEntity *pNewTarget, bool bNewTrySimplify = true )
  194. {
  195. pTarget = pNewTarget;
  196. bTrySimplify = bNewTrySimplify;
  197. }
  198. //----------------------------------
  199. // Fields that tend to stay constant
  200. unsigned collisionMask;
  201. float strictPointTolerance;
  202. float blockTolerance; // @TODO (toml 07-03-02): rename "blockTolerance". This is specifically the "simplify" block tolerance. See SimplifyFlyPath()
  203. float waypointTolerance;
  204. float goalTolerance; // @TODO (toml 07-03-02): goalTolerance appears to have come into existence because
  205. // noone had set a good tolerance in the path itself. It is therefore redundant,
  206. // and more than likely should be excised
  207. AI_NpcBlockHandling_t blockHandling; // @TODO (toml 07-03-02): rename "blockHandling". This is specifically the "simplify" block handling. See SimplifyFlyPath()
  208. // Fields that tend to change
  209. const CBaseEntity * pTarget;
  210. bool bTrySimplify;
  211. };
  212. //-----------------------------------------------------------------------------
  213. // CAI_Navigator
  214. //
  215. // Purpose: Implements pathing and path navigaton logic
  216. //-----------------------------------------------------------------------------
  217. class CAI_Navigator : public CAI_Component,
  218. public CAI_DefMovementSink
  219. {
  220. typedef CAI_Component BaseClass;
  221. public:
  222. // --------------------------------
  223. CAI_Navigator(CAI_BaseNPC *pOuter);
  224. virtual ~CAI_Navigator();
  225. virtual void Init( CAI_Network *pNetwork );
  226. // --------------------------------
  227. void SetPathcornerPathfinding( bool fNewVal) { m_bNoPathcornerPathfinds = !fNewVal; }
  228. void SetRememberStaleNodes( bool fNewVal) { m_fRememberStaleNodes = fNewVal; }
  229. void SetValidateActivitySpeed( bool bValidateActivitySpeed ) { m_bValidateActivitySpeed = bValidateActivitySpeed; }
  230. void SetLocalSucceedOnWithinTolerance( bool fNewVal ) { m_bLocalSucceedOnWithinTolerance = fNewVal; }
  231. // --------------------------------
  232. void Save( ISave &save );
  233. void Restore( IRestore &restore );
  234. // --------------------------------
  235. // Methods to issue movement directives
  236. // --------------------------------
  237. // Simple pathfind
  238. virtual bool SetGoal( const AI_NavGoal_t &goal, unsigned flags = 0 );
  239. // Change the target of the path
  240. virtual bool SetGoalTarget( CBaseEntity *pEntity, const Vector &offset );
  241. // Fancy pathing
  242. bool SetRadialGoal( const Vector &destination, const Vector &center, float radius, float arc, float stepDist, bool bClockwise, bool bAirRoute = false );
  243. bool SetRandomGoal( float minPathLength, const Vector &dir = vec3_origin );
  244. bool SetRandomGoal( const Vector &from, float minPathLength, const Vector &dir = vec3_origin );
  245. bool SetDirectGoal( const Vector &goalPos, Navigation_t navType = NAV_GROUND );
  246. bool SetWanderGoal( float minRadius, float maxRadius );
  247. bool SetVectorGoal( const Vector &dir, float targetDist, float minDist = 0, bool fShouldDeflect = false );
  248. bool SetVectorGoalFromTarget( const Vector &goalPos, float minDist = 0, bool fShouldDeflect = false );
  249. bool FindVectorGoal( Vector *pResult, const Vector &dir, float targetDist, float minDist = 0, bool fShouldDeflect = false );
  250. // Path manipulation
  251. bool PrependLocalAvoidance( float distObstacle, const AIMoveTrace_t &directTrace );
  252. void PrependWaypoint( const Vector &newPoint, Navigation_t navType, unsigned waypointFlags = 0 );
  253. // Query or change the movement activity
  254. Activity GetMovementActivity() const;
  255. Activity SetMovementActivity(Activity activity);
  256. int GetMovementSequence();
  257. void SetMovementSequence( int sequence );
  258. // Query or change the Arrival activity
  259. Activity GetArrivalActivity() const;
  260. void SetArrivalActivity( Activity activity );
  261. int GetArrivalSequence( int curSequence );
  262. void SetArrivalSequence( int sequence );
  263. // Set the facing direction at arrival
  264. void SetArrivalDirection( const Vector &goalDirection );
  265. void SetArrivalDirection( const QAngle &goalAngle );
  266. void SetArrivalDirection( CBaseEntity *pTarget );
  267. Vector GetArrivalDirection( );
  268. // Set the speed to reach at arrival (
  269. void SetArrivalSpeed( float flSpeed );
  270. float GetArrivalSpeed();
  271. // Set the estimated distance to stop before the actual goal
  272. void SetArrivalDistance( float flDistance );
  273. float GetArrivalDistance( ) const;
  274. // Query or change the goal tolerance
  275. float GetGoalTolerance() const;
  276. void SetGoalTolerance(float tolerance);
  277. GoalType_t GetGoalType() const;
  278. const Vector & GetGoalPos() const;
  279. CBaseEntity * GetGoalTarget();
  280. int GetGoalFlags() const;
  281. const Vector & GetCurWaypointPos() const;
  282. int GetCurWaypointFlags() const;
  283. bool CurWaypointIsGoal() const;
  284. bool GetPointAlongPath( Vector *pResult, float distance, bool fReducibleOnly = false );
  285. float GetPathDistanceToGoal();
  286. float GetPathTimeToGoal();
  287. // Query if there is a current goal
  288. bool IsGoalSet() const;
  289. // Query if the current goal is active, meaning the navigator has a path in can progress on
  290. bool IsGoalActive() const;
  291. // Update the goal position to reflect current conditions
  292. bool RefindPathToGoal( bool fSignalTaskStatus = true, bool bDontIgnoreBadLinks = false );
  293. bool UpdateGoalPos( const Vector & );
  294. // Wrap up current locomotion
  295. void StopMoving( bool bImmediate = true );
  296. // Discard the current goal, use StopMoving() if just executing a normal stop
  297. bool ClearGoal();
  298. // --------------------------------
  299. void SetAllowBigStep( CBaseEntity *pEntToStepOff ) { if ( !pEntToStepOff || !pEntToStepOff->IsWorld() ) m_hBigStepGroundEnt = pEntToStepOff; }
  300. // --------------------------------
  301. bool SetGoalFromStoppingPath();
  302. void IgnoreStoppingPath();
  303. // --------------------------------
  304. // Navigation mode
  305. // --------------------------------
  306. Navigation_t GetNavType() const { return m_navType; }
  307. void SetNavType( Navigation_t navType );
  308. bool IsInterruptable() const { return ( m_navType != NAV_CLIMB && m_navType != NAV_JUMP ); }
  309. // --------------------------------
  310. // Pathing
  311. // --------------------------------
  312. AI_NavPathProgress_t ProgressFlyPath( const AI_ProgressFlyPathParams_t &params); // note: will not return "blocked"
  313. AI_PathNode_t GetNearestNode();
  314. Vector GetNodePos( AI_PathNode_t );
  315. CAI_Network * GetNetwork() { return m_pAINetwork; }
  316. const CAI_Network * GetNetwork() const { return m_pAINetwork; }
  317. void SetNetwork( CAI_Network *pNetwork ) { m_pAINetwork = pNetwork; }
  318. CAI_Path * GetPath() { return m_pPath; }
  319. const CAI_Path * GetPath() const { return m_pPath; }
  320. void AdvancePath();
  321. virtual bool SimplifyPath( bool bFirstForPath = false, float maxDist = -1 );
  322. void SimplifyFlyPath( unsigned collisionMask, const CBaseEntity *pTarget,
  323. float strictPointTolerance = 32.0, float blockTolerance = 0.0,
  324. AI_NpcBlockHandling_t blockHandling = AISF_BLOCK);
  325. bool SimplifyFlyPath( const AI_ProgressFlyPathParams_t &params );
  326. bool CanFitAtNode(int nodeNum, unsigned int collisionMask = MASK_NPCSOLID_BRUSHONLY);
  327. float MovementCost( int moveType, Vector &vecStart, Vector &vecEnd );
  328. bool CanFitAtPosition( const Vector &vStartPos, unsigned int collisionMask, bool bIgnoreTransients = false, bool bAllowPlayerAvoid = true );
  329. bool IsOnNetwork() const { return !m_bNotOnNetwork; }
  330. void SetMaxRouteRebuildTime(float time) { m_timePathRebuildMax = time; }
  331. // --------------------------------
  332. void DrawDebugRouteOverlay( void );
  333. // --------------------------------
  334. // Miscellany
  335. // --------------------------------
  336. float CalcYawSpeed();
  337. float GetStepDownMultiplier();
  338. CBaseEntity * GetNextPathcorner( CBaseEntity *pPathCorner );
  339. virtual void OnScheduleChange();
  340. // --------------------------------
  341. // See comments at CAI_BaseNPC::Move()
  342. virtual bool Move( float flInterval = 0.1 );
  343. // --------------------------------
  344. CBaseEntity * GetBlockingEntity() { return m_hLastBlockingEnt; }
  345. protected:
  346. // --------------------------------
  347. //
  348. // Common services provided by CAI_BaseNPC
  349. //
  350. CBaseEntity * GetNavTargetEntity();
  351. void TaskMovementComplete();
  352. float MaxYawSpeed();
  353. void SetSpeed( float );
  354. // --------------------------------
  355. CAI_Motor * GetMotor() { return m_pMotor; }
  356. const CAI_Motor * GetMotor() const { return m_pMotor; }
  357. CAI_MoveProbe * GetMoveProbe() { return m_pMoveProbe; }
  358. const CAI_MoveProbe *GetMoveProbe() const { return m_pMoveProbe; }
  359. CAI_LocalNavigator *GetLocalNavigator() { return m_pLocalNavigator; }
  360. const CAI_LocalNavigator *GetLocalNavigator() const { return m_pLocalNavigator; }
  361. CAI_Pathfinder * GetPathfinder();
  362. const CAI_Pathfinder *GetPathfinder() const;
  363. virtual void OnClearPath(void);
  364. // --------------------------------
  365. virtual void OnNewGoal();
  366. virtual void OnNavComplete();
  367. void OnNavFailed( bool bMovement = false );
  368. void OnNavFailed( AI_TaskFailureCode_t code, bool bMovement = false );
  369. void OnNavFailed( const char *pszGeneralFailText, bool bMovement = false );
  370. // --------------------------------
  371. virtual AIMoveResult_t MoveNormal();
  372. // Navigation execution
  373. virtual AIMoveResult_t MoveClimb();
  374. virtual AIMoveResult_t MoveJump();
  375. // --------------------------------
  376. virtual AIMoveResult_t MoveEnact( const AILocalMoveGoal_t &baseMove );
  377. protected:
  378. // made this virtual so strider can implement hover behavior with a navigator
  379. virtual void MoveCalcBaseGoal( AILocalMoveGoal_t *pMoveGoal);
  380. private:
  381. virtual bool OnCalcBaseMove( AILocalMoveGoal_t *pMoveGoal, float distClear, AIMoveResult_t *pResult );
  382. virtual bool OnObstructionPreSteer( AILocalMoveGoal_t *pMoveGoal, float distClear, AIMoveResult_t *pResult );
  383. virtual bool OnFailedSteer( AILocalMoveGoal_t *pMoveGoal, float distClear, AIMoveResult_t *pResult );
  384. virtual bool OnFailedLocalNavigation( AILocalMoveGoal_t *pMoveGoal, float distClear, AIMoveResult_t *pResult );
  385. virtual bool OnInsufficientStopDist( AILocalMoveGoal_t *pMoveGoal, float distClear, AIMoveResult_t *pResult );
  386. virtual bool OnMoveStalled( const AILocalMoveGoal_t &move );
  387. virtual bool OnMoveExecuteFailed( const AILocalMoveGoal_t &move, const AIMoveTrace_t &trace, AIMotorMoveResult_t fMotorResult, AIMoveResult_t *pResult );
  388. virtual bool OnMoveBlocked( AIMoveResult_t *pResult );
  389. void ResetCalculations();
  390. // Methods shared between ground and fly movement
  391. bool PreMove();
  392. virtual bool MoveUpdateWaypoint( AIMoveResult_t *pResult );
  393. bool IsMovingOutOfWay( const AILocalMoveGoal_t &moveGoal, float distClear );
  394. bool DelayNavigationFailure( const AIMoveTrace_t &trace );
  395. static void CalculateDeflection( const Vector &start, const Vector &dir, const Vector &normal, Vector *pResult );
  396. // --------------------------------
  397. // Pathfinding
  398. // --------------------------------
  399. public:
  400. float GetPathDistToCurWaypoint() const;
  401. float GetPathDistToGoal() const;
  402. float BuildAndGetPathDistToGoal();
  403. // --------------------------------
  404. int GetNavFailCounter() const;
  405. void ClearNavFailCounter();
  406. float GetLastNavFailTime() const;
  407. bool TeleportAlongPath();
  408. private:
  409. bool DoFindPath( void ); // Find a route
  410. bool DoFindPathToPathcorner( CBaseEntity *pPathCorner );
  411. protected:
  412. virtual bool DoFindPathToPos(void);
  413. virtual bool ShouldOptimizeInitialPathSegment( AI_Waypoint_t * ) { return true; }
  414. private:
  415. void ClearPath(void);
  416. void SaveStoppingPath( void );
  417. protected:
  418. virtual bool GetStoppingPath( CAI_WaypointList *pClippedWaypoints );
  419. private:
  420. bool FindPath( const AI_NavGoal_t &goal, unsigned flags );
  421. bool FindPath( bool fSignalTaskStatus = true, bool bDontIgnoreBadLinks = false );
  422. bool MarkCurWaypointFailedLink( void ); // Call when route fails
  423. struct SimplifyForwardScanParams
  424. {
  425. float scanDist;
  426. float radius;
  427. float increment;
  428. int maxSamples;
  429. };
  430. bool ShouldAttemptSimplifyTo( const Vector &pos );
  431. bool ShouldSimplifyTo( bool passedDetour, const Vector &pos );
  432. bool SimplifyPathForwardScan( const CAI_Navigator::SimplifyForwardScanParams &params );
  433. bool SimplifyPathForwardScan( const SimplifyForwardScanParams &params, AI_Waypoint_t *pCurWaypoint, const Vector &curPoint, float distRemaining, bool skip, bool passedDetour, int *pTestCount );
  434. bool SimplifyPathForward( float maxDist = -1 );
  435. bool SimplifyPathBacktrack();
  436. bool SimplifyPathQuick();
  437. void SimplifyPathInsertSimplification( AI_Waypoint_t *pSegmentStart, const Vector &point );
  438. // ---------------------------------
  439. static bool ActivityIsLocomotive( Activity );
  440. // ---------------------------------
  441. Navigation_t m_navType; // My current navigation type (walk,fly)
  442. bool m_fNavComplete;
  443. bool m_bLastNavFailed;
  444. // Cached pointers to other components, for efficiency
  445. CAI_Motor * m_pMotor;
  446. CAI_MoveProbe * m_pMoveProbe;
  447. CAI_LocalNavigator *m_pLocalNavigator;
  448. // ---------------------------------
  449. CAI_Network* m_pAINetwork; // My current AINetwork
  450. CAI_Path* m_pPath; // My current route
  451. CAI_WaypointList * m_pClippedWaypoints;
  452. float m_flTimeClipped;
  453. Activity m_PreviousMoveActivity;
  454. Activity m_PreviousArrivalActivity;
  455. bool m_bValidateActivitySpeed;
  456. bool m_bCalledStartMove;
  457. bool m_bNotOnNetwork; // This NPC has no reachable nodes!
  458. float m_flNextSimplifyTime; // next time we should try to simplify our route
  459. bool m_bForcedSimplify;
  460. float m_flLastSuccessfulSimplifyTime;
  461. float m_flTimeLastAvoidanceTriangulate;
  462. // --------------
  463. float m_timePathRebuildMax; // How long to try rebuilding path before failing task
  464. float m_timePathRebuildDelay; // How long to wait before trying to rebuild again
  465. float m_timePathRebuildFail; // Current global time when should fail building path
  466. float m_timePathRebuildNext; // Global time to try rebuilding again
  467. // --------------
  468. bool m_fRememberStaleNodes;
  469. bool m_bNoPathcornerPathfinds;
  470. bool m_bLocalSucceedOnWithinTolerance;
  471. // --------------
  472. bool m_fPeerMoveWait;
  473. EHANDLE m_hPeerWaitingOn;
  474. CSimTimer m_PeerWaitMoveTimer;
  475. CSimTimer m_PeerWaitClearTimer;
  476. CSimTimer m_NextSidestepTimer;
  477. // --------------
  478. EHANDLE m_hBigStepGroundEnt;
  479. EHANDLE m_hLastBlockingEnt;
  480. // --------------
  481. Vector m_vPosBeginFailedSteer;
  482. float m_timeBeginFailedSteer;
  483. // --------------
  484. int m_nNavFailCounter;
  485. float m_flLastNavFailTime;
  486. public:
  487. DECLARE_SIMPLE_DATADESC();
  488. };
  489. //-----------------------------------------------------------------------------
  490. // AI_NavGoal_t inline methods
  491. //-----------------------------------------------------------------------------
  492. inline AI_NavGoal_t::AI_NavGoal_t( GoalType_t type,
  493. Activity activity,
  494. float tolerance,
  495. unsigned flags,
  496. CBaseEntity *pTarget)
  497. : type(type),
  498. dest(AIN_NO_DEST),
  499. destNode(AIN_NO_NODE),
  500. activity(activity),
  501. tolerance(tolerance),
  502. maxInitialSimplificationDist(-1),
  503. flags(flags),
  504. pTarget(pTarget),
  505. arrivalActivity( AIN_DEF_ACTIVITY ),
  506. arrivalSequence( ACT_INVALID )
  507. {
  508. }
  509. inline AI_NavGoal_t::AI_NavGoal_t( const Vector &dest,
  510. Activity activity,
  511. float tolerance,
  512. unsigned flags,
  513. CBaseEntity *pTarget)
  514. : type(GOALTYPE_LOCATION),
  515. dest(dest),
  516. destNode(AIN_NO_NODE),
  517. activity(activity),
  518. tolerance(tolerance),
  519. maxInitialSimplificationDist(-1),
  520. flags(flags),
  521. pTarget(pTarget),
  522. arrivalActivity( AIN_DEF_ACTIVITY ),
  523. arrivalSequence( ACT_INVALID )
  524. {
  525. }
  526. inline AI_NavGoal_t::AI_NavGoal_t( GoalType_t type,
  527. const Vector &dest,
  528. Activity activity,
  529. float tolerance,
  530. unsigned flags,
  531. CBaseEntity *pTarget)
  532. : type(type),
  533. dest(dest),
  534. destNode(AIN_NO_NODE),
  535. activity(activity),
  536. tolerance(tolerance),
  537. maxInitialSimplificationDist(-1),
  538. flags(flags),
  539. pTarget(pTarget),
  540. arrivalActivity( AIN_DEF_ACTIVITY ),
  541. arrivalSequence( ACT_INVALID )
  542. {
  543. }
  544. inline AI_NavGoal_t::AI_NavGoal_t( AI_PathNode_t destNode,
  545. Activity activity,
  546. float tolerance,
  547. unsigned flags,
  548. CBaseEntity * pTarget)
  549. : type(GOALTYPE_LOCATION),
  550. dest(AIN_NO_DEST),
  551. destNode(destNode),
  552. activity(activity),
  553. tolerance(tolerance),
  554. maxInitialSimplificationDist(-1),
  555. flags(flags),
  556. pTarget(pTarget),
  557. arrivalActivity( AIN_DEF_ACTIVITY ),
  558. arrivalSequence( ACT_INVALID )
  559. {
  560. }
  561. inline AI_NavGoal_t::AI_NavGoal_t( GoalType_t type,
  562. AI_PathNode_t destNode,
  563. Activity activity,
  564. float tolerance,
  565. unsigned flags,
  566. CBaseEntity * pTarget)
  567. : type(type),
  568. dest(AIN_NO_DEST),
  569. destNode(destNode),
  570. activity(activity),
  571. tolerance(tolerance),
  572. maxInitialSimplificationDist(-1),
  573. flags(flags),
  574. pTarget(pTarget),
  575. arrivalActivity( AIN_DEF_ACTIVITY ),
  576. arrivalSequence( ACT_INVALID )
  577. {
  578. }
  579. //-----------------------------------------------------------------------------
  580. #endif // AI_NAVIGATOR_H