本文整理汇总了C++中bwapi::TilePosition::x方法的典型用法代码示例。如果您正苦于以下问题:C++ TilePosition::x方法的具体用法?C++ TilePosition::x怎么用?C++ TilePosition::x使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bwapi::TilePosition
的用法示例。
在下文中一共展示了TilePosition::x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void BaseManager::update()
{
for(std::set<Base*>::iterator b = this->allBases.begin(); b != this->allBases.end(); b++)
{
if (!(*b)->isActive())
{
if ((*b)->getResourceDepot() == NULL)
{
BWAPI::TilePosition tile = (*b)->getBaseLocation()->getTilePosition();
std::set<BWAPI::Unit*> units = BWAPI::Broodwar->unitsOnTile(tile.x(),tile.y());
for(std::set<BWAPI::Unit*>::iterator u = units.begin(); u != units.end(); u++)
if ((*u)->getPlayer() == BWAPI::Broodwar->self() && (*u)->getType().isResourceDepot())
{
(*b)->setResourceDepot(*u);
break;
}
}
if ((*b)->getResourceDepot()!=NULL)
if ((*b)->getResourceDepot()->isCompleted() || (*b)->getResourceDepot()->getRemainingBuildTime() < 250)
(*b)->setActive(true);
}
}
//check to see if any new base locations need to be added
for(std::set<BWTA::BaseLocation*>::const_iterator bl = BWTA::getBaseLocations().begin(); bl != BWTA::getBaseLocations().end(); bl++)
if (location2base.find(*bl) == location2base.end())
{
BWAPI::TilePosition tile = (*bl)->getTilePosition();
std::set<BWAPI::Unit*> units = BWAPI::Broodwar->unitsOnTile(tile.x(), tile.y());
for(std::set<BWAPI::Unit*>::iterator u = units.begin(); u != units.end(); u++)
if ((*u)->getPlayer() == BWAPI::Broodwar->self() && (*u)->getType().isResourceDepot())
addBase(*bl);
}
}
示例2: operator
bool operator () (const BWAPI::TilePosition& position, const TileInformation& info) const
{
(void) info;
int minX = position.x() + lx;
if (minX < 0)
return false;
int maxX = position.x() + rx;
if (maxX >= mapWidth)
return false;
int minY = position.y() + ly;
if (minY < 0)
return false;
int maxY = position.y() + ry;
if (maxY >= mapHeight)
return false;
for(int x=minX; x<maxX; ++x)
for(int y=minY; y<maxY; ++y)
{
BWAPI::TilePosition pos(x, y);
TileInformation& subinfo = tileInformations[pos];
if (!tc(pos, subinfo))
return false;
}
return true;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: getRegionBoundingTilePositions
/* for a given BWTA region, finds corner tile positions for max width and height */
void EnhancedUI::getRegionBoundingTilePositions(const BWTA::Region * region, BWAPI::TilePosition & topLeftTP,
BWAPI::TilePosition & topRightTP, BWAPI::TilePosition & bottomRightTP,
BWAPI::TilePosition & bottomLeftTP)
{
BWTA::Polygon poly;
BWAPI::Position pLeft, pRight, pTop, pBottom;
/* tile sizes */
int tsLeft, tsTop, tsRight, tsBottom;
poly = region->getPolygon();
pLeft = pRight = pTop = pBottom = (Position) poly[0];
/* get bounds for BWTA region, map top left is (0,0) */
for(int j = 1; j < (int)poly.size(); j++)
{
if(poly[j].x() < pLeft.x()){
pLeft = poly[j];
}
if(poly[j].x() > pRight.x()){
pRight = poly[j];
}
if(poly[j].y() < pTop.y()){
pTop = poly[j];
}
if(poly[j].y() > pBottom.y()){
pBottom = poly[j];
}
}
/* align to tile sizes */
tsLeft = this->getMaxTileSize(pLeft.x());
tsTop = this->getMaxTileSize(pTop.y());
tsRight = this->getMinTileSize(pRight.x());
tsBottom = this->getMinTileSize(pBottom.y());
/* set tile positions */
topLeftTP.x() = tsLeft;
topLeftTP.y() = tsTop;
topRightTP.x() = tsRight;
topRightTP.y() = tsTop;
bottomRightTP.x() = tsRight;
bottomRightTP.y() = tsBottom;
bottomLeftTP.x() = tsLeft;
bottomLeftTP.y() = tsBottom;
}
示例7: buildPylon
void buildPylon(){
resourceSemaphore = true;
Unidade* nexus = Protoss_Nexus;
Unidade* worker = Protoss_Workers[numWorkers-1];
//nexus->getDistance();
//nexus->getPosition();
BWAPI::TilePosition aroundTile = nexus->getTilePosition();
int minDist = 8;
int stopDist = 40;
//debug("Pylon \n");
while(!worker->isConstructing()) {
for (int i=aroundTile.x(); (i<=aroundTile.x() + minDist) && !worker->isConstructing(); i++) {
for (int j=aroundTile.y(); (j<=aroundTile.y() + minDist) && !worker->isConstructing(); j++) {
//debug("1 Position: " + SSTR(i) + " " + SSTR(j) + "\n");
if (worker->isBuildable(BWAPI::TilePosition(i,j))) {
//debug("2 Position: " + SSTR(i) + " " + SSTR(j) + "\n");
worker->build(BWAPI::TilePosition(i,j),UnitTypes::Protoss_Pylon);
}
}
}
minDist+2;
}
resourceSemaphore = false;
// bool x = u->hasPower(3,4,50,60);
// u->isBuildable(50,50);
// u->isBuildable(BWAPI::TilePosition(3,5));
}
示例8:
BaseLocationImpl::BaseLocationImpl(const BWAPI::TilePosition &tp)
{
tilePosition=tp;
position=BWAPI::Position(tp.x()*32+64,tp.y()*32+48);
island=false;
region=NULL;
}
示例9: hasRefinery
bool BaseManager::hasRefinery(BWTA::BaseLocation* location)
{
bool refinery = false;
//if base has gas
if(!(location->isMineralOnly()))
{
std::set<BWAPI::Unit*> basegeysers = location->getGeysers();
BWAPI::TilePosition geyserlocation;
//cycle through geysers & get tile location
for(std::set<BWAPI::Unit*>::iterator bg = basegeysers.begin(); bg != basegeysers.end(); bg++)
{
geyserlocation = (*bg)->getInitialTilePosition();
}
//check for refinery already on geyser
//get units on geyser
std::set<BWAPI::Unit*> unitsOnGeyser = BWAPI::Broodwar->getUnitsOnTile(geyserlocation.x(),geyserlocation.y());
//cycle through units on geyser
for(std::set<BWAPI::Unit*>::iterator u = unitsOnGeyser.begin(); u != unitsOnGeyser.end(); u++)
{
//if unit is a refinery
if ((*u)->getType().isRefinery())
{
refinery = true;
}
}
}
return refinery;
}
示例10: updateDepositCenterPosition
void BaseManager::updateDepositCenterPosition()
{
std::set<Base*> allBases = this->getAllBases();
if (allBases.size() <=1)
{
return;
}
for(std::set<Base*>::iterator b = allBases.begin(); b != allBases.end(); b++)
{
BWAPI::TilePosition tile = (*b)->getBaseLocation()->getTilePosition();
std::set<BWAPI::Unit*> units = BWAPI::Broodwar->getUnitsOnTile(tile.x(),tile.y());
if (units.size() == 0)
{
UnitGroup commandCenters = SelectAll(BWAPI::UnitTypes::Terran_Command_Center).inRadius(400, (*b)->getBaseLocation()->getPosition());
if (commandCenters.size() > 0)
{
(*(commandCenters.begin()))->lift();
if ((*(commandCenters.begin()))->isLifted())
{
(*(commandCenters.begin()))->land(tile);
}
}
}
}
}
示例11: getBuildLocationNear
BWAPI::TilePosition BuildingPlacer::getBuildLocationNear(BWAPI::TilePosition position, BWAPI::UnitType type, int buildDist) const
{
//returns a valid build location near the specified tile position.
//searches outward in a spiral.
int x = position.x();
int y = position.y();
int length = 1;
int j = 0;
bool first = true;
int dx = 0;
int dy = 1;
while (length < BWAPI::Broodwar->mapWidth()) //We'll ride the spiral to the end
{
//if we can build here, return this tile position
if (x >= 0 && x < BWAPI::Broodwar->mapWidth() && y >= 0 && y < BWAPI::Broodwar->mapHeight())
if (this->canBuildHereWithSpace(BWAPI::TilePosition(x, y), type, buildDist))
return BWAPI::TilePosition(x, y);
//otherwise, move to another position
x = x + dx;
y = y + dy;
//count how many steps we take in this direction
j++;
if (j == length) //if we've reached the end, its time to turn
{
//reset step counter
j = 0;
//Spiral out. Keep going.
if (!first)
length++; //increment step counter if needed
//first=true for every other turn so we spiral out at the right rate
first =! first;
//turn counter clockwise 90 degrees:
if (dx == 0)
{
dx = dy;
dy = 0;
}
else
{
dy = -dx;
dx = 0;
}
}
//Spiral out. Keep going.
}
return BWAPI::TilePositions::None;
}
示例12: getGroundDistanceMap
void getGroundDistanceMap(BWAPI::TilePosition start, RectangleArray<double>& distanceMap)
{
distanceMap.resize(BWAPI::Broodwar->mapWidth(),BWAPI::Broodwar->mapHeight());
Heap< BWAPI::TilePosition , int > heap(true);
for(unsigned int x=0;x<distanceMap.getWidth();x++) {
for(unsigned int y=0;y<distanceMap.getHeight();y++) {
distanceMap[x][y]=-1;
}
}
heap.push(std::make_pair(start,0));
int sx=(int)start.x();
int sy=(int)start.y();
distanceMap[sx][sy]=0;
while (!heap.empty()) {
BWAPI::TilePosition pos=heap.top().first;
int distance=heap.top().second;
heap.pop();
int x=(int)pos.x();
int y=(int)pos.y();
int min_x=max(x-1,0);
int max_x=min(x+1,distanceMap.getWidth()-1);
int min_y=max(y-1,0);
int max_y=min(y+1,distanceMap.getHeight()-1);
for(int ix=min_x;ix<=max_x;ix++) {
for(int iy=min_y;iy<=max_y;iy++) {
int f=abs(ix-x)*32+abs(iy-y)*32;
if (f>32) {f=45;}
int v=distance+f;
if (distanceMap[ix][iy]>v) {
heap.set(BWAPI::TilePosition(x,y),v);
distanceMap[ix][iy]=v;
} else {
if (distanceMap[ix][iy]==-1 && MapData::lowResWalkability[ix][iy]==true) {
distanceMap[ix][iy]=v;
heap.push(std::make_pair(BWAPI::TilePosition(ix,iy),v));
}
}
}
}
}
}
示例13: getBuildLocationNear
BWAPI::TilePosition BuildingPlacer::getBuildLocationNear(BWAPI::TilePosition position, BWAPI::UnitType type) const
{
int x = position.x();
int y = position.y();
int length = 1;
int j = 0;
bool first = true;
int dx = 0;
int dy = 1;
while (length < BWAPI::Broodwar->mapWidth())
{
if (x >= 0 && x < BWAPI::Broodwar->mapWidth() && y >= 0 && y < BWAPI::Broodwar->mapHeight())
if (this->canBuildHereWithSpace(BWAPI::TilePosition(x, y), type))
return BWAPI::TilePosition(x, y);
x = x + dx;
y = y + dy;
j++;
if (j == length)
{
j = 0;
if (!first)
length++;
first =! first;
if (dx == 0)
{
dx = dy;
dy = 0;
}
else
{
dy = -dx;
dx = 0;
}
}
}
return BWAPI::TilePositions::None;
}
示例14: canBuildHereWithSpace
bool BuildingPlacer::canBuildHereWithSpace(BWAPI::TilePosition position, BWAPI::UnitType type, int buildDist) const
{
//returns true if we can build this type of unit here with the specified amount of space.
//space value is stored in this->buildDistance.
//if we can't build here, we of course can't build here with space
if (!this->canBuildHere(position, type))
return false;
int width=type.tileWidth();
int height=type.tileHeight();
//make sure we leave space for add-ons. These types of units can have addons:
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() - buildDist;
if (startx<0) return false;
int starty = position.y() - buildDist;
if (starty<0) return false;
int endx = position.x() + width + buildDist;
if (endx>BWAPI::Broodwar->mapWidth()) return false;
int endy = position.y() + height + buildDist;
if (endy>BWAPI::Broodwar->mapHeight()) return false;
if (!type.isRefinery())
{
for(int x = startx; x < endx; x++)
for(int y = starty; y < endy; y++)
if (!buildable(x, y) || reserveMap[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->getUnitsOnTile(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;
}
示例15: freeTiles
void BuildingPlacer::freeTiles(BWAPI::TilePosition position, int width, int height)
{
for(int x = position.x(); x < position.x() + width && x < (int)reserveMap.getWidth(); x++)
for(int y = position.y(); y < position.y() + height && y < (int)reserveMap.getHeight(); y++)
reserveMap[x][y] = false;
}