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

Function NormaliseDualHeads

src/train_cmd.cpp:938–954  ·  view source on GitHub ↗

* Normalise the dual heads in the train, i.e. if one is * missing move that one to this train. * @param t the train to normalise. */

Source from the content-addressed store, hash-verified

936 * @param t the train to normalise.
937 */
938static void NormaliseDualHeads(Train *t)
939{
940 for (; t != nullptr; t = t->GetNextVehicle()) {
941 if (!t->IsMultiheaded() || !t->IsEngine()) continue;
942
943 /* Make sure that there are no free cars before next engine */
944 Train *u;
945 for (u = t; u->Next() != nullptr && !u->Next()->IsEngine(); u = u->Next()) {}
946
947 if (u == t->other_multiheaded_part) continue;
948
949 /* Remove the part from the 'wrong' train */
950 RemoveFromConsist(t->other_multiheaded_part);
951 /* And add it to the 'right' train */
952 InsertInConsist(u, t->other_multiheaded_part);
953 }
954}
955
956/**
957 * Normalise the sub types of the parts in this chain.

Callers 1

ArrangeTrainsFunction · 0.85

Calls 6

RemoveFromConsistFunction · 0.85
InsertInConsistFunction · 0.85
IsMultiheadedMethod · 0.80
IsEngineMethod · 0.80
GetNextVehicleMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected