12 #include "../../stdafx.h" 13 #include "../../tunnelbridge_map.h" 14 #include "../../tunnelbridge.h" 15 #include "../../ship.h" 16 #include "../../core/random_func.hpp" 18 #include "../../safeguards.h" 23 Track last_choosen_track;
38 if (tile == pfs->dest_coords) {
39 pfs->best_bird_dist = 0;
41 pfs->best_length =
minu(pfs->best_length, length);
46 if (tile != pfs->skiptile) {
61 if (dir == direction) {
78 if (++tpf->rd.cur_length > 50)
return;
85 bool only_one_track =
true;
92 if (!only_one_track && track != tpf->rd.last_choosen_track) {
93 if (++tpf->rd.depth > 4) {
97 tpf->rd.last_choosen_track = track;
102 if (!ShipTrackFollower(tile, tpf, tpf->rd.cur_length)) {
115 tpf->rd.cur_length = 0;
119 ShipTrackFollower(tile, tpf, 0);
120 TPFModeShip(tpf, tile, direction);
139 uint best_bird_dist = 0;
140 uint best_length = 0;
144 pfs.skiptile = skiptile;
151 pfs.best_bird_dist = UINT_MAX;
152 pfs.best_length = UINT_MAX;
157 if (pfs.best_bird_dist != 0) {
159 if (pfs.best_bird_dist > best_bird_dist)
goto bad;
160 if (pfs.best_bird_dist < best_bird_dist)
goto good;
162 if (pfs.best_length > best_length)
goto bad;
163 if (pfs.best_length < best_length)
goto good;
168 uint r =
GB(Random(), 0, 8);
171 if (r <= 127)
goto bad;
175 best_bird_dist = pfs.best_bird_dist;
176 best_length = pfs.best_length;
182 return best_bird_dist;
201 uint distr = UINT_MAX;
203 distr = FindShipTrack(v, tile2,
ReverseDiagDir(enterdir), b, tile, &track);
204 if (distr != UINT_MAX) distr++;
208 uint dist = FindShipTrack(v, tile, enterdir, tracks, 0, &track);
212 if (dist <= distr)
return track;
static uint minu(const uint a, const uint b)
Returns the minimum of two unsigned integers.
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
DirectionByte direction
facing
Flag for an invalid DiagDirection.
Track
These are used to specify a single track.
TileIndex dest_tile
Heading for this tile.
static uint TileX(TileIndex tile)
Get the X component of a tile.
static Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
Maps a track and an (4-way) dir to the trackdir that represents the track with the entry in the given...
Northeast, upper right on your monitor.
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
static const DiagDirection _ship_search_directions[6][4]
Directions to search towards given track bits and the ship's enter direction.
TrackBits
Bitfield corresponding to Track.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
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)
Trackdir
Enumeration for tracks and directions.
Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
returns the track to choose on the next tile, or -1 when it's better to reverse.
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
DiagDirection
Enumeration for diagonal directions.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
All ships have this type.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
static TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction...
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Flag for an invalid track.
Tunnel entry/exit and bridge heads.
static Track RemoveFirstTrack(TrackBits *tracks)
Removes first Track from TrackBits and returns it.
uint32 TileIndex
The index/ID of a Tile.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static const byte _pick_shiptrack_table[6]
Track to "direction (& 3)" mapping.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles plus the Manhattan distance...
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
#define TILE_ADD(x, y)
Adds to tiles together.
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.