|
BWAPI
|
#include <ResourceManager.h>


Public Member Functions | |
| void | update () |
| void | draw () |
| int | getMineralRate () const |
| int | getNumWorkersGathering () const |
| virtual const std::string & | getName () const |
Static Public Member Functions | |
| static bool | makeAgentGatherMinerals (Agent &agent) |
| static BWAPI::Unit * | getClosestMineralPatch (const Agent &agent) |
Definition at line 10 of file ResourceManager.h.
| void ResourceManager::draw | ( | ) | [virtual] |
Reimplemented from Manager.
Definition at line 86 of file ResourceManager.cpp.
References BWAPI::Broodwar, and Manager::draw().
{
Broodwar->drawTextScreen(2, 0, "\x1F RM : (SCV=%d)", numAgents(UnitTypes::Terran_SCV));
Manager::draw();
}
| Unit * ResourceManager::getClosestMineralPatch | ( | const Agent & | agent | ) | [static] |
Definition at line 45 of file ResourceManager.cpp.
References BWAPI::Broodwar, and Agent::getUnit().
{
Unit *closest = NULL;
int minDist = std::numeric_limits<int>::max();
UnitSet minerals(Broodwar->getMinerals());
for(UnitSetIter mineral = minerals.begin(); mineral != minerals.end(); ++mineral)
{
int dist = agent.getUnit().getDistance(*mineral);
if (dist < minDist)
{
minDist = dist;
closest = *mineral;
}
}
return closest;
}

| int ResourceManager::getMineralRate | ( | ) | const |
Definition at line 64 of file ResourceManager.cpp.
{
// TODO
return 0;
}
| virtual const std::string& ResourceManager::getName | ( | ) | const [inline, virtual] |
Reimplemented from Manager.
Definition at line 22 of file ResourceManager.h.
{
static const std::string name("ResourceMgr");
return name;
}
| int ResourceManager::getNumWorkersGathering | ( | ) | const |
Definition at line 70 of file ResourceManager.cpp.
References Agent::getUnit().
{
int count = 0;
AgentSetConstIter it = agents.begin();
AgentSetConstIter end = agents.end();
for(; it != end;)
{
Agent *agent = *it;
if( agent->getUnit().isGatheringMinerals() )
{
++count;
}
}
return count;
}

| bool ResourceManager::makeAgentGatherMinerals | ( | Agent & | agent | ) | [static] |
Definition at line 28 of file ResourceManager.cpp.
References GatherState, Agent::setPositionTarget(), Agent::setState(), Agent::setUnitTarget(), and Agent::setUnitTypeTarget().
Referenced by BuildManager::update().
{
bool success = false;
Unit *closest = getClosestMineralPatch(agent);
if( closest != NULL )
{
agent.setState(GatherState);
agent.setUnitTarget(closest);
agent.setUnitTypeTarget(closest->getType());
agent.setPositionTarget(closest->getPosition());
success = true;
}
return success;
}


| void ResourceManager::update | ( | ) | [virtual] |
Reimplemented from Manager.
Definition at line 12 of file ResourceManager.cpp.
References Manager::update().
{
// TODO: store the mineral units locally in ResourceMgr
// so we can more effectively control which workers gather from which minerals
// Send workers to mine minerals near our base
AgentSet workers(getAgentsOfType(UnitTypes::Terran_SCV));
for(AgentSetIter worker = workers.begin(); worker != workers.end(); ++worker)
{
makeAgentGatherMinerals(**worker);
}
// Update all agents
Manager::update();
}

1.7.6.1