private void dataGridView1_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
 {
     if (pDeleted != null)
     {
         Client.DBContext.PenaltySet.Remove(pDeleted);
         pDeleted = null;
         Client.DBContext.SaveChanges();
         updatePoints();
         updateEnablement();
     }
 }
        private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (!dataGridView1.IsCurrentRowDirty)
            {
                return;
            }
            int penVal;
            var iDval         = dataGridView1.Rows[e.RowIndex].Cells[0].FormattedValue;
            var penaltyValue  = dataGridView1.Rows[e.RowIndex].Cells[1].FormattedValue;
            var penaltyReason = dataGridView1.Rows[e.RowIndex].Cells[2].FormattedValue;

            if (string.IsNullOrWhiteSpace(penaltyValue.ToString()))
            {
                dataGridView1.Rows[e.RowIndex].ErrorText = "Penalty points cannot be empty";
                e.Cancel = true;
                return;
            }
            if (string.IsNullOrWhiteSpace(penaltyReason.ToString()))
            {
                dataGridView1.Rows[e.RowIndex].ErrorText = "Penalty reason cannot be empty";
                e.Cancel = true;
                return;
            }
            if (!int.TryParse(penaltyValue.ToString(), out penVal))
            {
                dataGridView1.Rows[e.RowIndex].ErrorText = "Penalty points must be numeric";
                e.Cancel = true;
                return;
            }

            dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty;
            PenaltySet p = new PenaltySet();

            if (string.IsNullOrEmpty(iDval.ToString()))
            {
                FlightSet flt = dataGridView2.SelectedRows[0].Tag as FlightSet;
                p.Reason = penaltyReason.ToString().Trim();
                p.Points = penVal;
                if (!flt.PenaltySet.Contains(p))
                {
                    flt.PenaltySet.Add(p);
                }
                dataGridView1.Rows[e.RowIndex].Tag = p;
            }
            else
            {
                p        = dataGridView1.Rows[e.RowIndex].Tag as PenaltySet;
                p.Reason = penaltyReason.ToString().Trim();
                p.Points = penVal;
            }
            Client.DBContext.SaveChanges();
            updatePoints();
            updateEnablement();
        }
 private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 {
     if (!e.Row.IsNewRow)
     {
         string str = e.Row.Cells[1].Value.ToString() + " " + e.Row.Cells[2].Value.ToString();
         if (MessageBox.Show(string.Format("Delete the selected Penalty:\n {0} ?", str), "Delete Penalty", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.No)
         {
             e.Cancel = true;
             return;
         }
         pDeleted = e.Row.Tag as PenaltySet;
     }
 }
        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            if (dataGridView1.SelectedRows[0].Tag == null)
            {
                return;
            }
            PenaltySet p = dataGridView1.SelectedRows[0].Tag as PenaltySet;

            updateEnablement();
        }
    public virtual string WarningMessage(Creature c)
    {
        PenaltySet p = new PenaltySet(this, c);
        if (p.TotalPenalty() < PenaltyWarningThreshold)
            return "";
        switch(p.LimitingStat())
        {
            case PenaltySet.Stat.Str:
                return "Low STR";
            case PenaltySet.Stat.Dex:
                return "Low DEX";
            case PenaltySet.Stat.Aff:
                return "Low AFF";
        }

        Utils.Log("Error in PrimaryWeapon: Warning Message");
        return "";
    }
