tunnelbridge_cmd.c
changeset 4246 6dcc0e44a367
parent 4239 4869ca42ffd9
child 4261 28670f743746
equal deleted inserted replaced
4245:e8d08dbda199 4246:6dcc0e44a367
   116 
   116 
   117 	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW));
   117 	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW));
   118 	if (HASBIT(valid, tileh)) return 0;
   118 	if (HASBIT(valid, tileh)) return 0;
   119 
   119 
   120 	valid =
   120 	valid =
   121 		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) |
   121 		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) | M(SLOPE_STEEP_N) |
   122 		(axis == AXIS_X ? M(SLOPE_E) : M(SLOPE_W));
   122 		(axis == AXIS_X ? M(SLOPE_E) | M(SLOPE_STEEP_E) : M(SLOPE_W) | M(SLOPE_STEEP_W));
   123 	if (HASBIT(valid, tileh)) return _price.terraform;
   123 	if (HASBIT(valid, tileh)) return _price.terraform;
   124 
   124 
   125 	return CMD_ERROR;
   125 	return CMD_ERROR;
   126 }
   126 }
   127 
   127 
   131 
   131 
   132 	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE));
   132 	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE));
   133 	if (HASBIT(valid, tileh)) return 0;
   133 	if (HASBIT(valid, tileh)) return 0;
   134 
   134 
   135 	valid =
   135 	valid =
   136 		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) |
   136 		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) | M(SLOPE_STEEP_S) |
   137 		(axis == AXIS_X ? M(SLOPE_W) : M(SLOPE_E));
   137 		(axis == AXIS_X ? M(SLOPE_W) | M(SLOPE_STEEP_W) : M(SLOPE_E) | M(SLOPE_STEEP_E));
   138 	if (HASBIT(valid, tileh)) return _price.terraform;
   138 	if (HASBIT(valid, tileh)) return _price.terraform;
   139 
   139 
   140 	return CMD_ERROR;
   140 	return CMD_ERROR;
   141 }
   141 }
   142 #undef M
   142 #undef M
   243 	}
   243 	}
   244 
   244 
   245 	tileh_start = GetTileSlope(tile_start, &z_start);
   245 	tileh_start = GetTileSlope(tile_start, &z_start);
   246 	tileh_end = GetTileSlope(tile_end, &z_end);
   246 	tileh_end = GetTileSlope(tile_end, &z_end);
   247 
   247 
       
   248 	if (IsSteepSlope(tileh_start)) z_start += TILE_HEIGHT;
   248 	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) {
   249 	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) {
   249 		z_start += TILE_HEIGHT;
   250 		z_start += TILE_HEIGHT;
   250 		tileh_start = SLOPE_FLAT;
   251 		tileh_start = SLOPE_FLAT;
   251 	}
   252 	}
   252 
   253 
       
   254 	if (IsSteepSlope(tileh_end)) z_end += TILE_HEIGHT;
   253 	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) {
   255 	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) {
   254 		z_end += TILE_HEIGHT;
   256 		z_end += TILE_HEIGHT;
   255 		tileh_end = SLOPE_FLAT;
   257 		tileh_end = SLOPE_FLAT;
   256 	}
   258 	}
   257 
   259 
   594 	uint h;
   596 	uint h;
   595 	uint tileh = GetTileSlope(t, &h);
   597 	uint tileh = GetTileSlope(t, &h);
   596 	uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
   598 	uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
   597 
   599 
   598 	// one height level extra if the ramp is on a flat foundation
   600 	// one height level extra if the ramp is on a flat foundation
   599 	return h + TILE_HEIGHT + (IS_INT_INSIDE(f, 1, 15) ? TILE_HEIGHT : 0);
   601 	return
       
   602 		h + TILE_HEIGHT +
       
   603 		(IS_INT_INSIDE(f, 1, 15) ? TILE_HEIGHT : 0) +
       
   604 		(IsSteepSlope(tileh) ? TILE_HEIGHT : 0);
   600 }
   605 }
   601 
   606 
   602 
   607 
   603 static int32 DoClearBridge(TileIndex tile, uint32 flags)
   608 static int32 DoClearBridge(TileIndex tile, uint32 flags)
   604 {
   609 {
   830 uint GetBridgeHeight(TileIndex t)
   835 uint GetBridgeHeight(TileIndex t)
   831 {
   836 {
   832 	return GetBridgeHeightRamp(GetSouthernBridgeEnd(t));
   837 	return GetBridgeHeightRamp(GetSouthernBridgeEnd(t));
   833 }
   838 }
   834 
   839 
   835 static const byte _bridge_foundations[2][16] = {
   840 static const byte _bridge_foundations[][31] = {
   836 // 0 1  2  3  4 5 6 7  8 9 10 11 12 13 14 15
   841 //  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15                      _S          _W    _N _E
   837 	{0,16,18,3,20,5,0,7,22,0,10,11,12,13,14},
   842 	{ 0,16,18, 3,20, 5, 0, 7,22, 0,10,11,12,13,14, 0, 0, 0, 0, 0, 0, 0, 0,18, 0, 0, 0,16, 0,22,20 },
   838 	{0,15,17,0,19,5,6,7,21,9,10,11, 0,13,14},
   843 	{ 0,15,17, 0,19, 5, 6, 7,21, 9,10,11, 0,13,14, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0,15, 0,21,19 }
   839 };
   844 };
   840 
   845 
   841 extern const byte _road_sloped_sprites[14];
   846 extern const byte _road_sloped_sprites[14];
   842 
   847 
   843 static void DrawBridgePillars(PalSpriteID image, const TileInfo *ti, int x, int y, int z)
   848 static void DrawBridgePillars(PalSpriteID image, const TileInfo *ti, int x, int y, int z)
   888 
   893 
   889 	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) return tileh;
   894 	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) return tileh;
   890 
   895 
   891 	// inclined sloped building
   896 	// inclined sloped building
   892 	switch (tileh) {
   897 	switch (tileh) {
   893 		case SLOPE_W: i = 0; break;
   898 		case SLOPE_W:
   894 		case SLOPE_S: i = 2; break;
   899 		case SLOPE_STEEP_W: i = 0; break;
   895 		case SLOPE_E: i = 4; break;
   900 		case SLOPE_S:
   896 		case SLOPE_N: i = 6; break;
   901 		case SLOPE_STEEP_S: i = 2; break;
   897 		default:      return 0;
   902 		case SLOPE_E:
       
   903 		case SLOPE_STEEP_E: i = 4; break;
       
   904 		case SLOPE_N:
       
   905 		case SLOPE_STEEP_N: i = 6; break;
       
   906 		default: return 0;
   898 	}
   907 	}
   899 	if (axis != AXIS_X) ++i;
   908 	if (axis != AXIS_X) ++i;
   900 	return i + 15;
   909 	return i + 15;
   901 }
   910 }
   902 
   911 
  1101 
  1110 
  1102 			// On the bridge ramp?
  1111 			// On the bridge ramp?
  1103 			if (5 <= pos && pos <= 10) {
  1112 			if (5 <= pos && pos <= 10) {
  1104 				uint delta;
  1113 				uint delta;
  1105 
  1114 
       
  1115 				if (IsSteepSlope(tileh)) return z + TILE_HEIGHT * 2;
  1106 				if (HASBIT(BRIDGE_HORZ_RAMP, tileh)) return z + TILE_HEIGHT;
  1116 				if (HASBIT(BRIDGE_HORZ_RAMP, tileh)) return z + TILE_HEIGHT;
  1107 
  1117 
  1108 				if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) z += TILE_HEIGHT;
  1118 				if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) z += TILE_HEIGHT;
  1109 				switch (dir) {
  1119 				switch (dir) {
  1110 					default:
  1120 					default:
  1116 				return z + 1 + delta;
  1126 				return z + 1 + delta;
  1117 			} else {
  1127 			} else {
  1118 				uint f = GetBridgeFoundation(tileh, DiagDirToAxis(dir));
  1128 				uint f = GetBridgeFoundation(tileh, DiagDirToAxis(dir));
  1119 
  1129 
  1120 				if (f != 0) {
  1130 				if (f != 0) {
  1121 					if (f < 15) return z + TILE_HEIGHT;
  1131 					if (IsSteepSlope(tileh)) {
       
  1132 						z += TILE_HEIGHT;
       
  1133 					} else if (f < 15) {
       
  1134 						return z + TILE_HEIGHT;
       
  1135 					}
  1122 					tileh = _inclined_tileh[f - 15];
  1136 					tileh = _inclined_tileh[f - 15];
  1123 				}
  1137 				}
  1124 			}
  1138 			}
  1125 		} else {
  1139 		} else {
       
  1140 			uint ground_z;
       
  1141 
  1126 			// HACK on the bridge?
  1142 			// HACK on the bridge?
  1127 			if (_get_z_hint >= z + TILE_HEIGHT + (tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT)) return _get_z_hint;
  1143 			ground_z = z + TILE_HEIGHT;
       
  1144 			if (tileh != SLOPE_FLAT) ground_z += TILE_HEIGHT;
       
  1145 			if (IsSteepSlope(tileh)) ground_z += TILE_HEIGHT;
       
  1146 			if (_get_z_hint >= ground_z) return _get_z_hint;
  1128 
  1147 
  1129 			if (IsTransportUnderBridge(tile)) {
  1148 			if (IsTransportUnderBridge(tile)) {
  1130 				uint f = _bridge_foundations[GetBridgeAxis(tile)][tileh];
  1149 				uint f = _bridge_foundations[GetBridgeAxis(tile)][tileh];
  1131 
  1150 
  1132 				if (f != 0) {
  1151 				if (f != 0) {
  1133 					if (f < 15) return z + TILE_HEIGHT;
  1152 					if (IsSteepSlope(tileh)) {
       
  1153 						z += TILE_HEIGHT;
       
  1154 					} else if (f < 15) {
       
  1155 						return z + TILE_HEIGHT;
       
  1156 					}
  1134 					tileh = _inclined_tileh[f - 15];
  1157 					tileh = _inclined_tileh[f - 15];
  1135 				}
  1158 				}
  1136 			}
  1159 			}
  1137 		}
  1160 		}
  1138 	}
  1161 	}