summaryrefslogtreecommitdiff
path: root/src/waypoint.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-04-23 20:56:08 +0000
committerrubidium <rubidium@openttd.org>2008-04-23 20:56:08 +0000
commit6939569362a8c3e2c1b5174962309d0d73152845 (patch)
treea6906b106143841dcbc6aea392d11baa75492e05 /src/waypoint.cpp
parent1ba6e3deebf4c26896491842df51dc26f29a1c5d (diff)
downloadopenttd-6939569362a8c3e2c1b5174962309d0d73152845.tar.xz
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
Diffstat (limited to 'src/waypoint.cpp')
-rw-r--r--src/waypoint.cpp51
1 files changed, 24 insertions, 27 deletions
diff --git a/src/waypoint.cpp b/src/waypoint.cpp
index 781c67339..2a0e98eb6 100644
--- a/src/waypoint.cpp
+++ b/src/waypoint.cpp
@@ -18,7 +18,6 @@
#include "variables.h"
#include "yapf/yapf.h"
#include "newgrf.h"
-#include "misc/autoptr.hpp"
#include "strings_func.h"
#include "gfx_func.h"
#include "functions.h"
@@ -191,7 +190,6 @@ void AfterLoadWaypoints()
CommandCost CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
Waypoint *wp;
- AutoPtrT<Waypoint> wp_auto_delete;
Slope tileh;
Axis axis;
@@ -219,35 +217,35 @@ CommandCost CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint3
/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
wp = FindDeletedWaypointCloseTo(tile);
- if (wp == NULL) {
- wp = new Waypoint(tile);
- if (wp == NULL) return CMD_ERROR;
+ if (wp == NULL && !Waypoint::CanAllocateItem()) return CMD_ERROR;
- wp_auto_delete = wp;
+ if (flags & DC_EXEC) {
+ if (wp == NULL) {
+ wp = new Waypoint(tile);
+ if (wp == NULL) return CMD_ERROR;
- wp->town_index = INVALID_TOWN;
- wp->name = NULL;
- wp->town_cn = 0;
- } else if (flags & DC_EXEC) {
- /* Move existing (recently deleted) waypoint to the new location */
-
- /* First we update the destination for all vehicles that
- * have the old waypoint in their orders. */
- Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_TRAIN &&
- v->First() == v &&
- v->current_order.IsType(OT_GOTO_WAYPOINT) &&
- v->dest_tile == wp->xy) {
- v->dest_tile = tile;
+ wp->town_index = INVALID_TOWN;
+ wp->name = NULL;
+ wp->town_cn = 0;
+ } else {
+ /* Move existing (recently deleted) waypoint to the new location */
+
+ /* First we update the destination for all vehicles that
+ * have the old waypoint in their orders. */
+ Vehicle *v;
+ FOR_ALL_VEHICLES(v) {
+ if (v->type == VEH_TRAIN &&
+ v->First() == v &&
+ v->current_order.IsType(OT_GOTO_WAYPOINT) &&
+ v->dest_tile == wp->xy) {
+ v->dest_tile = tile;
+ }
}
- }
- RedrawWaypointSign(wp);
- wp->xy = tile;
- }
+ RedrawWaypointSign(wp);
+ wp->xy = tile;
+ }
- if (flags & DC_EXEC) {
const StationSpec* statspec;
MakeRailWaypoint(tile, GetTileOwner(tile), axis, GetRailType(tile), wp->index);
@@ -274,7 +272,6 @@ CommandCost CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint3
UpdateWaypointSign(wp);
RedrawWaypointSign(wp);
YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis));
- wp_auto_delete.Detach();
}
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_train_depot);