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);
115 const uint straightTracks = 2 *
min(dx, dy);
120 const uint diagTracks = dx + dy - straightTracks;
137 uint part1 =
TileX(key1) & NPF_HASH_HALFMASK;
138 uint part2 =
TileY(key1) & NPF_HASH_HALFMASK;
142 return ((part1 << NPF_HASH_HALFBITS | part2) + (NPF_HASH_SIZE * key2 /
TRACKDIR_END)) % NPF_HASH_SIZE;
175 DEBUG(npf, 4,
"Calculating H for: (%d, %d). Result: %d",
TileX(current->tile),
TileY(current->tile), dist);
177 if (dist < ftd->best_bird_dist) {
178 ftd->best_bird_dist = dist;
190 if (parent->path.
parent == NULL) {
191 Trackdir trackdir = current->direction;
195 DEBUG(npf, 6,
"Saving trackdir: 0x%X", trackdir);
205 static uint NPFTunnelCost(
AyStarNode *current)
221 static inline uint NPFBridgeCost(
AyStarNode *current)
236 int dx4 = (x2 - x1) / 4;
237 int dy4 = (y2 - y1) / 4;
242 int z1 = GetSlopePixelZ(x1 + dx4, y1 + dy4);
243 int z2 = GetSlopePixelZ(x2 - dx4, y2 - dy4);
255 static uint NPFReservedTrackCost(
AyStarNode *current)
278 #ifndef NO_DEBUG_MESSAGES 306 Trackdir trackdir = current->direction;
308 cost = _trackdir_length[trackdir];
332 cost =
IsTunnel(tile) ? NPFTunnelCost(current) : NPFBridgeCost(current);
368 cost += NPFSlopeCost(current);
377 DEBUG(npf, 4,
"Calculating G for: (%d, %d). Result: %d",
TileX(current->tile),
TileY(current->tile), cost);
386 Trackdir trackdir = current->direction;
394 cost =
IsTunnel(tile) ? NPFTunnelCost(current) : NPFBridgeCost(current);
398 cost = _trackdir_length[trackdir];
424 while (ft.
Follow(t, td)) {
465 if (!IsPbsSignal(sigtype)) {
502 new_node.path.node = *current;
508 cost += NPFSlopeCost(current);
526 cost += NPFReservedTrackCost(current);
529 DEBUG(npf, 4,
"Calculating G for: (%d, %d). Result: %d",
TileX(current->tile),
TileY(current->tile), cost);
598 bool first_run =
true;
599 for (; start != end; start = start->
parent) {
620 ftd->best_path_dist = current->g;
621 ftd->best_bird_dist = 0;
622 ftd->node = current->path.node;
623 ftd->res_okay =
false;
630 ftd->node = target->node;
639 ftd->node.tile = end_tile;
655 ftd->res_okay =
true;
787 if (!
HasBit(user->railtypes, rail_type))
return false;
830 DEBUG(npf, 4,
"Next node: (%d, %d) [%d], possible trackdirs: 0x%X",
TileX(dst_tile),
TileY(dst_tile), dst_tile, trackdirbits);
838 DEBUG(npf, 6,
"After filtering: (%d, %d), possible trackdirs: 0x%X",
TileX(dst_tile),
TileY(dst_tile), trackdirbits);
854 Trackdir src_trackdir = current->path.node.direction;
855 TileIndex src_tile = current->path.node.tile;
865 uint subtype = user->roadtypes;
868 aystar->num_neighbours = 0;
869 DEBUG(npf, 4,
"Expanding: (%d, %d, %d) [%d]",
TileX(src_tile),
TileY(src_tile), src_trackdir, src_tile);
876 if (ignore_src_tile) {
884 }
else if (
ForceReverse(src_tile, src_exitdir, type, subtype)) {
905 if (trackdirbits == 0) {
929 while (trackdirbits != 0) {
931 DEBUG(npf, 5,
"Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits);
942 AyStarNode *neighbour = &aystar->neighbours[i];
943 neighbour->tile = dst_tile;
944 neighbour->direction = dst_trackdir;
946 neighbour->user_data[NPF_NODE_FLAGS] = current->path.node.user_data[NPF_NODE_FLAGS];
947 NPFFillTrackdirChoice(neighbour, current);
951 aystar->num_neighbours = i;
970 _npf_aystar.CalculateH = heuristic_proc;
971 _npf_aystar.EndNodeCheck = target_proc;
973 _npf_aystar.GetNeighbours = NPFFollowTrack;
974 switch (user->type) {
975 default: NOT_REACHED();
976 case TRANSPORT_RAIL: _npf_aystar.CalculateG = NPFRailPathCost;
break;
977 case TRANSPORT_ROAD: _npf_aystar.CalculateG = NPFRoadPathCost;
break;
978 case TRANSPORT_WATER: _npf_aystar.CalculateG = NPFWaterPathCost;
break;
983 start1->user_data[NPF_NODE_FLAGS] = 0;
987 if (start2 != NULL) {
989 start2->user_data[NPF_NODE_FLAGS] = 0;
1002 _npf_aystar.user_path = &result;
1005 _npf_aystar.user_target = target;
1008 _npf_aystar.user_data = user;
1011 r = _npf_aystar.
Main();
1015 if (target != NULL) {
1016 DEBUG(npf, 1,
"Could not find route to tile 0x%X from 0x%X.", target->
dest_coords, start1->tile);
1019 DEBUG(npf, 1,
"Could not find route to a depot from tile 0x%X.", start1->tile);
1034 start1.tile = tile1;
1035 start2.tile = tile2;
1036 start1.direction = trackdir1;
1037 start2.direction = trackdir2;
1039 return NPFRouteInternal(&start1, ignore_start_tile1, (
IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindStationOrTile, NPFCalcStationOrTileHeuristic, user, 0);
1062 start1.tile = tile1;
1063 start2.tile = tile2;
1064 start1.direction = trackdir1;
1065 start2.direction = trackdir2;
1069 return NPFRouteInternal(&start1, ignore_start_tile1, (
IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty);
1072 void InitializeNPF()
1074 static bool first_init =
true;
1079 _npf_aystar.
Clear();
1135 NPFFillWithOrderData(&fstd, v);
1164 NPFFillWithOrderData(&fstd, v);
1183 NPFFillWithOrderData(&fstd, v);
1191 ftd = NPFRouteToStationOrTileTwoWay(v->
tile, trackdir,
false, v->
tile, trackdir_rev,
false, &fstd, &user);
1205 fstd.reserve_path =
false;
1230 start1.direction = trackdir;
1232 RailTypes railtypes = v->compatible_railtypes;
1238 return NPFRouteInternal(&start1,
true, NULL,
false, &fstd,
NPFFindSafeTile, NPFCalcZero, &user, 0,
true).
res_okay;
1247 NPFFillWithOrderData(&fstd, v);
1255 ftd = NPFRouteToStationOrTileTwoWay(v->
tile, trackdir,
false, last->
tile, trackdir_rev,
false, &fstd, &user);
1263 NPFFillWithOrderData(&fstd, v, reserve_track);
1271 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...
RailTypes
The different roadtypes we support, but then a bitmask of them.
Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
Finds the best path for given ship using NPF.
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.
Track NPFTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, struct PBSTileInfo *target)
Finds the best path for given train using NPF.
static bool IsValidTrackdir(Trackdir trackdir)
Checks if a Trackdir is valid for non-road vehicles.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give 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.
int32 AyStar_EndNodeCheck(AyStar *aystar, OpenListNode *current)
Check whether the end-tile is found.
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.
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?
TileIndex tile
Current tile index.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
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.
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).
Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found)
Finds the best path for given road vehicle using NPF.
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).
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
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.
Flag for an invalid track.
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 uint8 FindFirstBit2x64(const int value)
Finds the position of the first non-zero bit in an integer.
static Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
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.
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.
static int32 NPFFindSafeTile(AyStar *as, OpenListNode *current)
Find any safe and free tile.
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