protected override void Draw(DrawingHandleBase handle, OverlaySpace currentSpace) { var map = _owner.eyeManager.CurrentMap; var worldHandle = (DrawingHandleWorld)handle; ShaderInstance?currentShader = null; foreach (var effect in _owner._Effects) { if (_mapManager.GetGrid(effect.Coordinates.GridID).ParentMapId != map) { continue; } var newShader = effect.Shaded ? null : _unshadedShader; if (newShader != currentShader) { worldHandle.UseShader(newShader); currentShader = newShader; } var effectSprite = effect.EffectSprite; var effectOrigin = effect.Coordinates.ToMapPos(_mapManager); var effectArea = Box2.CenteredAround(effectOrigin, effect.Size); var rotatedBox = new Box2Rotated(effectArea, effect.Rotation, effectOrigin); worldHandle.DrawTextureRect(effectSprite, rotatedBox, ToColor(effect.Color)); } }
public IEnumerable <IMapGrid> FindGridsIntersecting(MapId mapId, Box2Rotated bounds, bool approx = false) { var aabb = bounds.CalcBoundingBox(); // TODO: We can do slower GJK checks to check if 2 bounds actually intersect, but WYCI. return(FindGridsIntersecting(mapId, aabb, approx)); }
protected override void Draw(DrawingHandleBase handle, OverlaySpace currentSpace) { var map = _owner.eyeManager.CurrentMap; var worldHandle = (DrawingHandleWorld)handle; ShaderInstance?currentShader = null; var player = _playerManager.LocalPlayer?.ControlledEntity; foreach (var effect in _owner._Effects) { if (effect.AttachedEntity?.Transform.MapID != player?.Transform.MapID && _mapManager.GetGrid(effect.Coordinates.GetGridId(_entityManager)).ParentMapId != map) { continue; } var newShader = effect.Shaded ? null : _unshadedShader; if (newShader != currentShader) { worldHandle.UseShader(newShader); currentShader = newShader; } var effectSprite = effect.EffectSprite; var effectOrigin = effect.AttachedEntity?.Transform.MapPosition.Position + effect.AttachedOffset ?? effect.Coordinates.ToMapPos(_entityManager); var effectArea = Box2.CenteredAround(effectOrigin, effect.Size); var rotatedBox = new Box2Rotated(effectArea, effect.Rotation, effectOrigin); worldHandle.DrawTextureRect(effectSprite, rotatedBox, ToColor(effect.Color)); } }
public void FullRotationTest([ValueSource(nameof(BoxRotations))] Box2[] boxes) { var rotatedBox = new Box2Rotated(boxes[0], Angle.FromDegrees(0)); for (int i = 0; i < 4; i++) { Assert.That(rotatedBox.CalcBoundingBox(), NUnit.Framework.Is.EqualTo(boxes[i])); rotatedBox.Rotation += Angle.FromDegrees(90); } Assert.That(rotatedBox.CalcBoundingBox(), NUnit.Framework.Is.EqualTo(boxes[0])); }
private IEnumerable <EntityUid> GetAnchored(MapId mapId, Box2Rotated worldBounds, LookupFlags flags) { if ((flags & LookupFlags.IncludeAnchored) == 0x0) { yield break; } foreach (var grid in _mapManager.FindGridsIntersecting(mapId, worldBounds)) { foreach (var uid in grid.GetAnchoredEntities(worldBounds)) { if (!EntityManager.EntityExists(uid)) { continue; } yield return(uid); } } }
public GridEdgeData(Vector2i tile, EntityUid?grid, Vector2 center, Angle angle, float size) { Tile = tile; Grid = grid; Box = new(Box2.CenteredAround(center, (size, size)), angle, center); }
private DockingConfig?GetDockingConfig(ShuttleComponent component, EntityUid targetGrid) { var gridDocks = GetDocks(targetGrid); if (gridDocks.Count <= 0) { return(null); } var xformQuery = GetEntityQuery <TransformComponent>(); var targetGridGrid = Comp <IMapGridComponent>(targetGrid); var targetGridXform = xformQuery.GetComponent(targetGrid); var targetGridAngle = targetGridXform.WorldRotation.Reduced(); var targetGridRotation = targetGridAngle.ToVec(); var shuttleDocks = GetDocks(component.Owner); var shuttleAABB = Comp <IMapGridComponent>(component.Owner).Grid.LocalAABB; var validDockConfigs = new List <DockingConfig>(); if (shuttleDocks.Count > 0) { // We'll try all combinations of shuttle docks and see which one is most suitable foreach (var shuttleDock in shuttleDocks) { var shuttleDockXform = xformQuery.GetComponent(shuttleDock.Owner); foreach (var gridDock in gridDocks) { var gridXform = xformQuery.GetComponent(gridDock.Owner); if (!CanDock( shuttleDock, shuttleDockXform, gridDock, gridXform, targetGridRotation, shuttleAABB, targetGridGrid, out var dockedAABB, out var matty, out var targetAngle)) { continue; } // Can't just use the AABB as we want to get bounds as tight as possible. var spawnPosition = new EntityCoordinates(targetGrid, matty.Transform(Vector2.Zero)); spawnPosition = new EntityCoordinates(targetGridXform.MapUid !.Value, spawnPosition.ToMapPos(EntityManager)); var dockedBounds = new Box2Rotated(shuttleAABB.Translated(spawnPosition.Position), targetGridAngle, spawnPosition.Position); // Check if there's no intersecting grids (AKA oh god it's docking at cargo). if (_mapManager.FindGridsIntersecting(targetGridXform.MapID, dockedBounds).Any(o => o.GridEntityId != targetGrid)) { 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 <(DockingComponent DockA, DockingComponent DockB)>() { (shuttleDock, gridDock), }; // TODO: Check shuttle orientation as the tiebreaker. foreach (var other in shuttleDocks) { if (other == shuttleDock) { continue; } foreach (var otherGrid in gridDocks) { if (otherGrid == gridDock) { continue; } if (!CanDock( other, xformQuery.GetComponent(other.Owner), otherGrid, xformQuery.GetComponent(otherGrid.Owner), targetGridRotation, shuttleAABB, targetGridGrid, out var otherDockedAABB, out _, out var otherTargetAngle) || !otherDockedAABB.Equals(dockedAABB) || !targetAngle.Equals(otherTargetAngle)) { continue; } dockedPorts.Add((other, otherGrid)); } } var spawnRotation = shuttleDockXform.LocalRotation + gridXform.LocalRotation + targetGridXform.LocalRotation; validDockConfigs.Add(new DockingConfig() { Docks = dockedPorts, Area = dockedAABB.Value, Coordinates = spawnPosition, Angle = spawnRotation, }); } } } if (validDockConfigs.Count <= 0) { return(null); } // Prioritise by priority docks, then by maximum connected ports, then by most similar angle. validDockConfigs = validDockConfigs .OrderByDescending(x => x.Docks.Any(docks => HasComp <EmergencyDockComponent>(docks.DockB.Owner))) .ThenByDescending(x => x.Docks.Count) .ThenBy(x => Math.Abs(Angle.ShortestDistance(x.Angle.Reduced(), targetGridAngle).Theta)).ToList(); var location = validDockConfigs.First(); location.TargetGrid = targetGrid; // TODO: Ideally do a hyperspace warpin, just have it run on like a 10 second timer. return(location); }