src/landscape.cpp
changeset 7764 e594296e90f6
parent 7728 68e794385dc9
child 7767 9866e9700e62
equal deleted inserted replaced
7763:342e5357b592 7764:e594296e90f6
   102 }
   102 }
   103 
   103 
   104 
   104 
   105 uint GetPartialZ(int x, int y, Slope corners)
   105 uint GetPartialZ(int x, int y, Slope corners)
   106 {
   106 {
       
   107 	if (IsHalftileSlope(corners)) {
       
   108 		switch (GetHalftileSlopeCorner(corners)) {
       
   109 			case CORNER_W:
       
   110 				if (x - y >= 0) return GetSlopeMaxZ(corners);
       
   111 				break;
       
   112 
       
   113 			case CORNER_S:
       
   114 				if (x - (y ^ 0xF) >= 0) return GetSlopeMaxZ(corners);
       
   115 				break;
       
   116 
       
   117 			case CORNER_E:
       
   118 				if (y - x >= 0) return GetSlopeMaxZ(corners);
       
   119 				break;
       
   120 
       
   121 			case CORNER_N:
       
   122 				if ((y ^ 0xF) - x >= 0) return GetSlopeMaxZ(corners);
       
   123 				break;
       
   124 
       
   125 			default: NOT_REACHED();
       
   126 		}
       
   127 	}
       
   128 
   107 	int z = 0;
   129 	int z = 0;
   108 
   130 
   109 	switch (corners) {
   131 	switch (corners & ~SLOPE_HALFTILE_MASK) {
   110 	case SLOPE_W:
   132 	case SLOPE_W:
   111 		if (x - y >= 0)
   133 		if (x - y >= 0)
   112 			z = (x - y) >> 1;
   134 			z = (x - y) >> 1;
   113 		break;
   135 		break;
   114 
   136 
   206 	return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y);
   228 	return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y);
   207 }
   229 }
   208 
   230 
   209 /**
   231 /**
   210  * Determine the Z height of the corners of a specific tile edge
   232  * Determine the Z height of the corners of a specific tile edge
       
   233  *
       
   234  * @note If a tile has a non-continuous halftile foundation, a corner can have different heights wrt. it's edges.
   211  *
   235  *
   212  * @pre z1 and z2 must be initialized (typ. with TileZ). The corner heights just get added.
   236  * @pre z1 and z2 must be initialized (typ. with TileZ). The corner heights just get added.
   213  *
   237  *
   214  * @param tileh The slope of the tile.
   238  * @param tileh The slope of the tile.
   215  * @param edge The edge of interest.
   239  * @param edge The edge of interest.
   225 		{SLOPE_S, SLOPE_E, SLOPE_STEEP_S, SLOPE_STEEP_E}, // DIAGDIR_SE, z1 = S, z2 = E
   249 		{SLOPE_S, SLOPE_E, SLOPE_STEEP_S, SLOPE_STEEP_E}, // DIAGDIR_SE, z1 = S, z2 = E
   226 		{SLOPE_S, SLOPE_W, SLOPE_STEEP_S, SLOPE_STEEP_W}, // DIAGDIR_SW, z1 = S, z2 = W
   250 		{SLOPE_S, SLOPE_W, SLOPE_STEEP_S, SLOPE_STEEP_W}, // DIAGDIR_SW, z1 = S, z2 = W
   227 		{SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
   251 		{SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
   228 	};
   252 	};
   229 
   253 
       
   254 	int halftile_test = (IsHalftileSlope(tileh) ? SlopeWithOneCornerRaised(GetHalftileSlopeCorner(tileh)) : 0);
       
   255 	if (halftile_test == corners[edge][0]) *z2 += TILE_HEIGHT; // The slope is non-continuous in z2. z2 is on the upper side.
       
   256 	if (halftile_test == corners[edge][1]) *z1 += TILE_HEIGHT; // The slope is non-continuous in z1. z1 is on the upper side.
       
   257 
   230 	if ((tileh & corners[edge][0]) != 0) *z1 += TILE_HEIGHT; // z1 is raised
   258 	if ((tileh & corners[edge][0]) != 0) *z1 += TILE_HEIGHT; // z1 is raised
   231 	if ((tileh & corners[edge][1]) != 0) *z2 += TILE_HEIGHT; // z2 is raised
   259 	if ((tileh & corners[edge][1]) != 0) *z2 += TILE_HEIGHT; // z2 is raised
   232 	if (tileh == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
   260 	if ((tileh & ~SLOPE_HALFTILE_MASK) == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
   233 	if (tileh == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
   261 	if ((tileh & ~SLOPE_HALFTILE_MASK) == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
   234 }
   262 }
   235 
   263 
   236 static Slope GetFoundationSlope(TileIndex tile, uint* z)
   264 static Slope GetFoundationSlope(TileIndex tile, uint* z)
   237 {
   265 {
   238 	Slope tileh = GetTileSlope(tile, z);
   266 	Slope tileh = GetTileSlope(tile, z);