AAS.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __AAS_H__
  21. #define __AAS_H__
  22. /*
  23. ===============================================================================
  24. Area Awareness System
  25. ===============================================================================
  26. */
  27. enum {
  28. PATHTYPE_WALK,
  29. PATHTYPE_WALKOFFLEDGE,
  30. PATHTYPE_BARRIERJUMP,
  31. PATHTYPE_JUMP
  32. };
  33. typedef struct aasPath_s {
  34. int type; // path type
  35. idVec3 moveGoal; // point the AI should move towards
  36. int moveAreaNum; // number of the area the AI should move towards
  37. idVec3 secondaryGoal; // secondary move goal for complex navigation
  38. const idReachability * reachability; // reachability used for navigation
  39. } aasPath_t;
  40. typedef struct aasGoal_s {
  41. int areaNum; // area the goal is in
  42. idVec3 origin; // position of goal
  43. } aasGoal_t;
  44. typedef struct aasObstacle_s {
  45. idBounds absBounds; // absolute bounds of obstacle
  46. idBounds expAbsBounds; // expanded absolute bounds of obstacle
  47. } aasObstacle_t;
  48. class idAASCallback {
  49. public:
  50. virtual ~idAASCallback() {};
  51. virtual bool TestArea( const class idAAS *aas, int areaNum ) = 0;
  52. };
  53. typedef int aasHandle_t;
  54. class idAAS {
  55. public:
  56. static idAAS * Alloc( void );
  57. virtual ~idAAS( void ) = 0;
  58. // Initialize for the given map.
  59. virtual bool Init( const idStr &mapName, unsigned int mapFileCRC ) = 0;
  60. // Print AAS stats.
  61. virtual void Stats( void ) const = 0;
  62. // Test from the given origin.
  63. virtual void Test( const idVec3 &origin ) = 0;
  64. // Get the AAS settings.
  65. virtual const idAASSettings *GetSettings( void ) const = 0;
  66. // Returns the number of the area the origin is in.
  67. virtual int PointAreaNum( const idVec3 &origin ) const = 0;
  68. // Returns the number of the nearest reachable area for the given point.
  69. virtual int PointReachableAreaNum( const idVec3 &origin, const idBounds &bounds, const int areaFlags ) const = 0;
  70. // Returns the number of the first reachable area in or touching the bounds.
  71. virtual int BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags ) const = 0;
  72. // Push the point into the area.
  73. virtual void PushPointIntoAreaNum( int areaNum, idVec3 &origin ) const = 0;
  74. // Returns a reachable point inside the given area.
  75. virtual idVec3 AreaCenter( int areaNum ) const = 0;
  76. // Returns the area flags.
  77. virtual int AreaFlags( int areaNum ) const = 0;
  78. // Returns the travel flags for traveling through the area.
  79. virtual int AreaTravelFlags( int areaNum ) const = 0;
  80. // Trace through the areas and report the first collision.
  81. virtual bool Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const = 0;
  82. // Get a plane for a trace.
  83. virtual const idPlane & GetPlane( int planeNum ) const = 0;
  84. // Get wall edges.
  85. virtual int GetWallEdges( int areaNum, const idBounds &bounds, int travelFlags, int *edges, int maxEdges ) const = 0;
  86. // Sort the wall edges to create continuous sequences of walls.
  87. virtual void SortWallEdges( int *edges, int numEdges ) const = 0;
  88. // Get the vertex numbers for an edge.
  89. virtual void GetEdgeVertexNumbers( int edgeNum, int verts[2] ) const = 0;
  90. // Get an edge.
  91. virtual void GetEdge( int edgeNum, idVec3 &start, idVec3 &end ) const = 0;
  92. // Find all areas within or touching the bounds with the given contents and disable/enable them for routing.
  93. virtual bool SetAreaState( const idBounds &bounds, const int areaContents, bool disabled ) = 0;
  94. // Add an obstacle to the routing system.
  95. virtual aasHandle_t AddObstacle( const idBounds &bounds ) = 0;
  96. // Remove an obstacle from the routing system.
  97. virtual void RemoveObstacle( const aasHandle_t handle ) = 0;
  98. // Remove all obstacles from the routing system.
  99. virtual void RemoveAllObstacles( void ) = 0;
  100. // Returns the travel time towards the goal area in 100th of a second.
  101. virtual int TravelTimeToGoalArea( int areaNum, const idVec3 &origin, int goalAreaNum, int travelFlags ) const = 0;
  102. // Get the travel time and first reachability to be used towards the goal, returns true if there is a path.
  103. virtual bool RouteToGoalArea( int areaNum, const idVec3 origin, int goalAreaNum, int travelFlags, int &travelTime, idReachability **reach ) const = 0;
  104. // Creates a walk path towards the goal.
  105. virtual bool WalkPathToGoal( aasPath_t &path, int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags ) const = 0;
  106. // Returns true if one can walk along a straight line from the origin to the goal origin.
  107. virtual bool WalkPathValid( int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags, idVec3 &endPos, int &endAreaNum ) const = 0;
  108. // Creates a fly path towards the goal.
  109. virtual bool FlyPathToGoal( aasPath_t &path, int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags ) const = 0;
  110. // Returns true if one can fly along a straight line from the origin to the goal origin.
  111. virtual bool FlyPathValid( int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags, idVec3 &endPos, int &endAreaNum ) const = 0;
  112. // Show the walk path from the origin towards the area.
  113. virtual void ShowWalkPath( const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin ) const = 0;
  114. // Show the fly path from the origin towards the area.
  115. virtual void ShowFlyPath( const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin ) const = 0;
  116. // Find the nearest goal which satisfies the callback.
  117. virtual bool FindNearestGoal( aasGoal_t &goal, int areaNum, const idVec3 origin, const idVec3 &target, int travelFlags, aasObstacle_t *obstacles, int numObstacles, idAASCallback &callback ) const = 0;
  118. };
  119. #endif /* !__AAS_H__ */