diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -31,6 +31,7 @@ #include "newgrf.h" #include "station_map.h" #include "tunnel_map.h" +#include "misc/autoptr.hpp" static uint CountRoadBits(RoadBits r) @@ -721,7 +722,6 @@ CommandCost CmdRemoveLongRoad(TileIndex CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { CommandCost cost; - Depot *dep; Slope tileh; SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); @@ -745,15 +745,16 @@ CommandCost CmdBuildRoadDepot(TileIndex if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); - dep = AllocateDepot(); + Depot *dep = new Depot(tile); if (dep == NULL) return CMD_ERROR; + AutoPtrT d_auto_delete = dep; if (flags & DC_EXEC) { - dep->xy = 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); } @@ -765,7 +766,10 @@ static CommandCost RemoveRoadDepot(TileI if (!EnsureNoVehicle(tile)) return CMD_ERROR; - if (flags & DC_EXEC) DeleteDepot(GetDepotByTile(tile)); + if (flags & DC_EXEC) { + DoClearSquare(tile); + delete GetDepotByTile(tile); + } return CommandCost(_price.remove_road_depot); }