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

Function SetTrainGroupID

src/group_cmd.cpp:765–783  ·  view source on GitHub ↗

* Affect the groupID of a train to new_g. * @note called in CmdAddVehicleGroup and CmdMoveRailVehicle * @param v First vehicle of the chain. * @param new_g index of array group */

Source from the content-addressed store, hash-verified

763 * @param new_g index of array group
764 */
765void SetTrainGroupID(Train *v, GroupID new_g)
766{
767 if (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g)) return;
768
769 assert(v->IsFrontEngine() || IsDefaultGroupID(new_g));
770
771 for (Vehicle *u = v; u != nullptr; u = u->Next()) {
772 if (u->IsEngineCountable()) UpdateNumEngineGroup(u, u->group_id, new_g);
773
774 u->group_id = new_g;
775 u->colourmap = PAL_NONE;
776 u->InvalidateNewGRFCache();
777 u->UpdateViewport(true);
778 }
779
780 /* Update the Replace Vehicle Windows */
781 GroupStatistics::UpdateAutoreplace(v->owner);
782 SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN);
783}
784
785
786/**

Callers 2

CmdMoveRailVehicleFunction · 0.85
AddVehicleToGroupFunction · 0.85

Calls 8

IsDefaultGroupIDFunction · 0.85
UpdateNumEngineGroupFunction · 0.85
SetWindowDirtyFunction · 0.85
IsFrontEngineMethod · 0.80
IsEngineCountableMethod · 0.80
InvalidateNewGRFCacheMethod · 0.80
NextMethod · 0.45
UpdateViewportMethod · 0.45

Tested by

no test coverage detected