summaryrefslogtreecommitdiff
path: root/src/tree_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-06-18 19:53:50 +0000
committerrubidium <rubidium@openttd.org>2007-06-18 19:53:50 +0000
commit49220cc6f1e3570dc1b9001c40af2a8a4e35b649 (patch)
tree62843984493ffedb69f91d7b85cb631ecb61ff3e /src/tree_cmd.cpp
parent3771d666c0e6bb48980b7548a2b38b3594efb3ff (diff)
downloadopenttd-49220cc6f1e3570dc1b9001c40af2a8a4e35b649.tar.xz
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
Diffstat (limited to 'src/tree_cmd.cpp')
-rw-r--r--src/tree_cmd.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp
index 42598789d..8f5500300 100644
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -235,8 +235,6 @@ CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (ex < sx) Swap(ex, sx);
if (ey < sy) Swap(ey, sy);
- cost = 0; // total cost
-
for (x = sx; x <= ex; x++) {
for (y = sy; y <= ey; y++) {
TileIndex tile = TileXY(x, y);
@@ -254,7 +252,7 @@ CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
MarkTileDirtyByTile(tile);
}
/* 2x as expensive to add more trees to an existing tile */
- cost += _price.build_trees * 2;
+ cost.AddCost(_price.build_trees * 2);
break;
case MP_CLEAR:
@@ -265,8 +263,8 @@ CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
switch (GetClearGround(tile)) {
- case CLEAR_FIELDS: cost += _price.clear_3; break;
- case CLEAR_ROCKS: cost += _price.clear_2; break;
+ case CLEAR_FIELDS: cost.AddCost(_price.clear_3); break;
+ case CLEAR_ROCKS: cost.AddCost(_price.clear_2); break;
default: break;
}
@@ -297,7 +295,7 @@ CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TREE_RAINFOREST, TREE_CACTUS))
SetTropicZone(tile, TROPICZONE_RAINFOREST);
}
- cost += _price.build_trees;
+ cost.AddCost(_price.build_trees);
break;
default:
@@ -307,7 +305,7 @@ CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
}
- if (cost == 0) {
+ if (cost.GetCost() == 0) {
return_cmd_error(msg);
} else {
return cost;
@@ -443,7 +441,7 @@ static CommandCost ClearTile_Trees(TileIndex tile, byte flags)
if (flags & DC_EXEC) DoClearSquare(tile);
- return num * _price.remove_trees;
+ return CommandCost(num * _price.remove_trees);
}
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)