author | convert-repo |
Mon, 07 Apr 2008 16:21:55 +0000 | |
changeset 10076 | dfd70e42c4ae |
parent 9300 | e57c8e9f4cf9 |
child 10164 | 3ff9e65f3d49 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
3 |
/** @file pathfind.cpp */ |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
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" |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3894
diff
changeset
|
9 |
#include "depot.h" |
8615
6b91ca653bad
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8604
diff
changeset
|
10 |
#include "tile_cmd.h" |
6949
72d11a1e1e60
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents:
6678
diff
changeset
|
11 |
#include "landscape.h" |
0 | 12 |
#include "pathfind.h" |
8599
b609cdeeff3f
(svn r11664) -Codechange: use more specific ("rail_type.h" instead of "rail.h" that includes way more than only "rail_type.h") includes at some places.
rubidium
parents:
8584
diff
changeset
|
13 |
#include "rail_type.h" |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
14 |
#include "debug.h" |
3154 | 15 |
#include "tunnel_map.h" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8732
diff
changeset
|
16 |
#include "settings_type.h" |
3735
56a5bdee6c9a
(svn r4715) - Fix: (FS#109) ? Wrongfully bad signal - Don't allow OPF to enter train depot from the back
KUDr
parents:
3618
diff
changeset
|
17 |
#include "depot.h" |
8579
3efbb430092e
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents:
8467
diff
changeset
|
18 |
#include "tunnelbridge_map.h" |
8615
6b91ca653bad
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8604
diff
changeset
|
19 |
#include "core/random_func.hpp" |
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
20 |
#include "core/alloc_func.hpp" |
8894
1e5b2d4380b8
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents:
8893
diff
changeset
|
21 |
#include "tunnelbridge.h" |
0 | 22 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
23 |
/* 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
|
24 |
static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir) |
0 | 25 |
{ |
26 |
uint hash, val, offs; |
|
27 |
TrackPathFinderLink *link, *new_link; |
|
28 |
uint bits = 1 << dir; |
|
29 |
||
30 |
if (tpf->disable_tile_hash) |
|
31 |
return true; |
|
32 |
||
33 |
hash = PATHFIND_HASH_TILE(tile); |
|
34 |
||
35 |
val = tpf->hash_head[hash]; |
|
36 |
||
37 |
if (val == 0) { |
|
38 |
/* unused hash entry, set the appropriate bit in it and return true |
|
39 |
* to indicate that a bit was set. */ |
|
40 |
tpf->hash_head[hash] = bits; |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
41 |
tpf->hash_tile[hash] = tile; |
0 | 42 |
return true; |
43 |
} else if (!(val & 0x8000)) { |
|
44 |
/* single tile */ |
|
45 |
||
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
46 |
if (tile == tpf->hash_tile[hash]) { |
0 | 47 |
/* found another bit for the same tile, |
48 |
* check if this bit is already set, if so, return false */ |
|
49 |
if (val & bits) |
|
50 |
return false; |
|
51 |
||
52 |
/* otherwise set the bit and return true to indicate that the bit |
|
53 |
* was set */ |
|
54 |
tpf->hash_head[hash] = val | bits; |
|
55 |
return true; |
|
56 |
} else { |
|
57 |
/* 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
|
58 |
|
0 | 59 |
/* allocate a link. if out of links, handle this by returning |
60 |
* 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
|
61 |
if (tpf->num_links_left == 0) { |
0 | 62 |
return false; |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
63 |
} |
0 | 64 |
tpf->num_links_left--; |
65 |
link = tpf->new_link++; |
|
66 |
||
67 |
/* move the data that was previously in the hash_??? variables |
|
68 |
* to the link struct, and let the hash variables point to the link */ |
|
69 |
link->tile = tpf->hash_tile[hash]; |
|
70 |
tpf->hash_tile[hash] = PATHFIND_GET_LINK_OFFS(tpf, link); |
|
71 |
||
72 |
link->flags = tpf->hash_head[hash]; |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
73 |
tpf->hash_head[hash] = 0xFFFF; // multi link |
0 | 74 |
|
75 |
link->next = 0xFFFF; |
|
76 |
} |
|
77 |
} else { |
|
78 |
/* a linked list of many tiles, |
|
79 |
* find the one corresponding to the tile, if it exists. |
|
80 |
* otherwise make a new link */ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
81 |
|
0 | 82 |
offs = tpf->hash_tile[hash]; |
83 |
do { |
|
84 |
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
|
85 |
if (tile == link->tile) { |
0 | 86 |
/* found the tile in the link list, |
87 |
* check if the bit was alrady set, if so return false to indicate that the |
|
88 |
* bit was already set */ |
|
89 |
if (link->flags & bits) |
|
90 |
return false; |
|
91 |
link->flags |= bits; |
|
92 |
return true; |
|
93 |
} |
|
94 |
} while ((offs=link->next) != 0xFFFF); |
|
95 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
96 |
|
0 | 97 |
/* get here if we need to add a new link to link, |
98 |
* 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
|
99 |
if (tpf->num_links_left == 0) { |
0 | 100 |
return false; |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
101 |
} |
0 | 102 |
tpf->num_links_left--; |
103 |
new_link = tpf->new_link++; |
|
104 |
||
105 |
/* then fill the link with the new info, and establish a ptr from the old |
|
106 |
* link to the new one */ |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
107 |
new_link->tile = tile; |
0 | 108 |
new_link->flags = bits; |
109 |
new_link->next = 0xFFFF; |
|
110 |
||
111 |
link->next = PATHFIND_GET_LINK_OFFS(tpf, new_link); |
|
112 |
return true; |
|
113 |
} |
|
114 |
||
9296
5878a50c67b2
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents:
9294
diff
changeset
|
115 |
static void TPFModeShip(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) |
0 | 116 |
{ |
117 |
RememberData rd; |
|
747
e795750b96de
(svn r1203) -Fix: the pathfinder no longer sees rail with an other owner as a
truelight
parents:
679
diff
changeset
|
118 |
|
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
|
119 |
assert(tpf->tracktype == TRANSPORT_WATER); |
0 | 120 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
121 |
/* This addition will sometimes overflow by a single tile. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
122 |
* The use of TILE_MASK here makes sure that we still point at a valid |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
123 |
* 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
|
124 |
tile = TILE_MASK(tile + TileOffsByDiagDir(direction)); |
0 | 125 |
|
126 |
if (++tpf->rd.cur_length > 50) |
|
127 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
128 |
|
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
129 |
TrackBits bits = TrackStatusToTrackBits(GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type)) & DiagdirReachesTracks(direction); |
9107
3e57b96e98f2
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents:
8976
diff
changeset
|
130 |
if (bits == TRACK_BIT_NONE) return; |
0 | 131 |
|
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
|
132 |
assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY()); |
0 | 133 |
|
9107
3e57b96e98f2
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents:
8976
diff
changeset
|
134 |
bool only_one_track = true; |
0 | 135 |
do { |
9107
3e57b96e98f2
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents:
8976
diff
changeset
|
136 |
Track track = RemoveFirstTrack(&bits); |
3e57b96e98f2
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents:
8976
diff
changeset
|
137 |
if (bits != TRACK_BIT_NONE) only_one_track = false; |
0 | 138 |
rd = tpf->rd; |
139 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
140 |
/* Change direction 4 times only */ |
9107
3e57b96e98f2
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents:
8976
diff
changeset
|
141 |
if (!only_one_track && track != tpf->rd.last_choosen_track) { |
2952 | 142 |
if (++tpf->rd.depth > 4) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
143 |
tpf->rd = rd; |
0 | 144 |
return; |
145 |
} |
|
9107
3e57b96e98f2
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents:
8976
diff
changeset
|
146 |
tpf->rd.last_choosen_track = track; |
0 | 147 |
} |
148 |
||
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
149 |
tpf->the_dir = TrackEnterdirToTrackdir(track, direction); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
150 |
|
9107
3e57b96e98f2
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents:
8976
diff
changeset
|
151 |
if (!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length)) { |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
152 |
TPFModeShip(tpf, tile, TrackdirToExitdir(tpf->the_dir)); |
0 | 153 |
} |
154 |
||
155 |
tpf->rd = rd; |
|
9107
3e57b96e98f2
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents:
8976
diff
changeset
|
156 |
} while (bits != TRACK_BIT_NONE); |
0 | 157 |
|
158 |
} |
|
159 |
||
8892
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
160 |
/** |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
161 |
* Checks if any vehicle can enter/leave tile in given diagdir |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
162 |
* Checks only for rail/road depots and road non-drivethrough stations |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
163 |
* @param tile tile to check |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
164 |
* @param side side of tile we are trying to leave/enter |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
165 |
* @param tracktype type of transport |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
166 |
* @pre tile has trackbit at that diagdir |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
167 |
* @return true iff vehicle can enter/leve the tile in given side |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
168 |
*/ |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
169 |
static inline bool CanAccessTileInDir(TileIndex tile, DiagDirection side, TransportType tracktype) |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
170 |
{ |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
171 |
if (tracktype == TRANSPORT_RAIL) { |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
172 |
/* depot from wrong side */ |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
173 |
if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) != side) return false; |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
174 |
} else if (tracktype == TRANSPORT_ROAD) { |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
175 |
/* depot from wrong side */ |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
176 |
if (IsTileDepotType(tile, TRANSPORT_ROAD) && GetRoadDepotDirection(tile) != side) return false; |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
177 |
/* non-driverthrough road station from wrong side */ |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
178 |
if (IsStandardRoadStopTile(tile) && GetRoadStopDir(tile) != side) return false; |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
179 |
} |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
180 |
|
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
181 |
return true; |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
182 |
} |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
183 |
|
9296
5878a50c67b2
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents:
9294
diff
changeset
|
184 |
static void TPFModeNormal(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) |
8888
94cc8a25185f
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz
parents:
8886
diff
changeset
|
185 |
{ |
8891
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
186 |
const TileIndex tile_org = tile; |
0 | 187 |
|
8888
94cc8a25185f
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz
parents:
8886
diff
changeset
|
188 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
8891
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
189 |
/* wrong track type */ |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
190 |
if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) return; |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
191 |
|
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
192 |
DiagDirection dir = GetTunnelBridgeDirection(tile); |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
193 |
/* entering tunnel / bridge? */ |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
194 |
if (dir == direction) { |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
195 |
TileIndex endtile = GetOtherTunnelBridgeEnd(tile); |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
196 |
|
8894
1e5b2d4380b8
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents:
8893
diff
changeset
|
197 |
tpf->rd.cur_length += GetTunnelBridgeLength(tile, endtile) + 1; |
8891
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
198 |
|
8888
94cc8a25185f
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz
parents:
8886
diff
changeset
|
199 |
TPFSetTileBit(tpf, tile, 14); |
8891
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
200 |
TPFSetTileBit(tpf, endtile, 14); |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
201 |
|
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
202 |
tile = endtile; |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
203 |
} else { |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
204 |
/* leaving tunnel / bridge? */ |
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
205 |
if (ReverseDiagDir(dir) != direction) return; |
8888
94cc8a25185f
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz
parents:
8886
diff
changeset
|
206 |
} |
8892
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
207 |
} else { |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
208 |
/* can we leave tile in this dir? */ |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
209 |
if (!CanAccessTileInDir(tile, direction, tpf->tracktype)) return; |
8888
94cc8a25185f
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz
parents:
8886
diff
changeset
|
210 |
} |
8891
88b9e51bcb1d
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz
parents:
8888
diff
changeset
|
211 |
|
8888
94cc8a25185f
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz
parents:
8886
diff
changeset
|
212 |
tile += TileOffsByDiagDir(direction); |
94cc8a25185f
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz
parents:
8886
diff
changeset
|
213 |
|
8892
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
214 |
/* can we enter tile in this dir? */ |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
215 |
if (!CanAccessTileInDir(tile, ReverseDiagDir(direction), tpf->tracktype)) return; |
eb0a4b4122c6
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz
parents:
8891
diff
changeset
|
216 |
|
5708
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
217 |
/* 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
|
218 |
* and transport type match */ |
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
219 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
8584
a8b6dffead63
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents:
8579
diff
changeset
|
220 |
if (GetTunnelBridgeDirection(tile) != direction || |
a8b6dffead63
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents:
8579
diff
changeset
|
221 |
GetTunnelBridgeTransportType(tile) != tpf->tracktype) { |
a8b6dffead63
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents:
8579
diff
changeset
|
222 |
return; |
5708
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
223 |
} |
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
224 |
} |
76382881636e
(svn r7718) -Fix (runknown): When pathfinding onto a bridge or tunnel end from
peter1138
parents:
5707
diff
changeset
|
225 |
|
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
226 |
TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type)); |
8893
af54cf3065cd
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz
parents:
8892
diff
changeset
|
227 |
|
af54cf3065cd
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz
parents:
8892
diff
changeset
|
228 |
/* Check in case of rail if the owner is the same */ |
af54cf3065cd
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz
parents:
8892
diff
changeset
|
229 |
if (tpf->tracktype == TRANSPORT_RAIL) { |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
230 |
if (trackdirbits != TRACKDIR_BIT_NONE && TrackStatusToTrackdirBits(GetTileTrackStatus(tile_org, TRANSPORT_RAIL, 0)) != TRACKDIR_BIT_NONE) { |
8893
af54cf3065cd
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz
parents:
8892
diff
changeset
|
231 |
if (GetTileOwner(tile_org) != GetTileOwner(tile)) return; |
af54cf3065cd
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz
parents:
8892
diff
changeset
|
232 |
} |
af54cf3065cd
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz
parents:
8892
diff
changeset
|
233 |
} |
af54cf3065cd
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz
parents:
8892
diff
changeset
|
234 |
|
0 | 235 |
tpf->rd.cur_length++; |
236 |
||
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
237 |
trackdirbits &= DiagdirReachesTrackdirs(direction); |
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
238 |
TrackBits bits = TrackdirBitsToTrackBits(trackdirbits); |
0 | 239 |
|
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
240 |
if (bits != TRACK_BIT_NONE) { |
8329
77e50bd6ad67
(svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents:
7577
diff
changeset
|
241 |
if (!tpf->disable_tile_hash || (tpf->rd.cur_length <= 64 && (KillFirstBit(bits) == 0 || ++tpf->rd.depth <= 7))) { |
0 | 242 |
do { |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
243 |
Track track = RemoveFirstTrack(&bits); |
0 | 244 |
|
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
245 |
tpf->the_dir = TrackEnterdirToTrackdir(track, direction); |
7567
8723fa633d31
(svn r10336) -Fix [FS#910]: reaching the end of a line in certain cases incorrectly stopped signal updates
peter1138
parents:
7179
diff
changeset
|
246 |
RememberData rd = tpf->rd; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
247 |
|
8976
1fd3a02c3432
(svn r12055) -Fix: another way to fix AI trying to build road through depots
smatz
parents:
8894
diff
changeset
|
248 |
/* make sure we are not leaving from invalid side */ |
1fd3a02c3432
(svn r12055) -Fix: another way to fix AI trying to build road through depots
smatz
parents:
8894
diff
changeset
|
249 |
if (TPFSetTileBit(tpf, tile, tpf->the_dir) && CanAccessTileInDir(tile, TrackdirToExitdir(tpf->the_dir), tpf->tracktype) && |
9107
3e57b96e98f2
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents:
8976
diff
changeset
|
250 |
!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length) ) { |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
251 |
TPFModeNormal(tpf, tile, TrackdirToExitdir(tpf->the_dir)); |
0 | 252 |
} |
253 |
tpf->rd = rd; |
|
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
254 |
} while (bits != TRACK_BIT_NONE); |
0 | 255 |
} |
256 |
} |
|
7567
8723fa633d31
(svn r10336) -Fix [FS#910]: reaching the end of a line in certain cases incorrectly stopped signal updates
peter1138
parents:
7179
diff
changeset
|
257 |
} |
8723fa633d31
(svn r10336) -Fix [FS#910]: reaching the end of a line in certain cases incorrectly stopped signal updates
peter1138
parents:
7179
diff
changeset
|
258 |
|
9296
5878a50c67b2
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents:
9294
diff
changeset
|
259 |
void FollowTrack(TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) |
0 | 260 |
{ |
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
261 |
assert(IsValidDiagDirection(direction)); |
0 | 262 |
|
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
263 |
SmallStackSafeStackAlloc<TrackPathFinder, 1> tpf; |
0 | 264 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
265 |
/* initialize path finder variables */ |
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
266 |
tpf->userdata = data; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
267 |
tpf->enum_proc = enum_proc; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
268 |
tpf->new_link = tpf->links; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
269 |
tpf->num_links_left = lengthof(tpf->links); |
0 | 270 |
|
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
271 |
tpf->rd.cur_length = 0; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
272 |
tpf->rd.depth = 0; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
273 |
tpf->rd.last_choosen_track = INVALID_TRACK; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
274 |
|
9296
5878a50c67b2
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents:
9294
diff
changeset
|
275 |
tpf->disable_tile_hash = (flags & PATHFIND_FLAGS_DISABLE_TILE_HASH) != 0; |
0 | 276 |
|
9296
5878a50c67b2
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents:
9294
diff
changeset
|
277 |
tpf->tracktype = tt; |
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
278 |
tpf->sub_type = sub_type; |
0 | 279 |
|
9296
5878a50c67b2
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents:
9294
diff
changeset
|
280 |
if ((flags & PATHFIND_FLAGS_SHIP_MODE) != 0) { |
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
281 |
tpf->enum_proc(tile, data, INVALID_TRACKDIR, 0); |
9296
5878a50c67b2
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents:
9294
diff
changeset
|
282 |
TPFModeShip(tpf, tile, direction); |
0 | 283 |
} else { |
284 |
/* clear the hash_heads */ |
|
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
285 |
memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); |
9296
5878a50c67b2
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents:
9294
diff
changeset
|
286 |
TPFModeNormal(tpf, tile, direction); |
0 | 287 |
} |
288 |
||
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
289 |
if (after_proc != NULL) after_proc(tpf); |
0 | 290 |
} |
291 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
292 |
struct StackedItem { |
0 | 293 |
TileIndex tile; |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
294 |
uint16 cur_length; ///< This is the current length to this tile. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
295 |
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
|
296 |
TrackdirByte track; |
0 | 297 |
byte depth; |
298 |
byte state; |
|
299 |
byte first_track; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
300 |
}; |
0 | 301 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
302 |
struct HashLink { |
0 | 303 |
TileIndex tile; |
304 |
uint16 typelength; |
|
305 |
uint16 next; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
306 |
}; |
0 | 307 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
308 |
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
|
309 |
NTPEnumProc *enum_proc; |
0 | 310 |
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
|
311 |
TileIndex dest; |
0 | 312 |
|
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
|
313 |
TransportType tracktype; |
8732
b18f578f7c16
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8635
diff
changeset
|
314 |
RailTypes railtypes; |
0 | 315 |
uint maxlength; |
316 |
||
317 |
HashLink *new_link; |
|
318 |
uint num_links_left; |
|
319 |
||
979
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
320 |
uint nstack; |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
321 |
StackedItem stack[256]; ///< priority queue of stacked items |
0 | 322 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
323 |
uint16 hash_head[0x400]; ///< hash heads. 0 means unused. 0xFFFC = length, 0x3 = dir |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
324 |
TileIndex hash_tile[0x400]; ///< tiles. or links. |
0 | 325 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
326 |
HashLink links[0x400]; ///< hash links |
0 | 327 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
328 |
}; |
0 | 329 |
#define NTP_GET_LINK_OFFS(tpf, link) ((byte*)(link) - (byte*)tpf->links) |
330 |
#define NTP_GET_LINK_PTR(tpf, link_offs) (HashLink*)((byte*)tpf->links + (link_offs)) |
|
331 |
||
332 |
#define ARR(i) tpf->stack[(i)-1] |
|
333 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
334 |
/** called after a new element was added in the queue at the last index. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
335 |
* move it down to the proper position */ |
536 | 336 |
static inline void HeapifyUp(NewTrackPathFinder *tpf) |
0 | 337 |
{ |
338 |
StackedItem si; |
|
339 |
int i = ++tpf->nstack; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
340 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
341 |
while (i != 1 && ARR(i).priority < ARR(i>>1).priority) { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
342 |
/* the child element is larger than the parent item. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
343 |
* swap the child item and the parent item. */ |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
344 |
si = ARR(i); ARR(i) = ARR(i >> 1); ARR(i >> 1) = si; |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
345 |
i >>= 1; |
0 | 346 |
} |
347 |
} |
|
348 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
349 |
/** called after the element 0 was eaten. fill it with a new element */ |
536 | 350 |
static inline void HeapifyDown(NewTrackPathFinder *tpf) |
0 | 351 |
{ |
352 |
StackedItem si; |
|
353 |
int i = 1, j; |
|
979
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
354 |
int n; |
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
355 |
|
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
356 |
assert(tpf->nstack > 0); |
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
357 |
n = --tpf->nstack; |
0 | 358 |
|
359 |
if (n == 0) return; // heap is empty so nothing to do? |
|
360 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
361 |
/* copy the last item to index 0. we use it as base for heapify. */ |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
362 |
ARR(1) = ARR(n + 1); |
0 | 363 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
364 |
while ((j = i * 2) <= n) { |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
365 |
/* figure out which is smaller of the children. */ |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
366 |
if (j != n && ARR(j).priority > ARR(j + 1).priority) |
0 | 367 |
j++; // right item is smaller |
368 |
||
369 |
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
|
370 |
if (ARR(i).priority <= ARR(j).priority) |
0 | 371 |
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
|
372 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
373 |
/* swap parent with the child */ |
0 | 374 |
si = ARR(i); ARR(i) = ARR(j); ARR(j) = si; |
375 |
i = j; |
|
376 |
} |
|
377 |
} |
|
378 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
379 |
/** mark a tile as visited and store the length of the path. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
380 |
* if we already had a better path to this tile, return false. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
381 |
* otherwise return true. */ |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3132
diff
changeset
|
382 |
static bool NtpVisit(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection dir, uint length) |
0 | 383 |
{ |
384 |
uint hash,head; |
|
385 |
HashLink *link, *new_link; |
|
386 |
||
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
387 |
assert(length < 16384-1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
388 |
|
0 | 389 |
hash = PATHFIND_HASH_TILE(tile); |
390 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
391 |
/* never visited before? */ |
0 | 392 |
if ((head=tpf->hash_head[hash]) == 0) { |
393 |
tpf->hash_tile[hash] = tile; |
|
394 |
tpf->hash_head[hash] = dir | (length << 2); |
|
395 |
return true; |
|
396 |
} |
|
397 |
||
398 |
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
|
399 |
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
|
400 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
401 |
/* longer length */ |
0 | 402 |
if (length >= (head >> 2)) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
403 |
|
0 | 404 |
tpf->hash_head[hash] = dir | (length << 2); |
405 |
return true; |
|
406 |
} |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
407 |
/* two tiles with the same hash, need to make a link |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
408 |
* allocate a link. if out of links, handle this by returning |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
409 |
* 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
|
410 |
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
|
411 |
DEBUG(ntp, 1, "No links left"); |
0 | 412 |
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
|
413 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
414 |
|
0 | 415 |
tpf->num_links_left--; |
416 |
link = tpf->new_link++; |
|
417 |
||
418 |
/* move the data that was previously in the hash_??? variables |
|
419 |
* to the link struct, and let the hash variables point to the link */ |
|
420 |
link->tile = tpf->hash_tile[hash]; |
|
421 |
tpf->hash_tile[hash] = NTP_GET_LINK_OFFS(tpf, link); |
|
422 |
||
423 |
link->typelength = tpf->hash_head[hash]; |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
424 |
tpf->hash_head[hash] = 0xFFFF; // multi link |
0 | 425 |
link->next = 0xFFFF; |
426 |
} else { |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
427 |
/* a linked list of many tiles, |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
428 |
* find the one corresponding to the tile, if it exists. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
429 |
* otherwise make a new link */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
430 |
|
0 | 431 |
uint offs = tpf->hash_tile[hash]; |
432 |
do { |
|
433 |
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
|
434 |
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
|
435 |
if (length >= (uint)(link->typelength >> 2)) return false; |
0 | 436 |
link->typelength = dir | (length << 2); |
437 |
return true; |
|
438 |
} |
|
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
|
439 |
} while ((offs = link->next) != 0xFFFF); |
0 | 440 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
441 |
|
0 | 442 |
/* get here if we need to add a new link to link, |
443 |
* 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
|
444 |
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
|
445 |
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
|
446 |
return false; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
447 |
} |
0 | 448 |
tpf->num_links_left--; |
449 |
new_link = tpf->new_link++; |
|
450 |
||
451 |
/* then fill the link with the new info, and establish a ptr from the old |
|
452 |
* link to the new one */ |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
453 |
new_link->tile = tile; |
0 | 454 |
new_link->typelength = dir | (length << 2); |
455 |
new_link->next = 0xFFFF; |
|
456 |
||
457 |
link->next = NTP_GET_LINK_OFFS(tpf, new_link); |
|
458 |
return true; |
|
459 |
} |
|
460 |
||
2782 | 461 |
/** |
462 |
* Checks if the shortest path to the given tile/dir so far is still the given |
|
463 |
* length. |
|
464 |
* @return true if the length is still the same |
|
465 |
* @pre The given tile/dir combination should be present in the hash, by a |
|
466 |
* previous call to NtpVisit(). |
|
467 |
*/ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
468 |
static bool NtpCheck(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint length) |
0 | 469 |
{ |
470 |
uint hash,head,offs; |
|
471 |
HashLink *link; |
|
472 |
||
473 |
hash = PATHFIND_HASH_TILE(tile); |
|
474 |
head=tpf->hash_head[hash]; |
|
475 |
assert(head); |
|
476 |
||
477 |
if (head != 0xffff) { |
|
478 |
assert( tpf->hash_tile[hash] == tile && (head & 3) == dir); |
|
479 |
assert( (head >> 2) <= length); |
|
480 |
return length == (head >> 2); |
|
481 |
} |
|
482 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
483 |
/* else it's a linked list of many tiles */ |
0 | 484 |
offs = tpf->hash_tile[hash]; |
2952 | 485 |
for (;;) { |
0 | 486 |
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
|
487 |
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
|
488 |
assert((uint)(link->typelength >> 2) <= length); |
a09d8f7b48be
(svn r3599) -Fix: added some casts to suppress some more warnings
truelight
parents:
3017
diff
changeset
|
489 |
return length == (uint)(link->typelength >> 2); |
0 | 490 |
} |
491 |
offs = link->next; |
|
492 |
assert(offs != 0xffff); |
|
493 |
} |
|
494 |
} |
|
495 |
||
496 |
||
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
497 |
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
|
498 |
{ |
8466
9ce95e16f9f9
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
8426
diff
changeset
|
499 |
const uint dx = Delta(TileX(t0), TileX(t1)); |
9ce95e16f9f9
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
8426
diff
changeset
|
500 |
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
|
501 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
502 |
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
|
503 |
/* OPTIMISATION: |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
504 |
* 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
|
505 |
* Proof: |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
506 |
* (dx-dy) - straightTracks == (min + max) - straightTracks = min + // max - 2 * min = max - min */ |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
507 |
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
|
508 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
509 |
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
|
510 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
511 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
512 |
/* These has to be small cause the max length of a track |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
513 |
* 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
|
514 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
515 |
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
|
516 |
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
|
517 |
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
|
518 |
}; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
519 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
520 |
/* new more optimized pathfinder for trains... |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
521 |
* Tile is the tile the train is at. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
522 |
* 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
|
523 |
|
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3132
diff
changeset
|
524 |
static void NTPEnum(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection direction) |
0 | 525 |
{ |
2782 | 526 |
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
|
527 |
Trackdir track; |
2782 | 528 |
TileIndex tile_org; |
0 | 529 |
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
|
530 |
int estimation; |
0 | 531 |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2186
diff
changeset
|
532 |
|
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
|
533 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
534 |
/* Need to have a special case for the start. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
535 |
* 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
|
536 |
si.cur_length = 1; // Need to start at 1 cause 0 is a reserved value. |
0 | 537 |
si.depth = 0; |
538 |
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
|
539 |
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
|
540 |
goto start_at; |
0 | 541 |
|
2952 | 542 |
for (;;) { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
543 |
/* 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
|
544 |
do { |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
545 |
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
|
546 |
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
|
547 |
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
|
548 |
tile = si.tile; |
0 | 549 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
550 |
HeapifyDown(tpf); |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
551 |
/* Make sure we havn't already visited this tile. */ |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
552 |
} while (!NtpCheck(tpf, tile, ReverseDiagDir(TrackdirToExitdir(ReverseTrackdir(si.track))), si.cur_length)); |
0 | 553 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
554 |
/* 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
|
555 |
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
|
556 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
557 |
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
|
558 |
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
|
559 |
return; |
0 | 560 |
|
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
|
561 |
assert(si.track <= 13); |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
562 |
direction = TrackdirToExitdir(si.track); |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
563 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
564 |
start_at: |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
565 |
/* If the tile is the entry tile of a tunnel, and we're not going out of the tunnel, |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
566 |
* 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
|
567 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
9178
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
568 |
if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) { |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
569 |
/* We are not just driving out of the tunnel/bridge */ |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
570 |
if (GetTunnelBridgeDirection(tile) != direction || |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
571 |
GetTunnelBridgeTransportType(tile) != tpf->tracktype) { |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
572 |
/* We are not driving into the tunnel/bridge, or it is an invalid tunnel/bridge */ |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
573 |
continue; |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
574 |
} |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
575 |
if (!HasBit(tpf->railtypes, GetRailType(tile))) { |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
576 |
bits = TRACK_BIT_NONE; |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
577 |
break; |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
578 |
} |
8894
1e5b2d4380b8
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents:
8893
diff
changeset
|
579 |
|
9178
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
580 |
TileIndex endtile = GetOtherTunnelBridgeEnd(tile); |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
581 |
si.cur_length += DIAG_FACTOR * (GetTunnelBridgeLength(tile, endtile) + 1); |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
582 |
tile = endtile; |
e0b883561546
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz
parents:
9149
diff
changeset
|
583 |
/* 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
|
584 |
} |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
585 |
} |
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
586 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
587 |
/* This is a special loop used to go through |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
588 |
* 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
|
589 |
tile_org = tile; |
2952 | 590 |
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
|
591 |
assert(direction <= 3); |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4406
diff
changeset
|
592 |
tile += TileOffsByDiagDir(direction); |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
593 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
594 |
/* 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
|
595 |
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
|
596 |
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
|
597 |
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
|
598 |
break; |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
599 |
} |
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
600 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
601 |
/* Not a regular rail tile? |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
602 |
* 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
|
603 |
if (!IsTileType(tile, MP_RAILWAY) || !IsPlainRailTile(tile)) { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
604 |
/* We found a tile which is not a normal railway tile. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
605 |
* Determine which tracks that exist on this tile. */ |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
606 |
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
|
607 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
608 |
/* Check that the tile contains exactly one track */ |
8329
77e50bd6ad67
(svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents:
7577
diff
changeset
|
609 |
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
|
610 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8329
diff
changeset
|
611 |
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
|
612 |
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
|
613 |
break; |
3804
13ee0f2f5cc9
(svn r4812) -Fix (FS#161) NTP properly checks for railtypes on non-plain-rail-tiles (Rubidium)
celestar
parents:
3735
diff
changeset
|
614 |
} |
13ee0f2f5cc9
(svn r4812) -Fix (FS#161) NTP properly checks for railtypes on non-plain-rail-tiles (Rubidium)
celestar
parents:
3735
diff
changeset
|
615 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
616 |
/******************* |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
617 |
* If we reach here, the tile has exactly one track. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
618 |
* tile - index to a tile that is not rail tile, but still straight (with optional signals) |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
619 |
* bits - bitmask of which track that exist on the tile (exactly one bit is set) |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
620 |
* direction - which direction are we moving in? |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
621 |
*******************/ |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
622 |
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
|
623 |
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
|
624 |
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
|
625 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
626 |
|
2782 | 627 |
/* 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
|
628 |
allbits = GetTrackBits(tile); |
2782 | 629 |
/* Which tracks are reachable? */ |
630 |
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
|
631 |
|
2782 | 632 |
/* The tile has no reachable tracks => End of rail segment |
633 |
* or Intersection => End of rail segment. We check this agains all the |
|
634 |
* 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
|
635 |
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
|
636 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8329
diff
changeset
|
637 |
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
|
638 |
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
|
639 |
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
|
640 |
} |
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
|
641 |
|
2782 | 642 |
/* If we reach here, the tile has exactly one track, and this |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
643 |
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
|
644 |
|
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
645 |
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
|
646 |
assert(track != INVALID_TRACKDIR); |
2137
0e686b34c3a9
(svn r2647) Fix: [ntp] Fix assertion error introduced in r2635
ludde
parents:
2136
diff
changeset
|
647 |
|
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
648 |
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
|
649 |
|
9149
cd335504407b
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
9112
diff
changeset
|
650 |
/* Check if this rail is an upwards slope. If it is, then add a penalty. */ |
cd335504407b
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
9112
diff
changeset
|
651 |
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
|
652 |
// upwards slope. add some penalty. |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
653 |
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
|
654 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
655 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
656 |
/* 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
|
657 |
if (HasSignals(tile)) { |
4631
3005b7b2e18c
(svn r6495) -Codechange: removed direct map access in pathfind.c
glx
parents:
4559
diff
changeset
|
658 |
if (!HasSignalOnTrackdir(tile, track)) { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
659 |
/* 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
|
660 |
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
|
661 |
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
|
662 |
break; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
663 |
} |
4631
3005b7b2e18c
(svn r6495) -Codechange: removed direct map access in pathfind.c
glx
parents:
4559
diff
changeset
|
664 |
} else if (GetSignalStateByTrackdir(tile, track) == SIGNAL_STATE_GREEN) { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
665 |
/* 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
|
666 |
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
|
667 |
} else { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
668 |
/* reached a red signal. */ |
4631
3005b7b2e18c
(svn r6495) -Codechange: removed direct map access in pathfind.c
glx
parents:
4559
diff
changeset
|
669 |
if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
670 |
/* two way red signal. unless we passed another green signal on the way, |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
671 |
* stop going in this direction => End of rail segment. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
672 |
* this is to prevent us from going into a full platform. */ |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
673 |
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
|
674 |
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
|
675 |
break; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
676 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
677 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
678 |
if (!(si.state & 2)) { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
679 |
/* Is this the first signal we see? And it's red... add penalty */ |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
680 |
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
|
681 |
si.state += 2; // remember that we added penalty. |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
682 |
/* Because we added a penalty, we can't just continue as usual. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
683 |
* Need to get out and let A* do it's job with |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
684 |
* 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
|
685 |
break; |
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 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
688 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
689 |
if (tpf->enum_proc(tile, tpf->userdata, si.first_track, si.cur_length)) |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
690 |
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
|
691 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
692 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
693 |
/* continue with the next track */ |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
694 |
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
|
695 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
696 |
/* 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
|
697 |
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
|
698 |
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
|
699 |
break; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
700 |
} |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
701 |
} |
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
702 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
703 |
/* There are no tracks to choose between. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
704 |
* 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
|
705 |
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
|
706 |
continue; |
0 | 707 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
708 |
/**************** |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
709 |
* We got multiple tracks to choose between (intersection). |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
710 |
* Branch the search space into several branches. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
711 |
****************/ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
712 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
713 |
/* Check if we've already visited this intersection. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
714 |
* If we've already visited it with a better length, then |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
715 |
* 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
|
716 |
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
|
717 |
continue; |
0 | 718 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
719 |
/* Push all possible alternatives that we can reach from here |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
720 |
* onto the priority heap. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
721 |
* '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
|
722 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
723 |
/* First compute the estimated distance to the target. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
724 |
* 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
|
725 |
estimation = 0; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
726 |
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
|
727 |
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
|
728 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
729 |
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
|
730 |
if (si.depth == 0) |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
731 |
continue; // We overflowed our depth. No more searching in this direction. |
0 | 732 |
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
|
733 |
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
|
734 |
Track track = RemoveFirstTrack(&bits); |
9300
e57c8e9f4cf9
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch
parents:
9296
diff
changeset
|
735 |
si.track = TrackEnterdirToTrackdir(track, direction); |
2782 | 736 |
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
|
737 |
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
|
738 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
739 |
/* 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
|
740 |
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
|
741 |
DEBUG(ntp, 1, "Out of stack"); |
0 | 742 |
break; |
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
743 |
} |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
744 |
|
0 | 745 |
tpf->stack[tpf->nstack] = si; |
746 |
HeapifyUp(tpf); |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
747 |
}; |
0 | 748 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
749 |
/* If this is the first intersection, we need to fill the first_track member. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
750 |
* so the code outside knows which path is better. |
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
751 |
* also randomize the order in which we search through them. */ |
0 | 752 |
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
|
753 |
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
|
754 |
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
|
755 |
uint32 r = Random(); |
5984 | 756 |
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
|
757 |
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
|
758 |
TrackdirByte t = tpf->stack[2].track; |
5984 | 759 |
if (r & 2) Swap(tpf->stack[0].track, t); |
760 |
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
|
761 |
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
|
762 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2049
diff
changeset
|
763 |
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
|
764 |
tpf->stack[1].first_track = tpf->stack[1].track; |
0 | 765 |
} |
766 |
} |
|
2044
68ec4a2f2d79
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2006
diff
changeset
|
767 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
768 |
/* 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
|
769 |
} |
0 | 770 |
} |
771 |
||
772 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6574
diff
changeset
|
773 |
/** new pathfinder for trains. better and faster. */ |
8732
b18f578f7c16
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8635
diff
changeset
|
774 |
void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data) |
0 | 775 |
{ |
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
776 |
SmallStackSafeStackAlloc<NewTrackPathFinder, 1> tpf; |
0 | 777 |
|
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
778 |
tpf->dest = dest; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
779 |
tpf->userdata = data; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
780 |
tpf->enum_proc = enum_proc; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
781 |
tpf->tracktype = TRANSPORT_RAIL; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
782 |
tpf->railtypes = railtypes; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
783 |
tpf->maxlength = min(_patches.pf_maxlength * 3, 10000); |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
784 |
tpf->nstack = 0; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
785 |
tpf->new_link = tpf->links; |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
786 |
tpf->num_links_left = lengthof(tpf->links); |
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
787 |
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
|
788 |
|
9294
5cd9e0da420f
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
rubidium
parents:
9178
diff
changeset
|
789 |
NTPEnum(tpf, tile, direction); |
0 | 790 |
} |