summaryrefslogtreecommitdiff
path: root/src/road_cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/road_cmd.cpp')
-rw-r--r--src/road_cmd.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index b6abc4b35..621338ea9 100644
--- 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 end_tile, uint32 flags, uint32 p1, uint3
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 tile, uint32 flags, uint32 p1, uint32 p2
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<Depot> 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(TileIndex tile, uint32 flags)
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);
}