本文整理汇总了C++中PathNode::tileX方法的典型用法代码示例。如果您正苦于以下问题:C++ PathNode::tileX方法的具体用法?C++ PathNode::tileX怎么用?C++ PathNode::tileX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathNode
的用法示例。
在下文中一共展示了PathNode::tileX方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setDestinationV
void VehicleInstance::setDestinationV(Mission *m, int x, int y, int z, int ox,
int oy, int new_speed)
{
std::set < PathNode > open, closed;
std::map < PathNode, PathNode > parent;
m->adjXYZ(x, y, z);
z = tile_z_;
dest_path_.clear();
setSpeed(0);
if (map_ == -1 || health_ <= 0 || !(walkable(x, y, z)))
return;
if (!walkable(tile_x_, tile_y_, tile_z_)) {
float dBest = 100000, dCur;
int xBest,yBest;
// we got somewhere we shouldn't, we need to find somewhere that is walkable
for (int j = 0; j < 5; j++)
for (int i = 0; i < 5; i++)
if (walkable(tile_x_ + i, tile_y_ + j, tile_z_)) {
dCur = sqrt((float)(i*i + j*j));
if(dCur < dBest) {
xBest = tile_x_ + i;
yBest = tile_y_ + j;
dBest = dCur;
}
}
for (int j = 0; j < 5; j++)
for (int i = 0; i > -5; --i)
if (walkable(tile_x_ + i, tile_y_ + j, tile_z_)) {
dCur = sqrt((float)(i*i + j*j));
if(dCur < dBest) {
xBest = tile_x_ + i;
yBest = tile_y_ + j;
dBest = dCur;
}
}
for (int j = 0; j > -5; --j)
for (int i = 0; i > -5; --i)
if (walkable(tile_x_ + i, tile_y_ + j, tile_z_)) {
dCur = sqrt((float)(i*i + j*j));
if(dCur < dBest) {
xBest = tile_x_ + i;
yBest = tile_y_ + j;
}
}
for (int j = 0; j > -5; --j)
for (int i = 0; i < 5; i++)
if (walkable(tile_x_ + i, tile_y_ + j, tile_z_)) {
dCur = sqrt((float)(i*i + j*j));
if(dCur < dBest) {
xBest = tile_x_ + i;
yBest = tile_y_ + j;
dBest = dCur;
}
}
if(dBest == 100000)
return;
else {
tile_x_ = xBest;
tile_y_ = yBest;
}
}
PathNode closest;
float closest_dist = 100000;
open.insert(PathNode(tile_x_, tile_y_, tile_z_, off_x_, off_y_));
int watchDog = 1000;
while (!open.empty()) {
watchDog--;
float dist = 100000;
PathNode p;
std::set < PathNode >::iterator pit;
for (std::set < PathNode >::iterator it = open.begin();
it != open.end(); it++) {
float d =
sqrt((float) (x - it->tileX()) * (x - it->tileX()) +
(y - it->tileY()) * (y - it->tileY()));
if (d < dist) {
dist = d;
p = *it;
pit = it; // it cannot be const_iterator because of this assign
}
}
if (dist < closest_dist) {
closest = p;
closest_dist = dist;
}
//printf("found best dist %f in %i nodes\n", dist, open.size());
open.erase(pit);
closed.insert(p);
if ((p.tileX() == x && p.tileY() == y && p.tileZ() == z)
|| watchDog < 0) {
if (watchDog < 0) {
p = closest;
dest_path_.
//.........这里部分代码省略.........