本文整理汇总了C++中Squad::addAgent方法的典型用法代码示例。如果您正苦于以下问题:C++ Squad::addAgent方法的具体用法?C++ Squad::addAgent怎么用?C++ Squad::addAgent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Squad
的用法示例。
在下文中一共展示了Squad::addAgent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addNewAgents
void CombatManager::addNewAgents()
{
// If we have any new Agents, they should go in the unassigned set
AgentSetIter it = agents.begin();
AgentSetIter end = agents.end();
Squad * squad;
for(; it != end; ++it)
{
Agent *agent = *it;
UnitType ut = agent->getUnit().getType();
// if not assigned yet
if( assignedAgents.find(agent) == assignedAgents.end() )
{
// check for bunkers
if (ut == UnitTypes::Terran_Bunker) {
bunkerAgents.insert(agent);
assignedAgents.insert(agent);
continue;
}
// init to unassigned
unassignedAgents.insert(agent);
// TODO - this is a hack to make them defend in the right place
Position unitPosition = agent->getUnit().getPosition();
Position rallyPoint = MapAdvisor::getPositionOutsideNearestChokepoint(unitPosition);
if (rallyPoint != Positions::None)
agent->setPositionTarget(rallyPoint);
// Assign Agent to a Squad
// if there isn't an empty bunker fill up defense squad
// with marines at max of 4 (only 1 bunker atm)
// these will be reassigned to a bunker squad eventually
if ((int)bunkerAgents.size() == 0
&& ut == UnitTypes::Terran_Marine
&& ( (int)defendSquads.size() == 0 || defendSquads.back()->getSize() < 4))
{
// if there isn't a defend squad make one
if ((int)defendSquads.size() == 0)
{
defendSquads.push_back(new Squad("defend-squad", defend));
}
// set pointer
squad = defendSquads.back();
}
else if ((int)bunkerAgents.size() == 1
&& ut == UnitTypes::Terran_Marine
&& ((int)bunkerSquads.size() == 0 || bunkerSquads.back()->getSize() < 4))
{
// if there isn't a bunker squad make one
if ((int)bunkerSquads.size() == 0)
{
bunkerSquads.push_back(new Squad("bunker-squad", bunker));
// always assigns first bunker as target
// TODO: make better bunker agent arrangement
bunkerSquads.back()->setBunkerTarget(&(*bunkerAgents.begin())->getUnit());
}
// set pointer
squad = bunkerSquads.back();
}
else
{
// if there isn't an attack squad make one
if ((int)attackSquads.size() == 0
|| attackSquads.back()->getSize() == AttackSquadSize)
{
attackSquads.push_back(new Squad("attack-squad", attack));
}
squad = attackSquads.back();
}
// TODO: only add the agent if we have (or can create)
// a squad that has an unfulfilled requirement for this type of unit,
// otherwise leave it in the unassigned set
squad->addAgent(*it);
// For now this should always be set, giving them the ability
// to look for nearby enemy targets
(*it)->setState(AttackState);
if (squad->getLeader() == NULL)
{
squad->setLeader(*it);
}
// change to assigned
unassignedAgents.erase(agent);
assignedAgents.insert(agent);
}
}
}