|
BWAPI
|
#include <SquadManager.h>

Public Member Functions | |
| SquadManagerClass () | |
| void | update () |
| void | onChangeBuild () |
| BaseSquadTaskPointer | createSquad (SquadType type) |
Private Attributes | |
| std::map< SquadType, std::set < BaseSquadTaskPointer > > | mSquads |
| ArmyBehaviour | mCurrentBehaviour |
| BaseSquadTaskPointer | mDefaultSquad |
| std::map< Base, DefenseSquadPointer > | mDefenseSquads |
Definition at line 10 of file SquadManager.h.
Definition at line 8 of file SquadManager.cpp.
References createSquad(), and mDefaultSquad.
{
mDefaultSquad = createSquad(SquadType::DefaultSquad);
}

Definition at line 102 of file SquadManager.cpp.
References Singleton< T >::Instance(), mCurrentBehaviour, mSquads, and SafeEnum< def, inner >::underlying().
Referenced by onChangeBuild(), SquadManagerClass(), and update().
{
BaseSquadTaskPointer task;
switch(type.underlying())
{
case SquadType::DefaultSquad:
task = BaseSquadTaskPointer(new DefaultSquadTask(mCurrentBehaviour));
break;
case SquadType::DefenseSquad:
task = BaseSquadTaskPointer(new DefenseSquadTask(mCurrentBehaviour));
break;
case SquadType::ReaverDropSquad:
//task = BaseSquadTaskPointer(new ReaverDropSquad());
break;
case SquadType::DarkTemplerSquad:
//task = BaseSquadTaskPointer(new DarkTemplerSquad());
break;
case SquadType::CorsairSquad:
//task = BaseSquadTaskPointer(new CorsairSquad());
break;
}
if(task)
{
mSquads[type].insert(task);
TaskManager::Instance().addTask(task);
}
return task;
}

| void SquadManagerClass::onChangeBuild | ( | ) |
Definition at line 37 of file SquadManager.cpp.
References createSquad(), Singleton< T >::Instance(), mCurrentBehaviour, and mSquads.
{
const std::map<SquadType, int> &squads = BuildOrderManager::Instance().getCurrentBuild().getSquads();
for(std::map<SquadType, int>::const_iterator it = squads.begin(); it != squads.end(); ++it)
{
if(it->first == SquadType::DefaultSquad || it->first == SquadType::DefenseSquad)
continue;
int numNeeded = it->second - mSquads[it->first].size();
while(numNeeded != 0)
{
if(numNeeded < 0)
{
++numNeeded;
int smallest = std::numeric_limits<int>::max();
BaseSquadTaskPointer smallestSquad;
for each(BaseSquadTaskPointer squad in mSquads[it->first])
{
int size = squad->controlSize();
if(size < smallest)
{
smallest = size;
smallestSquad = squad;
}
}
if(smallestSquad)
{
smallestSquad->cancel();
mSquads[it->first].erase(smallestSquad);
}
}
else
{
--numNeeded;
createSquad(it->first);
}
}
}
for(std::map<SquadType, std::set<BaseSquadTaskPointer>>::iterator o = mSquads.begin(); o != mSquads.end();)
{
if(o->first != SquadType::DefaultSquad && o->first != SquadType::DefenseSquad && squads.find(o->first) == squads.end())
{
for each(BaseSquadTaskPointer task in o->second)
{
task->cancel();
}
mSquads.erase(o++);
}
else ++o;
}
mCurrentBehaviour = BuildOrderManager::Instance().getCurrentBuild().getArmyBehaiour();
for(std::map<SquadType, std::set<BaseSquadTaskPointer>>::iterator o = mSquads.begin(); o != mSquads.end(); ++o)
{
for each(BaseSquadTaskPointer squad in o->second)
{
squad->changeBehaviour(mCurrentBehaviour);
}
}
}

| void SquadManagerClass::update | ( | ) |
Definition at line 13 of file SquadManager.cpp.
References createSquad(), ActionTypeDef::Defend, Singleton< T >::Instance(), mDefenseSquads, and DefenseSquadTask::setGoal().
{
for(std::map<Base, DefenseSquadPointer>::iterator it = mDefenseSquads.begin(); it != mDefenseSquads.end();)
{
if(it->first->getEnemyThreats().empty() || (it->first->isMinedOut() && it->first->getNumberOfTechBuildings() == 0))
it->second->cancel();
if(it->second->hasEnded())
mDefenseSquads.erase(it++);
else
++it;
}
for each(Base base in BaseTracker::Instance().getPlayerBases())
{
if(!base->getEnemyThreats().empty() && (base->getNumberOfTechBuildings() > 0 || (!base->isMinedOut() && base->getResourceDepot())) && mDefenseSquads.count(base) == 0)
{
DefenseSquadPointer squad = std::tr1::static_pointer_cast<DefenseSquadTask>(createSquad(SquadType::DefenseSquad));
squad->setGoal(Goal(ActionType::Defend, base));
mDefenseSquads[base] = squad;
}
}
}

Definition at line 23 of file SquadManager.h.
Referenced by createSquad(), and onChangeBuild().
Definition at line 25 of file SquadManager.h.
Referenced by SquadManagerClass().
std::map<Base, DefenseSquadPointer> SquadManagerClass::mDefenseSquads [private] |
Definition at line 26 of file SquadManager.h.
Referenced by update().
std::map<SquadType, std::set<BaseSquadTaskPointer> > SquadManagerClass::mSquads [private] |
Definition at line 21 of file SquadManager.h.
Referenced by createSquad(), and onChangeBuild().
1.7.6.1