src/tunnelbridge_cmd.cpp
changeset 7677 347f780de06a
parent 7601 988040ee27f4
child 7682 ee53a5efa35b
equal deleted inserted replaced
7676:926233c6e06a 7677:347f780de06a
   530 	/* if the command fails from here on we want the end tile to be highlighted */
   530 	/* if the command fails from here on we want the end tile to be highlighted */
   531 	_build_tunnel_endtile = end_tile;
   531 	_build_tunnel_endtile = end_tile;
   532 
   532 
   533 	/* slope of end tile must be complementary to the slope of the start tile */
   533 	/* slope of end tile must be complementary to the slope of the start tile */
   534 	if (end_tileh != ComplementSlope(start_tileh)) {
   534 	if (end_tileh != ComplementSlope(start_tileh)) {
   535 		/*
   535 		/* Check if there is a structure on the terraformed tile. Do not add the cost, that will be done by the terraforming */
   536 		 * A lot of things can be autosloped, but then there is still a structure with
   536 		ret = DoCommand(end_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR);
   537 		 * on top of a tunnel entrance which is bad. Therefor we disallow those.
   537 		if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
   538 		 * Furthermore half road bits (not tram bits) can always be removed, so we
   538 
   539 		 * need to preserve that behaviour here too.
   539 		ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
   540 		 */
   540 		if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
   541 		switch (GetTileType(end_tile)) {
       
   542 			default: return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
       
   543 
       
   544 			/* Tiles that can be (safely) "auto" terraformed for tunnels */
       
   545 			case MP_ROAD:
       
   546 				if (GetRoadTileType(end_tile) != ROAD_TILE_NORMAL ||       // Depots and crossings can't be removed
       
   547 						(GetRoadTypes(end_tile) & ROADTYPES_TRAMHWAY) != 0 ||      // Half tram bits must not be removed
       
   548 						COUNTBITS(GetRoadBits(end_tile, ROADTYPE_ROAD)) > 1) { // Non-half road bits must not be removed either
       
   549 					return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
       
   550 				}
       
   551 				/* FALL THROUGH */
       
   552 			case MP_CLEAR:
       
   553 			case MP_TREES:
       
   554 				ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
       
   555 				if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
       
   556 				break;
       
   557 		}
       
   558 	} else {
   541 	} else {
   559 		ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   542 		ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   560 		if (CmdFailed(ret)) return ret;
   543 		if (CmdFailed(ret)) return ret;
   561 	}
   544 	}
   562 	cost.AddCost(_price.build_tunnel);
   545 	cost.AddCost(_price.build_tunnel);