Mercurial > hg > openttd
annotate src/pathfind.cpp @ 9413:512ea64da840 draft
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 29 May 2008 15:13:28 +0000 |
parents | 2b0c6e62535e |
children | 8622c9315e8c |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
9111
d48433370037
(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 <rubidium@openttd.org>
parents:
8962
diff
changeset
|
3 /** @file pathfind.cpp Implementation of the oldest supported pathfinder. */ |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
4 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
5 #include "stdafx.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
6 #include "openttd.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
7 #include "bridge_map.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
8 #include "station_map.h" |
8119
b6ec923e9fa8
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents:
8108
diff
changeset
|
9 #include "tile_cmd.h" |
6453
666fc3ef3174
(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 <maedhros@openttd.org>
parents:
6352
diff
changeset
|
10 #include "landscape.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
11 #include "pathfind.h" |
8103
1721819ad261
(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 <rubidium@openttd.org>
parents:
8088
diff
changeset
|
12 #include "rail_type.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
13 #include "debug.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
14 #include "tunnel_map.h" |
8270
5613b863190d
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium <rubidium@openttd.org>
parents:
8236
diff
changeset
|
15 #include "settings_type.h" |
8083
e02014b06c7f
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz <smatz@openttd.org>
parents:
7971
diff
changeset
|
16 #include "tunnelbridge_map.h" |
8119
b6ec923e9fa8
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents:
8108
diff
changeset
|
17 #include "core/random_func.hpp" |
8925
d0568cbc5bdf
(svn r12695) -Codechange: only allocate window structs when needed. Based on a patch by Alberth.
rubidium <rubidium@openttd.org>
parents:
8804
diff
changeset
|
18 #include "core/alloc_type.hpp" |
8398
a6304b304752
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz <smatz@openttd.org>
parents:
8397
diff
changeset
|
19 #include "tunnelbridge.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
20 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
21 /* remember which tiles we have already visited so we don't visit them again. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
22 static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
23 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
24 uint hash, val, offs; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
25 TrackPathFinderLink *link, *new_link; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
26 uint bits = 1 << dir; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
27 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
28 if (tpf->disable_tile_hash) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
29 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
30 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
31 hash = PATHFIND_HASH_TILE(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
32 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
33 val = tpf->hash_head[hash]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
34 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
35 if (val == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
36 /* unused hash entry, set the appropriate bit in it and return true |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
37 * to indicate that a bit was set. */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
38 tpf->hash_head[hash] = bits; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
39 tpf->hash_tile[hash] = tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
40 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
41 } else if (!(val & 0x8000)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
42 /* single tile */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
43 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
44 if (tile == tpf->hash_tile[hash]) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
45 /* found another bit for the same tile, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
46 * check if this bit is already set, if so, return false */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
47 if (val & bits) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
48 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
49 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
50 /* otherwise set the bit and return true to indicate that the bit |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
51 * was set */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
52 tpf->hash_head[hash] = val | bits; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
53 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
54 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
55 /* two tiles with the same hash, need to make a link */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
56 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
57 /* allocate a link. if out of links, handle this by returning |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
58 * that a tile was already visisted. */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
59 if (tpf->num_links_left == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
60 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
61 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
62 tpf->num_links_left--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
63 link = tpf->new_link++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
64 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
65 /* move the data that was previously in the hash_??? variables |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
66 * to the link struct, and let the hash variables point to the link */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
67 link->tile = tpf->hash_tile[hash]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
68 tpf->hash_tile[hash] = PATHFIND_GET_LINK_OFFS(tpf, link); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
69 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
70 link->flags = tpf->hash_head[hash]; |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
71 tpf->hash_head[hash] = 0xFFFF; // multi link |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
72 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
73 link->next = 0xFFFF; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
74 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
75 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
76 /* a linked list of many tiles, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
77 * find the one corresponding to the tile, if it exists. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
78 * otherwise make a new link */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
79 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
80 offs = tpf->hash_tile[hash]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
81 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
82 link = PATHFIND_GET_LINK_PTR(tpf, offs); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
83 if (tile == link->tile) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
84 /* found the tile in the link list, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
85 * check if the bit was alrady set, if so return false to indicate that the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
86 * bit was already set */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
87 if (link->flags & bits) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
88 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
89 link->flags |= bits; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
90 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
91 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
92 } while ((offs=link->next) != 0xFFFF); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
93 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
94 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
95 /* get here if we need to add a new link to link, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
96 * first, allocate a new link, in the same way as before */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
97 if (tpf->num_links_left == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
98 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
99 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
100 tpf->num_links_left--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
101 new_link = tpf->new_link++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
102 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
103 /* then fill the link with the new info, and establish a ptr from the old |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
104 * link to the new one */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
105 new_link->tile = tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
106 new_link->flags = bits; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
107 new_link->next = 0xFFFF; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
108 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
109 link->next = PATHFIND_GET_LINK_OFFS(tpf, new_link); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
110 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
111 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
112 |
8800
2a908464da27
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch <frosch@openttd.org>
parents:
8798
diff
changeset
|
113 static void TPFModeShip(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
114 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
115 RememberData rd; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
116 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
117 assert(tpf->tracktype == TRANSPORT_WATER); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
118 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
119 /* This addition will sometimes overflow by a single tile. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
120 * The use of TILE_MASK here makes sure that we still point at a valid |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
121 * tile, and then this tile will be in the sentinel row/col, so GetTileTrackStatus will fail. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
122 tile = TILE_MASK(tile + TileOffsByDiagDir(direction)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
123 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
124 if (++tpf->rd.cur_length > 50) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
125 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
126 |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
127 TrackBits bits = TrackStatusToTrackBits(GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type)) & DiagdirReachesTracks(direction); |
8611
6992dec7779c
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch <frosch@openttd.org>
parents:
8480
diff
changeset
|
128 if (bits == TRACK_BIT_NONE) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
129 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
130 assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY()); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
131 |
8611
6992dec7779c
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch <frosch@openttd.org>
parents:
8480
diff
changeset
|
132 bool only_one_track = true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
133 do { |
8611
6992dec7779c
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch <frosch@openttd.org>
parents:
8480
diff
changeset
|
134 Track track = RemoveFirstTrack(&bits); |
6992dec7779c
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch <frosch@openttd.org>
parents:
8480
diff
changeset
|
135 if (bits != TRACK_BIT_NONE) only_one_track = false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
136 rd = tpf->rd; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
137 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
138 /* Change direction 4 times only */ |
8611
6992dec7779c
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch <frosch@openttd.org>
parents:
8480
diff
changeset
|
139 if (!only_one_track && track != tpf->rd.last_choosen_track) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
140 if (++tpf->rd.depth > 4) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
141 tpf->rd = rd; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
142 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
143 } |
8611
6992dec7779c
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch <frosch@openttd.org>
parents:
8480
diff
changeset
|
144 tpf->rd.last_choosen_track = track; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
145 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
146 |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
147 tpf->the_dir = TrackEnterdirToTrackdir(track, direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
148 |
8611
6992dec7779c
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch <frosch@openttd.org>
parents:
8480
diff
changeset
|
149 if (!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length)) { |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
150 TPFModeShip(tpf, tile, TrackdirToExitdir(tpf->the_dir)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
151 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
152 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
153 tpf->rd = rd; |
8611
6992dec7779c
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch <frosch@openttd.org>
parents:
8480
diff
changeset
|
154 } while (bits != TRACK_BIT_NONE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
155 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
156 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
157 |
8396
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
158 /** |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
159 * Checks if any vehicle can enter/leave tile in given diagdir |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
160 * Checks only for rail/road depots and road non-drivethrough stations |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
161 * @param tile tile to check |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
162 * @param side side of tile we are trying to leave/enter |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
163 * @param tracktype type of transport |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
164 * @pre tile has trackbit at that diagdir |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
165 * @return true iff vehicle can enter/leve the tile in given side |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
166 */ |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
167 static inline bool CanAccessTileInDir(TileIndex tile, DiagDirection side, TransportType tracktype) |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
168 { |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
169 if (tracktype == TRANSPORT_RAIL) { |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
170 /* depot from wrong side */ |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
171 if (IsRailDepotTile(tile) && GetRailDepotDirection(tile) != side) return false; |
8396
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
172 } else if (tracktype == TRANSPORT_ROAD) { |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
173 /* depot from wrong side */ |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
174 if (IsRoadDepotTile(tile) && GetRoadDepotDirection(tile) != side) return false; |
8396
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
175 /* non-driverthrough road station from wrong side */ |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
176 if (IsStandardRoadStopTile(tile) && GetRoadStopDir(tile) != side) return false; |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
177 } |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
178 |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
179 return true; |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
180 } |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
181 |
8800
2a908464da27
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch <frosch@openttd.org>
parents:
8798
diff
changeset
|
182 static void TPFModeNormal(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) |
8392
ab6601cad472
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
183 { |
8395
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
184 const TileIndex tile_org = tile; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
185 |
8392
ab6601cad472
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
186 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
8395
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
187 /* wrong track type */ |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
188 if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) return; |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
189 |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
190 DiagDirection dir = GetTunnelBridgeDirection(tile); |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
191 /* entering tunnel / bridge? */ |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
192 if (dir == direction) { |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
193 TileIndex endtile = GetOtherTunnelBridgeEnd(tile); |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
194 |
8398
a6304b304752
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz <smatz@openttd.org>
parents:
8397
diff
changeset
|
195 tpf->rd.cur_length += GetTunnelBridgeLength(tile, endtile) + 1; |
8395
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
196 |
8392
ab6601cad472
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
197 TPFSetTileBit(tpf, tile, 14); |
8395
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
198 TPFSetTileBit(tpf, endtile, 14); |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
199 |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
200 tile = endtile; |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
201 } else { |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
202 /* leaving tunnel / bridge? */ |
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
203 if (ReverseDiagDir(dir) != direction) return; |
8392
ab6601cad472
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
204 } |
8396
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
205 } else { |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
206 /* can we leave tile in this dir? */ |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
207 if (!CanAccessTileInDir(tile, direction, tpf->tracktype)) return; |
8392
ab6601cad472
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
208 } |
8395
11f2a49da775
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
smatz <smatz@openttd.org>
parents:
8392
diff
changeset
|
209 |
8392
ab6601cad472
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
210 tile += TileOffsByDiagDir(direction); |
ab6601cad472
(svn r11962) -Cleanup: OPF is no longer used to update signals
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
211 |
8396
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
212 /* can we enter tile in this dir? */ |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
213 if (!CanAccessTileInDir(tile, ReverseDiagDir(direction), tpf->tracktype)) return; |
e7ec7cd4f47a
(svn r11966) -Fix: OPF was searching through depots and normal road stops
smatz <smatz@openttd.org>
parents:
8395
diff
changeset
|
214 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
215 /* Check if the new tile is a tunnel or bridge head and that the direction |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
216 * and transport type match */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
217 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
8088
5d7c61206209
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz <smatz@openttd.org>
parents:
8083
diff
changeset
|
218 if (GetTunnelBridgeDirection(tile) != direction || |
5d7c61206209
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz <smatz@openttd.org>
parents:
8083
diff
changeset
|
219 GetTunnelBridgeTransportType(tile) != tpf->tracktype) { |
5d7c61206209
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz <smatz@openttd.org>
parents:
8083
diff
changeset
|
220 return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
221 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
222 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
223 |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
224 TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
225 |
8397
9134575844ba
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz <smatz@openttd.org>
parents:
8396
diff
changeset
|
226 /* Check in case of rail if the owner is the same */ |
9134575844ba
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz <smatz@openttd.org>
parents:
8396
diff
changeset
|
227 if (tpf->tracktype == TRANSPORT_RAIL) { |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
228 if (trackdirbits != TRACKDIR_BIT_NONE && TrackStatusToTrackdirBits(GetTileTrackStatus(tile_org, TRANSPORT_RAIL, 0)) != TRACKDIR_BIT_NONE) { |
8397
9134575844ba
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz <smatz@openttd.org>
parents:
8396
diff
changeset
|
229 if (GetTileOwner(tile_org) != GetTileOwner(tile)) return; |
9134575844ba
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz <smatz@openttd.org>
parents:
8396
diff
changeset
|
230 } |
9134575844ba
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz <smatz@openttd.org>
parents:
8396
diff
changeset
|
231 } |
9134575844ba
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz <smatz@openttd.org>
parents:
8396
diff
changeset
|
232 |
9134575844ba
(svn r11967) -Fix (r1400): MP_ROAD can have railbits too - OPF searching over rail of diffent owner behind crossing
smatz <smatz@openttd.org>
parents:
8396
diff
changeset
|
233 tpf->rd.cur_length++; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
234 |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
235 trackdirbits &= DiagdirReachesTrackdirs(direction); |
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
236 TrackBits bits = TrackdirBitsToTrackBits(trackdirbits); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
237 |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
238 if (bits != TRACK_BIT_NONE) { |
7833
f79d18d560b2
(svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight <truelight@openttd.org>
parents:
7081
diff
changeset
|
239 if (!tpf->disable_tile_hash || (tpf->rd.cur_length <= 64 && (KillFirstBit(bits) == 0 || ++tpf->rd.depth <= 7))) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
240 do { |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
241 Track track = RemoveFirstTrack(&bits); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
242 |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
243 tpf->the_dir = TrackEnterdirToTrackdir(track, direction); |
7071
ddb9ef82e02e
(svn r10336) -Fix [FS#910]: reaching the end of a line in certain cases incorrectly stopped signal updates
peter1138 <peter1138@openttd.org>
parents:
6683
diff
changeset
|
244 RememberData rd = tpf->rd; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
245 |
8480
82d7ec66e49f
(svn r12055) -Fix: another way to fix AI trying to build road through depots
smatz <smatz@openttd.org>
parents:
8398
diff
changeset
|
246 /* make sure we are not leaving from invalid side */ |
82d7ec66e49f
(svn r12055) -Fix: another way to fix AI trying to build road through depots
smatz <smatz@openttd.org>
parents:
8398
diff
changeset
|
247 if (TPFSetTileBit(tpf, tile, tpf->the_dir) && CanAccessTileInDir(tile, TrackdirToExitdir(tpf->the_dir), tpf->tracktype) && |
8611
6992dec7779c
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch <frosch@openttd.org>
parents:
8480
diff
changeset
|
248 !tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length) ) { |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
249 TPFModeNormal(tpf, tile, TrackdirToExitdir(tpf->the_dir)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
250 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
251 tpf->rd = rd; |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
252 } while (bits != TRACK_BIT_NONE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
253 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
254 } |
7071
ddb9ef82e02e
(svn r10336) -Fix [FS#910]: reaching the end of a line in certain cases incorrectly stopped signal updates
peter1138 <peter1138@openttd.org>
parents:
6683
diff
changeset
|
255 } |
ddb9ef82e02e
(svn r10336) -Fix [FS#910]: reaching the end of a line in certain cases incorrectly stopped signal updates
peter1138 <peter1138@openttd.org>
parents:
6683
diff
changeset
|
256 |
8800
2a908464da27
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch <frosch@openttd.org>
parents:
8798
diff
changeset
|
257 void FollowTrack(TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
258 { |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
259 assert(IsValidDiagDirection(direction)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
261 SmallStackSafeStackAlloc<TrackPathFinder, 1> tpf; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
262 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
263 /* initialize path finder variables */ |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
264 tpf->userdata = data; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
265 tpf->enum_proc = enum_proc; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
266 tpf->new_link = tpf->links; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
267 tpf->num_links_left = lengthof(tpf->links); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
268 |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
269 tpf->rd.cur_length = 0; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
270 tpf->rd.depth = 0; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
271 tpf->rd.last_choosen_track = INVALID_TRACK; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
272 |
8800
2a908464da27
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch <frosch@openttd.org>
parents:
8798
diff
changeset
|
273 tpf->disable_tile_hash = (flags & PATHFIND_FLAGS_DISABLE_TILE_HASH) != 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
274 |
8800
2a908464da27
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch <frosch@openttd.org>
parents:
8798
diff
changeset
|
275 tpf->tracktype = tt; |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
276 tpf->sub_type = sub_type; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
277 |
8800
2a908464da27
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch <frosch@openttd.org>
parents:
8798
diff
changeset
|
278 if ((flags & PATHFIND_FLAGS_SHIP_MODE) != 0) { |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
279 tpf->enum_proc(tile, data, INVALID_TRACKDIR, 0); |
8800
2a908464da27
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch <frosch@openttd.org>
parents:
8798
diff
changeset
|
280 TPFModeShip(tpf, tile, direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
281 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
282 /* clear the hash_heads */ |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
283 memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); |
8800
2a908464da27
(svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch <frosch@openttd.org>
parents:
8798
diff
changeset
|
284 TPFModeNormal(tpf, tile, direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
285 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
286 |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
287 if (after_proc != NULL) after_proc(tpf); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
288 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
289 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6172
diff
changeset
|
290 struct StackedItem { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
291 TileIndex tile; |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
292 uint16 cur_length; ///< This is the current length to this tile. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
293 uint16 priority; ///< This is the current length + estimated length to the goal. |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
294 TrackdirByte track; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
295 byte depth; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
296 byte state; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
297 byte first_track; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6172
diff
changeset
|
298 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
299 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6172
diff
changeset
|
300 struct HashLink { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
301 TileIndex tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
302 uint16 typelength; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
303 uint16 next; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6172
diff
changeset
|
304 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
305 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6172
diff
changeset
|
306 struct NewTrackPathFinder { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
307 NTPEnumProc *enum_proc; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
308 void *userdata; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
309 TileIndex dest; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
310 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
311 TransportType tracktype; |
8236
d1191295967a
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
312 RailTypes railtypes; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
313 uint maxlength; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
314 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
315 HashLink *new_link; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
316 uint num_links_left; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
317 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
318 uint nstack; |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
319 StackedItem stack[256]; ///< priority queue of stacked items |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
320 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
321 uint16 hash_head[0x400]; ///< hash heads. 0 means unused. 0xFFFC = length, 0x3 = dir |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
322 TileIndex hash_tile[0x400]; ///< tiles. or links. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
323 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
324 HashLink links[0x400]; ///< hash links |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
325 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6172
diff
changeset
|
326 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
327 #define NTP_GET_LINK_OFFS(tpf, link) ((byte*)(link) - (byte*)tpf->links) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
328 #define NTP_GET_LINK_PTR(tpf, link_offs) (HashLink*)((byte*)tpf->links + (link_offs)) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
329 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
330 #define ARR(i) tpf->stack[(i)-1] |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
331 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
332 /** called after a new element was added in the queue at the last index. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
333 * move it down to the proper position */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
334 static inline void HeapifyUp(NewTrackPathFinder *tpf) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
335 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
336 StackedItem si; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
337 int i = ++tpf->nstack; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
338 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
339 while (i != 1 && ARR(i).priority < ARR(i>>1).priority) { |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
340 /* the child element is larger than the parent item. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
341 * swap the child item and the parent item. */ |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
342 si = ARR(i); ARR(i) = ARR(i >> 1); ARR(i >> 1) = si; |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
343 i >>= 1; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
344 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
345 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
346 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
347 /** called after the element 0 was eaten. fill it with a new element */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
348 static inline void HeapifyDown(NewTrackPathFinder *tpf) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
349 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
350 StackedItem si; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
351 int i = 1, j; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
352 int n; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
353 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
354 assert(tpf->nstack > 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
355 n = --tpf->nstack; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
356 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
357 if (n == 0) return; // heap is empty so nothing to do? |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
358 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
359 /* copy the last item to index 0. we use it as base for heapify. */ |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
360 ARR(1) = ARR(n + 1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
361 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
362 while ((j = i * 2) <= n) { |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
363 /* figure out which is smaller of the children. */ |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
364 if (j != n && ARR(j).priority > ARR(j + 1).priority) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
365 j++; // right item is smaller |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
366 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
367 assert(i <= n && j <= n); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
368 if (ARR(i).priority <= ARR(j).priority) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
369 break; // base elem smaller than smallest, done! |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
370 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
371 /* swap parent with the child */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
372 si = ARR(i); ARR(i) = ARR(j); ARR(j) = si; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
373 i = j; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
374 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
375 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
376 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
377 /** mark a tile as visited and store the length of the path. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
378 * if we already had a better path to this tile, return false. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
379 * otherwise return true. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
380 static bool NtpVisit(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection dir, uint length) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
381 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
382 uint hash,head; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
383 HashLink *link, *new_link; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
384 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
385 assert(length < 16384-1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
386 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
387 hash = PATHFIND_HASH_TILE(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
388 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
389 /* never visited before? */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
390 if ((head=tpf->hash_head[hash]) == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
391 tpf->hash_tile[hash] = tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
392 tpf->hash_head[hash] = dir | (length << 2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
393 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
394 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
395 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
396 if (head != 0xffff) { |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
397 if (tile == tpf->hash_tile[hash] && (head & 0x3) == (uint)dir) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
398 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
399 /* longer length */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
400 if (length >= (head >> 2)) return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
401 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
402 tpf->hash_head[hash] = dir | (length << 2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
403 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
404 } |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
405 /* two tiles with the same hash, need to make a link |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
406 * allocate a link. if out of links, handle this by returning |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
407 * that a tile was already visisted. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
408 if (tpf->num_links_left == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
409 DEBUG(ntp, 1, "No links left"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
410 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
411 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
412 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
413 tpf->num_links_left--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
414 link = tpf->new_link++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
415 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
416 /* move the data that was previously in the hash_??? variables |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
417 * to the link struct, and let the hash variables point to the link */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
418 link->tile = tpf->hash_tile[hash]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
419 tpf->hash_tile[hash] = NTP_GET_LINK_OFFS(tpf, link); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
420 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
421 link->typelength = tpf->hash_head[hash]; |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
422 tpf->hash_head[hash] = 0xFFFF; // multi link |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
423 link->next = 0xFFFF; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
424 } else { |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
425 /* a linked list of many tiles, |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
426 * find the one corresponding to the tile, if it exists. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
427 * otherwise make a new link */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
428 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
429 uint offs = tpf->hash_tile[hash]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
430 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
431 link = NTP_GET_LINK_PTR(tpf, offs); |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
432 if (tile == link->tile && (link->typelength & 0x3U) == (uint)dir) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
433 if (length >= (uint)(link->typelength >> 2)) return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
434 link->typelength = dir | (length << 2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
435 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
436 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
437 } while ((offs = link->next) != 0xFFFF); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
438 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
439 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
440 /* get here if we need to add a new link to link, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
441 * first, allocate a new link, in the same way as before */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
442 if (tpf->num_links_left == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
443 DEBUG(ntp, 1, "No links left"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
444 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
445 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
446 tpf->num_links_left--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
447 new_link = tpf->new_link++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
448 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
449 /* then fill the link with the new info, and establish a ptr from the old |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
450 * link to the new one */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
451 new_link->tile = tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
452 new_link->typelength = dir | (length << 2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
453 new_link->next = 0xFFFF; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
454 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
455 link->next = NTP_GET_LINK_OFFS(tpf, new_link); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
456 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
457 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
458 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
459 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
460 * Checks if the shortest path to the given tile/dir so far is still the given |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
461 * length. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
462 * @return true if the length is still the same |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
463 * @pre The given tile/dir combination should be present in the hash, by a |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
464 * previous call to NtpVisit(). |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
465 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
466 static bool NtpCheck(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint length) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
467 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
468 uint hash,head,offs; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
469 HashLink *link; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
470 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
471 hash = PATHFIND_HASH_TILE(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
472 head=tpf->hash_head[hash]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
473 assert(head); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
474 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
475 if (head != 0xffff) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
476 assert( tpf->hash_tile[hash] == tile && (head & 3) == dir); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
477 assert( (head >> 2) <= length); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
478 return length == (head >> 2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
479 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
480 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
481 /* else it's a linked list of many tiles */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
482 offs = tpf->hash_tile[hash]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
483 for (;;) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
484 link = NTP_GET_LINK_PTR(tpf, offs); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
485 if (tile == link->tile && (link->typelength & 0x3U) == dir) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
486 assert((uint)(link->typelength >> 2) <= length); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
487 return length == (uint)(link->typelength >> 2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
488 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
489 offs = link->next; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
490 assert(offs != 0xffff); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
491 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
492 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
493 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
494 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
495 static uint DistanceMoo(TileIndex t0, TileIndex t1) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
496 { |
7970
c49c1607b294
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13 <skidd13@openttd.org>
parents:
7930
diff
changeset
|
497 const uint dx = Delta(TileX(t0), TileX(t1)); |
c49c1607b294
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13 <skidd13@openttd.org>
parents:
7930
diff
changeset
|
498 const uint dy = Delta(TileY(t0), TileY(t1)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
499 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
500 const uint straightTracks = 2 * min(dx, dy); // The number of straight (not full length) tracks |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
501 /* OPTIMISATION: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
502 * Original: diagTracks = max(dx, dy) - min(dx,dy); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
503 * Proof: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
504 * (dx-dy) - straightTracks == (min + max) - straightTracks = min + // max - 2 * min = max - min */ |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
505 const uint diagTracks = dx + dy - straightTracks; // The number of diagonal (full tile length) tracks. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
506 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
507 return diagTracks*DIAG_FACTOR + straightTracks*STR_FACTOR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
508 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
509 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
510 /* These has to be small cause the max length of a track |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
511 * is currently limited to 16384 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
512 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
513 static const byte _length_of_track[16] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
514 DIAG_FACTOR, DIAG_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, 0, 0, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
515 DIAG_FACTOR, DIAG_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, 0, 0 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
516 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
517 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
518 /* new more optimized pathfinder for trains... |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
519 * Tile is the tile the train is at. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
520 * direction is the tile the train is moving towards. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
521 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
522 static void NTPEnum(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection direction) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
523 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
524 TrackBits bits, allbits; |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
525 Trackdir track; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
526 TileIndex tile_org; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
527 StackedItem si; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
528 int estimation; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
529 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
530 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
531 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
532 /* Need to have a special case for the start. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
533 * We shouldn't call the callback for the current tile. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
534 si.cur_length = 1; // Need to start at 1 cause 0 is a reserved value. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
535 si.depth = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
536 si.state = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
537 si.first_track = 0xFF; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
538 goto start_at; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
539 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
540 for (;;) { |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
541 /* Get the next item to search from from the priority queue */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
542 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
543 if (tpf->nstack == 0) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
544 return; // nothing left? then we're done! |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
545 si = tpf->stack[0]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
546 tile = si.tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
547 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
548 HeapifyDown(tpf); |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
549 /* Make sure we havn't already visited this tile. */ |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
550 } while (!NtpCheck(tpf, tile, ReverseDiagDir(TrackdirToExitdir(ReverseTrackdir(si.track))), si.cur_length)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
551 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
552 /* Add the length of this track. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
553 si.cur_length += _length_of_track[si.track]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
554 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
555 callback_and_continue: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
556 if (tpf->enum_proc(tile, tpf->userdata, si.first_track, si.cur_length)) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
557 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
558 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
559 assert(si.track <= 13); |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
560 direction = TrackdirToExitdir(si.track); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
561 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
562 start_at: |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
563 /* If the tile is the entry tile of a tunnel, and we're not going out of the tunnel, |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
564 * need to find the exit of the tunnel. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
565 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
8682
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
566 if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) { |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
567 /* We are not just driving out of the tunnel/bridge */ |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
568 if (GetTunnelBridgeDirection(tile) != direction || |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
569 GetTunnelBridgeTransportType(tile) != tpf->tracktype) { |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
570 /* We are not driving into the tunnel/bridge, or it is an invalid tunnel/bridge */ |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
571 continue; |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
572 } |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
573 if (!HasBit(tpf->railtypes, GetRailType(tile))) { |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
574 bits = TRACK_BIT_NONE; |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
575 break; |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
576 } |
8398
a6304b304752
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz <smatz@openttd.org>
parents:
8397
diff
changeset
|
577 |
8682
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
578 TileIndex endtile = GetOtherTunnelBridgeEnd(tile); |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
579 si.cur_length += DIAG_FACTOR * (GetTunnelBridgeLength(tile, endtile) + 1); |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
580 tile = endtile; |
40efe8e42f8f
(svn r12348) -Fix (r7573): NTP skipped junction just after bridge end
smatz <smatz@openttd.org>
parents:
8653
diff
changeset
|
581 /* tile now points to the exit tile of the tunnel/bridge */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
582 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
583 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
584 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
585 /* This is a special loop used to go through |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
586 * a rail net and find the first intersection */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
587 tile_org = tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
588 for (;;) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
589 assert(direction <= 3); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
590 tile += TileOffsByDiagDir(direction); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
591 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
592 /* too long search length? bail out. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
593 if (si.cur_length >= tpf->maxlength) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
594 DEBUG(ntp, 1, "Cur_length too big"); |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
595 bits = TRACK_BIT_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
596 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
597 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
598 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
599 /* Not a regular rail tile? |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
600 * Then we can't use the code below, but revert to more general code. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
601 if (!IsTileType(tile, MP_RAILWAY) || !IsPlainRailTile(tile)) { |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
602 /* We found a tile which is not a normal railway tile. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
603 * Determine which tracks that exist on this tile. */ |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
604 bits = TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)) & DiagdirReachesTrackdirs(direction)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
605 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
606 /* Check that the tile contains exactly one track */ |
7833
f79d18d560b2
(svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight <truelight@openttd.org>
parents:
7081
diff
changeset
|
607 if (bits == 0 || KillFirstBit(bits) != 0) break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
608 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7833
diff
changeset
|
609 if (!HasBit(tpf->railtypes, GetRailType(tile))) { |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
610 bits = TRACK_BIT_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
611 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
612 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
613 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
614 /******************* |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
615 * If we reach here, the tile has exactly one track. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
616 * tile - index to a tile that is not rail tile, but still straight (with optional signals) |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
617 * bits - bitmask of which track that exist on the tile (exactly one bit is set) |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
618 * direction - which direction are we moving in? |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
619 *******************/ |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
620 si.track = TrackEnterdirToTrackdir(FindFirstTrack(bits), direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
621 si.cur_length += _length_of_track[si.track]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
622 goto callback_and_continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
623 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
624 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
625 /* Regular rail tile, determine which tracks exist. */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
626 allbits = GetTrackBits(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
627 /* Which tracks are reachable? */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
628 bits = allbits & DiagdirReachesTracks(direction); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
629 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
630 /* The tile has no reachable tracks => End of rail segment |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
631 * or Intersection => End of rail segment. We check this agains all the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
632 * bits, not just reachable ones, to prevent infinite loops. */ |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
633 if (bits == TRACK_BIT_NONE || TracksOverlap(allbits)) break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
634 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7833
diff
changeset
|
635 if (!HasBit(tpf->railtypes, GetRailType(tile))) { |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
636 bits = TRACK_BIT_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
637 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
638 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
639 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
640 /* If we reach here, the tile has exactly one track, and this |
6491
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6453
diff
changeset
|
641 track is reachable = > Rail segment continues */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
642 |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
643 track = TrackEnterdirToTrackdir(FindFirstTrack(bits), direction); |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
644 assert(track != INVALID_TRACKDIR); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
645 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
646 si.cur_length += _length_of_track[track]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
647 |
8653
af7d072af3e4
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch <frosch@openttd.org>
parents:
8616
diff
changeset
|
648 /* Check if this rail is an upwards slope. If it is, then add a penalty. */ |
af7d072af3e4
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch <frosch@openttd.org>
parents:
8616
diff
changeset
|
649 if (IsDiagonalTrackdir(track) && IsUphillTrackdir(GetTileSlope(tile, NULL), track)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
650 // upwards slope. add some penalty. |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
651 si.cur_length += 4 * DIAG_FACTOR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
652 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
653 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
654 /* railway tile with signals..? */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
655 if (HasSignals(tile)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
656 if (!HasSignalOnTrackdir(tile, track)) { |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
657 /* if one way signal not pointing towards us, stop going in this direction => End of rail segment. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
658 if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) { |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
659 bits = TRACK_BIT_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
660 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
661 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
662 } else if (GetSignalStateByTrackdir(tile, track) == SIGNAL_STATE_GREEN) { |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
663 /* green signal in our direction. either one way or two way. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
664 si.state |= 3; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
665 } else { |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
666 /* reached a red signal. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
667 if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) { |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
668 /* two way red signal. unless we passed another green signal on the way, |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
669 * stop going in this direction => End of rail segment. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
670 * this is to prevent us from going into a full platform. */ |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
671 if (!(si.state & 1)) { |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
672 bits = TRACK_BIT_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
673 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
674 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
675 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
676 if (!(si.state & 2)) { |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
677 /* Is this the first signal we see? And it's red... add penalty */ |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
678 si.cur_length += 10 * DIAG_FACTOR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
679 si.state += 2; // remember that we added penalty. |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
680 /* Because we added a penalty, we can't just continue as usual. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
681 * Need to get out and let A* do it's job with |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
682 * possibly finding an even shorter path. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
683 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
684 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
685 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
686 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
687 if (tpf->enum_proc(tile, tpf->userdata, si.first_track, si.cur_length)) |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
688 return; // Don't process this tile any further |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
689 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
690 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
691 /* continue with the next track */ |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
692 direction = TrackdirToExitdir(track); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
693 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
694 /* safety check if we're running around chasing our tail... (infinite loop) */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
695 if (tile == tile_org) { |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
696 bits = TRACK_BIT_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
697 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
698 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
699 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
700 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
701 /* There are no tracks to choose between. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
702 * Stop searching in this direction */ |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
703 if (bits == TRACK_BIT_NONE) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
704 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
705 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
706 /**************** |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
707 * We got multiple tracks to choose between (intersection). |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
708 * Branch the search space into several branches. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
709 ****************/ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
710 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
711 /* Check if we've already visited this intersection. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
712 * If we've already visited it with a better length, then |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
713 * there's no point in visiting it again. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
714 if (!NtpVisit(tpf, tile, direction, si.cur_length)) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
715 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
716 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
717 /* Push all possible alternatives that we can reach from here |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
718 * onto the priority heap. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
719 * 'bits' contains the tracks that we can choose between. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
720 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
721 /* First compute the estimated distance to the target. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
722 * This is used to implement A* */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
723 estimation = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
724 if (tpf->dest != 0) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
725 estimation = DistanceMoo(tile, tpf->dest); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
726 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
727 si.depth++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
728 if (si.depth == 0) |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
729 continue; // We overflowed our depth. No more searching in this direction. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
730 si.tile = tile; |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
731 while (bits != TRACK_BIT_NONE) { |
5598
b73ad40222d0
(svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr <KUDr@openttd.org>
parents:
5587
diff
changeset
|
732 Track track = RemoveFirstTrack(&bits); |
8804
e8c073db0351
(svn r12545) -Cleanup: Replace some tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8800
diff
changeset
|
733 si.track = TrackEnterdirToTrackdir(track, direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
734 assert(si.track != 0xFF); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
735 si.priority = si.cur_length + estimation; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
736 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
737 /* out of stack items, bail out? */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
738 if (tpf->nstack >= lengthof(tpf->stack)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
739 DEBUG(ntp, 1, "Out of stack"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
740 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
741 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
742 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
743 tpf->stack[tpf->nstack] = si; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
744 HeapifyUp(tpf); |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
745 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
746 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
747 /* If this is the first intersection, we need to fill the first_track member. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
748 * so the code outside knows which path is better. |
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
749 * also randomize the order in which we search through them. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
750 if (si.depth == 1) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
751 assert(tpf->nstack == 1 || tpf->nstack == 2 || tpf->nstack == 3); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
752 if (tpf->nstack != 1) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
753 uint32 r = Random(); |
5733 | 754 if (r & 1) Swap(tpf->stack[0].track, tpf->stack[1].track); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
755 if (tpf->nstack != 2) { |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
756 TrackdirByte t = tpf->stack[2].track; |
5733 | 757 if (r & 2) Swap(tpf->stack[0].track, t); |
758 if (r & 4) Swap(tpf->stack[1].track, t); | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
759 tpf->stack[2].first_track = tpf->stack[2].track = t; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
760 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
761 tpf->stack[0].first_track = tpf->stack[0].track; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
762 tpf->stack[1].first_track = tpf->stack[1].track; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
763 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
764 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
765 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
766 /* Continue with the next from the queue... */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
767 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
768 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
769 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
770 |
6352
d646bb89ca43
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
771 /** new pathfinder for trains. better and faster. */ |
8236
d1191295967a
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
772 void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
773 { |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
774 SmallStackSafeStackAlloc<NewTrackPathFinder, 1> tpf; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
775 |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
776 tpf->dest = dest; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
777 tpf->userdata = data; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
778 tpf->enum_proc = enum_proc; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
779 tpf->tracktype = TRANSPORT_RAIL; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
780 tpf->railtypes = railtypes; |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9354
diff
changeset
|
781 tpf->maxlength = min(_settings_game.pf.opf.pf_maxlength * 3, 10000); |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
782 tpf->nstack = 0; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
783 tpf->new_link = tpf->links; |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
784 tpf->num_links_left = lengthof(tpf->links); |
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
785 memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
786 |
8798
20105469cefe
(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 <rubidium@openttd.org>
parents:
8682
diff
changeset
|
787 NTPEnum(tpf, tile, direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
788 } |