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