BWAPI
trunk/bwapi/BWScriptEmulator/ScriptThread.h
Go to the documentation of this file.
00001 #include <windows.h>
00002 #include <BWAPI.h>
00003 
00004 #include <list>
00005 #include <deque>
00006 
00007 void UpdateScripts();
00008 bool LoadAIBinary(const char *pszFileName);
00009 int GetStandardUnitCount(BWAPI::UnitType type, bool bCompleted = true, BWAPI::Player *player = NULL);
00010 
00011 void AICreateThread(WORD wStartBlock, BWAPI::Position location, void *pTown = NULL);
00012 void AICreateThread(char *pszScriptID, BWAPI::Position location);
00013 
00014 #define AI_THREAD_BROODWAR        0x01
00015 #define AI_THREAD_KILLABLE        0x02
00016 #define AI_THREAD_WANT_KILLED     0x04
00017 #define AI_THREAD_TARG_EXPANSION  0x08
00018 
00019 class aithread
00020 {
00021 public:
00022   aithread();
00023   aithread(WORD wStartBlock, BWAPI::Position location, void *town = NULL);
00024   ~aithread();
00025   template <class _T>
00026   _T read()
00027   {
00028     _T rval = *(_T*)&pbAIScriptBinary[this->dwScriptOffset];
00029     this->dwScriptOffset += sizeof(_T);
00030     this->dwBytesRead    += sizeof(_T);
00031     return rval;
00032   }
00033   void  execute();
00034   DWORD getFlags();
00035   void  setFlags(DWORD dwFlags);
00036   void  clearFlags(DWORD dwFlags);
00037   DWORD sleep();
00038   void  killThread();
00039   void  showDebug(int x, int y);
00040   void  saveDebug(const char *prefix, int iOpcode, const char *pszFormat = NULL, ...);
00041   void  retry();
00042 
00043 private:
00044   DWORD             dwScriptOffset;   // the offset in the AIScript file
00045   DWORD             dwSleepTime;      // the number of frames remaining before the thread continues execution
00046   DWORD             dwPlayerID;       // the player index that owns the thread
00047   RECT              locationBounds;   // the location boundry of which the script is executed in
00048   //POINT             locationCenter;   // the center of the location of which the script is executed in
00049   BWAPI::Position   locationCenter;
00050   void              *pTown;           // town information
00051   DWORD             dwFlags;          // the flags for the thread behaviour
00052   BYTE              bTotBuildCount[228]; // not included
00053 
00054   int               threadId;
00055   DWORD             dwBytesRead;
00056   std::deque<char*> debugQueue;
00057 };
00058 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines