From c60988a1d5d2a140eb5f8ff1b90119ee40ec787e Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 2 Aug 2007 22:33:53 +0000 Subject: (svn r10758) -Codechange: make the depot struct use the pool item class as super class. --- src/rail_cmd.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/rail_cmd.cpp') diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index ac22758fa..024fd620d 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -37,6 +37,7 @@ #include "newgrf_callbacks.h" #include "newgrf_station.h" #include "train.h" +#include "misc/autoptr.hpp" const byte _track_sloped_sprites[14] = { 14, 15, 22, 13, @@ -574,7 +575,6 @@ CommandCost CmdRemoveRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint */ CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - Depot *d; CommandCost cost; Slope tileh; @@ -609,18 +609,20 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); - d = AllocateDepot(); + Depot *d = new Depot(tile); + if (d == NULL) return CMD_ERROR; + AutoPtrT d_auto_delete = d; if (flags & DC_EXEC) { MakeRailDepot(tile, _current_player, dir, (RailType)p1); MarkTileDirtyByTile(tile); - d->xy = tile; d->town_index = ClosestTownFromTile(tile, (uint)-1)->index; UpdateSignalsOnSegment(tile, dir); YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir))); + d_auto_delete.Detach(); } return cost.AddCost(_price.build_train_depot); @@ -1110,7 +1112,8 @@ static CommandCost RemoveTrainDepot(TileIndex tile, uint32 flags) if (flags & DC_EXEC) { DiagDirection dir = GetRailDepotDirection(tile); - DeleteDepot(GetDepotByTile(tile)); + DoClearSquare(tile); + delete GetDepotByTile(tile); UpdateSignalsOnSegment(tile, dir); YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir))); } -- cgit v1.2.3-54-g00ecf