void vessel_selected(ConfigNode node, CraftBrowserDialog.LoadType t)
        {
            vessel_selector = null;
            //load vessel config
            var construct = new ShipConstruct();

            if (!construct.LoadShip(node))
            {
                var shipName = node.GetValue("ship");
                Utils.Error($"Unable to load ShipConstruct '{shipName}'. " +
                            "This usually means that some parts are missing " +
                            "or some modules failed to initialize.");
                Utils.Message("Unable to load {0}", shipName);
                return;
            }
            //check if it's possible to launch such vessel
            bool cant_launch    = false;
            var  preFlightCheck = new PreFlightCheck(new Callback(() => cant_launch = false), new Callback(() => cant_launch = true));

            preFlightCheck.AddTest(new PreFlightTests.ExperimentalPartsAvailable(construct));
            preFlightCheck.RunTests();
            //cleanup loaded parts and try to store construct
            if (cant_launch)
            {
                construct.Unload();
            }
            else
            {
                StartCoroutine(delayed_process_construct(construct));
            }
        }
Beispiel #2
0
        public PreFlightCheck NewPreflightCheck(string launchSiteName)
        {
            //Log.Normal("using injected call");

            PreFlightCheck check = (PreFlightCheck)CustomPreLaunchChecks.preFlightCheckDetour.CallOriginal(EditorLogic.fetch, new object[] { launchSiteName });

            // Spawn the launchSite before we use it


            foreach (var lsCheck in CustomPreLaunchChecks.allChecks)
            {
                check.AddTest(lsCheck.Invoke(launchSiteName));
            }

            return(check);
        }
Beispiel #3
0
            public void RunPreFlightChecks()
            {
                var checks = new PreFlightCheck(
                    () => { preFlightChecksComplete = true; },
                    () => error = "Failed to launch vessel. Did not pass pre-flight checks.");
                var gameVars = GameVariables.Instance;

                checks.AddTest(new CraftWithinPartCountLimit(template, facility, gameVars.GetPartCountLimit(facilityLevel, isPad)));
                checks.AddTest(new CraftWithinSizeLimits(template, site, gameVars.GetCraftSizeLimit(siteLevel, isPad)));
                checks.AddTest(new CraftWithinMassLimits(template, site, gameVars.GetCraftMassLimit(siteLevel, isPad)));
                checks.AddTest(new ExperimentalPartsAvailable(manifest));
                checks.AddTest(new CanAffordLaunchTest(template, Funding.Instance));
                var launchSite = LaunchSite;

                checks.AddTest(new FacilityOperational(launchSite, launchSite));
                checks.AddTest(new NoControlSources(manifest));
                checks.RunTests();
            }
Beispiel #4
0
        void vessel_selected(string filename, string flagname)
        {
            EditorLogic EL = EditorLogic.fetch;

            if (EL == null)
            {
                return;
            }
            //load vessel config
            vessel_selector = null;
            PackedConstruct pc = new PackedConstruct(filename, flagname);

            if (pc.construct == null)
            {
                Utils.Log("PackedConstruct: unable to load ShipConstruct from {0}. " +
                          "This usually means that some parts are missing " +
                          "or some modules failed to initialize.", filename);
                ScreenMessager.showMessage(string.Format("Unable to load {0}", filename), 3);
                return;
            }
            //check if the construct contains launch clamps
            if (Utils.HasLaunchClamp(pc.construct))
            {
                ScreenMessager.showMessage(string.Format("{0} has launch clamps. Remove them before storing.", pc.name), 3);
                pc.UnloadConstruct();
                return;
            }
            //check if it's possible to launch such vessel
            bool           cant_launch    = false;
            PreFlightCheck preFlightCheck = new PreFlightCheck(new Callback(() => cant_launch = false), new Callback(() => cant_launch = true));

            preFlightCheck.AddTest(new PreFlightTests.ExperimentalPartsAvailable(pc.construct));
            preFlightCheck.RunTests();
            pc.UnloadConstruct();
            //cleanup loaded parts and try to store construct
            if (cant_launch)
            {
                return;
            }
            if (try_store_construct(pc))
            {
                change_part_params(pc.metric);
            }
        }
