Mercurial > hg > openttd
diff src/rail_cmd.cpp @ 7389:63f05f10a3c1 draft
(svn r10758) -Codechange: make the depot struct use the pool item class as super class.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 02 Aug 2007 22:33:53 +0000 |
parents | e03ba4271be4 |
children | 3de82701d2fc |
line wrap: on
line diff
--- 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 CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - Depot *d; CommandCost cost; Slope tileh; @@ -609,18 +609,20 @@ 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<Depot> 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 @@ if (flags & DC_EXEC) { DiagDirection dir = GetRailDepotDirection(tile); - DeleteDepot(GetDepotByTile(tile)); + DoClearSquare(tile); + delete GetDepotByTile(tile); UpdateSignalsOnSegment(tile, dir); YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir))); }