BWAPI
|
00001 #pragma once 00002 #include <Arbitrator.h> 00003 #include <BWAPI.h> 00004 #include "UnitItem.h" 00005 #include "TechItem.h" 00006 class BuildManager; 00007 class TechManager; 00008 class UpgradeManager; 00009 class WorkerManager; 00010 class SupplyManager; 00011 class BuildOrderManager 00012 { 00013 public: 00014 class PriorityLevel 00015 { 00016 public: 00017 std::list<TechItem> techs; 00018 std::map<BWAPI::UnitType, std::map<BWAPI::UnitType, UnitItem > > units; 00019 }; 00020 class Resources 00021 { 00022 public: 00023 Resources() : minerals(0),gas(0) {} 00024 Resources(int m, int g) : minerals(m),gas(g) {} 00025 int minerals; 00026 int gas; 00027 }; 00028 class MetaUnit 00029 { 00030 public: 00031 MetaUnit(BWAPI::Unit* unit); 00032 MetaUnit(int larvaSpawnTime); 00033 int nextFreeTime() const; 00034 int nextFreeTime(BWAPI::UnitType t) const; 00035 int nextFreeTime(BWAPI::TechType t) const; 00036 int nextFreeTime(BWAPI::UpgradeType t) const; 00037 BWAPI::UnitType getType() const; 00038 int getRemainingBuildTime() const; 00039 int getRemainingTrainTime() const; 00040 int getRemainingResearchTime() const; 00041 int getRemainingUpgradeTime() const; 00042 BWAPI::UpgradeType getUpgrade() const; 00043 bool hasBuildUnit() const; 00044 bool hasAddon() const; 00045 bool isBeingConstructed() const; 00046 bool isCompleted() const; 00047 bool isMorphing() const; 00048 bool isTraining() const; 00049 bool isUpgrading() const; 00050 BWAPI::Unit* unit; 00051 int larvaSpawnTime; 00052 }; 00053 class Type 00054 { 00055 public: 00056 Type(BWAPI::UnitType t, MetaUnit* unit, int priority, int time=0) : unitType(t), unit(unit), priority(priority), time(time) {} 00057 Type(BWAPI::TechType t, MetaUnit* unit, int priority, int time=0) : techType(t), unit(unit), priority(priority), time(time) {} 00058 Type(BWAPI::UpgradeType t, MetaUnit* unit, int priority, int time=0) : upgradeType(t), unit(unit), priority(priority), time(time) {} 00059 BWAPI::UnitType unitType; 00060 BWAPI::TechType techType; 00061 BWAPI::UpgradeType upgradeType; 00062 MetaUnit* unit; 00063 int priority; 00064 int time; 00065 }; 00066 00067 BuildOrderManager(BuildManager* buildManager, TechManager* techManager, UpgradeManager* upgradeManager, WorkerManager* workerManager, SupplyManager* supplyManager); 00068 void update(); 00069 std::string getName() const; 00070 void build(int count, BWAPI::UnitType t, int priority, BWAPI::TilePosition seedPosition=BWAPI::TilePositions::None); 00071 void buildAdditional(int count, BWAPI::UnitType t, int priority, BWAPI::TilePosition seedPosition=BWAPI::TilePositions::None); 00072 void research(BWAPI::TechType t, int priority); 00073 void upgrade(int level, BWAPI::UpgradeType t, int priority); 00074 bool hasResources(BWAPI::UnitType t); 00075 bool hasResources(BWAPI::TechType t); 00076 bool hasResources(BWAPI::UpgradeType t); 00077 void spendResources(BWAPI::UnitType t); 00078 void spendResources(BWAPI::TechType t); 00079 void spendResources(BWAPI::UpgradeType t); 00080 00081 int getPlannedCount(BWAPI::UnitType t); 00082 int getPlannedCount(BWAPI::UnitType t, int minPriority); 00083 void enableDependencyResolver(); 00084 void setDebugMode(bool debugMode); 00085 std::set<BWAPI::UnitType> unitsCanMake(MetaUnit* builder, int time); 00086 std::set<BWAPI::TechType> techsCanResearch(MetaUnit* techUnit, int time); 00087 std::set<BWAPI::UpgradeType> upgradesCanResearch(MetaUnit* techUnit, int time); 00088 00089 int nextFreeTime(const MetaUnit* unit); 00090 int nextFreeTime(BWAPI::UnitType t); 00091 int nextFreeTime(const MetaUnit* unit, BWAPI::UnitType t); 00092 int nextFreeTime(const MetaUnit* unit, BWAPI::TechType t); 00093 int nextFreeTime(const MetaUnit* unit, BWAPI::UpgradeType t); 00094 std::set<MetaUnit*> MetaUnitPointers; 00095 00096 BuildManager* getBuildManager(); 00097 00098 private: 00099 bool hasResources(BWAPI::UnitType t, int time); 00100 bool hasResources(BWAPI::TechType t, int time); 00101 bool hasResources(BWAPI::UpgradeType t, int time); 00102 bool hasResources(std::pair<int, BuildOrderManager::Resources> res); 00103 std::pair<int, Resources> reserveResources(MetaUnit* builder, BWAPI::UnitType unitType); 00104 std::pair<int, Resources> reserveResources(MetaUnit* techUnit, BWAPI::TechType techType); 00105 std::pair<int, Resources> reserveResources(MetaUnit* techUnit, BWAPI::UpgradeType upgradeType); 00106 void reserveResources(std::pair<int, BuildOrderManager::Resources> res); 00107 void unreserveResources(std::pair<int, BuildOrderManager::Resources> res); 00108 bool updateUnits(); 00109 void updatePlan(); 00110 bool isResourceLimited(); 00111 void removeCompletedItems(PriorityLevel* p); 00112 void debug(const char* text, ...); 00113 BuildManager* buildManager; 00114 TechManager* techManager; 00115 UpgradeManager* upgradeManager; 00116 WorkerManager* workerManager; 00117 SupplyManager* supplyManager; 00118 std::map<int, PriorityLevel > items; 00119 int usedMinerals; 00120 int usedGas; 00121 std::list<MetaUnit> MetaUnits; 00122 std::map<int, Resources> reservedResources; 00123 std::set<MetaUnit*> reservedUnits; 00124 std::map<BWAPI::UnitType,int> currentlyPlannedCount; 00125 std::list<Type> savedPlan; 00126 bool dependencyResolver; 00127 bool isMineralLimited; 00128 bool isGasLimited; 00129 bool debugMode; 00130 int nextUpdateFrame; 00131 };