BWAPI
Public Member Functions | Static Public Member Functions
ResourceManager Class Reference

#include <ResourceManager.h>

Inheritance diagram for ResourceManager:
Inheritance graph
[legend]
Collaboration diagram for ResourceManager:
Collaboration graph
[legend]

List of all members.

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)

Detailed Description

Definition at line 10 of file ResourceManager.h.


Member Function Documentation

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();
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

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; 
    }

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;    
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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();
}

Here is the call graph for this function:


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines