12 #include "../../stdafx.h" 13 #include "../../network/network.h" 14 #include "../../viewport_func.h" 15 #include "../../ship.h" 16 #include "../../roadstop_base.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;
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 == NULL) {
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)
309 Trackdir trackdir = current->direction;
311 cost = _trackdir_length[trackdir];
335 cost =
IsTunnel(tile) ? NPFTunnelCost(current) : NPFBridgeCost(current);
371 cost += NPFSlopeCost(current);
380 DEBUG(npf, 4,
"Calculating G for: (%d, %d). Result: %d",
TileX(current->tile),
TileY(current->tile), cost);
389 Trackdir trackdir = current->direction;
397 cost =
IsTunnel(tile) ? NPFTunnelCost(current) : NPFBridgeCost(current);
401 cost = _trackdir_length[trackdir];
427 while (ft.
Follow(t, td)) {
468 if (!IsPbsSignal(sigtype)) {
505 new_node.path.node = *current;
511 cost += NPFSlopeCost(current);
529 cost += NPFReservedTrackCost(current);
532 DEBUG(npf, 4,
"Calculating G for: (%d, %d). Result: %d",
TileX(current->tile),
TileY(current->tile), cost);
601 bool first_run =
true;
602 for (; start != end; start = start->
parent) {
623 ftd->best_path_dist = current->g;
624 ftd->best_bird_dist = 0;
625 ftd->node = current->path.node;
626 ftd->res_okay =
false;
633 ftd->node = target->node;
642 ftd->node.tile = end_tile;
658 ftd->res_okay =
true;
790 if (!
HasBit(user->railtypes, rail_type))
return false;
833 DEBUG(npf, 4,
"Next node: (%d, %d) [%d], possible trackdirs: 0x%X",
TileX(dst_tile),
TileY(dst_tile), dst_tile, trackdirbits);
841 DEBUG(npf, 6,
"After filtering: (%d, %d), possible trackdirs: 0x%X",
TileX(dst_tile),
TileY(dst_tile), trackdirbits);
857 Trackdir src_trackdir = current->path.node.direction;
858 TileIndex src_tile = current->path.node.tile;
863 uint subtype = user->roadtypes;
866 aystar->num_neighbours = 0;
867 DEBUG(npf, 4,
"Expanding: (%d, %d, %d) [%d]",
TileX(src_tile),
TileY(src_tile), src_trackdir, src_tile);
877 if (CheckIgnoreFirstTile(¤t->path)) {
885 }
else if (
ForceReverse(src_tile, src_exitdir, type, subtype)) {
932 DEBUG(npf, 5,
"Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits);
943 AyStarNode *neighbour = &aystar->neighbours[i];
944 neighbour->tile = dst_tile;
945 neighbour->direction = dst_trackdir;
947 neighbour->user_data[NPF_NODE_FLAGS] = current->path.node.user_data[NPF_NODE_FLAGS];
948 NPFFillTrackdirChoice(neighbour, current);
952 aystar->num_neighbours = i;
965 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)
972 _npf_aystar.CalculateH = heuristic_proc;
973 _npf_aystar.EndNodeCheck = target_proc;
975 _npf_aystar.GetNeighbours = NPFFollowTrack;
976 switch (user->type) {
977 default: NOT_REACHED();
978 case TRANSPORT_RAIL: _npf_aystar.CalculateG = NPFRailPathCost;
break;
979 case TRANSPORT_ROAD: _npf_aystar.CalculateG = NPFRoadPathCost;
break;
980 case TRANSPORT_WATER: _npf_aystar.CalculateG = NPFWaterPathCost;
break;
985 start1->user_data[NPF_NODE_FLAGS] = 0;
989 if (start2 != NULL) {
991 start2->user_data[NPF_NODE_FLAGS] = 0;
1004 _npf_aystar.user_path = &result;
1007 _npf_aystar.user_target = target;
1010 _npf_aystar.user_data = user;
1013 r = _npf_aystar.
Main();
1017 if (target != NULL) {
1018 DEBUG(npf, 1,
"Could not find route to tile 0x%X from 0x%X.", target->
dest_coords, start1->tile);
1021 DEBUG(npf, 1,
"Could not find route to a depot from tile 0x%X.", start1->tile);
1036 start1.tile = tile1;
1037 start2.tile = tile2;
1038 start1.direction = trackdir1;
1039 start2.direction = trackdir2;
1041 return NPFRouteInternal(&start1, ignore_start_tile1, (
IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindStationOrTile, NPFCalcStationOrTileHeuristic, user, 0);
1064 start1.tile = tile1;
1065 start2.tile = tile2;
1066 start1.direction = trackdir1;
1067 start2.direction = trackdir2;
1071 return NPFRouteInternal(&start1, ignore_start_tile1, (
IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty,
false, max_penalty);
1074 void InitializeNPF()
1076 static bool first_init =
true;
1081 _npf_aystar.
Clear();
1137 NPFFillWithOrderData(&fstd, v);
1161 NPFFillWithOrderData(&fstd, v);
1181 NPFFillWithOrderData(&fstd, v);
1189 ftd = NPFRouteToStationOrTileTwoWay(v->
tile, trackdir,
false, v->
tile, trackdir_rev,
false, &fstd, &user);
1203 fstd.reserve_path =
false;
1228 start1.direction = trackdir;
1230 RailTypes railtypes = v->compatible_railtypes;
1236 return NPFRouteInternal(&start1,
true, NULL,
false, &fstd,
NPFFindSafeTile, NPFCalcZero, &user, 0,
true).
res_okay;
1245 NPFFillWithOrderData(&fstd, v);
1253 ftd = NPFRouteToStationOrTileTwoWay(v->
tile, trackdir,
false, last->
tile, trackdir_rev,
false, &fstd, &user);
1261 NPFFillWithOrderData(&fstd, v, reserve_track);
1269 if (target != NULL) {
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.
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.
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.
RailType
Enumeration for all possible railtypes.
TrackdirBits m_new_td_bits
the new set of available trackdirs
static RoadStopType GetRoadStopType(TileIndex t)
Get the road stop type of this tile.
Flag for an invalid DiagDirection.
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.
Track
These are used to specify a single track.
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 RoadBits GetRoadBits(TileIndex t, RoadType rt)
Get the present road bits for a specific road type.
Northeast, upper right on your monitor.
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) ...
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.
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.
TrackBits
Bitfield corresponding to Track.
Buses, trucks and trams belong to this class.
Track x-axis, direction north-east.
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...
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...
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.
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.
Trackdir
Enumeration for tracks and directions.
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?
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.
DiagDirection
Enumeration for diagonal directions.
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...
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.
RoadTypes
The different roadtypes we support, but then a bitmask of them.
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).
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.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
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
Track x-axis, direction south-west.
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
Track y-axis, direction north-west.
uint32 npf_rail_curve_penalty
the penalty for curves
static uint TileY(TileIndex tile)
Get the Y component of a tile.
int Main()
This is the function you call to run AyStar.
OwnerByte owner
Which company owns the vehicle?
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.
static TrackdirBits GetDriveableTrackdirBits(TileIndex dst_tile, Trackdir src_trackdir, TransportType type, uint subtype)
Returns the driveable Trackdirs on a tile.
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.
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.
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?
uint32 npf_road_drive_through_penalty
the penalty for going through a drive-through road stop
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
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.
Track y-axis, direction south-east.
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.
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.
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.
Owner
Enum for all companies/owners.
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.
Flag for an invalid trackdir.
static bool NPFGetFlag(const AyStarNode *node, NPFNodeFlag flag)
Returns the current value of the given flag on the given AyStarNode.
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.
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const
Determines the REMAINING length of a platform, starting at (and including) the given tile...
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.
uint32 npf_rail_lastred_penalty
the penalty for when the last signal is red
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
VehicleTypeByte type
Type of vehicle.
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