예제 #1
0
 /// <summary>Scans a BaseFlightGroup's arrival/departure motherships for FG reference problems.</summary>
 private void scanMothershipProblems(Platform.BaseFlightGroup bfg, bool scrubProblems, List <string> output)
 {
     if (bfg.ArrivalMethod1)
     {
         logProblem("Arrival mothership is FG:" + bfg.ArrivalCraft1, output);
         if (scrubProblems)
         {
             bfg.ArrivalMethod1 = false; bfg.ArrivalCraft1 = 0;
         }
     }
     if (bfg.ArrivalMethod2)
     {
         logProblem("Alternate Arrival mothership is FG:" + bfg.ArrivalCraft2, output);
         if (scrubProblems)
         {
             bfg.ArrivalMethod2 = false; bfg.ArrivalCraft2 = 0;
         }
     }
     if (bfg.DepartureMethod1)
     {
         logProblem("Departure mothership is FG:" + bfg.DepartureCraft1, output);
         if (scrubProblems)
         {
             bfg.DepartureMethod1 = false; bfg.DepartureCraft1 = 0;
         }
     }
     if (bfg.DepartureMethod2)
     {
         logProblem("Alternate Departure mothership is FG:" + bfg.DepartureCraft2, output);
         if (scrubProblems)
         {
             bfg.DepartureMethod2 = false; bfg.DepartureCraft2 = 0;
         }
     }
 }
