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;
152 pfs.best_bird_dist = UINT_MAX;
153 pfs.best_length = UINT_MAX;
158 if (pfs.best_bird_dist != 0) {
160 if (pfs.best_bird_dist > best_bird_dist)
goto bad;
161 if (pfs.best_bird_dist < best_bird_dist)
goto good;
163 if (pfs.best_length > best_length)
goto bad;
164 if (pfs.best_length < best_length)
goto good;
169 uint r =
GB(Random(), 0, 8);
172 if (r <= 127)
goto bad;
176 best_bird_dist = pfs.best_bird_dist;
177 best_length = pfs.best_length;
183 return best_bird_dist;
204 uint rev_dist = UINT_MAX;
210 if (
HasTrack(rev_tracks, cur_track)) {
211 rev_dist = FindShipTrack(v, tile2, rev_enterdir,
TrackToTrackBits(cur_track), tile, &track);
212 if (rev_dist != UINT_MAX) rev_dist++;
216 uint dist = FindShipTrack(v, tile, enterdir, tracks, 0, &track);
220 if (dist <= rev_dist)
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.
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
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 given tiletype.
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)
Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
Finds the best track to choose on the next tile and returns INVALID_TRACK when it is better to revers...
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.
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
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.
static bool HasTrack(TileIndex tile, Track track)
Returns whether the given track is present on the given tile.
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.
#define TILE_ADD(x, y)
Adds to tiles together.
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.