Beispiel #5
0
        private void LaunchShip(CraftTemplate ship, string launchSiteName)
        {
            // From EditorLogic, see launchVessel(), proceedWithVesselLaunch(), and goForLaunch()
            var manifest = VesselCrewManifest.FromConfigNode(ship.InnerTemplate.config);

            manifest = HighLogic.CurrentGame.CrewRoster.DefaultCrewForVessel(ship.InnerTemplate.config, manifest);
            PreFlightCheck preFlightCheck = new PreFlightCheck(
                () =>
            {
                SafeHouse.Logger.Log("Launch new vessel!");
                FlightDriver.StartWithNewLaunch(ship.FilePath, EditorLogic.FlagURL, launchSiteName, manifest);
            },
                () =>
            {
                SafeHouse.Logger.LogError("Could not launch vessel, did not pass preflight...");
            });

            if (launchSiteName.Equals("runway", System.StringComparison.OrdinalIgnoreCase))
            {
                preFlightCheck.AddTest(new CraftWithinPartCountLimit(ship.InnerTemplate, SpaceCenterFacility.SpaceplaneHangar, GameVariables.Instance.GetPartCountLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.SpaceplaneHangar), false)));
                preFlightCheck.AddTest(new CraftWithinSizeLimits(ship.InnerTemplate, SpaceCenterFacility.Runway, GameVariables.Instance.GetCraftSizeLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Runway), false)));
                preFlightCheck.AddTest(new CraftWithinMassLimits(ship.InnerTemplate, SpaceCenterFacility.Runway, (double)GameVariables.Instance.GetCraftMassLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Runway), false)));
            }
            else if (launchSiteName.Equals("launchpad", System.StringComparison.OrdinalIgnoreCase))
            {
                preFlightCheck.AddTest(new CraftWithinPartCountLimit(ship.InnerTemplate, SpaceCenterFacility.VehicleAssemblyBuilding, GameVariables.Instance.GetPartCountLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.VehicleAssemblyBuilding), true)));
                preFlightCheck.AddTest(new CraftWithinSizeLimits(ship.InnerTemplate, SpaceCenterFacility.LaunchPad, GameVariables.Instance.GetCraftSizeLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.LaunchPad), true)));
                preFlightCheck.AddTest(new CraftWithinMassLimits(ship.InnerTemplate, SpaceCenterFacility.LaunchPad, (double)GameVariables.Instance.GetCraftMassLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.LaunchPad), true)));
            }
            else
            {
                throw new KOSException("Failed to lauch vessel, unrecognized lauch site: " + launchSiteName + ". Expected \"Runway\" or \"LaunchPad\".");
            }
            preFlightCheck.AddTest(new ExperimentalPartsAvailable(manifest));
            preFlightCheck.AddTest(new CanAffordLaunchTest(ship.InnerTemplate, Funding.Instance));
            preFlightCheck.AddTest(new FacilityOperational(launchSiteName, launchSiteName));
            preFlightCheck.AddTest(new NoControlSources(manifest));
            preFlightCheck.AddTest(new LaunchSiteClear(launchSiteName, launchSiteName, HighLogic.CurrentGame));
            preFlightCheck.RunTests();
            shared.Cpu.GetCurrentOpcode().AbortProgram = true;
            SafeHouse.Logger.Log("Craft waiting for preflight checks!");
        }
Beispiel #6
0
            // This should avoid a vessel being recovered and then the next vessel failing to launch
            public PreFlightCheck RunPreFlightChecks()
            {
                var preFlightCheck = new PreFlightCheck(
                    () => {
                    preFlightComplete = true;
                },
                    () => error = "Failed to launch vessel. Did not pass pre-flight checks.");
                var gameVars = GameVariables.Instance;

                preFlightCheck.AddTest(new CraftWithinPartCountLimit(template, facility, gameVars.GetPartCountLimit(facilityLevel, isPad)));
                preFlightCheck.AddTest(new CraftWithinSizeLimits(template, site, gameVars.GetCraftSizeLimit(siteLevel, isPad)));
                preFlightCheck.AddTest(new CraftWithinMassLimits(template, site, gameVars.GetCraftMassLimit(siteLevel, isPad)));
                preFlightCheck.AddTest(new ExperimentalPartsAvailable(manifest));
                preFlightCheck.AddTest(new CanAffordLaunchTest(template, Funding.Instance));
                var launchSite = LaunchSite;

                preFlightCheck.AddTest(new FacilityOperational(launchSite, launchSite));
                preFlightCheck.AddTest(new NoControlSources(manifest));
                if (!Recover)
                {
                    preFlightCheck.AddTest(Compatibility.NewLaunchSiteClear(launchSite, HighLogic.CurrentGame));
                }
                return(preFlightCheck);
            }
 void vessel_selected(string filename, string flagname)
 {
     EditorLogic EL = EditorLogic.fetch;
     if(EL == null) return;
     //load vessel config
     vessel_selector = null;
     var pc = new PackedConstruct(filename, flagname);
     if(pc.construct == null)
     {
         Utils.Log("PackedConstruct: unable to load ShipConstruct from {0}. " +
             "This usually means that some parts are missing " +
             "or some modules failed to initialize.", filename);
         ScreenMessager.showMessage("Unable to load {0}", filename);
         return;
     }
     //check if the construct contains launch clamps
     if(Utils.HasLaunchClamp(pc.construct))
     {
         ScreenMessager.showMessage("\"{0}\" has launch clamps. Remove them before storing.", pc.name);
         pc.UnloadConstruct();
         return;
     }
     //check if it's possible to launch such vessel
     bool cant_launch = false;
     var preFlightCheck = new PreFlightCheck(new Callback(() => cant_launch = false), new Callback(() => cant_launch = true));
     preFlightCheck.AddTest(new PreFlightTests.ExperimentalPartsAvailable(pc.construct));
     preFlightCheck.RunTests();
     //cleanup loaded parts and try to store construct
     if(cant_launch) pc.UnloadConstruct();
     else StartCoroutine(delayed_try_store_construct(pc));
 }
 public static void OnButtonInput()
 {
     checks = new PreFlightCheck(Complete, Abort);
     checks.AddTest(new CrewCheck());
     checks.RunTests();
 }
