|
@@ -347,30 +347,30 @@ CommandCost CmdCreateGroup(TileIndex til
|
|
|
* @param p1 index of array group
|
|
|
* - p1 bit 0-15 : GroupID
|
|
|
* @param p2 unused
|
|
|
* @param text unused
|
|
|
* @return the cost of this operation or an error
|
|
|
*/
|
|
|
CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
|
|
|
{
|
|
|
Group *g = Group::GetIfValid(p1);
|
|
|
if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
|
|
|
|
|
|
/* Remove all vehicles from the group */
|
|
|
DoCommand(0, p1, 0, flags, CMD_REMOVE_ALL_VEHICLES_GROUP);
|
|
|
DoCommand(flags, CMD_REMOVE_ALL_VEHICLES_GROUP, 0, p1, 0);
|
|
|
|
|
|
/* Delete sub-groups */
|
|
|
for (const Group *gp : Group::Iterate()) {
|
|
|
if (gp->parent == g->index) {
|
|
|
DoCommand(0, gp->index, 0, flags, CMD_DELETE_GROUP);
|
|
|
DoCommand(flags, CMD_DELETE_GROUP, 0, gp->index, 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
/* Update backupped orders if needed */
|
|
|
OrderBackup::ClearGroup(g->index);
|
|
|
|
|
|
/* If we set an autoreplace for the group we delete, remove it. */
|
|
|
if (_current_company < MAX_COMPANIES) {
|
|
|
Company *c;
|
|
|
|
|
|
c = Company::Get(_current_company);
|
|
@@ -571,25 +571,25 @@ CommandCost CmdAddSharedVehicleGroup(Til
|
|
|
GroupID id_g = p1;
|
|
|
if (!Group::IsValidID(id_g) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
/* Find the first front engine which belong to the group id_g
|
|
|
* then add all shared vehicles of this front engine to the group id_g */
|
|
|
for (const Vehicle *v : Vehicle::Iterate()) {
|
|
|
if (v->type == type && v->IsPrimaryVehicle()) {
|
|
|
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()) {
|
|
|
if (v2->group_id != id_g) DoCommand(tile, id_g, v2->index, flags, CMD_ADD_VEHICLE_GROUP, text);
|
|
|
if (v2->group_id != id_g) DoCommand(flags, CMD_ADD_VEHICLE_GROUP, tile, id_g, v2->index, text);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
InvalidateWindowData(GetWindowClassForVehicleType(type), VehicleListIdentifier(VL_GROUP_LIST, type, _current_company).Pack());
|
|
|
}
|
|
|
|
|
|
return CommandCost();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -607,25 +607,25 @@ CommandCost CmdRemoveAllVehiclesGroup(Ti
|
|
|
GroupID old_g = p1;
|
|
|
Group *g = Group::GetIfValid(old_g);
|
|
|
|
|
|
if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
/* Find each Vehicle that belongs to the group old_g and add it to the default group */
|
|
|
for (const Vehicle *v : Vehicle::Iterate()) {
|
|
|
if (v->IsPrimaryVehicle()) {
|
|
|
if (v->group_id != old_g) continue;
|
|
|
|
|
|
/* Add The Vehicle to the default group */
|
|
|
DoCommand(tile, DEFAULT_GROUP, v->index, flags, CMD_ADD_VEHICLE_GROUP, text);
|
|
|
DoCommand(flags, CMD_ADD_VEHICLE_GROUP, tile, DEFAULT_GROUP, v->index, text);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack());
|
|
|
}
|
|
|
|
|
|
return CommandCost();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Set the livery for a vehicle group.
|
|
|
* @param tile Unused.
|