summaryrefslogtreecommitdiff
path: root/src/tunnelbridge_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-11-21 17:42:18 +0000
committerfrosch <frosch@openttd.org>2010-11-21 17:42:18 +0000
commit0fff26db9725b1c0ea414bb246e842375c5a3e31 (patch)
tree7280cf0663cfa69c4a83dd280f920a21b3937fe8 /src/tunnelbridge_cmd.cpp
parentd5360390d00181b69a2aa90528a417d1299645d6 (diff)
downloadopenttd-0fff26db9725b1c0ea414bb246e842375c5a3e31.tar.xz
(svn r21289) -Fix [FS#4133]: Make terraforming and tunnel-excavation handle DC_AUTO-clearable multitile objects.
Diffstat (limited to 'src/tunnelbridge_cmd.cpp')
-rw-r--r--src/tunnelbridge_cmd.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 7a706a871..59484b03c 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -38,6 +38,7 @@
#include "pbs.h"
#include "company_base.h"
#include "newgrf_railtype.h"
+#include "object_base.h"
#include "table/sprites.h"
#include "table/strings.h"
@@ -583,23 +584,31 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
if (IsWaterTile(end_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
+ /* Clear the tile in any case */
+ ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
+ if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
+ cost.AddCost(ret);
+
/* slope of end tile must be complementary to the slope of the start tile */
if (end_tileh != ComplementSlope(start_tileh)) {
- /* Check if there is a structure on the terraformed tile. Do not add the cost, that will be done by the terraforming
- * Note: Currently the town rating is also affected by this clearing-test. So effectivly the player is punished twice for clearing
- * the tree on end_tile.
- */
- ret = DoCommand(end_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR);
- if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
+ /* Mark the tile as already cleared for the terraform command.
+ * Do this for all tiles (like trees), not only objects. */
+ ClearedObjectArea *coa = FindClearedObject(end_tile);
+ if (coa == NULL) {
+ coa = _cleared_object_areas.Append();
+ coa->first_tile = end_tile;
+ coa->area = TileArea(end_tile, 1, 1);
+ }
+ /* Hide the tile from the terraforming command */
+ TileIndex old_first_tile = coa->first_tile;
+ coa->first_tile = INVALID_TILE;
ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
+ coa->first_tile = old_first_tile;
if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
- } else {
- ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (ret.Failed()) return ret;
+ cost.AddCost(ret);
}
cost.AddCost(_price[PR_BUILD_TUNNEL]);
- cost.AddCost(ret);
/* Pay for the rail/road in the tunnel including entrances */
switch (transport_type) {