BWAPI
Public Member Functions | Protected Member Functions | Protected Attributes
Agent Class Reference

#include <Agent.h>

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

List of all members.

Public Member Functions

virtual void update ()
virtual void draw ()
bool operator== (const Agent &other)
void setState (State state)
void setUnitTarget (BWAPI::Unit *target)
void setPositionTarget (const BWAPI::Position &target)
void setUnitTypeTarget (const BWAPI::UnitType &target)
bool unitTypeTargetValid ()
const State getState () const
const BWAPI::Unit & getUnit () const
BWAPI::Unit & getUnit ()
const BWAPI::Position & getPositionTarget () const
const BWAPI::UnitType & getUnitTypeTarget () const
BWAPI::Unit * getUnitTarget () const
void setParentManager (Manager *manager)
const std::string getParentManagerName () const

Protected Member Functions

 Agent (BWAPI::Unit &u)

Protected Attributes

BWAPI::Unit & unit
State state
BWAPI::Unit * unitTarget
BWAPI::Position positionTarget
BWAPI::UnitType unitTypeTarget
bool buildingReserved
BWAPI::TilePosition buildingLocation
ManagerparentManager

Detailed Description

Definition at line 13 of file Agent.h.


Constructor & Destructor Documentation

Agent::Agent ( BWAPI::Unit &  u) [protected]

Definition at line 15 of file Agent.cpp.

    : unit(u)
    , state(IdleState)
    , unitTarget(NULL)
    , positionTarget()
    , unitTypeTarget(UnitTypes::None)
    , buildingReserved(false)
    , buildingLocation()
    , parentManager(NULL)
{ }

Member Function Documentation

void Agent::draw ( ) [virtual]

Definition at line 53 of file Agent.cpp.

References AttackState, BWAPI::Broodwar, GatherState, getParentManagerName(), positionTarget, state, StateStrings, unit, unitTarget, UnitTypeStrings, unitTypeTarget, and unitTypeTargetValid().

{
        const int px = unit.getPosition().x();
        const int py = unit.getPosition().y();
        const int radius = unit.getRight() - px;

        // Draw owner, state, type
        if (state != GatherState)
                Broodwar->drawTextMap(px, py, "(%s, %s%s)", getParentManagerName().c_str(),
                        StateStrings[state], unitTypeTargetValid() ? (string(", ") += string(UnitTypeStrings[unitTypeTarget.getID()])).c_str()
                                                                                                                :       "");

    // Note: drawing this stuff all the time clutters things up massively, but can be useful
    // TODO: look into adding a global chat flag to toggle this stuff (/debuginfo or something)
    if( 1 ) //unit.isSelected() )
    {
        Broodwar->drawCircleMap(px, py, radius, Colors::Yellow);

        // Draw line to position target if its valid
        if( positionTarget.isValid()
         && positionTarget != Positions::None 
         && positionTarget != Positions::Unknown 
         && positionTarget.x() != 0 && positionTarget.y() != 0 )
        {
            const int tx = positionTarget.x();
            const int ty = positionTarget.y();
            Broodwar->drawLineMap(px, py, tx, ty, Colors::Green);
            Broodwar->drawTextMap(tx, ty, "(%d, %d)", tx, ty);
        }

        // Draw a line to the unit target if its valid
        if( unitTarget != NULL )
        {
            const Position targetPos = unitTarget->getPosition();
            if( targetPos.isValid() 
             && targetPos != Positions::None 
             && targetPos != Positions::Unknown 
             && targetPos.x() != 0 && targetPos.y() != 0 )
            {
                const int tx = unitTarget->getPosition().x();
                const int ty = unitTarget->getPosition().y();
                Broodwar->drawLineMap(px, py, tx, ty, Colors::Red);
                Broodwar->drawTextMap(tx, ty, "id: %x", unitTarget);
            }
        }
    }

        if (state == AttackState)
        {
                // Draw our attack range
                Position unitPosition = unit.getPosition();
                int x = unitPosition.x();
                int y = unitPosition.y();
                int attackRadius = unit.getType().seekRange();
                Broodwar->drawCircle(CoordinateType::Map, x, y, attackRadius, BWAPI::Colors::White);


        }

        // Draw our current target position
        Position targetPosition = unit.getTargetPosition();
        Broodwar->drawLineMap(unit.getPosition().x(), unit.getPosition().y(),
                targetPosition.x(), targetPosition.y(), Colors::Yellow);
}

Here is the call graph for this function:

const std::string Agent::getParentManagerName ( ) const

Definition at line 47 of file Agent.cpp.

References Manager::getName(), and parentManager.

Referenced by draw().

{
    return (parentManager != NULL) ? 
        parentManager->getName() : "None";
}

Here is the call graph for this function:

