MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / scanAnchor

Method scanAnchor

source/game/StarDungeonGenerator.cpp:851–902  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

849 }
850
851 void Part::scanAnchor() {
852 int cx, cy, cc;
853 cx = cy = cc = 0;
854 int lowestAir = m_size[1];
855 int highestGound = -1;
856 int highestLiquid = -1;
857 try {
858 m_reader->forEachTile([&](Vec2I pos, Tile const& tile) -> bool {
859 int x = pos.x(), y = pos.y();
860 if (tile.collidesWithPlaces()) {
861 cx += x;
862 cy += y;
863 cc++;
864 }
865 if (tile.requiresOpen()) {
866 if ((int)y < lowestAir)
867 lowestAir = y;
868 }
869 if (tile.requiresSolid()) {
870 if ((int)y > highestGound)
871 highestGound = y;
872 }
873 if (tile.requiresLiquid()) {
874 if ((int)y > highestLiquid)
875 highestLiquid = y;
876 }
877 return false;
878 });
879 } catch (std::exception& e) {
880 throw DungeonException(strf("Exception {} in part {}", outputException(e, true), m_name));
881 }
882
883 highestGound = max(highestGound, highestLiquid);
884 if (highestGound == -1)
885 highestGound = lowestAir - 1;
886
887 if (lowestAir == (int)m_size[1])
888 lowestAir = highestGound + 1;
889
890 if (cc == 0) {
891 cx = m_size[0] / 2;
892 cy = m_size[1] / 2;
893 } else {
894 cx /= cc;
895 cy /= cc;
896 }
897
898 if (highestGound != -1)
899 cy = highestGound + 1;
900
901 m_anchorPoint = {cx, cy};
902 }
903
904 bool WorldGenMustContainSolidRule::checkTileCanPlace(Vec2I position, DungeonGeneratorWriter* writer) const {
905 return writer->checkSolid(position, layer);

Callers

nothing calls this directly

Calls 9

strfFunction · 0.85
xMethod · 0.80
yMethod · 0.80
collidesWithPlacesMethod · 0.80
outputExceptionFunction · 0.50
forEachTileMethod · 0.45
requiresOpenMethod · 0.45
requiresSolidMethod · 0.45
requiresLiquidMethod · 0.45

Tested by

no test coverage detected