예제 #2
0
        /// <summary>Checks FlightGroup for potential issues caused by explicit FlightGroup reference indices that may cause unintended behavior when added into the mission.</summary>
        /// <remarks>Checks mothership arrival/departure, all triggers and skip triggers, and orders.</remarks>
        /// <param name="fg">FlightGroup object to check.</param>
        /// <param name="scrubProblems">If true, if any FlightGroup references are detected or used in triggers, they will be replaced with null values.</param>
        /// <param name="compileProblems">If true, specifies that a list strings will be returned, detailing all FlightGroup references used by this FlightGroup.</param>
        /// <returns>Returns null if <paramref name="compileProblems"/> is false. Otherwise returns a list of strings.</returns>
        private List <string> scanProblems(object fg, bool scrubProblems, bool compileProblems)
        {
            List <string> errors = (compileProblems ? new List <string>() : null);

            Platform.BaseFlightGroup bfg = (Platform.BaseFlightGroup)fg;
            // Begin the list with a craft name indicating the object we're checking.
            if (errors != null)
            {
                errors.Add(bfg.ToString());
            }
            switch (_platform)
            {
            case Settings.Platform.XWING:
                Platform.Xwing.FlightGroup xwing = (Platform.Xwing.FlightGroup)fg;
                if (xwing.Mothership >= 0)
                {
                    if (xwing.ArrivalHyperspace == 0)
                    {
                        logProblem("Arrival mothership is FG:" + xwing.Mothership, errors);
                        if (scrubProblems)
                        {
                            xwing.ArrivalHyperspace = 1;
                        }
                    }
                    if (xwing.DepartureHyperspace == 0)
                    {
                        logProblem("Departure mothership is FG:" + xwing.Mothership, errors);
                        if (scrubProblems)
                        {
                            xwing.DepartureHyperspace = 1;
                        }
                    }
                    if (scrubProblems)
                    {
                        xwing.Mothership = -1;
                    }
                }
                if (xwing.ArrivalFG >= 0)
                {
                    logProblem("Arrival trigger is FG:" + xwing.ArrivalFG, errors);
                    if (scrubProblems)
                    {
                        xwing.ArrivalFG    = -1;
                        xwing.ArrivalEvent = 0;
                    }
                }
                if (xwing.TargetPrimary >= 0)
                {
                    logProblem("Primary target is FG:" + xwing.TargetPrimary, errors);
                    if (scrubProblems)
                    {
                        xwing.TargetPrimary = -1;
                    }
                }
                if (xwing.TargetSecondary >= 0)
                {
                    logProblem("Secondary target is FG:" + xwing.TargetSecondary, errors);
                    if (scrubProblems)
                    {
                        xwing.TargetSecondary = -1;
                    }
                }
                break;

            case Settings.Platform.TIE:
                Platform.Tie.FlightGroup tie = (Platform.Tie.FlightGroup)fg;
                scanMothershipProblems(tie, scrubProblems, errors);
                for (int i = 0; i < tie.ArrDepTriggers.Length; i++)
                {
                    Platform.Tie.Mission.Trigger trig = tie.ArrDepTriggers[i];
                    if (trig.Condition != 0 && trig.Condition != 10 && trig.VariableType == 1)
                    {
                        logProblem("ArrDep trigger #" + (i + 1) + " references FG:" + trig.Variable, errors);
                        if (scrubProblems)
                        {
                            trig.Condition = 0; trig.Variable = 0; trig.VariableType = 0;
                        }
                    }
                }
                for (int i = 0; i < tie.Orders.Length; i++)
                {
                    Platform.Tie.FlightGroup.Order order = tie.Orders[i];
                    if (order.Target1Type == 1)
                    {
                        logProblem("Order #" + (i + 1) + " Target1 references FG:" + order.Target1, errors); if (scrubProblems)
                        {
                            order.Target1 = 0; order.Target1Type = 0;
                        }
                    }
                    if (order.Target2Type == 1)
                    {
                        logProblem("Order #" + (i + 1) + " Target2 references FG:" + order.Target2, errors); if (scrubProblems)
                        {
                            order.Target2 = 0; order.Target2Type = 0;
                        }
                    }
                    if (order.Target3Type == 1)
                    {
                        logProblem("Order #" + (i + 1) + " Target3 references FG:" + order.Target3, errors); if (scrubProblems)
                        {
                            order.Target3 = 0; order.Target3Type = 0;
                        }
                    }
                    if (order.Target4Type == 1)
                    {
                        logProblem("Order #" + (i + 1) + " Target4 references FG:" + order.Target4, errors); if (scrubProblems)
                        {
                            order.Target4 = 0; order.Target4Type = 0;
                        }
                    }
                }
                break;

            case Settings.Platform.XvT:
            case Settings.Platform.BoP:
                Platform.Xvt.FlightGroup xvt = (Platform.Xvt.FlightGroup)fg;
                scanMothershipProblems(xvt, scrubProblems, errors);
                for (int i = 0; i < xvt.ArrDepTriggers.Length; i++)
                {
                    Platform.Xvt.Mission.Trigger trig = xvt.ArrDepTriggers[i];
                    if (trig.Condition != 0 && trig.Condition != 10 && (trig.VariableType == 1 || trig.VariableType == 0xF))
                    {
                        logProblem("ArrDep trigger #" + (i + 1) + " references FG:" + trig.Variable, errors);
                        if (scrubProblems)
                        {
                            trig.Condition = 0; trig.Variable = 0; trig.VariableType = 0;
                        }
                    }
                }
                for (int i = 0; i < xvt.Orders.Length; i++)
                {
                    Platform.Xvt.FlightGroup.Order order = xvt.Orders[i];
                    if (order.Target1Type == 1 || order.Target1Type == 0xF)
                    {
                        logProblem("Order #" + (i + 1) + " Target1 references FG:" + order.Target1, errors); if (scrubProblems)
                        {
                            order.Target1 = 0; order.Target1Type = 0;
                        }
                    }
                    if (order.Target2Type == 1 || order.Target2Type == 0xF)
                    {
                        logProblem("Order #" + (i + 1) + " Target2 references FG:" + order.Target2, errors); if (scrubProblems)
                        {
                            order.Target2 = 0; order.Target2Type = 0;
                        }
                    }
                    if (order.Target3Type == 1 || order.Target3Type == 0xF)
                    {
                        logProblem("Order #" + (i + 1) + " Target3 references FG:" + order.Target3, errors); if (scrubProblems)
                        {
                            order.Target3 = 0; order.Target3Type = 0;
                        }
                    }
                    if (order.Target4Type == 1 || order.Target4Type == 0xF)
                    {
                        logProblem("Order #" + (i + 1) + " Target4 references FG:" + order.Target4, errors); if (scrubProblems)
                        {
                            order.Target4 = 0; order.Target4Type = 0;
                        }
                    }
                }
                for (int i = 0; i < xvt.SkipToOrder4Trigger.Length; i++)
                {
                    Platform.Xvt.Mission.Trigger trig = xvt.SkipToOrder4Trigger[i];
                    if (trig.Condition != 0 && trig.Condition != 10 && (trig.VariableType == 1 || trig.VariableType == 0xF))
                    {
                        logProblem("Skip trigger #" + (i + 1) + " references FG:" + trig.Variable, errors);
                        if (scrubProblems)
                        {
                            trig.Condition = 0; trig.Variable = 0; trig.VariableType = 0;
                        }
                    }
                }
                break;

            case Settings.Platform.XWA:
                Platform.Xwa.FlightGroup xwa = (Platform.Xwa.FlightGroup)fg;
                scanMothershipProblems(xwa, scrubProblems, errors);
                for (int i = 0; i < xwa.ArrDepTriggers.Length; i++)
                {
                    Platform.Xwa.Mission.Trigger trig = xwa.ArrDepTriggers[i];
                    if (trig.Condition != 0 && trig.Condition != 10 && (trig.VariableType == 1 || trig.VariableType == 0xF))
                    {
                        logProblem("ArrDep trigger #" + (i + 1) + " references FG:" + trig.Variable, errors);
                        if (scrubProblems)
                        {
                            trig.Condition = 0; trig.Variable = 0; trig.VariableType = 0;
                        }
                    }
                    if (trig.Parameter1 > 4)
                    {
                        logProblem("ArrDep trigger #" + (i + 1) + " parameter references FG:" + (trig.Parameter1 - 1), errors);
                        if (scrubProblems)
                        {
                            trig.Parameter1 = 0;
                        }
                    }
                }
                for (int reg = 0; reg < 4; reg++)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        Platform.Xwa.FlightGroup.Order order = xwa.Orders[reg, i];
                        if (order.Target1Type == 1 || order.Target1Type == 0xF)
                        {
                            logProblem("Region #" + (reg + 1) + " Order #" + (i + 1) + " Target1 references FG:" + order.Target1, errors); if (scrubProblems)
                            {
                                order.Target1Type = 0;
                            }
                        }
                        if (order.Target2Type == 1 || order.Target2Type == 0xF)
                        {
                            logProblem("Region #" + (reg + 1) + " Order #" + (i + 1) + " Target2 references FG:" + order.Target2, errors); if (scrubProblems)
                            {
                                order.Target2Type = 0;
                            }
                        }
                        if (order.Target3Type == 1 || order.Target3Type == 0xF)
                        {
                            logProblem("Region #" + (reg + 1) + " Order #" + (i + 1) + " Target3 references FG:" + order.Target3, errors); if (scrubProblems)
                            {
                                order.Target3Type = 0;
                            }
                        }
                        if (order.Target4Type == 1 || order.Target4Type == 0xF)
                        {
                            logProblem("Region #" + (reg + 1) + " Order #" + (i + 1) + " Target4 references FG:" + order.Target4, errors); if (scrubProblems)
                            {
                                order.Target4Type = 0;
                            }
                        }
                        for (int k = 0; k < order.SkipTriggers.Length; k++)
                        {
                            Platform.Xwa.Mission.Trigger trig = order.SkipTriggers[k];
                            if (trig.Condition != 0 && trig.Condition != 10 && (trig.VariableType == 1 || trig.VariableType == 0xF))
                            {
                                logProblem("Region #" + (reg + 1) + " Order #" + (i + 1) + " Skip trigger #" + (k + 1) + " references FG:" + trig.Variable, errors);
                                if (scrubProblems)
                                {
                                    trig.Condition = 0; trig.Variable = 0; trig.VariableType = 0;
                                }
                            }
                            if (trig.Parameter1 > 4)
                            {
                                logProblem("Region #" + (reg + 1) + " Order #" + (i + 1) + " Skip trigger #" + (k + 1) + " parameter references FG:" + (trig.Parameter1 - 1), errors);
                                if (scrubProblems)
                                {
                                    trig.Parameter1 = 0;
                                }
                            }
                        }
                    }
                }
                break;
            }

            //Remove the name if no errors were logged.
            if (errors != null && errors.Count == 1)
            {
                errors.Clear();
            }
            return(errors);
        }