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

Method serverUpdate

source/game/StarSystemWorld.cpp:420–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418}
419
420void 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
456pair<ByteArray, uint64_t> SystemObject::writeNetState(uint64_t fromVersion, NetCompatibilityRules rules) {
457 return m_netGroup.writeNetState(fromVersion, rules);

Callers 1

updateMethod · 0.80

Calls 15

CelestialCoordinateClass · 0.85
orbitPositionMethod · 0.80
shipsAtLocationMethod · 0.80
isPlanetaryBodyMethod · 0.80
planetPositionMethod · 0.80
normalizedMethod · 0.80
planetSizeMethod · 0.80
planetsMethod · 0.80
orbitTargetMethod · 0.80
timeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected