本文整理汇总了C++中MetaType::whatBuilds方法的典型用法代码示例。如果您正苦于以下问题:C++ MetaType::whatBuilds方法的具体用法?C++ MetaType::whatBuilds怎么用?C++ MetaType::whatBuilds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetaType
的用法示例。
在下文中一共展示了MetaType::whatBuilds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getProducer
BWAPI::Unit ProductionManager::getProducer(MetaType t, BWAPI::Position closestTo)
{
// get the type of unit that builds this
BWAPI::UnitType producerType = t.whatBuilds();
// make a set of all candidate producers
BWAPI::Unitset candidateProducers;
for (auto & unit : BWAPI::Broodwar->self()->getUnits())
{
UAB_ASSERT(unit != nullptr, "Unit was null");
// reasons a unit can not train the desired type
if (unit->getType() != producerType) { continue; }
if (!unit->isCompleted()) { continue; }
if (unit->isTraining()) { continue; }
if (unit->isLifted()) { continue; }
if (!unit->isPowered()) { continue; }
// if the type is an addon, some special cases
if (t.getUnitType().isAddon())
{
// if the unit already has an addon, it can't make one
if (unit->getAddon() != nullptr)
{
continue;
}
// if we just told this unit to build an addon, then it will not be building another one
// this deals with the frame-delay of telling a unit to build an addon and it actually starting to build
if (unit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Build_Addon
&& (BWAPI::Broodwar->getFrameCount() - unit->getLastCommandFrame() < 10))
{
continue;
}
bool isBlocked = false;
// if the unit doesn't have space to build an addon, it can't make one
BWAPI::TilePosition addonPosition(unit->getTilePosition().x + unit->getType().tileWidth(), unit->getTilePosition().y + unit->getType().tileHeight() - t.getUnitType().tileHeight());
BWAPI::Broodwar->drawBoxMap(addonPosition.x*32, addonPosition.y*32, addonPosition.x*32 + 64, addonPosition.y*32 + 64, BWAPI::Colors::Red);
for (int i=0; i<unit->getType().tileWidth() + t.getUnitType().tileWidth(); ++i)
{
for (int j=0; j<unit->getType().tileHeight(); ++j)
{
BWAPI::TilePosition tilePos(unit->getTilePosition().x + i, unit->getTilePosition().y + j);
// if the map won't let you build here, we can't build it
if (!BWAPI::Broodwar->isBuildable(tilePos))
{
isBlocked = true;
BWAPI::Broodwar->drawBoxMap(tilePos.x*32, tilePos.y*32, tilePos.x*32 + 32, tilePos.y*32 + 32, BWAPI::Colors::Red);
}
// if there are any units on the addon tile, we can't build it
BWAPI::Unitset uot = BWAPI::Broodwar->getUnitsOnTile(tilePos.x, tilePos.y);
if (uot.size() > 0 && !(uot.size() == 1 && *(uot.begin()) == unit))
{
isBlocked = true;;
BWAPI::Broodwar->drawBoxMap(tilePos.x*32, tilePos.y*32, tilePos.x*32 + 32, tilePos.y*32 + 32, BWAPI::Colors::Red);
}
}
}
if (isBlocked)
{
continue;
}
}
// if the type requires an addon and the producer doesn't have one
typedef std::pair<BWAPI::UnitType, int> ReqPair;
for (const ReqPair & pair : t.getUnitType().requiredUnits())
{
BWAPI::UnitType requiredType = pair.first;
if (requiredType.isAddon())
{
if (!unit->getAddon() || (unit->getAddon()->getType() != requiredType))
{
continue;
}
}
}
// if we haven't cut it, add it to the set of candidates
candidateProducers.insert(unit);
}
return getClosestUnitToPosition(candidateProducers, closestTo);
}