|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
10 #include "../../stdafx.h"
11 #include "../../debug.h"
12 #include "../../network/network.h"
13 #include "../../viewport_func.h"
14 #include "../../ship.h"
15 #include "../../roadstop_base.h"
16 #include "../../vehicle_func.h"
17 #include "../pathfinder_func.h"
18 #include "../pathfinder_type.h"
19 #include "../follow_track.hpp"
22 #include "../../safeguards.h"
28 static const uint NPF_HASH_HALFMASK = (1 << NPF_HASH_HALFBITS) - 1;
82 #define NPF_STRAIGHT_LENGTH (uint)(NPF_TILE_LENGTH * STRAIGHT_TRACK_LENGTH)
94 return HasBit(node->user_data[NPF_NODE_FLAGS], flag);
102 SB(node->user_data[NPF_NODE_FLAGS], flag, 1, value);
105 bool CheckIgnoreFirstTile(
const PathNode *node)
121 const uint straightTracks = 2 * std::min(dx, dy);
126 const uint diagTracks = dx + dy - straightTracks;
143 uint part1 =
TileX(tile) & NPF_HASH_HALFMASK;
144 uint part2 =
TileY(tile) & NPF_HASH_HALFMASK;
148 return ((part1 << NPF_HASH_HALFBITS | part2) + (NPF_HASH_SIZE * dir /
TRACKDIR_END)) % NPF_HASH_SIZE;
181 Debug(npf, 4,
"Calculating H for: ({}, {}). Result: {}",
TileX(current->tile),
TileY(current->tile), dist);
183 if (dist < ftd->best_bird_dist) {
184 ftd->best_bird_dist = dist;
196 if (parent->path.
parent ==
nullptr) {
197 Trackdir trackdir = current->direction;
201 Debug(npf, 6,
"Saving trackdir: 0x{:X}", trackdir);
211 static uint NPFTunnelCost(
AyStarNode *current)
227 static inline uint NPFBridgeCost(
AyStarNode *current)
242 int dx4 = (x2 - x1) / 4;
243 int dy4 = (y2 - y1) / 4;
261 static uint NPFReservedTrackCost(
AyStarNode *current)
308 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: ({}, {}). Result: {}",
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: ({}, {}). Result: {}",
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;
865 Debug(npf, 4,
"Next node: ({}, {}) [{}], possible trackdirs: 0x{:X}",
TileX(dst_tile),
TileY(dst_tile), dst_tile, trackdirbits);
875 Debug(npf, 6,
"After filtering: ({}, {}), possible trackdirs: 0x{:X}",
TileX(dst_tile),
TileY(dst_tile), trackdirbits);
891 Trackdir src_trackdir = current->path.node.direction;
892 TileIndex src_tile = current->path.node.tile;
897 uint subtype = user->subtype;
900 aystar->num_neighbours = 0;
901 Debug(npf, 4,
"Expanding: ({}, {}, {}) [{}]",
TileX(src_tile),
TileY(src_tile), src_trackdir, src_tile);
911 if (CheckIgnoreFirstTile(¤t->path)) {
919 }
else if (
ForceReverse(src_tile, src_exitdir, type, subtype)) {
932 if (type !=
TRANSPORT_ROAD || (RoadTramType)subtype == RTT_TRAM)
return;
942 if (type !=
TRANSPORT_ROAD || (RoadTramType)subtype == RTT_TRAM)
return;
965 Debug(npf, 5,
"Expanded into trackdir: {}, remaining trackdirs: 0x{:X}", dst_trackdir, trackdirbits);
976 AyStarNode *neighbour = &aystar->neighbours[i];
977 neighbour->tile = dst_tile;
978 neighbour->direction = dst_trackdir;
980 neighbour->user_data[NPF_NODE_FLAGS] = current->path.node.user_data[NPF_NODE_FLAGS];
981 NPFFillTrackdirChoice(neighbour, current);
985 aystar->num_neighbours = i;
998 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)
1002 _npf_aystar.CalculateH = heuristic_proc;
1003 _npf_aystar.EndNodeCheck = target_proc;
1005 _npf_aystar.GetNeighbours = NPFFollowTrack;
1006 switch (user->type) {
1007 default: NOT_REACHED();
1008 case TRANSPORT_RAIL: _npf_aystar.CalculateG = NPFRailPathCost;
break;
1009 case TRANSPORT_ROAD: _npf_aystar.CalculateG = NPFRoadPathCost;
break;
1010 case TRANSPORT_WATER: _npf_aystar.CalculateG = NPFWaterPathCost;
break;
1015 start1->user_data[NPF_NODE_FLAGS] = 0;
1019 if (start2 !=
nullptr) {
1021 start2->user_data[NPF_NODE_FLAGS] = 0;
1030 result.best_bird_dist = UINT_MAX;
1031 result.best_path_dist = UINT_MAX;
1034 result.res_okay =
false;
1035 _npf_aystar.user_path = &result;
1038 _npf_aystar.user_target = target;
1041 _npf_aystar.user_data = user;
1044 [[maybe_unused]]
int r = _npf_aystar.
Main();
1047 if (result.best_bird_dist != 0) {
1048 if (target !=
nullptr) {
1049 Debug(npf, 1,
"Could not find route to tile 0x{:X} from 0x{:X}.", target->
dest_coords, start1->tile);
1052 Debug(npf, 1,
"Could not find route to a depot from tile 0x{:X}.", start1->tile);
1067 start1.tile = tile1;
1068 start2.tile = tile2;
1069 start1.direction = trackdir1;
1070 start2.direction = trackdir2;
1072 return NPFRouteInternal(&start1, ignore_start_tile1, (
IsValidTile(tile2) ? &start2 :
nullptr), ignore_start_tile2, target, NPFFindStationOrTile, NPFCalcStationOrTileHeuristic, user, 0);
1095 start1.tile = tile1;
1096 start2.tile = tile2;
1097 start1.direction = trackdir1;
1098 start2.direction = trackdir2;
1102 return NPFRouteInternal(&start1, ignore_start_tile1, (
IsValidTile(tile2) ? &start2 :
nullptr), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty,
false, max_penalty);
1105 void InitializeNPF()
1107 static bool first_init =
true;
1112 _npf_aystar.
Clear();
1173 NPFFillWithOrderData(&fstd, v);
1197 NPFFillWithOrderData(&fstd, v);
1217 NPFFillWithOrderData(&fstd, v);
1225 if (best_td !=
nullptr) {
1233 ftd = NPFRouteToStationOrTileTwoWay(v->
tile, best,
false, v->
tile, td,
false, &fstd, &user);
1241 ftd = NPFRouteToStationOrTileTwoWay(v->
tile, trackdir,
false, v->
tile, trackdir_rev,
false, &fstd, &user);
1281 start1.direction = trackdir;
1283 RailTypes railtypes = v->compatible_railtypes;
1289 return NPFRouteInternal(&start1,
true,
nullptr,
false, &fstd,
NPFFindSafeTile, NPFCalcZero, &user, 0,
true).
res_okay;
1298 NPFFillWithOrderData(&fstd, v);
1306 ftd = NPFRouteToStationOrTileTwoWay(v->
tile, trackdir,
false, last->
tile, trackdir_rev,
false, &fstd, &user);
1314 NPFFillWithOrderData(&fstd, v, reserve_track);
1322 if (target !=
nullptr) {
Buses, trucks and trams belong to this class.
bool Rail90DegTurnDisallowed(RailType rt1, RailType rt2, bool def=_settings_game.pf.forbid_90_deg)
Test if 90 degree turns are disallowed between two railtypes.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
uint32_t npf_rail_firstred_exit_penalty
the penalty for when the first signal is red (and it is an exit or combo signal)
bool okay
True if tile is a safe waiting position, false otherwise.
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.
NPFSettings npf
pathfinder settings for the new pathfinder
#define TILE_ADD(x, y)
Adds two 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.
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.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
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.
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
static const int NPF_INFINITE_PENALTY
This penalty is the equivalent of "infinite", which means that paths that get this penalty will be ch...
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
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)
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
int GetOccupied() const
Get the amount of occupied space in this drive through stop.
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
Set the reservation for a complete station platform.
bool IsOnewaySignal(Tile t, Track track)
One-way signals can't be passed the 'wrong' way.
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
DestinationID GetDestination() const
Gets the destination of this order.
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
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.
TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
@ RAIL_TILE_SIGNALS
Normal rail tile with signals.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
uint32_t npf_water_curve_penalty
the penalty for curves
uint32_t npf_rail_firstred_penalty
the penalty for when the first signal is red (and it is not an exit or combo signal)
PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res)
Follow a train reservation to the last tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static TrackdirBits GetDriveableTrackdirBits(TileIndex dst_tile, TileIndex src_tile, Trackdir src_trackdir, TransportType type, uint subtype)
Returns the driveable Trackdirs on a tile.
static void NPFSetFlag(AyStarNode *node, NPFNodeFlag flag, bool value)
Sets the given flag on the given AyStarNode to the given value.
@ ROADSIDE_BARREN
Road on barren land.
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
static const uint TILE_SIZE
Tile size in world coordinates.
@ 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.
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
const Entry * GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
DiagDirection GetRoadStopDir(Tile t)
Gets the direction the road stop entrance points towards.
@ TRANSPORT_WATER
Transport over water.
bool NPFTrainCheckReverse(const Train *v)
Returns true if it is better to reverse the train before leaving station using NPF.
#define STRAIGHT_TRACK_LENGTH
Approximation of the length of a straight track, relative to a diagonal track (ie the size of a tile ...
Trackdir NextTrackdir(Trackdir trackdir)
Maps a trackdir to the trackdir that you will end up on if you go straight ahead.
RoadType roadtype
Roadtype of this vehicle.
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
@ VEH_ROAD
Road vehicle type.
int Main()
This is the function you call to run AyStar.
Owner owner
Which company owns the vehicle?
Owner
Enum for all companies/owners.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
RailTypes
Allow incrementing of Track variables.
@ MP_ROAD
A tile with road (or tram tracks)
constexpr T KillFirstBit(T value)
Clear the first bit in an integer.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
uint32_t npf_rail_pbs_signal_back_penalty
the penalty for passing a pbs signal from the backside
bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations)
Try to reserve a specific track on a tile.
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
SignalType
Type of signal, i.e.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
@ NPF_FLAG_LAST_SIGNAL_RED
Used to mark that the last signal on this path was red.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
void Init(Hash_HashProc hash, uint num_buckets)
Initialize an AyStar.
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
StationType
Station types.
int32_t AyStar_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
Calculate the H-value for the AyStar algorithm.
PathfinderSettings pf
settings for all pathfinders
@ ROADTYPES_NONE
No roadtypes.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
@ VS_HIDDEN
Vehicle is not visible.
void UnreserveRailTrack(TileIndex tile, Track t)
Lift the reservation of a specific track on a tile.
static debug_inline bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
@ TRANSPORT_RAIL
Transport by train.
TileIndex dest_tile
Heading for this tile.
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg)
Check if a safe position is free.
@ ROAD_NE
North-east part.
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
RailType
Enumeration for all possible railtypes.
uint32_t npf_crossing_penalty
the penalty for level crossings
uint32_t npf_rail_lastred_penalty
the penalty for when the last signal is red
Iterable ensemble of each set bit in a value.
Trackdir GetVehicleTrackdir() const override
Get the tracks of the train vehicle.
TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
Track NPFTrainChooseTrack(const Train *v, bool &path_found, bool reserve_track, struct PBSTileInfo *target)
Finds the best path for given train using NPF.
RoadTypes
The different roadtypes we support, but then a bitmask of them.
TileIndex tile
Current tile index.
@ 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...
bool IsTunnel(Tile t)
Is this a tunnel (entrance)?
TransportType
Available types of transport.
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.
@ TRACKDIR_BIT_NONE
No track build.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
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.
void SetRoadside(Tile tile, Roadside s)
Set the decorations of a road.
byte loops_per_tick
How many loops are there called before Main() gives control back to the caller. 0 = until done.
uint32_t npf_rail_station_penalty
the penalty for station tiles
TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
Maps a trackdir to the trackdirs that can be reached from it (ie, when entering the next tile.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
static void NPFSaveTargetData(AyStar *as, OpenListNode *current)
To be called when current contains the (shortest route to) the target node.
Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
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.
bool IsBuoyTile(Tile t)
Is tile t a buoy tile?
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
StationType station_type
The type of station we're heading for.
DiagDirection VehicleExitDir(Direction direction, TrackBits track)
Determine the side in which the vehicle will leave the tile.
bool res_okay
True if a path reservation could be made.
static debug_inline bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
'Train' is either a loco or a wagon.
Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
Removes first Trackdir from TrackdirBits and returns it.
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.
SignalState GetSignalStateByTrackdir(Tile tile, Trackdir trackdir)
Gets the state of the signal along the given trackdir.
DiagDirection GetShipDepotDirection(Tile t)
Get the direction of the ship depot.
bool _networking
are we in networking mode?
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
bool IsDepotTypeTile(Tile tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
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 CanEnterTileOwnerCheck(Owner owner, TileIndex tile, DiagDirection enterdir)
Finds out if a given company's vehicles are allowed to enter a given tile.
DiagDirection
Enumeration for diagonal directions.
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
Finds the best path for given road vehicle using NPF.
@ SIGTYPE_EXIT
presignal block exit
void SetRailStationReservation(Tile t, bool b)
Set the reservation state of the rail station.
@ SIGTYPE_COMBO
presignal inter-block
AyStarNodeUserDataType
Indices into AyStarNode.userdata[].
uint32_t npf_rail_pbs_cross_penalty
the penalty for crossing a reserved rail track
static int32_t NPFFindSafeTile(const AyStar *as, const OpenListNode *current)
Find any safe and free tile.
@ NPF_FLAG_LAST_SIGNAL_BLOCK
Used to mark that the last signal on this path was a block signal.
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
StationType GetStationType(Tile t)
Get the station type of this tile.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Direction direction
facing
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
uint32_t npf_road_dt_occupied_penalty
the penalty multiplied by the fill percentage of a drive-through road stop
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.
int32_t AyStar_EndNodeCheck(const AyStar *aystar, const OpenListNode *current)
Check whether the end-tile is found.
TileIndex tile
Tile the path ends, INVALID_TILE if no valid path was found.
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
uint32_t npf_rail_curve_penalty
the penalty for curves
@ 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.
@ AYSTAR_FOUND_END_NODE
An end node was found.
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.
uint32_t npf_road_curve_penalty
the penalty for curves
Axis GetCrossingRoadAxis(Tile t)
Get the road axis of a level crossing.
bool IsDockingTile(Tile t)
Checks whether the tile is marked as a dockling tile.
static debug_inline bool IsRailDepotTile(Tile t)
Is this tile rail tile and a rail depot?
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
static uint NPFHash(TileIndex tile, Trackdir dir)
Calculates a hash value for use in the NPF.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
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...
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.
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...
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
TrackBits state
The "track" the ship is following.
uint32_t npf_road_drive_through_penalty
the penalty for going through a drive-through road stop
@ MP_STATION
A tile of a station.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific 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[].
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
@ TRACKDIR_END
Used for iterations.
RoadType
The different roadtypes we support.
int GetLength() const
Get the length of this drive through stop.
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
@ NPF_TRACKDIR_CHOICE
The trackdir chosen to get here.
RoadBits
Enumeration for the road parts on a tile.
Track NPFShipChooseTrack(const Ship *v, bool &path_found)
Finds the best path for given ship using NPF.
bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
TrackBits
Allow incrementing of Track variables.
RoadStopType GetRoadStopType(Tile t)
Get the road stop type of this tile.
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
uint32_t npf_road_bay_occupied_penalty
the penalty multiplied by the fill percentage of a road bay
@ ROAD_NW
North-west part.
@ ROAD_SW
South-west part.
uint32_t npf_max_search_nodes
The maximum amount of search nodes a single NPF run should take.
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
@ ROAD_SE
South-east part.
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.
bool IsBus() const
Check whether a roadvehicle is a bus.
@ TRANSPORT_ROAD
Transport by road vehicle.
uint max_path_cost
If the g-value goes over this number, it stops searching, 0 = infinite.
bool NPFShipCheckReverse(const Ship *v, Trackdir *best_td)
Returns true if it is better to reverse the ship before leaving depot using NPF.
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
uint32_t npf_rail_depot_reverse_penalty
the penalty for reversing in depots
Trackdir
Enumeration for tracks and directions.
NPFNodeFlag
Flags for AyStarNode.userdata[NPF_NODE_FLAGS].
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
@ VEH_TRAIN
Train vehicle type.
bool IsRailWaypoint(Tile t)
Is this station tile a rail waypoint?
TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
A Stop for a Road Vehicle.
VehicleType type
Type of vehicle.
uint32_t npf_buoy_penalty
the penalty for going over (through) a buoy
TrackdirBits
Allow incrementing of Trackdir variables.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
bool HasPbsSignalOnTrackdir(Tile tile, Trackdir td)
Is a pbs signal present along the trackdir?
Track
These are used to specify a single track.
uint32_t npf_rail_slope_penalty
the penalty for sloping upwards
bool IsValidTrackdir(Trackdir trackdir)
Checks if a Trackdir is valid for non-road vehicles.
uint best_path_dist
The shortest path. Is UINT_MAX if no path is found.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Container for each entry point of a drive through road stop.
@ VEH_SHIP
Ship vehicle type.
void AddStartNode(AyStarNode *start_node, uint g)
Adds a node from where to start an algorithm.
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.
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
static debug_inline bool IsRoadDepot(Tile t)
Return whether a tile is a road depot.
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).
bool IsDriveThroughStopTile(Tile t)
Is tile t a drive through road stop station?
static debug_inline bool IsRoadDepotTile(Tile t)
Return whether a tile is a road depot tile.
@ NPF_FLAG_2ND_SIGNAL
Used to mark that two signals were seen, rail only.
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
bool HasSignalOnTrackdir(Tile tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
uint max_search_nodes
The maximum number of nodes that will be expanded, 0 = infinite.
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
@ RAILTYPES_NONE
No rail types.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.