OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #include "../../stdafx.h"
11 #include "../../network/network.h"
12 #include "../../viewport_func.h"
13 #include "../../ship.h"
14 #include "../../roadstop_base.h"
15 #include "../../vehicle_func.h"
16 #include "../pathfinder_func.h"
17 #include "../pathfinder_type.h"
18 #include "../follow_track.hpp"
21 #include "../../safeguards.h"
27 static const uint NPF_HASH_HALFMASK = (1 << NPF_HASH_HALFBITS) - 1;
81 #define NPF_STRAIGHT_LENGTH (uint)(NPF_TILE_LENGTH * STRAIGHT_TRACK_LENGTH)
93 return HasBit(node->user_data[NPF_NODE_FLAGS], flag);
101 SB(node->user_data[NPF_NODE_FLAGS], flag, 1, value);
104 bool CheckIgnoreFirstTile(
const PathNode *node)
120 const uint straightTracks = 2 * std::min(dx, dy);
125 const uint diagTracks = dx + dy - straightTracks;
142 uint part1 =
TileX(key1) & NPF_HASH_HALFMASK;
143 uint part2 =
TileY(key1) & NPF_HASH_HALFMASK;
147 return ((part1 << NPF_HASH_HALFBITS | part2) + (NPF_HASH_SIZE * key2 /
TRACKDIR_END)) % NPF_HASH_SIZE;
180 DEBUG(npf, 4,
"Calculating H for: (%d, %d). Result: %d",
TileX(current->tile),
TileY(current->tile), dist);
182 if (dist < ftd->best_bird_dist) {
183 ftd->best_bird_dist = dist;
195 if (parent->path.
parent ==
nullptr) {
196 Trackdir trackdir = current->direction;
200 DEBUG(npf, 6,
"Saving trackdir: 0x%X", trackdir);
210 static uint NPFTunnelCost(
AyStarNode *current)
226 static inline uint NPFBridgeCost(
AyStarNode *current)
241 int dx4 = (x2 - x1) / 4;
242 int dy4 = (y2 - y1) / 4;
247 int z1 = GetSlopePixelZ(x1 + dx4, y1 + dy4);
248 int z2 = GetSlopePixelZ(x2 - dx4, y2 - dy4);
260 static uint NPFReservedTrackCost(
AyStarNode *current)
307 uint *count = (uint *)data;
318 Trackdir trackdir = current->direction;
320 cost = _trackdir_length[trackdir];
334 cost += count * 3 * _trackdir_length[trackdir];
351 cost =
IsTunnel(tile) ? NPFTunnelCost(current) : NPFBridgeCost(current);
387 cost += NPFSlopeCost(current);
396 DEBUG(npf, 4,
"Calculating G for: (%d, %d). Result: %d",
TileX(current->tile),
TileY(current->tile), cost);
405 Trackdir trackdir = current->direction;
413 cost =
IsTunnel(tile) ? NPFTunnelCost(current) : NPFBridgeCost(current);
417 cost = _trackdir_length[trackdir];
443 while (ft.Follow(t, td)) {
444 assert(t != ft.m_new_tile);
484 if (!IsPbsSignal(sigtype)) {
521 new_node.path.node = *current;
527 cost += NPFSlopeCost(current);
545 cost += NPFReservedTrackCost(current);
548 DEBUG(npf, 4,
"Calculating G for: (%d, %d). Result: %d",
TileX(current->tile),
TileY(current->tile), cost);
623 bool first_run =
true;
624 for (; start != end; start = start->
parent) {
645 ftd->best_path_dist = current->g;
646 ftd->best_bird_dist = 0;
647 ftd->node = current->path.node;
648 ftd->res_okay =
false;
655 ftd->node = target->node;
664 ftd->node.tile = end_tile;
680 ftd->res_okay =
true;
810 switch (user->type) {
813 if (!
HasBit(user->railtypes, rail_type))
return false;
818 RoadType road_type = GetRoadType(tile, (RoadTramType)user->subtype);
819 if (!
HasBit(user->roadtypes, road_type))
return false;
867 DEBUG(npf, 4,
"Next node: (%d, %d) [%d], possible trackdirs: 0x%X",
TileX(dst_tile),
TileY(dst_tile), dst_tile, trackdirbits);
877 DEBUG(npf, 6,
"After filtering: (%d, %d), possible trackdirs: 0x%X",
TileX(dst_tile),
TileY(dst_tile), trackdirbits);
893 Trackdir src_trackdir = current->path.node.direction;
894 TileIndex src_tile = current->path.node.tile;
899 uint subtype = user->subtype;
902 aystar->num_neighbours = 0;
903 DEBUG(npf, 4,
"Expanding: (%d, %d, %d) [%d]",
TileX(src_tile),
TileY(src_tile), src_trackdir, src_tile);
913 if (CheckIgnoreFirstTile(¤t->path)) {
921 }
else if (
ForceReverse(src_tile, src_exitdir, type, subtype)) {
934 if (type !=
TRANSPORT_ROAD || (RoadTramType)subtype == RTT_TRAM)
return;
944 if (type !=
TRANSPORT_ROAD || (RoadTramType)subtype == RTT_TRAM)
return;
968 DEBUG(npf, 5,
"Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits);
979 AyStarNode *neighbour = &aystar->neighbours[i];
980 neighbour->tile = dst_tile;
981 neighbour->direction = dst_trackdir;
983 neighbour->user_data[NPF_NODE_FLAGS] = current->path.node.user_data[NPF_NODE_FLAGS];
984 NPFFillTrackdirChoice(neighbour, current);
988 aystar->num_neighbours = i;
1001 static NPFFoundTargetData NPFRouteInternal(
AyStarNode *start1,
bool ignore_start_tile1,
AyStarNode *start2,
bool ignore_start_tile2,
NPFFindStationOrTileData *target,
AyStar_EndNodeCheck target_proc,
AyStar_CalculateH heuristic_proc,
AyStarUserData *user, uint reverse_penalty,
bool ignore_reserved =
false,
int max_penalty = 0)
1008 _npf_aystar.CalculateH = heuristic_proc;
1009 _npf_aystar.EndNodeCheck = target_proc;
1011 _npf_aystar.GetNeighbours = NPFFollowTrack;
1012 switch (user->type) {
1013 default: NOT_REACHED();
1014 case TRANSPORT_RAIL: _npf_aystar.CalculateG = NPFRailPathCost;
break;
1015 case TRANSPORT_ROAD: _npf_aystar.CalculateG = NPFRoadPathCost;
break;
1016 case TRANSPORT_WATER: _npf_aystar.CalculateG = NPFWaterPathCost;
break;
1021 start1->user_data[NPF_NODE_FLAGS] = 0;
1025 if (start2 !=
nullptr) {
1027 start2->user_data[NPF_NODE_FLAGS] = 0;
1040 _npf_aystar.user_path = &result;
1043 _npf_aystar.user_target = target;
1046 _npf_aystar.user_data = user;
1049 r = _npf_aystar.
Main();
1053 if (target !=
nullptr) {
1054 DEBUG(npf, 1,
"Could not find route to tile 0x%X from 0x%X.", target->
dest_coords, start1->tile);
1057 DEBUG(npf, 1,
"Could not find route to a depot from tile 0x%X.", start1->tile);
1072 start1.tile = tile1;
1073 start2.tile = tile2;
1074 start1.direction = trackdir1;
1075 start2.direction = trackdir2;
1077 return NPFRouteInternal(&start1, ignore_start_tile1, (
IsValidTile(tile2) ? &start2 :
nullptr), ignore_start_tile2, target, NPFFindStationOrTile, NPFCalcStationOrTileHeuristic, user, 0);
1100 start1.tile = tile1;
1101 start2.tile = tile2;
1102 start1.direction = trackdir1;
1103 start2.direction = trackdir2;
1107 return NPFRouteInternal(&start1, ignore_start_tile1, (
IsValidTile(tile2) ? &start2 :
nullptr), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty,
false, max_penalty);
1110 void InitializeNPF()
1112 static bool first_init =
true;
1117 _npf_aystar.
Clear();
1179 NPFFillWithOrderData(&fstd, v);
1203 NPFFillWithOrderData(&fstd, v);
1223 NPFFillWithOrderData(&fstd, v);
1231 ftd = NPFRouteToStationOrTileTwoWay(v->
tile, trackdir,
false, v->
tile, trackdir_rev,
false, &fstd, &user);
1270 start1.direction = trackdir;
1272 RailTypes railtypes = v->compatible_railtypes;
1278 return NPFRouteInternal(&start1,
true,
nullptr,
false, &fstd,
NPFFindSafeTile, NPFCalcZero, &user, 0,
true).
res_okay;
1287 NPFFillWithOrderData(&fstd, v);
1295 ftd = NPFRouteToStationOrTileTwoWay(v->
tile, trackdir,
false, last->
tile, trackdir_rev,
false, &fstd, &user);
1303 NPFFillWithOrderData(&fstd, v, reserve_track);
1311 if (target !=
nullptr) {
Buses, trucks and trams belong to this class.
bool okay
True if tile is a safe waiting position, false otherwise.
uint32 npf_road_curve_penalty
the penalty for curves
static bool CanEnterTile(TileIndex tile, DiagDirection dir, AyStarUserData *user)
Tests if a vehicle can enter a tile.
FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_penalty)
Used when user sends train to the nearest depot or if train needs servicing using NPF.
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
uint32 TileIndex
The index/ID of a Tile.
static TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
NPFSettings npf
pathfinder settings for the new pathfinder
#define TILE_ADD(x, y)
Adds to tiles together.
bool reserve_path
Indicates whether the found path should be reserved.
@ TRACK_BIT_NONE
No track.
@ AYSTAR_DONE
Not an end-tile, or wrong direction.
bool IsType(OrderType type) const
Check whether this order is of the given type.
const Vehicle * v
The vehicle we are pathfinding for.
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Meant to be stored in AyStar.userpath.
uint32 npf_road_drive_through_penalty
the penalty for going through a drive-through road stop
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
uint32 npf_rail_slope_penalty
the penalty for sloping upwards
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override
Determines the REMAINING length of a platform, starting at (and including) the given tile.
@ NPF_FLAG_SEEN_SIGNAL
Used to mark that a signal was seen on the way, for rail only.
StationID station_index
station index we're heading for, or INVALID_STATION when we're heading for a tile
Helper container to find a depot.
static Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
Removes first Trackdir from TrackdirBits and returns it.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
bool forbid_90_deg
forbid trains to make 90 deg turns
@ NPF_FLAG_IGNORE_RESERVED
Used to mark that reserved tiles should be considered impassable.
static const int NPF_INFINITE_PENALTY
This penalty is the equivalent of "infinite", which means that paths that get this penalty will be ch...
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
static DiagDirection GetSingleTramBit(TileIndex tile)
Tests if a tile is a road tile with a single tramtrack (tram can reverse)
int GetOccupied() const
Get the amount of occupied space in this drive through stop.
@ TRANSPORT_RAIL
Transport by train.
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
Set the reservation for a complete station platform.
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
DestinationID GetDestination() const
Gets the destination of this order.
Trackdir best_trackdir
The trackdir that leads to the shortest path/closest birds dist.
@ NPF_FLAG_IGNORE_START_TILE
Used to mark that the start tile is invalid, and searching should start from the second tile on.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
@ ROAD_SW
South-west part.
@ RAIL_TILE_SIGNALS
Normal rail tile with signals.
static bool IsRoadDepotTile(TileIndex t)
Return whether a tile is a road depot tile.
static void SetRailStationReservation(TileIndex t, bool b)
Set the reservation state of the rail station.
PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res)
Follow a train reservation to the last tile.
static T KillFirstBit(T value)
Clear the first bit in an integer.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static bool IsDepotTypeTile(TileIndex tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
static TrackdirBits GetDriveableTrackdirBits(TileIndex dst_tile, TileIndex src_tile, Trackdir src_trackdir, TransportType type, uint subtype)
Returns the driveable Trackdirs on a tile.
static RoadStopType GetRoadStopType(TileIndex t)
Get the road stop type of this tile.
static void NPFSetFlag(AyStarNode *node, NPFNodeFlag flag, bool value)
Sets the given flag on the given AyStarNode to the given value.
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
@ ROADSIDE_BARREN
Road on barren land.
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
static const uint TILE_SIZE
Tile size in world coordinates.
uint32 npf_crossing_penalty
the penalty for level crossings
@ RAIL_GROUND_BARREN
Nothing (dirt)
static DiagDirection GetTileSingleEntry(TileIndex tile, TransportType type, uint subtype)
Tests if a tile can be entered or left only from one side.
int32 AyStar_EndNodeCheck(const AyStar *aystar, const OpenListNode *current)
Check whether the end-tile is found.
const Entry * GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
bool NPFTrainCheckReverse(const Train *v)
Returns true if it is better to reverse the train before leaving station using NPF.
static bool Rail90DegTurnDisallowed(RailType rt1, RailType rt2, bool def=_settings_game.pf.forbid_90_deg)
Test if 90 degree turns are disallowed between two railtypes.
#define STRAIGHT_TRACK_LENGTH
Approximation of the length of a straight track, relative to a diagonal track (ie the size of a tile ...
uint32 npf_rail_pbs_cross_penalty
the penalty for crossing a reserved rail track
RoadType roadtype
Roadtype of this vehicle.
TransportType
Available types of transport.
@ VEH_ROAD
Road vehicle type.
int Main()
This is the function you call to run AyStar.
@ RAILTYPES_NONE
No rail types.
Owner owner
Which company owns the vehicle?
Trackdir GetVehicleTrackdir() const
Get the tracks of the train vehicle.
Owner
Enum for all companies/owners.
@ MP_ROAD
A tile with road (or tram tracks)
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
static DiagDirection GetShipDepotDirection(TileIndex t)
Get the direction of the ship depot.
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
static bool HasPbsSignalOnTrackdir(TileIndex tile, Trackdir td)
Is a pbs signal present along the trackdir?
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations)
Try to reserve a specific track on a tile.
static uint TileX(TileIndex tile)
Get the X component of a tile.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
SignalType
Type of signal, i.e.
@ NPF_FLAG_LAST_SIGNAL_RED
Used to mark that the last signal on this path was red.
uint32 npf_road_dt_occupied_penalty
the penalty multiplied by the fill percentage of a drive-through road stop
void Init(Hash_HashProc hash, uint num_buckets)
Initialize an AyStar.
StationType
Station types.
@ TRANSPORT_ROAD
Transport by road vehicle.
RoadBits
Enumeration for the road parts on a tile.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
uint32 npf_rail_pbs_signal_back_penalty
the penalty for passing a pbs signal from the backside
PathfinderSettings pf
settings for all pathfinders
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
static TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
Maps a trackdir to the trackdirs that can be reached from it (ie, when entering the next tile.
@ VS_HIDDEN
Vehicle is not visible.
void UnreserveRailTrack(TileIndex tile, Track t)
Lift the reservation of a specific track on a tile.
TileIndex dest_tile
Heading for this tile.
#define FOR_EACH_SET_TRACK(var, track_bits)
Iterate through each set Track in a TrackBits value.
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg)
Check if a safe position is free.
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
RailType
Enumeration for all possible railtypes.
Track NPFTrainChooseTrack(const Train *v, bool &path_found, bool reserve_track, struct PBSTileInfo *target)
Finds the best path for given train using NPF.
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
TileIndex tile
Current tile index.
#define DEBUG(name, level,...)
Output a line of debugging information.
@ SIGNAL_STATE_RED
The signal is red.
TileIndex dest_coords
An indication of where the station is, for heuristic purposes, or the target tile.
static const uint NPF_HASH_BITS
The size of the hash used in pathfinding. Just changing this value should be sufficient to change the...
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
This struct contains information about the end of a reserved path.
static void ClearPathReservation(const PathNode *start, const PathNode *end)
Lift the reservation of the tiles from start till end, excluding end itself.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
@ SIGTYPE_EXIT
presignal block exit
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
bool not_articulated
The (road) vehicle is not articulated.
Order current_order
The current order (+ status, like: loading)
Trackdir trackdir
The reserved trackdir on the tile.
@ SIGTYPE_COMBO
presignal inter-block
static bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
byte loops_per_tick
How many loops are there called before Main() gives control back to the caller. 0 = until done.
RoadTypes
The different roadtypes we support, but then a bitmask of them.
static void NPFSaveTargetData(AyStar *as, OpenListNode *current)
To be called when current contains the (shortest route to) the target node.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty)
Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using NPF.
@ NPF_FLAG_REVERSE
Used to mark that this node was reached from the second start node, if applicable.
static bool ForceReverse(TileIndex tile, DiagDirection dir, TransportType type, uint subtype)
Tests if a vehicle must reverse on a tile.
static TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
StationType station_type
The type of station we're heading for.
@ ROAD_NE
North-east part.
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
@ ROAD_SE
South-east part.
static bool IsRailDepotTile(TileIndex t)
Is this tile rail tile and a rail depot?
bool res_okay
True if a path reservation could be made.
static uint NPFHash(uint key1, uint key2)
Calculates a hash value for use in the NPF.
'Train' is either a loco or a wagon.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Meant to be stored in AyStar.targetdata.
@ NPF_FLAG_TARGET_RESERVED
Used to mark that the possible reservation target is already reserved.
bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg)
Determine whether a certain track on a tile is a safe position to end a path.
@ AYSTAR_STILL_BUSY
Some checking was done, but no path found yet, and there are still items left to try.
bool _networking
are we in networking mode?
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
uint32 npf_road_bay_occupied_penalty
the penalty multiplied by the fill percentage of a road bay
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
static uint NPFDistanceTrack(TileIndex t0, TileIndex t1)
Calculates the minimum distance travelled to get from t0 to t1 when only using tracks (ie,...
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
static bool CanEnterTileOwnerCheck(Owner owner, TileIndex tile, DiagDirection enterdir)
Finds out if a given company's vehicles are allowed to enter a given tile.
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
DiagDirection
Enumeration for diagonal directions.
Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
Finds the best path for given road vehicle using NPF.
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
AyStarNodeUserDataType
Indices into AyStarNode.userdata[].
static bool IsOnewaySignal(TileIndex t, Track track)
One-way signals can't be passed the 'wrong' way.
RoadType
The different roadtypes we support.
uint32 npf_rail_depot_reverse_penalty
the penalty for reversing in depots
@ NPF_FLAG_LAST_SIGNAL_BLOCK
Used to mark that the last signal on this path was a block signal.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
@ ROAD_NW
North-west part.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
static TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type)
Calculates the tile of given station that is closest to a given tile for this we assume the station i...
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
static const PathNode * FindSafePosition(PathNode *path, const Train *v)
Find the node containing the first signal on the path.
void Clear()
This function make the memory go back to zero.
TileIndex tile
Tile the path ends, INVALID_TILE if no valid path was found.
@ TRACKDIR_BIT_NONE
No track build.
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
@ NPF_FLAG_3RD_SIGNAL
Used to mark that three signals were seen, rail only.
All ships have this type.
AyStarNode node
The node within the target the search led us to.
uint32 npf_rail_firstred_exit_penalty
the penalty for when the first signal is red (and it is an exit or combo signal)
uint32 npf_rail_station_penalty
the penalty for station tiles
@ AYSTAR_FOUND_END_NODE
An end node was found.
static bool IsRailWaypoint(TileIndex t)
Is this station tile a rail waypoint?
AyStar search algorithm struct.
static DiagDirection GetDepotDirection(TileIndex tile, TransportType type)
Returns the direction the exit of the depot on the given tile is facing.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
bool NPFShipCheckReverse(const Ship *v)
Returns true if it is better to reverse the ship before leaving depot using NPF.
bool NPFTrainFindNearestSafeTile(const Train *v, TileIndex tile, Trackdir trackdir, bool override_railtype)
Try to extend the reserved path of a train to the nearest safe tile using NPF.
PathNode * parent
The parent of this item.
static SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir)
Gets the state of the signal along the given trackdir.
static TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static bool IsDriveThroughRoadStopContinuation(TileIndex rs, TileIndex next)
Checks whether the 'next' tile is still part of the road same drive through stop 'rs' in the same dir...
@ TRANSPORT_WATER
Transport over water.
@ MP_STATION
A tile of a station.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
static const int NPF_TILE_LENGTH
Length (penalty) of one tile with NPF.
Indices into AyStar.userdata[].
static int32 NPFFindSafeTile(const AyStar *as, const OpenListNode *current)
Find any safe and free tile.
@ TRACKDIR_END
Used for iterations.
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
int GetLength() const
Get the length of this drive through stop.
@ NPF_TRACKDIR_CHOICE
The trackdir chosen to get here.
Track NPFShipChooseTrack(const Ship *v, bool &path_found)
Finds the best path for given ship using NPF.
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
TrackBits
Bitfield corresponding to Track.
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
uint32 npf_max_search_nodes
The maximum amount of search nodes a single NPF run should take.
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
bool IsFreeBay(uint nr) const
Checks whether the given bay is free in this road stop.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
bool IsBus() const
Check whether a roadvehicle is a bus.
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
static void SetRoadside(TileIndex tile, Roadside s)
Set the decorations of a road.
uint max_path_cost
If the g-value goes over this number, it stops searching, 0 = infinite.
static Axis GetCrossingRoadAxis(TileIndex t)
Get the road axis of a level crossing.
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Trackdir
Enumeration for tracks and directions.
NPFNodeFlag
Flags for AyStarNode.userdata[NPF_NODE_FLAGS].
static Trackdir NextTrackdir(Trackdir trackdir)
Maps a trackdir to the trackdir that you will end up on if you go straight ahead.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
@ VEH_TRAIN
Train vehicle type.
int32 AyStar_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
Calculate the H-value for the AyStar algorithm.
A Stop for a Road Vehicle.
VehicleType type
Type of vehicle.
Track
These are used to specify a single track.
uint32 npf_rail_curve_penalty
the penalty for curves
uint best_path_dist
The shortest path. Is UINT_MAX if no path is found.
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Container for each entry point of a drive through road stop.
@ VEH_SHIP
Ship vehicle type.
@ ROADTYPES_NONE
No roadtypes.
void AddStartNode(AyStarNode *start_node, uint g)
Adds a node from where to start an algorithm.
uint32 npf_rail_firstred_penalty
the penalty for when the first signal is red (and it is not an exit or combo signal)
RailTypes
The different railtypes we support, but then a bitmask of them.
static TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
uint32 npf_water_curve_penalty
the penalty for curves
T * Last()
Get the last vehicle in the chain.
static bool NPFGetFlag(const AyStarNode *node, NPFNodeFlag flag)
Returns the current value of the given flag on the given AyStarNode.
uint best_bird_dist
The best heuristic found. Is 0 if the target was found.
static bool IsValidTrackdir(Trackdir trackdir)
Checks if a Trackdir is valid for non-road vehicles.
uint32 npf_buoy_penalty
the penalty for going over (through) a buoy
static void NPFMarkTile(TileIndex tile)
Mark tiles by mowing the grass when npf debug level >= 1.
Track follower helper template class (can serve pathfinders and vehicle controllers).
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
uint32 npf_rail_lastred_penalty
the penalty for when the last signal is red
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
@ NPF_FLAG_2ND_SIGNAL
Used to mark that two signals were seen, rail only.
uint max_search_nodes
The maximum number of nodes that will be expanded, 0 = infinite.