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 *
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)) {
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);
1245 fstd.reserve_path =
false;
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) {
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Owner
Enum for all companies/owners.
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
void Init(Hash_HashProc hash, uint num_buckets)
Initialize an AyStar.
Used to mark that the start tile is invalid, and searching should start from the second tile on...
static bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
Used to mark that the possible reservation target is already reserved.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
bool _networking
are we in networking mode?
static DiagDirection GetDepotDirection(TileIndex tile, TransportType type)
Returns the direction the exit of the depot on the given tile is facing.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
bool Follow(TileIndex old_tile, Trackdir old_td)
main follower routine.
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.
SignalType
Type of signal, i.e.
TrackdirBits m_new_td_bits
the new set of available trackdirs
static RoadStopType GetRoadStopType(TileIndex t)
Get the road stop type of this tile.
RoadTypes
The different roadtypes we support, but then a bitmask of them.
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
int GetLength() const
Get the length of this drive through stop.
Used to mark that two signals were seen, rail only.
Trackdir
Enumeration for tracks and directions.
A tile with road (or tram tracks)
byte loops_per_tick
How many loops are there called before Main() gives control back to the caller. 0 = until done...
uint max_path_cost
If the g-value goes over this number, it stops searching, 0 = infinite.
static TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
int GetOccupied() const
Get the amount of occupied space in this drive through stop.
static const PathNode * FindSafePosition(PathNode *path, const Train *v)
Find the node containing the first signal on the path.
TileIndex dest_tile
Heading for this tile.
static bool IsOnewaySignal(TileIndex t, Track track)
One-way signals can't be passed the 'wrong' way.
NPFSettings npf
pathfinder settings for the new pathfinder
static uint TileX(TileIndex tile)
Get the X component of a tile.
Not an end-tile, or wrong direction.
PathfinderSettings pf
settings for all pathfinders
uint32 npf_max_search_nodes
The maximum amount of search nodes a single NPF run should take.
NPFNodeFlag
Flags for AyStarNode.userdata[NPF_NODE_FLAGS].
static uint NPFHash(uint key1, uint key2)
Calculates a hash value for use in the NPF.
static Trackdir NextTrackdir(Trackdir trackdir)
Maps a trackdir to the trackdir that you will end up on if you go straight ahead. ...
bool forbid_90_deg
forbid trains to make 90 deg turns
static void SetRailStationReservation(TileIndex t, bool b)
Set the reservation state of the rail station.
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel ...
uint32 npf_rail_firstred_penalty
the penalty for when the first signal is red (and it is not an exit or combo signal) ...
Flag for an invalid DiagDirection.
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...
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
RoadType
The different roadtypes we support.
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res)
Follow a train reservation to the last tile.
Meant to be stored in AyStar.targetdata.
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
static bool CanEnterTile(TileIndex tile, DiagDirection dir, AyStarUserData *user)
Tests if a vehicle can enter a tile.
uint32 npf_crossing_penalty
the penalty for level crossings
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations)
Try to reserve a specific track on a tile.
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
static const uint TILE_SIZE
Tile size in world coordinates.
This file has the header for AyStar.
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.
uint32 npf_rail_pbs_cross_penalty
the penalty for crossing a reserved rail track
static DiagDirection GetTileSingleEntry(TileIndex tile, TransportType type, uint subtype)
Tests if a tile can be entered or left only from one side.
Normal rail tile with signals.
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 bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Buses, trucks and trams belong to this class.
RoadType roadtype
Roadtype of this vehicle.
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
AyStarNodeUserDataType
Indices into AyStarNode.userdata[].
AyStar search algorithm struct.
static void ClearPathReservation(const PathNode *start, const PathNode *end)
Lift the reservation of the tiles from start till end, excluding end itself.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static bool IsValidTrackdir(Trackdir trackdir)
Checks if a Trackdir is valid for non-road vehicles.
Track NPFTrainChooseTrack(const Train *v, bool &path_found, bool reserve_track, struct PBSTileInfo *target)
Finds the best path for given train using NPF.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Meant to be stored in AyStar.userpath.
uint32 npf_road_dt_occupied_penalty
the penalty multiplied by the fill percentage of a drive-through road stop
static bool ForceReverse(TileIndex tile, DiagDirection dir, TransportType type, uint subtype)
Tests if a vehicle must reverse on 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 RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
void AddStartNode(AyStarNode *start_node, uint g)
Adds a node from where to start an algorithm.
static TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
uint32 npf_buoy_penalty
the penalty for going over (through) a buoy
Used to mark that reserved tiles should be considered impassable.
static bool IsDepotTypeTile(TileIndex tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
static uint NPFDistanceTrack(TileIndex t0, TileIndex t1)
Calculates the minimum distance travelled to get from t0 to t1 when only using tracks (ie...
TileIndex dest_coords
An indication of where the station is, for heuristic purposes, or the target tile.
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
bool res_okay
True if a path reservation could be made.
bool IsType(OrderType type) const
Check whether this order is of the given type.
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
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 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.
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
Track y-axis, direction south-east.
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg)
Check if a safe position is free.
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Trackdir best_trackdir
The trackdir that leads to the shortest path/closest birds dist.
#define FOR_EACH_SET_TRACK(var, track_bits)
Iterate through each set Track in a TrackBits value.
Flag for an invalid trackdir.
static Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
Removes first Trackdir from TrackdirBits and returns it.
static int32 NPFFindSafeTile(const AyStar *as, const OpenListNode *current)
Find any safe and free tile.
uint max_search_nodes
The maximum number of nodes that will be expanded, 0 = infinite.
uint best_bird_dist
The best heuristic found. Is 0 if the target was found.
RoadBits
Enumeration for the road parts on a tile.
static bool IsRoadDepotTile(TileIndex t)
Return whether a tile is a road depot tile.
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
static bool HasPbsSignalOnTrackdir(TileIndex tile, Trackdir td)
Is a pbs signal present along the trackdir?
static Axis GetCrossingRoadAxis(TileIndex t)
Get the road axis of a level crossing.
uint32 npf_road_curve_penalty
the penalty for curves
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
TrackBits
Bitfield corresponding to Track.
Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
Finds the best path for given road vehicle using NPF.
TileIndex tile
Current tile index.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
bool IsFreeBay(uint nr) const
Checks whether the given bay is free in this road stop.
bool okay
True if tile is a safe waiting position, false otherwise.
static void NPFSetFlag(AyStarNode *node, NPFNodeFlag flag, bool value)
Sets the given flag on the given AyStarNode to the given value.
Owner owner
Which company owns the vehicle?
StationID station_index
station index we're heading for, or INVALID_STATION when we're heading for a tile ...
static TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
Maps a trackdir to the trackdirs that can be reached from it (ie, when entering the next tile...
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
static T min(const T a, const T b)
Returns the minimum of two values.
bool NPFTrainCheckReverse(const Train *v)
Returns true if it is better to reverse the train before leaving station using NPF.
Used to mark that this node was reached from the second start node, if applicable.
RailTypes
The different railtypes we support, but then a bitmask of them.
int32 AyStar_EndNodeCheck(const AyStar *aystar, const OpenListNode *current)
Check whether the end-tile is found.
Used to mark that three signals were seen, rail only.
PathNode * parent
The parent of this item.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Track follower helper template class (can serve pathfinders and vehicle controllers).
All ships have this type.
bool reserve_path
Indicates whether the found path should be reserved.
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...
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
TileIndex tile
Tile the path ends, INVALID_TILE if no valid path was found.
int32 AyStar_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
Calculate the H-value for the AyStar algorithm.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
static void SetRoadside(TileIndex tile, Roadside s)
Set the decorations of a road.
Container for each entry point of a drive through road stop.
Used to mark that the last signal on this path was a block signal.
uint32 npf_rail_firstred_exit_penalty
the penalty for when the first signal is red (and it is an exit or combo signal)
#define DEBUG(name, level,...)
Output a line of debugging information.
'Train' is either a loco or a wagon.
This struct contains information about the end of a reserved path.
uint32 npf_rail_pbs_signal_back_penalty
the penalty for passing a pbs signal from the backside
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
static TrackdirBits GetDriveableTrackdirBits(TileIndex dst_tile, TileIndex src_tile, Trackdir src_trackdir, TransportType type, uint subtype)
Returns the driveable Trackdirs on a tile.
Some checking was done, but no path found yet, and there are still items left to try.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
static DiagDirection GetSingleTramBit(TileIndex tile)
Tests if a tile is a road tile with a single tramtrack (tram can reverse)
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Indices into AyStar.userdata[].
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
static DiagDirection GetShipDepotDirection(TileIndex t)
Get the direction of the ship depot.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
static T KillFirstBit(T value)
Clear the first bit in an integer.
bool IsBus() const
Check whether a roadvehicle is a bus.
StationType
Station types.
uint32 npf_road_bay_occupied_penalty
the penalty multiplied by the fill percentage of a road bay
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
RailType
Enumeration for all possible railtypes.
Trackdir GetVehicleTrackdir() const
Get the tracks of the train vehicle.
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
Tunnel entry/exit and bridge heads.
DestinationID GetDestination() const
Gets the destination of this order.
static bool IsRailDepotTile(TileIndex t)
Is this tile rail tile and a rail depot?
uint32 npf_rail_slope_penalty
the penalty for sloping upwards
T * Last()
Get the last vehicle in the chain.
uint32 TileIndex
The index/ID of a Tile.
bool not_articulated
The (road) vehicle is not articulated.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Helper container to find a depot.
uint32 npf_rail_depot_reverse_penalty
the penalty for reversing in depots
uint32 npf_rail_curve_penalty
the penalty for curves
Track
These are used to specify a single track.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
int Main()
This is the function you call to run AyStar.
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
TileIndex m_new_tile
the new tile (the vehicle has entered)
TransportType
Available types of transport.
AyStarNode node
The node within the target the search led us to.
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
VehicleType type
Type of vehicle.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
uint best_path_dist
The shortest path. Is UINT_MAX if no path is found.
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
Set the reservation for a complete station platform.
#define STRAIGHT_TRACK_LENGTH
Approximation of the length of a straight track, relative to a diagonal track (ie the size of a tile ...
Transport by road vehicle.
const Entry * GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
Track x-axis, direction south-west.
static const int NPF_TILE_LENGTH
Length (penalty) of one tile with NPF.
static bool IsRailWaypoint(TileIndex t)
Is this station tile a rail waypoint?
Track y-axis, direction north-west.
uint32 npf_road_drive_through_penalty
the penalty for going through a drive-through road stop
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
A Stop for a Road Vehicle.
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...
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
const Vehicle * v
The vehicle we are pathfinding for.
Used to mark that the last signal on this path was red.
Trackdir trackdir
The reserved trackdir on the tile.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
The trackdir chosen to get here.
DiagDirection
Enumeration for diagonal directions.
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Track NPFShipChooseTrack(const Ship *v, bool &path_found)
Finds the best path for given ship using NPF.
Northeast, upper right on your monitor.
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 TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
StationType station_type
The type of station we're heading for.
Used to mark that a signal was seen on the way, for rail only.
static bool NPFGetFlag(const AyStarNode *node, NPFNodeFlag flag)
Returns the current value of the given flag on the given AyStarNode.
Track x-axis, direction north-east.
static TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
#define TILE_ADD(x, y)
Adds to tiles together.
static SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir)
Gets the state of the signal along the given trackdir.
void Clear()
This function make the memory go back to zero.
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
static TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
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.
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override
Determines the REMAINING length of a platform, starting at (and including) the given tile...
uint32 npf_rail_lastred_penalty
the penalty for when the last signal is red
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
bool NPFShipCheckReverse(const Ship *v)
Returns true if it is better to reverse the ship before leaving depot using NPF.
static void NPFMarkTile(TileIndex tile)
Mark tiles by mowing the grass when npf debug level >= 1.
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Order current_order
The current order (+ status, like: loading)
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
uint32 npf_water_curve_penalty
the penalty for curves
static void NPFSaveTargetData(AyStar *as, OpenListNode *current)
To be called when current contains the (shortest route to) the target node.
void UnreserveRailTrack(TileIndex tile, Track t)
Lift the reservation of a specific track on a tile.
uint32 npf_rail_station_penalty
the penalty for station tiles