summaryrefslogtreecommitdiff
path: root/src/road_cmd.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-03-14 15:42:26 +0000
committeralberth <alberth@openttd.org>2010-03-14 15:42:26 +0000
commit05e549ccdcb4859fcfd80ab2a03803b387cf5872 (patch)
tree2fa83ddd4d1a1856252fc1a7d644338f69567435 /src/road_cmd.cpp
parent28b0a3e335701d3fea872590476732487bad3efa (diff)
downloadopenttd-05e549ccdcb4859fcfd80ab2a03803b387cf5872.tar.xz
(svn r19420) -Codechange: Don't use _error_message to keep track of success/failure, use a had_success boolean.
Diffstat (limited to 'src/road_cmd.cpp')
-rw-r--r--src/road_cmd.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index d76dba933..5f985babc 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -728,14 +728,8 @@ do_clear:;
*/
CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- CommandCost cost(EXPENSES_CONSTRUCTION);
- bool had_bridge = false;
- bool had_tunnel = false;
- bool had_success = false;
DisallowedRoadDirections drd = DRD_NORTHBOUND;
- _error_message = INVALID_STRING_ID;
-
if (p1 >= MapSize()) return CMD_ERROR;
TileIndex end_tile = p1;
@@ -763,7 +757,12 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
/* No disallowed direction bits have to be toggled */
if (!HasBit(p2, 5)) drd = DRD_NONE;
+ CommandCost cost(EXPENSES_CONSTRUCTION);
+ CommandCost last_error = CMD_ERROR;
TileIndex tile = start_tile;
+ bool had_bridge = false;
+ bool had_tunnel = false;
+ bool had_success = false;
/* Start tile is the first tile clicked by the user. */
for (;;) {
RoadBits bits = AxisToRoadBits(axis);
@@ -772,11 +771,12 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
if (tile == end_tile && !HasBit(p2, 1)) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
- _error_message = INVALID_STRING_ID;
CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
if (ret.Failed()) {
- if (_error_message != STR_ERROR_ALREADY_BUILT) {
- if (HasBit(p2, 6)) return CMD_ERROR;
+ last_error = ret;
+ last_error.SetGlobalErrorMessage();
+ if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {
+ if (HasBit(p2, 6)) return last_error;
break;
}
} else {
@@ -804,7 +804,7 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
tile += TileOffsByDiagDir(dir);
}
- return !had_success ? CMD_ERROR : cost;
+ return had_success ? cost : last_error;
}
/** Remove a long piece of road.