summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-14 17:05:33 +0000
committerrubidium <rubidium@openttd.org>2007-08-14 17:05:33 +0000
commitb169fceabc420305384679755620f4d464e2a9ac (patch)
tree74e101a132d80ca035119a9e590f5c1b44677315 /src
parente474b58d2fae23918ca8d7fe61d14c1aba9c3943 (diff)
downloadopenttd-b169fceabc420305384679755620f4d464e2a9ac.tar.xz
(svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
Diffstat (limited to 'src')
-rw-r--r--src/road_cmd.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index c79d263d9..d0a65fea4 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -673,7 +673,7 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32
CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
{
TileIndex start_tile, tile;
- CommandCost cost, ret;
+ CommandCost cost, ret, money;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@@ -695,6 +695,7 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint3
p2 ^= IS_INT_INSIDE(p2 & 3, 1, 3) ? 3 : 0;
}
+ money.AddCost(GetAvailableMoneyForCommand());
tile = start_tile;
/* Start tile is the small number. */
for (;;) {
@@ -705,8 +706,18 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint3
/* try to remove the halves. */
if (bits != 0) {
- ret = DoCommand(tile, rt << 4 | bits, 0, flags, CMD_REMOVE_ROAD);
- if (CmdSucceeded(ret)) cost.AddCost(ret);
+ ret = DoCommand(tile, rt << 4 | bits, 0, flags & ~DC_EXEC, CMD_REMOVE_ROAD);
+ if (CmdSucceeded(ret)) {
+ if (flags & DC_EXEC) {
+ money.AddCost(-ret.GetCost());
+ if (money.GetCost() < 0) {
+ _additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
+ return cost;
+ }
+ DoCommand(tile, rt << 4 | bits, 0, flags, CMD_REMOVE_ROAD);
+ }
+ cost.AddCost(ret);
+ }
}
if (tile == end_tile) break;