tunnelbridge_cmd.c
changeset 3242 1cefa03f0d5e
parent 3234 986c30171e92
child 3243 6232a0862ae6
equal deleted inserted replaced
3241:ffde1325bab8 3242:1cefa03f0d5e
   331 				if (_m[tile].m5 != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
   331 				if (_m[tile].m5 != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
   332 					goto not_valid_below;
   332 					goto not_valid_below;
   333 				}
   333 				}
   334 				transport_under = TRANSPORT_RAIL;
   334 				transport_under = TRANSPORT_RAIL;
   335 				owner_under = GetTileOwner(tile);
   335 				owner_under = GetTileOwner(tile);
   336 				rail_under = GB(_m[tile].m3, 0, 4);
   336 				rail_under = GetRailType(tile);
   337 				break;
   337 				break;
   338 
   338 
   339 			case MP_STREET:
   339 			case MP_STREET:
   340 				if (GetRoadType(tile) != ROAD_NORMAL ||
   340 				if (GetRoadType(tile) != ROAD_NORMAL ||
   341 						GetRoadBits(tile) != (direction == AXIS_X ? ROAD_Y : ROAD_X)) {
   341 						GetRoadBits(tile) != (direction == AXIS_X ? ROAD_Y : ROAD_X)) {
   670 		DoClearSquare(tile);
   670 		DoClearSquare(tile);
   671 		DoClearSquare(endtile);
   671 		DoClearSquare(endtile);
   672 		for (c = tile + delta; c != endtile; c += delta) {
   672 		for (c = tile + delta; c != endtile; c += delta) {
   673 			if (IsTransportUnderBridge(c)) {
   673 			if (IsTransportUnderBridge(c)) {
   674 				if (GetTransportTypeUnderBridge(c) == TRANSPORT_RAIL) {
   674 				if (GetTransportTypeUnderBridge(c) == TRANSPORT_RAIL) {
   675 					MakeRailNormal(c, GetTileOwner(c), GetRailBitsUnderBridge(c), GB(_m[c].m3, 0, 3));
   675 					MakeRailNormal(c, GetTileOwner(c), GetRailBitsUnderBridge(c), GetRailType(tile));
   676 				} else {
   676 				} else {
   677 					uint town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0;
   677 					uint town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0;
   678 					MakeRoadNormal(c, GetTileOwner(c), GetRoadBitsUnderBridge(c), town);
   678 					MakeRoadNormal(c, GetTileOwner(c), GetRoadBitsUnderBridge(c), town);
   679 				}
   679 				}
   680 				MarkTileDirtyByTile(c);
   680 				MarkTileDirtyByTile(c);
   719 	Vehicle *v;
   719 	Vehicle *v;
   720 
   720 
   721 	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
   721 	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
   722 		if (!CheckTileOwnership(tile)) return CMD_ERROR;
   722 		if (!CheckTileOwnership(tile)) return CMD_ERROR;
   723 
   723 
   724 		if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
   724 		if (GetRailType(tile) == totype) return CMD_ERROR;
   725 
   725 
   726 		endtile = CheckTunnelBusy(tile, &length);
   726 		endtile = CheckTunnelBusy(tile, &length);
   727 		if (endtile == INVALID_TILE) return CMD_ERROR;
   727 		if (endtile == INVALID_TILE) return CMD_ERROR;
   728 
   728 
   729 		if (exec) {
   729 		if (exec) {
   730 			SB(_m[tile].m3, 0, 4, totype);
   730 			SetRailType(tile, totype);
   731 			SB(_m[endtile].m3, 0, 4, totype);
   731 			SetRailType(endtile, totype);
   732 			MarkTileDirtyByTile(tile);
   732 			MarkTileDirtyByTile(tile);
   733 			MarkTileDirtyByTile(endtile);
   733 			MarkTileDirtyByTile(endtile);
   734 		}
   734 		}
   735 		return (length + 1) * (_price.build_rail >> 1);
   735 		return (length + 1) * (_price.build_rail >> 1);
   736 	} else if (IsBridge(tile) &&
   736 	} else if (IsBridge(tile) &&
   739 			GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
   739 			GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
   740 		// only check for train under bridge
   740 		// only check for train under bridge
   741 		if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
   741 		if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
   742 			return CMD_ERROR;
   742 			return CMD_ERROR;
   743 
   743 
   744 		// tile is already of requested type?
   744 		if (GetRailType(tile) == totype) return CMD_ERROR;
   745 		if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
   745 
   746 		// change type.
       
   747 		if (exec) {
   746 		if (exec) {
   748 			SB(_m[tile].m3, 0, 4, totype);
   747 			SetRailType(tile, totype);
   749 			MarkTileDirtyByTile(tile);
   748 			MarkTileDirtyByTile(tile);
   750 		}
   749 		}
   751 		return _price.build_rail >> 1;
   750 		return _price.build_rail >> 1;
   752 	} else if (IsBridge(tile) && IsBridgeRamp(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
   751 	} else if (IsBridge(tile) && IsBridgeRamp(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
   753 		TileIndexDiff delta;
   752 		TileIndexDiff delta;
   769 		if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) {
   768 		if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) {
   770 			_error_message = STR_8803_TRAIN_IN_THE_WAY;
   769 			_error_message = STR_8803_TRAIN_IN_THE_WAY;
   771 			return CMD_ERROR;
   770 			return CMD_ERROR;
   772 		}
   771 		}
   773 
   772 
   774 		if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
   773 		if (GetRailType(tile) == totype) return CMD_ERROR;
   775 
   774 
   776 		if (exec) {
   775 		if (exec) {
   777 			SB(_m[tile].m3, 0, 4, totype);
   776 			SetRailType(tile, totype);
   778 			SB(_m[endtile].m3, 0, 4, totype);
   777 			SetRailType(endtile, totype);
   779 			MarkTileDirtyByTile(tile);
   778 			MarkTileDirtyByTile(tile);
   780 			MarkTileDirtyByTile(endtile);
   779 			MarkTileDirtyByTile(endtile);
   781 		}
   780 		}
   782 		cost = 2 * (_price.build_rail >> 1);
   781 		cost = 2 * (_price.build_rail >> 1);
   783 		delta = TileOffsByDir(GetBridgeRampDirection(tile));
   782 		delta = TileOffsByDir(GetBridgeRampDirection(tile));
   784 		for (tile += delta; tile != endtile; tile += delta) {
   783 		for (tile += delta; tile != endtile; tile += delta) {
   785 			if (exec) {
   784 			if (exec) {
   786 				SB(_m[tile].m3, 4, 4, totype);
   785 				SetRailTypeOnBridge(tile, totype);
   787 				MarkTileDirtyByTile(tile);
   786 				MarkTileDirtyByTile(tile);
   788 			}
   787 			}
   789 			cost += _price.build_rail >> 1;
   788 			cost += _price.build_rail >> 1;
   790 		}
   789 		}
   791 
   790 
   916 	const PalSpriteID *b;
   915 	const PalSpriteID *b;
   917 	bool ice = _m[ti->tile].m4 & 0x80;
   916 	bool ice = _m[ti->tile].m4 & 0x80;
   918 
   917 
   919 	if (IsTunnel(ti->tile)) {
   918 	if (IsTunnel(ti->tile)) {
   920 		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
   919 		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
   921 			image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel;
   920 			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
   922 		} else {
   921 		} else {
   923 			image = SPR_TUNNEL_ENTRY_REAR_ROAD;
   922 			image = SPR_TUNNEL_ENTRY_REAR_ROAD;
   924 		}
   923 		}
   925 
   924 
   926 		if (ice) image += 32;
   925 		if (ice) image += 32;
   934 
   933 
   935 		if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
   934 		if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
   936 			RailType rt;
   935 			RailType rt;
   937 
   936 
   938 			if (IsBridgeRamp(ti->tile)) {
   937 			if (IsBridgeRamp(ti->tile)) {
   939 				rt = GB(_m[ti->tile].m3, 0, 3);
   938 				rt = GetRailType(ti->tile);
   940 			} else {
   939 			} else {
   941 				rt = GB(_m[ti->tile].m3, 4, 3);
   940 				rt = GetRailTypeOnBridge(ti->tile);
   942 			}
   941 			}
   943 
   942 
   944 			base_offset = GetRailTypeInfo(rt)->bridge_offset;
   943 			base_offset = GetRailTypeInfo(rt)->bridge_offset;
   945 			assert(base_offset != 8); /* This one is used for roads */
   944 			assert(base_offset != 8); /* This one is used for roads */
   946 		} else {
   945 		} else {
   985 					int f = _bridge_foundations[axis][ti->tileh];
   984 					int f = _bridge_foundations[axis][ti->tileh];
   986 					if (f) DrawFoundation(ti, f);
   985 					if (f) DrawFoundation(ti, f);
   987 				}
   986 				}
   988 
   987 
   989 				if (GetTransportTypeUnderBridge(ti->tile) == TRANSPORT_RAIL) {
   988 				if (GetTransportTypeUnderBridge(ti->tile) == TRANSPORT_RAIL) {
   990 					const RailtypeInfo *rti = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4));
   989 					const RailtypeInfo* rti = GetRailTypeInfo(GetRailType(ti->tile));
   991 
   990 
   992 					if (ti->tileh == 0) {
   991 					if (ti->tileh == 0) {
   993 						image = (axis == AXIS_X ? SPR_RAIL_TRACK_Y : SPR_RAIL_TRACK_X);
   992 						image = (axis == AXIS_X ? SPR_RAIL_TRACK_Y : SPR_RAIL_TRACK_X);
   994 					} else {
   993 					} else {
   995 						image = SPR_RAIL_TRACK_Y + _track_sloped_sprites[ti->tileh - 1];
   994 						image = SPR_RAIL_TRACK_Y + _track_sloped_sprites[ti->tileh - 1];