BWAPI
trunk/bwapi/BWAPI/Source/BW/Pathing.h
Go to the documentation of this file.
00001 #pragma once
00002 #pragma pack(1)
00003 #include "Position.h"
00004 #include <Util/Types.h>
00005 #include <set>
00006 #include <list>
00007 #include <vector>
00008 
00009 #define getRegionFromId(x) (&(BW::BWDATA_SAIPathing->regions[(x)&0x1FFF]))
00010 
00011 namespace BW
00012 {
00013   struct pathPoint
00014   {
00015     u16 x;
00016     u16 y;
00017   };
00018 
00019   struct pathBox
00020   {
00021     s16 x1;
00022     s16 y1;
00023     s16 x2;
00024     s16 y2;
00025   };
00026 
00027   struct pathRect
00028   {
00029     u16 left;
00030     u16 top;
00031     u16 right;
00032     u16 bottom;
00033   };
00034 
00035   class region
00036   {
00037   public:
00038     bool                  isConnectedTo(region *target);
00039     bool                  isConnectedTo(u16 index);
00040     std::vector<region*>  &getAccessibleNeighbours();
00041     int                   getAirDistance(region *dst);
00042     region                *getNeighbor(u8 index);
00043     Position              getCenter();
00044     u16                   getIndex();
00045 
00046     /*0x00*/u16       accessabilityFlags;
00047                       // 0x1FF9 = High ground    1001
00048                       // 0x1FFB = Low ground     1011
00049                       // 0x1FFD = Inaccessible   1101
00050     /*0x02*/u16       groupIndex; // Identifies connected regions
00051     /*0x04*/u16       tileCount;
00052     /*0x06*/u8        pathCount;
00053     /*0x07*/u8        neighborCount;
00054     /*0x08*/u32       unk_8;
00055     /*0x0C*/u16       *neighbors; // allocated array of IDs for neighbors
00056     /*0x10*/u32       rgnCenterX; // must >> 8; in pixels
00057     /*0x14*/u32       rgnCenterY; // must >> 8; in pixels
00058     /*0x18*/pathRect  rgnBox; // in pixels
00059     /*0x20*/u32       properties; // flags
00060                       /*
00061                         0x001 = Key Point
00062                         0x002 = Choke Point/Corridor
00063                         0x100 = Map Bottom
00064                       */
00065     /*0x24*/u32       unk_24;
00066     /*0x28*/u32       unk_28;
00067     /*0x2C*/u16       localBuffer[10]; // local array of IDs for neighbors
00068   };
00069 
00070   CTASSERT( sizeof(region) == 64 );
00071 
00072   /* Contour IDs and values:
00073      0: BOTTOM: y1, x1, x2
00074      1: LEFT;   x1, y1, y2
00075      2: TOP;    y1, x1, x2
00076      3: RIGHT:  x1, y1, y2
00077 
00078     In Starcraft Beta they are labelled opposite: TOP, RIGHT, BOTTOM, LEFT
00079     Additional Beta Notes:
00080 
00081     Involving a 16-byte const array:
00082       LEFT_TURN  = true;
00083       RIGHT_TURN = false;
00084   */
00085   struct contour
00086   {
00087     s16 v[3];
00088     u8  type;
00089     u8  unk_relation;   // Relation to neighboring contours. The highest 2 bits are unused.
00090                         // bitwise:   YY XXXX
00091                         // Where YY is the neighboring contours direction; 
00092                         //    1 = in, 0 = out; One bit for each neighbor
00093                         // And XXXX is a unique ID for the combination, used for an unknown array.
00094   };
00095 
00096   struct contourHub
00097   {
00098     contour *contours[4];
00099     u16     contourCount[4];
00100     u16     contourMax[4];
00101     s16     searchInner[4];
00102     s16     unk_28[4];
00103     s16     searchOuter[4];
00104   };
00105 
00106   struct split
00107   {
00108     u16 minitileMask; // 16 minitiles per tile corresponds to 16 bits;
00109     u16 rgn1;         // region with unset bits
00110     u16 rgn2;         // region with set   bits
00111   };
00112 
00113   struct SAI_Paths
00114   {
00115     u32        regionCount;
00116     void       *globalBuffer_ptr;
00117     void       *splitTiles_end;
00118     u16        mapTileRegionId[256][256];   // rgnId is &0x1FFF; split = &0x2000, 
00119     split      splitTiles[25000];     // 0x2000C
00120     region     regions[5000];         // 0x449FC
00121     u16        globalBuffer[10000];   // 0x92BFC; extra buffer used for large neighbor ID arrays
00122     contourHub *contours;             // 0x97A1C
00123   };
00124 
00125   bool isCollidingWithContour(contourHub *hub, int x, int y, int left, int top, int right, int bottom);
00126 }
00127 
00128 #pragma pack()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines