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

Function UpdateTrainGroupID

src/group_cmd.cpp:793–809  ·  view source on GitHub ↗

* Recalculates the groupID of a train. Should be called each time a vehicle is added * to/removed from the chain,. * @note this needs to be called too for 'wagon chains' (in the depot, without an engine) * @note Called in CmdBuildRailVehicle, CmdBuildRailWagon, CmdMoveRailVehicle, CmdSellRailWagon * @param v First vehicle of the chain. */

Source from the content-addressed store, hash-verified

791 * @param v First vehicle of the chain.
792 */
793void UpdateTrainGroupID(Train *v)
794{
795 assert(v->IsFrontEngine() || v->IsFreeWagon());
796
797 GroupID new_g = v->IsFrontEngine() ? v->group_id : (GroupID)DEFAULT_GROUP;
798 for (Vehicle *u = v; u != nullptr; u = u->Next()) {
799 if (u->IsEngineCountable()) UpdateNumEngineGroup(u, u->group_id, new_g);
800
801 u->group_id = new_g;
802 u->colourmap = PAL_NONE;
803 u->InvalidateNewGRFCache();
804 }
805
806 /* Update the Replace Vehicle Windows */
807 GroupStatistics::UpdateAutoreplace(v->owner);
808 SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN);
809}
810
811/**
812 * Get the number of engines with EngineID id_e in the group with GroupID

Callers 3

CmdBuildRailWagonFunction · 0.85
CmdBuildRailVehicleFunction · 0.85
NormaliseTrainHeadFunction · 0.85

Calls 7

UpdateNumEngineGroupFunction · 0.85
SetWindowDirtyFunction · 0.85
IsFrontEngineMethod · 0.80
IsFreeWagonMethod · 0.80
IsEngineCountableMethod · 0.80
InvalidateNewGRFCacheMethod · 0.80
NextMethod · 0.45

Tested by

no test coverage detected