* 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. */
| 791 | * @param v First vehicle of the chain. |
| 792 | */ |
| 793 | void 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 |
no test coverage detected