author | matthijs |
Mon, 23 May 2005 19:00:16 +0000 | |
changeset 1857 | f07b4fc6c4bf |
parent 1777 | f703cf05b5b9 |
child 1891 | 862800791170 |
permissions | -rw-r--r-- |
1247 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1248
diff
changeset
|
3 |
#include "debug.h" |
1247 | 4 |
#include "npf.h" |
5 |
#include "aystar.h" |
|
6 |
#include "macros.h" |
|
7 |
#include "pathfind.h" |
|
8 |
#include "station.h" |
|
9 |
#include "tile.h" |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
10 |
#include "depot.h" |
1247 | 11 |
|
12 |
AyStar _train_find_station; |
|
13 |
AyStar _train_find_depot; |
|
14 |
AyStar _road_find_station; |
|
15 |
AyStar _road_find_depot; |
|
16 |
AyStar _npf_aystar; |
|
17 |
||
18 |
/* Maps a trackdir to the bit that stores its status in the map arrays, in the |
|
19 |
* direction along with the trackdir */ |
|
20 |
const byte _signal_along_trackdir[14] = { |
|
21 |
0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0, |
|
22 |
0x40, 0x40, 0x40, 0x10, 0x80, 0x20 |
|
23 |
}; |
|
24 |
||
25 |
/* Maps a trackdir to the bit that stores its status in the map arrays, in the |
|
26 |
* direction against the trackdir */ |
|
27 |
const byte _signal_against_trackdir[14] = { |
|
28 |
0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0, |
|
29 |
0x80, 0x80, 0x80, 0x20, 0x40, 0x10 |
|
30 |
}; |
|
31 |
||
32 |
/* Maps a trackdir to the trackdirs that can be reached from it (ie, when |
|
33 |
* entering the next tile */ |
|
34 |
const uint16 _trackdir_reaches_trackdirs[14] = { |
|
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
35 |
0x1009, 0x0016, 0x1009, 0x0016, 0x0520, 0x0016, 0, 0, |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
36 |
0x0520, 0x2A00, 0x2A00, 0x0520, 0x2A00, 0x1009 |
1247 | 37 |
}; |
38 |
||
1751
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
39 |
const uint16 _next_trackdir[14] = { |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
40 |
0, 1, 3, 2, 5, 4, 0, 0, |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
41 |
8, 9, 11, 10, 13, 12 |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
42 |
}; |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
43 |
|
1247 | 44 |
/* Maps a trackdir to all trackdirs that make 90 deg turns with it. */ |
45 |
const uint16 _trackdir_crosses_trackdirs[14] = { |
|
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
46 |
0x0202, 0x0101, 0x3030, 0x3030, 0x0C0C, 0x0C0C, 0, 0, |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
47 |
0x0202, 0x0101, 0x3030, 0x3030, 0x0C0C, 0x0C0C |
1247 | 48 |
}; |
49 |
||
50 |
/* Maps a track to all tracks that make 90 deg turns with it. */ |
|
51 |
const byte _track_crosses_tracks[6] = { |
|
52 |
0x2, /* Track 1 -> Track 2 */ |
|
53 |
0x1, /* Track 2 -> Track 1 */ |
|
54 |
0x30, /* Upper -> Left | Right */ |
|
55 |
0x30, /* Lower -> Left | Right */ |
|
56 |
0x0C, /* Left -> Upper | Lower */ |
|
57 |
0x0C, /* Right -> Upper | Lower */ |
|
58 |
}; |
|
59 |
||
60 |
/* Maps a trackdir to the (4-way) direction the tile is exited when following |
|
61 |
* that trackdir */ |
|
62 |
const byte _trackdir_to_exitdir[14] = { |
|
63 |
0,1,0,1,2,1, 0,0, |
|
64 |
2,3,3,2,3,0, |
|
65 |
}; |
|
66 |
||
67 |
const byte _track_exitdir_to_trackdir[6][4] = { |
|
68 |
{0, 0xff, 8, 0xff}, |
|
69 |
{0xff, 1, 0xff, 9}, |
|
70 |
{2, 0xff, 0xff, 10}, |
|
71 |
{0xff, 3, 11, 0xf}, |
|
72 |
{0xff, 0xff, 4, 12}, |
|
73 |
{13, 5, 0xff, 0xff} |
|
74 |
}; |
|
75 |
||
76 |
const byte _track_direction_to_trackdir[6][8] = { |
|
77 |
{0xff, 0, 0xff, 0xff, 0xff, 8, 0xff, 0xff}, |
|
78 |
{0xff, 0xff, 0xff, 1, 0xff, 0xff, 0xff, 9}, |
|
79 |
{0xff, 0xff, 2, 0xff, 0xff, 0xff, 10, 0xff}, |
|
80 |
{0xff, 0xff, 3, 0xff, 0xff, 0xff, 11, 0xff}, |
|
81 |
{12, 0xff, 0xff, 0xff, 4, 0xff, 0xff, 0xff}, |
|
82 |
{13, 0xff, 0xff, 0xff, 5, 0xff, 0xff, 0xff} |
|
83 |
}; |
|
84 |
||
85 |
const byte _dir_to_diag_trackdir[4] = { |
|
86 |
0, 1, 8, 9, |
|
87 |
}; |
|
88 |
||
89 |
const byte _reverse_dir[4] = { |
|
90 |
2, 3, 0, 1 |
|
91 |
}; |
|
92 |
||
93 |
const byte _reverse_trackdir[14] = { |
|
94 |
8, 9, 10, 11, 12, 13, 0xFF, 0xFF, |
|
95 |
0, 1, 2, 3, 4, 5 |
|
96 |
}; |
|
97 |
||
98 |
/* The cost of each trackdir. A diagonal piece is the full NPF_TILE_LENGTH, |
|
99 |
* the shorter piece is sqrt(2)/2*NPF_TILE_LENGTH =~ 0.7071 |
|
100 |
*/ |
|
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1661
diff
changeset
|
101 |
#define NPF_STRAIGHT_LENGTH (uint)(NPF_TILE_LENGTH * STRAIGHT_TRACK_LENGTH) |
1247 | 102 |
static const uint _trackdir_length[14] = { |
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
103 |
NPF_TILE_LENGTH, NPF_TILE_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
104 |
0, 0, |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
105 |
NPF_TILE_LENGTH, NPF_TILE_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH |
1247 | 106 |
}; |
107 |
||
108 |
uint NTPHash(uint key1, uint key2) |
|
109 |
{ |
|
1661
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
110 |
/* This function uses the old hash, which is fixed on 10 bits (1024 buckets) */ |
1247 | 111 |
return PATHFIND_HASH_TILE(key1); |
112 |
} |
|
113 |
||
1661
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
114 |
uint NPFHash(uint key1, uint key2) |
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
115 |
{ |
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
116 |
/* TODO: think of a better hash? */ |
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
117 |
uint part1 = TileX(key1) & NPF_HASH_HALFMASK; |
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
118 |
uint part2 = TileY(key1) & NPF_HASH_HALFMASK; |
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
119 |
/* The value of 14 below is based on the maximum value of key2 (13) */ |
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
120 |
return ((((part1 << NPF_HASH_HALFBITS) | part2)) + (NPF_HASH_SIZE * key2 / 14)) % NPF_HASH_SIZE; |
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
121 |
} |
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
122 |
|
1247 | 123 |
int32 NPFCalcZero(AyStar* as, AyStarNode* current, OpenListNode* parent) { |
124 |
return 0; |
|
125 |
} |
|
126 |
||
1452
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
127 |
/* Calcs the tile of given station that is closest to a given tile |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
128 |
* for this we assume the station is a rectangle, |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
129 |
* as defined by its top tile (st->train_tile) and its width/height (st->trainst_w, st->trainst_h) |
1247 | 130 |
*/ |
1452
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
131 |
TileIndex CalcClosestStationTile(int station, TileIndex tile) { |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
132 |
const Station* st = GetStation(station); |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
133 |
|
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
134 |
int x1,x2,x3,tx; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
135 |
int y1,y2,y3,ty; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
136 |
|
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
137 |
x1 = TileX(st->train_tile); y1 = TileY(st->train_tile); // topmost corner of station |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
138 |
x2 = x1 + st->trainst_w - 1; y2 = y1 + st->trainst_h - 1; // lowermost corner of station |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
139 |
x3 = TileX(tile); y3 = TileY(tile); // tile we take the distance from |
1452
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
140 |
|
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
141 |
// we are going the aim for the x coordinate of the closest corner |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
142 |
// but if we are between those coordinates, we will aim for our own x coordinate |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
143 |
if (x3 < x1) |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
144 |
tx = x1; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
145 |
else if (x3 > x2) |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
146 |
tx = x2; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
147 |
else |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
148 |
tx = x3; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
149 |
|
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
150 |
// same for y coordinate, see above comment |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
151 |
if (y3 < y1) |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
152 |
ty = y1; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
153 |
else if (y3 > y2) |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
154 |
ty = y2; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
155 |
else |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
156 |
ty = y3; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
157 |
|
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
158 |
// return the tile of our target coordinates |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
159 |
return TILE_XY(tx,ty); |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
160 |
}; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
161 |
|
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1661
diff
changeset
|
162 |
/* Calcs the heuristic to the target station or tile. For train stations, it |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1661
diff
changeset
|
163 |
* takes into account the direction of approach. |
1452
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
164 |
*/ |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
165 |
int32 NPFCalcStationOrTileHeuristic(AyStar* as, AyStarNode* current, OpenListNode* parent) { |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
166 |
NPFFindStationOrTileData* fstd = (NPFFindStationOrTileData*)as->user_target; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
167 |
NPFFoundTargetData* ftd = (NPFFoundTargetData*)as->user_path; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
168 |
TileIndex from = current->tile; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
169 |
TileIndex to = fstd->dest_coords; |
1453 | 170 |
uint dist; |
1452
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
171 |
|
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
172 |
// for train-stations, we are going to aim for the closest station tile |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
173 |
if ((as->user_data[NPF_TYPE] == TRANSPORT_RAIL) && (fstd->station_index != -1)) |
1453 | 174 |
to = CalcClosestStationTile(fstd->station_index, from); |
1452
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
175 |
|
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1661
diff
changeset
|
176 |
if (as->user_data[NPF_TYPE] == TRANSPORT_ROAD) |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1661
diff
changeset
|
177 |
/* Since roads only have diagonal pieces, we use manhattan distance here */ |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1661
diff
changeset
|
178 |
dist = DistanceManhattan(from, to) * NPF_TILE_LENGTH; |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1661
diff
changeset
|
179 |
else |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1661
diff
changeset
|
180 |
/* Ships and trains can also go diagonal, so the minimum distance is shorter */ |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1661
diff
changeset
|
181 |
dist = DistanceTrack(from, to) * NPF_TILE_LENGTH; |
1452
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
182 |
|
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
183 |
if (dist < ftd->best_bird_dist) { |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
184 |
ftd->best_bird_dist = dist; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
185 |
ftd->best_trackdir = current->user_data[NPF_TRACKDIR_CHOICE]; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
186 |
} |
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
187 |
DEBUG(npf, 4)("Calculating H for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), dist); |
1452
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
188 |
return dist; |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
189 |
} |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
190 |
|
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
191 |
|
1247 | 192 |
/* Fills AyStarNode.user_data[NPF_TRACKDIRCHOICE] with the chosen direction to |
193 |
* get here, either getting it from the current choice or from the parent's |
|
194 |
* choice */ |
|
195 |
void NPFFillTrackdirChoice(AyStarNode* current, OpenListNode* parent) |
|
196 |
{ |
|
197 |
if (parent->path.parent == NULL) { |
|
198 |
byte trackdir = current->direction; |
|
199 |
/* This is a first order decision, so we'd better save the |
|
200 |
* direction we chose */ |
|
201 |
current->user_data[NPF_TRACKDIR_CHOICE] = trackdir; |
|
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
202 |
DEBUG(npf, 6)("Saving trackdir: %#x", trackdir); |
1247 | 203 |
} else { |
204 |
/* We've already made the decision, so just save our parent's |
|
205 |
* decision */ |
|
206 |
current->user_data[NPF_TRACKDIR_CHOICE] = parent->path.node.user_data[NPF_TRACKDIR_CHOICE]; |
|
207 |
} |
|
208 |
||
209 |
} |
|
210 |
||
211 |
/* Will return the cost of the tunnel. If it is an entry, it will return the |
|
212 |
* cost of that tile. If the tile is an exit, it will return the tunnel length |
|
213 |
* including the exit tile. Requires that this is a Tunnel tile */ |
|
214 |
uint NPFTunnelCost(AyStarNode* current) { |
|
215 |
byte exitdir = _trackdir_to_exitdir[current->direction]; |
|
216 |
TileIndex tile = current->tile; |
|
217 |
if ( (uint)(_map5[tile] & 3) == _reverse_dir[exitdir]) { |
|
218 |
/* We just popped out if this tunnel, since were |
|
219 |
* facing the tunnel exit */ |
|
220 |
FindLengthOfTunnelResult flotr; |
|
221 |
flotr = FindLengthOfTunnel(tile, _reverse_dir[exitdir]); |
|
222 |
return flotr.length * NPF_TILE_LENGTH; |
|
223 |
//TODO: Penalty for tunnels? |
|
224 |
} else { |
|
225 |
/* We are entering the tunnel, the enter tile is just a |
|
226 |
* straight track */ |
|
227 |
return NPF_TILE_LENGTH; |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
uint NPFSlopeCost(AyStarNode* current) { |
|
232 |
TileIndex next = current->tile + TileOffsByDir(_trackdir_to_exitdir[current->direction]); |
|
1503
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
233 |
int x,y; |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
234 |
int8 z1,z2; |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
235 |
|
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
236 |
x = TileX(current->tile) * 16; |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
237 |
y = TileY(current->tile) * 16; |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
238 |
z1 = GetSlopeZ(x+8, y+8); |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
239 |
|
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
240 |
x = TileX(next) * 16; |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
241 |
y = TileY(next) * 16; |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
242 |
z2 = GetSlopeZ(x+8, y+8); |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
243 |
|
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
244 |
if ((z2 - z1) > 1) { |
1247 | 245 |
/* Slope up */ |
246 |
return _patches.npf_rail_slope_penalty; |
|
247 |
} |
|
248 |
return 0; |
|
249 |
/* Should we give a bonus for slope down? Probably not, we |
|
250 |
* could just substract that bonus from the penalty, because |
|
251 |
* there is only one level of steepness... */ |
|
252 |
} |
|
253 |
||
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
254 |
/* Mark tiles by mowing the grass when npf debug level >= 1 */ |
1247 | 255 |
void NPFMarkTile(TileIndex tile) { |
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
256 |
#ifdef NO_DEBUG_MESSAGES |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
257 |
return; |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
258 |
#else |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
259 |
if (_debug_npf_level >= 1) |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
260 |
switch(GetTileType(tile)) { |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
261 |
case MP_RAILWAY: |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
262 |
/* DEBUG: mark visited tiles by mowing the grass under them |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
263 |
* ;-) */ |
1753
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
264 |
if (!IsTileDepotType(tile, TRANSPORT_RAIL)) { |
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
265 |
_map2[tile] &= ~15; /* Clear bits 0-3 */ |
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
266 |
MarkTileDirtyByTile(tile); |
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
267 |
} |
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
268 |
break; |
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
269 |
case MP_STREET: |
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
270 |
if (!IsTileDepotType(tile, TRANSPORT_ROAD)) { |
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
271 |
_map3_hi[tile] &= ~0x70; /* Clear bits 4-6 */ |
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
272 |
MarkTileDirtyByTile(tile); |
270374d3297f
(svn r2257) - Fix: [NPF] NPF debug markings modify _map2 instead of _map3_hi for street tiles, corrupting them.
matthijs
parents:
1751
diff
changeset
|
273 |
} |
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
274 |
break; |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
275 |
default: |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
276 |
break; |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
277 |
} |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
278 |
#endif |
1247 | 279 |
} |
280 |
||
281 |
int32 NPFWaterPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) { |
|
282 |
//TileIndex tile = current->tile; |
|
283 |
int32 cost = 0; |
|
284 |
byte trackdir = current->direction; |
|
285 |
||
286 |
cost = _trackdir_length[trackdir]; /* Should be different for diagonal tracks */ |
|
287 |
||
1751
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
288 |
if (IsBuoyTile(current->tile) && IsDiagonalTrackdir(current->direction)) |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
289 |
cost += _patches.npf_buoy_penalty; /* A small penalty for going over buoys */ |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
290 |
|
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
291 |
if (current->direction != _next_trackdir[parent->path.node.direction]) |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
292 |
cost += _patches.npf_water_curve_penalty; |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
293 |
|
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
294 |
/* TODO More penalties? */ |
1247 | 295 |
|
296 |
return cost; |
|
297 |
} |
|
298 |
||
299 |
/* Determine the cost of this node, for road tracks */ |
|
300 |
int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) { |
|
301 |
TileIndex tile = current->tile; |
|
302 |
int32 cost = 0; |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
303 |
|
1247 | 304 |
/* Determine base length */ |
305 |
switch (GetTileType(tile)) { |
|
306 |
case MP_TUNNELBRIDGE: |
|
307 |
if ((_map5[tile] & 0xF0)==0) { |
|
308 |
cost = NPFTunnelCost(current); |
|
309 |
break; |
|
310 |
} |
|
311 |
/* Fall through if above if is false, it is a bridge |
|
312 |
* then. We treat that as ordinary rail */ |
|
313 |
case MP_STREET: |
|
314 |
cost = NPF_TILE_LENGTH; |
|
315 |
break; |
|
316 |
default: |
|
317 |
break; |
|
318 |
} |
|
319 |
||
320 |
/* Determine extra costs */ |
|
321 |
||
322 |
/* Check for slope */ |
|
323 |
cost += NPFSlopeCost(current); |
|
324 |
||
325 |
/* Check for turns */ |
|
326 |
//TODO |
|
327 |
||
328 |
NPFMarkTile(tile); |
|
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
329 |
DEBUG(npf, 4)("Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost); |
1247 | 330 |
return cost; |
331 |
} |
|
332 |
||
333 |
||
334 |
/* Determine the cost of this node, for railway tracks */ |
|
335 |
int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) { |
|
336 |
TileIndex tile = current->tile; |
|
337 |
byte trackdir = current->direction; |
|
338 |
int32 cost = 0; |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
339 |
/* HACK: We create a OpenListNode manualy, so we can call EndNodeCheck */ |
1617
c3d3caad6d1e
(svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents:
1503
diff
changeset
|
340 |
OpenListNode new_node; |
c3d3caad6d1e
(svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents:
1503
diff
changeset
|
341 |
|
1247 | 342 |
/* Determine base length */ |
343 |
switch (GetTileType(tile)) { |
|
344 |
case MP_TUNNELBRIDGE: |
|
345 |
if ((_map5[tile] & 0xF0)==0) { |
|
346 |
cost = NPFTunnelCost(current); |
|
347 |
break; |
|
348 |
} |
|
349 |
/* Fall through if above if is false, it is a bridge |
|
350 |
* then. We treat that as ordinary rail */ |
|
351 |
case MP_RAILWAY: |
|
352 |
cost = _trackdir_length[trackdir]; /* Should be different for diagonal tracks */ |
|
353 |
break; |
|
354 |
case MP_STREET: /* Railway crossing */ |
|
355 |
cost = NPF_TILE_LENGTH; |
|
356 |
break; |
|
1503
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
357 |
case MP_STATION: |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
358 |
/* We give a station tile a penalty. Logically we would only |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
359 |
* want to give station tiles that are not our destination |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
360 |
* this penalty. This would discourage trains to drive through |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
361 |
* busy stations. But, we can just give any station tile a |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
362 |
* penalty, because every possible route will get this penalty |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
363 |
* exactly once, on its end tile (if it's a station) and it |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
364 |
* will therefore not make a difference. */ |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
365 |
cost = NPF_TILE_LENGTH + _patches.npf_rail_station_penalty; |
39d0f85977cf
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
matthijs
parents:
1502
diff
changeset
|
366 |
break; |
1247 | 367 |
default: |
368 |
break; |
|
369 |
} |
|
370 |
||
371 |
/* Determine extra costs */ |
|
372 |
||
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
373 |
/* Check for signals */ |
1502
620b1d5904c4
(svn r2006) - Fix: [NPF] Wrong signal detection for last signal red detection. Multiple tracks per tile with only one signal were detected wrong. (HackyKid)
matthijs
parents:
1464
diff
changeset
|
374 |
if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xC0) == 0x40 && (_map3_lo[tile] & _signal_along_trackdir[trackdir]) != 0) { |
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
375 |
/* Ordinary track with signals */ |
1247 | 376 |
if ((_map2[tile] & _signal_along_trackdir[trackdir]) == 0) { |
377 |
/* Signal facing us is red */ |
|
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
378 |
if (!NPFGetFlag(current, NPF_FLAG_SEEN_SIGNAL)) { |
1247 | 379 |
/* Penalize the first signal we |
380 |
* encounter, if it is red */ |
|
1643
420cad9e62e4
(svn r2147) - Add: [NPF] Give red presignal exit signals a different (higher) penalty, to discourage trains from waiting at presignal exits.
matthijs
parents:
1617
diff
changeset
|
381 |
|
420cad9e62e4
(svn r2147) - Add: [NPF] Give red presignal exit signals a different (higher) penalty, to discourage trains from waiting at presignal exits.
matthijs
parents:
1617
diff
changeset
|
382 |
/* Is this a presignal exit or combo? */ |
420cad9e62e4
(svn r2147) - Add: [NPF] Give red presignal exit signals a different (higher) penalty, to discourage trains from waiting at presignal exits.
matthijs
parents:
1617
diff
changeset
|
383 |
if ((_map3_hi[tile] & 0x3) == 0x2 || (_map3_hi[tile] & 0x3) == 0x3) |
420cad9e62e4
(svn r2147) - Add: [NPF] Give red presignal exit signals a different (higher) penalty, to discourage trains from waiting at presignal exits.
matthijs
parents:
1617
diff
changeset
|
384 |
/* Penalise exit and combo signals differently (heavier) */ |
420cad9e62e4
(svn r2147) - Add: [NPF] Give red presignal exit signals a different (higher) penalty, to discourage trains from waiting at presignal exits.
matthijs
parents:
1617
diff
changeset
|
385 |
cost += _patches.npf_rail_firstred_exit_penalty; |
420cad9e62e4
(svn r2147) - Add: [NPF] Give red presignal exit signals a different (higher) penalty, to discourage trains from waiting at presignal exits.
matthijs
parents:
1617
diff
changeset
|
386 |
else |
420cad9e62e4
(svn r2147) - Add: [NPF] Give red presignal exit signals a different (higher) penalty, to discourage trains from waiting at presignal exits.
matthijs
parents:
1617
diff
changeset
|
387 |
cost += _patches.npf_rail_firstred_penalty; |
1247 | 388 |
} |
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
389 |
/* Record the state of this signal */ |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
390 |
NPFSetFlag(current, NPF_FLAG_LAST_SIGNAL_RED, true); |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
391 |
} else { |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
392 |
/* Record the state of this signal */ |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
393 |
NPFSetFlag(current, NPF_FLAG_LAST_SIGNAL_RED, false); |
1247 | 394 |
} |
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
395 |
NPFSetFlag(current, NPF_FLAG_SEEN_SIGNAL, true); |
1247 | 396 |
} |
397 |
||
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
398 |
/* Penalise the tile if it is a target tile and the last signal was |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
399 |
* red */ |
1617
c3d3caad6d1e
(svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents:
1503
diff
changeset
|
400 |
new_node.path.node = *current; |
c3d3caad6d1e
(svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents:
1503
diff
changeset
|
401 |
if (as->EndNodeCheck(as, &new_node)==AYSTAR_FOUND_END_NODE && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED)) |
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
402 |
cost += _patches.npf_rail_lastred_penalty; |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
403 |
|
1247 | 404 |
/* Check for slope */ |
405 |
cost += NPFSlopeCost(current); |
|
406 |
||
407 |
/* Check for turns */ |
|
1751
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1749
diff
changeset
|
408 |
if (current->direction != _next_trackdir[parent->path.node.direction]) |
1460 | 409 |
cost += _patches.npf_rail_curve_penalty; |
410 |
//TODO, with realistic acceleration, also the amount of straight track between |
|
411 |
// curves should be taken into account, as this affects the speed limit. |
|
1247 | 412 |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
413 |
/* Check for reverse in depot */ |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
414 |
if (IsTileDepotType(tile, TRANSPORT_RAIL) && !as->EndNodeCheck(as, &new_node)==AYSTAR_FOUND_END_NODE) |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
415 |
/* Penalise any depot tile that is not the last tile in the path. This |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
416 |
* _should_ penalise every occurence of reversing in a depot (and only |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
417 |
* that) */ |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
418 |
cost += _patches.npf_rail_depot_reverse_penalty; |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
419 |
|
1247 | 420 |
/* Check for occupied track */ |
421 |
//TODO |
|
422 |
||
423 |
NPFMarkTile(tile); |
|
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
424 |
DEBUG(npf, 4)("Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost); |
1247 | 425 |
return cost; |
426 |
} |
|
427 |
||
428 |
/* Will find any depot */ |
|
1617
c3d3caad6d1e
(svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents:
1503
diff
changeset
|
429 |
int32 NPFFindDepot(AyStar* as, OpenListNode *current) { |
c3d3caad6d1e
(svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents:
1503
diff
changeset
|
430 |
TileIndex tile = current->path.node.tile; |
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
431 |
|
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
432 |
/* It's not worth caching the result with NPF_FLAG_IS_TARGET here as below, |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
433 |
* since checking the cache not that much faster than the actual check */ |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
434 |
if (IsTileDepotType(tile, as->user_data[NPF_TYPE])) |
1247 | 435 |
return AYSTAR_FOUND_END_NODE; |
436 |
else |
|
437 |
return AYSTAR_DONE; |
|
438 |
} |
|
439 |
||
440 |
/* Will find a station identified using the NPFFindStationOrTileData */ |
|
1617
c3d3caad6d1e
(svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents:
1503
diff
changeset
|
441 |
int32 NPFFindStationOrTile(AyStar* as, OpenListNode *current) { |
1464
fe5fcc14b2a2
(svn r1968) - Fix: [NPF] Mixed declarations and statements
matthijs
parents:
1463
diff
changeset
|
442 |
NPFFindStationOrTileData* fstd = (NPFFindStationOrTileData*)as->user_target; |
1617
c3d3caad6d1e
(svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents:
1503
diff
changeset
|
443 |
AyStarNode *node = ¤t->path.node; |
1464
fe5fcc14b2a2
(svn r1968) - Fix: [NPF] Mixed declarations and statements
matthijs
parents:
1463
diff
changeset
|
444 |
TileIndex tile = node->tile; |
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
445 |
|
1247 | 446 |
/* If GetNeighbours said we could get here, we assume the station type |
447 |
* is correct */ |
|
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
448 |
if ( |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
449 |
(fstd->station_index == -1 && tile == fstd->dest_coords) || /* We've found the tile, or */ |
1247 | 450 |
(IsTileType(tile, MP_STATION) && _map2[tile] == fstd->station_index) /* the station */ |
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
451 |
) { |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
452 |
return AYSTAR_FOUND_END_NODE; |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
453 |
} else { |
1247 | 454 |
return AYSTAR_DONE; |
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
455 |
} |
1247 | 456 |
} |
457 |
||
458 |
/* To be called when current contains the (shortest route to) the target node. |
|
459 |
* Will fill the contents of the NPFFoundTargetData using |
|
460 |
* AyStarNode[NPF_TRACKDIR_CHOICE]. |
|
461 |
*/ |
|
462 |
void NPFSaveTargetData(AyStar* as, OpenListNode* current) { |
|
463 |
NPFFoundTargetData* ftd = (NPFFoundTargetData*)as->user_path; |
|
464 |
ftd->best_trackdir = current->path.node.user_data[NPF_TRACKDIR_CHOICE]; |
|
465 |
ftd->best_path_dist = current->g; |
|
466 |
ftd->best_bird_dist = 0; |
|
467 |
ftd->node = current->path.node; |
|
468 |
} |
|
469 |
||
1749
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
470 |
/** |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
471 |
* Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile. |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
472 |
* Note that there is no check if the given trackdir is actually present on |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
473 |
* the tile! |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
474 |
* The given trackdir is used when there are (could be) multiple rail types on |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
475 |
* one tile. |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
476 |
*/ |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
477 |
static inline RailType GetTileRailType(TileIndex tile, byte trackdir) |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
478 |
{ |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
479 |
byte type = INVALID_RAILTYPE; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
480 |
switch (GetTileType(tile)) { |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
481 |
case MP_RAILWAY: |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
482 |
/* railway track */ |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
483 |
type = _map3_lo[tile] & RAILTYPE_MASK; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
484 |
break; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
485 |
case MP_STREET: |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
486 |
/* rail/road crossing */ |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
487 |
if ((_map5[tile] & 0xF0) == 0x10) |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
488 |
type = _map3_hi[tile] & RAILTYPE_MASK; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
489 |
break; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
490 |
case MP_STATION: |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
491 |
if (IsTrainStationTile(tile)) |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
492 |
type = _map3_lo[tile] & RAILTYPE_MASK; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
493 |
break; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
494 |
case MP_TUNNELBRIDGE: |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
495 |
/* railway tunnel */ |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
496 |
if ((_map5[tile] & 0xFC) == 0) type = _map3_lo[tile] & RAILTYPE_MASK; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
497 |
/* railway bridge ending */ |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
498 |
if ((_map5[tile] & 0xC6) == 0x80) type = _map3_lo[tile] & RAILTYPE_MASK; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
499 |
/* on railway bridge */ |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
500 |
if ((_map5[tile] & 0xC6) == 0xC0 && (_map5[tile] & 0x1) == (_trackdir_to_exitdir[trackdir] & 0x1)) |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
501 |
type = (_map3_lo[tile] >> 4) & RAILTYPE_MASK; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
502 |
/* under bridge (any type) */ |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
503 |
if ((_map5[tile] & 0xC0) == 0xC0 && (_map5[tile] & 0x1) != (trackdir & 0x1)) |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
504 |
type = _map3_lo[tile] & RAILTYPE_MASK; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
505 |
break; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
506 |
default: |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
507 |
break; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
508 |
} |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
509 |
return type; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
510 |
} |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
511 |
|
1247 | 512 |
/* Will just follow the results of GetTileTrackStatus concerning where we can |
513 |
* go and where not. Uses AyStar.user_data[NPF_TYPE] as the transport type and |
|
514 |
* an argument to GetTileTrackStatus. Will skip tunnels, meaning that the |
|
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
515 |
* entry and exit are neighbours. Will fill |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
516 |
* AyStarNode.user_data[NPF_TRACKDIR_CHOICE] with an appropriate value, and |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
517 |
* copy AyStarNode.user_data[NPF_NODE_FLAGS] from the parent */ |
1247 | 518 |
void NPFFollowTrack(AyStar* aystar, OpenListNode* current) { |
519 |
byte src_trackdir = current->path.node.direction; |
|
520 |
TileIndex src_tile = current->path.node.tile; |
|
521 |
byte src_exitdir = _trackdir_to_exitdir[src_trackdir]; |
|
522 |
FindLengthOfTunnelResult flotr; |
|
523 |
TileIndex dst_tile; |
|
524 |
int i = 0; |
|
525 |
uint trackdirs, ts; |
|
526 |
TransportType type = aystar->user_data[NPF_TYPE]; |
|
527 |
/* Initialize to 0, so we can jump out (return) somewhere an have no neighbours */ |
|
528 |
aystar->num_neighbours = 0; |
|
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
529 |
DEBUG(npf, 4)("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile); |
1247 | 530 |
|
531 |
/* Find dest tile */ |
|
532 |
if (IsTileType(src_tile, MP_TUNNELBRIDGE) && (_map5[src_tile] & 0xF0)==0 && (_map5[src_tile] & 3) == src_exitdir) { |
|
533 |
/* This is a tunnel. We know this tunnel is our type, |
|
534 |
* otherwise we wouldn't have got here. It is also facing us, |
|
535 |
* so we should skip it's body */ |
|
536 |
flotr = FindLengthOfTunnel(src_tile, src_exitdir); |
|
537 |
dst_tile = flotr.tile; |
|
538 |
} else { |
|
1650
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
539 |
if (type != TRANSPORT_WATER && (IsRoadStationTile(src_tile) || IsTileDepotType(src_tile, type))){ |
1247 | 540 |
/* This is a road station or a train or road depot. We can enter and exit |
541 |
* those from one side only. Trackdirs don't support that (yet), so we'll |
|
542 |
* do this here. */ |
|
543 |
||
544 |
byte exitdir; |
|
545 |
/* Find out the exit direction first */ |
|
546 |
if (IsRoadStationTile(src_tile)) |
|
547 |
exitdir = GetRoadStationDir(src_tile); |
|
548 |
else /* Train or road depot. Direction is stored the same for both, in map5 */ |
|
1650
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
549 |
exitdir = GetDepotDirection(src_tile, type); |
1247 | 550 |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
551 |
/* Let's see if were headed the right way into the depot, and reverse |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
552 |
* otherwise (only for trains, since only with trains you can |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
553 |
* (sometimes) reach tiles after reversing that you couldn't reach |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
554 |
* without reversing. */ |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
555 |
if (src_trackdir == _dir_to_diag_trackdir[_reverse_dir[exitdir]] && type == TRANSPORT_RAIL) |
1644
581b4e76ed36
(svn r2148) - Add: [NPF] Trains can now plan taking into account that they can reverse in depots. This makes forced servicing tracks work with NPF.
matthijs
parents:
1643
diff
changeset
|
556 |
/* We are headed inwards. We can only reverse here, so we'll not |
581b4e76ed36
(svn r2148) - Add: [NPF] Trains can now plan taking into account that they can reverse in depots. This makes forced servicing tracks work with NPF.
matthijs
parents:
1643
diff
changeset
|
557 |
* consider this direction, but jump ahead to the reverse direction. |
581b4e76ed36
(svn r2148) - Add: [NPF] Trains can now plan taking into account that they can reverse in depots. This makes forced servicing tracks work with NPF.
matthijs
parents:
1643
diff
changeset
|
558 |
* It would be nicer to return one neighbour here (the reverse |
581b4e76ed36
(svn r2148) - Add: [NPF] Trains can now plan taking into account that they can reverse in depots. This makes forced servicing tracks work with NPF.
matthijs
parents:
1643
diff
changeset
|
559 |
* trackdir of the one we are considering now) and then considering |
581b4e76ed36
(svn r2148) - Add: [NPF] Trains can now plan taking into account that they can reverse in depots. This makes forced servicing tracks work with NPF.
matthijs
parents:
1643
diff
changeset
|
560 |
* that one to return the tracks outside of the depot. But, because |
581b4e76ed36
(svn r2148) - Add: [NPF] Trains can now plan taking into account that they can reverse in depots. This makes forced servicing tracks work with NPF.
matthijs
parents:
1643
diff
changeset
|
561 |
* the code layout is cleaner this way, we will just pretend we are |
581b4e76ed36
(svn r2148) - Add: [NPF] Trains can now plan taking into account that they can reverse in depots. This makes forced servicing tracks work with NPF.
matthijs
parents:
1643
diff
changeset
|
562 |
* reversed already */ |
581b4e76ed36
(svn r2148) - Add: [NPF] Trains can now plan taking into account that they can reverse in depots. This makes forced servicing tracks work with NPF.
matthijs
parents:
1643
diff
changeset
|
563 |
src_trackdir = _reverse_trackdir[src_trackdir]; |
1247 | 564 |
} |
565 |
/* This a normal tile, a bridge, a tunnel exit, etc. */ |
|
566 |
dst_tile = AddTileIndexDiffCWrap(src_tile, TileIndexDiffCByDir(_trackdir_to_exitdir[src_trackdir])); |
|
567 |
if (dst_tile == INVALID_TILE) { |
|
568 |
/* We reached the border of the map */ |
|
569 |
/* TODO Nicer control flow for this */ |
|
570 |
return; |
|
571 |
} |
|
572 |
} |
|
573 |
||
1749
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
574 |
/* check correct rail type (mono, maglev, etc) |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
575 |
* XXX: This now compares with the previous tile, which should not pose a |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
576 |
* problem, but it might be nicer to compare with the first tile, or even |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
577 |
* the type of the vehicle... Maybe an NPF_RAILTYPE userdata sometime? */ |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
578 |
if (type == TRANSPORT_RAIL) { |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
579 |
byte src_type = GetTileRailType(src_tile, src_trackdir); |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
580 |
byte dst_type = GetTileRailType(dst_tile, _trackdir_to_exitdir[src_trackdir]); |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
581 |
if (src_type != dst_type) { |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
582 |
return; |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
583 |
} |
711c154a1fb7
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
matthijs
parents:
1700
diff
changeset
|
584 |
} |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
585 |
|
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
586 |
/* Check the owner of the tile */ |
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
587 |
if ( |
1650
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
588 |
IsTileType(dst_tile, MP_RAILWAY) /* Rail tile (also rail depot) */ |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
589 |
|| IsTrainStationTile(dst_tile) /* Rail station tile */ |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
590 |
|| IsTileDepotType(dst_tile, TRANSPORT_ROAD) /* Road depot tile */ |
1650
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
591 |
|| IsRoadStationTile(dst_tile) /* Road station tile */ |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
592 |
|| IsTileDepotType(dst_tile, TRANSPORT_WATER) /* Water depot tile */ |
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
593 |
) /* TODO: Crossings, tunnels and bridges are "public" now */ |
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
594 |
/* The above cases are "private" tiles, we need to check the owner */ |
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
595 |
if (!IsTileOwner(dst_tile, aystar->user_data[NPF_OWNER])) |
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
596 |
return; |
1247 | 597 |
|
598 |
/* Determine available tracks */ |
|
1655
8f9e052ce51e
(svn r2159) - Fix: [NPF] Road vehicles never found their target station or depots (introduced in r2154)
matthijs
parents:
1650
diff
changeset
|
599 |
if (type != TRANSPORT_WATER && (IsRoadStationTile(dst_tile) || IsTileDepotType(dst_tile, type))){ |
8f9e052ce51e
(svn r2159) - Fix: [NPF] Road vehicles never found their target station or depots (introduced in r2154)
matthijs
parents:
1650
diff
changeset
|
600 |
/* Road stations and road and train depots return 0 on GTTS, so we have to do this by hand... */ |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
601 |
byte exitdir; |
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
602 |
if (IsRoadStationTile(dst_tile)) |
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
603 |
exitdir = GetRoadStationDir(dst_tile); |
1655
8f9e052ce51e
(svn r2159) - Fix: [NPF] Road vehicles never found their target station or depots (introduced in r2154)
matthijs
parents:
1650
diff
changeset
|
604 |
else /* Road or train depot */ |
1650
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
605 |
exitdir = GetDepotDirection(dst_tile, type); |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
606 |
/* Find the trackdirs that are available for a depot or station with this |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
607 |
* orientation. They are only "inwards", since we are reaching this tile |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
608 |
* from some other tile. This prevents vehicles driving into depots from |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1644
diff
changeset
|
609 |
* the back */ |
1655
8f9e052ce51e
(svn r2159) - Fix: [NPF] Road vehicles never found their target station or depots (introduced in r2154)
matthijs
parents:
1650
diff
changeset
|
610 |
ts = (1 << _dir_to_diag_trackdir[_reverse_dir[exitdir]]); |
1247 | 611 |
} else { |
612 |
ts = GetTileTrackStatus(dst_tile, type); |
|
613 |
} |
|
614 |
trackdirs = ts & 0x3F3F; /* Filter out signal status and the unused bits */ |
|
615 |
||
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
616 |
DEBUG(npf, 4)("Next node: (%d, %d) [%d], possible trackdirs: %#x", TileX(dst_tile), TileY(dst_tile), dst_tile, trackdirs); |
1247 | 617 |
/* Select only trackdirs we can reach from our current trackdir */ |
618 |
trackdirs &= _trackdir_reaches_trackdirs[src_trackdir]; |
|
619 |
if (_patches.forbid_90_deg && (type == TRANSPORT_RAIL || type == TRANSPORT_WATER)) /* Filter out trackdirs that would make 90 deg turns for trains */ |
|
620 |
trackdirs &= ~_trackdir_crosses_trackdirs[src_trackdir]; |
|
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
621 |
DEBUG(npf,6)("After filtering: (%d, %d), possible trackdirs: %#x", TileX(dst_tile), TileY(dst_tile), trackdirs); |
1247 | 622 |
|
623 |
/* Enumerate possible track */ |
|
624 |
while (trackdirs != 0) { |
|
625 |
byte dst_trackdir; |
|
626 |
dst_trackdir = FindFirstBit2x64(trackdirs); |
|
627 |
trackdirs = KillFirstBit2x64(trackdirs); |
|
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1677
diff
changeset
|
628 |
DEBUG(npf, 5)("Expanded into trackdir: %d, remaining trackdirs: %#x", dst_trackdir, trackdirs); |
1247 | 629 |
|
630 |
/* Check for oneway signal against us */ |
|
631 |
if (IsTileType(dst_tile, MP_RAILWAY) && (_map5[dst_tile]&0xC0) == 0x40) { |
|
632 |
// the tile has a signal |
|
633 |
byte signal_present = _map3_lo[dst_tile]; |
|
634 |
if (!(signal_present & _signal_along_trackdir[dst_trackdir])) { |
|
635 |
// if one way signal not pointing towards us, stop going in this direction. |
|
636 |
if (signal_present & _signal_against_trackdir[dst_trackdir]) |
|
637 |
break; |
|
638 |
} |
|
639 |
} |
|
640 |
{ |
|
641 |
/* We've found ourselves a neighbour :-) */ |
|
642 |
AyStarNode* neighbour = &aystar->neighbours[i]; |
|
643 |
neighbour->tile = dst_tile; |
|
644 |
neighbour->direction = dst_trackdir; |
|
645 |
/* Save user data */ |
|
646 |
neighbour->user_data[NPF_NODE_FLAGS] = current->path.node.user_data[NPF_NODE_FLAGS]; |
|
647 |
NPFFillTrackdirChoice(neighbour, current); |
|
648 |
} |
|
649 |
i++; |
|
650 |
} |
|
651 |
aystar->num_neighbours = i; |
|
652 |
} |
|
653 |
||
654 |
/* |
|
655 |
* Plan a route to the specified target (which is checked by target_proc), |
|
656 |
* from start1 and if not NULL, from start2 as well. The type of transport we |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
657 |
* are checking is in type. reverse_penalty is applied to all routes that |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
658 |
* originate from the second start node. |
1247 | 659 |
* When we are looking for one specific target (optionally multiple tiles), we |
660 |
* should use a good heuristic to perform aystar search. When we search for |
|
661 |
* multiple targets that are spread around, we should perform a breadth first |
|
662 |
* search by specifiying CalcZero as our heuristic. |
|
663 |
*/ |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
664 |
NPFFoundTargetData NPFRouteInternal(AyStarNode* start1, AyStarNode* start2, NPFFindStationOrTileData* target, AyStar_EndNodeCheck target_proc, AyStar_CalculateH heuristic_proc, TransportType type, Owner owner, uint reverse_penalty) { |
1247 | 665 |
int r; |
666 |
NPFFoundTargetData result; |
|
667 |
||
668 |
/* Initialize procs */ |
|
669 |
_npf_aystar.CalculateH = heuristic_proc; |
|
670 |
_npf_aystar.EndNodeCheck = target_proc; |
|
671 |
_npf_aystar.FoundEndNode = NPFSaveTargetData; |
|
672 |
_npf_aystar.GetNeighbours = NPFFollowTrack; |
|
673 |
if (type == TRANSPORT_RAIL) |
|
674 |
_npf_aystar.CalculateG = NPFRailPathCost; |
|
675 |
else if (type == TRANSPORT_ROAD) |
|
676 |
_npf_aystar.CalculateG = NPFRoadPathCost; |
|
677 |
else if (type == TRANSPORT_WATER) |
|
678 |
_npf_aystar.CalculateG = NPFWaterPathCost; |
|
679 |
else |
|
680 |
assert(0); |
|
681 |
||
682 |
/* Initialize Start Node(s) */ |
|
683 |
start1->user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
|
684 |
start1->user_data[NPF_NODE_FLAGS] = 0; |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
685 |
_npf_aystar.addstart(&_npf_aystar, start1, 0); |
1247 | 686 |
if (start2) { |
687 |
start2->user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
|
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
688 |
start2->user_data[NPF_NODE_FLAGS] = 0; |
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1453
diff
changeset
|
689 |
NPFSetFlag(start2, NPF_FLAG_REVERSE, true); |
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
690 |
_npf_aystar.addstart(&_npf_aystar, start2, reverse_penalty); |
1247 | 691 |
} |
692 |
||
693 |
/* Initialize result */ |
|
694 |
result.best_bird_dist = (uint)-1; |
|
695 |
result.best_path_dist = (uint)-1; |
|
696 |
result.best_trackdir = 0xff; |
|
697 |
_npf_aystar.user_path = &result; |
|
698 |
||
699 |
/* Initialize target */ |
|
700 |
_npf_aystar.user_target = target; |
|
701 |
||
702 |
/* Initialize user_data */ |
|
703 |
_npf_aystar.user_data[NPF_TYPE] = type; |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
704 |
_npf_aystar.user_data[NPF_OWNER] = owner; |
1247 | 705 |
|
706 |
/* GO! */ |
|
707 |
r = AyStarMain_Main(&_npf_aystar); |
|
708 |
assert(r != AYSTAR_STILL_BUSY); |
|
709 |
||
710 |
if (result.best_bird_dist != 0) { |
|
711 |
if (target) { |
|
712 |
DEBUG(misc, 1) ("NPF: Could not find route to 0x%x from 0x%x.", target->dest_coords, start1->tile); |
|
713 |
} else { |
|
714 |
/* Assumption: target == NULL, so we are looking for a depot */ |
|
715 |
DEBUG(misc, 1) ("NPF: Could not find route to a depot from 0x%x.", start1->tile); |
|
716 |
} |
|
717 |
||
718 |
} |
|
719 |
return result; |
|
720 |
} |
|
721 |
||
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
722 |
NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, byte trackdir1, TileIndex tile2, byte trackdir2, NPFFindStationOrTileData* target, TransportType type, Owner owner) { |
1247 | 723 |
AyStarNode start1; |
724 |
AyStarNode start2; |
|
725 |
||
726 |
start1.tile = tile1; |
|
727 |
start2.tile = tile2; |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
728 |
/* We set this in case the target is also the start tile, we will just |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
729 |
* return a not found then */ |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
730 |
start1.user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
1247 | 731 |
start1.direction = trackdir1; |
732 |
start2.direction = trackdir2; |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
733 |
start2.user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
1247 | 734 |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
735 |
return NPFRouteInternal(&start1, (IsValidTile(tile2) ? &start2 : NULL), target, NPFFindStationOrTile, NPFCalcStationOrTileHeuristic, type, owner, 0); |
1247 | 736 |
} |
737 |
||
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
738 |
NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, byte trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner) { |
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
739 |
return NPFRouteToStationOrTileTwoWay(tile, trackdir, INVALID_TILE, 0, target, type, owner); |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
740 |
} |
1247 | 741 |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
742 |
NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, byte trackdir1, TileIndex tile2, byte trackdir2, TransportType type, Owner owner, uint reverse_penalty) { |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
743 |
AyStarNode start1; |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
744 |
AyStarNode start2; |
1247 | 745 |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
746 |
start1.tile = tile1; |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
747 |
start2.tile = tile2; |
1247 | 748 |
/* We set this in case the target is also the start tile, we will just |
749 |
* return a not found then */ |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
750 |
start1.user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
751 |
start1.direction = trackdir1; |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
752 |
start2.direction = trackdir2; |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
753 |
start2.user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
1247 | 754 |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
755 |
/* perform a breadth first search. Target is NULL, |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
756 |
* since we are just looking for any depot...*/ |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
757 |
return NPFRouteInternal(&start1, (IsValidTile(tile2) ? &start2 : NULL), NULL, NPFFindDepot, NPFCalcZero, type, owner, reverse_penalty); |
1247 | 758 |
} |
759 |
||
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
760 |
NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, byte trackdir, TransportType type, Owner owner) { |
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
761 |
return NPFRouteToDepotBreadthFirstTwoWay(tile, trackdir, INVALID_TILE, 0, type, owner, 0); |
1247 | 762 |
} |
763 |
||
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
764 |
NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, byte trackdir, TransportType type, Owner owner) { |
1247 | 765 |
/* Okay, what we're gonna do. First, we look at all depots, calculate |
766 |
* the manhatten distance to get to each depot. We then sort them by |
|
767 |
* distance. We start by trying to plan a route to the closest, then |
|
768 |
* the next closest, etc. We stop when the best route we have found so |
|
769 |
* far, is shorter than the manhattan distance. This will obviously |
|
770 |
* always find the closest depot. It will probably be most efficient |
|
771 |
* for ships, since the heuristic will not be to far off then. I hope. |
|
772 |
*/ |
|
773 |
Queue depots; |
|
774 |
int r; |
|
775 |
NPFFoundTargetData best_result; |
|
776 |
NPFFoundTargetData result; |
|
777 |
NPFFindStationOrTileData target; |
|
778 |
AyStarNode start; |
|
779 |
Depot* current; |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
780 |
Depot *depot; |
1247 | 781 |
|
782 |
init_InsSort(&depots); |
|
783 |
/* Okay, let's find all depots that we can use first */ |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
784 |
FOR_ALL_DEPOTS(depot) { |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
785 |
/* Check if this is really a valid depot, it is of the needed type and |
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
786 |
* owner */ |
1338 | 787 |
if (IsValidDepot(depot) && IsTileDepotType(depot->xy, type) && IsTileOwner(depot->xy, owner)) |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
788 |
/* If so, let's add it to the queue, sorted by distance */ |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
789 |
depots.push(&depots, depot, DistanceManhattan(tile, depot->xy)); |
1247 | 790 |
} |
791 |
||
792 |
/* Now, let's initialise the aystar */ |
|
793 |
||
794 |
/* Initialize procs */ |
|
795 |
_npf_aystar.CalculateH = NPFCalcStationOrTileHeuristic; |
|
796 |
_npf_aystar.EndNodeCheck = NPFFindStationOrTile; |
|
797 |
_npf_aystar.FoundEndNode = NPFSaveTargetData; |
|
798 |
_npf_aystar.GetNeighbours = NPFFollowTrack; |
|
799 |
if (type == TRANSPORT_RAIL) |
|
800 |
_npf_aystar.CalculateG = NPFRailPathCost; |
|
801 |
else if (type == TRANSPORT_ROAD) |
|
802 |
_npf_aystar.CalculateG = NPFRoadPathCost; |
|
803 |
else if (type == TRANSPORT_WATER) |
|
804 |
_npf_aystar.CalculateG = NPFWaterPathCost; |
|
805 |
else |
|
806 |
assert(0); |
|
807 |
||
808 |
/* Initialize target */ |
|
809 |
target.station_index = -1; /* We will initialize dest_coords inside the loop below */ |
|
810 |
_npf_aystar.user_target = ⌖ |
|
811 |
||
812 |
/* Initialize user_data */ |
|
813 |
_npf_aystar.user_data[NPF_TYPE] = type; |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
814 |
_npf_aystar.user_data[NPF_OWNER] = owner; |
1247 | 815 |
|
816 |
/* Initialize Start Node */ |
|
817 |
start.tile = tile; |
|
818 |
start.direction = trackdir; /* We will initialize user_data inside the loop below */ |
|
819 |
||
820 |
/* Initialize Result */ |
|
821 |
_npf_aystar.user_path = &result; |
|
822 |
best_result.best_path_dist = (uint)-1; |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
823 |
best_result.best_bird_dist = (uint)-1; |
1247 | 824 |
|
825 |
/* Just iterate the depots in order of increasing distance */ |
|
826 |
while ((current = depots.pop(&depots))) { |
|
827 |
/* Check to see if we already have a path shorter than this |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
828 |
* depot's manhattan distance. HACK: We call DistanceManhattan |
1247 | 829 |
* again, we should probably modify the queue to give us that |
830 |
* value... */ |
|
831 |
if ( DistanceManhattan(tile, current->xy * NPF_TILE_LENGTH) > best_result.best_path_dist) |
|
832 |
break; |
|
833 |
||
834 |
/* Initialize Start Node */ |
|
835 |
/* We set this in case the target is also the start tile, we will just |
|
836 |
* return a not found then */ |
|
837 |
start.user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
|
838 |
start.user_data[NPF_NODE_FLAGS] = 0; |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1753
diff
changeset
|
839 |
_npf_aystar.addstart(&_npf_aystar, &start, 0); |
1247 | 840 |
|
841 |
/* Initialize result */ |
|
842 |
result.best_bird_dist = (uint)-1; |
|
843 |
result.best_path_dist = (uint)-1; |
|
844 |
result.best_trackdir = 0xff; |
|
845 |
||
846 |
/* Initialize target */ |
|
847 |
target.dest_coords = current->xy; |
|
848 |
||
849 |
/* GO! */ |
|
850 |
r = AyStarMain_Main(&_npf_aystar); |
|
851 |
assert(r != AYSTAR_STILL_BUSY); |
|
852 |
||
853 |
/* This depot is closer */ |
|
854 |
if (result.best_path_dist < best_result.best_path_dist) |
|
855 |
best_result = result; |
|
856 |
} |
|
857 |
if (result.best_bird_dist != 0) { |
|
858 |
DEBUG(misc, 1) ("NPF: Could not find route to any depot from 0x%x.", tile); |
|
859 |
} |
|
860 |
return best_result; |
|
861 |
} |
|
862 |
||
863 |
void InitializeNPF(void) |
|
864 |
{ |
|
1661
f3799f2c84fa
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents:
1655
diff
changeset
|
865 |
init_AyStar(&_npf_aystar, NPFHash, NPF_HASH_SIZE); |
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
866 |
_npf_aystar.loops_per_tick = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
867 |
_npf_aystar.max_path_cost = 0; |
1700
e1fe3446d013
(svn r2204) - Add: [NPF] NPF now has a maximum number of nodes it will search. The default value is 5000 for now, which is an educated guess. Probably needs some finetuning. Hopefully this "feature" can be removed later on, when more sophisticated means of limiting the pathfinder have been implemented. This should make ships and larger networks playable for now, though.
matthijs
parents:
1678
diff
changeset
|
868 |
//_npf_aystar.max_search_nodes = 0; |
e1fe3446d013
(svn r2204) - Add: [NPF] NPF now has a maximum number of nodes it will search. The default value is 5000 for now, which is an educated guess. Probably needs some finetuning. Hopefully this "feature" can be removed later on, when more sophisticated means of limiting the pathfinder have been implemented. This should make ships and larger networks playable for now, though.
matthijs
parents:
1678
diff
changeset
|
869 |
/* We will limit the number of nodes for now, until we have a better |
e1fe3446d013
(svn r2204) - Add: [NPF] NPF now has a maximum number of nodes it will search. The default value is 5000 for now, which is an educated guess. Probably needs some finetuning. Hopefully this "feature" can be removed later on, when more sophisticated means of limiting the pathfinder have been implemented. This should make ships and larger networks playable for now, though.
matthijs
parents:
1678
diff
changeset
|
870 |
* solution to really fix performance */ |
e1fe3446d013
(svn r2204) - Add: [NPF] NPF now has a maximum number of nodes it will search. The default value is 5000 for now, which is an educated guess. Probably needs some finetuning. Hopefully this "feature" can be removed later on, when more sophisticated means of limiting the pathfinder have been implemented. This should make ships and larger networks playable for now, though.
matthijs
parents:
1678
diff
changeset
|
871 |
_npf_aystar.max_search_nodes = _patches.npf_max_search_nodes; |
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
872 |
#if 0 |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
873 |
init_AyStar(&_train_find_station, NTPHash, 1024); |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
874 |
init_AyStar(&_train_find_depot, NTPHash, 1024); |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
875 |
init_AyStar(&_road_find_station, NTPHash, 1024); |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
876 |
init_AyStar(&_road_find_depot, NTPHash, 1024); |
1247 | 877 |
|
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
878 |
_train_find_station.loops_per_tick = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
879 |
_train_find_depot.loops_per_tick = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
880 |
_road_find_station.loops_per_tick = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
881 |
_road_find_depot.loops_per_tick = 0; |
1247 | 882 |
|
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
883 |
_train_find_station.max_path_cost = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
884 |
_train_find_depot.max_path_cost = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
885 |
_road_find_station.max_path_cost = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
886 |
_road_find_depot.max_path_cost = 0; |
1247 | 887 |
|
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
888 |
_train_find_station.max_search_nodes = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
889 |
_train_find_depot.max_search_nodes = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
890 |
_road_find_station.max_search_nodes = 0; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
891 |
_road_find_depot.max_search_nodes = 0; |
1247 | 892 |
|
1463
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
893 |
_train_find_station.CalculateG = NPFRailPathCost; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
894 |
_train_find_depot.CalculateG = NPFRailPathCost; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
895 |
_road_find_station.CalculateG = NPFRoadPathCost; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
896 |
_road_find_depot.CalculateG = NPFRoadPathCost; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
897 |
|
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
898 |
_train_find_station.CalculateH = NPFCalcStationHeuristic; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
899 |
_train_find_depot.CalculateH = NPFCalcStationHeuristic; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
900 |
_road_find_station.CalculateH = NPFCalcStationHeuristic; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
901 |
_road_find_depot.CalculateH = NPFCalcStationHeuristic; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
902 |
|
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
903 |
_train_find_station.EndNodeCheck = NPFFindStationOrTile; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
904 |
_train_find_depot.EndNodeCheck = NPFFindStationOrTile; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
905 |
_road_find_station.EndNodeCheck = NPFFindStationOrTile; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
906 |
_road_find_depot.EndNodeCheck = NPFFindStationOrTile; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
907 |
|
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
908 |
_train_find_station.FoundEndNode = NPFSaveTargetData; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
909 |
_train_find_depot.FoundEndNode = NPFSaveTargetData; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
910 |
_road_find_station.FoundEndNode = NPFSaveTargetData; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
911 |
_road_find_depot.FoundEndNode = NPFSaveTargetData; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
912 |
|
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
913 |
_train_find_station.GetNeighbours = NPFFollowTrack; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
914 |
_train_find_depot.GetNeighbours = NPFFollowTrack; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
915 |
_road_find_station.GetNeighbours = NPFFollowTrack; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
916 |
_road_find_depot.GetNeighbours = NPFFollowTrack; |
85a05f2da980
(svn r1967) Codechange: A mix of mostly indentation-related tidyups.
pasky
parents:
1460
diff
changeset
|
917 |
#endif |
1247 | 918 |
} |
919 |
||
920 |
void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v) { |
|
921 |
/* Ships don't really reach their stations, but the tile in front. So don't |
|
922 |
* save the station id for ships. For roadvehs we don't store it either, |
|
923 |
* because multistop depends on vehicles actually reaching the exact |
|
924 |
* dest_tile, not just any stop of that station. |
|
925 |
* So only for train orders to stations we fill fstd->station_index, for all |
|
926 |
* others only dest_coords */ |
|
927 |
if ((v->current_order.type) == OT_GOTO_STATION && v->type == VEH_Train) { |
|
928 |
fstd->station_index = v->current_order.station; |
|
1452
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
929 |
/* Let's take the closest tile of the station as our target for trains */ |
a978fdcbca3e
(svn r1956) -Fix: [NPF] New target tile for heuristic should perform better with larger stations (HackyKid)
matthijs
parents:
1339
diff
changeset
|
930 |
fstd->dest_coords = CalcClosestStationTile(v->current_order.station, v->tile); |
1247 | 931 |
} else { |
932 |
fstd->dest_coords = v->dest_tile; |
|
933 |
fstd->station_index = -1; |
|
934 |
} |
|
935 |
} |