@@ -21,48 +21,48 @@ static AyStar _npf_aystar;
static const uint _trackdir_length[TRACKDIR_END] = {
NPF_TILE_LENGTH, NPF_TILE_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH,
0, 0,
NPF_TILE_LENGTH, NPF_TILE_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH
};
/**
* Calculates the minimum distance traveled to get from t0 to t1 when only
* using tracks (ie, only making 45 degree turns). Returns the distance in the
* NPF scale, ie the number of full tiles multiplied by NPF_TILE_LENGTH to
* prevent rounding.
*/
uint NPFDistanceTrack(TileIndex t0, TileIndex t1)
static uint NPFDistanceTrack(TileIndex t0, TileIndex t1)
{
const uint dx = abs(TileX(t0) - TileX(t1));
const uint dy = abs(TileY(t0) - TileY(t1));
const uint straightTracks = 2 * min(dx, dy); /* The number of straight (not full length) tracks */
/* OPTIMISATION:
* Original: diagTracks = max(dx, dy) - min(dx,dy);
* Proof:
* (dx+dy) - straightTracks == (min + max) - straightTracks = min + max - 2 * min = max - min */
const uint diagTracks = dx + dy - straightTracks; /* The number of diagonal (full tile length) tracks. */
/* Don't factor out NPF_TILE_LENGTH below, this will round values and lose
* precision */
return diagTracks * NPF_TILE_LENGTH + straightTracks * NPF_TILE_LENGTH * STRAIGHT_TRACK_LENGTH;
}
* Check if a rail track is the end of the line. Will also consider 1-way signals to be the end of a line.
* @param tile The tile on which the current track is.
* @param trackdir The (track)direction in which you want to look.
* @param enginetype The type of the engine for which we are checking this.
bool IsEndOfLine(TileIndex tile, Trackdir trackdir, RailType enginetype)
static bool IsEndOfLine(TileIndex tile, Trackdir trackdir, RailType enginetype)
byte exitdir = TrackdirToExitdir(trackdir);
TileIndex dst_tile;
uint32 ts;
/* Can always go into a tunnel */
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0)==0 && (_m[tile].m5 & 3) == exitdir)
return false;
/* Cannot go through the back of a depot */
if (IsTileDepotType(tile, TRANSPORT_RAIL) && (exitdir != GetDepotDirection(tile, TRANSPORT_RAIL)))
return true;
@@ -152,25 +152,25 @@ static TileIndex CalcClosestStationTile(
// but if we are between those coordinates, we will aim for our own x coordinate
x = clamp(TileX(tile), minx, maxx);
// same for y coordinate, see above comment
y = clamp(TileY(tile), miny, maxy);
// return the tile of our target coordinates
return TileXY(x, y);
/* On PBS pathfinding runs, this is called before pathfinding ends (BeforeExit aystar callback), and will
* reserve the appropriate tracks, if needed. */
void NPFReservePBSPath(AyStar *as)
static void NPFReservePBSPath(AyStar *as)
NPFFoundTargetData* ftd = (NPFFoundTargetData*)as->user_path;
bool eol_end = false;
if (ftd->best_trackdir == 0xFF)
return;
if (!NPFGetFlag(&ftd->node, NPF_FLAG_PBS_EXIT) && IsEndOfLine(ftd->node.tile, ftd->node.direction, as->user_data[NPF_RAILTYPE]) && !NPFGetFlag(&ftd->node, NPF_FLAG_SEEN_SIGNAL)) {
/* The path ends in an end of line, we'll need to reserve a path.
* We treat and end of line as a red exit signal */
eol_end = true;
NPFSetFlag(&ftd->node, NPF_FLAG_PBS_EXIT, true);
Status change: