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

Function TrainCrashed

src/train_cmd.cpp:3181–3197  ·  view source on GitHub ↗

* Marks train as crashed and creates an AI event. * Doesn't do anything if the train is crashed already. * @param v first vehicle of chain * @return number of victims (including 2 drivers; zero if train was already crashed) */

Source from the content-addressed store, hash-verified

3179 * @return number of victims (including 2 drivers; zero if train was already crashed)
3180 */
3181static uint TrainCrashed(Train *v)
3182{
3183 uint victims = 0;
3184
3185 /* do not crash train twice */
3186 if (!v->vehstatus.Test(VehState::Crashed)) {
3187 victims = v->Crash();
3188 AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN, victims, v->owner));
3189 Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN, victims, v->owner));
3190 }
3191
3192 /* Try to re-reserve track under already crashed train too.
3193 * Crash() clears the reservation! */
3194 v->ReserveTrackUnderConsist();
3195
3196 return victims;
3197}
3198
3199/**
3200 * Collision test function.

Callers 1

CheckTrainCollisionFunction · 0.85

Calls 3

TestMethod · 0.80
CrashMethod · 0.45

Tested by

no test coverage detected