本文整理汇总了C++中BaseAgent::getUnitID方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseAgent::getUnitID方法的具体用法?C++ BaseAgent::getUnitID怎么用?C++ BaseAgent::getUnitID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseAgent
的用法示例。
在下文中一共展示了BaseAgent::getUnitID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkUnitsToHeal
bool MedicAgent::checkUnitsToHeal()
{
try {
double bestDist = -1;
Unit* toHeal = NULL;
vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
for (int i = 0; i < (int)agents.size(); i++)
{
BaseAgent* agent = agents.at(i);
if (agent->isAlive() && agent->isDamaged())
{
if (isMedicTarget(agent->getUnit()) && agent->getUnitID() != unit->getID())
{
Unit* cUnit = agent->getUnit();
if (cUnit->exists() && cUnit->getHitPoints() > 0)
{
double dist = unit->getDistance(cUnit);
if (bestDist < 0 || dist < bestDist)
{
bestDist = dist;
toHeal = cUnit;
}
}
}
}
}
if (bestDist >= 0 && toHeal !=NULL)
{
//Broodwar->printf("[%d] Medic healing", unitID);
unit->useTech(TechTypes::Healing, toHeal);
}
}
catch(exception)
{
Broodwar->printf("[%d] checkUnitToHeal() error", unit->getID());
}
return false;
}
示例2: executeOrder
bool BuildPlanner::executeOrder(UnitType type)
{
//Max 3 concurrent buildings allowed at the same time
if ((int)buildQueue.size() >= 3)
{
return false;
}
////Hold if we are to build a new base
//if ((int)buildQueue.size() > 0)
//{
// if (buildQueue.at(0).toBuild.isResourceDepot())
// {
// return false;
// }
// vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
// for (int i = 0; i < (int)agents.size(); i++)
// {
// if (agents.at(i)->getUnitType().isResourceDepot() && agents.at(i)->getUnit()->isBeingConstructed())
// {
// return false; // TODO: Check if necessary
// }
// }
//}
if (type.isResourceDepot())
{
TilePosition pos = CoverMap::getInstance()->findExpansionSite();
if (pos.x() == -1)
{
Broodwar->printf("Removing expand as no expansion site could be found");
//No expansion site found.
if ((int)buildOrder.size() > 0) buildOrder.erase(buildOrder.begin());
return true;
}
}
if (type.isRefinery())
{
TilePosition rSpot = CoverMap::getInstance()->searchRefinerySpot();
if (rSpot.x() < 0)
{
//No buildspot found
if ((int)buildOrder.size() > 0) buildOrder.erase(buildOrder.begin());
return true;
}
}
if (isZerg())
{
pair<UnitType, int> builder = type.whatBuilds();
if (builder.first.getID() != UnitTypes::Zerg_Drone)
{
//Needs to be morphed
return executeMorph(builder.first, type);
}
}
//Check if we have resources
if (!ResourceManager::getInstance()->hasResources(type))
{
return false;
}
// TODO: Check if we can improve finding the best worker
vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
for (int i = 0; i < (int)agents.size(); i++)
{
BaseAgent* agent = agents.at(i);
if (agent != NULL && agent->isAlive())
{
if (agent->canBuild(type))
{
if (agent->assignToBuild(type))
{
lock(0, agent->getUnitID());
return true;
}
else
{
//Unable to find a buildspot. Dont bother checking for all
//other workers
handleNoBuildspotFound(type);
Broodwar->printf("No build spot found for %s", type.getName().c_str());
return false;
}
}
}
}
return false;
}