BWAPI
|
00001 #pragma once 00002 00003 #include "Interface.h" 00004 #include <deque> 00005 #include <sstream> 00006 00007 #include "Singleton.h" 00008 #include "BuildOrder.h" 00009 #include "TypeSafeEnum.h" 00010 #include "TrainTask.h" 00011 #include "UnitTracker.h" 00012 00013 struct TrainTypeDef 00014 { 00015 enum type 00016 { 00017 Normal, 00018 LowMineral, 00019 LowGas 00020 }; 00021 }; 00022 typedef SafeEnum<TrainTypeDef> TrainType; 00023 00024 class MacroItem 00025 { 00026 public: 00027 MacroItem() : mUnit(BWAPI::UnitTypes::None), mTech(BWAPI::TechTypes::None), mUpgrade(BWAPI::UpgradeTypes::None), mLevel(0), mPriority(0){} 00028 MacroItem(BWAPI::UnitType unit, int priority) : mUnit(unit), mTech(BWAPI::TechTypes::None), mUpgrade(BWAPI::UpgradeTypes::None), mLevel(0), mPriority(priority){} 00029 MacroItem(BWAPI::TechType tech, int priority) : mUnit(BWAPI::UnitTypes::None), mTech(tech), mUpgrade(BWAPI::UpgradeTypes::None), mLevel(0), mPriority(priority){} 00030 MacroItem(BWAPI::UpgradeType upgrade, int level, int priority) : mUnit(BWAPI::UnitTypes::None), mTech(BWAPI::TechTypes::None), mUpgrade(upgrade), mLevel(level), mPriority(priority){} 00031 00032 std::string getDebugInfo() const 00033 { 00034 std::stringstream returnString; 00035 returnString << mPriority << " : "; 00036 00037 if(mUnit != BWAPI::UnitTypes::None) 00038 returnString << mUnit.getName(); 00039 else if(mTech != BWAPI::TechTypes::None) 00040 returnString << mTech.getName(); 00041 else if(mUpgrade != BWAPI::UpgradeTypes::None) 00042 returnString << mUpgrade.getName() << " (" << mLevel << ")"; 00043 else 00044 returnString << "null"; 00045 00046 return returnString.str(); 00047 } 00048 00049 bool isUnitType() const { return mUnit != BWAPI::UnitTypes::None; } 00050 bool isTechType() const { return mTech != BWAPI::TechTypes::None; } 00051 bool isUpgradeType() const { return mUpgrade != BWAPI::UpgradeTypes::None; } 00052 00053 BWAPI::UnitType getUnitType() const { return mUnit; } 00054 BWAPI::TechType getTechType() const { return mTech; } 00055 BWAPI::UpgradeType getUpgradeType() const { return mUpgrade; } 00056 00057 int getUpgradeLevel() const { return mLevel; } 00058 00059 int getPriority() const { return mPriority; } 00060 00061 bool inProgress() const; 00062 00063 TaskPointer createTask(TaskType taskType) const; 00064 00065 private: 00066 BWAPI::UnitType mUnit; 00067 BWAPI::TechType mTech; 00068 BWAPI::UpgradeType mUpgrade; 00069 int mLevel; 00070 00071 int mPriority; 00072 }; 00073 00074 class MacroManagerClass 00075 { 00076 public: 00077 MacroManagerClass(){} 00078 00079 void onBegin(); 00080 void update(); 00081 void updateTaskLists(); 00082 00083 void updateUnitProduction(); 00084 void updateObserverProduction(); 00085 void updateProductionProduction(); 00086 void updateTech(); 00087 00088 void onChangeBuild(); 00089 00090 bool hasRequirements(BWAPI::UnitType type); 00091 bool hasRequirements(BWAPI::TechType type); 00092 bool hasRequirements(BWAPI::UpgradeType type, int level); 00093 00094 int getPlannedCount(BWAPI::UnitType unitType); 00095 int getPlannedTotal(BWAPI::UnitType unitType); 00096 bool isPlanningUnit(BWAPI::UnitType unitType); 00097 00098 int getPlannedCount(BWAPI::TechType techType); 00099 int getPlannedTotal(BWAPI::TechType techType); 00100 bool isPlanningTech(BWAPI::TechType techType); 00101 00102 int getPlannedCount(BWAPI::UpgradeType upgradeType, int level); 00103 int getPlannedTotal(BWAPI::UpgradeType upgradeType, int level); 00104 bool isPlanningUpgrade(BWAPI::UpgradeType upgradeType, int level); 00105 00106 std::set<BWAPI::UnitType> getNeededUnits(BWAPI::UnitType type); 00107 std::set<BWAPI::UnitType> getNeededUnits(BWAPI::TechType type); 00108 std::set<BWAPI::UnitType> getNeededUnits(BWAPI::UpgradeType type, int level); 00109 00110 void onBuildTask(TaskPointer task, BWAPI::UnitType unitType); 00111 void onTechTask(TaskPointer task,BWAPI::TechType techType); 00112 void onUpgradeTask(TaskPointer task, BWAPI::UpgradeType upgradeType, int level); 00113 00114 private: 00115 std::map<BWAPI::TechType, int> mTechPriorityMap; 00116 std::map<BWAPI::UpgradeType, int> mUpgradePriorityMap; 00117 00118 std::list<UnitToProduce> mNormalUnits; 00119 std::list<UnitToProduce> mLowGasUnits; 00120 std::list<UnitToProduce> mLowMineralUnits; 00121 00122 std::list<std::pair<TaskPointer, BWAPI::UnitType>> mUnitProduce; 00123 std::map<BWAPI::UnitType, std::list<TaskPointer>> mTasksPerProductionType; 00124 std::map<BWAPI::TechType, std::list<TaskPointer>> mTasksPerTechType; 00125 std::map<BWAPI::UpgradeType, std::map<int, std::list<TaskPointer>>> mTasksPerUpgradeType; 00126 std::map<BWAPI::UnitType, std::list<TaskPointer>> mTasksPerProducedType; 00127 00128 TaskPointer mObserver; 00129 00130 std::list<MacroItem> mTechItemsToCreate; 00131 std::list<std::pair<MacroItem, TaskPointer>> mTechItems; 00132 00133 void addNeeded(std::set<BWAPI::UnitType> &neededUnits); 00134 void createTechItems(); 00135 }; 00136 00137 typedef Singleton<MacroManagerClass> MacroManager;