Here is the caller graph for this function:

const BWAPI::Position& Agent::getPositionTarget ( ) const [inline]

Definition at line 55 of file Agent.h.

References positionTarget.

Referenced by Squad::update().

{ return positionTarget; }

Here is the caller graph for this function:

const State Agent::getState ( ) const [inline]

Definition at line 52 of file Agent.h.

References state.

Referenced by BuildManager::update().

{ return state; }

Here is the caller graph for this function:

const BWAPI::Unit& Agent::getUnit ( ) const [inline]
BWAPI::Unit& Agent::getUnit ( ) [inline]

Definition at line 54 of file Agent.h.

References unit.

{ return unit; }  
BWAPI::Unit* Agent::getUnitTarget ( ) const [inline]

Definition at line 57 of file Agent.h.

References unitTarget.

Referenced by Squad::update().

{ return unitTarget; }

Here is the caller graph for this function:

const BWAPI::UnitType& Agent::getUnitTypeTarget ( ) const [inline]

Definition at line 56 of file Agent.h.

References unitTypeTarget.

Referenced by Squad::update().

{ return unitTypeTarget; }

Here is the caller graph for this function:

bool Agent::operator== ( const Agent other)

Definition at line 26 of file Agent.cpp.

References unit.

{
        // Compare by pointer values
        if( &(this->unit) == &(other.unit) )
                return true;
        else
                return false;
}
void Agent::setParentManager ( Manager manager)

Definition at line 41 of file Agent.cpp.

References parentManager.

Referenced by Strategizer::redistributeAgents().

{
    if( manager != NULL ) 
        parentManager = manager;
}

Here is the caller graph for this function:

void Agent::setPositionTarget ( const BWAPI::Position &  target) [inline]

Definition at line 42 of file Agent.h.

References positionTarget.

Referenced by CombatManager::addNewAgents(), ResourceManager::makeAgentGatherMinerals(), Squad::update(), and CombatManager::update().

{ positionTarget = target; }

Here is the caller graph for this function:

void Agent::setState ( State  state) [inline]

Definition at line 40 of file Agent.h.

References state.

Referenced by ResourceManager::makeAgentGatherMinerals(), GasManager::update(), Squad::update(), and CombatManager::update().

{ this->state = state; }

Here is the caller graph for this function:

void Agent::setUnitTarget ( BWAPI::Unit *  target) [inline]

Definition at line 41 of file Agent.h.

References unitTarget.

Referenced by ResourceManager::makeAgentGatherMinerals(), and Squad::update().

{ unitTarget = target; }

Here is the caller graph for this function:

void Agent::setUnitTypeTarget ( const BWAPI::UnitType &  target) [inline]

Definition at line 43 of file Agent.h.

References unitTypeTarget.

Referenced by ResourceManager::makeAgentGatherMinerals(), GasManager::update(), and Squad::update().

{ unitTypeTarget = target; }

Here is the caller graph for this function:

bool Agent::unitTypeTargetValid ( ) [inline]

Definition at line 45 of file Agent.h.

References NUM_UNIT_TYPES, and unitTypeTarget.

Referenced by draw().

                                   { 
                int typeTargetID = unitTypeTarget.getID();
                return typeTargetID >= 0 && 
                        typeTargetID < NUM_UNIT_TYPES && 
                        typeTargetID != BWAPI::UnitTypes::None; 
        }

Here is the caller graph for this function:

void Agent::update ( ) [virtual]

Reimplemented in BarracksAgent, FirebatAgent, MarineAgent, MedicAgent, SCVAgent, SiegeTankAgent, CommandCenterAgent, RefineryAgent, ActorAgent, GroundAgent, and StructureAgent.

Definition at line 35 of file Agent.cpp.

References buildingLocation, BuildState, positionTarget, and state.

Referenced by Manager::update().

{
    if( state == BuildState )
        positionTarget = Position(buildingLocation);
}

Here is the caller graph for this function:


Member Data Documentation

BWAPI::TilePosition Agent::buildingLocation [protected]

Definition at line 24 of file Agent.h.

Referenced by SCVAgent::update(), and update().

bool Agent::buildingReserved [protected]

Definition at line 23 of file Agent.h.

Referenced by SCVAgent::update().

Definition at line 26 of file Agent.h.

Referenced by getParentManagerName(), and setParentManager().

BWAPI::Position Agent::positionTarget [protected]
State Agent::state [protected]
BWAPI::Unit& Agent::unit [protected]
BWAPI::Unit* Agent::unitTarget [protected]

Definition at line 19 of file Agent.h.

Referenced by draw(), getUnitTarget(), setUnitTarget(), and SCVAgent::update().

BWAPI::UnitType Agent::unitTypeTarget [protected]

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