Index: src/lang/english.txt
===================================================================
--- src/lang/english.txt	(revision 22103)
+++ src/lang/english.txt	(working copy)
@@ -1887,6 +1887,7 @@
 STR_TRANSPARENT_STRUCTURES_TOOLTIP                              :{BLACK}Toggle transparency for structures like lighthouses and antennas. Ctrl+Click to lock
 STR_TRANSPARENT_CATENARY_TOOLTIP                                :{BLACK}Toggle transparency for catenary. Ctrl+Click to lock
 STR_TRANSPARENT_LOADING_TOOLTIP                                 :{BLACK}Toggle transparency for loading indicators. Ctrl+Click to lock
+STR_TRANSPARENT_TUNNELS_TOOLTIP                                 :{BLACK}Toggle transparency for vehicles in tunnels. Ctrl+Click to lock.
 STR_TRANSPARENT_INVISIBLE_TOOLTIP                               :{BLACK}Set objects invisible instead of transparent
 
 # Base for station construction window(s)
Index: src/rail_cmd.cpp
===================================================================
--- src/rail_cmd.cpp	(revision 22103)
+++ src/rail_cmd.cpp	(working copy)
@@ -2364,6 +2364,8 @@
 	RailGroundType old_ground = GetRailGroundType(tile);
 	RailGroundType new_ground;
 
+	ReduceStuckCounter(tile);
+
 	if (old_ground == RAIL_GROUND_WATER) {
 		TileLoop_Water(tile);
 		return;
Index: src/smallmap_gui.cpp
===================================================================
--- src/smallmap_gui.cpp	(revision 22103)
+++ src/smallmap_gui.cpp	(working copy)
@@ -237,6 +237,21 @@
 };
 assert_compile(lengthof(_green_map_heights) == MAX_TILE_HEIGHT + 1);
 
+/**
+ * Colour Coding for Stuck Counter
+ */
+static const uint32 _stuck_counter_colours[] = {
+	MKCOLOUR(0xD0D0D0D0),
+	MKCOLOUR(0xCECECECE),
+	MKCOLOUR(0xBFBFBFBF),
+	MKCOLOUR(0xBDBDBDBD),
+	MKCOLOUR(0xBABABABA),
+	MKCOLOUR(0xB8B8B8B8),
+	MKCOLOUR(0xB6B6B6B6),
+	MKCOLOUR(0xB4B4B4B4),
+};
+assert_compile(lengthof(_stuck_counter_colours) == 8);
+
 /** Height map colours for the dark green colour scheme, ordered by height. */
 static const uint32 _dark_green_map_heights[] = {
 	MKCOLOUR(0x60606060),
@@ -468,13 +483,9 @@
 			default:              return MKCOLOUR(0xFFFFFFFF);
 		}
 	} else if (t == MP_RAILWAY) {
-		AndOr andor = {
-			GetRailTypeInfo(GetRailType(tile))->map_colour * MKCOLOUR(0x00010100),
-			_smallmap_contours_andor[t].mand
-		};
-
-		const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
-		return ApplyMask(cs->default_colour, &andor);
+		byte c = GetStuckCounter(tile);
+		if (c==0) return 0;
+		return _stuck_counter_colours[c/32];
 	}
 
 	/* Ground colour */
Index: src/table/settings.h
===================================================================
--- src/table/settings.h	(revision 22103)
+++ src/table/settings.h	(working copy)
@@ -282,8 +282,8 @@
 #endif
 	  SDTG_VAR("sprite_cache_size",SLE_UINT, S, 0, _sprite_cache_size,     4, 1, 64, 0, STR_NULL, NULL),
 	  SDTG_VAR("player_face",    SLE_UINT32, S, 0, _company_manager_face,0,0,0xFFFFFFFF,0, STR_NULL, NULL),
