diff --git a/Content.Server/Shuttles/Systems/ArrivalsSystem.cs b/Content.Server/Shuttles/Systems/ArrivalsSystem.cs index 0cbbc46a4fd5..40a2778b9375 100644 --- a/Content.Server/Shuttles/Systems/ArrivalsSystem.cs +++ b/Content.Server/Shuttles/Systems/ArrivalsSystem.cs @@ -45,10 +45,10 @@ public sealed class ArrivalsSystem : EntitySystem [Dependency] private readonly IConfigurationManager _cfgManager = default!; [Dependency] private readonly IConsoleHost _console = default!; [Dependency] private readonly IGameTiming _timing = default!; - [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IPrototypeManager _protoManager = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IChatManager _chat = default!; + [Dependency] private readonly SharedMapSystem _mapSystem = default!; [Dependency] private readonly BiomeSystem _biomes = default!; [Dependency] private readonly GameTicker _ticker = default!; [Dependency] private readonly MapLoaderSystem _loader = default!; @@ -496,9 +496,7 @@ private void OnRoundStarting(RoundStartingEvent ev) private void SetupArrivalsStation() { - var mapId = _mapManager.CreateMap(); - var mapUid = _mapManager.GetMapEntityId(mapId); - _mapManager.AddUninitializedMap(mapId); + var mapUid = _mapSystem.CreateMap(out var mapId, false); if (!_loader.TryLoad(mapId, _cfgManager.GetCVar(CCVars.ArrivalsMap), out var uids)) { @@ -524,7 +522,7 @@ private void SetupArrivalsStation() AddComp(mapUid, restricted); } - _mapManager.DoMapInitialize(mapId); + _mapSystem.InitializeMap(mapId); // Handle roundstart stations. var query = AllEntityQuery(); @@ -582,10 +580,10 @@ private void SetupShuttle(EntityUid uid, StationArrivalsComponent component) return; // Spawn arrivals on a dummy map then dock it to the source. - var dummyMap = _mapManager.CreateMap(); + var dummpMapEntity = _mapSystem.CreateMap(out var dummyMapId); if (TryGetArrivals(out var arrivals) && - _loader.TryLoad(dummyMap, component.ShuttlePath.ToString(), out var shuttleUids)) + _loader.TryLoad(dummyMapId, component.ShuttlePath.ToString(), out var shuttleUids)) { component.Shuttle = shuttleUids[0]; var shuttleComp = Comp(component.Shuttle); @@ -597,7 +595,7 @@ private void SetupShuttle(EntityUid uid, StationArrivalsComponent component) } // Don't start the arrivals shuttle immediately docked so power has a time to stabilise? - var timer = AddComp(_mapManager.GetMapEntityId(dummyMap)); + var timer = AddComp(dummpMapEntity); timer.Lifetime = 15f; } } diff --git a/Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs b/Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs index 1a95ef9cb22b..597d74dcc7a0 100644 --- a/Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs +++ b/Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs @@ -18,143 +18,143 @@ public sealed partial class DockingSystem private const int DockRoundingDigits = 2; public Angle GetAngle(EntityUid uid, TransformComponent xform, EntityUid targetUid, TransformComponent targetXform, EntityQuery xformQuery) - { - var (shuttlePos, shuttleRot) = _transform.GetWorldPositionRotation(xform); - var (targetPos, targetRot) = _transform.GetWorldPositionRotation(targetXform); - - var shuttleCOM = Robust.Shared.Physics.Transform.Mul(new Transform(shuttlePos, shuttleRot), - _physicsQuery.GetComponent(uid).LocalCenter); - var targetCOM = Robust.Shared.Physics.Transform.Mul(new Transform(targetPos, targetRot), - _physicsQuery.GetComponent(targetUid).LocalCenter); - - var mapDiff = shuttleCOM - targetCOM; - var angle = mapDiff.ToWorldAngle(); - angle -= targetRot; - return angle; - } - - /// - /// Checks if 2 docks can be connected by moving the shuttle directly onto docks. - /// - private bool CanDock( - DockingComponent shuttleDock, - TransformComponent shuttleDockXform, - DockingComponent gridDock, - TransformComponent gridDockXform, - Box2 shuttleAABB, - Angle targetGridRotation, - FixturesComponent shuttleFixtures, - MapGridComponent grid, - bool isMap, - out Matrix3x2 matty, - out Box2 shuttleDockedAABB, - out Angle gridRotation) - { - shuttleDockedAABB = Box2.UnitCentered; - gridRotation = Angle.Zero; - matty = Matrix3x2.Identity; - - if (shuttleDock.Docked || - gridDock.Docked || - !shuttleDockXform.Anchored || - !gridDockXform.Anchored) - { - return false; - } - - // First, get the station dock's position relative to the shuttle, this is where we rotate it around - var stationDockPos = shuttleDockXform.LocalPosition + - shuttleDockXform.LocalRotation.RotateVec(new Vector2(0f, -1f)); - - // Need to invert the grid's angle. - var shuttleDockAngle = shuttleDockXform.LocalRotation; - var gridDockAngle = gridDockXform.LocalRotation.Opposite(); - var offsetAngle = gridDockAngle - shuttleDockAngle; - - var stationDockMatrix = Matrix3Helpers.CreateInverseTransform(stationDockPos, shuttleDockAngle); - var gridXformMatrix = Matrix3Helpers.CreateTransform(gridDockXform.LocalPosition, gridDockAngle); - matty = Matrix3x2.Multiply(stationDockMatrix, gridXformMatrix); - - if (!ValidSpawn(grid, matty, offsetAngle, shuttleFixtures, isMap)) - return false; - - shuttleDockedAABB = matty.TransformBox(shuttleAABB); - gridRotation = (targetGridRotation + offsetAngle).Reduced(); - return true; - } - - /// - /// Gets docking config between 2 specific docks. - /// - public DockingConfig? GetDockingConfig( - EntityUid shuttleUid, - EntityUid targetGrid, - EntityUid shuttleDockUid, - DockingComponent shuttleDock, - EntityUid gridDockUid, - DockingComponent gridDock) - { - var shuttleDocks = new List>(1) + { + var (shuttlePos, shuttleRot) = _transform.GetWorldPositionRotation(xform); + var (targetPos, targetRot) = _transform.GetWorldPositionRotation(targetXform); + + var shuttleCOM = Robust.Shared.Physics.Transform.Mul(new Transform(shuttlePos, shuttleRot), + _physicsQuery.GetComponent(uid).LocalCenter); + var targetCOM = Robust.Shared.Physics.Transform.Mul(new Transform(targetPos, targetRot), + _physicsQuery.GetComponent(targetUid).LocalCenter); + + var mapDiff = shuttleCOM - targetCOM; + var angle = mapDiff.ToWorldAngle(); + angle -= targetRot; + return angle; + } + + /// + /// Checks if 2 docks can be connected by moving the shuttle directly onto docks. + /// + private bool CanDock( + DockingComponent shuttleDock, + TransformComponent shuttleDockXform, + DockingComponent gridDock, + TransformComponent gridDockXform, + Box2 shuttleAABB, + Angle targetGridRotation, + FixturesComponent shuttleFixtures, + Entity gridEntity, + bool isMap, + out Matrix3x2 matty, + out Box2 shuttleDockedAABB, + out Angle gridRotation) + { + shuttleDockedAABB = Box2.UnitCentered; + gridRotation = Angle.Zero; + matty = Matrix3x2.Identity; + + if (shuttleDock.Docked || + gridDock.Docked || + !shuttleDockXform.Anchored || + !gridDockXform.Anchored) + { + return false; + } + + // First, get the station dock's position relative to the shuttle, this is where we rotate it around + var stationDockPos = shuttleDockXform.LocalPosition + + shuttleDockXform.LocalRotation.RotateVec(new Vector2(0f, -1f)); + + // Need to invert the grid's angle. + var shuttleDockAngle = shuttleDockXform.LocalRotation; + var gridDockAngle = gridDockXform.LocalRotation.Opposite(); + var offsetAngle = gridDockAngle - shuttleDockAngle; + + var stationDockMatrix = Matrix3Helpers.CreateInverseTransform(stationDockPos, shuttleDockAngle); + var gridXformMatrix = Matrix3Helpers.CreateTransform(gridDockXform.LocalPosition, gridDockAngle); + matty = Matrix3x2.Multiply(stationDockMatrix, gridXformMatrix); + + if (!ValidSpawn(gridEntity, matty, offsetAngle, shuttleFixtures, isMap)) + return false; + + shuttleDockedAABB = matty.TransformBox(shuttleAABB); + gridRotation = (targetGridRotation + offsetAngle).Reduced(); + return true; + } + + /// + /// Gets docking config between 2 specific docks. + /// + public DockingConfig? GetDockingConfig( + EntityUid shuttleUid, + EntityUid targetGrid, + EntityUid shuttleDockUid, + DockingComponent shuttleDock, + EntityUid gridDockUid, + DockingComponent gridDock) + { + var shuttleDocks = new List>(1) { (shuttleDockUid, shuttleDock) }; - var gridDocks = new List>(1) + var gridDocks = new List>(1) { (gridDockUid, gridDock) }; - return GetDockingConfigPrivate(shuttleUid, targetGrid, shuttleDocks, gridDocks); - } - - /// - /// Tries to get a valid docking configuration for the shuttle to the target grid. - /// - /// Priority docking tag to prefer, e.g. for emergency shuttle - public DockingConfig? GetDockingConfig(EntityUid shuttleUid, EntityUid targetGrid, string? priorityTag = null) - { - var gridDocks = GetDocks(targetGrid); - var shuttleDocks = GetDocks(shuttleUid); - - return GetDockingConfigPrivate(shuttleUid, targetGrid, shuttleDocks, gridDocks, priorityTag); - } - - /// - /// Tries to get a docking config at the specified coordinates and angle. - /// - public DockingConfig? GetDockingConfigAt(EntityUid shuttleUid, - EntityUid targetGrid, - EntityCoordinates coordinates, - Angle angle) - { - var gridDocks = GetDocks(targetGrid); - var shuttleDocks = GetDocks(shuttleUid); - - var configs = GetDockingConfigs(shuttleUid, targetGrid, shuttleDocks, gridDocks); - - foreach (var config in configs) - { - if (config.Coordinates.Equals(coordinates) && config.Angle.EqualsApprox(angle, 0.15)) - { - return config; - } - } - - return null; - } - - /// - /// Gets all docking configs between the 2 grids. - /// - private List GetDockingConfigs( - EntityUid shuttleUid, - EntityUid targetGrid, - List> shuttleDocks, - List> gridDocks) - { - var validDockConfigs = new List(); - - if (gridDocks.Count <= 0) + return GetDockingConfigPrivate(shuttleUid, targetGrid, shuttleDocks, gridDocks); + } + + /// + /// Tries to get a valid docking configuration for the shuttle to the target grid. + /// + /// Priority docking tag to prefer, e.g. for emergency shuttle + public DockingConfig? GetDockingConfig(EntityUid shuttleUid, EntityUid targetGrid, string? priorityTag = null) + { + var gridDocks = GetDocks(targetGrid); + var shuttleDocks = GetDocks(shuttleUid); + + return GetDockingConfigPrivate(shuttleUid, targetGrid, shuttleDocks, gridDocks, priorityTag); + } + + /// + /// Tries to get a docking config at the specified coordinates and angle. + /// + public DockingConfig? GetDockingConfigAt(EntityUid shuttleUid, + EntityUid targetGrid, + EntityCoordinates coordinates, + Angle angle) + { + var gridDocks = GetDocks(targetGrid); + var shuttleDocks = GetDocks(shuttleUid); + + var configs = GetDockingConfigs(shuttleUid, targetGrid, shuttleDocks, gridDocks); + + foreach (var config in configs) + { + if (config.Coordinates.Equals(coordinates) && config.Angle.EqualsApprox(angle, 0.15)) + { + return config; + } + } + + return null; + } + + /// + /// Gets all docking configs between the 2 grids. + /// + private List GetDockingConfigs( + EntityUid shuttleUid, + EntityUid targetGrid, + List> shuttleDocks, + List> gridDocks) + { + var validDockConfigs = new List(); + + if (gridDocks.Count <= 0) return validDockConfigs; var targetGridGrid = _gridQuery.GetComponent(targetGrid); @@ -168,117 +168,118 @@ private List GetDockingConfigs( var grids = new List>(); if (shuttleDocks.Count > 0) { - // We'll try all combinations of shuttle docks and see which one is most suitable - foreach (var (dockUid, shuttleDock) in shuttleDocks) - { - var shuttleDockXform = _xformQuery.GetComponent(dockUid); - - foreach (var (gridDockUid, gridDock) in gridDocks) - { - var gridXform = _xformQuery.GetComponent(gridDockUid); - - if (!CanDock( - shuttleDock, shuttleDockXform, - gridDock, gridXform, - shuttleAABB, - targetGridAngle, - shuttleFixturesComp, - targetGridGrid, - isMap, - out var matty, - out var dockedAABB, - out var targetAngle)) - { - continue; - } - - // Can't just use the AABB as we want to get bounds as tight as possible. - var gridPosition = new EntityCoordinates(targetGrid, Vector2.Transform(Vector2.Zero, matty)); - var spawnPosition = new EntityCoordinates(targetGridXform.MapUid!.Value, gridPosition.ToMapPos(EntityManager, _transform)); - - // TODO: use tight bounds - var dockedBounds = new Box2Rotated(shuttleAABB.Translated(spawnPosition.Position), targetAngle, spawnPosition.Position); - - // Check if there's no intersecting grids (AKA oh god it's docking at cargo). - grids.Clear(); - _mapManager.FindGridsIntersecting(targetGridXform.MapID, dockedBounds, ref grids, includeMap: false); - if (grids.Any(o => o.Owner != targetGrid && o.Owner != targetGridXform.MapUid)) - { - continue; - } - - // Alright well the spawn is valid now to check how many we can connect - // Get the matrix for each shuttle dock and test it against the grid docks to see - // if the connected position / direction matches. - - var dockedPorts = new List<(EntityUid DockAUid, EntityUid DockBUid, DockingComponent DockA, DockingComponent DockB)>() + // We'll try all combinations of shuttle docks and see which one is most suitable + foreach (var (dockUid, shuttleDock) in shuttleDocks) + { + var shuttleDockXform = _xformQuery.GetComponent(dockUid); + + foreach (var (gridDockUid, gridDock) in gridDocks) + { + var gridXform = _xformQuery.GetComponent(gridDockUid); + + if (!CanDock( + shuttleDock, shuttleDockXform, + gridDock, gridXform, + shuttleAABB, + targetGridAngle, + shuttleFixturesComp, + (targetGrid, targetGridGrid), + isMap, + out var matty, + out var dockedAABB, + out var targetAngle)) + { + continue; + } + + // Can't just use the AABB as we want to get bounds as tight as possible. + var gridPosition = new EntityCoordinates(targetGrid, Vector2.Transform(Vector2.Zero, matty)); + var spawnPosition = new EntityCoordinates(targetGridXform.MapUid!.Value, _transform.ToMapCoordinates(gridPosition).Position); + + // TODO: use tight bounds + var dockedBounds = new Box2Rotated(shuttleAABB.Translated(spawnPosition.Position), targetAngle, spawnPosition.Position); + + // Check if there's no intersecting grids (AKA oh god it's docking at cargo). + grids.Clear(); + _mapManager.FindGridsIntersecting(targetGridXform.MapID, dockedBounds, ref grids, includeMap: false); + if (grids.Any(o => o.Owner != targetGrid && o.Owner != targetGridXform.MapUid)) + { + continue; + } + + // Alright well the spawn is valid now to check how many we can connect + // Get the matrix for each shuttle dock and test it against the grid docks to see + // if the connected position / direction matches. + + var dockedPorts = new List<(EntityUid DockAUid, EntityUid DockBUid, DockingComponent DockA, DockingComponent DockB)>() { (dockUid, gridDockUid, shuttleDock, gridDock), }; - dockedAABB = dockedAABB.Rounded(DockRoundingDigits); - - foreach (var (otherUid, other) in shuttleDocks) - { - if (other == shuttleDock) - continue; - - foreach (var (otherGridUid, otherGrid) in gridDocks) - { - if (otherGrid == gridDock) - continue; - - if (!CanDock( - other, - _xformQuery.GetComponent(otherUid), - otherGrid, - _xformQuery.GetComponent(otherGridUid), - shuttleAABB, - targetGridAngle, - shuttleFixturesComp, targetGridGrid, - isMap, - out _, - out var otherdockedAABB, - out var otherTargetAngle)) - { - continue; - } - - otherdockedAABB = otherdockedAABB.Rounded(DockRoundingDigits); - - // Different setup. - if (!targetAngle.Equals(otherTargetAngle) || - !dockedAABB.Equals(otherdockedAABB)) - { - continue; - } - - dockedPorts.Add((otherUid, otherGridUid, other, otherGrid)); - } - } - - validDockConfigs.Add(new DockingConfig() - { - Docks = dockedPorts, - Coordinates = gridPosition, - Area = dockedAABB, - Angle = targetAngle, - }); - } - } + dockedAABB = dockedAABB.Rounded(DockRoundingDigits); + + foreach (var (otherUid, other) in shuttleDocks) + { + if (other == shuttleDock) + continue; + + foreach (var (otherGridUid, otherGrid) in gridDocks) + { + if (otherGrid == gridDock) + continue; + + if (!CanDock( + other, + _xformQuery.GetComponent(otherUid), + otherGrid, + _xformQuery.GetComponent(otherGridUid), + shuttleAABB, + targetGridAngle, + shuttleFixturesComp, + (targetGrid, targetGridGrid), + isMap, + out _, + out var otherdockedAABB, + out var otherTargetAngle)) + { + continue; + } + + otherdockedAABB = otherdockedAABB.Rounded(DockRoundingDigits); + + // Different setup. + if (!targetAngle.Equals(otherTargetAngle) || + !dockedAABB.Equals(otherdockedAABB)) + { + continue; + } + + dockedPorts.Add((otherUid, otherGridUid, other, otherGrid)); + } + } + + validDockConfigs.Add(new DockingConfig() + { + Docks = dockedPorts, + Coordinates = gridPosition, + Area = dockedAABB, + Angle = targetAngle, + }); + } + } } return validDockConfigs; - } + } - private DockingConfig? GetDockingConfigPrivate( - EntityUid shuttleUid, - EntityUid targetGrid, - List> shuttleDocks, - List> gridDocks, - string? priorityTag = null) - { - var validDockConfigs = GetDockingConfigs(shuttleUid, targetGrid, shuttleDocks, gridDocks); + private DockingConfig? GetDockingConfigPrivate( + EntityUid shuttleUid, + EntityUid targetGrid, + List> shuttleDocks, + List> gridDocks, + string? priorityTag = null) + { + var validDockConfigs = GetDockingConfigs(shuttleUid, targetGrid, shuttleDocks, gridDocks); if (validDockConfigs.Count <= 0) return null; @@ -300,56 +301,56 @@ private List GetDockingConfigs( return location; } - /// - /// Checks whether the shuttle can warp to the specified position. - /// - private bool ValidSpawn(MapGridComponent grid, Matrix3x2 matty, Angle angle, FixturesComponent shuttleFixturesComp, bool isMap) - { - var transform = new Transform(Vector2.Transform(Vector2.Zero, matty), angle); + /// + /// Checks whether the shuttle can warp to the specified position. + /// + private bool ValidSpawn(Entity gridEntity, Matrix3x2 matty, Angle angle, FixturesComponent shuttleFixturesComp, bool isMap) + { + var transform = new Transform(Vector2.Transform(Vector2.Zero, matty), angle); - // Because some docking bounds are tight af need to check each chunk individually - foreach (var fix in shuttleFixturesComp.Fixtures.Values) - { - var polyShape = (PolygonShape) fix.Shape; - var aabb = polyShape.ComputeAABB(transform, 0); - aabb = aabb.Enlarged(-0.01f); - - // If it's a map check no hard collidable anchored entities overlap - if (isMap) - { - foreach (var tile in grid.GetLocalTilesIntersecting(aabb)) - { - var anchoredEnumerator = grid.GetAnchoredEntitiesEnumerator(tile.GridIndices); - - while (anchoredEnumerator.MoveNext(out var anc)) - { - if (!_physicsQuery.TryGetComponent(anc, out var physics) || - !physics.CanCollide || - !physics.Hard) - { - continue; - } - - return false; - } - } - } - // If it's not a map check it doesn't overlap the grid. - else - { - if (grid.GetLocalTilesIntersecting(aabb).Any()) - return false; - } - } - - return true; - } - - public List> GetDocks(EntityUid uid) - { - _dockingSet.Clear(); - _lookup.GetChildEntities(uid, _dockingSet); - - return _dockingSet.ToList(); - } + // Because some docking bounds are tight af need to check each chunk individually + foreach (var fix in shuttleFixturesComp.Fixtures.Values) + { + var polyShape = (PolygonShape)fix.Shape; + var aabb = polyShape.ComputeAABB(transform, 0); + aabb = aabb.Enlarged(-0.01f); + + // If it's a map check no hard collidable anchored entities overlap + if (isMap) + { + foreach (var tile in _mapSystem.GetLocalTilesIntersecting(gridEntity.Owner, gridEntity.Comp, aabb)) + { + var anchoredEnumerator = _mapSystem.GetAnchoredEntitiesEnumerator(gridEntity.Owner, gridEntity.Comp, tile.GridIndices); + + while (anchoredEnumerator.MoveNext(out var anc)) + { + if (!_physicsQuery.TryGetComponent(anc, out var physics) || + !physics.CanCollide || + !physics.Hard) + { + continue; + } + + return false; + } + } + } + // If it's not a map check it doesn't overlap the grid. + else + { + if (_mapSystem.GetLocalTilesIntersecting(gridEntity.Owner, gridEntity.Comp, aabb).Any()) + return false; + } + } + + return true; + } + + public List> GetDocks(EntityUid uid) + { + _dockingSet.Clear(); + _lookup.GetChildEntities(uid, _dockingSet); + + return _dockingSet.ToList(); + } } diff --git a/Content.Server/Shuttles/Systems/DockingSystem.cs b/Content.Server/Shuttles/Systems/DockingSystem.cs index f46c3980e58c..fcdd6c0c1ae3 100644 --- a/Content.Server/Shuttles/Systems/DockingSystem.cs +++ b/Content.Server/Shuttles/Systems/DockingSystem.cs @@ -23,6 +23,7 @@ namespace Content.Server.Shuttles.Systems public sealed partial class DockingSystem : SharedDockingSystem { [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly SharedMapSystem _mapSystem = default!; [Dependency] private readonly DoorSystem _doorSystem = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly PathfindingSystem _pathfinding = default!; @@ -262,7 +263,7 @@ public void Dock(Entity dockA, Entity dockB) joint.LocalAnchorA = anchorA; joint.LocalAnchorB = anchorB; - joint.ReferenceAngle = (float) (_transform.GetWorldRotation(gridBXform) - _transform.GetWorldRotation(gridAXform)); + joint.ReferenceAngle = (float)(_transform.GetWorldRotation(gridBXform) - _transform.GetWorldRotation(gridAXform)); joint.CollideConnected = true; joint.Stiffness = stiffness; joint.Damping = damping; diff --git a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs index 887ee11c63d9..ede0b687fcc5 100644 --- a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs +++ b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs @@ -220,7 +220,7 @@ private void UpdateEmergencyConsole(float frameTime) ShuttlesLeft = true; _chatSystem.DispatchGlobalAnnouncement(Loc.GetString("emergency-shuttle-left", ("transitTime", $"{TransitTime:0}"))); - Timer.Spawn((int) (TransitTime * 1000) + _bufferTime.Milliseconds, () => _roundEnd.EndRound(), _roundEndCancelToken?.Token ?? default); + Timer.Spawn((int)(TransitTime * 1000) + _bufferTime.Milliseconds, () => _roundEnd.EndRound(), _roundEndCancelToken?.Token ?? default); } // All the others. diff --git a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs index 45397ede088e..1f3b4a749bc7 100644 --- a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs @@ -50,8 +50,8 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem [Dependency] private readonly IAdminManager _admin = default!; [Dependency] private readonly IConfigurationManager _configManager = default!; [Dependency] private readonly IGameTiming _timing = default!; - [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly SharedMapSystem _mapSystem = default!; [Dependency] private readonly AccessReaderSystem _reader = default!; [Dependency] private readonly ChatSystem _chatSystem = default!; [Dependency] private readonly CommunicationsConsoleSystem _commsConsole = default!; @@ -212,7 +212,7 @@ private void OnEmergencyFTL(EntityUid uid, EmergencyShuttleComponent component, { [ShuttleTimerMasks.ShuttleMap] = uid, [ShuttleTimerMasks.SourceMap] = args.FromMapUid, - [ShuttleTimerMasks.DestMap] = args.TargetCoordinates.GetMapUid(_entityManager), + [ShuttleTimerMasks.DestMap] = _transformSystem.GetMap(args.TargetCoordinates), [ShuttleTimerMasks.ShuttleTime] = ftlTime, [ShuttleTimerMasks.SourceTime] = ftlTime, [ShuttleTimerMasks.DestTime] = ftlTime @@ -289,7 +289,7 @@ public void CallEmergencyShuttle(EntityUid stationUid, StationEmergencyShuttleCo { var angle = _dock.GetAngle(stationShuttle.EmergencyShuttle.Value, xform, targetGrid.Value, targetXform, xformQuery); var direction = ContentLocalizationManager.FormatDirection(angle.GetDir()); - var location = FormattedMessage.RemoveMarkup(_navMap.GetNearestBeaconString((stationShuttle.EmergencyShuttle.Value, xform))); + var location = FormattedMessage.RemoveMarkupPermissive(_navMap.GetNearestBeaconString((stationShuttle.EmergencyShuttle.Value, xform))); _chatSystem.DispatchStationAnnouncement(stationUid, Loc.GetString("emergency-shuttle-docked", ("time", $"{_consoleAccumulator:0}"), ("direction", direction), ("location", location)), playDefaultSound: false); } @@ -320,7 +320,7 @@ public void CallEmergencyShuttle(EntityUid stationUid, StationEmergencyShuttleCo { var angle = _dock.GetAngle(stationShuttle.EmergencyShuttle.Value, xform, targetGrid.Value, targetXform, xformQuery); var direction = ContentLocalizationManager.FormatDirection(angle.GetDir()); - var location = FormattedMessage.RemoveMarkup(_navMap.GetNearestBeaconString((stationShuttle.EmergencyShuttle.Value, xform))); + var location = FormattedMessage.RemoveMarkupPermissive(_navMap.GetNearestBeaconString((stationShuttle.EmergencyShuttle.Value, xform))); _chatSystem.DispatchStationAnnouncement(stationUid, Loc.GetString("emergency-shuttle-nearby", ("time", $"{_consoleAccumulator:0}"), ("direction", direction), ("location", location)), playDefaultSound: false); } @@ -401,7 +401,7 @@ private void SetupEmergencyShuttle() private void AddCentcomm(EntityUid station, StationCentcommComponent component) { - DebugTools.Assert(LifeStage(station)>= EntityLifeStage.MapInitialized); + DebugTools.Assert(LifeStage(station) >= EntityLifeStage.MapInitialized); if (component.MapEntity != null || component.Entity != null) { Log.Warning("Attempted to re-add an existing centcomm map."); @@ -434,12 +434,11 @@ private void AddCentcomm(EntityUid station, StationCentcommComponent component) return; } - var mapId = _mapManager.CreateMap(); + var map = _mapSystem.CreateMap(out var mapId); var grid = _map.LoadGrid(mapId, component.Map.ToString(), new MapLoadOptions() { LoadMap = false, }); - var map = _mapManager.GetMapEntityId(mapId); if (!Exists(map)) { @@ -492,7 +491,7 @@ private void AddEmergencyShuttle(Entity ent, ref Shuttle private void OnPositionFTLMessage(Entity entity, ref ShuttleConsoleFTLPositionMessage args) { - var mapUid = _mapManager.GetMapEntityId(args.Coordinates.MapId); + var mapUid = _mapSystem.GetMap(args.Coordinates.MapId); // If it's beacons only block all position messages. if (!Exists(mapUid) || _shuttle.IsBeaconMap(mapUid)) diff --git a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs index 81a2b29beb49..f02ea945d05d 100644 --- a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs @@ -26,7 +26,7 @@ namespace Content.Server.Shuttles.Systems; public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem { - [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly SharedMapSystem _mapSystem = default!; [Dependency] private readonly ActionBlockerSystem _blocker = default!; [Dependency] private readonly AlertsSystem _alertsSystem = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!; @@ -129,7 +129,7 @@ public void RefreshShuttleConsoles() while (query.MoveNext(out var uid, out _)) { - UpdateState(uid,ref dockState); + UpdateState(uid, ref dockState); } } @@ -138,7 +138,7 @@ public void RefreshShuttleConsoles() /// private void OnConsoleUIClose(EntityUid uid, ShuttleConsoleComponent component, BoundUIClosedEvent args) { - if ((ShuttleConsoleUiKey) args.UiKey != ShuttleConsoleUiKey.Key) + if ((ShuttleConsoleUiKey)args.UiKey != ShuttleConsoleUiKey.Key) { return; } diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs index afe7a7b6db62..274437aa4047 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs @@ -134,13 +134,12 @@ private EntityUid EnsureFTLMap() return uid; } - var mapId = _mapManager.CreateMap(); - var mapUid = _mapManager.GetMapEntityId(mapId); + var mapUid = _mapSystem.CreateMap(out var mapId); var ftlMap = AddComp(mapUid); _metadata.SetEntityName(mapUid, "FTL"); Log.Debug($"Setup hyperspace map at {mapUid}"); - DebugTools.Assert(!_mapManager.IsMapPaused(mapId)); + DebugTools.Assert(!_mapSystem.IsPaused(mapId)); var parallax = EnsureComp(mapUid); parallax.Parallax = ftlMap.Parallax; @@ -188,7 +187,7 @@ public void SetFTLWhitelist(Entity entity, EntityWhite /// public bool TryAddFTLDestination(MapId mapId, bool enabled, [NotNullWhen(true)] out FTLDestinationComponent? component) { - var mapUid = _mapManager.GetMapEntityId(mapId); + var mapUid = _mapSystem.GetMapOrInvalid(mapId); component = null; if (!Exists(mapUid)) @@ -281,8 +280,8 @@ public void FTLToCoordinates( _console.RefreshShuttleConsoles(shuttleUid); - var mapId = coordinates.GetMapId(EntityManager); - var mapUid = _mapManager.GetMapEntityId(mapId); + var mapId = _transform.GetMapId(coordinates); + var mapUid = _mapSystem.GetMap(mapId); var ev = new FTLRequestEvent(mapUid); RaiseLocalEvent(shuttleUid, ref ev, true); } @@ -388,7 +387,7 @@ private void UpdateFTLStarting(Entity entity) if (fromMapUid != null && TryComp(comp.StartupStream, out AudioComponent? startupAudio)) { var clippedAudio = _audio.PlayStatic(_startupSound, Filter.Broadcast(), - new EntityCoordinates(fromMapUid.Value, _maps.GetGridPosition(entity.Owner)), true, startupAudio.Params); + new EntityCoordinates(fromMapUid.Value, _mapSystem.GetGridPosition(entity.Owner)), true, startupAudio.Params); _audio.SetPlaybackPosition(clippedAudio, entity.Comp1.StartupTime); clippedAudio.Value.Component.Flags |= AudioFlags.NoOcclusion; @@ -477,7 +476,7 @@ private void UpdateFTLArriving(Entity entity) var map = maps.Min(o => o.GetHashCode()); mapId = new MapId(map); - TryFTLProximity(uid, _mapManager.GetMapEntityId(mapId)); + TryFTLProximity(uid, _mapSystem.GetMap(mapId)); } // Docking FTL else if (HasComp(target.EntityId) && @@ -502,7 +501,7 @@ private void UpdateFTLArriving(Entity entity) else { // TODO: This should now use tryftlproximity - mapId = target.GetMapId(EntityManager); + mapId = _transform.GetMapId(target); _transform.SetCoordinates(uid, xform, target, rotation: entity.Comp1.TargetAngle); } @@ -540,7 +539,7 @@ private void UpdateFTLArriving(Entity entity) _mapManager.SetMapPaused(mapId, false); Smimsh(uid, xform: xform); - var ftlEvent = new FTLCompletedEvent(uid, _mapManager.GetMapEntityId(mapId)); + var ftlEvent = new FTLCompletedEvent(uid, _mapSystem.GetMap(mapId)); RaiseLocalEvent(uid, ref ftlEvent, true); } @@ -616,7 +615,7 @@ private void DoTheDinosaur(TransformComponent xform) // If the guy we knocked down is on a spaced tile, throw them too if (grid != null) - TossIfSpaced(grid, shuttleBody, child); + TossIfSpaced((xform.GridUid.Value, grid, shuttleBody), child); } } } @@ -637,13 +636,15 @@ private void KnockOverKids(TransformComponent xform, ref ValueList to /// /// Throws people who are standing on a spaced tile, tries to throw them towards a neighbouring space tile /// - private void TossIfSpaced(MapGridComponent shuttleGrid, PhysicsComponent shuttleBody, EntityUid tossed) + private void TossIfSpaced(Entity shuttleEntity, EntityUid tossed) { - if (!_xformQuery.TryGetComponent(tossed, out var childXform) ) + var shuttleGrid = shuttleEntity.Comp1; + var shuttleBody = shuttleEntity.Comp2; + if (!_xformQuery.TryGetComponent(tossed, out var childXform)) return; // only toss if its on lattice/space - var tile = shuttleGrid.GetTileRef(childXform.Coordinates); + var tile = _mapSystem.GetTileRef(shuttleEntity, shuttleGrid, childXform.Coordinates); if (!tile.IsSpace(_tileDefManager)) return; @@ -689,7 +690,7 @@ public void FTLDock(Entity shuttle, DockingConfig config) { // Set position var mapCoordinates = _transform.ToMapCoordinates(config.Coordinates); - var mapUid = _mapManager.GetMapEntityId(mapCoordinates.MapId); + var mapUid = _mapSystem.GetMap(mapCoordinates.MapId); _transform.SetCoordinates(shuttle.Owner, shuttle.Comp, new EntityCoordinates(mapUid, mapCoordinates.Position), rotation: config.Angle); // Connect everything diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs index 4760e92e212b..5ad94699bed1 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs @@ -110,7 +110,7 @@ private bool TryDungeonSpawn(Entity targetGrid, DungeonSpawnG spawnCoords = spawnCoords.Offset(_random.NextVector2(distancePadding + group.MinimumDistance, distancePadding + group.MaximumDistance)); } - _maps.CreateMap(out var mapId); + _mapSystem.CreateMap(out var mapId); var spawnedGrid = _mapManager.CreateGridEntity(mapId); diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs index 8a8d2d883d09..436b24840736 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs @@ -39,8 +39,8 @@ private void OnShuttleCollide(EntityUid uid, ShuttleComponent component, ref Sta var otherXform = Transform(args.OtherEntity); - var ourPoint = Vector2.Transform(args.WorldPoint, ourXform.InvWorldMatrix); - var otherPoint = Vector2.Transform(args.WorldPoint, otherXform.InvWorldMatrix); + var ourPoint = Vector2.Transform(args.WorldPoint, _transform.GetInvWorldMatrix(ourXform)); + var otherPoint = Vector2.Transform(args.WorldPoint, _transform.GetInvWorldMatrix(otherXform)); var ourVelocity = _physics.GetLinearVelocity(uid, ourPoint, ourBody, ourXform); var otherVelocity = _physics.GetLinearVelocity(args.OtherEntity, otherPoint, otherBody, otherXform); diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.cs index 6ae4aff2f4a4..054c42f934a8 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.cs @@ -49,7 +49,6 @@ public sealed partial class ShuttleSystem : SharedShuttleSystem [Dependency] private readonly MetaDataSystem _metadata = default!; [Dependency] private readonly PvsOverrideSystem _pvs = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; - [Dependency] private readonly SharedMapSystem _maps = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly ShuttleConsoleSystem _console = default!; diff --git a/Content.Server/Shuttles/Systems/ThrusterSystem.cs b/Content.Server/Shuttles/Systems/ThrusterSystem.cs index af780df44af5..f5e8f7823e72 100644 --- a/Content.Server/Shuttles/Systems/ThrusterSystem.cs +++ b/Content.Server/Shuttles/Systems/ThrusterSystem.cs @@ -27,6 +27,7 @@ public sealed class ThrusterSystem : EntitySystem { [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!; + [Dependency] private readonly SharedMapSystem _mapSystem = default!; [Dependency] private readonly AmbientSoundSystem _ambient = default!; [Dependency] private readonly FixtureSystem _fixtureSystem = default!; [Dependency] private readonly DamageableSystem _damageable = default!; @@ -109,7 +110,7 @@ private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref continue; var checkPos = tilePos + new Vector2i(x, y); - var enumerator = grid.GetAnchoredEntitiesEnumerator(checkPos); + var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, checkPos); while (enumerator.MoveNext(out var ent)) { @@ -120,7 +121,7 @@ private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref var xform = xformQuery.GetComponent(ent.Value); var direction = xform.LocalRotation.ToWorldVec(); - if (new Vector2i((int) direction.X, (int) direction.Y) != new Vector2i(x, y)) + if (new Vector2i((int)direction.X, (int)direction.Y) != new Vector2i(x, y)) continue; DisableThruster(ent.Value, thruster, xform.GridUid); @@ -183,8 +184,8 @@ private void OnRotate(EntityUid uid, ThrusterComponent component, ref MoveEvent return; } - var oldDirection = (int) args.OldRotation.GetCardinalDir() / 2; - var direction = (int) args.NewRotation.GetCardinalDir() / 2; + var oldDirection = (int)args.OldRotation.GetCardinalDir() / 2; + var direction = (int)args.NewRotation.GetCardinalDir() / 2; var oldShuttleComponent = shuttleComponent; if (args.ParentChanged) @@ -282,7 +283,7 @@ public void EnableThruster(EntityUid uid, ThrusterComponent component, Transform switch (component.Type) { case ThrusterType.Linear: - var direction = (int) xform.LocalRotation.GetCardinalDir() / 2; + var direction = (int)xform.LocalRotation.GetCardinalDir() / 2; shuttleComponent.LinearThrust[direction] += component.Thrust; DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(uid)); @@ -294,7 +295,7 @@ public void EnableThruster(EntityUid uid, ThrusterComponent component, Transform { var shape = new PolygonShape(); shape.Set(component.BurnPoly); - _fixtureSystem.TryCreateFixture(uid, shape, BurnFixture, hard: false, collisionLayer: (int) CollisionGroup.FullTileMask, body: physicsComponent); + _fixtureSystem.TryCreateFixture(uid, shape, BurnFixture, hard: false, collisionLayer: (int)CollisionGroup.FullTileMask, body: physicsComponent); } break; @@ -334,7 +335,7 @@ private void RefreshCenter(EntityUid uid, ShuttleComponent shuttle) foreach (var dir in new[] { Direction.South, Direction.East, Direction.North, Direction.West }) { - var index = (int) dir / 2; + var index = (int)dir / 2; var pop = shuttle.LinearThrusters[index]; var totalThrust = 0f; @@ -380,7 +381,7 @@ public void DisableThruster(EntityUid uid, ThrusterComponent component, EntityUi { case ThrusterType.Linear: angle ??= xform.LocalRotation; - var direction = (int) angle.Value.GetCardinalDir() / 2; + var direction = (int)angle.Value.GetCardinalDir() / 2; shuttleComponent.LinearThrust[direction] -= component.Thrust; DebugTools.Assert(shuttleComponent.LinearThrusters[direction].Contains(uid)); @@ -426,7 +427,7 @@ public bool CanEnable(EntityUid uid, ThrusterComponent component) var xform = Transform(uid); - if (!xform.Anchored ||!this.IsPowered(uid, EntityManager)) + if (!xform.Anchored || !this.IsPowered(uid, EntityManager)) { return false; } @@ -443,7 +444,8 @@ private bool NozzleExposed(TransformComponent xform) return true; var (x, y) = xform.LocalPosition + xform.LocalRotation.Opposite().ToWorldVec(); - var tile = Comp(xform.GridUid.Value).GetTileRef(new Vector2i((int) Math.Floor(x), (int) Math.Floor(y))); + var mapGrid = Comp(xform.GridUid.Value); + var tile = _mapSystem.GetTileRef(xform.GridUid.Value, mapGrid, new Vector2i((int)Math.Floor(x), (int)Math.Floor(y))); return tile.Tile.IsSpace(); } @@ -582,6 +584,6 @@ public void SetAngularThrust(ShuttleComponent component, bool on) private int GetFlagIndex(DirectionFlag flag) { - return (int) Math.Log2((int) flag); + return (int)Math.Log2((int)flag); } }