|
BWAPI
|

Public Member Functions | |
| PossibleLocationCompare (UnitGroup *resources, TilePosition *bestLocation) | |
| bool | operator() (TilePosition &location) |
Private Attributes | |
| unsigned int | mBestRating |
| TilePosition * | mBestLocation |
| UnitGroup * | mResources |
Definition at line 508 of file TerrainAnaysis.cpp.
| PossibleLocationCompare::PossibleLocationCompare | ( | UnitGroup * | resources, |
| TilePosition * | bestLocation | ||
| ) | [inline] |
Definition at line 511 of file TerrainAnaysis.cpp.
: mBestLocation(bestLocation) , mResources(resources) , mBestRating(std::numeric_limits<unsigned int>::max()) {}
| bool PossibleLocationCompare::operator() | ( | TilePosition & | location | ) | [inline] |
Definition at line 517 of file TerrainAnaysis.cpp.
References BWAPI::Broodwar, BWAPI::UnitType::dimensionDown(), BWAPI::UnitType::dimensionLeft(), BWAPI::UnitType::dimensionRight(), BWAPI::UnitType::dimensionUp(), BWAPI::Position::getApproxDistance(), BWAPI::Race::getCenter(), BWAPI::Player::getRace(), BWAPI::Game::mapHeight(), mBestLocation, mBestRating, mResources, BWAPI::UnitTypes::Protoss_Nexus, BWAPI::UnitTypes::Resource_Mineral_Field, BWAPI::Game::self(), BWAPI::UnitType::tileHeight(), BWAPI::UnitType::tileWidth(), BWAPI::TilePosition::x(), BWAPI::Position::x(), BWAPI::TilePosition::y(), and BWAPI::Position::y().
{
for(int x = location.x(); x < location.x() + BWAPI::UnitTypes::Protoss_Nexus.tileWidth(); ++x)
{
for(int y = location.y(); y < location.y() + BWAPI::UnitTypes::Protoss_Nexus.tileHeight(); ++y)
{
if(x < 0 && y < 0 && x >= BWAPI::Broodwar->mapWidth() && y >= BWAPI::Broodwar->mapHeight())
return false;
if(!BWAPI::Broodwar->isBuildable(x, y))
return false;
}
}
unsigned int distanceToResources = 0;
for each(const Unit &resource in *mResources)
{
const BWAPI::UnitType &resourceType = resource->getType();
const TilePosition &resourceTilePosition = resource->getTilePosition();
if (resourceTilePosition.x() > location.x() - (resourceType == BWAPI::UnitTypes::Resource_Mineral_Field ? 5 : 7) &&
resourceTilePosition.y() > location.y() - (resourceType == BWAPI::UnitTypes::Resource_Mineral_Field ? 4 : 5) &&
resourceTilePosition.x() < location.x() + 7 &&
resourceTilePosition.y() < location.y() + 6)
{
return false;
}
const Position &resourcePosition = resource->getPosition();
int tx = location.x()*32+64;
int ty = location.y()*32+48;
int uLeft = resourcePosition.x() - resourceType.dimensionLeft();
int uTop = resourcePosition.y() - resourceType.dimensionUp();
int uRight = resourcePosition.x() + resourceType.dimensionRight() + 1;
int uBottom = resourcePosition.y() + resourceType.dimensionDown() + 1;
int targLeft = tx - BWAPI::Broodwar->self()->getRace().getCenter().dimensionLeft();
int targTop = ty - BWAPI::Broodwar->self()->getRace().getCenter().dimensionUp();
int targRight = tx + BWAPI::Broodwar->self()->getRace().getCenter().dimensionRight() + 1;
int targBottom = ty + BWAPI::Broodwar->self()->getRace().getCenter().dimensionDown() + 1;
int xDist = uLeft - targRight;
if(xDist < 0)
{
xDist = targLeft - uRight;
if(xDist < 0)
xDist = 0;
}
int yDist = uTop - targBottom;
if(yDist < 0)
{
yDist = targTop - uBottom;
if(yDist < 0)
yDist = 0;
}
distanceToResources += Position(0,0).getApproxDistance(Position(xDist, yDist));
}
if(distanceToResources < mBestRating)
{
mBestRating = distanceToResources;
*mBestLocation = location;
}
return false;
}

Definition at line 590 of file TerrainAnaysis.cpp.
Referenced by operator()().
unsigned int PossibleLocationCompare::mBestRating [private] |
Definition at line 589 of file TerrainAnaysis.cpp.
Referenced by operator()().
UnitGroup* PossibleLocationCompare::mResources [private] |
Definition at line 591 of file TerrainAnaysis.cpp.
Referenced by operator()().
1.7.6.1