-	  SDTG_VAR("transparency_options", SLE_UINT, S, 0, _transparency_opt,  0,0,0x1FF,0, STR_NULL, NULL),
-	  SDTG_VAR("transparency_locks", SLE_UINT, S, 0, _transparency_lock,   0,0,0x1FF,0, STR_NULL, NULL),
+	  SDTG_VAR("transparency_options", SLE_UINT, S, 0, _transparency_opt,  0,0,0x3FF,0, STR_NULL, NULL),
+	  SDTG_VAR("transparency_locks", SLE_UINT, S, 0, _transparency_lock,   0,0,0x3FF,0, STR_NULL, NULL),
 	  SDTG_VAR("invisibility_options", SLE_UINT, S, 0, _invisibility_opt,  0,0, 0xFF,0, STR_NULL, NULL),
 	  SDTG_STR("keyboard",         SLE_STRB, S, 0, _keyboard_opt[0],       NULL,    STR_NULL, NULL),
 	  SDTG_STR("keyboard_caps",    SLE_STRB, S, 0, _keyboard_opt[1],       NULL,    STR_NULL, NULL),
Index: src/train_cmd.cpp
===================================================================
--- src/train_cmd.cpp	(revision 22103)
+++ src/train_cmd.cpp	(working copy)
@@ -2991,6 +2991,9 @@
 
 						/* Don't handle stuck trains here. */
 						if (HasBit(v->flags, VRF_TRAIN_STUCK)) return;
+						/* this codepath seems to be run every 5 ticks, so increase counter twice every 20 ticks */
+						IncreaseStuckCounter(v->tile);
+						if (v->tick_counter % 4 == 0) IncreaseStuckCounter(v->tile);
 
 						if (!HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(i))) {
 							v->cur_speed = 0;
@@ -3150,7 +3153,7 @@
 			} else {
 				v->x_pos = gp.x;
 				v->y_pos = gp.y;
-				VehicleMove(v, !(v->vehstatus & VS_HIDDEN));
+				VehicleMove(v, v->IsDrawn());
 				continue;
 			}
 		}
@@ -3591,6 +3594,7 @@
 	/* Handle stuck trains. */
 	if (!mode && HasBit(v->flags, VRF_TRAIN_STUCK)) {
 		++v->wait_counter;
+		if (v->tick_counter % 4 == 0) IncreaseStuckCounter(v->tile);
 
 		/* Should we try reversing this tick if still stuck? */
 		bool turn_around = v->wait_counter % (_settings_game.pf.wait_for_pbs_path * DAY_TICKS) == 0 && _settings_game.pf.reverse_at_signals;
@@ -3666,7 +3670,7 @@
 	}
 
 	for (Train *u = v; u != NULL; u = u->Next()) {
-		if ((u->vehstatus & VS_HIDDEN) != 0) continue;
+		if (!u->IsDrawn()) continue;
 
 		u->UpdateViewport(false, false);
 	}
Index: src/transparency.h
===================================================================
--- src/transparency.h	(revision 22103)
+++ src/transparency.h	(working copy)
@@ -31,6 +31,7 @@
 	TO_STRUCTURES, ///< other objects such as transmitters and lighthouses
 	TO_CATENARY,   ///< catenary
 	TO_LOADING,    ///< loading indicators
+	TO_TUNNELS,    ///< vehicles in tunnels
 	TO_END,
 };
 
Index: src/transparency_gui.cpp
===================================================================
--- src/transparency_gui.cpp	(revision 22103)
+++ src/transparency_gui.cpp	(working copy)
@@ -35,14 +35,14 @@
 	TTW_WIDGET_STRUCTURES,               ///< Object structure transparency toggle button.
 	TTW_WIDGET_CATENARY,                 ///< Catenary transparency toggle button.
 	TTW_WIDGET_LOADING,                  ///< Loading indicators transparency toggle button.
+	TTW_WIDGET_TUNNELS,                  ///< Vehicles in tunnels toggle button.
 	TTW_WIDGET_END,                      ///< End of toggle buttons.
 
 	/* Panel with buttons for invisibility */
 	TTW_WIDGET_BUTTONS,                  ///< Panel with 'invisibility' buttons.
 };
 
