* Check if the train is on the last reserved tile and try to extend the path then. * @param v %Train that needs its path extended. */
| 2232 | * @param v %Train that needs its path extended. |
| 2233 | */ |
| 2234 | static void CheckNextTrainTile(Train *v) |
| 2235 | { |
| 2236 | /* Don't do any look-ahead if path_backoff_interval is 255. */ |
| 2237 | if (_settings_game.pf.path_backoff_interval == 255) return; |
| 2238 | |
| 2239 | /* Exit if we are inside a depot. */ |
| 2240 | if (v->track == TRACK_BIT_DEPOT) return; |
| 2241 | |
| 2242 | switch (v->current_order.GetType()) { |
| 2243 | /* Exit if we reached our destination depot. */ |
| 2244 | case OT_GOTO_DEPOT: |
| 2245 | if (v->tile == v->dest_tile) return; |
| 2246 | break; |
| 2247 | |
| 2248 | case OT_GOTO_WAYPOINT: |
| 2249 | /* If we reached our waypoint, make sure we see that. */ |
| 2250 | if (IsRailWaypointTile(v->tile) && GetStationIndex(v->tile) == v->current_order.GetDestination()) ProcessOrders(v); |
| 2251 | break; |
| 2252 | |
| 2253 | case OT_NOTHING: |
| 2254 | case OT_LEAVESTATION: |
| 2255 | case OT_LOADING: |
| 2256 | /* Exit if the current order doesn't have a destination, but the train has orders. */ |
| 2257 | if (v->GetNumOrders() > 0) return; |
| 2258 | break; |
| 2259 | |
| 2260 | default: |
| 2261 | break; |
| 2262 | } |
| 2263 | /* Exit if we are on a station tile and are going to stop. */ |
| 2264 | if (IsRailStationTile(v->tile) && v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile))) return; |
| 2265 | |
| 2266 | Trackdir td = v->GetVehicleTrackdir(); |
| 2267 | |
| 2268 | /* On a tile with a red non-pbs signal, don't look ahead. */ |
| 2269 | if (IsTileType(v->tile, MP_RAILWAY) && HasSignalOnTrackdir(v->tile, td) && |
| 2270 | !IsPbsSignal(GetSignalType(v->tile, TrackdirToTrack(td))) && |
| 2271 | GetSignalStateByTrackdir(v->tile, td) == SIGNAL_STATE_RED) return; |
| 2272 | |
| 2273 | CFollowTrackRail ft(v); |
| 2274 | if (!ft.Follow(v->tile, td)) return; |
| 2275 | |
| 2276 | if (!HasReservedTracks(ft.new_tile, TrackdirBitsToTrackBits(ft.new_td_bits))) { |
| 2277 | /* Next tile is not reserved. */ |
| 2278 | if (KillFirstBit(ft.new_td_bits) == TRACKDIR_BIT_NONE) { |
| 2279 | if (HasPbsSignalOnTrackdir(ft.new_tile, FindFirstTrackdir(ft.new_td_bits))) { |
| 2280 | /* If the next tile is a PBS signal, try to make a reservation. */ |
| 2281 | TrackBits tracks = TrackdirBitsToTrackBits(ft.new_td_bits); |
| 2282 | if (Rail90DegTurnDisallowed(GetTileRailType(ft.old_tile), GetTileRailType(ft.new_tile))) { |
| 2283 | tracks &= ~TrackCrossesTracks(TrackdirToTrack(ft.old_td)); |
| 2284 | } |
| 2285 | ChooseTrainTrack(v, ft.new_tile, ft.exitdir, tracks, false, nullptr, false); |
| 2286 | } |
| 2287 | } |
| 2288 | } |
| 2289 | } |
| 2290 | |
| 2291 | /** |
no test coverage detected