diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -12,7 +12,6 @@ #include "train.h" #include "aircraft.h" #include "vehicle_gui.h" -#include "misc/autoptr.hpp" #include "strings_func.h" #include "functions.h" #include "window_func.h" @@ -94,20 +93,14 @@ CommandCost CmdCreateGroup(TileIndex til VehicleType vt = (VehicleType)p1; if (!IsPlayerBuildableVehicleType(vt)) return CMD_ERROR; - AutoPtrT g_auto_delete; - - Group *g = new Group(_current_player); - if (g == NULL) return CMD_ERROR; - - g_auto_delete = g; + if (!Group::CanAllocateItem()) return CMD_ERROR; if (flags & DC_EXEC) { + Group *g = new Group(_current_player); g->replace_protection = false; g->vehicle_type = vt; InvalidateWindowData(GetWCForVT(vt), (vt << 11) | VLW_GROUP_LIST | _current_player); - - g_auto_delete.Detach(); } return CommandCost();