/** * Add all vehicles in the given group to the default group and then deletes the group. * @param tile unused * @param flags type of operation * @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 char *text) { Group *g = Group::GetIfValid(p1); if (g == NULL || g->owner != _current_company) return CMD_ERROR; /* Remove all vehicles from the group */ DoCommand(0, p1, 0, flags, CMD_REMOVE_ALL_VEHICLES_GROUP); /* Delete sub-groups */ Group *gp; FOR_ALL_GROUPS(gp) { if (gp->parent == g->index) { DoCommand(0, gp->index, 0, flags, CMD_DELETE_GROUP); } } 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; EngineRenew *er; c = Company::Get(_current_company); FOR_ALL_ENGINE_RENEWS(er) { if (er->group_id == g->index) RemoveEngineReplacementForCompany(c, er->from, g->index, flags); } }
/** * Change engine renewal parameters * @param tile unused * @param flags operation to perform * @param p1 packed data * - bits 16-31 = engine group * @param p2 packed data * - bits 0-15 = old engine type * - bits 16-31 = new engine type * @param text unused * @return the cost of this operation or an error */ CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { Company *c = Company::GetIfValid(_current_company); if (c == NULL) return CMD_ERROR; EngineID old_engine_type = GB(p2, 0, 16); EngineID new_engine_type = GB(p2, 16, 16); GroupID id_g = GB(p1, 16, 16); CommandCost cost; if (Group::IsValidID(id_g) ? Group::Get(id_g)->owner != _current_company : !IsAllGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR; if (!Engine::IsValidID(old_engine_type)) return CMD_ERROR; if (new_engine_type != INVALID_ENGINE) { if (!Engine::IsValidID(new_engine_type)) return CMD_ERROR; if (!CheckAutoreplaceValidity(old_engine_type, new_engine_type, _current_company)) return CMD_ERROR; cost = AddEngineReplacementForCompany(c, old_engine_type, new_engine_type, id_g, flags); } else { cost = RemoveEngineReplacementForCompany(c, old_engine_type, id_g, flags); } if (flags & DC_EXEC) GroupStatistics::UpdateAutoreplace(_current_company); if ((flags & DC_EXEC) && IsLocalCompany()) InvalidateAutoreplaceWindow(old_engine_type, id_g); return cost; }
/** * Add all vehicles in the given group to the default group and then deletes the group. * @param tile unused * @param flags type of operation * @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 char *text) { Group *g = Group::GetIfValid(p1); if (g == NULL || g->owner != _current_company) return CMD_ERROR; if (flags & DC_EXEC) { Vehicle *v; /* Add all vehicles belong to the group to the default group */ FOR_ALL_VEHICLES(v) { if (v->group_id == g->index && v->type == g->vehicle_type) v->group_id = DEFAULT_GROUP; } /* Update backupped orders if needed */ if (_backup_orders_data.group == g->index) _backup_orders_data.group = DEFAULT_GROUP; /* If we set an autoreplace for the group we delete, remove it. */ if (_current_company < MAX_COMPANIES) { Company *c; EngineRenew *er; c = Company::Get(_current_company); FOR_ALL_ENGINE_RENEWS(er) { if (er->group_id == g->index) RemoveEngineReplacementForCompany(c, er->from, g->index, flags); } }