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

Function updateSurface

src/OpenLoco/src/Map/SurfaceElement.cpp:274–322  ·  view source on GitHub ↗

0x004691FA

Source from the content-addressed store, hash-verified

272
273 // 0x004691FA
274 bool updateSurface(SurfaceElement& elSurface, const World::Pos2 loc)
275 {
276 bool elSurfaceValid = true;
277 if (elSurface.isIndustrial())
278 {
279 elSurfaceValid = !updateIndustrialSurface(elSurface, loc);
280 }
281 else
282 {
283 updateNonIndustrialSurface(elSurface, loc);
284 }
285
286 auto* surf = elSurfaceValid ? &elSurface : TileManager::get(loc).surface();
287
288 const MicroZ snow = Scenario::getCurrentSnowLine() / kMicroToSmallZStep;
289 uint8_t targetCoverage = std::clamp(((surf->baseZ() / kMicroToSmallZStep) + 1) - snow, 0, 5);
290 if (surf->snowCoverage() != targetCoverage)
291 {
292 if (surf->snowCoverage() > targetCoverage)
293 {
294 surf->setSnowCoverage(surf->snowCoverage() - 1);
295 }
296 else
297 {
298 surf->setSnowCoverage(surf->snowCoverage() + 1);
299 }
300 Ui::ViewportManager::invalidate(loc, surf->baseHeight(), surf->baseHeight());
301 }
302
303 if (!surf->water())
304 {
305 return elSurfaceValid;
306 }
307 if (surf->hasType6Flag())
308 {
309 surf->setVariation(surf->variation() + 1);
310 if (surf->variation() >= 64)
311 {
312 surf->setVariation(0);
313 surf->setType6Flag(false);
314 }
315 }
316 if (surf->isFlag6())
317 {
318 return elSurfaceValid;
319 }
320 WaveManager::createWave(*surf, loc);
321 return elSurfaceValid;
322 }
323}

Callers 1

updateFunction · 0.85

Calls 15

updateIndustrialSurfaceFunction · 0.85
getCurrentSnowLineFunction · 0.85
createWaveFunction · 0.85
isIndustrialMethod · 0.80
surfaceMethod · 0.80
baseZMethod · 0.80
snowCoverageMethod · 0.80
setSnowCoverageMethod · 0.80
baseHeightMethod · 0.80
waterMethod · 0.80
hasType6FlagMethod · 0.80

Tested by

no test coverage detected