本文整理汇总了C++中bwapi::Position类的典型用法代码示例。如果您正苦于以下问题:C++ Position类的具体用法?C++ Position怎么用?C++ Position使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Position类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildGateway
void buildGateway(){
resourceSemaphore = true;
Unidade* worker = Protoss_Workers[numWorkers-1];
Selected_Worker = worker;
Unidade* Selected_Pylon = Protoss_Pylons[numPylons-1];
Unidade* nexus = Protoss_Nexus;
int delta_y;
int delta_x;
int desviox=0;
int desvioy=0;
delta_y = nexus->getPosition().y() - Selected_Pylon->getPosition().y();
delta_x = nexus->getPosition().x() - Selected_Pylon->getPosition().x();
BWAPI::Position setPos = BWAPI::Position(Selected_Pylon->getPosition().x()-delta_x*3/2,Selected_Pylon->getPosition().y()-delta_y*3/2);
worker->build(BWAPI::TilePosition(setPos),UnitTypes::Protoss_Gateway);
while(!worker->isConstructing())
{
desviox += 5*(rand()%3-1);
desvioy += 5*(rand()%3-1);
setPos = BWAPI::Position(Selected_Pylon->getPosition().x()-delta_x*3/2+desviox,Selected_Pylon->getPosition().y()-delta_y*3/2+desvioy);
worker->build(BWAPI::TilePosition(setPos),UnitTypes::Protoss_Gateway);
}
printf("X:%d Y:%d \n",setPos.x(),setPos.y());
Selected_Worker = NULL;
resourceSemaphore = false;
}
示例2: getMoveTo
// given a position, get the position we should move to to minimize distance
BWAPI::Position getMoveTo(const BWAPI::Position p, const int lookAhead = 1) const
{
// the initial row an column
int row = p.y() / 32;
int col = p.x() / 32;
// for each lookahead
for (int i=0; i<lookAhead; ++i)
{
// get the index
int index = getIndex(row,col);
// adjust the row and column accordingly
if (moveTo[index] == 'L')
{
col -= 1;
}
else if (moveTo[index] == 'R')
{
col += 1;
}
else if (moveTo[index] == 'U')
{
row -= 1;
}
else
{
row += 1;
}
}
// return the position
return BWAPI::Position(col * 32 + 16, row * 32 + 16);
}
示例3: onNukeDetect
void StarCraftAIModule::onNukeDetect(BWAPI::Position target)
{
if (target!=Positions::Unknown)
Broodwar->printf("Nuclear Launch Detected at (%d,%d)",target.x(),target.y());
else
Broodwar->printf("Nuclear Launch Detected");
}
示例4: onNukeDetect
void BattleBroodAI::onNukeDetect(BWAPI::Position target)
{
micro->onNukeDetect(target);
if (target!=Positions::Unknown)
Broodwar->printf("Nuclear Launch Detected at (%d,%d)",target.x(),target.y());
else
Broodwar->printf("Nuclear Launch Detected");
}
示例5: operator
bool operator()(const BWAPI::Position lhs, const BWAPI::Position rhs)
{
if (lhs.getDistance(InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition()) <
rhs.getDistance(InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition())) return true;
//ensure each position gets added to the set
if (lhs.getDistance(InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition()) >
rhs.getDistance(InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition())) return false;
return true;
}
示例6: move
void UnitMng::move()
{
BWAPI::Position* currentPosition= new BWAPI::Position((this->conUnit)->getPosition());
BWAPI::Position *movePosition;
int updown=128*(outputs[3]-0.5);
int leftright=128*(outputs[4]-0.5);
movePosition= new BWAPI::Position((currentPosition->x() + updown),(currentPosition->y()+leftright));
movePosition->makeValid();
this->conUnit->move(*movePosition);
}
示例7: calculate_walk_distances_area
void calculate_walk_distances_area(const BWAPI::Position& start
, int width
, int height
, int max_distance
, RectangleArray<int>& distance_map)
{
Heap<BWAPI::Position, int> heap(true);
for (unsigned int x = 0;x < distance_map.getWidth();x++) {
for (unsigned int y = 0;y < distance_map.getHeight();y++) {
distance_map[x][y] = -1;
}
}
int sx = (int)start.x();
int sy = (int)start.y();
for (int x = sx;x < sx + width;x++) {
for (int y = sy;y < sy + height;y++) {
heap.push(std::make_pair(BWAPI::Position(x, y), 0));
distance_map[x][y] = 0;
}
}
while (!heap.empty()) {
BWAPI::Position pos = heap.top().first;
int distance = heap.top().second;
heap.pop();
int x = (int)pos.x();
int y = (int)pos.y();
if (distance > max_distance && max_distance > 0)
break;
int min_x = max(x - 1, 0);
int max_x = min(x + 1, BWAPI::Broodwar->mapWidth() * 4 - 1);
int min_y = max(y - 1, 0);
int max_y = min(y + 1, BWAPI::Broodwar->mapHeight() * 4 - 1);
for (int ix = min_x;ix <= max_x;ix++) {
for (int iy = min_y;iy <= max_y;iy++) {
int f = abs(ix - x) * 10 + abs(iy - y) * 10;
if (f > 10) {
f = 14;
}
int v = distance + f;
if (distance_map[ix][iy] > v) {
heap.set(BWAPI::Position(x, y), v);
distance_map[ix][iy] = v;
} else {
if (distance_map[ix][iy] == -1 && MapData::rawWalkability[ix][iy] == true) {
distance_map[ix][iy] = v;
heap.push(std::make_pair(BWAPI::Position(ix, iy), v));
}
}
}
}
}
}
示例8: calculate_walk_distances
void calculate_walk_distances(const RectangleArray<bool>& read_map
, const BWAPI::Position& start
, int max_distance
, RectangleArray<int>& distance_map)
{
Heap<BWAPI::Position, int> heap(true);
for (unsigned int x = 0;x < distance_map.getWidth();x++) {
for (unsigned int y = 0;y < distance_map.getHeight();y++) {
distance_map[x][y] = -1;
}
}
heap.push(std::make_pair(start, 0));
int sx = (int)start.x();
int sy = (int)start.y();
distance_map[sx][sy] = 0;
while (!heap.empty()) {
BWAPI::Position pos = heap.top().first;
int distance = heap.top().second;
heap.pop();
int x = (int)pos.x();
int y = (int)pos.y();
if (distance > max_distance && max_distance > 0)
break;
int min_x = max(x - 1, 0);
int max_x = min(x + 1, read_map.getWidth() - 1);
int min_y = max(y - 1, 0);
int max_y = min(y + 1, read_map.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) * 10 + abs(iy - y) * 10;
if (f > 10) {
f = 14;
}
int v = distance + f;
if (distance_map[ix][iy] > v) {
heap.set(BWAPI::Position(x, y), v);
distance_map[ix][iy] = v;
} else {
if (distance_map[ix][iy] == -1 && read_map[ix][iy] == true) {
distance_map[ix][iy] = v;
heap.push(std::make_pair(BWAPI::Position(ix, iy), v));
}
}
}
}
}
}
示例9: printGraphicDebugInfo
void PlayerSquad::printGraphicDebugInfo() const {
// Skip if not turned on
if (config::debug::GRAPHICS_VERBOSITY == config::debug::GraphicsVerbosity_Off || !isDebugOn())
{
return;
}
// Low
// Print id, state, number of units and number of supplies.
if (config::debug::GRAPHICS_VERBOSITY >= config::debug::GraphicsVerbosity_Low) {
if (!mCenter.empty()) {
BWAPI::Position squadCenterOnMap = BWAPI::Position(mCenter.front());
BWAPI::Broodwar->drawTextMap(squadCenterOnMap.x(), squadCenterOnMap.y(), "%s", getDebugString().c_str());
}
}
// Medium
// Draw line from the front and back center, display the length of this line
if (config::debug::GRAPHICS_VERBOSITY >= config::debug::GraphicsVerbosity_Medium) {
if (!mCenter.empty()) {
pair<Position, Position> squadMovement = make_pair(mCenter.front(), mCenter.back());
// Length
double length = (mCenter.front() - mCenter.back()).getLength();
// Draw line
Broodwar->drawLineMap(
squadMovement.first.x(), squadMovement.first.y(),
squadMovement.second.x(), squadMovement.second.y(),
Colors::Purple
);
int xOffset = -64;
// Draw text in back of line
Broodwar->drawTextMap(
squadMovement.second.x() + xOffset, squadMovement.second.y(),
"%sLength: %g",
TextColors::PURPLE.c_str(),
length
);
}
}
}
示例10: moveFormation
void Fireteam::moveFormation(BWAPI::Position pos) {
mission.objectivePosition = pos;
for(std::set<BWAPI::Unit*>::const_iterator i=units.begin(); i != units.end(); i++)
{
(*i)->move(BWAPI::Position::Position(pos.x() + (int)formation.positionMap[(*i)].xOffset, pos.y() + (int)formation.positionMap[(*i)].yOffset), 0);
}
}
示例11: camera
void AIModule::camera()
{
if (game->getMouseState(BWAPI::M_LEFT))
{
return;
}
const int CENTER_SCREEN_X = 320;
const int CENTER_SCREEN_Y = 140;
if (!autocam)
{
return;
}
UnitGroup interestingUnits = AllUnits()(isAttacking);
if (interestingUnits.size() == 0)
{
return;
}
BWAPI::Unit *unit = (*interestingUnits.begin());
BWAPI::Position unitPosition = unit->getPosition();
int x, y;
x = unitPosition.x() - CENTER_SCREEN_X;
y = unitPosition.y() - CENTER_SCREEN_Y;
if (x < 0)
{
x = 0;
}
if (y < 0)
{
y = 0;
}
BWAPI::Broodwar->setScreenPosition(x, y);
}
示例12: getSectorCornerPosition
BWAPI::Position getSectorCornerPosition (char s, int c){
int width = centro.x()*2;
int height = centro.y()*2;
double C1 = width / 3;
double C2 = (2*width) / 3;
double L1 = height / 3;
double L2 = (2*height) / 3;
double halfSectorWidth = (C1 / 2);
double halfSectorHeight = (L1 / 2);
BWAPI::Position sectorCenter = getSectorCenter(s);
if(c == 0) return BWAPI::Position((int) (sectorCenter.x() - halfSectorWidth), (int) (sectorCenter.y() - halfSectorHeight));
if(c == 1) return BWAPI::Position((int) (sectorCenter.x() + halfSectorWidth), (int) (sectorCenter.y() - halfSectorHeight));
if(c == 2) return BWAPI::Position((int) (sectorCenter.x() - halfSectorWidth), (int) (sectorCenter.y() + halfSectorHeight));
if(c == 3) return BWAPI::Position((int) (sectorCenter.x() + halfSectorWidth), (int) (sectorCenter.y() + halfSectorHeight));
}
示例13: RushDefend
void ProductionManager::RushDefend(BWAPI::UnitType defendBuilding, int buildingCount, BWAPI::UnitType defendUnit, int unitCount)
{
BWAPI::Position chokePosition = BWTA::getNearestChokepoint(BWAPI::Broodwar->self()->getStartLocation())->getCenter();
BWAPI::Position basePositon = BWAPI::Position(BWAPI::Broodwar->self()->getStartLocation());
double2 direc = chokePosition - basePositon;
double2 direcNormal = direc / direc.len();
int targetx = (basePositon.x() + int(direcNormal.x * 32 * 10)) / 32;
int targety = (basePositon.y() + int(direcNormal.y * 32 * 10)) / 32;
for (int i = 0; i < unitCount; i++)
{
queue.queueAsHighestPriority(defendUnit, false);
}
for (int i = 0; i < buildingCount; i++)
{
queue.queueAsHighestPriority(MetaType(BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TilePosition(targetx, targety)), true);
queue.queueAsHighestPriority(defendBuilding, false);
}
}
示例14: onSendText
void AIModule::onSendText(std::string text)
{
game->printf(text.c_str());
if (text == "dbg")
{
debug = !debug;
buildOrderManager->setDebugMode(debug);
game->printf("Debug turned %s.", (debug) ? "on" : "off");
}
if (text == "atc")
{
autocam = !autocam;
game->printf("Autocam turned %s.", (autocam) ? "on" : "off");
}
if (text == "gsn")
{
localSpeed = 30;
frameSkip = 0;
updateGameSpeed();
}
if (text == "gsf")
{
localSpeed = 0;
frameSkip = 0;
updateGameSpeed();
}
if (text == "gsfs")
{
localSpeed = 0;
frameSkip = 8;
updateGameSpeed();
}
if (text == "atk")
{
BWAPI::Position mousePosition = game->getMousePosition();
BWAPI::Position screenPosition = game->getScreenPosition();
BWAPI::Position mapPosition = BWAPI::Position(mousePosition.x() + screenPosition.x(), mousePosition.y() + screenPosition.y());
agentManager->attackMoveTo(mapPosition);
game->printf("Issued manual attack at %d %d.", mapPosition.x(), mapPosition.y());
}
}
示例15: onNukeDetect
void ExampleAIModule::onNukeDetect(BWAPI::Position target)
{
// Check if the target is a valid position
if ( target )
{
// if so, print the location of the nuclear strike target
Broodwar->printf("Nuclear Launch Detected at (%d,%d)", target.x(), target.y() );
}
else
{
// Otherwise, ask other players where the nuke is!
Broodwar->sendText("Where's the nuke?");
}
// You can also retrieve all the nuclear missile targets using Broodwar->getNukeDots()!
}