| 205 | } |
| 206 | |
| 207 | Maybe<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 | |
| 233 | Maybe<CelestialParameters> CelestialMasterDatabase::parameters(CelestialCoordinate const& coordinate) { |
| 234 | RecursiveMutexLocker locker(m_mutex); |