本文整理汇总了C++中TilePosition::x方法的典型用法代码示例。如果您正苦于以下问题:C++ TilePosition::x方法的具体用法?C++ TilePosition::x怎么用?C++ TilePosition::x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TilePosition
的用法示例。
在下文中一共展示了TilePosition::x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNextScanLocation
TilePosition StructureAgent::getNextScanLocation()
{
TilePosition ePos = ExplorationManager::getInstance()->getClosestSpottedBuilding(Broodwar->self()->getStartLocation());
if (ePos.x() > -1)
{
//Already found enemy base
return TilePosition(-1, -1);
}
for(set<BaseLocation*>::const_iterator i=getStartLocations().begin();i!=getStartLocations().end();i++)
{
TilePosition basePos = (*i)->getTilePosition();
bool needScan = true;
//1. Check previous scans
for (int i = 0; i < (int)hasScanned.size(); i++)
{
if (hasScanned.at(i).x() == basePos.x() && hasScanned.at(i).y() == basePos.y())
{
needScan = false;
}
}
//2. Check if we have this base
vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
for (int i = 0; i < (int)agents.size(); i++)
{
if (agents.at(i)->isAlive())
{
double dist = basePos.getDistance(agents.at(i)->getUnit()->getTilePosition());
if (dist <= 10)
{
needScan = false;
break;
}
}
}
//3. Check if enemy units are near
for(set<Unit*>::const_iterator j=Broodwar->enemy()->getUnits().begin();j!=Broodwar->enemy()->getUnits().end();j++)
{
if ((*j)->exists())
{
double dist = basePos.getDistance((*j)->getTilePosition());
if (dist <= 10)
{
needScan = false;
break;
}
}
}
if (needScan)
{
return basePos;
}
}
return TilePosition(-1, -1);
}
示例2: unitDestroyed
void ExplorationManager::unitDestroyed(Unit* unit)
{
TilePosition uPos = unit->getTilePosition();
if (unit->getType().isBuilding())
{
bool removed = false;
for (int i = 0; i < (int)spottedBuildings.size(); i++)
{
TilePosition sPos = spottedBuildings.at(i)->getTilePosition();
if (uPos.x() == sPos.x() && uPos.y() == sPos.y())
{
spottedBuildings.at(i)->setInactive();
removed = true;
}
}
if (!removed)
{
//Broodwar->printf("[EM]: Building %s at (%d,%d) was not removed from EM!!!", unit->getType().getName().c_str(), uPos.x(), uPos.y());
}
}
else
{
for (int i = 0; i < (int)spottedUnits.size(); i++)
{
if (spottedUnits.at(i)->getUnitID() == unit->getID())
{
spottedUnits.at(i)->setInactive();
//Broodwar->printf("[EM]: Remove %s at (%d,%d)", unit->getType().getName().c_str(), uPos.x(), uPos.y());
}
}
}
}
示例3: moveToGoal
bool PFManager::moveToGoal(BaseAgent* agent, TilePosition checkpoint, TilePosition goal)
{
if (checkpoint.x() == -1 || goal.x() == -1) return false;
Unit* unit = agent->getUnit();
if (unit->isStartingAttack() || unit->isAttacking())
{
return false;
}
Position toReach = Position(checkpoint);
double distToReach = toReach.getDistance(unit->getPosition());
int engageDist = unit->getType().groundWeapon().maxRange();
if (agent->isOfType(UnitTypes::Terran_Medic))
{
engageDist = 6 * 32;
}
if (engageDist <= 64)
{
engageDist = 64;
}
if (distToReach <= engageDist)
{
if (unit->isMoving()) unit->stop();
return true;
}
//Move
if (!unit->isMoving()) return unit->attack(toReach);
else return true;
}
示例4: isVisible
bool Squad::isVisible(TilePosition pos)
{
if (!ExplorationManager::canReach(Broodwar->self()->getStartLocation(), pos))
{
return true;
}
if (Broodwar->isVisible(pos))
{
return true;
}
if (getCenter().getDistance(pos) <= 3)
{
return true;
}
for (int i = 0; i < (int)hasVisited.size(); i++)
{
TilePosition vPos = hasVisited.at(i);
if (vPos.x() == pos.x() && vPos.y() == pos.y())
{
return true;
}
}
return false;
}
示例5: drawUnitTilePosition
void UnitClass::drawUnitTilePosition()
{
TilePosition tile = getTilePosition();
BWAPI::UnitType type = getType();
Player player = getPlayer();
BWAPI::Broodwar->drawBox(BWAPI::CoordinateType::Map, tile.x()*32, tile.y()*32, (tile.x()+type.tileWidth())*32, (tile.y()+type.tileHeight())*32, player->getColor());
}
示例6: blockPosition
void CoverMap::blockPosition(TilePosition buildSpot)
{
if (buildSpot.x() == -1)
{
//Error check
return;
}
cover_map[buildSpot.x()][buildSpot.y()] = BLOCKED;
}
示例7: canBuildAt
bool CoverMap::canBuildAt(UnitType toBuild, TilePosition pos)
{
int maxW = w - toBuild.tileWidth() - 1;
int maxH = h - toBuild.tileHeight() - 1;
//Out of bounds check
if (pos.x() >= 0 && pos.x() < maxW && pos.y() >= 0 && pos.y() < maxH)
{
if (canBuild(toBuild, pos))
{
return true;
}
}
return false;
}
示例8: isOccupied
bool Commander::isOccupied(BWTA::Region* region)
{
BWTA::Polygon p = region->getPolygon();
vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
for (int i = 0; i < (int)agents.size(); i++)
{
BaseAgent* agent = agents.at(i);
if (agent->isAlive() && agent->getUnitType().isResourceDepot())
{
BWTA::Region* aRegion = getRegion(agents.at(i)->getUnit()->getTilePosition());
Position c1 = region->getCenter();
Position c2 = aRegion->getCenter();
if (c2.x() == c1.x() && c2.y() == c1.y())
{
return true;
}
}
}
//Check expansion site
TilePosition expansionSite = ExplorationManager::getInstance()->getExpansionSite();
TilePosition center = TilePosition(region->getCenter());
if (expansionSite.x() >= 0)
{
double dist = expansionSite.getDistance(center);
if (dist <= 15)
{
return true;
}
}
return false;
}
示例9: 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);
}
}
示例10: removeMember
void Squad::removeMember(BaseAgent* agent)
{
//Step 1. Remove the agent instance
for (int i = 0; i < (int)agents.size(); i++)
{
if (agents.at(i)->getUnitID() == agent->getUnitID())
{
agents.at(i)->setSquadID(-1);
agents.at(i)->assignToDefend();
agents.erase(agents.begin() + i);
break;
}
}
//Step 2. Update the setup list
for (int i = 0; i < (int)setup.size(); i++)
{
if (setup.at(i).equals(agent->getUnitType()))
{
setup.at(i).current--;
}
}
//Step 3. If Explorer, set destination as explored (to avoid being killed at the same
//place over and over again).
if (isExplorer())
{
TilePosition goal = agent->getGoal();
if (goal.x() >= 0)
{
ExplorationManager::Instance().setExplored(goal);
}
}
}
示例11: scanForVulnerableBase
TilePosition ExplorationManager::scanForVulnerableBase()
{
TilePosition spot = TilePosition(-1, -1);
for (int i = 0; i < (int)spottedBuildings.size(); i++)
{
if (spottedBuildings.at(i)->isActive())
{
SpottedObject* obj = spottedBuildings.at(i);
if (obj->getType().isResourceDepot())
{
if (!isDetectorCovering(obj->getTilePosition()))
{
//Broodwar->printf("Found probable vulnerable base at (%d,%d)", obj->getTilePosition().x(), obj->getTilePosition().y());
spot = obj->getTilePosition();
}
}
}
}
if (spot.x() < 0)
{
//Broodwar->printf("Scan: No vulnerable base found");
}
return spot;
}
示例12: findBuildSpot
TilePosition CoverMap::findBuildSpot(UnitType toBuild, TilePosition start)
{
//Check start pos
if (canBuildAt(toBuild, start)) return start;
//Search outwards
bool found = false;
int cDiff = 1;
TilePosition spot = TilePosition(-1, -1);
while (!found)
{
//Top
TilePosition s = TilePosition(start.x() - cDiff, start.y() - cDiff);
TilePosition e = TilePosition(start.x() + cDiff, start.y() - cDiff);
spot = findSpotAtSide(toBuild, s, e);
if (spot.x() != -1 && spot.y() != -1)
{
found = true;
break;
}
//Bottom
s = TilePosition(start.x() - cDiff, start.y() + cDiff);
e = TilePosition(start.x() + cDiff, start.y() + cDiff);
spot = findSpotAtSide(toBuild, s, e);
if (spot.x() != -1 && spot.y() != -1)
{
found = true;
break;
}
//Left
s = TilePosition(start.x() - cDiff, start.y() - cDiff);
e = TilePosition(start.x() - cDiff, start.y() + cDiff);
spot = findSpotAtSide(toBuild, s, e);
if (spot.x() != -1 && spot.y() != -1)
{
found = true;
break;
}
//Right
s = TilePosition(start.x() + cDiff, start.y() - cDiff);
e = TilePosition(start.x() + cDiff, start.y() + cDiff);
spot = findSpotAtSide(toBuild, s, e);
if (spot.x() != -1 && spot.y() != -1)
{
found = true;
break;
}
cDiff++;
if (cDiff > range) found = true;
}
return spot;
}
示例13: findChokePoint
TilePosition Commander::findChokePoint()
{
//First, check the DefenseLocator
//for a stored defense position.
DefenseLocator* df = DefenseLocator::getInstance();
TilePosition storedPos = df->getBaseDefensePos(Broodwar->mapHash());
if (storedPos.x() != -1) return storedPos;
double bestPrio = -1;
Chokepoint* bestChoke = NULL;
for(set<BWTA::Region*>::const_iterator i=getRegions().begin();i!=getRegions().end();i++)
{
if (isOccupied((*i)))
{
for(set<Chokepoint*>::const_iterator c=(*i)->getChokepoints().begin();c!=(*i)->getChokepoints().end();c++)
{
if (isEdgeChokepoint((*c)))
{
double cPrio = getChokepointPrio(TilePosition((*c)->getCenter()));
if (cPrio > bestPrio)
{
bestPrio = cPrio;
bestChoke = (*c);
}
}
}
}
}
TilePosition guardPos = Broodwar->self()->getStartLocation();
if (bestChoke != NULL)
{
guardPos = findDefensePos(bestChoke);
//guardPos = TilePosition(bestChoke->getCenter());
//Pre-calculate path
TilePosition b = ExplorationManager::getInstance()->getClosestSpottedBuilding(guardPos);
if (b.x() >= 0)
{
Pathfinder::getInstance()->requestPath(guardPos, b);
}
}
return guardPos;
}
示例14: setExpansionSite
void ExplorationManager::setExpansionSite(TilePosition pos)
{
if (pos.x() >= 0)
{
siteSetFrame = Broodwar->getFrameCount();
expansionSite = pos;
}
}
示例15: positionFree
bool CoverMap::positionFree(TilePosition pos)
{
if (cover_map[pos.x()][pos.y()] == BUILDABLE)
{
return true;
}
return false;
}