/// <summary>
        /// Adds a filled arc to the batch of figures to be rendered using up to the given number of subdivisions.
        /// </summary>
        /// <param name="brush">The brush to render the shape with.</param>
        /// <param name="center">The center coordinate of the arc.</param>
        /// <param name="radius">The radius of the arc.</param>
        /// <param name="startAngle">The starting angle of the arc in radians, where 0 is 3 O'Clock.</param>
        /// <param name="arcAngle">The sweep of the arc in radians.  Positive values draw clockwise.</param>
        /// <param name="arcType">Whether the arc is drawn as a segment or a sector.</param>
        /// <param name="subdivisions">The number of subdivisions in the circle with the same radius as the arc.</param>
        /// <exception cref="InvalidOperationException"><c>FillArc</c> was called, but <see cref="Begin()"/> has not yet been called.</exception>
        /// <remarks>The number of subdivisions in the arc is computed as <c>subdivisions * (arcAngle / 2PI)</c>.</remarks>
        public void FillArc (Brush brush, CCVector2 center, float radius, float startAngle, float arcAngle, ArcType arcType, int subdivisions)
        {
            if (!_inDraw)
                throw new InvalidOperationException();
            if (brush == null)
                throw new ArgumentNullException("brush");

            int vertexCount = BuildArcGeometryBuffer(center, radius, subdivisions, startAngle, arcAngle);

            RequestBufferSpace(vertexCount + 1, (vertexCount - 1) * 3);
            AddInfo(PrimitiveType.TriangleList, vertexCount + 1, (vertexCount - 1) * 3, brush);

            //int baseVertexIndex = _vertexBufferIndex;

            //for (int i = 0; i < vertexCount; i++)
            //    AddVertex(_geometryBuffer[i], brush);

            //switch (arcType) {
            //    case ArcType.Sector:
            //        AddVertex(new CCVector2(center.X, center.Y), brush);
            //        break;
            //    case ArcType.Segment:
            //        AddVertex(new CCVector2((_geometryBuffer[0].X + _geometryBuffer[vertexCount - 1].X) / 2, 
            //            (_geometryBuffer[0].Y + _geometryBuffer[vertexCount - 1].Y) / 2), brush); 
            //        break;
            //}

            //if (arcAngle < 0) {
            //    for (int i = 0; i < vertexCount - 1; i++)
            //        AddTriangle(baseVertexIndex + vertexCount, baseVertexIndex + i + 1, baseVertexIndex + i);
            //}
            //else {
            //    for (int i = vertexCount - 1; i > 0; i--)
            //        AddTriangle(baseVertexIndex + vertexCount, baseVertexIndex + i - 1, baseVertexIndex + i);
            //}

            //if (_sortMode == DrawSortMode.Immediate)
            //    FlushBuffer();
        }
        /// <summary>
        /// Computes and adds a closed arc path to the batch of figures to be rendered using up to the given number of subdivisions.
        /// </summary>
        /// <param name="pen">The pen to render the path with.</param>
        /// <param name="center">The center coordinate of the the arc.</param>
        /// <param name="radius">The radius of the arc.</param>
        /// <param name="startAngle">The starting angle of the arc in radians, where 0 is 3 O'Clock.</param>
        /// <param name="arcAngle">The sweep of the arc in radians.  Positive values draw clockwise.</param>
        /// <param name="arcType">Whether the arc is drawn as a segment or a sector.</param>
        /// <param name="subdivisions">The number of subdivisions in a circle of the same radius.</param>
        /// <exception cref="InvalidOperationException"><c>DrawClosedArc</c> was called, but <see cref="Begin()"/> has not yet been called.</exception>
        /// <remarks>The number of subdivisions in the arc is computed as <c>subdivisions * (arcAngle / 2PI)</c>.</remarks>
        public void DrawClosedArc (Pen pen, CCVector2 center, float radius, float startAngle, float arcAngle, ArcType arcType, int subdivisions)
        {
            if (!_inDraw)
                throw new InvalidOperationException();
            if (pen == null)
                throw new ArgumentNullException("pen");

            _ws.ResetWorkspace(pen);

            _pathBuilder.Reset();
            _pathBuilder.CalculateLengths = pen.NeedsPathLength;

            if (arcType == ArcType.Sector)
                _pathBuilder.AddPoint(center);
            _pathBuilder.AddArc(center, radius, startAngle, arcAngle, subdivisions);

            if (_pathBuilder.Count > 1)
            {
                AddClosedPath(_pathBuilder.Buffer, 0, _pathBuilder.Count, pen, _ws);

                //if (_sortMode == DrawSortMode.Immediate)
                //    FlushBuffer();
            }
        }
 /// <summary>
 /// Adds a filled arc to the batch of figures to be rendered.
 /// </summary>
 /// <param name="brush">The brush to render the shape with.</param>
 /// <param name="center">The center coordinate of the arc.</param>
 /// <param name="radius">The radius of the arc.</param>
 /// <param name="startAngle">The starting angle of the arc in radians, where 0 is 3 O'Clock.</param>
 /// <param name="arcAngle">The sweep of the arc in radians.  Positive values draw clockwise.</param>
 /// <param name="arcType">Whether the arc is drawn as a segment or a sector.</param>
 /// <exception cref="InvalidOperationException"><c>FillArc</c> was called, but <see cref="Begin()"/> has not yet been called.</exception>
 /// <remarks>The number of subdivisions in the arc is computed as <c>(radius / 1.5) * (arcAngle / 2PI)</c>.</remarks>
 public void FillArc (Brush brush, CCVector2 center, float radius, float startAngle, float arcAngle, ArcType arcType)
 {
     FillArc(brush, center, radius, startAngle, arcAngle, arcType, DefaultSubdivisions(radius));
 }
        /// <summary>
        /// Adds a closed primitive arc path to the batch of figures to be rendered using up to the given number of subdivisions.
        /// </summary>
        /// <param name="pen">The pen supplying the color to render the path with.</param>
        /// <param name="center">The center coordinate of the the arc.</param>
        /// <param name="radius">The radius of the arc.</param>
        /// <param name="startAngle">The starting angle of the arc in radians, where 0 is 3 O'Clock.</param>
        /// <param name="arcAngle">The sweep of the arc in radians.  Positive values draw clockwise.</param>
        /// <param name="arcType">Whether the arc is drawn as a segment or a sector.</param>
        /// <param name="subdivisions">The number of subdivisions in a circle of the same radius.</param>
        /// <exception cref="InvalidOperationException"><c>DrawPrimitiveClosedArc</c> was called, but <see cref="Begin()"/> has not yet been called.</exception>
        /// <remarks>The number of subdivisions in the arc is computed as <c>(subdivisions * (arcAngle / 2PI)</c>.</remarks>
        public void DrawPrimitiveClosedArc (Pen pen, CCVector2 center, float radius, float startAngle, float arcAngle, ArcType arcType, int subdivisions)
        {
            if (!_inDraw)
                throw new InvalidOperationException();
            if (pen == null)
                throw new ArgumentNullException("pen");

            _pathBuilder.Reset();
            _pathBuilder.CalculateLengths = pen.NeedsPathLength;

            if (arcType == ArcType.Sector)
                _pathBuilder.AddPoint(center);
            _pathBuilder.AddArc(center, radius, startAngle, arcAngle, subdivisions);

            if (_pathBuilder.Count > 1)
                DrawPrimitivePath(pen, _pathBuilder.Buffer, 0, _pathBuilder.Count, PathType.Closed);
        }
 /// <summary>
 /// Computes and adds a closed arc path to the batch of figures to be rendered.
 /// </summary>
 /// <param name="pen">The pen to render the path with.</param>
 /// <param name="center">The center coordinate of the the arc.</param>
 /// <param name="radius">The radius of the arc.</param>
 /// <param name="startAngle">The starting angle of the arc in radians, where 0 is 3 O'Clock.</param>
 /// <param name="arcAngle">The sweep of the arc in radians.  Positive values draw clockwise.</param>
 /// <param name="arcType">Whether the arc is drawn as a segment or a sector.</param>
 /// <exception cref="InvalidOperationException"><c>DrawClosedArc</c> was called, but <see cref="Begin()"/> has not yet been called.</exception>
 /// <remarks>The number of subdivisions in the arc is computed as <c>(radius / 1.5) * (arcAngle / 2PI)</c>.</remarks>
 public void DrawClosedArc (Pen pen, CCVector2 center, float radius, float startAngle, float arcAngle, ArcType arcType)
 {
     DrawClosedArc(pen, center, radius, startAngle, arcAngle, arcType, DefaultSubdivisions(radius));
 }
 public ArcRestriction(ArcType arcType)
 {
     ArcType = arcType;
 }
 public SectorCheckAction(ArcType sectorType, Func <GenericShip> targetShip, AbilityPart action)
 {
     SectorType    = sectorType;
     GetTargetShip = targetShip;
     Action        = action;
 }
