mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Iterate group vehicle list for CmdAddSharedVehicleGroup
parent
1fb35c5cce
commit
b492a7b53d
|
@ -614,16 +614,13 @@ CommandCost CmdAddSharedVehicleGroup(DoCommandFlag flags, GroupID id_g, VehicleT
|
||||||
if (!Group::IsValidID(id_g) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
|
if (!Group::IsValidID(id_g) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
/* Find the first front engine which belong to the group id_g
|
/* For each vehicle belonging to the group id_g
|
||||||
* then add all shared vehicles of this front engine to the group id_g */
|
* add all vehicles sharing orders with it to that group */
|
||||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
const VehicleList vehicle_list = Group::Get(id_g)->statistics.vehicle_list;
|
||||||
if (v->type == type && v->IsPrimaryVehicle()) {
|
for (const Vehicle *v : vehicle_list) {
|
||||||
if (v->group_id != id_g) continue;
|
/* For each shared vehicles add it to the group */
|
||||||
|
for (Vehicle *v2 = v->FirstShared(); v2 != nullptr; v2 = v2->NextShared()) {
|
||||||
/* For each shared vehicles add it to the group */
|
if (v2->group_id != id_g) Command<CMD_ADD_VEHICLE_GROUP>::Do(flags, id_g, v2->index, false, VehicleListIdentifier{});
|
||||||
for (Vehicle *v2 = v->FirstShared(); v2 != nullptr; v2 = v2->NextShared()) {
|
|
||||||
if (v2->group_id != id_g) Command<CMD_ADD_VEHICLE_GROUP>::Do(flags, id_g, v2->index, false, VehicleListIdentifier{});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue