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

Function adjustSurfaceHeight

src/OpenLoco/src/Map/TileManager.cpp:1324–1498  ·  view source on GitHub ↗

0x00468651

Source from the content-addressed store, hash-verified

1322
1323 // 0x00468651
1324 uint32_t adjustSurfaceHeight(World::Pos2 pos, SmallZ targetBaseZ, uint8_t slopeFlags, World::TileClearance::RemovedBuildings& removedBuildings, uint8_t flags)
1325 {
1326 if (!validCoords(pos))
1327 {
1328 GameCommands::setErrorText(StringIds::off_edge_of_map);
1329 return GameCommands::kFailure;
1330 }
1331
1332 if (targetBaseZ < 4)
1333 {
1334 GameCommands::setErrorText(StringIds::error_too_low);
1335 return GameCommands::kFailure;
1336 }
1337 if (targetBaseZ > 160
1338 || (targetBaseZ == 160 && (slopeFlags & 0x1F) != 0)
1339 || (targetBaseZ == 156 && (slopeFlags & 0x10) != 0))
1340 {
1341 GameCommands::setErrorText(StringIds::error_too_high);
1342 return GameCommands::kFailure;
1343 }
1344
1345 currency32_t totalCost = 0;
1346
1347 if (flags & GameCommands::Flags::apply)
1348 {
1349 removeSurfaceIndustry(pos);
1350
1351 if (!SceneManager::isEditorMode())
1352 {
1353 setTerrainStyleAsCleared(pos);
1354 }
1355
1356 auto clearHeight = getHeight(pos).landHeight;
1357 removeAllWallsOnTileAbove(toTileSpace(pos), clearHeight / 4);
1358 }
1359
1360 // Compute cost of landscape operation
1361 auto tile = get(pos);
1362 auto* surface = tile.surface();
1363 auto landObj = ObjectManager::get<LandObject>(surface->terrain());
1364 totalCost += Economy::getInflationAdjustedCost(landObj->costFactor, landObj->costIndex, 10);
1365
1366 auto targetClearZ = targetBaseZ;
1367 if (slopeFlags & 0x1F)
1368 {
1369 targetClearZ += kSmallZStep;
1370 }
1371 if (slopeFlags & SurfaceSlope::doubleHeight)
1372 {
1373 targetClearZ += kSmallZStep;
1374 }
1375
1376 // If surface is in use as a water(route), and has water, ensure we don't remove it
1377 if (surface->hasType6Flag() && surface->water() > 0)
1378 {
1379 auto waterHeight = (surface->water() - 1) * kMicroToSmallZStep;
1380
1381 if (waterHeight < targetClearZ)

Callers 3

adjustSurfaceSlopeFunction · 0.85
raiseLandFunction · 0.85
lowerLandFunction · 0.85

Calls 15

validCoordsFunction · 0.85
setErrorTextFunction · 0.85
removeSurfaceIndustryFunction · 0.85
isEditorModeFunction · 0.85
setTerrainStyleAsClearedFunction · 0.85
getHeightFunction · 0.85
toTileSpaceFunction · 0.85
getInflationAdjustedCostFunction · 0.85
applyClearAtAllHeightsFunction · 0.85
commonFunction · 0.85

Tested by

no test coverage detected