Example #8
0
        public override bool DefenderIsReinforcedAgainstAttacker(ArcFacing facing, GenericShip defender, GenericShip attacker)
        {
            ArcType arcType = (facing == ArcFacing.FullFront) ? ArcType.FullFront : ArcType.FullRear;

            return(defender.SectorsInfo.IsShipInSector(attacker, arcType));
        }
Example #9
0
        /// <summary>
        /// Create circular arc
        /// </summary>
        /// <param name="ArcStart">Arc starting point</param>
        /// <param name="ArcEnd">Arc ending point</param>
        /// <param name="Radius">Arc radius</param>
        /// <param name="Type">Arc type</param>
        /// <returns>Array of points.</returns>
        internal static PointD[] CircularArc
        (
            PointD ArcStart,
            PointD ArcEnd,
            double Radius,
            ArcType Type
        )
        {
            // chord line from start point to end point
            double ChordDeltaX = ArcEnd.X - ArcStart.X;
            double ChordDeltaY = ArcEnd.Y - ArcStart.Y;
            double ChordLength = Math.Sqrt(ChordDeltaX * ChordDeltaX + ChordDeltaY * ChordDeltaY);

            // test radius
            if (2 * Radius < ChordLength)
            {
                throw new ApplicationException("Radius too small.");
            }

            // line perpendicular to chord at mid point
            // distance from chord mid point to center of circle
            double ChordToCircleLen = Math.Sqrt(Radius * Radius - ChordLength * ChordLength / 4);
            double ChordToCircleCos = -ChordDeltaY / ChordLength;
            double ChordToCircleSin = ChordDeltaX / ChordLength;

            if (Type == ArcType.SmallClockWise || Type == ArcType.LargeCounterClockWise)
            {
                ChordToCircleCos = -ChordToCircleCos;
                ChordToCircleSin = -ChordToCircleSin;
            }

            // circle center
            double CenterX = (ArcStart.X + ArcEnd.X) / 2 + ChordToCircleLen * ChordToCircleCos;
            double CenterY = (ArcStart.Y + ArcEnd.Y) / 2 + ChordToCircleLen * ChordToCircleSin;

            // arc angle
            double ArcAngle = 2 * Math.Asin(ChordLength / (2 * Radius));

            if (ArcAngle < 0.001)
            {
                throw new ApplicationException("Angle too small");
            }
            if (Type == ArcType.LargeCounterClockWise || Type == ArcType.LargeClockWise)
            {
                ArcAngle = 2 * Math.PI - ArcAngle;
            }

            // segment array
            PointD[] SegArray;

            // one segment equal or less than 90 deg
            if (ArcAngle < Math.PI / 2 + 0.001)
            {
                double K1 = 4 * (1 - Math.Cos(ArcAngle / 2)) / (3 * Math.Sin(ArcAngle / 2));
                if (Type == ArcType.LargeClockWise || Type == ArcType.SmallClockWise)
                {
                    K1 = -K1;
                }
                SegArray    = new PointD[4];
                SegArray[0] = ArcStart;
                SegArray[1] = new PointD(ArcStart.X - K1 * (ArcStart.Y - CenterY), ArcStart.Y + K1 * (ArcStart.X - CenterX));
                SegArray[2] = new PointD(ArcEnd.X + K1 * (ArcEnd.Y - CenterY), ArcEnd.Y - K1 * (ArcEnd.X - CenterX));
                SegArray[3] = ArcEnd;
                return(SegArray);
            }

            // 2, 3 or 4 segments
            int    Segments = (int)(ArcAngle / (0.5 * Math.PI)) + 1;
            double SegAngle = ArcAngle / Segments;
            double K        = 4 * (1 - Math.Cos(SegAngle / 2)) / (3 * Math.Sin(SegAngle / 2));

            if (Type == ArcType.LargeClockWise || Type == ArcType.SmallClockWise)
            {
                K        = -K;
                SegAngle = -SegAngle;
            }

            // segments array
            SegArray    = new PointD[3 * Segments + 1];
            SegArray[0] = new PointD(ArcStart.X, ArcStart.Y);

            // angle from cricle center to start point
            double SegStartX  = ArcStart.X;
            double SegStartY  = ArcStart.Y;
            double StartAngle = Math.Atan2(ArcStart.Y - CenterY, ArcStart.X - CenterX);

            // process all segments
            int SegEnd = SegArray.Length;

            for (int Seg = 1; Seg < SegEnd; Seg += 3)
            {
                double EndAngle = StartAngle + SegAngle;
                double SegEndX  = CenterX + Radius * Math.Cos(EndAngle);
                double SegEndY  = CenterY + Radius * Math.Sin(EndAngle);
                SegArray[Seg]     = new PointD(SegStartX - K * (SegStartY - CenterY), SegStartY + K * (SegStartX - CenterX));
                SegArray[Seg + 1] = new PointD(SegEndX + K * (SegEndY - CenterY), SegEndY - K * (SegEndX - CenterX));
                SegArray[Seg + 2] = new PointD(SegEndX, SegEndY);
                SegStartX         = SegEndX;
                SegStartY         = SegEndY;
                StartAngle        = EndAngle;
            }
            return(SegArray);
        }
 public void Remove(ArcType arcType)
 {
     StoredArcsList.Remove(arcType);
 }
 public SpecialWeaponInfo(int attackValue, int minRange, int maxRange, List <Type> requiresTokens = null, Type requiresToken = null, Type spendsToken = null, int charges = 0, bool discard = false, bool twinAttack = false, bool canShootOutsideArc = false, ArcType arc = ArcType.Front, bool noRangeBonus = false)
 {
     AttackValue    = attackValue;
     MinRange       = minRange;
     MaxRange       = maxRange;
     RequiresTokens = (requiresToken != null) ? new List <Type>()
     {
         requiresToken
     } : new List <Type>();
     SpendsToken        = spendsToken;
     Discard            = discard;
     Charges            = charges;
     TwinAttack         = twinAttack;
     ArcRestrictions    = new ArcsList(arc);
     CanShootOutsideArc = canShootOutsideArc;
     NoRangeBonus       = noRangeBonus;
 }
 public void Add(ArcType arcType)
 {
     StoredArcsList.Add(arcType);
 }
 public DefenderInSectorCondition(ArcType arcType)
 {
     ArcType = arcType;
 }
Example #14
0
 public bool HasArc(ArcType arcType)
 {
     return(HostShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == arcType));
 }
Example #15
0
 public ShipArcInfo(ArcType arcType, int firepower = -1)
 {
     ArcType   = arcType;
     Firepower = firepower;
     Name      = GetArcName(arcType);
 }
Example #16
0
 public SpecialWeaponInfo(int attackValue, int minRange, int maxRange, Type requiresToken = null, Type spendsToken = null, int charges = 0, bool discard = false, bool twinAttack = false, bool canShootOutsideArc = false, ArcType arc = ArcType.Front)
 {
     AttackValue     = attackValue;
     MinRange        = minRange;
     MaxRange        = maxRange;
     RequiresToken   = requiresToken;
     SpendsToken     = spendsToken;
     Discard         = discard;
     Charges         = charges;
     TwinAttack      = twinAttack;
     ArcRestrictions = new List <ArcType>()
     {
         arc
     };
     CanShootOutsideArc = canShootOutsideArc;
 }