本文整理汇总了C++中bwta::BaseLocation类的典型用法代码示例。如果您正苦于以下问题:C++ BaseLocation类的具体用法?C++ BaseLocation怎么用?C++ BaseLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseLocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawScoutInformation
void ScoutManager::drawScoutInformation(int x, int y)
{
if (!Config::Debug::DrawScoutInfo)
{
return;
}
BWAPI::Broodwar->drawTextScreen(x, y - 10, "Enemy base timer == %d", patrol_counter);
BWAPI::Broodwar->drawTextScreen(x, y, "ScoutInfo: %s", _scoutStatus.c_str());
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
double distance = 0.0;
if (_workerScout && _workerScout->exists() && enemyBaseLocation)
{
BWAPI::Position tmp = BWAPI::Position(enemyBaseLocation->getTilePosition());
int x1 = _workerScout->getPosition().x;
int y1 = _workerScout->getPosition().y;
int x2 = tmp.x;
int y2 = tmp.y;
distance = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) + 0.0);
}
BWAPI::Broodwar->drawTextScreen(x, y+10, "Distance to enemy base: %.2lf", distance);
for (size_t i(0); i < _enemyRegionVertices.size(); ++i)
{
BWAPI::Broodwar->drawCircleMap(_enemyRegionVertices[i], 4, BWAPI::Colors::Green, false);
BWAPI::Broodwar->drawTextMap(_enemyRegionVertices[i], "%d", i);
}
}
示例2: getNextExpansionLocation
BWAPI::TilePosition getNextExpansionLocation(TilePosition currentExpo)
{
//remove the current expo from the list
//loop through expos and find the nearest one
std::set<BWTA::BaseLocation*> bases;
for (auto &u : allBases)
{
//make sure we delete the current expansion
if (u->getTilePosition() == currentExpo)
{
allBases.erase(u);
}
}
BWTA::BaseLocation *ret = *allBases.begin();
int minDistance = currentExpo.getApproxDistance(ret->getTilePosition());
//make sure we dont accidently find current expansion
for (auto &u : allBases)
{
int tempDistance = currentExpo.getApproxDistance(u->getTilePosition());
if (tempDistance < minDistance && tempDistance > 10)
{
//found a closer base
minDistance = tempDistance;
ret = u;
}
}
return ret->getTilePosition();
}
示例3: getMainAttackLocation
BWAPI::Position CombatCommander::getMainAttackLocation()
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
// First choice: Attack an enemy region if we can see units inside it
if (enemyBaseLocation)
{
BWAPI::Position enemyBasePosition = enemyBaseLocation->getPosition();
// get all known enemy units in the area
BWAPI::Unitset enemyUnitsInArea;
MapGrid::Instance().GetUnits(enemyUnitsInArea, enemyBasePosition, 800, false, true);
bool onlyOverlords = true;
for (auto & unit : enemyUnitsInArea)
{
if (unit->getType() != BWAPI::UnitTypes::Zerg_Overlord)
{
onlyOverlords = false;
}
}
if (!BWAPI::Broodwar->isExplored(BWAPI::TilePosition(enemyBasePosition)) || !enemyUnitsInArea.empty())
{
if (!onlyOverlords)
{
return enemyBaseLocation->getPosition();
}
}
}
// Second choice: Attack known enemy buildings
for (const auto & kv : InformationManager::Instance().getUnitInfo(BWAPI::Broodwar->enemy()))
{
const UnitInfo & ui = kv.second;
if (ui.type.isBuilding() && ui.lastPosition != BWAPI::Positions::None)
{
return ui.lastPosition;
}
}
// Third choice: Attack visible enemy units that aren't overlords
for (auto & unit : BWAPI::Broodwar->enemy()->getUnits())
{
if (unit->getType() == BWAPI::UnitTypes::Zerg_Overlord)
{
continue;
}
if (UnitUtil::IsValidUnit(unit) && unit->isVisible())
{
return unit->getPosition();
}
}
// Fourth choice: We can't see anything so explore the map attacking along the way
return MapGrid::Instance().getLeastExplored();
}
示例4: getBuildingLocation
BWAPI::TilePosition BuildingManager::getBuildingLocation(const Building & b)
{
int numPylons = BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Protoss_Pylon);
if (b.isGasSteal)
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
UAB_ASSERT(enemyBaseLocation,"Should have enemy base location before attempting gas steal");
UAB_ASSERT(enemyBaseLocation->getGeysers().size() > 0,"Should have spotted an enemy geyser");
for (auto & unit : enemyBaseLocation->getGeysers())
{
BWAPI::TilePosition tp(unit->getInitialTilePosition());
return tp;
}
}
if (b.type.requiresPsi() && numPylons == 0)
{
return BWAPI::TilePositions::None;
}
//if building a bunker for strategy "Terran_Custom", return one location near an attacked unit
if ((b.type == BWAPI::UnitTypes::Terran_Bunker) && (Config::Strategy::StrategyName == "Terran_Custom"))
{
for (auto & unit : BWAPI::Broodwar->self()->getUnits())
{
if (unit->isUnderAttack())
{
return BuildingPlacer::Instance().getBuildLocationNear(b, 1, false);
break;
}
}
}
if (b.type.isRefinery())
{
return BuildingPlacer::Instance().getRefineryPosition();
}
if (b.type.isResourceDepot())
{
// get the location
BWAPI::TilePosition tile = MapTools::Instance().getNextExpansion();
return tile;
}
// set the building padding specifically
int distance = b.type == BWAPI::UnitTypes::Protoss_Photon_Cannon ? 0 : Config::Macro::BuildingSpacing;
if (b.type == BWAPI::UnitTypes::Protoss_Pylon && (numPylons < 3))
{
distance = Config::Macro::PylonSpacing;
}
// get a position within our region
return BuildingPlacer::Instance().getBuildLocationNear(b,distance,false);
}
示例5: updateAttackSquads
void CombatCommander::updateAttackSquads()
{
Squad & mainAttackSquad = _squadData.getSquad("MainAttack");
//check for overlord in squad
bool containsoverlord = false;
int numOverlords = 0;
for (auto& unit : mainAttackSquad.getUnits()) {
if (unit->getType() == BWAPI::UnitTypes::Zerg_Overlord)
{
containsoverlord = true;
numOverlords++;
}
}
// BWAPI::Broodwar->printf("Overlords in Attack squad: %d", numOverlords);
for (auto & unit : _combatUnits)
{
if (unit->getType() == BWAPI::UnitTypes::Zerg_Scourge && UnitUtil::GetAllUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) < 30)
{
continue;
}
// get every unit of a lower priority and put it into the attack squad
if (!unit->getType().isWorker() && (unit->getType() != BWAPI::UnitTypes::Zerg_Lurker) && _squadData.canAssignUnitToSquad(unit, mainAttackSquad))
{
if (unit->getType() == BWAPI::UnitTypes::Zerg_Overlord)
{
if (!containsoverlord && numOverlords < 2)
{
_squadData.assignUnitToSquad(unit, mainAttackSquad);
containsoverlord = true;
numOverlords++;
}
}
else {
_squadData.assignUnitToSquad(unit, mainAttackSquad);
}
}
}
// Defend bases until we have 3 lurkers
if (BWAPI::Broodwar->self()->getRace() == BWAPI::Races::Zerg && mainAttackSquad.getUnits().size() < 10) {
BWTA::BaseLocation * pos = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->self());
SquadOrder mainAttackOrder(SquadOrderTypes::Defend, pos->getPosition(), 250, "Defend Region!");
mainAttackSquad.setSquadOrder(mainAttackOrder);
return;
}
SquadOrder mainAttackOrder(SquadOrderTypes::Attack, getMainAttackLocation(), 800, "Attack Enemy Base");
mainAttackSquad.setSquadOrder(mainAttackOrder);
}
示例6: getEnemyGeyser
BWAPI::Unit ScoutManager::getEnemyGeyser()
{
BWAPI::Unit geyser = nullptr;
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
for (auto & unit : enemyBaseLocation->getGeysers())
{
geyser = unit;
}
return geyser;
}
示例7: getEnemyGeyser
BWAPI::UnitInterface* ScoutManager::getEnemyGeyser()
{
BWAPI::UnitInterface* geyser = NULL;
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
for (BWAPI::UnitInterface* unit : enemyBaseLocation->getGeysers())
{
geyser = unit;
}
return geyser;
}
示例8: check
void ProbeUnit::check()
{
if (backUpMineral == NULL || !backUpMineral->exists())
{
if (Broodwar->getFrameCount() < 10*24*60)
{
BWTA::BaseLocation* b = BWTA::getStartLocation(Broodwar->self());
if (b != NULL && !b->getMinerals().empty())
backUpMineral = *(b->getMinerals().begin());
if (backUpMineral == NULL || !backUpMineral->exists())
backUpMineral = NULL;
}
}
}
示例9: onRevoke
void ScoutManager::onRevoke( BWAPI::Unit unit, double bid )
{
if ( m_scouts.find( unit ) != m_scouts.end() )
{
BWTA::BaseLocation* lostTarget = m_scouts[unit].m_target;
if ( m_baseLocationsExplored.find( lostTarget ) == m_baseLocationsExplored.end() )
{
m_baseLocationsToScout.push_back( lostTarget );
if ( m_debugMode )
{
BWAPI::Broodwar->printf( "Reassigning ( %d, %d )", lostTarget->getPosition().x, lostTarget->getPosition().y );
}
}
m_scouts.erase( unit );
}
}
示例10: expand
BWTA::BaseLocation* BaseManager::expand(int priority)
{
BWTA::BaseLocation* location = NULL;
BWTA::BaseLocation* locationWithoutGas = NULL;
double minDist=-1;
BWTA::BaseLocation* home = BWTA::getStartLocation(BWAPI::Broodwar->self());
std::set<BWTA::BaseLocation*>::const_iterator i;
for(i = BWTA::getBaseLocations().begin(); i != BWTA::getBaseLocations().end(); i++)
{
BWTA::BaseLocation *baseLocation = (*i);
if (baseLocation->isIsland())
{
continue;
}
double dist = home->getGroundDistance(baseLocation);
if (dist > 0 && getBase(baseLocation) == NULL)
{
if (minDist == -1 || dist < minDist)
{
if (baseLocation->isMineralOnly())
{
locationWithoutGas = baseLocation;
}
else
{
location = baseLocation;
minDist = dist;
}
}
}
}
if (location == NULL && locationWithoutGas != NULL)
{
BWAPI::Broodwar->printf("Expanding to location without gas.");
location = locationWithoutGas;
}
return expand(location, priority);
}
示例11: getBuildingLocation
BWAPI::TilePosition BuildingManager::getBuildingLocation(const Building & b)
{
int numPylons = BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Protoss_Pylon);
if (b.isGasSteal)
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
UAB_ASSERT(enemyBaseLocation,"Should have enemy base location before attempting gas steal");
UAB_ASSERT(enemyBaseLocation->getGeysers().size() > 0,"Should have spotted an enemy geyser");
for (auto & unit : enemyBaseLocation->getGeysers())
{
BWAPI::TilePosition tp(unit->getInitialTilePosition());
return tp;
}
}
if (b.type.requiresPsi() && numPylons == 0)
{
return BWAPI::TilePositions::None;
}
if (b.type.isRefinery())
{
return BuildingPlacer::Instance().getRefineryPosition();
}
if (b.type.isResourceDepot())
{
// get the location
BWAPI::TilePosition tile = MapTools::Instance().getNextExpansion();
return tile;
}
if (b.type == BWAPI::UnitTypes::Terran_Bunker)
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
UAB_ASSERT(enemyBaseLocation, "Should have enemy base location before attempting gas steal");
BWTA::Chokepoint * chokePoint = BWTA::getNearestChokepoint(enemyBaseLocation->getTilePosition());
std::pair<BWAPI::Position, BWAPI::Position> sides = chokePoint->getSides();
BWAPI::Position poi = enemyBaseLocation->getPosition().getDistance(sides.first) > enemyBaseLocation->getPosition().getDistance(sides.second) ? sides.first : sides.second;
//BWAPI::Broodwar->printf("Tisssle Position (%d, %d)", BWAPI::TilePosition(poi).x, BWAPI::TilePosition(poi).y);
return BWAPI::TilePosition(sides.second);
}
// set the building padding specifically
int distance = b.type == BWAPI::UnitTypes::Protoss_Photon_Cannon ? 0 : Config::Macro::BuildingSpacing;
if (b.type == BWAPI::UnitTypes::Protoss_Pylon && (numPylons < 3))
{
distance = Config::Macro::PylonSpacing;
}
// get a position within our region
return BuildingPlacer::Instance().getBuildLocationNear(b,distance,false);
}
示例12: isGasStealRefinery
bool WorkerManager::isGasStealRefinery(BWAPI::Unit unit)
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
if (!enemyBaseLocation)
{
return false;
}
if (enemyBaseLocation->getGeysers().empty())
{
return false;
}
for (auto & u : enemyBaseLocation->getGeysers())
{
if (unit->getTilePosition() == u->getTilePosition())
{
return true;
}
}
return false;
}
示例13: checkEnemyMovedOut
void InformationManager::checkEnemyMovedOut(){
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
BWTA::BaseLocation * ourBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->self());
BWAPI::TilePosition ourBase = BWAPI::TilePosition(ourBaseLocation->getPosition());
if (enemyBaseLocation == nullptr)
{
double baseToBase = 0;
if (_distToFarthestBase < 1.0)
{
double currentBtoB = 0;
for (auto &bases : BWTA::getStartLocations())
{
currentBtoB = BWTA::getGroundDistance(ourBase, bases->getTilePosition());
if (currentBtoB > baseToBase)
{
baseToBase = currentBtoB;
}
}
_distToFarthestBase = baseToBase;
}
baseToBase = _distToFarthestBase;
double baseToUnit;
for (auto &unit : InformationManager::Instance().getUnitInfo(BWAPI::Broodwar->enemy()))
{
if (UnitUtil::IsCombatUnit(unit.second.unit))
{
BWAPI::TilePosition enemyPos = BWAPI::TilePosition(unit.second.lastPosition);
if (_movedOutMap.count(enemyPos) != 0)
{
if (_movedOutMap[enemyPos] == true)
{
//BWAPI::Broodwar->printf("Enemy has moved out!");
_enemyMovedOut = true;
return;
}
}
else
{
baseToUnit = BWTA::getGroundDistance(ourBase, BWAPI::TilePosition(unit.second.lastPosition));
if (baseToUnit < baseToBase)
{
//BWAPI::Broodwar->printf("Enemy has moved out!");
_enemyMovedOut = true;
_movedOutMap[enemyPos] = true;
return;
}
else
{
_movedOutMap[enemyPos] = false;
}
}
}
}
_enemyMovedOut = false;
//BWAPI::Broodwar->printf("Enemy in their base");
}
else
{
BWAPI::TilePosition enemyChoke = BWAPI::TilePosition(BWTA::getNearestChokepoint(enemyBaseLocation->getPosition())->getCenter());
if (_distToEnemyChoke < 1.0)
{
_distToEnemyChoke = BWTA::getGroundDistance(ourBase, enemyChoke);
}
double baseToChoke = _distToEnemyChoke;
double baseToUnit;
for (auto &unit : InformationManager::Instance().getUnitInfo(BWAPI::Broodwar->enemy()))
{
if (UnitUtil::IsCombatUnit(unit.second.unit))
{
BWAPI::TilePosition enemyPos = BWAPI::TilePosition(unit.second.lastPosition);
if (_movedOutMap.count(enemyPos) != 0)
{
if (_movedOutMap[enemyPos] == true)
{
//BWAPI::Broodwar->printf("Enemy has moved out!");
_enemyMovedOut = true;
return;
}
}
else
{
baseToUnit = BWTA::getGroundDistance(ourBase, enemyPos);
if (baseToUnit < baseToChoke)
{
//BWAPI::Broodwar->printf("Enemy has moved out!");
_enemyMovedOut = true;
_movedOutMap[enemyPos] = true;
return;
}
else
{
_movedOutMap[enemyPos] = false;
}
}
}
}
_enemyMovedOut = false;
//BWAPI::Broodwar->printf("Enemy in their base");
}
}
示例14: getNextExpansion
BWAPI::TilePosition MapTools::getNextExpansion(BWAPI::Player player)
{
BWTA::BaseLocation * closestBase = nullptr;
double minDistance = 100000;
BWAPI::TilePosition homeTile = player->getStartLocation();
// for each base location
for (BWTA::BaseLocation * base : BWTA::getBaseLocations())
{
// if the base has gas
if (!base->isMineralOnly() && !(base == BWTA::getStartLocation(player)))
{
// get the tile position of the base
BWAPI::TilePosition tile = base->getTilePosition();
bool buildingInTheWay = false;
for (int x = 0; x < BWAPI::Broodwar->self()->getRace().getCenter().tileWidth(); ++x)
{
for (int y = 0; y < BWAPI::Broodwar->self()->getRace().getCenter().tileHeight(); ++y)
{
BWAPI::TilePosition tp(tile.x + x, tile.y + y);
for (auto & unit : BWAPI::Broodwar->getUnitsOnTile(tp))
{
if (unit->getType().isBuilding() && !unit->isFlying())
{
buildingInTheWay = true;
break;
}
}
}
}
if (buildingInTheWay)
{
continue;
}
// the base's distance from our main nexus
BWAPI::Position myBasePosition(player->getStartLocation());
BWAPI::Position thisTile = BWAPI::Position(tile);
double distanceFromHome = MapTools::Instance().getGroundDistance(thisTile,myBasePosition);
// if it is not connected, continue
if (!BWTA::isConnected(homeTile,tile) || distanceFromHome < 0)
{
continue;
}
if (!closestBase || distanceFromHome < minDistance)
{
closestBase = base;
minDistance = distanceFromHome;
}
}
}
if (closestBase)
{
return closestBase->getTilePosition();
}
else
{
return BWAPI::TilePositions::None;
}
}
示例15: moveScouts
void ScoutManager::moveScouts()
{
if (!_workerScout || !_workerScout->exists() || !(_workerScout->getHitPoints() > 0))
{
return;
}
int scoutHP = _workerScout->getHitPoints() + _workerScout->getShields();
gasSteal();
// get the enemy base location, if we have one
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
int scoutDistanceThreshold = 30;
if (_workerScout->isCarryingGas())
{
BWAPI::Broodwar->drawCircleMap(_workerScout->getPosition(), 10, BWAPI::Colors::Purple, true);
}
// if we initiated a gas steal and the worker isn't idle,
bool finishedConstructingGasSteal = _workerScout->isIdle() || _workerScout->isCarryingGas();
if (!_gasStealFinished && _didGasSteal && !finishedConstructingGasSteal)
{
return;
}
// check to see if the gas steal is completed
else if (_didGasSteal && finishedConstructingGasSteal)
{
_gasStealFinished = true;
}
// if we know where the enemy region is and where our scout is
if (_workerScout && enemyBaseLocation)
{
int scoutDistanceToEnemy = MapTools::Instance().getGroundDistance(_workerScout->getPosition(), enemyBaseLocation->getPosition());
bool scoutInRangeOfenemy = scoutDistanceToEnemy <= scoutDistanceThreshold;
// we only care if the scout is under attack within the enemy region
// this ignores if their scout worker attacks it on the way to their base
if (scoutHP < _previousScoutHP)
{
_scoutUnderAttack = true;
}
if (!_workerScout->isUnderAttack() && !enemyWorkerInRadius())
{
_scoutUnderAttack = false;
}
// if the scout is in the enemy region
if (scoutInRangeOfenemy)
{
// get the closest enemy worker
BWAPI::Unit closestWorker = closestEnemyWorker();
// if the worker scout is not under attack
if (!_scoutUnderAttack)
{
// if there is a worker nearby, harass it
if (Config::Strategy::ScoutHarassEnemy && (!Config::Strategy::GasStealWithScout || _gasStealFinished) && closestWorker && (_workerScout->getDistance(closestWorker) < 800))
{
_scoutStatus = "Harass enemy worker";
_currentRegionVertexIndex = -1;
Micro::SmartAttackUnit(_workerScout, closestWorker);
}
// otherwise keep moving to the enemy region
else
{
_scoutStatus = "Following perimeter";
followPerimeter();
}
}
// if the worker scout is under attack
else
{
_scoutStatus = "Under attack inside, fleeing";
followPerimeter();
}
}
// if the scout is not in the enemy region
else if (_scoutUnderAttack)
{
_scoutStatus = "Under attack inside, fleeing";
followPerimeter();
}
else
{
_scoutStatus = "Enemy region known, going there";
// move to the enemy region
followPerimeter();
}
}
// for each start location in the level
//.........这里部分代码省略.........