author | rubidium |
Fri, 18 Apr 2008 23:33:51 +0000 | |
branch | noai |
changeset 10249 | 58810805030e |
parent 10181 | 54df587fef5d |
child 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9505 | 3 |
/** @file pathfind.cpp */ |
4 |
||
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1209
diff
changeset
|
6 |
#include "openttd.h" |
3234
986c30171e92
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3184
diff
changeset
|
7 |
#include "bridge_map.h" |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3894
diff
changeset
|
8 |
#include "station_map.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
9 |
#include "tile_cmd.h" |
9599 | 10 |
#include "landscape.h" |
0 | 11 |
#include "pathfind.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
12 |
#include "rail_type.h" |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
13 |
#include "debug.h" |
3154 | 14 |
#include "tunnel_map.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
15 |
#include "settings_type.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
16 |
#include "tunnelbridge_map.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
17 |
#include "core/random_func.hpp" |
10181
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
9869
diff
changeset
|
18 |
#include "core/alloc_type.hpp" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
19 |
#include "tunnelbridge.h" |
0 | 20 |
|
9505 | 21 |
/* remember which tiles we have already visited so we don't visit them again. */ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
22 |
static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir) |
0 | 23 |
{ |
24 |
uint hash, val, offs; |
|
25 |
TrackPathFinderLink *link, *new_link; |
|
26 |
uint bits = 1 << dir; |
|
27 |
||
28 |
if (tpf->disable_tile_hash) |
|
29 |
return true; |
|
30 |
||
31 |
hash = PATHFIND_HASH_TILE(tile); |
|
32 |
||
33 |
val = tpf->hash_head[hash]; |
|
34 |
||
35 |
if (val == 0) { |
|
36 |
/* unused hash entry, set the appropriate bit in it and return true |
|
37 |
* to indicate that a bit was set. */ |
|
38 |
tpf->hash_head[hash] = bits; |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
39 |
tpf->hash_tile[hash] = tile; |
0 | 40 |
return true; |
41 |
} else if (!(val & 0x8000)) { |
|
42 |
/* single tile */ |
|
43 |
||
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
44 |
if (tile == tpf->hash_tile[hash]) { |
0 | 45 |
/* found another bit for the same tile, |
46 |
* check if this bit is already set, if so, return false */ |
|
47 |
if (val & bits) |
|
48 |
return false; |
|
49 |
||
50 |
/* otherwise set the bit and return true to indicate that the bit |
|
51 |
* was set */ |
|
52 |
tpf->hash_head[hash] = val | bits; |
|
53 |
return true; |
|
54 |
} else { |
|
55 |
/* two tiles with the same hash, need to make a link */ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
56 |
|
0 | 57 |
/* allocate a link. if out of links, handle this by returning |
58 |
* that a tile was already visisted. */ |
|
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
59 |
if (tpf->num_links_left == 0) { |
0 | 60 |
return false; |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
61 |
} |
0 | 62 |
tpf->num_links_left--; |
63 |
link = tpf->new_link++; |
|
64 |
||
65 |
/* move the data that was previously in the hash_??? variables |
|
66 |
* to the link struct, and let the hash variables point to the link */ |
|
67 |
link->tile = tpf->hash_tile[hash]; |
|
68 |
tpf->hash_tile[hash] = PATHFIND_GET_LINK_OFFS(tpf, link); |
|
69 |
||
70 |
link->flags = tpf->hash_head[hash]; |
|
9505 | 71 |
tpf->hash_head[hash] = 0xFFFF; // multi link |
0 | 72 |
|
73 |
link->next = 0xFFFF; |
|
74 |
} |
|
75 |
} else { |
|
76 |
/* a linked list of many tiles, |
|
77 |
* find the one corresponding to the tile, if it exists. |
|
78 |
* otherwise make a new link */ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
79 |
|
0 | 80 |
offs = tpf->hash_tile[hash]; |
81 |
do { |
|
82 |
link = PATHFIND_GET_LINK_PTR(tpf, offs); |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
83 |
if (tile == link->tile) { |
0 | 84 |
/* found the tile in the link list, |
85 |
* check if the bit was alrady set, if so return false to indicate that the |
|
86 |
* bit was already set */ |
|
87 |
if (link->flags & bits) |
|
88 |
return false; |
|
89 |
link->flags |= bits; |
|
90 |
return true; |
|
91 |
} |
|
92 |
} while ((offs=link->next) != 0xFFFF); |
|
93 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
94 |
|
0 | 95 |
/* get here if we need to add a new link to link, |
96 |
* first, allocate a new link, in the same way as before */ |
|
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
97 |
if (tpf->num_links_left == 0) { |
0 | 98 |
return false; |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
99 |
} |
0 | 100 |
tpf->num_links_left--; |
101 |
new_link = tpf->new_link++; |
|
102 |
||
103 |
/* then fill the link with the new info, and establish a ptr from the old |
|
104 |
* link to the new one */ |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
105 |
new_link->tile = tile; |
0 | 106 |
new_link->flags = bits; |
107 |
new_link->next = 0xFFFF; |
|
108 |
||
109 |
link->next = PATHFIND_GET_LINK_OFFS(tpf, new_link); |
|
110 |
return true; |
|
111 |
} |
|
112 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
113 |
static void TPFModeShip(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) |
0 | 114 |
{ |
115 |
RememberData rd; |
|
747
e795750b96de
(svn r1203) -Fix: the pathfinder no longer sees rail with an other owner as a
truelight
parents:
679
diff
changeset
|
116 |
|
3618
dc8cebe5ffd3
(svn r4515) -Codechange: TPFMode2 is currently only used for TRANSPORT_WATER. So remove all stuff that deals with other transport types and assert TRANSPORT_WATER
celestar
parents:
3420
diff
changeset
|
117 |
assert(tpf->tracktype == TRANSPORT_WATER); |
0 | 118 |
|
9505 | 119 |
/* This addition will sometimes overflow by a single tile. |
120 |
* The use of TILE_MASK here makes sure that we still point at a valid |
|
121 |
* tile, and then this tile will be in the sentinel row/col, so GetTileTrackStatus will fail. */ |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4406
diff
changeset
|
122 |
tile = TILE_MASK(tile + TileOffsByDiagDir(direction)); |
0 | 123 |
|
124 |
if (++tpf->rd.cur_length > 50) |
|
125 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
126 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
127 |
TrackBits bits = TrackStatusToTrackBits(GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type)) & DiagdirReachesTracks(direction); |
9732 | 128 |
if (bits == TRACK_BIT_NONE) return; |
0 | 129 |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
913
diff
changeset
|
130 |
assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY()); |
0 | 131 |
|
9732 | 132 |
bool only_one_track = true; |
0 | 133 |
do { |
9732 | 134 |
Track track = RemoveFirstTrack(&bits); |
135 |
if (bits != TRACK_BIT_NONE) only_one_track = false; |
|
0 | 136 |
rd = tpf->rd; |
137 |
||
9505 | 138 |
/* Change direction 4 times only */ |
9732 | 139 |
if (!only_one_track && track != tpf->rd.last_choosen_track) { |
2952 | 140 |
if (++tpf->rd.depth > 4) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
141 |
tpf->rd = rd; |
0 | 142 |
return; |
143 |
} |
|
9732 | 144 |
tpf->rd.last_choosen_track = track; |
0 | 145 |
} |
146 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
147 |
tpf->the_dir = TrackEnterdirToTrackdir(track, direction); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
148 |
|
9732 | 149 |
if (!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length)) { |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
150 |
TPFModeShip(tpf, tile, TrackdirToExitdir(tpf->the_dir)); |
0 | 151 |
} |
152 |
||
153 |
tpf->rd = rd; |
|
9732 | 154 |
} while (bits != TRACK_BIT_NONE); |
0 | 155 |
|
156 |
} |
|
157 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
158 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
159 |
* Checks if any vehicle can enter/leave tile in given diagdir |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
160 |
* Checks only for rail/road depots and road non-drivethrough stations |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
161 |
* @param tile tile to check |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
162 |
* @param side side of tile we are trying to leave/enter |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
163 |
* @param tracktype type of transport |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
164 |
* @pre tile has trackbit at that diagdir |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
165 |
* @return true iff vehicle can enter/leve the tile in given side |
22 | 166 |
*/ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
167 |
static inline bool CanAccessTileInDir(TileIndex tile, DiagDirection side, TransportType tracktype) |
0 | 168 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
169 |
if (tracktype == TRANSPORT_RAIL) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
170 |
/* depot from wrong side */ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
171 |
if (IsRailDepotTile(tile) && GetRailDepotDirection(tile) != side) return false; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
172 |
} else if (tracktype == TRANSPORT_ROAD) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
173 |
/* depot from wrong side */ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
174 |
if (IsRoadDepotTile(tile) && GetRoadDepotDirection(tile) != side) return false; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
175 |
/* non-driverthrough road station from wrong side */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
176 |
if (IsStandardRoadStopTile(tile) && GetRoadStopDir(tile) != side) return false; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
177 |
} |
0 | 178 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
179 |
return true; |
0 | 180 |
} |
181 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
182 |
static void TPFModeNormal(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
183 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
184 |
const TileIndex tile_org = tile; |
0 | 185 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
186 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
187 |
/* wrong track type */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
188 |
if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) return; |
5668
76262aa5075d
(svn r7620) -Fix: [OPF] signal update was incorrectly propagated:
KUDr
parents:
5573
diff
changeset
|
189 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
190 |
DiagDirection dir = GetTunnelBridgeDirection(tile); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
191 |
/* entering tunnel / bridge? */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
192 |
if (dir == direction) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
193 |
TileIndex endtile = GetOtherTunnelBridgeEnd(tile); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
194 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
195 |
tpf->rd.cur_length += GetTunnelBridgeLength(tile, endtile) + 1; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
196 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
197 |
TPFSetTileBit(tpf, tile, 14); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
198 |
TPFSetTileBit(tpf, endtile, 14); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
199 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
200 |
tile = endtile; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
201 |
} else { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
202 |
/* leaving tunnel / bridge? */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
203 |
if (ReverseDiagDir(dir) != direction) return; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
204 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
205 |
} else { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
206 |
/* can we leave tile in this dir? */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
207 |
if (!CanAccessTileInDir(tile, direction, tpf->tracktype)) return; |
752
df3e096dd9db
(svn r1208) -Fix: the owner-check introduced in r1203 now also works correctly for
truelight
parents:
747
diff
changeset
|
208 |
} |
747
e795750b96de
(svn r1203) -Fix: the pathfinder no longer sees rail with an other owner as a
truelight
parents:
679
diff
changeset
|
209 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
210 |
tile += TileOffsByDiagDir(direction); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
211 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
212 |
/* can we enter tile in this dir? */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
213 |
if (!CanAccessTileInDir(tile, ReverseDiagDir(direction), tpf->tracktype)) return; |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3894
diff
changeset
|
214 |
|
5708
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
215 |
/* Check if the new tile is a tunnel or bridge head and that the direction |
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
216 |
* and transport type match */ |
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
217 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
218 |
if (GetTunnelBridgeDirection(tile) != direction || |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
219 |
GetTunnelBridgeTransportType(tile) != tpf->tracktype) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
220 |
return; |
5708
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
221 |
} |
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
222 |
} |
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
223 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
224 |
TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type)); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
225 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
226 |
/* Check in case of rail if the owner is the same */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
227 |
if (tpf->tracktype == TRANSPORT_RAIL) { |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
228 |
if (trackdirbits != TRACKDIR_BIT_NONE && TrackStatusToTrackdirBits(GetTileTrackStatus(tile_org, TRANSPORT_RAIL, 0)) != TRACKDIR_BIT_NONE) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
229 |
if (GetTileOwner(tile_org) != GetTileOwner(tile)) return; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
230 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
231 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
232 |
|
0 | 233 |
tpf->rd.cur_length++; |
234 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
235 |
trackdirbits &= DiagdirReachesTrackdirs(direction); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
236 |
TrackBits bits = TrackdirBitsToTrackBits(trackdirbits); |
0 | 237 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
238 |
if (bits != TRACK_BIT_NONE) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9629
diff
changeset
|
239 |
if (!tpf->disable_tile_hash || (tpf->rd.cur_length <= 64 && (KillFirstBit(bits) == 0 || ++tpf->rd.depth <= 7))) { |
0 | 240 |
do { |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
241 |
Track track = RemoveFirstTrack(&bits); |
0 | 242 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
243 |
tpf->the_dir = TrackEnterdirToTrackdir(track, direction); |
9629 | 244 |
RememberData rd = tpf->rd; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
245 |
|
9732 | 246 |
/* make sure we are not leaving from invalid side */ |
247 |
if (TPFSetTileBit(tpf, tile, tpf->the_dir) && CanAccessTileInDir(tile, TrackdirToExitdir(tpf->the_dir), tpf->tracktype) && |
|
248 |
!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length) ) { |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
249 |
TPFModeNormal(tpf, tile, TrackdirToExitdir(tpf->the_dir)); |
0 | 250 |
} |
251 |
tpf->rd = rd; |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
252 |
} while (bits != TRACK_BIT_NONE); |
0 | 253 |
} |
254 |
} |
|
9629 | 255 |
} |
256 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
257 |
void FollowTrack(TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) |
0 | 258 |
{ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
259 |
assert(IsValidDiagDirection(direction)); |
0 | 260 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
261 |
SmallStackSafeStackAlloc<TrackPathFinder, 1> tpf; |
0 | 262 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
263 |
/* initialize path finder variables */ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
264 |
tpf->userdata = data; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
265 |
tpf->enum_proc = enum_proc; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
266 |
tpf->new_link = tpf->links; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
267 |
tpf->num_links_left = lengthof(tpf->links); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
268 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
269 |
tpf->rd.cur_length = 0; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
270 |
tpf->rd.depth = 0; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
271 |
tpf->rd.last_choosen_track = INVALID_TRACK; |
0 | 272 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
273 |
tpf->disable_tile_hash = (flags & PATHFIND_FLAGS_DISABLE_TILE_HASH) != 0; |
0 | 274 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
275 |
tpf->tracktype = tt; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
276 |
tpf->sub_type = sub_type; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
277 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
278 |
if ((flags & PATHFIND_FLAGS_SHIP_MODE) != 0) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
279 |
tpf->enum_proc(tile, data, INVALID_TRACKDIR, 0); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
280 |
TPFModeShip(tpf, tile, direction); |
0 | 281 |
} else { |
282 |
/* clear the hash_heads */ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
283 |
memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
284 |
TPFModeNormal(tpf, tile, direction); |
0 | 285 |
} |
286 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
287 |
if (after_proc != NULL) after_proc(tpf); |
0 | 288 |
} |
289 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
290 |
struct StackedItem { |
0 | 291 |
TileIndex tile; |
9505 | 292 |
uint16 cur_length; ///< This is the current length to this tile. |
293 |
uint16 priority; ///< This is the current length + estimated length to the goal. |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
294 |
TrackdirByte track; |
0 | 295 |
byte depth; |
296 |
byte state; |
|
297 |
byte first_track; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
298 |
}; |
0 | 299 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
300 |
struct HashLink { |
0 | 301 |
TileIndex tile; |
302 |
uint16 typelength; |
|
303 |
uint16 next; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
304 |
}; |
0 | 305 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
306 |
struct NewTrackPathFinder { |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
307 |
NTPEnumProc *enum_proc; |
0 | 308 |
void *userdata; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
309 |
TileIndex dest; |
0 | 310 |
|
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3267
diff
changeset
|
311 |
TransportType tracktype; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
312 |
RailTypes railtypes; |
0 | 313 |
uint maxlength; |
314 |
||
315 |
HashLink *new_link; |
|
316 |
uint num_links_left; |
|
317 |
||
979
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
318 |
uint nstack; |
9505 | 319 |
StackedItem stack[256]; ///< priority queue of stacked items |
0 | 320 |
|
9505 | 321 |
uint16 hash_head[0x400]; ///< hash heads. 0 means unused. 0xFFFC = length, 0x3 = dir |
322 |
TileIndex hash_tile[0x400]; ///< tiles. or links. |
|
0 | 323 |
|
9505 | 324 |
HashLink links[0x400]; ///< hash links |
0 | 325 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
326 |
}; |
0 | 327 |
#define NTP_GET_LINK_OFFS(tpf, link) ((byte*)(link) - (byte*)tpf->links) |
328 |
#define NTP_GET_LINK_PTR(tpf, link_offs) (HashLink*)((byte*)tpf->links + (link_offs)) |
|
329 |
||
330 |
#define ARR(i) tpf->stack[(i)-1] |
|
331 |
||
9505 | 332 |
/** called after a new element was added in the queue at the last index. |
333 |
* move it down to the proper position */ |
|
536 | 334 |
static inline void HeapifyUp(NewTrackPathFinder *tpf) |
0 | 335 |
{ |
336 |
StackedItem si; |
|
337 |
int i = ++tpf->nstack; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
338 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
339 |
while (i != 1 && ARR(i).priority < ARR(i>>1).priority) { |
9505 | 340 |
/* the child element is larger than the parent item. |
341 |
* swap the child item and the parent item. */ |
|
342 |
si = ARR(i); ARR(i) = ARR(i >> 1); ARR(i >> 1) = si; |
|
343 |
i >>= 1; |
|
0 | 344 |
} |
345 |
} |
|
346 |
||
9505 | 347 |
/** called after the element 0 was eaten. fill it with a new element */ |
536 | 348 |
static inline void HeapifyDown(NewTrackPathFinder *tpf) |
0 | 349 |
{ |
350 |
StackedItem si; |
|
351 |
int i = 1, j; |
|
979
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
352 |
int n; |
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
353 |
|
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
354 |
assert(tpf->nstack > 0); |
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
355 |
n = --tpf->nstack; |
0 | 356 |
|
357 |
if (n == 0) return; // heap is empty so nothing to do? |
|
358 |
||
9505 | 359 |
/* copy the last item to index 0. we use it as base for heapify. */ |
360 |
ARR(1) = ARR(n + 1); |
|
0 | 361 |
|
9505 | 362 |
while ((j = i * 2) <= n) { |
363 |
/* figure out which is smaller of the children. */ |
|
364 |
if (j != n && ARR(j).priority > ARR(j + 1).priority) |
|
0 | 365 |
j++; // right item is smaller |
366 |
||
367 |
assert(i <= n && j <= n); |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
368 |
if (ARR(i).priority <= ARR(j).priority) |
0 | 369 |
break; // base elem smaller than smallest, done! |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
370 |
|
9505 | 371 |
/* swap parent with the child */ |
0 | 372 |
si = ARR(i); ARR(i) = ARR(j); ARR(j) = si; |
373 |
i = j; |
|
374 |
} |
|
375 |
} |
|
376 |
||
9505 | 377 |
/** mark a tile as visited and store the length of the path. |
378 |
* if we already had a better path to this tile, return false. |
|
379 |
* otherwise return true. */ |
|
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3132
diff
changeset
|
380 |
static bool NtpVisit(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection dir, uint length) |
0 | 381 |
{ |
382 |
uint hash,head; |
|
383 |
HashLink *link, *new_link; |
|
384 |
||
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
385 |
assert(length < 16384-1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
386 |
|
0 | 387 |
hash = PATHFIND_HASH_TILE(tile); |
388 |
||
9505 | 389 |
/* never visited before? */ |
0 | 390 |
if ((head=tpf->hash_head[hash]) == 0) { |
391 |
tpf->hash_tile[hash] = tile; |
|
392 |
tpf->hash_head[hash] = dir | (length << 2); |
|
393 |
return true; |
|
394 |
} |
|
395 |
||
396 |
if (head != 0xffff) { |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
397 |
if (tile == tpf->hash_tile[hash] && (head & 0x3) == (uint)dir) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
398 |
|
9505 | 399 |
/* longer length */ |
0 | 400 |
if (length >= (head >> 2)) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
401 |
|
0 | 402 |
tpf->hash_head[hash] = dir | (length << 2); |
403 |
return true; |
|
404 |
} |
|
9505 | 405 |
/* two tiles with the same hash, need to make a link |
406 |
* allocate a link. if out of links, handle this by returning |
|
407 |
* that a tile was already visisted. */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
408 |
if (tpf->num_links_left == 0) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5028
diff
changeset
|
409 |
DEBUG(ntp, 1, "No links left"); |
0 | 410 |
return false; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
411 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
412 |
|
0 | 413 |
tpf->num_links_left--; |
414 |
link = tpf->new_link++; |
|
415 |
||
416 |
/* move the data that was previously in the hash_??? variables |
|
417 |
* to the link struct, and let the hash variables point to the link */ |
|
418 |
link->tile = tpf->hash_tile[hash]; |
|
419 |
tpf->hash_tile[hash] = NTP_GET_LINK_OFFS(tpf, link); |
|
420 |
||
421 |
link->typelength = tpf->hash_head[hash]; |
|
9505 | 422 |
tpf->hash_head[hash] = 0xFFFF; // multi link |
0 | 423 |
link->next = 0xFFFF; |
424 |
} else { |
|
9505 | 425 |
/* a linked list of many tiles, |
426 |
* find the one corresponding to the tile, if it exists. |
|
427 |
* otherwise make a new link */ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
428 |
|
0 | 429 |
uint offs = tpf->hash_tile[hash]; |
430 |
do { |
|
431 |
link = NTP_GET_LINK_PTR(tpf, offs); |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
432 |
if (tile == link->tile && (link->typelength & 0x3U) == (uint)dir) { |
3019
a09d8f7b48be
(svn r3599) -Fix: added some casts to suppress some more warnings
truelight
parents:
3017
diff
changeset
|
433 |
if (length >= (uint)(link->typelength >> 2)) return false; |
0 | 434 |
link->typelength = dir | (length << 2); |
435 |
return true; |
|
436 |
} |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2952
diff
changeset
|
437 |
} while ((offs = link->next) != 0xFFFF); |
0 | 438 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
439 |
|
0 | 440 |
/* get here if we need to add a new link to link, |
441 |
* first, allocate a new link, in the same way as before */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
442 |
if (tpf->num_links_left == 0) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5028
diff
changeset
|
443 |
DEBUG(ntp, 1, "No links left"); |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
444 |
return false; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
445 |
} |
0 | 446 |
tpf->num_links_left--; |
447 |
new_link = tpf->new_link++; |
|
448 |
||
449 |
/* then fill the link with the new info, and establish a ptr from the old |
|
450 |
* link to the new one */ |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
451 |
new_link->tile = tile; |
0 | 452 |
new_link->typelength = dir | (length << 2); |
453 |
new_link->next = 0xFFFF; |
|
454 |
||
455 |
link->next = NTP_GET_LINK_OFFS(tpf, new_link); |
|
456 |
return true; |
|
457 |
} |
|
458 |
||
2782 | 459 |
/** |
460 |
* Checks if the shortest path to the given tile/dir so far is still the given |
|
461 |
* length. |
|
462 |
* @return true if the length is still the same |
|
463 |
* @pre The given tile/dir combination should be present in the hash, by a |
|
464 |
* previous call to NtpVisit(). |
|
465 |
*/ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
466 |
static bool NtpCheck(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint length) |
0 | 467 |
{ |
468 |
uint hash,head,offs; |
|
469 |
HashLink *link; |
|
470 |
||
471 |
hash = PATHFIND_HASH_TILE(tile); |
|
472 |
head=tpf->hash_head[hash]; |
|
473 |
assert(head); |
|
474 |
||
475 |
if (head != 0xffff) { |
|
476 |
assert( tpf->hash_tile[hash] == tile && (head & 3) == dir); |
|
477 |
assert( (head >> 2) <= length); |
|
478 |
return length == (head >> 2); |
|
479 |
} |
|
480 |
||
9505 | 481 |
/* else it's a linked list of many tiles */ |
0 | 482 |
offs = tpf->hash_tile[hash]; |
2952 | 483 |
for (;;) { |
0 | 484 |
link = NTP_GET_LINK_PTR(tpf, offs); |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2952
diff
changeset
|
485 |
if (tile == link->tile && (link->typelength & 0x3U) == dir) { |
3019
a09d8f7b48be
(svn r3599) -Fix: added some casts to suppress some more warnings
truelight
parents:
3017
diff
changeset
|
486 |
assert((uint)(link->typelength >> 2) <= length); |
a09d8f7b48be
(svn r3599) -Fix: added some casts to suppress some more warnings
truelight
parents:
3017
diff
changeset
|
487 |
return length == (uint)(link->typelength >> 2); |
0 | 488 |
} |
489 |
offs = link->next; |
|
490 |
assert(offs != 0xffff); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
||
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
495 |
static uint DistanceMoo(TileIndex t0, TileIndex t1) |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
496 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
497 |
const uint dx = Delta(TileX(t0), TileX(t1)); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
498 |
const uint dy = Delta(TileY(t0), TileY(t1)); |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
499 |
|
9505 | 500 |
const uint straightTracks = 2 * min(dx, dy); // The number of straight (not full length) tracks |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
501 |
/* OPTIMISATION: |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
502 |
* Original: diagTracks = max(dx, dy) - min(dx,dy); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
503 |
* Proof: |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
504 |
* (dx-dy) - straightTracks == (min + max) - straightTracks = min + // max - 2 * min = max - min */ |
9505 | 505 |
const uint diagTracks = dx + dy - straightTracks; // The number of diagonal (full tile length) tracks. |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
506 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
507 |
return diagTracks*DIAG_FACTOR + straightTracks*STR_FACTOR; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
508 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
509 |
|
9505 | 510 |
/* These has to be small cause the max length of a track |
511 |
* is currently limited to 16384 */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
512 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
513 |
static const byte _length_of_track[16] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4081
diff
changeset
|
514 |
DIAG_FACTOR, DIAG_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, 0, 0, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4081
diff
changeset
|
515 |
DIAG_FACTOR, DIAG_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, 0, 0 |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
516 |
}; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
517 |
|
9505 | 518 |
/* new more optimized pathfinder for trains... |
519 |
* Tile is the tile the train is at. |
|
520 |
* direction is the tile the train is moving towards. */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
521 |
|
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3132
diff
changeset
|
522 |
static void NTPEnum(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection direction) |
0 | 523 |
{ |
2782 | 524 |
TrackBits bits, allbits; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
525 |
Trackdir track; |
2782 | 526 |
TileIndex tile_org; |
0 | 527 |
StackedItem si; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
528 |
int estimation; |
0 | 529 |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2186
diff
changeset
|
530 |
|
2136
2c9fda706e52
(svn r2646) Change: [ntp] Fix uninitialized variable and add some more asserts to be able to debug an assert error.
ludde
parents:
2125
diff
changeset
|
531 |
|
9505 | 532 |
/* Need to have a special case for the start. |
533 |
* We shouldn't call the callback for the current tile. */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
534 |
si.cur_length = 1; // Need to start at 1 cause 0 is a reserved value. |
0 | 535 |
si.depth = 0; |
536 |
si.state = 0; |
|
2136
2c9fda706e52
(svn r2646) Change: [ntp] Fix uninitialized variable and add some more asserts to be able to debug an assert error.
ludde
parents:
2125
diff
changeset
|
537 |
si.first_track = 0xFF; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
538 |
goto start_at; |
0 | 539 |
|
2952 | 540 |
for (;;) { |
9505 | 541 |
/* Get the next item to search from from the priority queue */ |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
542 |
do { |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
543 |
if (tpf->nstack == 0) |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
544 |
return; // nothing left? then we're done! |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
545 |
si = tpf->stack[0]; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
546 |
tile = si.tile; |
0 | 547 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
548 |
HeapifyDown(tpf); |
9505 | 549 |
/* Make sure we havn't already visited this tile. */ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
550 |
} while (!NtpCheck(tpf, tile, ReverseDiagDir(TrackdirToExitdir(ReverseTrackdir(si.track))), si.cur_length)); |
0 | 551 |
|
9505 | 552 |
/* Add the length of this track. */ |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
553 |
si.cur_length += _length_of_track[si.track]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
554 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
555 |
callback_and_continue: |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
556 |
if (tpf->enum_proc(tile, tpf->userdata, si.first_track, si.cur_length)) |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
557 |
return; |
0 | 558 |
|
2136
2c9fda706e52
(svn r2646) Change: [ntp] Fix uninitialized variable and add some more asserts to be able to debug an assert error.
ludde
parents:
2125
diff
changeset
|
559 |
assert(si.track <= 13); |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
560 |
direction = TrackdirToExitdir(si.track); |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
561 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
562 |
start_at: |
9505 | 563 |
/* If the tile is the entry tile of a tunnel, and we're not going out of the tunnel, |
564 |
* need to find the exit of the tunnel. */ |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
565 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
566 |
if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) { |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
567 |
/* We are not just driving out of the tunnel/bridge */ |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
568 |
if (GetTunnelBridgeDirection(tile) != direction || |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
569 |
GetTunnelBridgeTransportType(tile) != tpf->tracktype) { |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
570 |
/* We are not driving into the tunnel/bridge, or it is an invalid tunnel/bridge */ |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
571 |
continue; |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
572 |
} |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
573 |
if (!HasBit(tpf->railtypes, GetRailType(tile))) { |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
574 |
bits = TRACK_BIT_NONE; |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
575 |
break; |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
576 |
} |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
577 |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
578 |
TileIndex endtile = GetOtherTunnelBridgeEnd(tile); |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
579 |
si.cur_length += DIAG_FACTOR * (GetTunnelBridgeLength(tile, endtile) + 1); |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
580 |
tile = endtile; |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
581 |
/* tile now points to the exit tile of the tunnel/bridge */ |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
582 |
} |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
583 |
} |
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
584 |
|
9505 | 585 |
/* This is a special loop used to go through |
586 |
* a rail net and find the first intersection */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
587 |
tile_org = tile; |
2952 | 588 |
for (;;) { |
2136
2c9fda706e52
(svn r2646) Change: [ntp] Fix uninitialized variable and add some more asserts to be able to debug an assert error.
ludde
parents:
2125
diff
changeset
|
589 |
assert(direction <= 3); |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4406
diff
changeset
|
590 |
tile += TileOffsByDiagDir(direction); |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
591 |
|
9505 | 592 |
/* too long search length? bail out. */ |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
593 |
if (si.cur_length >= tpf->maxlength) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5028
diff
changeset
|
594 |
DEBUG(ntp, 1, "Cur_length too big"); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
595 |
bits = TRACK_BIT_NONE; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
596 |
break; |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
597 |
} |
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
598 |
|
9505 | 599 |
/* Not a regular rail tile? |
600 |
* Then we can't use the code below, but revert to more general code. */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
601 |
if (!IsTileType(tile, MP_RAILWAY) || !IsPlainRailTile(tile)) { |
9505 | 602 |
/* We found a tile which is not a normal railway tile. |
603 |
* Determine which tracks that exist on this tile. */ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
604 |
bits = TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)) & DiagdirReachesTrackdirs(direction)); |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
605 |
|
9505 | 606 |
/* Check that the tile contains exactly one track */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9629
diff
changeset
|
607 |
if (bits == 0 || KillFirstBit(bits) != 0) break; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
608 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9629
diff
changeset
|
609 |
if (!HasBit(tpf->railtypes, GetRailType(tile))) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
610 |
bits = TRACK_BIT_NONE; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
611 |
break; |
3804
13ee0f2f5cc9
(svn r4812) -Fix (FS#161) NTP properly checks for railtypes on non-plain-rail-tiles (Rubidium)
celestar
parents:
3735
diff
changeset
|
612 |
} |
13ee0f2f5cc9
(svn r4812) -Fix (FS#161) NTP properly checks for railtypes on non-plain-rail-tiles (Rubidium)
celestar
parents:
3735
diff
changeset
|
613 |
|
9505 | 614 |
/******************* |
615 |
* If we reach here, the tile has exactly one track. |
|
616 |
* tile - index to a tile that is not rail tile, but still straight (with optional signals) |
|
617 |
* bits - bitmask of which track that exist on the tile (exactly one bit is set) |
|
618 |
* direction - which direction are we moving in? |
|
619 |
*******************/ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
620 |
si.track = TrackEnterdirToTrackdir(FindFirstTrack(bits), direction); |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
621 |
si.cur_length += _length_of_track[si.track]; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
622 |
goto callback_and_continue; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
623 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
624 |
|
2782 | 625 |
/* Regular rail tile, determine which tracks exist. */ |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
626 |
allbits = GetTrackBits(tile); |
2782 | 627 |
/* Which tracks are reachable? */ |
628 |
bits = allbits & DiagdirReachesTracks(direction); |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
629 |
|
2782 | 630 |
/* The tile has no reachable tracks => End of rail segment |
631 |
* or Intersection => End of rail segment. We check this agains all the |
|
632 |
* bits, not just reachable ones, to prevent infinite loops. */ |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
633 |
if (bits == TRACK_BIT_NONE || TracksOverlap(allbits)) break; |
2137
0e686b34c3a9
(svn r2647) Fix: [ntp] Fix assertion error introduced in r2635
ludde
parents:
2136
diff
changeset
|
634 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9629
diff
changeset
|
635 |
if (!HasBit(tpf->railtypes, GetRailType(tile))) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
636 |
bits = TRACK_BIT_NONE; |
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3267
diff
changeset
|
637 |
break; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3267
diff
changeset
|
638 |
} |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3267
diff
changeset
|
639 |
|
2782 | 640 |
/* If we reach here, the tile has exactly one track, and this |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
641 |
track is reachable = > Rail segment continues */ |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
642 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
643 |
track = TrackEnterdirToTrackdir(FindFirstTrack(bits), direction); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
644 |
assert(track != INVALID_TRACKDIR); |
2137
0e686b34c3a9
(svn r2647) Fix: [ntp] Fix assertion error introduced in r2635
ludde
parents:
2136
diff
changeset
|
645 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
646 |
si.cur_length += _length_of_track[track]; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
647 |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
648 |
/* Check if this rail is an upwards slope. If it is, then add a penalty. */ |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
649 |
if (IsDiagonalTrackdir(track) && IsUphillTrackdir(GetTileSlope(tile, NULL), track)) { |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
650 |
// upwards slope. add some penalty. |
9505 | 651 |
si.cur_length += 4 * DIAG_FACTOR; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
652 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
653 |
|
9505 | 654 |
/* railway tile with signals..? */ |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
655 |
if (HasSignals(tile)) { |
4631
3005b7b2e18c
(svn r6495) -Codechange: removed direct map access in pathfind.c
glx
parents:
4559
diff
changeset
|
656 |
if (!HasSignalOnTrackdir(tile, track)) { |
9505 | 657 |
/* if one way signal not pointing towards us, stop going in this direction => End of rail segment. */ |
4631
3005b7b2e18c
(svn r6495) -Codechange: removed direct map access in pathfind.c
glx
parents:
4559
diff
changeset
|
658 |
if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
659 |
bits = TRACK_BIT_NONE; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
660 |
break; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
661 |
} |
4631
3005b7b2e18c
(svn r6495) -Codechange: removed direct map access in pathfind.c
glx
parents:
4559
diff
changeset
|
662 |
} else if (GetSignalStateByTrackdir(tile, track) == SIGNAL_STATE_GREEN) { |
9505 | 663 |
/* green signal in our direction. either one way or two way. */ |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
664 |
si.state |= 3; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
665 |
} else { |
9505 | 666 |
/* reached a red signal. */ |
4631
3005b7b2e18c
(svn r6495) -Codechange: removed direct map access in pathfind.c
glx
parents:
4559
diff
changeset
|
667 |
if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) { |
9505 | 668 |
/* two way red signal. unless we passed another green signal on the way, |
669 |
* stop going in this direction => End of rail segment. |
|
670 |
* this is to prevent us from going into a full platform. */ |
|
671 |
if (!(si.state & 1)) { |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
672 |
bits = TRACK_BIT_NONE; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
673 |
break; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
674 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
675 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
676 |
if (!(si.state & 2)) { |
9505 | 677 |
/* Is this the first signal we see? And it's red... add penalty */ |
678 |
si.cur_length += 10 * DIAG_FACTOR; |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
679 |
si.state += 2; // remember that we added penalty. |
9505 | 680 |
/* Because we added a penalty, we can't just continue as usual. |
681 |
* Need to get out and let A* do it's job with |
|
682 |
* possibly finding an even shorter path. */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
683 |
break; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
684 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
685 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
686 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
687 |
if (tpf->enum_proc(tile, tpf->userdata, si.first_track, si.cur_length)) |
9505 | 688 |
return; // Don't process this tile any further |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
689 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
690 |
|
9505 | 691 |
/* continue with the next track */ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
692 |
direction = TrackdirToExitdir(track); |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
693 |
|
9505 | 694 |
/* safety check if we're running around chasing our tail... (infinite loop) */ |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
695 |
if (tile == tile_org) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
696 |
bits = TRACK_BIT_NONE; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
697 |
break; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
698 |
} |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
699 |
} |
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
700 |
|
9505 | 701 |
/* There are no tracks to choose between. |
702 |
* Stop searching in this direction */ |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
703 |
if (bits == TRACK_BIT_NONE) |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
704 |
continue; |
0 | 705 |
|
9505 | 706 |
/**************** |
707 |
* We got multiple tracks to choose between (intersection). |
|
708 |
* Branch the search space into several branches. |
|
709 |
****************/ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
710 |
|
9505 | 711 |
/* Check if we've already visited this intersection. |
712 |
* If we've already visited it with a better length, then |
|
713 |
* there's no point in visiting it again. */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
714 |
if (!NtpVisit(tpf, tile, direction, si.cur_length)) |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
715 |
continue; |
0 | 716 |
|
9505 | 717 |
/* Push all possible alternatives that we can reach from here |
718 |
* onto the priority heap. |
|
719 |
* 'bits' contains the tracks that we can choose between. */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
720 |
|
9505 | 721 |
/* First compute the estimated distance to the target. |
722 |
* This is used to implement A* */ |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
723 |
estimation = 0; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
724 |
if (tpf->dest != 0) |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
725 |
estimation = DistanceMoo(tile, tpf->dest); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
726 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
727 |
si.depth++; |
2774
4b7d8beec975
(svn r3321) - Fix: A wrong use of the map m5 bits, where a previously calculated "bits" variable should have been used. This resulted in the pathfinder imagining junctions, which negatively affects performance somewhat (Darkvater).
matthijs
parents:
2548
diff
changeset
|
728 |
if (si.depth == 0) |
9505 | 729 |
continue; // We overflowed our depth. No more searching in this direction. |
0 | 730 |
si.tile = tile; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
731 |
while (bits != TRACK_BIT_NONE) { |
5849
58039c9dc565
(svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents:
5838
diff
changeset
|
732 |
Track track = RemoveFirstTrack(&bits); |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
733 |
si.track = TrackEnterdirToTrackdir(track, direction); |
2782 | 734 |
assert(si.track != 0xFF); |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
735 |
si.priority = si.cur_length + estimation; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
736 |
|
9505 | 737 |
/* out of stack items, bail out? */ |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
738 |
if (tpf->nstack >= lengthof(tpf->stack)) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5028
diff
changeset
|
739 |
DEBUG(ntp, 1, "Out of stack"); |
0 | 740 |
break; |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
741 |
} |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
742 |
|
0 | 743 |
tpf->stack[tpf->nstack] = si; |
744 |
HeapifyUp(tpf); |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
745 |
}; |
0 | 746 |
|
9505 | 747 |
/* If this is the first intersection, we need to fill the first_track member. |
748 |
* so the code outside knows which path is better. |
|
749 |
* also randomize the order in which we search through them. */ |
|
0 | 750 |
if (si.depth == 1) { |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
751 |
assert(tpf->nstack == 1 || tpf->nstack == 2 || tpf->nstack == 3); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
752 |
if (tpf->nstack != 1) { |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
753 |
uint32 r = Random(); |
5984 | 754 |
if (r & 1) Swap(tpf->stack[0].track, tpf->stack[1].track); |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
755 |
if (tpf->nstack != 2) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
756 |
TrackdirByte t = tpf->stack[2].track; |
5984 | 757 |
if (r & 2) Swap(tpf->stack[0].track, t); |
758 |
if (r & 4) Swap(tpf->stack[1].track, t); |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
759 |
tpf->stack[2].first_track = tpf->stack[2].track = t; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
760 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
761 |
tpf->stack[0].first_track = tpf->stack[0].track; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
762 |
tpf->stack[1].first_track = tpf->stack[1].track; |
0 | 763 |
} |
764 |
} |
|
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
765 |
|
9505 | 766 |
/* Continue with the next from the queue... */ |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
767 |
} |
0 | 768 |
} |
769 |
||
770 |
||
9505 | 771 |
/** new pathfinder for trains. better and faster. */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
772 |
void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data) |
0 | 773 |
{ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
774 |
SmallStackSafeStackAlloc<NewTrackPathFinder, 1> tpf; |
0 | 775 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
776 |
tpf->dest = dest; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
777 |
tpf->userdata = data; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
778 |
tpf->enum_proc = enum_proc; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
779 |
tpf->tracktype = TRANSPORT_RAIL; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
780 |
tpf->railtypes = railtypes; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
781 |
tpf->maxlength = min(_patches.pf_maxlength * 3, 10000); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
782 |
tpf->nstack = 0; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
783 |
tpf->new_link = tpf->links; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
784 |
tpf->num_links_left = lengthof(tpf->links); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
785 |
memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
786 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
787 |
NTPEnum(tpf, tile, direction); |
0 | 788 |
} |