diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -24,7 +24,6 @@ #include "industry_map.h" #include "newgrf.h" #include "newgrf_canal.h" -#include "misc/autoptr.hpp" #include "transparency.h" #include "strings_func.h" #include "functions.h" @@ -201,18 +200,16 @@ CommandCost CmdBuildShipDepot(TileIndex ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR); if (CmdFailed(ret)) return CMD_ERROR; - Depot *depot = new Depot(tile); - if (depot == NULL) return CMD_ERROR; - AutoPtrT d_auto_delete = depot; + if (!Depot::CanAllocateItem()) return CMD_ERROR; if (flags & DC_EXEC) { + Depot *depot = new Depot(tile); depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index; MakeShipDepot(tile, _current_player, DEPOT_NORTH, axis, wc1); MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis, wc2); MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile2); - d_auto_delete.Detach(); } return CommandCost(EXPENSES_CONSTRUCTION, _price.build_ship_depot);