* 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 */
| 763 | * @param new_g index of array group |
| 764 | */ |
| 765 | void 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 | /** |
no test coverage detected