BWAPI
Public Member Functions | Private Attributes
Squad Class Reference

#include <Squad.h>

Collaboration diagram for Squad:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Squad ()
 Squad (const Squad &other)
 ~Squad ()
Squadoperator= (const Squad &rhs)
void update ()
void draw ()
void addAgent (Agent *agent)
void removeAgent (Agent *agent)
bool isAssigned (Agent *agent)
AgentSetgetAgents ()
AgentgetLeader ()
void setLeader (Agent *agent)

Private Attributes

AgentSet agents
Agentleader

Detailed Description

Definition at line 9 of file Squad.h.


Constructor & Destructor Documentation

Definition at line 15 of file Squad.cpp.

    : agents()
    , leader(NULL)
{ }
Squad::Squad ( const Squad other)

Definition at line 20 of file Squad.cpp.

    : agents(other.agents)
    , leader(other.leader)
{ }

Definition at line 25 of file Squad.cpp.

References agents, and leader.

{
    agents.clear();
    leader = NULL;
}

Member Function Documentation

void Squad::addAgent ( Agent agent) [inline]

Definition at line 25 of file Squad.h.

References agents.

Referenced by CombatManager::addNewAgents(), and setLeader().

{ agents.insert(agent); }

Here is the caller graph for this function:

void Squad::draw ( )

Definition at line 63 of file Squad.cpp.

References agents, and BWAPI::Broodwar.

{
        // Draw a box enclosing my squad
        int minX, maxX, minY, maxY;
        minX = minY = 999999;
        maxX = maxY = -1;
        int sumX, sumY;
        sumX = sumY = 0;
        for (AgentSetIter it = agents.begin(); it != agents.end(); it++)
        {
                int x = (*it)->getUnit().getPosition().x();
                int y = (*it)->getUnit().getPosition().y();
                sumX += x;
                sumY += y;
                minX = min(x, minX);
                maxX = max(x, maxX);
                minY = min(y, minY);
                maxY = max(y, maxY);
        }
        int x0, y0;
        if (agents.size())
        {
                x0 = sumX / agents.size();
                y0 = sumY / agents.size();
                Broodwar->drawEllipseMap(x0, y0, maxX-minX, maxY-minY, Colors::Cyan);
        }
}
AgentSet& Squad::getAgents ( ) [inline]

Definition at line 36 of file Squad.h.

References agents.

{ return agents; }
Agent* Squad::getLeader ( ) [inline]

Definition at line 37 of file Squad.h.

References leader.

Referenced by CombatManager::addNewAgents().

{ return leader; }

Here is the caller graph for this function:

bool Squad::isAssigned ( Agent agent) [inline]

Definition at line 28 of file Squad.h.

References agents.

Referenced by setLeader().

    { 
        if( agents.find(agent) != agents.end() )
            return true;
        else 
            return false;
    }

Here is the caller graph for this function:

Squad & Squad::operator= ( const Squad rhs)

Definition at line 31 of file Squad.cpp.

References agents, and leader.

{
    if( this != &rhs )
    {
        agents.clear();
        agents = rhs.agents;
        leader = rhs.leader;
    }
    return *this;
}
void Squad::removeAgent ( Agent agent) [inline]

Definition at line 26 of file Squad.h.

References agents.

{ agents.erase(agent); }
void Squad::setLeader ( Agent agent) [inline]

Definition at line 39 of file Squad.h.

References addAgent(), isAssigned(), and leader.

Referenced by CombatManager::addNewAgents().

    {
        if( leader == agent ) 
            return;
        if( !isAssigned(agent) )
            addAgent(agent);
        leader = agent;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void Squad::update ( )

Definition at line 42 of file Squad.cpp.

References agents, AttackState, Agent::getPositionTarget(), Agent::getUnitTarget(), Agent::getUnitTypeTarget(), leader, Agent::setPositionTarget(), Agent::setState(), Agent::setUnitTarget(), and Agent::setUnitTypeTarget().

{
    assert(leader != NULL);

    // Do what the leader is doing
    AgentSetIter it  = agents.begin();
    AgentSetIter end = agents.end();
    for(; it != end; ++it)
    {
        Agent *agent = *it;
        if( agent != leader ) 
        {
            // agent->setState(leader->getState());
                        agent->setState(AttackState);
                        agent->setPositionTarget(leader->getPositionTarget());
            agent->setUnitTarget(leader->getUnitTarget());
            agent->setUnitTypeTarget(leader->getUnitTypeTarget());
        }
    }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 12 of file Squad.h.

Referenced by addAgent(), draw(), getAgents(), isAssigned(), operator=(), removeAgent(), update(), and ~Squad().

Agent* Squad::leader [private]

Definition at line 13 of file Squad.h.

Referenced by getLeader(), operator=(), setLeader(), update(), and ~Squad().


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