|
BWAPI
|
#include <CombatManager.h>


Public Member Functions | |
| virtual void | onMatchStart () |
| virtual void | update () |
| virtual void | draw () |
| virtual const std::string & | getName () const |
Private Member Functions | |
| void | addNewAgents () |
Private Attributes | |
| AgentSet | unassignedAgents |
| AgentSet | assignedAgents |
| SquadVector | squads |
| BWAPI::Position | enemyBase |
Definition at line 13 of file CombatManager.h.
| void CombatManager::addNewAgents | ( | ) | [private] |
Definition at line 80 of file CombatManager.cpp.
References Squad::addAgent(), BWAPI::Broodwar, Squad::getLeader(), Agent::getUnit(), Squad::setLeader(), and Agent::setPositionTarget().
{
// If we have any new Agents, they should go in the unassigned set
AgentSetIter it = agents.begin();
AgentSetIter end = agents.end();
for(; it != end; ++it)
{
Agent *agent = *it;
if( assignedAgents.find(agent) == assignedAgents.end() )
{
unassignedAgents.insert(agent);
// TODO - this is a hack to make them defend in the right place
Chokepoint *cp = BWTA::getNearestChokepoint(agent->getUnit().getPosition());
if( cp != NULL )
agent->setPositionTarget(cp->getCenter());
else
agent->setPositionTarget(Position(Broodwar->self()->getStartLocation()));
// Assign Agent to a Squad (only 1 atm)
if (squads.empty())
{
squads.push_back(new Squad());
}
// Create a new squad if current is full
if (squads.back()->getAgents().size() > 10)
{
squads.push_back(new Squad());
}
Squad *squad = squads.back();
squad->addAgent(*it);
if (squad->getLeader() == NULL)
{
squad->setLeader(*it);
}
unassignedAgents.erase(agent);
assignedAgents.insert(agent);
}
}
}

| void CombatManager::draw | ( | ) | [virtual] |
Reimplemented from Manager.
Definition at line 121 of file CombatManager.cpp.
References BWAPI::Broodwar, and Manager::draw().
{
Broodwar->drawTextScreen(2, 20,
"\x11 CM : (SCV=%d) (Marine=%d) (Firebat=%d) (Medic=%d)",
numAgents(UnitTypes::Terran_SCV),
numAgents(UnitTypes::Terran_Marine),
numAgents(UnitTypes::Terran_Firebat),
numAgents(UnitTypes::Terran_Medic));
for (SquadVectorIter it = squads.begin(); it != squads.end(); it++)
{
(*it)->draw();
}
Manager::draw();
}
| virtual const std::string& CombatManager::getName | ( | ) | const [inline, virtual] |
Reimplemented from Manager.
Definition at line 26 of file CombatManager.h.
{
static const std::string name("CombatMgr");
return name;
}
| void CombatManager::onMatchStart | ( | ) | [virtual] |
Reimplemented from Manager.
Definition at line 16 of file CombatManager.cpp.
References BWAPI::Broodwar.
{
Player* enemy = Broodwar->enemy();
if( enemy != NULL )
{
// Get the likely enemy base location (furthest from myStart)
// TODO - this should probably be calculated only once,
// maybe we should have a Manager::onMatchStart() method?
TilePosition myStart = Broodwar->self()->getStartLocation();
TilePosition target;
double maxDistance = 0.0;
set<TilePosition>& startPositions = Broodwar->getStartLocations();
set<TilePosition>::iterator pit = startPositions.begin();
set<TilePosition>::iterator pend = startPositions.end();
for(; pit != pend; ++pit)
{
TilePosition pos = *pit;
const double distance = pos.getDistance(myStart);
if( distance > maxDistance )
{
target = pos;
maxDistance = distance;
}
}
enemyBase = Position(target);
}
}
| void CombatManager::update | ( | ) | [virtual] |
Reimplemented from Manager.
Definition at line 45 of file CombatManager.cpp.
References AttackState, Agent::setPositionTarget(), Agent::setState(), and Manager::update().
{
// Get new agents into state
addNewAgents();
// TODO : Merge squads
// Attack?
const int numTroops = agents.size();
const int threshold = 50;
if( numTroops >= threshold )
{
// Attack with full force (adjust to lower)
for (SquadVectorIter it = squads.begin(); it != squads.end(); it++)
{
Agent *a = (*it)->getLeader();
if (a != NULL)
{
a->setState(AttackState);
a->setPositionTarget(enemyBase);
}
}
}
/* Update squads */
for (SquadVectorIter it = squads.begin(); it != squads.end(); it++)
{
(*it)->update();
}
/* Base class updates Agents */
Manager::update();
}

AgentSet CombatManager::assignedAgents [private] |
Definition at line 17 of file CombatManager.h.
BWAPI::Position CombatManager::enemyBase [private] |
Definition at line 19 of file CombatManager.h.
SquadVector CombatManager::squads [private] |
Definition at line 18 of file CombatManager.h.
AgentSet CombatManager::unassignedAgents [private] |
Definition at line 16 of file CombatManager.h.
1.7.6.1