MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DetermineNextTrainForceProceeding

Function DetermineNextTrainForceProceeding

src/train_cmd.cpp:2153–2162  ·  view source on GitHub ↗

* Determine to what force_proceed should be changed. * If we are forced to proceed, cancel that order. * If we are marked stuck we would want to force the train to * proceed to the next signal unless we are stuck just before * the next signal. In the other cases we would like to pass * the signal at danger and run till the next signal we encounter. * @param t The train to determine the new v

Source from the content-addressed store, hash-verified

2151 * @return The next state of force_proceed.
2152 */
2153static TrainForceProceeding DetermineNextTrainForceProceeding(const Train *t)
2154{
2155 if (t->vehstatus.Test(VehState::Crashed) || t->force_proceed == TFP_SIGNAL) return TFP_NONE;
2156 if (!t->flags.Test(VehicleRailFlag::Stuck)) return t->IsChainInDepot() ? TFP_STUCK : TFP_SIGNAL;
2157
2158 TileIndex next_tile = TileAddByDiagDir(t->tile, TrackdirToExitdir(t->GetVehicleTrackdir()));
2159 if (next_tile == INVALID_TILE || !IsTileType(next_tile, MP_RAILWAY) || !HasSignals(next_tile)) return TFP_STUCK;
2160 TrackBits new_tracks = DiagdirReachesTracks(TrackdirToExitdir(t->GetVehicleTrackdir())) & GetTrackBits(next_tile);
2161 return new_tracks != TRACK_BIT_NONE && HasSignalOnTrack(next_tile, FindFirstTrack(new_tracks)) ? TFP_SIGNAL : TFP_STUCK;
2162}
2163
2164/**
2165 * Force a train through a red signal

Callers 1

CmdForceTrainProceedFunction · 0.85

Calls 11

TileAddByDiagDirFunction · 0.85
TrackdirToExitdirFunction · 0.85
IsTileTypeFunction · 0.85
HasSignalsFunction · 0.85
DiagdirReachesTracksFunction · 0.85
GetTrackBitsFunction · 0.85
HasSignalOnTrackFunction · 0.85
FindFirstTrackFunction · 0.85
TestMethod · 0.80
IsChainInDepotMethod · 0.45
GetVehicleTrackdirMethod · 0.45

Tested by

no test coverage detected