Example #6
0
        public static List <PenaltySet> CalculatePenaltyPoints(FlightSet flight, out List <IntersectionPoint> lstIntersectionPoints)
        {
            bool useProhZoneCalculation = false;

            Point             last             = null;
            List <PenaltySet> result           = new List <PenaltySet>();
            List <LineP>      PenaltyZoneLines = new List <LineP>();
            // intersectionPoints will contain the intersection poinst of the flight path with SP, FP, PROH areas
            List <IntersectionPoint> intersectionPoints = new List <IntersectionPoint>();
            QualificationRoundSet    qr = flight.QualificationRoundSet;
            ParcourSet parcour          = flight.QualificationRoundSet.ParcourSet;

            useProhZoneCalculation = (parcour.PenaltyCalcType != (int)ParcourType.CHANNELS);


            List <LineP> ChannelZoneLines = getAssignedChannelLineP(parcour, (Route)flight.Route);

            foreach (Line nl in parcour.Line.Where(p => p.Type == (int)LineType.PENALTYZONE))
            {
                PenaltyZoneLines.Add(getLine(nl));
            }

            // add also all channel-specific prohibited zones assigned channel
            PenaltyZoneLines.AddRange(getAssignedProhZonelLines(parcour, (Route)flight.Route));

            List <LineP> dataLines = new List <LineP>();

            foreach (Point g in flight.Point)
            {
                if (last != null)
                {
                    LineP l = new LineP();
                    l.end           = new Vector(g.longitude, g.latitude, 0);
                    l.TimestamEnd   = g.Timestamp;
                    l.start         = new Vector(last.longitude, last.latitude, 0);
                    l.TimestamStart = last.Timestamp;
                    dataLines.Add(l);
                }
                last = g;
            }
            LineP startLine = getStartLine(parcour, (Route)flight.Route);
            LineP endLine   = getEndLine(parcour, (Route)flight.Route);

            if (startLine == null || endLine == null)
            {
                lstIntersectionPoints = intersectionPoints;
                return(result);
            }
            LineP takeOffLine = new LineP();

            takeOffLine.start       = new Vector(qr.TakeOffLine.A.longitude, qr.TakeOffLine.A.latitude, 0);
            takeOffLine.end         = new Vector(qr.TakeOffLine.B.longitude, qr.TakeOffLine.B.latitude, 0);
            takeOffLine.orientation = Vector.Orthogonal(takeOffLine.end - takeOffLine.start);

            long maxTimestamp = 0;

            maxTimestamp = flight.Point.Max(x => x.Timestamp);

            // For TakeOff-, Start- and End Line, we obviously(?) assume that these lines should have been passed two minutes before the end of recording
            // below values are used in case they are not passed
            bool shouldHaveCrossedTakeOff = (maxTimestamp - 2 * tickOfMinute) > flight.TimeTakeOff;
            bool shouldHaveCrossedStart   = (maxTimestamp - 2 * tickOfMinute) > flight.TimeStartLine;
            bool shouldHaveCrossedEnd     = (maxTimestamp - 2 * tickOfMinute) > flight.TimeEndLine;

            bool haveCrossedTakeOff         = false;
            bool haveCrossedStart           = false;
            bool haveCrossedEnd             = false;
            bool insidePenalty              = false;
            long timeSinceInsidePenalty     = 0;
            bool outsideOwnChannel          = true;
            long timeSinceOutsideOwnChannel = 0;
            bool isFirstTimeIntoChannel     = true;

            IntersectionPoint ipTakeOff = new IntersectionPoint();
            IntersectionPoint ipStart   = new IntersectionPoint();
            IntersectionPoint ipEnd     = new IntersectionPoint();

            foreach (LineP l in dataLines)
            {
                double            intersectionTakeOff = getIntersection(l, takeOffLine);
                double            intersectionStart   = getIntersection(l, startLine);
                double            intersectionEnd     = getIntersection(l, endLine);
                IntersectionPoint ip = new IntersectionPoint();

                #region crossing takeOff line
                if (getIntersection(l, takeOffLine, out ip) && !haveCrossedTakeOff)
                {
                    haveCrossedTakeOff = true;
                    intersectionPoints.Add(ip);
                    long crossTime = ip.Timestamp;
                    crossTime = ((crossTime + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // round
                    ipTakeOff = ip;
                    long       diff    = crossTime - flight.TimeTakeOff;
                    PenaltySet penalty = new PenaltySet();
                    penalty.Points = (diff > C_TKOF_TimeUpper * tickOfSecond || diff < C_TKOF_TimeLower * tickOfSecond) ? C_TKOF_MaxPenalty : 0;
                    penalty.Reason = string.Format("Take-off Line planned: {1}, actual: {0}", new DateTime((Int64)crossTime).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime((Int64)flight.TimeTakeOff).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                    result.Add(penalty);
                }
                #endregion

                #region crossing start line
                if (getIntersection(l, startLine, out ip) & !haveCrossedStart)
                {
                    haveCrossedStart = true;
                    intersectionPoints.Add(ip);
                    long crossTime = ip.Timestamp;
                    ipStart = ip;
                    long diff = Math.Abs(crossTime - flight.TimeStartLine);
                    crossTime = ((crossTime + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // round
                    int        sec     = (int)((diff + (tickOfSecond / 2) + 1) / tickOfSecond);
                    PenaltySet penalty = new PenaltySet();
                    penalty.Points = (diff > C_SPFP_TimeTolerance * tickOfSecond) ? Math.Min((sec - C_SPFP_TimeTolerance) * C_PointsPerSec, C_SPFP_MaxPenalty) : 0;
                    penalty.Reason = string.Format("SP Line planned: {1}, actual: {0}", new DateTime((Int64)crossTime).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime((Int64)flight.TimeStartLine).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                    result.Add(penalty);
                }
                #endregion

                if (useProhZoneCalculation || ChannelZoneLines.Count == 0)
                {
                    #region entering or leaving prohibited zone

                    bool stateChanged = false;
                    //IntersectionPoint ip = new IntersectionPoint();
                    if (intersectsProhAreaPoint(PenaltyZoneLines, l, out stateChanged, out ip))
                    {
                        if (stateChanged)
                        {
                            intersectionPoints.Add(ip);
                            if (!insidePenalty)
                            {
                                insidePenalty          = true;
                                timeSinceInsidePenalty = ip.Timestamp;
                            }
                            else
                            {
                                insidePenalty = false;
                                long diff = ip.Timestamp - timeSinceInsidePenalty;
                                if (diff > tickOfSecond * C_PROH_TimeTolerance)
                                {
                                    PenaltySet penalty = new PenaltySet();
                                    // round times for entering/leaving penalty zone to nearest full second
                                    long pstart = ((timeSinceInsidePenalty + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // rounded
                                    long pend   = ((ip.Timestamp + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond;           // rounded
                                    int  sec    = (int)((pend - pstart) / tickOfSecond);
                                    penalty.Points = (sec - C_PROH_TimeTolerance) * C_PointsPerSec;
                                    // Max penalty inside PROH zone: ======>> NOTE: acc FAI rules disabled after NOV 2017; zero means no maximum per event
                                    penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - C_PROH_TimeTolerance) * C_PointsPerSec, C_MaxPenaltyPerEvent) : penalty.Points;
                                    //penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - 5) * 3, C_MaxPenaltyPerEvent) : penalty.Points;
                                    penalty.Reason = string.Format("Penalty zone for {0} sec, [{1} - {2}]", sec, new DateTime(pstart).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime(pend).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                                    result.Add(penalty);
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region entering or leaving channel

                    bool stateChanged = false;
                    if (intersectsOwnChannel(ChannelZoneLines, l, out stateChanged, out ip))
                    {
                        if (stateChanged)
                        {
                            intersectionPoints.Add(ip);
                            if (!outsideOwnChannel)
                            {
                                outsideOwnChannel          = true;
                                timeSinceOutsideOwnChannel = ip.Timestamp;
                            }
                            else
                            {
                                if (isFirstTimeIntoChannel)
                                {
                                    isFirstTimeIntoChannel = false;
                                    if (haveCrossedStart)
                                    {
                                        timeSinceOutsideOwnChannel = ipStart.Timestamp;
                                    }
                                    else
                                    {
                                        timeSinceOutsideOwnChannel = flight.TimeStartLine;
                                    }
                                }
                                outsideOwnChannel = false;
                                long diff = ip.Timestamp - timeSinceOutsideOwnChannel;
                                if (diff > tickOfSecond * C_PROH_TimeTolerance)
                                {
                                    PenaltySet penalty = new PenaltySet();
                                    // round times for entering/leaving penalty zone to nearest full second
                                    long pstart = ((timeSinceOutsideOwnChannel + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // rounded
                                    long pend   = ((ip.Timestamp + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond;               // rounded
                                    int  sec    = (int)((pend - pstart) / tickOfSecond);
                                    penalty.Points = (sec - C_PROH_TimeTolerance) * C_PointsPerSec;
                                    penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - C_PROH_TimeTolerance) * C_PointsPerSec, C_MaxPenaltyPerEvent) : penalty.Points;
                                    //penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - 5) * 3, C_MaxPenaltyPerEvent) : penalty.Points;
                                    penalty.Reason = string.Format("outside channel for {0} sec, [{1} - {2}]", sec, new DateTime(pstart).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime(pend).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                                    result.Add(penalty);
                                }
                            }
                        }
                    }
                    else
                    {
                        // check if end line is passed now but outside the cannel. if yes, set outSideOwnChannel = false
                        if (getIntersection(l, endLine, out ip))
                        {
                            outsideOwnChannel = false;
                            long diff = ip.Timestamp - timeSinceOutsideOwnChannel;
                            if (diff > tickOfSecond * C_PROH_TimeTolerance)
                            {
                                PenaltySet penalty = new PenaltySet();
                                // round times for entering/leaving penalty zone to nearest full second
                                long pstart = ((timeSinceOutsideOwnChannel + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // rounded
                                long pend   = ((ip.Timestamp + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond;               // rounded
                                int  sec    = (int)((pend - pstart) / tickOfSecond);
                                penalty.Points = (sec - C_PROH_TimeTolerance) * C_PointsPerSec;
                                // Max penalty outside channel; zero value means no Max penalty
                                penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - C_PROH_TimeTolerance) * C_PointsPerSec, C_MaxPenaltyPerEvent) : penalty.Points;
                                //penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - 5) * 3, C_MaxPenaltyPerEvent) : penalty.Points;
                                penalty.Reason = string.Format("outside channel for {0} sec, [{1} - {2}]", sec, new DateTime(pstart).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime(pend).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                                result.Add(penalty);
                            }
                        }
                    }

                    #endregion
                }

                #region crossing end line
                if (getIntersection(l, endLine, out ip) & !haveCrossedEnd)
                {
                    haveCrossedEnd = true;
                    intersectionPoints.Add(ip);
                    long crossTime = ip.Timestamp;
                    ipEnd = ip;
                    long diff = Math.Abs(crossTime - flight.TimeEndLine);
                    crossTime = ((crossTime + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // round
                    int        sec     = (int)((diff + (tickOfSecond / 2) + 1) / tickOfSecond);
                    PenaltySet penalty = new PenaltySet();
                    penalty.Points = (diff > C_SPFP_TimeTolerance * tickOfSecond) ? Math.Min((sec - C_SPFP_TimeTolerance) * C_PointsPerSec, C_SPFP_MaxPenalty) : 0;
                    penalty.Reason = string.Format("FP Line planned: {1}, actual: {0}", new DateTime((Int64)crossTime).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime((Int64)flight.TimeEndLine).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                    result.Add(penalty);
                }
                #endregion
            }

            #region handling cases where Takeoff-, Start- or End line are not observed/never crossed

            if (shouldHaveCrossedStart && !haveCrossedStart)
            {
                PenaltySet penalty = new PenaltySet();
                penalty.Points = C_SPFP_MaxPenalty;
                penalty.Reason = "SP Line not passed";
                result.Insert(0, penalty); // add to begin of list
            }
            ;
            if (shouldHaveCrossedTakeOff && !haveCrossedTakeOff)
            {
                PenaltySet penalty = new PenaltySet();
                penalty.Points = C_TKOF_MaxPenalty;
                penalty.Reason = "Takeoff Line not passed";
                result.Insert(0, penalty); // add to begin of list
            }
            ;
            if (shouldHaveCrossedEnd && !haveCrossedEnd)
            {
                PenaltySet penalty = new PenaltySet();
                // TODO: handle the case where we have channel calculation but no FP line
                if (!(useProhZoneCalculation || ChannelZoneLines.Count == 0) && outsideOwnChannel)
                {
                    outsideOwnChannel = false;
                    long crossTime = flight.TimeEndLine;
                    long diff      = Math.Abs(crossTime - timeSinceOutsideOwnChannel);
                    if (diff > C_SPFP_TimeTolerance * tickOfSecond)
                    {
                        crossTime = ((crossTime + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // round
                        int sec = (int)((diff + (tickOfSecond / 2) + 1) / tickOfSecond);
                        penalty.Points = Math.Min((sec - C_SPFP_TimeTolerance) * C_PointsPerSec, C_SPFP_MaxPenalty);
                        penalty.Reason = string.Format("outside channel for {0} sec, [{1} - {2}]", sec, new DateTime(timeSinceOutsideOwnChannel).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime(crossTime).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                        result.Add(penalty);
                    }
                }
                penalty        = new PenaltySet();
                penalty.Points = C_SPFP_MaxPenalty;
                penalty.Reason = "FP Line not passed";
                result.Add(penalty);
            }
            ;
            #endregion



            lstIntersectionPoints = intersectionPoints;
            return(result);
        }
 public int Accuracy(Creature c)
 {
     PenaltySet p = new PenaltySet(this, c);
     return Math.Max(1, 99 - p.TotalPenalty());
 }