diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -23,7 +23,6 @@ #include "newgrf.h" #include "station_map.h" #include "tunnel_map.h" -#include "misc/autoptr.hpp" #include "variables.h" #include "autoslope.h" #include "transparency.h" @@ -817,16 +816,14 @@ CommandCost CmdBuildRoadDepot(TileIndex if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); - Depot *dep = new Depot(tile); - if (dep == NULL) return CMD_ERROR; - AutoPtrT d_auto_delete = dep; + if (!Depot::CanAllocateItem()) return CMD_ERROR; if (flags & DC_EXEC) { + Depot *dep = new Depot(tile); dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; MakeRoadDepot(tile, _current_player, dir, rt); MarkTileDirtyByTile(tile); - d_auto_delete.Detach(); } return cost.AddCost(_price.build_road_depot); }