Exemplo n.º 1
0
        private void HandleVessel(Vessel target)
        {
            if (target == null)
            {
                return;
            }

            IEnumerable <string> partsToTest = PartsToTest(contract).Select(p => p.title);

            foreach (Part part in target.parts.Where(p => partsToTest.Contains(p.partInfo.title)))
            {
                bool handled = false;
                foreach (PartModule pm in part.Modules)
                {
                    ModuleTestSubject mts = pm as ModuleTestSubject;
                    if (mts != null)
                    {
                        mts.isTestSubject = true;
                        mts.Events["RunTestEvent"].active = true;

                        handled = true;
                        break;
                    }
                }

                if (!handled)
                {
                    LoggingUtil.LogWarning(this, "Part " + part.name + " does not have a ModuleTestSubject, cannot be used as the target of a PartTest");
                }
                else
                {
                    LoggingUtil.LogVerbose(this, "    activate part " + part.name);
                }
            }
        }
Exemplo n.º 2
0
        protected void HandlePartChange(Vessel targetVessel, AvailablePart targetPart)
        {
            if (targetVessel == null)
            {
                return;
            }

            IEnumerable <string> partsToTest = ContractSystem.Instance.Contracts.
                                               Where(c => c.ContractState == Contract.State.Active).
                                               SelectMany(PartsToTest).
                                               Select(p => p.title);
            bool isActive = partsToTest.Contains(targetPart.title);

            LoggingUtil.LogVerbose(this, "   part " + targetPart.title + ", active = " + isActive);

            foreach (Part part in targetVessel.parts.Where(p => partsToTest.Contains(p.partInfo.title)))
            {
                foreach (PartModule pm in part.Modules)
                {
                    ModuleTestSubject mts = pm as ModuleTestSubject;
                    if (mts != null)
                    {
                        mts.isTestSubject = isActive;
                        mts.Events["RunTestEvent"].active = isActive;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void customStartup(parameterContainer p)
        {
            Type       t = p.CParam.GetType();
            GameScenes s = HighLogic.LoadedScene;

            try
            {
                if (t == typeof(ReachDestination) && s == GameScenes.FLIGHT && FlightGlobals.ActiveVessel != null)
                {
                    if (p.CParam.State == ParameterState.Incomplete && ((ReachDestination)p.CParam).checkVesselDestination(FlightGlobals.ActiveVessel))
                    {
                        MethodInfo m = (typeof(ContractParameter)).GetMethod("SetComplete", BindingFlags.NonPublic | BindingFlags.Instance);

                        if (m == null)
                        {
                            return;
                        }

                        m.Invoke(p.CParam, null);
                    }
                    else if (p.CParam.State == ParameterState.Complete && !((ReachDestination)p.CParam).checkVesselDestination(FlightGlobals.ActiveVessel))
                    {
                        MethodInfo m = (typeof(ContractParameter)).GetMethod("SetIncomplete", BindingFlags.NonPublic | BindingFlags.Instance);

                        if (m == null)
                        {
                            return;
                        }

                        m.Invoke(p.CParam, null);
                    }
                }
                else if (t == typeof(ReachSituation) && s == GameScenes.FLIGHT && FlightGlobals.ActiveVessel != null)
                {
                    if (p.CParam.State == ParameterState.Incomplete && ((ReachSituation)p.CParam).checkVesselSituation(FlightGlobals.ActiveVessel))
                    {
                        MethodInfo m = (typeof(ContractParameter)).GetMethod("SetComplete", BindingFlags.NonPublic | BindingFlags.Instance);

                        if (m == null)
                        {
                            return;
                        }

                        m.Invoke(p.CParam, null);
                    }
                    else if (p.CParam.State == ParameterState.Complete && !((ReachSituation)p.CParam).checkVesselSituation(FlightGlobals.ActiveVessel))
                    {
                        MethodInfo m = (typeof(ContractParameter)).GetMethod("SetIncomplete", BindingFlags.NonPublic | BindingFlags.Instance);

                        if (m == null)
                        {
                            return;
                        }

                        m.Invoke(p.CParam, null);
                    }
                }
                else if (t == typeof(SpecificOrbitParameter) && s == GameScenes.FLIGHT)
                {
                    ((SpecificOrbitParameter)p.CParam).SetupRenderer();
                }
                else if (t == typeof(VesselSystemsParameter) && s == GameScenes.FLIGHT)
                {
                    VesselSystemsParameter sys = (VesselSystemsParameter)p.CParam;

                    MethodInfo m = (typeof(VesselSystemsParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke(sys, null);

                    if (!sys.requireNew)
                    {
                        return;
                    }

                    Vessel v = FlightGlobals.ActiveVessel;

                    if (v == null)
                    {
                        return;
                    }

                    if (v.situation != Vessel.Situations.PRELAUNCH)
                    {
                        return;
                    }

                    uint launchID = v.Parts.Min(r => r.launchID);

                    sys.launchID = launchID;
                }
                else if (t == typeof(SurveyWaypointParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(SurveyWaypointParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((SurveyWaypointParameter)p.CParam, null);

                    if (p.Way == null)
                    {
                        return;
                    }

                    var waypoints = WaypointManager.Instance().Waypoints;

                    if (waypoints.Contains(p.Way))
                    {
                        return;
                    }

                    WaypointManager.AddWaypoint(p.Way);
                }
                else if (t == typeof(StationaryPointParameter) && s == GameScenes.FLIGHT)
                {
                    if (p.Way == null)
                    {
                        return;
                    }

                    var waypoints = WaypointManager.Instance().Waypoints;

                    if (waypoints.Contains(p.Way))
                    {
                        return;
                    }

                    WaypointManager.AddWaypoint(p.Way);
                }
                else if (t == typeof(AsteroidParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(AsteroidParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((AsteroidParameter)p.CParam, null);
                }
                else if (t == typeof(CrewCapacityParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(CrewCapacityParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((CrewCapacityParameter)p.CParam, null);
                }
                else if (t == typeof(CrewTraitParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(CrewTraitParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((CrewTraitParameter)p.CParam, null);
                }
                else if (t == typeof(KerbalDestinationParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(KerbalDestinationParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((KerbalDestinationParameter)p.CParam, null);
                }
                else if (t == typeof(KerbalTourParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(KerbalTourParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((KerbalTourParameter)p.CParam, null);
                }
                else if (t == typeof(KerbalGeeAdventureParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(KerbalGeeAdventureParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((KerbalGeeAdventureParameter)p.CParam, null);
                }
                else if (t == typeof(LocationAndSituationParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(LocationAndSituationParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((LocationAndSituationParameter)p.CParam, null);
                }
                else if (t == typeof(MobileBaseParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(MobileBaseParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((MobileBaseParameter)p.CParam, null);
                }
                else if (t == typeof(PartRequestParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(PartRequestParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((PartRequestParameter)p.CParam, null);
                }
                else if (t == typeof(ProgressTrackingParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(ProgressTrackingParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((ProgressTrackingParameter)p.CParam, null);
                }
                else if (t == typeof(ResourceExtractionParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(ResourceExtractionParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((ResourceExtractionParameter)p.CParam, null);
                }
                else if (t == typeof(VesselDestinationParameter) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(VesselDestinationParameter)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((VesselDestinationParameter)p.CParam, null);
                }
                else if (t == typeof(RecoverKerbal) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(RecoverKerbal)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((RecoverKerbal)p.CParam, null);
                }
                else if (t == typeof(RecoverPart) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(RecoverPart)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((RecoverPart)p.CParam, null);
                }
                else if (t == typeof(AcquirePart) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(AcquirePart)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((AcquirePart)p.CParam, null);
                }
                else if (t == typeof(AcquireCrew) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(AcquireCrew)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((AcquireCrew)p.CParam, null);
                }
                else if (t == typeof(PartTest) && s == GameScenes.FLIGHT)
                {
                    MethodInfo m = (typeof(PartTest)).GetMethod("OnRegister", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (m == null)
                    {
                        return;
                    }

                    m.Invoke((PartTest)p.CParam, null);

                    if (((PartTest)p.CParam).hauled)
                    {
                        return;
                    }

                    AvailablePart targetPart = ((PartTest)p.CParam).tgtPartInfo;

                    if (targetPart == null)
                    {
                        return;
                    }

                    for (int i = FlightGlobals.VesselsLoaded.Count - 1; i >= 0; i--)
                    {
                        Vessel v = FlightGlobals.VesselsLoaded[i];

                        if (v == null)
                        {
                            continue;
                        }

                        for (int j = v.Parts.Count - 1; j >= 0; j--)
                        {
                            Part part = v.Parts[j];

                            if (part == null)
                            {
                                continue;
                            }

                            if (part.partInfo != targetPart)
                            {
                                continue;
                            }

                            var mods = part.FindModulesImplementing <ModuleTestSubject>();

                            for (int k = 0; k < mods.Count; k++)
                            {
                                ModuleTestSubject test = mods[k];

                                if (test == null)
                                {
                                    continue;
                                }

                                test.Events["RunTestEvent"].active = true;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogFormatted("Error while forcing Contract Parameter activation:\n{0}", e);
            }
        }