|
BWAPI
|
00001 #pragma once 00002 00003 #include "Common.h" 00004 #include "CombatCommander.h" 00005 #include "UnitInfoState.h" 00006 #include "MapGrid.h" 00007 #include "base/WorkerManager.h" 00008 #include "base/ProductionManager.h" 00009 #include "base/BuildingManager.h" 00010 #include "ScoutManager.h" 00011 #include "StrategyManager.h" 00012 00013 #include "starcraftsearch\Timer.hpp" 00014 00015 class TimerManager 00016 { 00017 00018 std::vector<Timer> timers; 00019 std::vector<std::string> timerNames; 00020 00021 int barWidth; 00022 00023 public: 00024 00025 enum Type { All, Worker, Production, Building, Combat, Scout, UnitInfoState, MapGrid, MapTools, Search, NumTypes }; 00026 00027 00028 TimerManager() : timers(std::vector<Timer>(NumTypes)), barWidth(40) 00029 { 00030 timerNames.push_back("Total"); 00031 timerNames.push_back("Worker"); 00032 timerNames.push_back("Production"); 00033 timerNames.push_back("Building"); 00034 timerNames.push_back("Combat"); 00035 timerNames.push_back("Scout"); 00036 timerNames.push_back("UnitInfo"); 00037 timerNames.push_back("MapGrid"); 00038 timerNames.push_back("MapTools"); 00039 timerNames.push_back("Search"); 00040 } 00041 00042 ~TimerManager() {} 00043 00044 void startTimer(const TimerManager::Type t) 00045 { 00046 timers[t].start(); 00047 } 00048 00049 void stopTimer(const TimerManager::Type t) 00050 { 00051 timers[t].stop(); 00052 } 00053 00054 double getTotalElapsed() 00055 { 00056 return timers[0].getElapsedTimeInMilliSec(); 00057 } 00058 00059 void displayTimers(int x, int y) 00060 { 00061 if (DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawBoxScreen(x-5, y-5, x+110+barWidth, y+5+(10*timers.size()), BWAPI::Colors::Black, true); 00062 00063 int yskip = 0; 00064 double total = timers[0].getElapsedTimeInMilliSec(); 00065 for (size_t i(0); i<timers.size(); ++i) 00066 { 00067 double elapsed = timers[i].getElapsedTimeInMilliSec(); 00068 00069 int width = (int)((elapsed == 0) ? 0 : (barWidth * (elapsed / total))); 00070 00071 if (DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawTextScreen(x, y+yskip-3, "\x04 %s", timerNames[i].c_str()); 00072 if (DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawBoxScreen(x+60, y+yskip, x+60+width+1, y+yskip+8, BWAPI::Colors::White); 00073 if (DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawTextScreen(x+70+barWidth, y+yskip-3, "%.4lf", elapsed); 00074 yskip += 10; 00075 } 00076 } 00077 }; 00078 00079 class UnitToAssign 00080 { 00081 public: 00082 00083 BWAPI::Unit * unit; 00084 bool isAssigned; 00085 00086 UnitToAssign(BWAPI::Unit * u) 00087 { 00088 unit = u; 00089 isAssigned = false; 00090 } 00091 }; 00092 00093 class GameCommander { 00094 00095 CombatCommander combatCommander; 00096 ScoutManager scoutManager; 00097 TimerManager timerManager; 00098 00099 // pair is (unit pointer, isAlreadyAssigned) 00100 std::vector<UnitToAssign> validUnits; 00101 00102 UnitVector combatUnits; 00103 UnitVector scoutUnits; 00104 UnitVector workerUnits; 00105 00106 BWAPI::Unit * currentScout; 00107 int numWorkerScouts; 00108 00109 public: 00110 00111 GameCommander(); 00112 ~GameCommander() {}; 00113 00114 void update(); 00115 00116 void populateUnitVectors(); 00117 void setValidUnits(); 00118 void setScoutUnits(); 00119 void setWorkerUnits(); 00120 void setCombatUnits(); 00121 00122 bool isValidUnit(BWAPI::Unit * unit); 00123 bool isCombatUnit(BWAPI::Unit * unit) const; 00124 00125 BWAPI::Unit * getFirstSupplyProvider(); 00126 int getClosestUnitToTarget(BWAPI::UnitType type, BWAPI::Position target); 00127 00128 void onSendText(std::string text); 00129 void onUnitShow(BWAPI::Unit * unit); 00130 void onUnitHide(BWAPI::Unit * unit); 00131 void onUnitCreate(BWAPI::Unit * unit); 00132 void onUnitRenegade(BWAPI::Unit * unit); 00133 void onUnitDestroy(BWAPI::Unit * unit); 00134 void onUnitMorph(BWAPI::Unit * unit); 00135 };
1.7.6.1