当前位置: 首页>>代码示例>>C++>>正文


C++ Squad::addAgent方法代码示例

本文整理汇总了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);
		}
	}
}
开发者ID:jmloethen,项目名称:CS-638-BWAPI,代码行数:94,代码来源:CombatManager.cpp


注:本文中的Squad::addAgent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。