vector3d Space::GetHyperspaceExitPoint(const SystemPath &source) const { assert(m_starSystem); assert(source.IsSystemPath()); const SystemPath &dest = m_starSystem->GetPath(); Sector source_sec(source.sectorX, source.sectorY, source.sectorZ); Sector dest_sec(dest.sectorX, dest.sectorY, dest.sectorZ); Sector::System source_sys = source_sec.m_systems[source.systemIndex]; Sector::System dest_sys = dest_sec.m_systems[dest.systemIndex]; const vector3d sourcePos = vector3d(source_sys.p) + vector3d(source.sectorX, source.sectorY, source.sectorZ); const vector3d destPos = vector3d(dest_sys.p) + vector3d(dest.sectorX, dest.sectorY, dest.sectorZ); // find the first non-gravpoint. should be the primary star Body *primary = 0; for (BodyIterator i = BodiesBegin(); i != BodiesEnd(); ++i) if ((*i)->GetSystemBody()->type != SystemBody::TYPE_GRAVPOINT) { primary = *i; break; } assert(primary); // point along the line between source and dest, a reasonable distance // away based on the radius (don't want to end up inside black holes, and // then mix it up so that ships don't end up on top of each other vector3d pos = (sourcePos - destPos).Normalized() * (primary->GetSystemBody()->GetRadius()/AU+1.0)*11.0*AU*Pi::rng.Double(0.95,1.2) + MathUtil::RandomPointOnSphere(5.0,20.0)*1000.0; assert(pos.Length() > primary->GetSystemBody()->GetRadius()); return pos + primary->GetPositionRelTo(GetRootFrame()); }
vector3d Space::GetHyperspaceExitPoint(const SystemPath &source) const { assert(m_starSystem); assert(source.IsSystemPath()); const SystemPath &dest = m_starSystem->GetPath(); Sector source_sec(source.sectorX, source.sectorY, source.sectorZ); Sector dest_sec(dest.sectorX, dest.sectorY, dest.sectorZ); Sector::System source_sys = source_sec.m_systems[source.systemIndex]; Sector::System dest_sys = dest_sec.m_systems[dest.systemIndex]; const vector3d sourcePos = vector3d(source_sys.p) + vector3d(source.sectorX, source.sectorY, source.sectorZ); const vector3d destPos = vector3d(dest_sys.p) + vector3d(dest.sectorX, dest.sectorY, dest.sectorZ); return (sourcePos - destPos).Normalized() * 11.0*AU + MathUtil::RandomPointOnSphere(5.0,20.0)*1000.0; // "hyperspace zone": 11 AU from primary }