home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / aas / AASFile.h next >
C/C++ Source or Header  |  2005-11-14  |  17KB  |  468 lines

  1.  
  2. #ifndef __AASFILE_H__
  3. #define __AASFILE_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.     AAS File
  9.  
  10. ===============================================================================
  11. */
  12.  
  13. #define AAS_FILEID                    "DewmAAS"
  14. #define AAS_FILEVERSION                "1.08"
  15.  
  16. // travel flags
  17. #define TFL_INVALID                    BIT(0)        // not valid
  18. #define TFL_WALK                    BIT(1)        // walking
  19. #define TFL_CROUCH                    BIT(2)        // crouching
  20. #define TFL_WALKOFFLEDGE            BIT(3)        // walking of a ledge
  21. #define TFL_BARRIERJUMP                BIT(4)        // jumping onto a barrier
  22. #define TFL_JUMP                    BIT(5)        // jumping
  23. #define TFL_LADDER                    BIT(6)        // climbing a ladder
  24. #define TFL_SWIM                    BIT(7)        // swimming
  25. #define TFL_WATERJUMP                BIT(8)        // jump out of the water
  26. #define TFL_TELEPORT                BIT(9)        // teleportation
  27. #define TFL_ELEVATOR                BIT(10)        // travel by elevator
  28. #define TFL_FLY                        BIT(11)        // fly
  29. #define TFL_SPECIAL                    BIT(12)        // special
  30. #define TFL_WATER                    BIT(21)        // travel through water
  31. #define TFL_AIR                        BIT(22)        // travel through air
  32.  
  33. // face flags
  34. #define FACE_SOLID                    BIT(0)        // solid at the other side
  35. #define FACE_LADDER                    BIT(1)        // ladder surface
  36. #define FACE_FLOOR                    BIT(2)        // standing on floor when on this face
  37. #define FACE_LIQUID                    BIT(3)        // face seperating two areas with liquid
  38. #define FACE_LIQUIDSURFACE            BIT(4)        // face seperating liquid and air
  39.  
  40. // area flags
  41. #define AREA_FLOOR                    BIT(0)        // AI can stand on the floor in this area
  42. #define AREA_GAP                    BIT(1)        // area has a gap
  43. #define AREA_LEDGE                    BIT(2)        // if entered the AI bbox partly floats above a ledge
  44. #define AREA_LADDER                    BIT(3)        // area contains one or more ladder faces
  45. #define AREA_LIQUID                    BIT(4)        // area contains a liquid
  46. #define AREA_CROUCH                    BIT(5)        // AI cannot walk but can only crouch in this area
  47. #define AREA_REACHABLE_WALK            BIT(6)        // area is reachable by walking or swimming
  48. #define AREA_REACHABLE_FLY            BIT(7)        // area is reachable by flying
  49.  
  50. // area contents flags
  51. #define AREACONTENTS_SOLID            BIT(0)        // solid, not a valid area
  52. #define AREACONTENTS_WATER            BIT(1)        // area contains water
  53. #define AREACONTENTS_CLUSTERPORTAL    BIT(2)        // area is a cluster portal
  54. #define AREACONTENTS_OBSTACLE        BIT(3)        // area contains (part of) a dynamic obstacle
  55. #define AREACONTENTS_TELEPORTER        BIT(4)        // area contains (part of) a teleporter trigger
  56.  
  57. // bits for different bboxes
  58. #define AREACONTENTS_BBOX_BIT        24
  59.  
  60.  
  61. // RAVEN BEGIN
  62. // cdr: AASTactical 
  63.  
  64. // feature bits
  65. #define FEATURE_COVER                BIT(0)        // provides cover
  66. #define FEATURE_LOOK_LEFT            BIT(1)        // attack by leaning left
  67. #define FEATURE_LOOK_RIGHT            BIT(2)        // attack by leaning right
  68. #define FEATURE_LOOK_OVER            BIT(3)        // attack by leaning over the cover
  69. #define FEATURE_CORNER_LEFT            BIT(4)        // is a left corner
  70. #define FEATURE_CORNER_RIGHT        BIT(5)        // is a right corner
  71. #define FEATURE_PINCH                BIT(6)        // is a tight area connecting two larger areas
  72. #define FEATURE_VANTAGE                BIT(7)        // provides a good view of the sampled area as a whole
  73.  
  74. // forward reference of sensor object
  75. struct rvAASTacticalSensor;
  76. struct rvMarker;
  77.  
  78. // RAVEN END
  79.  
  80.  
  81. #define MAX_REACH_PER_AREA            256
  82. #define MAX_AAS_TREE_DEPTH            128
  83.  
  84. #define MAX_AAS_BOUNDING_BOXES        4
  85.  
  86. typedef enum {
  87.  
  88.     RE_WALK,
  89.     RE_WALKOFFLEDGE,
  90.     RE_FLY,
  91.     RE_SWIM,
  92.     RE_WATERJUMP,
  93.     RE_BARRIERJUMP,
  94.     RE_SPECIAL
  95. };
  96.  
  97.  
  98. // reachability to another area
  99. class idReachability {
  100. public:
  101.     int                            travelType;            // type of travel required to get to the area
  102.     short                        toAreaNum;            // number of the reachable area
  103.     short                        fromAreaNum;        // number of area the reachability starts
  104.     idVec3                        start;                // start point of inter area movement
  105.     idVec3                        end;                // end point of inter area movement
  106.     int                            edgeNum;            // edge crossed by this reachability
  107.     unsigned short                travelTime;            // travel time of the inter area movement
  108.     byte                        number;                // reachability number within the fromAreaNum (must be < 256)
  109.     byte                        disableCount;        // number of times this reachability has been disabled
  110.     idReachability *            next;                // next reachability in list
  111.     idReachability *            rev_next;            // next reachability in reversed list
  112.     unsigned short *            areaTravelTimes;    // travel times within the fromAreaNum from reachabilities that lead towards this area
  113. public:
  114.     void                        CopyBase( idReachability &reach );
  115. };
  116.  
  117. class idReachability_Walk : public idReachability {
  118. };
  119.  
  120. class idReachability_BarrierJump : public idReachability {
  121. };
  122.  
  123. class idReachability_WaterJump : public idReachability {
  124. };
  125.  
  126. class idReachability_WalkOffLedge : public idReachability {
  127. };
  128.  
  129. class idReachability_Swim : public idReachability {
  130. };
  131.  
  132. class idReachability_Fly : public idReachability {
  133. };
  134.  
  135. class idReachability_Special : public idReachability {
  136. public:
  137.     idDict                        dict;
  138. };
  139.  
  140. // index
  141. typedef int aasIndex_t;
  142.  
  143. // vertex
  144. typedef idVec3 aasVertex_t;
  145.  
  146. // edge
  147. typedef struct aasEdge_s {
  148.     int                            vertexNum[2];        // numbers of the vertexes of this edge
  149. } aasEdge_t;
  150.  
  151. // area boundary face
  152. typedef struct aasFace_s {
  153.     unsigned short                planeNum;            // number of the plane this face is on
  154.     unsigned short                flags;                // face flags
  155.     int                            numEdges;            // number of edges in the boundary of the face
  156.     int                            firstEdge;            // first edge in the edge index
  157.     short                        areas[2];            // area at the front and back of this face
  158. } aasFace_t;
  159.  
  160. // area with a boundary of faces
  161. typedef struct aasArea_s {
  162.     int                            numFaces;            // number of faces used for the boundary of the area
  163.     int                            firstFace;            // first face in the face index used for the boundary of the area
  164.     idBounds                    bounds;                // bounds of the area
  165.     idVec3                        center;                // center of the area an AI can move towards
  166.     float                        ceiling;            // top of the area
  167.     unsigned short                flags;                // several area flags
  168.     unsigned short                contents;            // contents of the area
  169.     short                        cluster;            // cluster the area belongs to, if negative it's a portal
  170.     short                        clusterAreaNum;        // number of the area in the cluster
  171.     int                            travelFlags;        // travel flags for traveling through this area
  172.     idReachability *            reach;                // reachabilities that start from this area
  173.     idReachability *            rev_reach;            // reachabilities that lead to this area
  174.  
  175.     // RAVEN BEGIN
  176.     // cdr: AASTactical
  177.     unsigned short                numFeatures;        // number of features in this area
  178.     unsigned short                firstFeature;        // first feature in the feature index within this area
  179.  
  180.     // cdr: Obstacle Avoidance
  181.     rvMarker*                    firstMarker;        // first obstacle avoidance threat in this area (0 if none)
  182.     // RAVEN END
  183. } aasArea_t;
  184.  
  185. // nodes of the bsp tree
  186. typedef struct aasNode_s {
  187.     unsigned short                planeNum;            // number of the plane that splits the subspace at this node
  188.     int                            children[2];        // child nodes, zero is solid, negative is -(area number)
  189. } aasNode_t;
  190.  
  191. // cluster portal
  192. typedef struct aasPortal_s {
  193.     short                        areaNum;            // number of the area that is the actual portal
  194.     short                        clusters[2];        // number of cluster at the front and back of the portal
  195.     short                        clusterAreaNum[2];    // number of this portal area in the front and back cluster
  196.     unsigned short                maxAreaTravelTime;    // maximum travel time through the portal area
  197. } aasPortal_t;
  198.  
  199. // cluster
  200. typedef struct aasCluster_s {
  201.     int                            numAreas;            // number of areas in the cluster
  202.     int                            numReachableAreas;    // number of areas with reachabilities
  203.     int                            numPortals;            // number of cluster portals
  204.     int                            firstPortal;        // first cluster portal in the index
  205. } aasCluster_t;
  206.  
  207. // RAVEN BEGIN
  208. // cdr: AASTactical
  209. typedef    struct aasFeature_s {
  210.     short                        x;                    // 2 Bytes
  211.     short                        y;                    // 2 Bytes
  212.     short                        z;                    // 2 Bytes
  213.     unsigned short                flags;                // 2 Bytes
  214.     unsigned char                normalx;            // 1 Byte
  215.     unsigned char                normaly;            // 1 Byte
  216.     unsigned char                height;                // 1 Byte
  217.     unsigned char                weight;                // 1 Byte
  218.  
  219.     idVec3&            Normal();
  220.     idVec3&            Origin();
  221.  
  222.     void            DrawDebugInfo( int index=-1 );
  223.       int                GetLookPos( idVec3& lookPos, const idVec3& aimAtOrigin, const float leanDistance=16.0f );
  224. } aasFeature_t;                                        //--------------------------------
  225.                                                     // 12 Bytes
  226. // RAVEN END
  227.  
  228. // trace through the world
  229. typedef struct aasTrace_s {
  230.                                 // parameters
  231.     int                            flags;                // areas with these flags block the trace
  232.     int                            travelFlags;        // areas with these travel flags block the trace
  233.     int                            maxAreas;            // size of the 'areas' array
  234.     int                            getOutOfSolid;        // trace out of solid if the trace starts in solid
  235.                                 // output
  236.     float                        fraction;            // fraction of trace completed
  237.     idVec3                        endpos;                // end position of trace
  238.     int                            planeNum;            // plane hit
  239.     int                            lastAreaNum;        // number of last area the trace went through
  240.     int                            blockingAreaNum;    // area that could not be entered
  241.     int                            numAreas;            // number of areas the trace went through
  242.     int *                        areas;                // array to store areas the trace went through
  243.     idVec3 *                    points;                // points where the trace entered each new area
  244.                                 aasTrace_s( void ) { areas = NULL; points = NULL; getOutOfSolid = false; flags = travelFlags = maxAreas = 0; }
  245. } aasTrace_t;
  246.  
  247. // settings
  248. class idAASSettings {
  249. public:
  250.                                 // collision settings
  251.     int                            numBoundingBoxes;
  252.     idBounds                    boundingBoxes[MAX_AAS_BOUNDING_BOXES];
  253.     bool                        usePatches;
  254.     bool                        writeBrushMap;
  255.     bool                        playerFlood;
  256.     bool                        noOptimize;
  257.     bool                        allowSwimReachabilities;
  258.     bool                        allowFlyReachabilities;
  259. // RAVEN BEGIN
  260. // cdr: AASTactical
  261.     bool                        generateTacticalFeatures;
  262. // scork: AASOnly numbers
  263.     int                            iAASOnly;    // 0, else 32,48,96,250 or -1 for all
  264. // RAVEN END
  265.     idStr                        fileExtension;
  266.                                 // physics settings
  267.     idVec3                        gravity;
  268.     idVec3                        gravityDir;
  269.     idVec3                        invGravityDir;
  270.     float                        gravityValue;
  271.     float                        maxStepHeight;
  272.     float                        maxBarrierHeight;
  273.     float                        maxWaterJumpHeight;
  274.     float                        maxFallHeight;
  275.     float                        minFloorCos;
  276.                                 // fixed travel times
  277.     int                            tt_barrierJump;
  278.     int                            tt_startCrouching;
  279.     int                            tt_waterJump;
  280.     int                            tt_startWalkOffLedge;
  281.  
  282. // RAVEN BEGIN 
  283. // rjohnson: added more debug drawing
  284.     idVec4                        debugColor;
  285.     bool                        debugDraw;
  286. // RAVEN END
  287.  
  288. public:
  289.                                 idAASSettings( void );
  290.  
  291.     bool                        FromFile( const idStr &fileName );
  292. // RAVEN BEGIN
  293. // jsinger: changed to be Lexer instead of idLexer so that we have the ability to read binary files
  294.     bool                        FromParser( Lexer &src );
  295. // RAVEN END
  296.     bool                        FromDict( const char *name, const idDict *dict );
  297.     bool                        WriteToFile( idFile *fp ) const;
  298.     bool                        ValidForBounds( const idBounds &bounds ) const;
  299.     bool                        ValidEntity( const char *classname, bool* needFlyReachabilities=NULL ) const;
  300.  
  301. // RAVEN BEGIN
  302.     float                        Radius( float scale=1.0f ) const;
  303. // RAVEN END
  304.  
  305.  
  306. private:
  307. // RAVEN BEGIN
  308. // jsinger: changed to be Lexer instead of idLexer so that we have the ability to read binary files
  309.     bool                        ParseBool( Lexer &src, bool &b );
  310.     bool                        ParseInt( Lexer &src, int &i );
  311.     bool                        ParseFloat( Lexer &src, float &f );
  312.     bool                        ParseVector( Lexer &src, idVec3 &vec );
  313.     bool                        ParseBBoxes( Lexer &src );
  314. // RAVEN END
  315. };
  316.  
  317.  
  318. /*
  319.  
  320. -    when a node child is a solid leaf the node child number is zero
  321. -    two adjacent areas (sharing a plane at opposite sides) share a face
  322.     this face is a portal between the areas
  323. -    when an area uses a face from the faceindex with a positive index
  324.     then the face plane normal points into the area
  325. -    the face edges are stored counter clockwise using the edgeindex
  326. -    two adjacent convex areas (sharing a face) only share One face
  327.     this is a simple result of the areas being convex
  328. -    the areas can't have a mixture of ground and gap faces
  329.     other mixtures of faces in one area are allowed
  330. -    areas with the AREACONTENTS_CLUSTERPORTAL in the settings have
  331.     the cluster number set to the negative portal number
  332. -    edge zero is a dummy
  333. -    face zero is a dummy
  334. -    area zero is a dummy
  335. -    node zero is a dummy
  336. -    portal zero is a dummy
  337. -    cluster zero is a dummy
  338.  
  339. */
  340. typedef struct sizeEstimate_s {
  341.     int            numEdgeIndexes;
  342.     int            numFaceIndexes;
  343.     int            numAreas;
  344.     int            numNodes;
  345. } sizeEstimate_t;
  346.  
  347.  
  348. class idAASFile {
  349. public:    
  350.     virtual                         ~idAASFile( void ) {}
  351. // RAVEN BEGIN
  352. // jscott: made pure virtual
  353.     virtual class idAASFile    *        CreateNew( void ) = 0;
  354.     virtual class idAASSettings *    CreateAASSettings( void ) = 0;
  355.     virtual class idReachability *    CreateReachability( int type ) = 0;
  356. // RAVEN BEGIN
  357. // jsinger: changed to be Lexer instead of idLexer so that we have the ability to read binary files
  358.     virtual bool                    FromParser( class idAASSettings *edit, Lexer &src ) = 0;
  359. // RAVEN END
  360.  
  361.     virtual    const char *            GetName( void ) const = 0;
  362.     virtual    unsigned int            GetCRC( void ) const = 0;
  363.     virtual    void                    SetSizes( sizeEstimate_t size ) = 0;
  364.  
  365.     virtual    int                        GetNumPlanes( void ) const = 0;
  366.     virtual    idPlane &                GetPlane( int index ) = 0;
  367.     virtual int                        FindPlane( const idPlane &plane, const float normalEps, const float distEps ) = 0;
  368.  
  369.     virtual    int                        GetNumVertices( void ) const = 0;
  370.     virtual    aasVertex_t &            GetVertex( int index ) = 0;
  371.     virtual int                        AppendVertex( aasVertex_t &vert ) = 0;
  372.  
  373.     virtual    int                        GetNumEdges( void ) const = 0;
  374.     virtual    aasEdge_t &                GetEdge( int index ) = 0;
  375.     virtual int                        AppendEdge( aasEdge_t &edge ) = 0;
  376.  
  377.     virtual    int                        GetNumEdgeIndexes( void ) const = 0;
  378.     virtual    aasIndex_t &            GetEdgeIndex( int index ) = 0;
  379.     virtual int                        AppendEdgeIndex( aasIndex_t &edgeIdx ) = 0;
  380.  
  381.     virtual    int                        GetNumFaces( void ) const = 0;
  382.     virtual    aasFace_t &                GetFace( int index ) = 0;
  383.     virtual int                        AppendFace( aasFace_t &face ) = 0;
  384.  
  385.     virtual    int                        GetNumFaceIndexes( void ) const = 0;
  386.     virtual    aasIndex_t &            GetFaceIndex( int index ) = 0;
  387.     virtual int                        AppendFaceIndex( aasIndex_t &faceIdx ) = 0;
  388.  
  389.     virtual    int                        GetNumAreas( void ) const = 0;
  390.     virtual    aasArea_t &                GetArea( int index ) = 0;
  391.     virtual int                        AppendArea( aasArea_t &area ) = 0;
  392.  
  393.     virtual    int                        GetNumNodes( void ) const = 0;
  394.     virtual    aasNode_t &                GetNode( int index ) = 0;
  395.     virtual int                        AppendNode( aasNode_t &node ) = 0;
  396.     virtual void                    SetNumNodes( int num ) = 0;
  397.  
  398.     virtual    int                        GetNumPortals( void ) const = 0;
  399.     virtual    aasPortal_t &            GetPortal( int index ) = 0;
  400.     virtual int                        AppendPortal( aasPortal_t &portal ) = 0;
  401.  
  402.     virtual    int                        GetNumPortalIndexes( void ) const = 0;
  403.     virtual    aasIndex_t &            GetPortalIndex( int index ) = 0;
  404.     virtual int                        AppendPortalIndex( aasIndex_t &portalIdx, int clusterNum ) = 0;
  405.  
  406.     virtual    int                        GetNumClusters( void ) const = 0;
  407.     virtual    aasCluster_t &            GetCluster( int index ) = 0;
  408.     virtual int                        AppendCluster( aasCluster_t &cluster ) = 0;
  409.  
  410.     // RAVEN BEGIN
  411.     // cdr: AASTactical
  412.     virtual void                    ClearTactical( void ) = 0;
  413.  
  414.     virtual    int                        GetNumFeatureIndexes( void ) const = 0;
  415.     virtual    aasIndex_t &            GetFeatureIndex( int index ) = 0;
  416.     virtual int                        AppendFeatureIndex( aasIndex_t &featureIdx ) = 0;
  417.  
  418.     virtual    int                        GetNumFeatures( void ) const = 0;
  419.     virtual    aasFeature_t &            GetFeature( int index ) = 0;
  420.     virtual int                        AppendFeature( aasFeature_t &cluster ) = 0;
  421.     // RAVEN END
  422.  
  423.     virtual    idAASSettings &            GetSettings( void ) = 0;
  424.     virtual    void                    SetSettings( const idAASSettings &in ) = 0;
  425.  
  426.     virtual void                    SetPortalMaxTravelTime( int index, int time ) = 0;
  427.     virtual void                    SetAreaTravelFlag( int index, int flag ) = 0;
  428.     virtual void                    RemoveAreaTravelFlag( int index, int flag ) = 0;
  429. // RAVEN END
  430.  
  431.     virtual idVec3                EdgeCenter( int edgeNum ) const = 0;
  432.     virtual idVec3                FaceCenter( int faceNum ) const = 0;
  433.     virtual idVec3                AreaCenter( int areaNum ) const = 0;
  434.  
  435.     virtual idBounds            EdgeBounds( int edgeNum ) const = 0;
  436.     virtual idBounds            FaceBounds( int faceNum ) const = 0;
  437.     virtual idBounds            AreaBounds( int areaNum ) const = 0;
  438.  
  439.     virtual int                    PointAreaNum( const idVec3 &origin ) const = 0;
  440.     virtual int                    PointReachableAreaNum( const idVec3 &origin, const idBounds &searchBounds, const int areaFlags, const int excludeTravelFlags ) const = 0;
  441.     virtual int                    BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags, const int excludeTravelFlags ) const = 0;
  442.     virtual void                PushPointIntoAreaNum( int areaNum, idVec3 &point ) const = 0;
  443.     virtual bool                Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const = 0;
  444.     virtual void                PrintInfo( void ) const = 0;
  445. // RAVEN BEGIN
  446. // jscott: added
  447.     virtual size_t                GetMemorySize( void ) = 0;
  448.  
  449.     virtual    void                Init( void ) = 0;
  450.     virtual bool                Load( const idStr &fileName, unsigned int mapFileCRC ) = 0;
  451.     virtual    bool                Write( const idStr &fileName, unsigned int mapFileCRC ) = 0;
  452.     virtual    void                Clear( void ) = 0;
  453.     virtual    void                FinishAreas( void ) = 0;
  454.     virtual    void                ReportRoutingEfficiency( void ) const = 0;
  455.     virtual    void                LinkReversedReachability( void ) = 0;
  456.     virtual    void                DeleteReachabilities( void ) = 0;
  457.     virtual    void                DeleteClusters( void ) = 0;
  458.     virtual    void                Optimize( void ) = 0;
  459.     virtual bool                IsDummyFile( unsigned int mapFileCRC ) = 0;
  460. // RAVEN END
  461. };
  462.  
  463. // RAVEN BEGIN
  464. extern idAASFile        *AASFile;
  465. // RAVEN END
  466.  
  467. #endif /* !__AASFILE_H__ */
  468.