MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetTileSlopeGivenHeight

Function GetTileSlopeGivenHeight

src/tile_map.cpp:23–48  ·  view source on GitHub ↗

* Get a tile's slope given the height of its four corners. * @param hnorth The height at the northern corner in the same unit as TileHeight. * @param hwest The height at the western corner in the same unit as TileHeight. * @param heast The height at the eastern corner in the same unit as TileHeight. * @param hsouth The height at the southern corner in the same unit as TileHeight. * @return

Source from the content-addressed store, hash-verified

21 * @return The slope and the lowest height of the four corners.
22 */
23static std::tuple<Slope, int> GetTileSlopeGivenHeight(int hnorth, int hwest, int heast, int hsouth)
24{
25 /* Due to the fact that tiles must connect with each other without leaving gaps, the
26 * biggest difference in height between any corner and 'min' is between 0, 1, or 2.
27 *
28 * Also, there is at most 1 corner with height difference of 2.
29 */
30 int hminnw = std::min(hnorth, hwest);
31 int hmines = std::min(heast, hsouth);
32 int hmin = std::min(hminnw, hmines);
33
34 int hmaxnw = std::max(hnorth, hwest);
35 int hmaxes = std::max(heast, hsouth);
36 int hmax = std::max(hmaxnw, hmaxes);
37
38 Slope r = SLOPE_FLAT;
39
40 if (hnorth != hmin) r |= SLOPE_N;
41 if (hwest != hmin) r |= SLOPE_W;
42 if (heast != hmin) r |= SLOPE_E;
43 if (hsouth != hmin) r |= SLOPE_S;
44
45 if (hmax - hmin == 2) r |= SLOPE_STEEP;
46
47 return {r, hmin};
48}
49
50/**
51 * Return the slope of a given tile inside the map.

Callers 2

GetTileSlopeZFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected