|
BWAPI
|
#include <GasManager.h>


Public Member Functions | |
| GasManager () | |
| virtual void | update () |
| virtual void | draw () |
| int | getGasRate () const |
| int | getNumWorkersGathering () const |
| virtual const std::string & | getName () const |
Private Attributes | |
| int | refineryCount |
| int | refineryConstructingCount |
| int | workersConstructing |
| int | newRefineries |
Definition at line 10 of file GasManager.h.
Definition at line 15 of file GasManager.cpp.
: refineryCount(0) , refineryConstructingCount(0) , workersConstructing(0) , newRefineries(0) { }
| void GasManager::draw | ( | ) | [virtual] |
Reimplemented from Manager.
Definition at line 103 of file GasManager.cpp.
References BWAPI::Broodwar, and Manager::numAgents().
{
Broodwar->drawTextScreen(2, 30, "\x10 GM : (SCV=%d)", numAgents(UnitTypes::Terran_SCV));
Manager::draw();
}
| int GasManager::getGasRate | ( | ) | const |
Definition at line 81 of file GasManager.cpp.
{
// TODO
return 0;
}
| virtual const std::string& GasManager::getName | ( | ) | const [inline, virtual] |
Reimplemented from Manager.
Definition at line 27 of file GasManager.h.
{
static const std::string name("GasMgr");
return name;
}
| int GasManager::getNumWorkersGathering | ( | ) | const |
Definition at line 87 of file GasManager.cpp.
References Manager::agents, and Agent::getUnit().
{
int count = 0;
AgentSetConstIter it = agents.begin();
AgentSetConstIter end = agents.end();
for(; it != end;)
{
Agent *agent = *it;
if( agent->getUnit().isGatheringGas() )
{
++count;
}
}
return count;
}

| void GasManager::update | ( | ) | [virtual] |
Reimplemented from Manager.
Definition at line 22 of file GasManager.cpp.
References BuildState, GatherState, Manager::getAgentsOfType(), newRefineries, refineryCount, Agent::setState(), Agent::setUnitTypeTarget(), and workersConstructing.
{
// TODO: the refineries could be persistently stores by the GasMgr
// so we can see who is gathering from where, and whether its exhausted
// TODO: worry about gas steal?
AgentSet refineries(getAgentsOfType(UnitTypes::Terran_Refinery));
// Get a count on new refineries
newRefineries = static_cast<int>(refineries.size()) - refineryCount;
refineryCount = static_cast<int>(refineries.size());
// Keep the workers constructing count up to date
// TODO: remove this? is this responsibility being delegated to the BuildMgr?
//*
if( newRefineries > 0 )
{
// refineryConstructingCount -= newRefineries;
workersConstructing -= newRefineries;
}
//*/
AgentSet workers(getAgentsOfType(UnitTypes::Terran_SCV));
// Set a worker to build a refinery if we need to (for now just grab the first one)
// TODO: remove this? is this responsibility being delegated to the BuildMgr?
//*
if( refineries.empty() && !workers.empty() && workersConstructing == 0 )
{
//Broodwar->sendText("Gas manager, search for agent out of %d\n", (int)workers.size());
Agent* worker = *(workers.begin());
worker->setState(BuildState);
worker->setUnitTypeTarget(UnitTypes::Terran_Refinery);
// TODO - worker->setPositionTarget() to where?
// how does this worker know where to build?
++workersConstructing;
}
//*/
// Get our workers gathering from our refineries
for(AgentSetIter worker = workers.begin(); worker != workers.end(); ++worker)
{
Unit& unit = (*worker)->getUnit();
if( !unit.isGatheringGas() && !unit.isConstructing() )
{
for(AgentSetIter refinery = refineries.begin(); refinery != refineries.end(); refinery++)
{
Unit& refineryUnit = (*refinery)->getUnit();
(*worker)->setState(GatherState);
(*worker)->setUnitTarget(&refineryUnit);
(*worker)->setUnitTypeTarget(UnitTypes::Terran_Refinery);
(*worker)->setPositionTarget(refineryUnit.getPosition());
}
}
}
// Update all agents, very important!
Manager::update();
}

int GasManager::newRefineries [private] |
Definition at line 16 of file GasManager.h.
Referenced by update().
int GasManager::refineryConstructingCount [private] |
Definition at line 14 of file GasManager.h.
int GasManager::refineryCount [private] |
Definition at line 13 of file GasManager.h.
Referenced by update().
int GasManager::workersConstructing [private] |
Definition at line 15 of file GasManager.h.
Referenced by update().
1.7.6.1