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

Function adjustWaterHeight

src/OpenLoco/src/Map/TileManager.cpp:1501–1582  ·  view source on GitHub ↗

0x004C4C28

Source from the content-addressed store, hash-verified

1499
1500 // 0x004C4C28
1501 uint32_t adjustWaterHeight(World::Pos2 pos, SmallZ targetHeight, World::TileClearance::RemovedBuildings& removedBuildings, uint8_t flags)
1502 {
1503 GameCommands::setExpenditureType(ExpenditureType::Construction);
1504 GameCommands::setPosition(World::Pos3(pos.x + World::kTileSize / 2, pos.y + World::kTileSize / 2, targetHeight * kMicroToSmallZStep));
1505
1506 if (targetHeight < 4)
1507 {
1508 GameCommands::setErrorText(StringIds::error_too_low);
1509 return GameCommands::kFailure;
1510 }
1511
1512 if (targetHeight >= 116)
1513 {
1514 GameCommands::setErrorText(StringIds::error_too_high);
1515 return GameCommands::kFailure;
1516 }
1517
1518 currency32_t totalCost = 0;
1519
1520 if (flags & GameCommands::Flags::apply)
1521 {
1522 removeSurfaceIndustry(pos);
1523
1524 if (!SceneManager::isEditorMode())
1525 {
1526 setTerrainStyleAsCleared(pos);
1527 }
1528
1529 auto clearHeight = getHeight(pos).landHeight;
1530 removeAllWallsOnTileAbove(toTileSpace(pos), clearHeight / kSmallZStep);
1531 }
1532
1533 auto tile = get(pos);
1534 auto* surface = tile.surface();
1535
1536 auto referenceZ = surface->baseZ();
1537 auto water = surface->water();
1538 if (water > 0)
1539 {
1540 referenceZ = water * kMicroToSmallZStep;
1541 }
1542
1543 const auto baseTargetZ = std::min(targetHeight, referenceZ);
1544 const auto clearTargetZ = std::max(targetHeight, referenceZ);
1545
1546 // Bind our local vars to the tile clear function
1547 auto clearFunc = [pos, &removedBuildings, flags, &totalCost](TileElement& el) {
1548 return TileClearance::clearWithDefaultCollision(el, pos, removedBuildings, flags, totalCost);
1549 };
1550
1551 QuarterTile qt(0xF, 0);
1552 if (!TileClearance::applyClearAtAllHeights(pos, baseTargetZ, clearTargetZ, qt, clearFunc))
1553 {
1554 return GameCommands::kFailure;
1555 }
1556
1557 if (surface->hasType6Flag())
1558 {

Callers 2

lowerWaterFunction · 0.85
raiseWaterFunction · 0.85

Calls 15

setExpenditureTypeFunction · 0.85
setPositionFunction · 0.85
setErrorTextFunction · 0.85
removeSurfaceIndustryFunction · 0.85
isEditorModeFunction · 0.85
setTerrainStyleAsClearedFunction · 0.85
getHeightFunction · 0.85
toTileSpaceFunction · 0.85
applyClearAtAllHeightsFunction · 0.85
getInflationAdjustedCostFunction · 0.85

Tested by

no test coverage detected