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

Function placeTreeCluster

src/OpenLoco/src/Map/Tree.cpp:139–161  ·  view source on GitHub ↗

0x004BDC67 (when treeType is nullopt) & 0x004BDDC6 (when treeType is set)

Source from the content-addressed store, hash-verified

137
138 // 0x004BDC67 (when treeType is nullopt) & 0x004BDDC6 (when treeType is set)
139 bool placeTreeCluster(const World::TilePos2& centreLoc, const uint16_t range, const uint16_t density, const std::optional<uint8_t> treeType)
140 {
141 const auto numPlacements = (range * range * density) / 8192;
142 uint16_t numErrors = 0;
143 for (auto i = 0; i < numPlacements; ++i)
144 {
145 // Choose a random offset in a circle
146 auto& rng = gPrng1();
147 auto randomMagnitude = rng.randNext(std::numeric_limits<uint16_t>::max()) * range / 65536;
148 auto randomDirection = rng.randNext(Math::Trigonometry::kDirectionPrecisionHigh - 1);
149 World::Pos2 randomOffset(
150 Math::Trigonometry::integerSinePrecisionHigh(randomDirection, randomMagnitude),
151 Math::Trigonometry::integerCosinePrecisionHigh(randomDirection, randomMagnitude));
152
153 if (!placeRandomTree(randomOffset + World::toWorldSpace(centreLoc), treeType))
154 {
155 numErrors++;
156 }
157 }
158
159 // Have we placed any trees?
160 return (numErrors < numPlacements);
161 }
162}

Callers 2

onToolDownFunction · 0.85
generateTreesFunction · 0.85

Calls 5

integerSinePrecisionHighFunction · 0.85
placeRandomTreeFunction · 0.85
toWorldSpaceFunction · 0.85
randNextMethod · 0.45

Tested by

no test coverage detected