本文整理汇总了C++中BaseAgent::canBuild方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseAgent::canBuild方法的具体用法?C++ BaseAgent::canBuild怎么用?C++ BaseAgent::canBuild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseAgent
的用法示例。
在下文中一共展示了BaseAgent::canBuild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}