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


C++ Squad类代码示例

本文整理汇总了C++中Squad的典型用法代码示例。如果您正苦于以下问题:C++ Squad类的具体用法?C++ Squad怎么用?C++ Squad使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Squad类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getCurrentLoad

int TransportAgent::getCurrentLoad()
{
	Squad* sq = Commander::getInstance()->getSquad(squadID);
	if (sq != NULL)
	{
		int load = 0;
		vector<BaseAgent*> agents = sq->getMembers();
		for (int i = 0; i < (int)agents.size(); i++)
		{
			BaseAgent* a = agents.at(i);
			if (a->isAlive())
			{
				if (a->getUnit()->isLoaded())
				{
					if (a->getUnit()->getTransport()->getID() == unit->getID())
					{
						load += a->getUnitType().spaceRequired();
					}
				}
			}
		}
		currentLoad = load;
	}

	return currentLoad;
}
开发者ID:jieverson,项目名称:BTHAIMOD,代码行数:26,代码来源:TransportAgent.cpp

示例2: while

void CombatCommander::updateDefenseSquadUnits(Squad & defenseSquad, const size_t & flyingDefendersNeeded, const size_t & groundDefendersNeeded)
{
    auto & squadUnits = defenseSquad.getUnits();

    // TODO: right now this will assign arbitrary defenders, change this so that we make sure they can attack air/ground

    // if there's nothing left to defend, clear the squad
    if (flyingDefendersNeeded == 0 && groundDefendersNeeded == 0)
    {
        defenseSquad.clear();
        return;
    }

    size_t defendersNeeded = flyingDefendersNeeded + groundDefendersNeeded;
    size_t defendersAdded = 0;

    while (defendersNeeded > defendersAdded)
    {
        UnitTag defenderToAdd = findClosestDefender(defenseSquad, defenseSquad.getSquadOrder().getPosition());

        if (defenderToAdd)
        {
            m_squadData.assignUnitToSquad(defenderToAdd, defenseSquad);
            defendersAdded++;
        }
        else
        {
            break;
        }
    }
}
开发者ID:droiter,项目名称:commandcenter,代码行数:31,代码来源:CombatCommander.cpp

示例3: findUnitToLoad

BaseAgent* TransportAgent::findUnitToLoad(int spaceLimit)
{
	BaseAgent* agent = NULL;
	double bestDist = 100000;

	Squad* sq = Commander::getInstance()->getSquad(squadID);
	if (sq != NULL)
	{
		vector<BaseAgent*> agents = sq->getMembers();
		for (int i = 0; i < (int)agents.size(); i++)
		{
			BaseAgent* a = agents.at(i);
			if (isValidLoadUnit(a))
			{
				double cDist = unit->getPosition().getDistance(a->getUnit()->getPosition());
				if (cDist < bestDist)
				{
					bestDist = cDist;
					agent = a;
				}
			}
		}
	}

	return agent;
}
开发者ID:jieverson,项目名称:BTHAIMOD,代码行数:26,代码来源:TransportAgent.cpp

示例4: Squad

int Commander::addBunkerSquad()
{
	Squad* bSquad = new Squad(100 + AgentManager::getInstance()->countNoUnits(UnitTypes::Terran_Bunker), Squad::BUNKER, "BunkerSquad", 5);
	bSquad->addSetup(UnitTypes::Terran_Marine, 4);
	squads.push_back(bSquad);

	//Try to fill from other squads.
	int added = 0;
	for (Squad* s : squads)
	{
		if (s->isOffensive() || s->isDefensive())
		{
			for (int i = 0; i < 4 - added; i++)
			{
				if (s->hasUnits(UnitTypes::Terran_Marine, 1))
				{
					if (added < 4)
					{
						BaseAgent* ma = s->removeMember(UnitTypes::Terran_Marine);
						if (ma != NULL)
						{
							added++;
							bSquad->addMember(ma);
							ma->clearGoal();
						}
					}
				}
			}
		}
	}

	return bSquad->getID();
}
开发者ID:jhagelback,项目名称:OpprimoBot,代码行数:33,代码来源:Commander.cpp

示例5: isNeededInBunker

