本文整理汇总了C++中TilePosition::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ TilePosition::isValid方法的具体用法?C++ TilePosition::isValid怎么用?C++ TilePosition::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TilePosition
的用法示例。
在下文中一共展示了TilePosition::isValid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateCenter
void PlayerSquad::updateCenter() {
TilePosition center(0,0);
for (size_t i = 0; i < mUnits.size(); ++i) {
TilePosition unitPos = mUnits[i]->getTilePosition();
if (unitPos.isValid()) {
center += unitPos;
}
}
if (mUnits.size() > 0) {
center.x() /= mUnits.size();
center.y() /= mUnits.size();
}
mCenter.push_front(center);
// Delete the oldest (if full)
if (config::classification::squad::MEASURE_SIZE < mCenter.size()) {
mCenter.pop_back();
}
}
示例2: getCenter
TilePosition Squad::getCenter()
{
if (agents.size() == 1)
{
return agents.at(0)->getUnit()->getTilePosition();
}
int cX = 0;
int cY = 0;
int cnt = 0;
//Calculate sum (x,y)
for (int i = 0; i < (int)agents.size(); i++)
{
if (agents.at(i)->isAlive())
{
TilePosition unitPos = agents.at(i)->getUnit()->getTilePosition();
if (!unitPos.isValid())
{
Broodwar->printf("Encountered invalid position, skipping");
continue;
}
cX += unitPos.x();
cY += unitPos.y();
cnt++;
}
}
//Calculate average (x,y)
if(cnt > 0)
{
cX = cX / cnt;
cY = cY / cnt;
}
//To make sure the center is in a walkable tile, we need to
//find the unit closest to center
TilePosition c = TilePosition(cX, cY);
TilePosition bestSpot = c;
double bestDist = 10000;
for (int i = 0; i < (int)agents.size(); i++)
{
if (agents.at(i)->isAlive())
{
TilePosition unitPos = agents.at(i)->getUnit()->getTilePosition();
if (!unitPos.isValid())
continue;
if ( (isAir() && agents.at(i)->getUnitType().isFlyer()) || (isGround() && !agents.at(i)->getUnitType().isFlyer()))
{
double dist = unitPos.getDistance(c);
if (dist < bestDist)
{
bestDist = dist;
bestSpot = unitPos;
}
}
}
}
if (!bestSpot.isValid())
{
Broodwar->printf("Invalid positions has distrupted the time-space continuum, expect the universe to implode.");
}
return bestSpot;
}
示例3: addPoint
void addPoint(std::set<TilePosition>& points, const TilePosition& location) {
if (location.isValid()) {
points.insert(location);
}
}