Beispiel #9
0
 private void LaunchShip(CraftTemplate ship, string launchSiteName)
 {
     // From EditorLogic, see launchVessel(), proceedWithVesselLaunch(), and goForLaunch()
     var manifest = VesselCrewManifest.FromConfigNode(ship.InnerTemplate.config);
     manifest = HighLogic.CurrentGame.CrewRoster.DefaultCrewForVessel(ship.InnerTemplate.config, manifest);
     PreFlightCheck preFlightCheck = new PreFlightCheck(
         () =>
         {
             SafeHouse.Logger.Log("Launch new vessel!");
             FlightDriver.StartWithNewLaunch(ship.FilePath, EditorLogic.FlagURL, launchSiteName, manifest);
         },
         () =>
         {
             SafeHouse.Logger.LogError("Could not launch vessel, did not pass preflight...");
         });
     if (launchSiteName.Equals("runway", System.StringComparison.OrdinalIgnoreCase))
     {
         preFlightCheck.AddTest(new CraftWithinPartCountLimit(ship.InnerTemplate, SpaceCenterFacility.SpaceplaneHangar, GameVariables.Instance.GetPartCountLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.SpaceplaneHangar), false)));
         preFlightCheck.AddTest(new CraftWithinSizeLimits(ship.InnerTemplate, SpaceCenterFacility.Runway, GameVariables.Instance.GetCraftSizeLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Runway), false)));
         preFlightCheck.AddTest(new CraftWithinMassLimits(ship.InnerTemplate, SpaceCenterFacility.Runway, (double)GameVariables.Instance.GetCraftMassLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Runway), false)));
     }
     else if (launchSiteName.Equals("launchpad", System.StringComparison.OrdinalIgnoreCase))
     {
         preFlightCheck.AddTest(new CraftWithinPartCountLimit(ship.InnerTemplate, SpaceCenterFacility.VehicleAssemblyBuilding, GameVariables.Instance.GetPartCountLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.VehicleAssemblyBuilding), true)));
         preFlightCheck.AddTest(new CraftWithinSizeLimits(ship.InnerTemplate, SpaceCenterFacility.LaunchPad, GameVariables.Instance.GetCraftSizeLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.LaunchPad), true)));
         preFlightCheck.AddTest(new CraftWithinMassLimits(ship.InnerTemplate, SpaceCenterFacility.LaunchPad, (double)GameVariables.Instance.GetCraftMassLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.LaunchPad), true)));
     }
     else
     {
         throw new KOSException("Failed to lauch vessel, unrecognized lauch site: " + launchSiteName + ". Expected \"Runway\" or \"LaunchPad\".");
     }
     preFlightCheck.AddTest(new ExperimentalPartsAvailable(manifest));
     preFlightCheck.AddTest(new CanAffordLaunchTest(ship.InnerTemplate, Funding.Instance));
     preFlightCheck.AddTest(new FacilityOperational(launchSiteName, launchSiteName));
     preFlightCheck.AddTest(new NoControlSources(manifest));
     preFlightCheck.AddTest(new LaunchSiteClear(launchSiteName, HighLogic.CurrentGame));
     preFlightCheck.RunTests();
     shared.Cpu.GetCurrentOpcode().AbortProgram = true;
     SafeHouse.Logger.Log("Craft waiting for preflight checks!");
 }
 public static void OnButtonInput()
 {
     checks = new PreFlightCheck(Complete, Abort);
     checks.AddTest(new CrewCheck());
     checks.RunTests();
 }