BWAPI
|
00001 /* 00002 * SupplyManager.cpp 00003 * 00004 * Used to ensure SupplyDepot count keeps supply below capacity 00005 */ 00006 #include "SupplyManager.h" 00007 #include "BuildManager.h" 00008 #include "Strategizer.h" 00009 00010 #include <BWAPI.h> 00011 00012 using namespace BWAPI; 00013 00014 00015 SupplyManager::SupplyManager() 00016 : depotCount(0) 00017 , plannedDepotCount(0) 00018 { } 00019 00020 void SupplyManager::update() 00021 { 00022 /* Build supply if running low */ 00023 int currentSupply = Broodwar->self()->supplyUsed(); 00024 if (plannedSupply() - currentSupply < 12) 00025 { 00026 Broodwar->sendText("SM: Nearing capacity (%d/%d), Supply Depot ordered", 00027 currentSupply, plannedSupply()); 00028 plannedDepotCount++; 00029 Strategizer::instance().buildManager.build(UnitTypes::Terran_Supply_Depot, true); 00030 } 00031 00032 /* Detect Supply Depot completion */ 00033 int completedDepots = Broodwar->self()->completedUnitCount(UnitTypes::Terran_Supply_Depot); 00034 if (completedDepots > depotCount) 00035 { 00036 depotCount++; 00037 plannedDepotCount--; 00038 } 00039 00040 /* Base class updates Agents */ 00041 Manager::update(); 00042 } 00043 00044 int SupplyManager::plannedSupply() const 00045 { 00046 // Note: supplyProvided() returns double the onscreen supply count 00047 const int plannedSupply = plannedDepotCount * UnitTypes::Terran_Supply_Depot.supplyProvided(); 00048 const int totalSupply = Broodwar->self()->supplyTotal(); 00049 return plannedSupply + totalSupply; 00050 } 00051 00052 void SupplyManager::draw() 00053 { 00054 Broodwar->drawTextScreen(2, 10, "\x1E SM : %d planned", plannedSupply()/2); 00055 Manager::draw(); 00056 }