204 TileIndex tile = TileVirtXY(x, y); |
204 TileIndex tile = TileVirtXY(x, y); |
205 |
205 |
206 return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y); |
206 return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y); |
207 } |
207 } |
208 |
208 |
|
209 /** |
|
210 * Determine the Z height of the corners of a specific tile edge |
|
211 * |
|
212 * @pre z1 and z2 must be initialized (typ. with TileZ). The corner heights just get added. |
|
213 * |
|
214 * @param tileh The slope of the tile. |
|
215 * @param edge The edge of interest. |
|
216 * @param z1 Gets incremented by the height of the first corner of the edge. (near corner wrt. the camera) |
|
217 * @param z2 Gets incremented by the height of the second corner of the edge. (far corner wrt. the camera) |
|
218 */ |
|
219 void GetSlopeZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2) |
|
220 { |
|
221 static const Slope corners[4][4] = { |
|
222 /* corner | steep slope |
|
223 * z1 z2 | z1 z2 */ |
|
224 {SLOPE_E, SLOPE_N, SLOPE_STEEP_E, SLOPE_STEEP_N}, // DIAGDIR_NE, z1 = E, z2 = N |
|
225 {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 |
|
227 {SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N |
|
228 }; |
|
229 |
|
230 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 |
|
232 if (tileh == 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 |
|
234 } |
209 |
235 |
210 static Slope GetFoundationSlope(TileIndex tile, uint* z) |
236 static Slope GetFoundationSlope(TileIndex tile, uint* z) |
211 { |
237 { |
212 Slope tileh = GetTileSlope(tile, z); |
238 Slope tileh = GetTileSlope(tile, z); |
213 Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh); |
239 Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh); |
217 |
243 |
218 |
244 |
219 static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here) |
245 static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here) |
220 { |
246 { |
221 uint z; |
247 uint z; |
|
248 |
|
249 int z_W_here = z_here; |
|
250 int z_N_here = z_here; |
|
251 GetSlopeZOnEdge(slope_here, DIAGDIR_NW, &z_W_here, &z_N_here); |
|
252 |
222 Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z); |
253 Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z); |
223 |
254 int z_W = z; |
224 return |
255 int z_N = z; |
225 ( |
256 GetSlopeZOnEdge(slope, DIAGDIR_SE, &z_W, &z_N); |
226 z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_N ? TILE_HEIGHT : 0) > |
257 |
227 z + (slope & SLOPE_E ? TILE_HEIGHT : 0) + (slope == SLOPE_STEEP_E ? TILE_HEIGHT : 0) |
258 return (z_N_here > z_N) || (z_W_here > z_W); |
228 ) || ( |
|
229 z_here + (slope_here & SLOPE_W ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_W ? TILE_HEIGHT : 0) > |
|
230 z + (slope & SLOPE_S ? TILE_HEIGHT : 0) + (slope == SLOPE_STEEP_S ? TILE_HEIGHT : 0) |
|
231 ); |
|
232 } |
259 } |
233 |
260 |
234 |
261 |
235 static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here) |
262 static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here) |
236 { |
263 { |
237 uint z; |
264 uint z; |
|
265 |
|
266 int z_E_here = z_here; |
|
267 int z_N_here = z_here; |
|
268 GetSlopeZOnEdge(slope_here, DIAGDIR_NE, &z_E_here, &z_N_here); |
|
269 |
238 Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z); |
270 Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z); |
239 |
271 int z_E = z; |
240 return |
272 int z_N = z; |
241 ( |
273 GetSlopeZOnEdge(slope, DIAGDIR_SW, &z_E, &z_N); |
242 z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_N ? TILE_HEIGHT : 0) > |
274 |
243 z + (slope & SLOPE_W ? TILE_HEIGHT : 0) + (slope == SLOPE_STEEP_W ? TILE_HEIGHT : 0) |
275 return (z_N_here > z_N) || (z_E_here > z_E); |
244 ) || ( |
|
245 z_here + (slope_here & SLOPE_E ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_E ? TILE_HEIGHT : 0) > |
|
246 z + (slope & SLOPE_S ? TILE_HEIGHT : 0) + (slope == SLOPE_STEEP_S ? TILE_HEIGHT : 0) |
|
247 ); |
|
248 } |
276 } |
249 |
277 |
250 |
278 |
251 void DrawFoundation(TileInfo *ti, Foundation f) |
279 void DrawFoundation(TileInfo *ti, Foundation f) |
252 { |
280 { |