BWAPI
Public Member Functions | Private Attributes
GasManager Class Reference

#include <GasManager.h>

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

List of all members.

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

Detailed Description

Definition at line 10 of file GasManager.h.


Constructor & Destructor Documentation

Definition at line 15 of file GasManager.cpp.


Member Function Documentation

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

Here is the call graph for this function:

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

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

Here is the call graph for this function:

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

Here is the call graph for this function:


Member Data Documentation

Definition at line 16 of file GasManager.h.

Referenced by update().

Definition at line 14 of file GasManager.h.

Definition at line 13 of file GasManager.h.

Referenced by update().

Definition at line 15 of file GasManager.h.

Referenced by update().


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