本文整理汇总了C++中bwapi::UnitType类的典型用法代码示例。如果您正苦于以下问题:C++ UnitType类的具体用法?C++ UnitType怎么用?C++ UnitType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnitType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetAllUnitCount
size_t UnitUtil::GetAllUnitCount(BWAPI::UnitType type)
{
size_t count = 0;
for (const auto & unit : BWAPI::Broodwar->self()->getUnits())
{
// trivial case: unit which exists matches the type
if (unit->getType() == type)
{
count++;
}
// case where a zerg egg contains the unit type
if (unit->getType() == BWAPI::UnitTypes::Zerg_Egg && unit->getBuildType() == type)
{
count += type.isTwoUnitsInOneEgg() ? 2 : 1;
}
// case where a building has started constructing a unit but it doesn't yet have a unit associated with it
if (unit->getRemainingTrainTime() > 0)
{
BWAPI::UnitType trainType = unit->getLastCommand().getUnitType();
if (trainType == type && unit->getRemainingTrainTime() == trainType.buildTime())
{
count++;
}
}
}
return count;
}
示例2: build
void UnitClass::build(TilePosition target, BWAPI::UnitType type)
{
if(exists())
{
const Position targetPosition(target.x()*32+type.tileWidth()*16, target.y()*32+type.tileHeight()*16);
if(getDistance(type, targetPosition) > 48 || !MapHelper::isAllVisible(target, type))
{
move(targetPosition, 0);
return;
}
if(mUnit->getOrder() == BWAPI::Orders::PlaceBuilding)
{
if(mUnit->getBuildType() == type && mUnit->getOrderTargetPosition() == targetPosition)
return;
}
if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Build && mUnit->getLastCommand().getUnitType() == type && mUnit->getLastCommand().getTargetTilePosition() == target)
{
if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount())
return;
}
if(mUnit->build(target, type))
mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames();
else
move(targetPosition, 0);
}
}
示例3: checkSupportedUnitType
void checkSupportedUnitType(const BWAPI::UnitType & type)
{
if (type == BWAPI::UnitTypes::None || type == BWAPI::UnitTypes::Unknown)
{
System::FatalError("Unknown unit type in experiment file");
}
if (type == BWAPI::UnitTypes::Protoss_Corsair ||
type == BWAPI::UnitTypes::Zerg_Devourer ||
type == BWAPI::UnitTypes::Zerg_Scourge ||
type == BWAPI::UnitTypes::Terran_Valkyrie)
{
System::FatalError("Units with just air weapons currently not supported correctly: " + type.getName());
}
if (type.isBuilding() && (type != BWAPI::UnitTypes::Protoss_Photon_Cannon || type != BWAPI::UnitTypes::Zerg_Sunken_Colony || type != BWAPI::UnitTypes::Terran_Missile_Turret))
{
System::FatalError("Non-attacking buildings not currently supported: " + type.getName());
}
if (type.isSpellcaster())
{
System::FatalError("Spell casting units not currently supported: " + type.getName());
}
}
示例4: getAttackPriority
// get the attack priority of a type in relation to a zergling
int RangedManager::getAttackPriority(BWAPI::UnitInterface* rangedUnit, BWAPI::UnitInterface* target)
{
BWAPI::UnitType rangedUnitType = rangedUnit->getType();
BWAPI::UnitType targetType = target->getType();
bool canAttackUs = rangedUnitType.isFlyer() ? targetType.airWeapon() != BWAPI::WeaponTypes::None : targetType.groundWeapon() != BWAPI::WeaponTypes::None;
// highest priority is something that can attack us or aid in combat
if (targetType == BWAPI::UnitTypes::Terran_Medic || canAttackUs ||
targetType == BWAPI::UnitTypes::Terran_Bunker)
{
return 3;
}
// next priority is worker
else if (targetType.isWorker())
{
return 2;
}
// then everything else
else
{
return 1;
}
}
示例5: hasResources
bool BuildOrderManager::hasResources(BWAPI::UnitType t)
{
if (BWAPI::Broodwar->self()->cumulativeMinerals()-this->usedMinerals<t.mineralPrice())
return false;
if (BWAPI::Broodwar->self()->cumulativeGas()-this->usedGas<t.gasPrice())
return false;
return true;
}
示例6:
void sim::UnitProps::SetType(BWAPI::UnitType type)
{
this->type = type;
maxEnergy[0] = maxEnergy[1] = type.maxEnergy();
sightRange[0] = sightRange[1] = type.sightRange() << pixelShift;
extraArmor[0] = extraArmor[1] = 0;
speed[0] = speed[1] = static_cast<int>((1 << pixelShift) * type.topSpeed());
}
示例7: hasResources
bool BuildOrderManager::hasResources(BWAPI::UnitType t, int time)
{
pair<int, Resources> res;
res.first=time;
res.second.minerals=t.mineralPrice();
res.second.gas=t.gasPrice();
bool ret=hasResources(res);
return ret;
}
示例8: onSendText
void UAlbertaBotModule::onSendText(std::string text)
{
if (Config::Modules::UsingBuildOrderDemo)
{
std::stringstream type;
std::stringstream numUnitType;
size_t numUnits = 0;
size_t i=0;
for (i=0; i<text.length(); ++i)
{
if (text[i] == ' ')
{
i++;
break;
}
type << text[i];
}
for (; i<text.length(); ++i)
{
numUnitType << text[i];
}
numUnits = atoi(numUnitType.str().c_str());
BWAPI::UnitType t;
for (const BWAPI::UnitType & tt : BWAPI::UnitTypes::allUnitTypes())
{
if (tt.getName().compare(type.str()) == 0)
{
t = tt;
break;
}
}
BWAPI::Broodwar->printf("Searching for %d of %s", numUnits, t.getName().c_str());
if (t != BWAPI::UnitType())
{
MetaPairVector goal;
goal.push_back(MetaPair(BWAPI::UnitTypes::Protoss_Probe, 8));
goal.push_back(MetaPair(BWAPI::UnitTypes::Protoss_Gateway, 2));
goal.push_back(MetaPair(t, numUnits));
ProductionManager::Instance().setSearchGoal(goal);
}
else
{
BWAPI::Broodwar->printf("Unknown unit type %s", type.str().c_str());
}
}
}
示例9: canBuildHere
bool BuildingPlacer::canBuildHere(BWAPI::TilePosition position, BWAPI::UnitType type) const
{
if (!BWAPI::Broodwar->canBuildHere(NULL, position, type))
return false;
for(int x = position.x(); x < position.x() + type.tileWidth(); x++)
for(int y = position.y(); y < position.y() + type.tileHeight(); y++)
if (reserveMap[x][y])
return false;
return true;
}
示例10: addBuildingTask
// add a new building to be constructed
void BuildingManager::addBuildingTask(BWAPI::UnitType type, BWAPI::TilePosition desiredLocation, bool isGasSteal)
{
_reservedMinerals += type.mineralPrice();
_reservedGas += type.gasPrice();
Building b(type, desiredLocation);
b.isGasSteal = isGasSteal;
b.status = BuildingStatus::Unassigned;
_buildings.push_back(b);
}
示例11: drawCommandStatus
void UnitCommandManager::drawCommandStatus(BWAPI::UnitInterface* unit)
{
BWAPI::UnitType type = unit->getType();
int width = type.dimensionRight();
int height = type.dimensionDown()/6;
int x1 = unit->getPosition().x - width;
int x2 = unit->getPosition().y + width;
int y1 = unit->getPosition().y - height;
int y2 = unit->getPosition().y + height;
}
示例12: buildAdditional
void BuildOrderManager::buildAdditional(int count, BWAPI::UnitType t, int priority, BWAPI::TilePosition seedPosition)
{
if (t == BWAPI::UnitTypes::None || t == BWAPI::UnitTypes::Unknown) return;
if (seedPosition == BWAPI::TilePositions::None || seedPosition == BWAPI::TilePositions::Unknown)
seedPosition=BWAPI::Broodwar->self()->getStartLocation();
if (items[priority].units[t.whatBuilds().first].find(t)==items[priority].units[t.whatBuilds().first].end())
items[priority].units[t.whatBuilds().first].insert(make_pair(t,UnitItem(t)));
items[priority].units[t.whatBuilds().first][t].addAdditional(count,seedPosition);
nextUpdateFrame=0;
}
示例13: canBuildHere
bool BuildingPlacer::canBuildHere(BWAPI::TilePosition position, BWAPI::UnitType type) const
{
//returns true if we can build this type of unit here. Takes into account reserved tiles.
if (!BWAPI::Broodwar->canBuildHere(NULL, position, type))
return false;
for(int x = position.x(); x < position.x() + type.tileWidth(); x++)
for(int y = position.y(); y < position.y() + type.tileHeight(); y++)
if (reserveMap[x][y])
return false;
return true;
}
示例14: TireBaseBuilding
//----------------------------------------------------------------------------------------------
EntityClassType StarCraftTechTree::TireBaseBuilding(BaseType p_tireId) const
{
BWAPI::UnitType baseType;
if (p_tireId == BASETYPE_END)
return ECLASS_END;
baseType = m_player->getRace().getCenter();
return g_Database.EntityMapping.GetByFirst(baseType.getID());
}
示例15: canBuildHereWithSpace
bool BuildingPlacer::canBuildHereWithSpace(BWAPI::TilePosition position, BWAPI::UnitType type) const
{
if (!this->canBuildHere(position, type))
return false;
int width=type.tileWidth();
int height=type.tileHeight();
if (type==BWAPI::UnitTypes::Terran_Command_Center ||
type==BWAPI::UnitTypes::Terran_Factory ||
type==BWAPI::UnitTypes::Terran_Starport ||
type==BWAPI::UnitTypes::Terran_Science_Facility)
{
width+=2;
}
int startx = position.x() - buildDistance;
if (startx<0) startx=0;
int starty = position.y() - buildDistance;
if (starty<0) starty=0;
int endx = position.x() + width + buildDistance;
if (endx>BWAPI::Broodwar->mapWidth()) endx=BWAPI::Broodwar->mapWidth();
int endy = position.y() + height + buildDistance;
if (endy>BWAPI::Broodwar->mapHeight()) endy=BWAPI::Broodwar->mapHeight();
for(int x = startx; x < endx; x++)
for(int y = starty; y < endy; y++)
if (!type.isRefinery())
if (!buildable(x, y))
return false;
if (position.x()>3)
{
int startx2=startx-2;
if (startx2<0) startx2=0;
for(int x = startx2; x < startx; x++)
for(int y = starty; y < endy; y++)
{
std::set<BWAPI::Unit*> units = BWAPI::Broodwar->unitsOnTile(x, y);
for(std::set<BWAPI::Unit*>::iterator i = units.begin(); i != units.end(); i++)
{
if (!(*i)->isLifted())
{
BWAPI::UnitType type=(*i)->getType();
if (type==BWAPI::UnitTypes::Terran_Command_Center ||
type==BWAPI::UnitTypes::Terran_Factory ||
type==BWAPI::UnitTypes::Terran_Starport ||
type==BWAPI::UnitTypes::Terran_Science_Facility)
{
return false;
}
}
}
}
}
return true;
}