bool MarineAgent::isNeededInBunker()
{
	if (!unit->isLoaded())
	{
		Squad* sq = Commander::getInstance()->getSquad(squadID);
		if (sq != NULL)
		{
			if (sq->isBunkerDefend())
			{
				vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
				for (int i = 0; i < (int)agents.size(); i++)
				{
					if (agents.at(i)->isAlive() && agents.at(i)->isOfType(UnitTypes::Terran_Bunker))
				{
						if (agents.at(i)->getUnit()->getLoadedUnits().size() < 4)
				{
							unit->rightClick(agents.at(i)->getUnit());
							return true;
						}
					}
				}
			}
		}
	}
	return false;
}
开发者ID:BuffBuff,项目名称:BTHAI_3.0,代码行数:26,代码来源:MarineAgent.cpp

示例6: findUnitToLoad

BaseAgent* TransportAgent::findUnitToLoad(int spaceLimit)
{
	BaseAgent* agent = NULL;
	double bestDist = 100000;

	Squad* sq = Commander::getInstance()->getSquad(squadID);
	if (sq != NULL)
	{
		Agentset agents = sq->getMembers();
		for (auto &a : agents)
		{
			if (isValidLoadUnit(a))
			{
				double cDist = unit->getPosition().getDistance(a->getUnit()->getPosition());
				if (cDist < bestDist)
				{
					bestDist = cDist;
					agent = a;
				}
			}
		}
	}

	return agent;
}
开发者ID:JongKul,项目名称:bthai,代码行数:25,代码来源:TransportAgent.cpp

示例7: incoming

void NodeCombat::incoming(Squad s)
{
    const Gamer &g = s.getOwner();
    int ressource = s.getNbRessources();

    if(&g == owner)
    {
        //Entrée d'allier
        setRessources(nbRessources+ressource);
    }
    else
    {
        //Entrée d'ennemis
        if(invicible) ressource = 0;
        ressource = dealDamageOnArmor(ressource);
        if (nbRessources < ressource)
        {
            //Changement de propriétaire
            ressource -= nbRessources;
            setRessources(ressource);
            setOwner(&g);
        }
        else
        {
            setRessources(nbRessources-ressource);
        }
    }
}
开发者ID:LukasBitter,项目名称:P2,代码行数:28,代码来源:nodecombat.cpp

示例8: getCurrentLoad

int TransportAgent::getCurrentLoad()
{
	Squad* sq = Commander::getInstance()->getSquad(squadID);
	if (sq != NULL)
	{
		int load = 0;
		Agentset agents = sq->getMembers();
		for (auto &a : agents)
		{
			if (a->isAlive())
			{
				if (a->getUnit()->isLoaded())
				{
					if (a->getUnit()->getTransport()->getID() == unit->getID())
					{
						load += a->getUnitType().spaceRequired();
					}
				}
			}
		}
		currentLoad = load;
	}

	return currentLoad;
}
开发者ID:JongKul,项目名称:bthai,代码行数:25,代码来源:TransportAgent.cpp

示例9: numZerglingsInOurBase

