AASFile.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition 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 BFG Edition 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 __AASFILE_H__
  21. #define __AASFILE_H__
  22. /*
  23. ===============================================================================
  24. AAS File
  25. ===============================================================================
  26. */
  27. #define AAS_FILEID "DewmAAS"
  28. #define AAS_FILEVERSION "1.07"
  29. // travel flags
  30. #define TFL_INVALID BIT(0) // not valid
  31. #define TFL_WALK BIT(1) // walking
  32. #define TFL_CROUCH BIT(2) // crouching
  33. #define TFL_WALKOFFLEDGE BIT(3) // walking of a ledge
  34. #define TFL_BARRIERJUMP BIT(4) // jumping onto a barrier
  35. #define TFL_JUMP BIT(5) // jumping
  36. #define TFL_LADDER BIT(6) // climbing a ladder
  37. #define TFL_SWIM BIT(7) // swimming
  38. #define TFL_WATERJUMP BIT(8) // jump out of the water
  39. #define TFL_TELEPORT BIT(9) // teleportation
  40. #define TFL_ELEVATOR BIT(10) // travel by elevator
  41. #define TFL_FLY BIT(11) // fly
  42. #define TFL_SPECIAL BIT(12) // special
  43. #define TFL_WATER BIT(21) // travel through water
  44. #define TFL_AIR BIT(22) // travel through air
  45. // face flags
  46. #define FACE_SOLID BIT(0) // solid at the other side
  47. #define FACE_LADDER BIT(1) // ladder surface
  48. #define FACE_FLOOR BIT(2) // standing on floor when on this face
  49. #define FACE_LIQUID BIT(3) // face seperating two areas with liquid
  50. #define FACE_LIQUIDSURFACE BIT(4) // face seperating liquid and air
  51. // area flags
  52. #define AREA_FLOOR BIT(0) // AI can stand on the floor in this area
  53. #define AREA_GAP BIT(1) // area has a gap
  54. #define AREA_LEDGE BIT(2) // if entered the AI bbox partly floats above a ledge
  55. #define AREA_LADDER BIT(3) // area contains one or more ladder faces
  56. #define AREA_LIQUID BIT(4) // area contains a liquid
  57. #define AREA_CROUCH BIT(5) // AI cannot walk but can only crouch in this area
  58. #define AREA_REACHABLE_WALK BIT(6) // area is reachable by walking or swimming
  59. #define AREA_REACHABLE_FLY BIT(7) // area is reachable by flying
  60. // area contents flags
  61. #define AREACONTENTS_SOLID BIT(0) // solid, not a valid area
  62. #define AREACONTENTS_WATER BIT(1) // area contains water
  63. #define AREACONTENTS_CLUSTERPORTAL BIT(2) // area is a cluster portal
  64. #define AREACONTENTS_OBSTACLE BIT(3) // area contains (part of) a dynamic obstacle
  65. #define AREACONTENTS_TELEPORTER BIT(4) // area contains (part of) a teleporter trigger
  66. // bits for different bboxes
  67. #define AREACONTENTS_BBOX_BIT 24
  68. #define MAX_REACH_PER_AREA 256
  69. #define MAX_AAS_TREE_DEPTH 128
  70. #define MAX_AAS_BOUNDING_BOXES 4
  71. // reachability to another area
  72. class idReachability {
  73. public:
  74. int travelType; // type of travel required to get to the area
  75. short toAreaNum; // number of the reachable area
  76. short fromAreaNum; // number of area the reachability starts
  77. idVec3 start; // start point of inter area movement
  78. idVec3 end; // end point of inter area movement
  79. int edgeNum; // edge crossed by this reachability
  80. unsigned short travelTime; // travel time of the inter area movement
  81. byte number; // reachability number within the fromAreaNum (must be < 256)
  82. byte disableCount; // number of times this reachability has been disabled
  83. idReachability * next; // next reachability in list
  84. idReachability * rev_next; // next reachability in reversed list
  85. unsigned short * areaTravelTimes; // travel times within the fromAreaNum from reachabilities that lead towards this area
  86. public:
  87. void CopyBase( idReachability &reach );
  88. };
  89. class idReachability_Walk : public idReachability {
  90. };
  91. class idReachability_BarrierJump : public idReachability {
  92. };
  93. class idReachability_WaterJump : public idReachability {
  94. };
  95. class idReachability_WalkOffLedge : public idReachability {
  96. };
  97. class idReachability_Swim : public idReachability {
  98. };
  99. class idReachability_Fly : public idReachability {
  100. };
  101. class idReachability_Special : public idReachability {
  102. public:
  103. idDict dict;
  104. };
  105. // index
  106. typedef int aasIndex_t;
  107. // vertex
  108. typedef idVec3 aasVertex_t;
  109. // edge
  110. typedef struct aasEdge_s {
  111. int vertexNum[2]; // numbers of the vertexes of this edge
  112. } aasEdge_t;
  113. // area boundary face
  114. typedef struct aasFace_s {
  115. unsigned short planeNum; // number of the plane this face is on
  116. unsigned short flags; // face flags
  117. int numEdges; // number of edges in the boundary of the face
  118. int firstEdge; // first edge in the edge index
  119. short areas[2]; // area at the front and back of this face
  120. } aasFace_t;
  121. // area with a boundary of faces
  122. typedef struct aasArea_s {
  123. int numFaces; // number of faces used for the boundary of the area
  124. int firstFace; // first face in the face index used for the boundary of the area
  125. idBounds bounds; // bounds of the area
  126. idVec3 center; // center of the area an AI can move towards
  127. unsigned short flags; // several area flags
  128. unsigned short contents; // contents of the area
  129. short cluster; // cluster the area belongs to, if negative it's a portal
  130. short clusterAreaNum; // number of the area in the cluster
  131. int travelFlags; // travel flags for traveling through this area
  132. idReachability * reach; // reachabilities that start from this area
  133. idReachability * rev_reach; // reachabilities that lead to this area
  134. } aasArea_t;
  135. // nodes of the bsp tree
  136. typedef struct aasNode_s {
  137. unsigned short planeNum; // number of the plane that splits the subspace at this node
  138. int children[2]; // child nodes, zero is solid, negative is -(area number)
  139. } aasNode_t;
  140. // cluster portal
  141. typedef struct aasPortal_s {
  142. short areaNum; // number of the area that is the actual portal
  143. short clusters[2]; // number of cluster at the front and back of the portal
  144. short clusterAreaNum[2]; // number of this portal area in the front and back cluster
  145. unsigned short maxAreaTravelTime; // maximum travel time through the portal area
  146. } aasPortal_t;
  147. // cluster
  148. typedef struct aasCluster_s {
  149. int numAreas; // number of areas in the cluster
  150. int numReachableAreas; // number of areas with reachabilities
  151. int numPortals; // number of cluster portals
  152. int firstPortal; // first cluster portal in the index
  153. } aasCluster_t;
  154. // trace through the world
  155. typedef struct aasTrace_s {
  156. // parameters
  157. int flags; // areas with these flags block the trace
  158. int travelFlags; // areas with these travel flags block the trace
  159. int maxAreas; // size of the 'areas' array
  160. int getOutOfSolid; // trace out of solid if the trace starts in solid
  161. // output
  162. float fraction; // fraction of trace completed
  163. idVec3 endpos; // end position of trace
  164. int planeNum; // plane hit
  165. int lastAreaNum; // number of last area the trace went through
  166. int blockingAreaNum; // area that could not be entered
  167. int numAreas; // number of areas the trace went through
  168. int * areas; // array to store areas the trace went through
  169. idVec3 * points; // points where the trace entered each new area
  170. aasTrace_s() { areas = NULL; points = NULL; getOutOfSolid = false; flags = travelFlags = maxAreas = 0; }
  171. } aasTrace_t;
  172. // settings
  173. class idAASSettings {
  174. public:
  175. // collision settings
  176. int numBoundingBoxes;
  177. idBounds boundingBoxes[MAX_AAS_BOUNDING_BOXES];
  178. bool usePatches;
  179. bool writeBrushMap;
  180. bool playerFlood;
  181. bool noOptimize;
  182. bool allowSwimReachabilities;
  183. bool allowFlyReachabilities;
  184. idStr fileExtension;
  185. // physics settings
  186. idVec3 gravity;
  187. idVec3 gravityDir;
  188. idVec3 invGravityDir;
  189. float gravityValue;
  190. float maxStepHeight;
  191. float maxBarrierHeight;
  192. float maxWaterJumpHeight;
  193. float maxFallHeight;
  194. float minFloorCos;
  195. // fixed travel times
  196. int tt_barrierJump;
  197. int tt_startCrouching;
  198. int tt_waterJump;
  199. int tt_startWalkOffLedge;
  200. public:
  201. idAASSettings();
  202. bool FromFile( const idStr &fileName );
  203. bool FromParser( idLexer &src );
  204. bool FromDict( const char *name, const idDict *dict );
  205. bool WriteToFile( idFile *fp ) const;
  206. bool ValidForBounds( const idBounds &bounds ) const;
  207. bool ValidEntity( const char *classname ) const;
  208. private:
  209. bool ParseBool( idLexer &src, bool &b );
  210. bool ParseInt( idLexer &src, int &i );
  211. bool ParseFloat( idLexer &src, float &f );
  212. bool ParseVector( idLexer &src, idVec3 &vec );
  213. bool ParseBBoxes( idLexer &src );
  214. };
  215. /*
  216. - when a node child is a solid leaf the node child number is zero
  217. - two adjacent areas (sharing a plane at opposite sides) share a face
  218. this face is a portal between the areas
  219. - when an area uses a face from the faceindex with a positive index
  220. then the face plane normal points into the area
  221. - the face edges are stored counter clockwise using the edgeindex
  222. - two adjacent convex areas (sharing a face) only share One face
  223. this is a simple result of the areas being convex
  224. - the areas can't have a mixture of ground and gap faces
  225. other mixtures of faces in one area are allowed
  226. - areas with the AREACONTENTS_CLUSTERPORTAL in the settings have
  227. the cluster number set to the negative portal number
  228. - edge zero is a dummy
  229. - face zero is a dummy
  230. - area zero is a dummy
  231. - node zero is a dummy
  232. - portal zero is a dummy
  233. - cluster zero is a dummy
  234. */
  235. class idAASFile {
  236. public:
  237. virtual ~idAASFile() {}
  238. const char * GetName() const { return name.c_str(); }
  239. unsigned int GetCRC() const { return crc; }
  240. int GetNumPlanes() const { return planeList.Num(); }
  241. const idPlane & GetPlane( int index ) const { return planeList[index]; }
  242. int GetNumVertices() const { return vertices.Num(); }
  243. const aasVertex_t & GetVertex( int index ) const { return vertices[index]; }
  244. int GetNumEdges() const { return edges.Num(); }
  245. const aasEdge_t & GetEdge( int index ) const { return edges[index]; }
  246. int GetNumEdgeIndexes() const { return edgeIndex.Num(); }
  247. const aasIndex_t & GetEdgeIndex( int index ) const { return edgeIndex[index]; }
  248. int GetNumFaces() const { return faces.Num(); }
  249. const aasFace_t & GetFace( int index ) const { return faces[index]; }
  250. int GetNumFaceIndexes() const { return faceIndex.Num(); }
  251. const aasIndex_t & GetFaceIndex( int index ) const { return faceIndex[index]; }
  252. int GetNumAreas() const { return areas.Num(); }
  253. const aasArea_t & GetArea( int index ) { return areas[index]; }
  254. int GetNumNodes() const { return nodes.Num(); }
  255. const aasNode_t & GetNode( int index ) const { return nodes[index]; }
  256. int GetNumPortals() const { return portals.Num(); }
  257. const aasPortal_t & GetPortal( int index ) { return portals[index]; }
  258. int GetNumPortalIndexes() const { return portalIndex.Num(); }
  259. const aasIndex_t & GetPortalIndex( int index ) const { return portalIndex[index]; }
  260. int GetNumClusters() const { return clusters.Num(); }
  261. const aasCluster_t & GetCluster( int index ) const { return clusters[index]; }
  262. const idAASSettings & GetSettings() const { return settings; }
  263. void SetPortalMaxTravelTime( int index, int time ) { portals[index].maxAreaTravelTime = time; }
  264. void SetAreaTravelFlag( int index, int flag ) { areas[index].travelFlags |= flag; }
  265. void RemoveAreaTravelFlag( int index, int flag ) { areas[index].travelFlags &= ~flag; }
  266. virtual idVec3 EdgeCenter( int edgeNum ) const = 0;
  267. virtual idVec3 FaceCenter( int faceNum ) const = 0;
  268. virtual idVec3 AreaCenter( int areaNum ) const = 0;
  269. virtual idBounds EdgeBounds( int edgeNum ) const = 0;
  270. virtual idBounds FaceBounds( int faceNum ) const = 0;
  271. virtual idBounds AreaBounds( int areaNum ) const = 0;
  272. virtual int PointAreaNum( const idVec3 &origin ) const = 0;
  273. virtual int PointReachableAreaNum( const idVec3 &origin, const idBounds &searchBounds, const int areaFlags, const int excludeTravelFlags ) const = 0;
  274. virtual int BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags, const int excludeTravelFlags ) const = 0;
  275. virtual void PushPointIntoAreaNum( int areaNum, idVec3 &point ) const = 0;
  276. virtual bool Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const = 0;
  277. virtual void PrintInfo() const = 0;
  278. protected:
  279. idStr name;
  280. unsigned int crc;
  281. idPlaneSet planeList;
  282. idList<aasVertex_t, TAG_AAS> vertices;
  283. idList<aasEdge_t, TAG_AAS> edges;
  284. idList<aasIndex_t, TAG_AAS> edgeIndex;
  285. idList<aasFace_t, TAG_AAS> faces;
  286. idList<aasIndex_t, TAG_AAS> faceIndex;
  287. idList<aasArea_t, TAG_AAS> areas;
  288. idList<aasNode_t, TAG_AAS> nodes;
  289. idList<aasPortal_t, TAG_AAS> portals;
  290. idList<aasIndex_t, TAG_AAS> portalIndex;
  291. idList<aasCluster_t, TAG_AAS> clusters;
  292. idAASSettings settings;
  293. };
  294. #endif /* !__AASFILE_H__ */