MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / generateLand

Function generateLand

src/OpenLoco/src/Map/MapGenerator/MapGenerator.cpp:148–211  ·  view source on GitHub ↗

0x004625D0

Source from the content-addressed store, hash-verified

146
147 // 0x004625D0
148 static void generateLand(HeightMap& heightMap)
149 {
150 for (auto& pos : World::getDrawableTileRange())
151 {
152 const MicroZ q00 = heightMap[pos + TilePos2{ -1, -1 }];
153 const MicroZ q01 = heightMap[pos + TilePos2{ 0, -1 }];
154 const MicroZ q10 = heightMap[pos + TilePos2{ -1, 0 }];
155 const MicroZ q11 = heightMap[pos + TilePos2{ 0, 0 }];
156
157 const auto tile = TileManager::get(pos);
158 auto* surfaceElement = tile.surface();
159 if (surfaceElement == nullptr)
160 {
161 continue;
162 }
163
164 const MicroZ baseHeight = std::min({ q00, q01, q10, q11 });
165 surfaceElement->setBaseZ(baseHeight * kMicroToSmallZStep);
166
167 uint8_t currentSlope = SurfaceSlope::flat;
168
169 // First, figure out basic corner style
170 if (q00 > baseHeight)
171 {
172 currentSlope |= SurfaceSlope::CornerUp::south;
173 }
174 if (q01 > baseHeight)
175 {
176 currentSlope |= SurfaceSlope::CornerUp::east;
177 }
178 if (q10 > baseHeight)
179 {
180 currentSlope |= SurfaceSlope::CornerUp::west;
181 }
182 if (q11 > baseHeight)
183 {
184 currentSlope |= SurfaceSlope::CornerUp::north;
185 }
186
187 // Now, deduce if we should go for double height
188 // clang-format off
189 if ((currentSlope == SurfaceSlope::CornerDown::north && q00 - baseHeight >= 2) ||
190 (currentSlope == SurfaceSlope::CornerDown::west && q01 - baseHeight >= 2) ||
191 (currentSlope == SurfaceSlope::CornerDown::east && q10 - baseHeight >= 2) ||
192 (currentSlope == SurfaceSlope::CornerDown::south && q11 - baseHeight >= 2))
193 {
194 currentSlope |= SurfaceSlope::doubleHeight;
195 }
196 // clang-format on
197
198 surfaceElement->setSlope(currentSlope);
199
200 auto clearZ = surfaceElement->baseZ();
201 if (surfaceElement->slopeCorners())
202 {
203 clearZ += kSmallZStep;
204 }
205 if (surfaceElement->isSlopeDoubleHeight())

Callers 1

generateFunction · 0.85

Calls 9

getDrawableTileRangeFunction · 0.85
surfaceMethod · 0.80
setBaseZMethod · 0.80
setSlopeMethod · 0.80
baseZMethod · 0.80
slopeCornersMethod · 0.80
isSlopeDoubleHeightMethod · 0.80
setClearZMethod · 0.80
getFunction · 0.50

Tested by

no test coverage detected