void CombatCommander::updateDefenseSquadUnits(Squad & defenseSquad, const size_t & flyingDefendersNeeded, const size_t & groundDefendersNeeded)
{


	int zerglingsInOurBase = numZerglingsInOurBase();
	bool zerglingRush = zerglingsInOurBase > 0 && BWAPI::Broodwar->getFrameCount() < 5000;

	const BWAPI::Unitset & squadUnits = defenseSquad.getUnits();
	size_t flyingDefendersInSquad = std::count_if(squadUnits.begin(), squadUnits.end(), UnitUtil::CanAttackAir);
	size_t groundDefendersInSquad = std::count_if(squadUnits.begin(), squadUnits.end(), UnitUtil::CanAttackGround);

	// if there's nothing left to defend, clear the squad
	if (flyingDefendersNeeded == 0 && groundDefendersNeeded == 0)
	{
		defenseSquad.clear();
		return;
	}



	// add flying defenders if we still need them
	size_t flyingDefendersAdded = 0;
	while (flyingDefendersNeeded > flyingDefendersInSquad + flyingDefendersAdded)
	{
		BWAPI::Unit defenderToAdd = findClosestDefender(defenseSquad, defenseSquad.getSquadOrder().getPosition(), true);

		// if we find a valid flying defender, add it to the squad
		if (defenderToAdd)
		{
			_squadData.assignUnitToSquad(defenderToAdd, defenseSquad);
			++flyingDefendersAdded;
		}
		// otherwise we'll never find another one so break out of this loop
		else
		{
			break;
		}
	}


	// add ground defenders if we still need them
	size_t groundDefendersAdded = 0;
	while (groundDefendersNeeded > groundDefendersInSquad + groundDefendersAdded)
	{
		BWAPI::Unit defenderToAdd = findClosestDefender(defenseSquad, defenseSquad.getSquadOrder().getPosition(), false);

		// if we find a valid ground defender add it
		if (defenderToAdd)
		{
			_squadData.assignUnitToSquad(defenderToAdd, defenseSquad);
			++groundDefendersAdded;
		}
		// otherwise we'll never find another one so break out of this loop
		else
		{
			break;
		}
	}
}
开发者ID:cmput350-charles,项目名称:ualbertabot,代码行数:59,代码来源:CombatCommander.cpp

示例10: apiJoinSquad

int SquadBindings::apiJoinSquad(apikey squadKey, apikey shipKey) {
    Squad* squad = m_scriptEngine.get<Squad>(squadKey);
    if (!squad) { return -1; }

    Ship* ship = m_scriptEngine.get<Ship>(shipKey);
    if (!ship) { return -1; }

    ship->squadLogic()->joinSquadOf(squad->leader());
    return 0;
}
开发者ID:voxelinc,项目名称:voxellancer,代码行数:10,代码来源:squadbindings.cpp

示例11:

void	Squad::_copyUnits(const Squad& src)
{
	int	i = 0;
	int	n = src.getCount();

	while (i < n) {
		push(src.getUnit(i));
		++i;
	}
}
开发者ID:z0mbie42,项目名称:42,代码行数:10,代码来源:Squad.cpp

示例12: assistBuilding

void Commander::assistBuilding(BaseAgent* building) {
	for (int i = 0; i < (int)squads.size(); i++) {
		Squad* sq = squads.at(i);
		if (sq->isDefensive()) {
			sq->setGoal(building->getUnit()->getTilePosition());
		}
		if (sq->isOffensive() && currentState == DEFEND) {
			sq->setGoal(building->getUnit()->getTilePosition());
		}
	}
}
开发者ID:zarac,项目名称:tgspu-bthai,代码行数:11,代码来源:Commander.cpp

示例13: getSquad

void Commander::unitDestroyed(BaseAgent* agent)
{
	int squadID = agent->getSquadID();
	if (squadID != -1)
	{
		Squad* squad = getSquad(squadID);
		if (squad != NULL)
		{
			squad->removeMember(agent);
		}
	}
}
开发者ID:jieverson,项目名称:BTHAIMOD,代码行数:12,代码来源:Commander.cpp

示例14: apiCreatePatrolWaypointsTask

int SquadBindings::apiCreatePatrolWaypointsTask(apikey squadKey) {
    Squad* squad = m_scriptEngine.get<Squad>(squadKey);

    if (!squad) { return -1; }

    auto task = std::make_shared<PatrolWaypointsTask>(*squad);
    m_scriptEngine.registerScriptable(task.get());

    squad->setTask(task);

    return task->scriptKey();
}
开发者ID:voxelinc,项目名称:voxellancer,代码行数:12,代码来源:squadbindings.cpp

示例15: apiCreateDefendAreaTask

int SquadBindings::apiCreateDefendAreaTask(apikey squadKey, const glm::vec3& point, float range) {
    Squad* squad = m_scriptEngine.get<Squad>(squadKey);

    if (!squad) { return -1; }

    auto task = std::shared_ptr<DefendAreaTask>(new DefendAreaTask(*squad, { point }, range));
    m_scriptEngine.registerScriptable(task.get());

    squad->setTask(task);

    return task->scriptKey();
}
开发者ID:voxelinc,项目名称:voxellancer,代码行数:12,代码来源:squadbindings.cpp


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