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

Function AddVehicleToGroup

src/group_cmd.cpp:524–551  ·  view source on GitHub ↗

* Do add a vehicle to a group. * @param v Vehicle to add. * @param new_g Group to add to. */

Source from the content-addressed store, hash-verified

522 * @param new_g Group to add to.
523 */
524static void AddVehicleToGroup(Vehicle *v, GroupID new_g)
525{
526 GroupStatistics::CountVehicle(v, -1);
527
528 switch (v->type) {
529 default: NOT_REACHED();
530 case VEH_TRAIN:
531 SetTrainGroupID(Train::From(v), new_g);
532 break;
533
534 case VEH_ROAD:
535 case VEH_SHIP:
536 case VEH_AIRCRAFT:
537 if (v->IsEngineCountable()) UpdateNumEngineGroup(v, v->group_id, new_g);
538 v->group_id = new_g;
539 for (Vehicle *u = v; u != nullptr; u = u->Next()) {
540 u->colourmap = PAL_NONE;
541 u->InvalidateNewGRFCache();
542 u->UpdateViewport(true);
543 }
544 break;
545 }
546
547 InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
548 InvalidateWindowData(WC_VEHICLE_DETAILS, v->index);
549
550 GroupStatistics::CountVehicle(v, 1);
551}
552
553/**
554 * Add a vehicle to a group

Callers 1

CmdAddVehicleGroupFunction · 0.85

Calls 8

NOT_REACHEDFunction · 0.85
SetTrainGroupIDFunction · 0.85
UpdateNumEngineGroupFunction · 0.85
IsEngineCountableMethod · 0.80
InvalidateNewGRFCacheMethod · 0.80
InvalidateWindowDataFunction · 0.70
NextMethod · 0.45
UpdateViewportMethod · 0.45

Tested by

no test coverage detected