| 402 | } |
| 403 | |
| 404 | SkyParameters SystemWorldServer::locationSkyParameters(SystemLocation const& location) const { |
| 405 | SkyParameters skyParameters = systemConfig().emptySkyParameters; |
| 406 | |
| 407 | if (auto coordinate = location.maybe<CelestialCoordinate>()) { |
| 408 | return SkyParameters(*coordinate, m_celestialDatabase); |
| 409 | } else if (auto position = location.maybe<Vec2F>()) { |
| 410 | for (auto planet : planets()) { |
| 411 | if (abs(position->magnitude() - planetPosition(planet).magnitude()) > systemConfig().asteroidBeamDistance) |
| 412 | continue; |
| 413 | |
| 414 | if (auto parameters = m_celestialDatabase->parameters(planet)) { |
| 415 | if (auto asteroidsParameters = as<AsteroidsWorldParameters>(parameters->visitableParameters())) { |
| 416 | return SkyParameters(planet, m_celestialDatabase); |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | } else if (!location.empty()) { |
| 421 | CelestialCoordinate orbitTarget; |
| 422 | if (auto objectUuid = location.maybe<Uuid>()) { |
| 423 | auto object = getObject(*objectUuid); |
| 424 | skyParameters = object->skyParameters(); |
| 425 | if (auto target = object->orbitTarget()) |
| 426 | orbitTarget = *target; |
| 427 | } else if (auto orbit = location.maybe<CelestialOrbit>()) { |
| 428 | orbitTarget = orbit->target; |
| 429 | } |
| 430 | |
| 431 | if (orbitTarget.isPlanetaryBody()) { |
| 432 | auto parameters = m_celestialDatabase->parameters(orbitTarget); |
| 433 | |
| 434 | if (auto visitableParameters = parameters->visitableParameters()) { |
| 435 | if (is<TerrestrialWorldParameters>(visitableParameters)) { |
| 436 | uint64_t seed = staticRandomU64(toString(m_location)); |
| 437 | List<CelestialParameters> worlds; |
| 438 | if (auto planet = m_celestialDatabase->parameters(orbitTarget)) |
| 439 | worlds.append(*planet); |
| 440 | for (auto coordinate : m_celestialDatabase->children(orbitTarget)) { |
| 441 | if (auto satellite = m_celestialDatabase->parameters(coordinate)) |
| 442 | worlds.append(*satellite); |
| 443 | } |
| 444 | |
| 445 | for (uint64_t i = 0; i < worlds.size(); i++) { |
| 446 | auto world = worlds.get(i); |
| 447 | Vec2F pos = { |
| 448 | staticRandomFloat(seed, world.seed(), "x"), |
| 449 | staticRandomFloat(seed, world.seed(), "y") |
| 450 | }; |
| 451 | CelestialParameters parent = i > 0 ? worlds[0] : CelestialParameters(); |
| 452 | skyParameters.nearbyMoons.append({CelestialGraphics::drawWorld(world, parent), pos}); |
| 453 | } |
| 454 | } else { |
| 455 | // put orbited horizon behind existing horizon images |
| 456 | skyParameters.horizonImages.insertAllAt(0, CelestialGraphics::worldHorizonImages(*parameters)); |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | return skyParameters; |
| 461 | } |
nothing calls this directly
no test coverage detected