/// <summary> /// Retrieves a shuttle for delivery. /// </summary> public void CallShuttle(StationCargoOrderDatabaseComponent orderDatabase) { if (!TryComp <CargoShuttleComponent>(orderDatabase.Shuttle, out var shuttle) || !TryComp <TransformComponent>(orderDatabase.Owner, out var xform)) { return; } // Already called / not available if (shuttle.NextCall == null || _timing.CurTime < shuttle.NextCall) { return; } shuttle.NextCall = null; // Find a valid free area nearby to spawn in on // TODO: Make this use hyperspace now. var center = new Vector2(); var minRadius = 0f; Box2?aabb = null; foreach (var grid in _mapManager.GetAllMapGrids(xform.MapID)) { aabb = aabb?.Union(grid.WorldAABB) ?? grid.WorldAABB; } if (aabb != null) { center = aabb.Value.Center; minRadius = MathF.Max(aabb.Value.Width, aabb.Value.Height); } var offset = 0f; if (TryComp <IMapGridComponent>(orderDatabase.Shuttle, out var shuttleGrid)) { var bounds = shuttleGrid.Grid.LocalAABB; offset = MathF.Max(bounds.Width, bounds.Height) / 2f; } Transform(shuttle.Owner).Coordinates = new EntityCoordinates(xform.ParentUid, center + _random.NextVector2(minRadius + offset, minRadius + CallOffset + offset)); DebugTools.Assert(!MetaData(shuttle.Owner).EntityPaused); AddCargoContents(shuttle, orderDatabase); UpdateOrders(orderDatabase); UpdateShuttleCargoConsoles(shuttle); _console.RefreshShuttleConsoles(); _sawmill.Info($"Retrieved cargo shuttle {ToPrettyString(shuttle.Owner)} from {ToPrettyString(orderDatabase.Owner)}"); }