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

Function getHeight

src/OpenLoco/src/Map/TileManager.cpp:509–576  ·  view source on GitHub ↗

* Return the absolute height of an element, given its (x, y) coordinates * remember to & with 0xFFFF if you don't want water affecting results * * @param x @ * @param y @ * @return height @ * * 0x00467297 rct2: 0x00662783 (numbers different) */

Source from the content-addressed store, hash-verified

507 * 0x00467297 rct2: 0x00662783 (numbers different)
508 */
509 TileHeight getHeight(const Pos2& pos)
510 {
511 TileHeight height{ 16, 0 };
512 // Off the map
513 if ((unsigned)pos.x >= (World::kMapWidth - 1) || (unsigned)pos.y >= (World::kMapHeight - 1))
514 {
515 return height;
516 }
517
518 auto tile = TileManager::get(pos);
519 // Get the surface element for the tile
520 auto surfaceEl = tile.surface();
521
522 if (surfaceEl == nullptr)
523 {
524 return height;
525 }
526
527 height.waterHeight = surfaceEl->waterHeight();
528 height.landHeight = surfaceEl->baseHeight();
529
530 const auto slope = surfaceEl->slopeCorners();
531
532 // Sub-tile coords
533 const auto xl = pos.x & 0x1f;
534 const auto yl = pos.y & 0x1f;
535
536 // Slope logic:
537 // Each of the four bits in slope represents that corner being raised
538 // slope == 15 (all four bits) is not used and slope == 0 is flat
539 // If the extra_height bit is set, then the slope goes up two z-levels (this happens with one corner down with opposite corner up)
540
541 // We arbitrarily take the SW corner to be closest to the viewer
542
543 switch (slope)
544 {
545 case SurfaceSlope::flat:
546 // Flat surface requires no further calculations.
547 break;
548
549 case SurfaceSlope::CornerUp::north:
550 case SurfaceSlope::CornerUp::east:
551 case SurfaceSlope::CornerUp::south:
552 case SurfaceSlope::CornerUp::west:
553 height.landHeight += getOneCornerUpLandHeight(xl, yl, slope);
554 break;
555
556 case SurfaceSlope::SideUp::northeast:
557 case SurfaceSlope::SideUp::southeast:
558 case SurfaceSlope::SideUp::northwest:
559 case SurfaceSlope::SideUp::southwest:
560 height.landHeight += getOneSideUpLandHeight(xl, yl, slope);
561 break;
562
563 case SurfaceSlope::CornerDown::north:
564 case SurfaceSlope::CornerDown::east:
565 case SurfaceSlope::CornerDown::south:
566 case SurfaceSlope::CornerDown::west:

Callers 15

handleStepFunction · 0.85
getCentreMapPositionMethod · 0.85
generateTownNameFunction · 0.85
updateLabelMethod · 0.85
spendMoneyEffectFunction · 0.85
getSurfaceLocFromUiFunction · 0.85
viewportCentreOnTileMethod · 0.85
viewportRotateMethod · 0.85
createGiantViewportFunction · 0.85
moveMainViewToMapViewFunction · 0.85

Calls 10

getOneCornerUpLandHeightFunction · 0.85
getOneSideUpLandHeightFunction · 0.85
getValleyLandHeightFunction · 0.85
surfaceMethod · 0.80
waterHeightMethod · 0.80
baseHeightMethod · 0.80
slopeCornersMethod · 0.80
isSlopeDoubleHeightMethod · 0.80
getFunction · 0.70

Tested by

no test coverage detected