|
@@ -2,13 +2,13 @@
|
|
|
#include "openttd.h"
|
|
|
#include "map.h"
|
|
|
#include "tile.h"
|
|
|
#include "pathfind.h"
|
|
|
|
|
|
// remember which tiles we have already visited so we don't visit them again.
|
|
|
static bool TPFSetTileBit(TrackPathFinder *tpf, uint tile, int dir)
|
|
|
static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir)
|
|
|
{
|
|
|
uint hash, val, offs;
|
|
|
TrackPathFinderLink *link, *new_link;
|
|
|
uint bits = 1 << dir;
|
|
|
|
|
|
if (tpf->disable_tile_hash)
|
|
@@ -117,17 +117,17 @@ static const byte _otherdir_mask[4] = {
|
|
|
0,
|
|
|
0x5,
|
|
|
0x2A,
|
|
|
};
|
|
|
|
|
|
#ifdef DEBUG_TILE_PUSH
|
|
|
extern void dbg_push_tile(uint tile, int track);
|
|
|
extern void dbg_push_tile(TileIndex tile, int track);
|
|
|
extern void dbg_pop_tile();
|
|
|
#endif
|
|
|
|
|
|
static void TPFMode2(TrackPathFinder *tpf, uint tile, int direction)
|
|
|
static void TPFMode2(TrackPathFinder *tpf, TileIndex tile, int direction)
|
|
|
{
|
|
|
uint bits;
|
|
|
int i;
|
|
|
RememberData rd;
|
|
|
int owner = -1;
|
|
|
|
|
@@ -208,13 +208,13 @@ continue_here:;
|
|
|
|
|
|
static const int8 _get_tunlen_inc[5] = { -16, 0, 16, 0, -16 };
|
|
|
|
|
|
/* Returns the end tile and the length of a tunnel. The length does not
|
|
|
* include the starting tile (entry), it does include the end tile (exit).
|
|
|
*/
|
|
|
FindLengthOfTunnelResult FindLengthOfTunnel(uint tile, int direction)
|
|
|
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, int direction)
|
|
|
{
|
|
|
FindLengthOfTunnelResult flotr;
|
|
|
int x,y;
|
|
|
byte z;
|
|
|
|
|
|
flotr.length = 0;
|
|
@@ -243,13 +243,14 @@ FindLengthOfTunnelResult FindLengthOfTun
|
|
|
flotr.tile = tile;
|
|
|
return flotr;
|
|
|
}
|
|
|
|
|
|
static const uint16 _tpfmode1_and[4] = { 0x1009, 0x16, 0x520, 0x2A00 };
|
|
|
|
|
|
static uint SkipToEndOfTunnel(TrackPathFinder *tpf, uint tile, int direction) {
|
|
|
static uint SkipToEndOfTunnel(TrackPathFinder *tpf, TileIndex tile, int direction)
|
|
|
{
|
|
|
FindLengthOfTunnelResult flotr;
|
|
|
TPFSetTileBit(tpf, tile, 14);
|
|
|
flotr = FindLengthOfTunnel(tile, direction);
|
|
|
tpf->rd.cur_length += flotr.length;
|
|
|
TPFSetTileBit(tpf, flotr.tile, 14);
|
|
|
return flotr.tile;
|
|
@@ -272,18 +273,18 @@ 16,24,24,26,24,28,28,30,
|
|
|
0,32,32,34,32,36,36,38,
|
|
|
32,40,40,42,40,44,44,46,
|
|
|
32,48,48,50,48,52,52,54,
|
|
|
48,56,56,58,56,60,60,62,
|
|
|
};
|
|
|
|
|
|
static void TPFMode1(TrackPathFinder *tpf, uint tile, int direction)
|
|
|
static void TPFMode1(TrackPathFinder *tpf, TileIndex tile, int direction)
|
|
|
{
|
|
|
uint bits;
|
|
|
int i;
|
|
|
RememberData rd;
|
|
|
uint tile_org = tile;
|
|
|
TileIndex tile_org = tile;
|
|
|
|
|
|
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0) == 0) {
|
|
|
if ((_map5[tile] & 3) != direction || ((_map5[tile]>>2)&3) != tpf->tracktype)
|
|
|
return;
|
|
|
tile = SkipToEndOfTunnel(tpf, tile, direction);
|
|
|
}
|
|
@@ -367,13 +368,13 @@ static void TPFMode1(TrackPathFinder *tp
|
|
|
TPFMode1(tpf, tile, _tpf_new_direction[tpf->the_dir]);
|
|
|
}
|
|
|
tpf->rd = rd;
|
|
|
} while (bits != 0);
|
|
|
}
|
|
|
|
|
|
void FollowTrack(uint tile, uint16 flags, byte direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
|
|
|
void FollowTrack(TileIndex tile, uint16 flags, byte direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
|
|
|
{
|
|
|
TrackPathFinder tpf;
|
|
|
|
|
|
assert(direction < 4);
|
|
|
|
|
|
/* initialize path finder variables */
|
|
@@ -510,13 +511,13 @@ static inline void HeapifyDown(NewTrackP
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// mark a tile as visited and store the length of the path.
|
|
|
// if we already had a better path to this tile, return false.
|
|
|
// otherwise return true.
|
|
|
static bool NtpVisit(NewTrackPathFinder *tpf, uint tile, uint dir, uint length)
|
|
|
static bool NtpVisit(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint length)
|
|
|
{
|
|
|
uint hash,head;
|
|
|
HashLink *link, *new_link;
|
|
|
|
|
|
assert(length < 1024);
|
|
|
|
|
@@ -584,13 +585,13 @@ static bool NtpVisit(NewTrackPathFinder
|
|
|
new_link->next = 0xFFFF;
|
|
|
|
|
|
link->next = NTP_GET_LINK_OFFS(tpf, new_link);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
static bool NtpCheck(NewTrackPathFinder *tpf, uint tile, uint dir, uint length)
|
|
|
static bool NtpCheck(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint length)
|
|
|
{
|
|
|
uint hash,head,offs;
|
|
|
HashLink *link;
|
|
|
|
|
|
hash = PATHFIND_HASH_TILE(tile);
|
|
|
head=tpf->hash_head[hash];
|
|
@@ -614,13 +615,13 @@ static bool NtpCheck(NewTrackPathFinder
|
|
|
assert(offs != 0xffff);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// new more optimized pathfinder for trains...
|
|
|
static void NTPEnum(NewTrackPathFinder *tpf, uint tile, uint direction)
|
|
|
static void NTPEnum(NewTrackPathFinder *tpf, TileIndex tile, uint direction)
|
|
|
{
|
|
|
uint bits, tile_org;
|
|
|
int i;
|
|
|
StackedItem si;
|
|
|
FindLengthOfTunnelResult flotr;
|
|
|
|
|
@@ -741,13 +742,13 @@ popnext:
|
|
|
direction = _tpf_new_direction[si.track];
|
|
|
goto restart;
|
|
|
}
|
|
|
|
|
|
|
|
|
// new pathfinder for trains. better and faster.
|
|
|
void NewTrainPathfind(uint tile, byte direction, TPFEnumProc *enum_proc, void *data, byte *cache)
|
|
|
void NewTrainPathfind(TileIndex tile, byte direction, TPFEnumProc *enum_proc, void *data, byte *cache)
|
|
|
{
|
|
|
if (!_patches.new_pathfinding) {
|
|
|
FollowTrack(tile, 0x3000 | TRANSPORT_RAIL, direction, enum_proc, NULL, data);
|
|
|
} else {
|
|
|
NewTrackPathFinder tpf;
|
|
|
tpf.userdata = data;
|