Example #1
0
        public SnapCandidate Snap(UserCoordinates userCoordinates, FortressLayout layout)
        {
            var centerPoint       = userCoordinates.NearestHardpoint();
            var candidatePosition = Position.ThreeByThreeCenteredAt(centerPoint);

            bool isLegal   = false;
            var  isBlocked = layout.ComponentsByHardpoint(centerPoint)
                             .Any(c => c.ComponentType == FoundationComponentType.Floor);

            if (!isBlocked)
            {
                var neighbors             = GetNeighboringFoundations(candidatePosition, layout);
                var hasMisalignedNeighbor = neighbors.Any(
                    n => n.Position.OverlapWith(candidatePosition).Hardpoints.Count == 2);
                isLegal = !hasMisalignedNeighbor;
            }

            var candidate = new SnapCandidate()
            {
                Position    = candidatePosition,
                BoundingBox = new RectangleF(centerPoint.X - .1f, centerPoint.Y - .1f, .2f, .2f),
                IsLegal     = isLegal
            };

            return(candidate);
        }
        public void RenderInUiCoordinates(Graphics graphics, FortressLayout fortress)
        {
            var originalState = graphics.Save();

            graphics.TranslateTransform(-HardpointViewingWindow.X, -HardpointViewingWindow.Y);
            graphics.ScaleTransform(ScaleFactor, ScaleFactor);
            RenderInHardpointCoordinates(graphics, fortress);
            graphics.Restore(originalState);
        }
Example #3
0
        public SnapCandidate Snap(UserCoordinates userCoordinates, FortressLayout layout)
        {
            var hardpoint = userCoordinates.NearestHardpoint();
            var overlaps  = layout.ComponentsByHardpoint(hardpoint).ToList();

            var isLegal =
                overlaps.Any(c => c.ComponentType == FoundationComponentType.Floor) &&
                overlaps.All(c => c.ComponentType != FoundationComponentType.Pillar);

            var candidate = new SnapCandidate()
            {
                Position    = Position.OneByOneAt(hardpoint),
                BoundingBox = new RectangleF(hardpoint.X - .1f, hardpoint.Y - .1f, .2f, .2f),
                IsLegal     = isLegal
            };

            return(candidate);
        }
        public void RenderInHardpointCoordinates(Graphics graphics, FortressLayout fortress)
        {
            var brush          = new SolidBrush(Color.Black);
            var pen            = Pens.Black;
            var penScaleFactor = 1f / (ScaleFactor / 2f);

            pen.ScaleTransform(penScaleFactor, penScaleFactor, MatrixOrder.Append);

            // Perf optimization for later: don't render components outside the viewing window
            foreach (var component in fortress.ComponentsByZOrder)
            {
                brush.Color = component.FillColor;
                var bbox = component.BoundingBox;
                graphics.FillRectangle(brush, bbox);

                graphics.DrawRectangle(pen, bbox.X, bbox.Y, bbox.Width, bbox.Height);
            }
            pen.ResetTransform();
        }
Example #5
0
 public IEnumerable <IFortressComponent> GetNeighboringFoundations(Position p, FortressLayout layout)
 {
     // There's no need to check the sides or center - foundations are 2x2, so any foundation
     // touching a non-corner hardpoint must also touch a corner hardpoint.
     return(p.GetCorners()
            .SelectMany(layout.ComponentsByHardpoint)
            .Where(c => c.ComponentType == FoundationComponentType.Floor)
            .Distinct());
 }
Example #6
0
 public MainForm()
 {
     InitializeComponent();
     fortress = CreateDummyFortress();
     renderer = new FortressRenderer();
 }