| 418 | } |
| 419 | |
| 420 | void SystemObject::serverUpdate(SystemWorldServer* system, float dt) { |
| 421 | if (!m_config.permanent && m_spawnTime > 0.0 && system->time() > m_spawnTime + m_config.lifeTime) |
| 422 | m_shouldDestroy = true; |
| 423 | |
| 424 | if (m_orbit.get()) { |
| 425 | setPosition(system->orbitPosition(*m_orbit.get())); |
| 426 | } else if (m_config.permanent || !m_config.moving) { |
| 427 | // permanent locations always have a solar orbit |
| 428 | enterOrbit(CelestialCoordinate(system->location()), {0.0, 0.0}, system->time()); |
| 429 | } else if (m_approach && !m_approach->isNull()) { |
| 430 | |
| 431 | if (system->shipsAtLocation(m_uuid).size() > 0) |
| 432 | return; |
| 433 | |
| 434 | if (m_approach->isPlanetaryBody()) { |
| 435 | auto approach = system->planetPosition(*m_approach); |
| 436 | auto toApproach = (approach - position()); |
| 437 | auto pos = position(); |
| 438 | setPosition(pos + toApproach.normalized() * m_config.speed * dt); |
| 439 | |
| 440 | if ((approach - position()).magnitude() < system->planetSize(*m_approach) + m_config.orbitDistance) |
| 441 | enterOrbit(*m_approach, approach, system->time()); |
| 442 | } else { |
| 443 | enterOrbit(*m_approach, {0.0, 0.0}, system->time()); |
| 444 | } |
| 445 | } else { |
| 446 | auto planets = system->planets().filtered([system](CelestialCoordinate const& p) { |
| 447 | auto objectsAtPlanet = system->objects().filtered([p](SystemObjectPtr const& o) { return o->orbitTarget() == p; }); |
| 448 | return objectsAtPlanet.size() == 0; |
| 449 | }); |
| 450 | |
| 451 | if (planets.size() > 0) |
| 452 | m_approach = Random::randFrom(planets); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | pair<ByteArray, uint64_t> SystemObject::writeNetState(uint64_t fromVersion, NetCompatibilityRules rules) { |
| 457 | return m_netGroup.writeNetState(fromVersion, rules); |
no test coverage detected