-class TransparenciesWindow : public Window
-{
+class TransparenciesWindow : public Window {
 public:
 	TransparenciesWindow(const WindowDesc *desc, int window_number) : Window()
 	{
@@ -51,7 +51,7 @@
 
 	virtual void OnPaint()
 	{
-		OnInvalidateData(0); // Must be sure that the widgets show the transparency variable changes, also when we use shortcuts.
+		this->OnInvalidateData(0); // Must be sure that the widgets show the transparency variable changes, also when we use shortcuts.
 		this->DrawWidgets();
 	}
 
@@ -66,14 +66,15 @@
 			case TTW_WIDGET_BRIDGES:
 			case TTW_WIDGET_STRUCTURES:
 			case TTW_WIDGET_CATENARY:
-			case TTW_WIDGET_LOADING: {
+			case TTW_WIDGET_LOADING:
+			case TTW_WIDGET_TUNNELS: {
 				uint i = widget - TTW_WIDGET_BEGIN;
 				if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, r.left + 1, r.top + 1);
 				break;
 			}
 			case TTW_WIDGET_BUTTONS:
 				for (uint i = TTW_WIDGET_BEGIN; i < TTW_WIDGET_END; i++) {
-					if (i == TTW_WIDGET_LOADING) continue; // Do not draw button for invisible loading indicators.
+					if (i >= TTW_WIDGET_LOADING) continue; // Do not draw button for invisible loading indicators.
 
 					const NWidgetBase *wi = this->GetWidget<NWidgetBase>(i);
 					DrawFrameRect(wi->pos_x + 1, r.top + 2, wi->pos_x + wi->current_x - 2, r.bottom - 2, COLOUR_PALE_GREEN,
@@ -85,7 +86,7 @@
 
 	virtual void OnClick(Point pt, int widget, int click_count)
 	{
-		if (widget >= TTW_WIDGET_BEGIN && widget < TTW_WIDGET_END) {
+		if (IsInsideMM(widget, TTW_WIDGET_BEGIN, TTW_WIDGET_END)) {
 			if (_ctrl_pressed) {
 				/* toggle the bit of the transparencies lock variable */
 				ToggleTransparencyLock((TransparencyOption)(widget - TTW_WIDGET_BEGIN));
@@ -149,7 +150,8 @@
 		NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_STRUCTURES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_TOOLTIP),
 		NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_CATENARY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_TOOLTIP),
 		NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_LOADING), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_TOOLTIP),
-		NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
+		NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_TUNNELS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_TRANSPARENT_TUNNELS_TOOLTIP),
+	NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
 	EndContainer(),
 	/* Panel with 'inivisibility' buttons. */
 	NWidget(WWT_PANEL, COLOUR_DARK_GREEN, TTW_WIDGET_BUTTONS), SetMinimalSize(219, 13), SetDataTip(0x0, STR_TRANSPARENT_INVISIBLE_TOOLTIP),
Index: src/roadveh_cmd.cpp
===================================================================
--- src/roadveh_cmd.cpp	(revision 22103)
+++ src/roadveh_cmd.cpp	(working copy)
@@ -1097,7 +1097,7 @@
 
 		v->x_pos = gp.x;
 		v->y_pos = gp.y;
-		VehicleMove(v, !(v->vehstatus & VS_HIDDEN));
+		VehicleMove(v, v->IsDrawn());
 		return true;
 	}
 
Index: src/vehicle.cpp
===================================================================
--- src/vehicle.cpp	(revision 22103)
+++ src/vehicle.cpp	(working copy)
@@ -198,7 +198,15 @@
 	return pass;
 }
 
+bool Vehicle::IsDrawn() const
+{
+	return !(this->vehstatus & VS_HIDDEN) ||
+			(!IsTransparencySet(TO_TUNNELS) &&
+				((this->type == VEH_TRAIN && Train::From(this)->track == TRACK_BIT_WORMHOLE) ||
+				(this->type == VEH_ROAD && RoadVehicle::From(this)->state == RVSB_WORMHOLE)));
+}
 
+
 /**
  * Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.
  * @param engine The engine that caused the problem
@@ -740,7 +748,7 @@
 
 	/* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles,
 	 * it may happen that vehicle chain is deleted when visible */
-	if (!(this->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(this);
+	if (this->IsDrawn()) MarkSingleVehicleDirty(this);
 
 	Vehicle *v = this->Next();
 	this->SetNext(NULL);
@@ -900,7 +908,7 @@
 	if (v->vehstatus & VS_DEFPAL) pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
 
 	AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs,
-		v->x_extent, v->y_extent, v->z_extent, v->z_pos, (v->vehstatus & VS_SHADOW) != 0);
+		v->x_extent, v->y_extent, v->z_extent, v->z_pos, (v->vehstatus & (VS_SHADOW | VS_HIDDEN)));
 }
 
 /**
@@ -941,7 +949,7 @@
 			const Vehicle *v = _vehicle_position_hash[x + y]; // already masked & 0xFFF
 
 			while (v != NULL) {
-				if (!(v->vehstatus & VS_HIDDEN) &&
+				if (v->IsDrawn() &&
 						l <= v->coord.right &&
 						t <= v->coord.bottom &&
 						r >= v->coord.left &&
@@ -976,7 +984,7 @@
 	y = ScaleByZoom(y, vp->zoom) + vp->virtual_top;
 
 	FOR_ALL_VEHICLES(v) {
-		if ((v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0 &&
+		if (v->IsDrawn() && !(v->vehstatus & VS_UNCLICKABLE) &&
 				x >= v->coord.left && x <= v->coord.right &&
 				y >= v->coord.top && y <= v->coord.bottom) {
 
Index: src/vehicle_base.h
===================================================================
--- src/vehicle_base.h	(revision 22103)
+++ src/vehicle_base.h	(working copy)
@@ -254,6 +254,12 @@
 	void HandleLoading(bool mode = false);
 
 	/**
+	 * Is this vehicle drawn?
+	 * @return true if it is drawn
+	 */
+	bool IsDrawn() const;
+
+	/**
 	 * Marks the vehicles to be redrawn and updates cached variables
 	 *
 	 * This method marks the area of the vehicle on the screen as dirty.
Index: src/rail_map.h
===================================================================
--- src/rail_map.h	(revision 22103)
+++ src/rail_map.h	(working copy)
@@ -552,4 +552,27 @@
 	_me[t].m7 = 0;
 }
 
+
+static inline void IncreaseStuckCounter(TileIndex t)
+{
+	if (!IsTileType(t, MP_RAILWAY)) return;
+	if (_me[t].m7 == 255) return;
+	_me[t].m7++;
+}
+
+
+static inline void ReduceStuckCounter(TileIndex t)
+{
+	if (!IsTileType(t, MP_RAILWAY)) return;
+	_me[t].m7 -= _me[t].m7/4;
+}
+
+
+static inline byte GetStuckCounter(TileIndex t)
+{
+	if (!IsTileType(t, MP_RAILWAY)) return 0;
+	return _me[t].m7;
+
+}
+
 #endif /* RAIL_MAP_H */
Index: findversion.sh
===================================================================
--- findversion.sh	(revision 22103)
+++ findversion.sh	(working copy)
@@ -106,22 +106,19 @@
 	fi
 elif [ -d "$ROOT_DIR/.hg" ]; then
 	# We are a hg checkout
-	if [ -n "`hg status | grep -v '^?'`" ]; then
+	if [ -n "`hg status | grep -v '^?'`" ] || [ -z "`hg parent --template="{svnrev}"`" ]; then
 		MODIFIED="2"
 	fi
 	HASH=`LC_ALL=C hg id -i | cut -c1-12`
 	REV="h`echo $HASH | cut -c1-8`"
 	BRANCH="`hg branch | sed 's@^default$@@'`"
-	TAG="`hg id -t | grep -v 'tip$'`"
+	REV_NR=`hg log -f --template="{svnrev}\n" | grep -v "^$" | head -n 1`
+	REV="r$REV_NR"
+	TAG="`hg log -r "svnrev($REV_NR)" --template="{tags}" | grep -v 'tip$' | sed s@qparent@@ | cut -f1 -d' '`"
 	if [ -n "$TAG" ]; then
 		BRANCH=""
 		REV="$TAG"
 	fi
-	REV_NR=`LC_ALL=C hg log -f -k "(svn r" -l 1 --template "{desc|firstline}\n" | grep "^(svn r[0-9]*)" | sed "s@.*(svn r\([0-9]*\)).*@\1@"`
-	if [ -z "$REV_NR" ]; then
-		# No rev? Maybe it is a custom hgsubversion clone
-		REV_NR=`LC_ALL=C hg parent --template="{svnrev}"`
-	fi
 elif [ -f "$ROOT_DIR/.ottdrev" ]; then
 	# We are an exported source bundle
 	cat $ROOT_DIR/.ottdrev
@@ -134,10 +131,6 @@
 	REV_NR=""
 fi
 
-if [ "$MODIFIED" -eq "2" ]; then
-	REV="${REV}M"
-fi
-
 CLEAN_REV=${REV}
 
 if [ -n "$BRANCH" ]; then
Index: openttd-clientpatches-1.1.1.1.0_RC1-patch.err.log
===================================================================
