BWAPI
|
00001 #ifndef __EXPLORATIONMANAGER_H__ 00002 #define __EXPLORATIONMANAGER_H__ 00003 00004 #include "UnitAgent.h" 00005 #include "SpottedObject.h" 00006 #include "Squad.h" 00007 00008 using namespace BWAPI; 00009 using namespace BWTA; 00010 using namespace std; 00011 00012 struct ForceData { 00013 int airAttackStr; 00014 int airDefendStr; 00015 int groundAttackStr; 00016 int groundDefendStr; 00017 00018 int noRefineries; 00019 int noCommandCenters; 00020 int noFactories; 00021 int noAirports; 00022 int noBarracks; 00023 int noDefenseStructures; 00024 int noDetectorStructures; 00025 int noDetectorUnits; 00026 00027 void reset() { 00028 airAttackStr = 0; 00029 airDefendStr = 0; 00030 groundAttackStr = 0; 00031 groundDefendStr = 0; 00032 00033 noRefineries = 0; 00034 noCommandCenters = 0; 00035 noFactories = 0; 00036 noAirports = 0; 00037 noBarracks = 0; 00038 noDefenseStructures = 0; 00039 noDetectorStructures = 0; 00040 noDetectorUnits = 0; 00041 } 00042 00043 void checkType(UnitType type) { 00044 if (type.isRefinery()) { 00045 noRefineries++; 00046 } 00047 if (type.isResourceDepot()) { 00048 noCommandCenters++; 00049 } 00050 if (type.isBuilding() && type.isDetector()) { 00051 noDetectorStructures++; 00052 } 00053 if (!type.isBuilding() && type.isDetector()) { 00054 noDetectorUnits++; 00055 } 00056 if (type.isBuilding() && type.canAttack()) { 00057 noDefenseStructures++; 00058 } 00059 if (type.getID() == UnitTypes::Terran_Bunker.getID()) { 00060 noDefenseStructures++; 00061 } 00062 if (type.getID() == UnitTypes::Terran_Starport.getID() || type.getID() == UnitTypes::Protoss_Stargate.getID()) { 00063 noAirports++; 00064 } 00065 if (type.getID() == UnitTypes::Terran_Barracks.getID() || type.getID() == UnitTypes::Protoss_Gateway.getID()) { 00066 noBarracks++; 00067 } 00068 if (type.getID() == UnitTypes::Terran_Factory.getID() || type.getID() == UnitTypes::Protoss_Gateway.getID() || type.getID() == UnitTypes::Protoss_Robotics_Facility.getID()) { 00069 noFactories++; 00070 } 00071 } 00072 }; 00073 00074 struct ExploreData { 00075 TilePosition center; 00076 int lastVisitFrame; 00077 00078 ExploreData(Position tCenter) { 00079 center = TilePosition(tCenter); 00080 lastVisitFrame = 0; 00081 } 00082 00083 int getX() { 00084 return center.x(); 00085 } 00086 00087 int getY() { 00088 return center.y(); 00089 } 00090 00091 bool matches(Region* region) { 00092 if (region == NULL) { 00093 return false; 00094 } 00095 TilePosition tCenter = TilePosition(region->getCenter()); 00096 return matches(tCenter); 00097 } 00098 00099 bool matches(TilePosition tCenter) { 00100 double dist = tCenter.getDistance(center); 00101 if (dist <= 2) { 00102 return true; 00103 } 00104 return false; 00105 } 00106 }; 00107 00116 class ExplorationManager { 00117 00118 private: 00119 vector<SpottedObject*> spottedBuildings; 00120 vector<SpottedObject*> spottedUnits; 00121 00122 vector<ExploreData> exploreData; 00123 int getLastVisitFrame(Region* region); 00124 00125 ForceData ownForce; 00126 ForceData enemyForce; 00127 00128 ExplorationManager(); 00129 static ExplorationManager* instance; 00130 static bool instanceFlag; 00131 00132 void calcEnemyForceData(); 00133 void calcOwnForceData(); 00134 00135 void cleanup(); 00136 00137 bool active; 00138 00139 int lastCallFrame; 00140 00141 int siteSetFrame; 00142 TilePosition expansionSite; 00143 00144 public: 00146 ~ExplorationManager(); 00147 00149 static ExplorationManager* getInstance(); 00150 00152 void setInactive(); 00153 00155 bool isActive(); 00156 00158 void computeActions(); 00159 00161 TilePosition getNextToExplore(Squad* squad); 00162 00164 TilePosition searchExpansionSite(); 00165 00167 TilePosition getExpansionSite(); 00168 00170 void setExpansionSite(TilePosition pos); 00171 00173 void printInfo(); 00174 00176 void addSpottedUnit(Unit* unit); 00177 00180 void unitDestroyed(Unit* unit); 00181 00183 vector<SpottedObject*> getSpottedBuildings(); 00184 00187 TilePosition getClosestSpottedBuilding(TilePosition start); 00188 00190 int spottedBuildingsWithinRange(TilePosition pos, int range); 00191 00193 bool buildingsSpotted(); 00194 00196 void showIntellData(); 00197 00200 static bool canReach(TilePosition a, TilePosition b); 00201 00203 static bool canReach(BaseAgent* agent, TilePosition b); 00204 00207 void setExplored(TilePosition goal); 00208 00210 TilePosition scanForVulnerableBase(); 00211 00213 bool isDetectorCovering(TilePosition pos); 00214 00216 bool isDetectorCovering(Position pos); 00217 00219 static bool enemyIsProtoss(); 00220 00222 static bool enemyIsZerg(); 00223 00225 static bool enemyIsTerran(); 00226 00228 static bool enemyIsUnknown(); 00229 }; 00230 00231 #endif