28 #include "yapf/yapf.h" |
28 #include "yapf/yapf.h" |
29 #include "newgrf_engine.h" |
29 #include "newgrf_engine.h" |
30 #include "newgrf_callbacks.h" |
30 #include "newgrf_callbacks.h" |
31 #include "newgrf_station.h" |
31 #include "newgrf_station.h" |
32 #include "train.h" |
32 #include "train.h" |
33 #include "misc/autoptr.hpp" |
|
34 #include "variables.h" |
33 #include "variables.h" |
35 #include "autoslope.h" |
34 #include "autoslope.h" |
36 #include "transparency.h" |
35 #include "transparency.h" |
37 #include "water.h" |
36 #include "water.h" |
38 #include "tunnelbridge_map.h" |
37 #include "tunnelbridge_map.h" |
761 CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
760 CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
762 if (CmdFailed(cost)) return CMD_ERROR; |
761 if (CmdFailed(cost)) return CMD_ERROR; |
763 |
762 |
764 if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
763 if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
765 |
764 |
766 Depot *d = new Depot(tile); |
765 if (!Depot::CanAllocateItem()) return CMD_ERROR; |
767 |
|
768 if (d == NULL) return CMD_ERROR; |
|
769 AutoPtrT<Depot> d_auto_delete = d; |
|
770 |
766 |
771 if (flags & DC_EXEC) { |
767 if (flags & DC_EXEC) { |
|
768 Depot *d = new Depot(tile); |
772 MakeRailDepot(tile, _current_player, dir, (RailType)p1); |
769 MakeRailDepot(tile, _current_player, dir, (RailType)p1); |
773 MarkTileDirtyByTile(tile); |
770 MarkTileDirtyByTile(tile); |
774 |
771 |
775 d->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
772 d->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
776 |
773 |
777 AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_player); |
774 AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_player); |
778 YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir))); |
775 YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir))); |
779 d_auto_delete.Detach(); |
|
780 } |
776 } |
781 |
777 |
782 return cost.AddCost(_price.build_train_depot); |
778 return cost.AddCost(_price.build_train_depot); |
783 } |
779 } |
784 |
780 |