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

Method findRandomWorld

source/game/StarCelestialDatabase.cpp:207–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207Maybe<CelestialCoordinate> CelestialMasterDatabase::findRandomWorld(unsigned tries, unsigned trySpatialRange,
208 function<bool(CelestialCoordinate)> filter, Maybe<uint64_t> seed) {
209 RandomSource randSource;
210 if (seed)
211 randSource.init(*seed);
212 for (unsigned i = 0; i < tries; ++i) {
213 RectI range = xyRange();
214 Vec2I randomLocation = Vec2I(randSource.randInt(range.xMin(), range.xMax()), randSource.randInt(range.yMin(), range.yMax()));
215 for (auto& system : scanSystems(RectI::withCenter(randomLocation, Vec2I::filled(trySpatialRange)))) {
216 if (!hasChildren(system).value(false))
217 continue;
218
219 auto world = randSource.randFrom(children(system));
220 // This sucks, 50% of the time will try and return satellite, not really
221 // balanced probability wise
222 if (hasChildren(world).value(false) && randSource.randb())
223 world = randSource.randFrom(children(world));
224
225 if (!filter || filter(world))
226 return world;
227 }
228 }
229
230 return {};
231}
232
233Maybe<CelestialParameters> CelestialMasterDatabase::parameters(CelestialCoordinate const& coordinate) {
234 RecursiveMutexLocker locker(m_mutex);

Callers 5

nextStarterWorldMethod · 0.80
TitleScreenMethod · 0.80
mainFunction · 0.80
mainFunction · 0.80
TESTFunction · 0.80

Calls 9

filterFunction · 0.85
randIntMethod · 0.80
xMinMethod · 0.80
xMaxMethod · 0.80
yMinMethod · 0.80
yMaxMethod · 0.80
randbMethod · 0.80
initMethod · 0.45
valueMethod · 0.45

Tested by 1

TESTFunction · 0.64