mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Remove unused CYapfDestinationTileT (#13086)
parent
57ac1cbe0c
commit
71ea58c6de
|
@ -115,71 +115,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/** YAPF destination provider base class - used when destination is single tile / multiple trackdirs */
|
||||
template <class Types>
|
||||
class CYapfDestinationTileT
|
||||
{
|
||||
public:
|
||||
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||
typedef typename Types::NodeList::Item Node; ///< this will be our node type
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
protected:
|
||||
TileIndex dest_tile; ///< destination tile
|
||||
TrackdirBits dest_trackdirs; ///< destination trackdir mask
|
||||
|
||||
public:
|
||||
/** set the destination tile / more trackdirs */
|
||||
void SetDestination(TileIndex tile, TrackdirBits trackdirs)
|
||||
{
|
||||
this->dest_tile = tile;
|
||||
this->dest_trackdirs = trackdirs;
|
||||
}
|
||||
|
||||
protected:
|
||||
/** to access inherited path finder */
|
||||
Tpf &Yapf()
|
||||
{
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return (n.key.tile == this->dest_tile) && HasTrackdir(this->dest_trackdirs, n.GetTrackdir());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by YAPF to calculate cost estimate. Calculates distance to the destination
|
||||
* adds it to the actual cost from origin and stores the sum to the Node::estimate
|
||||
*/
|
||||
inline bool PfCalcEstimate(Node &n)
|
||||
{
|
||||
static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
|
||||
if (this->PfDetectDestination(n)) {
|
||||
n.estimate = n.cost;
|
||||
return true;
|
||||
}
|
||||
|
||||
TileIndex tile = n.GetTile();
|
||||
DiagDirection exitdir = TrackdirToExitdir(n.GetTrackdir());
|
||||
int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
|
||||
int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
|
||||
int x2 = 2 * TileX(this->dest_tile);
|
||||
int y2 = 2 * TileY(this->dest_tile);
|
||||
int dx = abs(x1 - x2);
|
||||
int dy = abs(y1 - y2);
|
||||
int dmin = std::min(dx, dy);
|
||||
int dxy = abs(dx - dy);
|
||||
int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
|
||||
n.estimate = n.cost + d;
|
||||
assert(n.estimate >= n.parent->estimate);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* YAPF template that uses Ttypes template argument to determine all YAPF
|
||||
* components (base classes) from which the actual YAPF is composed.
|
||||
|
|
Loading…
Reference in New Issue