BWAPI
|
00001 #ifndef __COMMANDER_H__ 00002 #define __COMMANDER_H__ 00003 00004 #include "Squad.h" 00005 #include "BaseAgent.h" 00006 00007 using namespace BWAPI; 00008 using namespace BWTA; 00009 using namespace std; 00010 00011 struct SortSquadList { 00012 bool operator()(Squad*& sq1, Squad*& sq2) { 00013 if (sq1->getPriority() != sq2->getPriority()) { 00014 return sq1->getPriority() < sq2->getPriority(); 00015 } 00016 else { 00017 if (sq1->isRequired() && !sq2->isRequired()) return true; 00018 else return false; 00019 } 00020 } 00021 }; 00022 00034 class Commander { 00035 00036 private: 00037 bool chokePointFortified(TilePosition center); 00038 bool chokePointGuarded(TilePosition center); 00039 void sortSquadList(); 00040 bool isOccupied(Region* region); 00041 bool isEdgeChokepoint(Chokepoint* choke); 00042 double getDistToBase(Chokepoint* choke); 00043 TilePosition findDefensePos(Chokepoint* choke); 00044 double getChokepointPrio(TilePosition center); 00045 00046 void checkNoSquadUnits(); 00047 void assignUnit(BaseAgent* agent); 00048 00049 int lastCallFrame; 00050 00051 protected: 00052 vector<Squad*> squads; 00053 int currentID; 00054 static Commander* instance; 00055 00056 int currentState; 00057 static const int DEFEND = 0; 00058 static const int ATTACK = 1; 00059 00060 Commander(); 00061 00064 TilePosition findOffensiveSquadPosition(TilePosition closeEnemy); 00065 00066 public: 00068 ~Commander(); 00069 00071 static Commander* getInstance(); 00072 00074 void computeActions(); 00075 00078 bool shallEngage(); 00079 00080 void updateGoals(); 00081 00084 void unitCreated(BaseAgent* agent); 00085 00088 void unitDestroyed(BaseAgent* agent); 00089 00090 /* Checks if the specified unittype needs to be built. */ 00091 bool needUnit(UnitType type); 00092 00094 Squad* getSquad(int id); 00095 00097 vector<Squad*> getSquads(); 00098 00101 TilePosition getClosestEnemyBuilding(TilePosition start); 00102 00105 int noOffensiveSquadsWithin(TilePosition center, int maxRange); 00106 00109 bool checkWorkersAttack(BaseAgent* base); 00110 00112 void assistBuilding(BaseAgent* building); 00113 00115 void assistWorker(BaseAgent* worker); 00116 00118 int enemyUnitsWithinRange(TilePosition start, int range); 00119 00121 void handleCloakedEnemy(TilePosition pos, Squad* squad); 00122 00125 void checkRemovableObstacles(); 00126 00128 void forceAttack(); 00129 00131 void printInfo(); 00132 00135 TilePosition findUnfortifiedChokePoint(); 00136 00138 TilePosition findChokePoint(); 00139 00141 bool isPowered(TilePosition pos); 00142 00144 bool isBuildable(TilePosition pos); 00145 00147 bool checkUnfinishedBuildings(); 00148 00150 bool checkRepairUnits(); 00151 00155 bool isImportantUnit(Unit* unit); 00156 00158 void repair(BaseAgent* agent); 00159 00161 void finishBuild(BaseAgent* agent); 00162 00164 int ownDeadScore; 00165 00167 int enemyDeadScore; 00168 00170 void addBunkerSquad(); 00171 }; 00172 00173 #endif