BWAPI
Public Member Functions
ActorAgent Class Reference

#include <ActorAgent.h>

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

List of all members.

Public Member Functions

virtual void update ()
 ActorAgent (BWAPI::Unit &u)
bool isOccupiedPosition (BWAPI::Position target)
BWAPI::Position getClosestPosition (BWAPI::Position target)

Detailed Description

Definition at line 7 of file ActorAgent.h.


Constructor & Destructor Documentation

ActorAgent::ActorAgent ( BWAPI::Unit &  u)

Definition at line 13 of file ActorAgent.cpp.

        : Agent(u)
{ }

Member Function Documentation

Position ActorAgent::getClosestPosition ( BWAPI::Position  target)

Definition at line 66 of file ActorAgent.cpp.

References isOccupiedPosition(), and Agent::unit.

{
        typedef pair<int,int> pt;
        queue<pt> open;
        map<pt, bool> visited;

        // Start at target
        open.push(pt(target.x(), target.y()));

        while (!open.empty())
        {
                // Visited?
                if (visited[open.front()])
                {
                        open.pop();
                        continue;
                }

                // Mark visited
                pt p = open.front(); open.pop();
                visited[p] = true;

                // Prepare
                int x = p.first;
                int y = p.second;
                Position pos = Position(p.first, p.second).makeValid();

                // Goal test
                if (!isOccupiedPosition(pos) &&
                        unit.hasPath(pos))
                {
                        return pos;
                }
                // Search
                else
                {
                        open.push(pt(x + 1, y));
                        open.push(pt(x - 1, y));
                        open.push(pt(x, y + 1));
                        open.push(pt(x, y - 1));
                }               
        }
        
        // If we couldn't find anything, try again later
        return target;
}

Here is the call graph for this function:

bool ActorAgent::isOccupiedPosition ( BWAPI::Position  target)

Definition at line 54 of file ActorAgent.cpp.

References BWAPI::Broodwar, and Agent::unit.

Referenced by getClosestPosition().

{
        UnitSet units = Broodwar->getUnitsInRadius(target, unit.getRight() - unit.getLeft());
        for (UnitSetIter it = units.begin(); it != units.end(); it++)
        {
                if ((*it)->getID() != unit.getID())
                        return true;
        }
        return false;
}

Here is the caller graph for this function:

void ActorAgent::update ( ) [virtual]

Reimplemented from Agent.

Reimplemented in FirebatAgent, MarineAgent, MedicAgent, SCVAgent, SiegeTankAgent, and GroundAgent.

Definition at line 17 of file ActorAgent.cpp.

References AttackState, DefendState, IdleState, Agent::positionTarget, Agent::state, and Agent::unit.

{
    switch(state)
    {
    case IdleState:
                break;

    case AttackState: 
        {
                // Move to attack target
                if (!unit.isAttacking() && !unit.isMoving() && unit.getDistance(positionTarget) > 300)
                {
                        /*
                        // Correct our destination if necessary
                        Position tp = positionTarget;
                        if (isOccupiedPosition(tp))
                        {
                                unit.attack(getClosestPosition(tp));
                                positionTarget = unit.getTargetPosition();
                        }
                        */
                        // Move/attack
                        unit.attack(positionTarget);
                }
        }
        break;

    case DefendState: 
                if (!unit.isAttacking() && !unit.isMoving())
                        unit.attack(positionTarget); 
                break;
    }

        Agent::update();
}

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