branch | custombridgeheads |
changeset 5621 | 6ce400c0a2f4 |
parent 5618 | a7db50b9f817 |
child 5623 | ef2a8a524a95 |
5620:3b40a41f90d2 | 5621:6ce400c0a2f4 |
---|---|
47 } |
47 } |
48 |
48 |
49 FORCEINLINE bool FindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) |
49 FORCEINLINE bool FindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) |
50 { |
50 { |
51 // set origin and destination nodes |
51 // set origin and destination nodes |
52 Yapf().SetOrigin(t1, TrackdirToTrackdirBits(td1), t2, TrackdirToTrackdirBits(td2), reverse_penalty, true); |
52 Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true); |
53 Yapf().SetDestination(v); |
53 Yapf().SetDestination(v); |
54 Yapf().SetMaxCost(YAPF_TILE_LENGTH * max_distance); |
54 Yapf().SetMaxCost(YAPF_TILE_LENGTH * max_distance); |
55 |
55 |
56 // find the best path |
56 // find the best path |
57 bool bFound = Yapf().FindPath(v); |
57 bool bFound = Yapf().FindPath(v); |
111 } |
111 } |
112 |
112 |
113 FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool *path_not_found) |
113 FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool *path_not_found) |
114 { |
114 { |
115 // set origin and destination nodes |
115 // set origin and destination nodes |
116 if (v->tile == tile) { |
116 Yapf().SetOrigin(v->tile, GetVehicleTrackdir(v), INVALID_TILE, INVALID_TRACKDIR, 1, true); |
117 // probably bridge head |
|
118 trackdirs = (TrackdirBits)(GetTileTrackStatus(tile, TRANSPORT_RAIL) & TRACKDIR_BIT_MASK); |
|
119 trackdirs &= DiagdirReachesTrackdirs(ReverseDiagDir(TrackdirToExitdir(ReverseTrackdir(GetVehicleTrackdir(v))))); |
|
120 Yapf().SetOrigin(tile, trackdirs, INVALID_TILE, INVALID_TRACKDIR_BIT, 1, true); |
|
121 } else { |
|
122 Yapf().SetOrigin(v->tile, TrackdirToTrackdirBits(GetVehicleTrackdir(v)), INVALID_TILE, INVALID_TRACKDIR_BIT, 1, true); |
|
123 } |
|
124 Yapf().SetDestination(v); |
117 Yapf().SetDestination(v); |
125 |
118 |
126 // find the best path |
119 // find the best path |
127 bool path_found = Yapf().FindPath(v); |
120 bool path_found = Yapf().FindPath(v); |
128 if (!path_found && path_not_found != NULL) { |
121 if (!path_found && path_not_found != NULL) { |
140 while (pNode->m_parent != NULL) { |
133 while (pNode->m_parent != NULL) { |
141 pPrev = pNode; |
134 pPrev = pNode; |
142 pNode = pNode->m_parent; |
135 pNode = pNode->m_parent; |
143 } |
136 } |
144 // return trackdir from the best origin node (one of start nodes) |
137 // return trackdir from the best origin node (one of start nodes) |
145 Node& best_next_node = (v->tile == tile ? *pNode : *pPrev); |
138 Node& best_next_node = *pPrev; |
146 assert(v->tile == tile || best_next_node.GetTile() == tile); |
139 assert(best_next_node.GetTile() == tile); |
147 next_trackdir = best_next_node.GetTrackdir(); |
140 next_trackdir = best_next_node.GetTrackdir(); |
148 } |
141 } |
149 return next_trackdir; |
142 return next_trackdir; |
150 } |
143 } |
151 |
144 |
157 |
150 |
158 FORCEINLINE bool CheckReverseTrain(Vehicle* v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2) |
151 FORCEINLINE bool CheckReverseTrain(Vehicle* v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2) |
159 { |
152 { |
160 // create pathfinder instance |
153 // create pathfinder instance |
161 // set origin and destination nodes |
154 // set origin and destination nodes |
162 Yapf().SetOrigin(t1, TrackdirToTrackdirBits(td1), t2, TrackdirToTrackdirBits(td2), 1, false); |
155 Yapf().SetOrigin(t1, td1, t2, td2, 1, false); |
163 Yapf().SetDestination(v); |
156 Yapf().SetDestination(v); |
164 |
157 |
165 // find the best path |
158 // find the best path |
166 bool bFound = Yapf().FindPath(v); |
159 bool bFound = Yapf().FindPath(v); |
167 |
160 |