Permalink
Browse files

Resolved conflict in strategizer.

  • Loading branch information...
2 parents e18b21a + 4467d34 commit 97c880a86c898d2df1ccf54e68d9038fe5abfc8c Andy Reichert committed Apr 22, 2012
@@ -244,10 +244,6 @@
RelativePath=".\source\Managers\ScoutManager.cpp"
>
</File>
- <File
- RelativePath=".\source\Managers\SupplyManager.cpp"
- >
- </File>
</Filter>
<Filter
Name="Agents"
@@ -324,6 +320,10 @@
RelativePath=".\source\Advisors\SquadAdvisor.cpp"
>
</File>
+ <File
+ RelativePath=".\source\Advisors\SupplyAdvisor.cpp"
+ >
+ </File>
</Filter>
</Filter>
<Filter
@@ -492,10 +492,6 @@
RelativePath=".\include\Managers\ScoutManager.h"
>
</File>
- <File
- RelativePath=".\include\Managers\SupplyManager.h"
- >
- </File>
<Filter
Name="Tasks"
>
@@ -564,6 +560,10 @@
RelativePath=".\include\Advisors\SquadAdvisor.h"
>
</File>
+ <File
+ RelativePath=".\include\Advisors\SupplyAdvisor.h"
+ >
+ </File>
</Filter>
</Filter>
</Files>
@@ -2,8 +2,7 @@
/*
* IncludeAllAdvisors.h"
*/
-
-
#include "MapAdvisor.h"
#include "SquadAdvisor.h"
+#include "SupplyAdvisor.h"
#include "ResourceAdvisor.h"
@@ -0,0 +1,18 @@
+#pragma once
+/*
+ * SupplyAdvisor.h
+ *
+ * Used to ensure SupplyDepot count keeps supply below capacity
+ */
+
+
+class SupplyAdvisor
+{
+private:
+ static int depotCount;
+ static int plannedDepotCount;
+
+public:
+ static void update();
+ static int plannedSupply();
+};
@@ -9,4 +9,3 @@
#include "CombatManager.h"
#include "GasManager.h"
#include "ScoutManager.h"
-#include "SupplyManager.h"
@@ -1,30 +0,0 @@
-#pragma once
-/*
- * SupplyManager.h
- *
- * Used to ensure SupplyDepot count keeps supply below capacity
- */
-#include "Manager.h"
-
-
-class SupplyManager : public Manager
-{
-private:
- int depotCount;
- int plannedDepotCount;
-
- /* plannedSupply - plannedSupply from planned depots + currentSupply*/
- int plannedSupply() const;
-
-public:
- SupplyManager();
-
- virtual void update();
- virtual void draw();
-
- virtual const std::string& getName() const
- {
- static const std::string name("SupplyMgr");
- return name;
- }
-};
@@ -18,7 +18,6 @@ class Strategizer
CombatManager combatManager;
GasManager gasManager;
ScoutManager scoutManager;
- SupplyManager supplyManager;
private:
UnitAgentMap unitAgentMap;
@@ -0,0 +1,53 @@
+/*
+ * SupplyAdvisor.cpp
+ *
+ * Used to ensure SupplyDepot count keeps supply below capacity
+ */
+#include "SupplyAdvisor.h"
+#include "Strategizer.h"
+#include "BuildManager.h"
+
+#include <BWAPI.h>
+
+using namespace BWAPI;
+
+
+int SupplyAdvisor::depotCount = 0;
+int SupplyAdvisor::plannedDepotCount = 0;
+
+
+void SupplyAdvisor::update()
+{
+ const Player *self = Broodwar->self();
+ const int MIN_SUPPLY_DIFF = 12;
+
+ // Build supply if running low
+ const int currentSupply = self->supplyUsed();
+ const int supplyDiff = plannedSupply() - currentSupply;
+ if( supplyDiff < MIN_SUPPLY_DIFF )
+ {
+ Broodwar->sendText(
+ "SM: Nearing capacity (%d/%d), Supply Depot ordered",
+ currentSupply, plannedSupply() );
+
+ ++plannedDepotCount;
+
+ Strategizer::instance().buildManager.build(UnitTypes::Terran_Supply_Depot, true);
+ }
+
+ // Detect Supply Depot completion
+ const int completedDepots = self->completedUnitCount(UnitTypes::Terran_Supply_Depot);
+ if( completedDepots > depotCount )
+ {
+ ++depotCount;
+ --plannedDepotCount;
+ }
+}
+
+int SupplyAdvisor::plannedSupply()
+{
+ // Note: supplyProvided() returns double the onscreen supply count
+ const int plannedSupply = plannedDepotCount * UnitTypes::Terran_Supply_Depot.supplyProvided();
+ const int totalSupply = Broodwar->self()->supplyTotal();
+ return plannedSupply + totalSupply;
+}
@@ -1,56 +0,0 @@
-/*
- * SupplyManager.cpp
- *
- * Used to ensure SupplyDepot count keeps supply below capacity
- */
-#include "SupplyManager.h"
-#include "BuildManager.h"
-#include "Strategizer.h"
-
-#include <BWAPI.h>
-
-using namespace BWAPI;
-
-
-SupplyManager::SupplyManager()
- : depotCount(0)
- , plannedDepotCount(0)
-{ }
-
-void SupplyManager::update()
-{
- /* Build supply if running low */
- int currentSupply = Broodwar->self()->supplyUsed();
- if (plannedSupply() - currentSupply < 12)
- {
- Broodwar->sendText("SM: Nearing capacity (%d/%d), Supply Depot ordered",
- currentSupply, plannedSupply());
- plannedDepotCount++;
- Strategizer::instance().buildManager.build(UnitTypes::Terran_Supply_Depot, true);
- }
-
- /* Detect Supply Depot completion */
- int completedDepots = Broodwar->self()->completedUnitCount(UnitTypes::Terran_Supply_Depot);
- if (completedDepots > depotCount)
- {
- depotCount++;
- plannedDepotCount--;
- }
-
- /* Base class updates Agents */
- Manager::update();
-}
-
-int SupplyManager::plannedSupply() const
-{
- // Note: supplyProvided() returns double the onscreen supply count
- const int plannedSupply = plannedDepotCount * UnitTypes::Terran_Supply_Depot.supplyProvided();
- const int totalSupply = Broodwar->self()->supplyTotal();
- return plannedSupply + totalSupply;
-}
-
-void SupplyManager::draw()
-{
- Broodwar->drawTextScreen(2, 10, "\x1E SM : %d planned", plannedSupply()/2);
- Manager::draw();
-}
@@ -27,8 +27,12 @@ void Strategizer::update()
// Draw "GUI"
Broodwar->drawTextScreen(300, 0, "\x17 APM=%d", Broodwar->getAPM());
Broodwar->drawTextScreen(300,10, "\x17 FPS=%d", Broodwar->getFPS());
- TacticalBuildingPlacer::instance().update(); // draw reserved map
- draw(); // draw managers
+
+ // Draw reserved map
+ TacticalBuildingPlacer::instance().update();
+
+ // Draw managers
+ draw();
if (Broodwar->getFrameCount() % 10 == 0)
{
@@ -44,6 +48,10 @@ void Strategizer::update()
// Let Managers manager
updateManagers();
+ // Update any advisors that might need updating
+ SupplyAdvisor::update();
+
+ // Forfeit the match if conditions warrant
if( checkForfeit() )
{
Broodwar->sendText("Surrendering match...");
@@ -65,6 +73,7 @@ void Strategizer::onMatchStart()
supplyManager.onMatchStart();
MapAdvisor::init(Broodwar->mapWidth() * 4, Broodwar->mapHeight() * 4);
+
buildManager.build(UnitTypes::Terran_SCV);
// Barracks do not ever leave idle state (for now), so 1 per unit type
@@ -284,15 +293,6 @@ void Strategizer::updateAgentManagerMap()
}
}
- // If we are running low on supply, give an SCV to the SupplyManager
- /*
- const int remainingSupply = Broodwar->self()->supplyTotal() - Broodwar->self()->supplyUsed();
- if (remainingSupply < 6 && supplyManager.numAgents(UnitTypes::Terran_SCV) < 1)
- {
- remap(UnitTypes::Terran_SCV, resourceManager, supplyManager);
- }
- */
-
// take one of the resourceManager SCV's and give it to the gas manager
if (Broodwar->self()->supplyUsed() >= 30 &&
gasManager.numAgents(UnitTypes::Terran_SCV) < 1)
@@ -322,7 +322,6 @@ void Strategizer::redistributeAgents()
combatManager.removeAllAgents();
gasManager.removeAllAgents();
scoutManager.removeAllAgents();
- supplyManager.removeAllAgents();
// Redistribute agents
AgentManagerMapIter it = agentManagerMap.begin();
@@ -349,15 +348,17 @@ void Strategizer::updateManagers()
scoutManager.update();
supplyManager.update();
MapAdvisor::update();
-}
+
void Strategizer::draw()
{
buildManager.draw();
combatManager.draw();
gasManager.draw();
- supplyManager.draw();
scoutManager.draw();
+
+ Broodwar->drawTextScreen(2, 0, "\x1E SM : %d planned"
+ , SupplyAdvisor::plannedSupply() / 2);
}
bool Strategizer::remap(BWAPI::UnitType type, Manager &src, Manager &dst)

0 comments on commit 97c880a

Please sign in to comment.