Ejemplo n.º 1
0
        public void Update()
        {
            // in flight
            if (Lib.IsFlight())
            {
                // get info from cache
                Vessel_info vi = Cache.VesselInfo(vessel);

                // do nothing if vessel is invalid
                if (!vi.is_valid)
                {
                    return;
                }

                // update ui
                bool has_operator = operator_cs.Check(vessel);
                Events["Toggle"].guiName = Lib.StatusToggle(exp_name, !recording ? "stopped" : issue.Length == 0 ? "recording" : Lib.BuildString("<color=#ffff00>", issue, "</color>"));
            }
            // in the editor
            else if (Lib.IsEditor())
            {
                // update ui
                Events["Toggle"].guiName = Lib.StatusToggle(exp_name, recording ? "recording" : "stopped");
            }
        }
Ejemplo n.º 2
0
        public void ToggleWindow()
        {
            // in flight
            if (Lib.IsFlight())
            {
                // disable for dead eva kerbals
                Vessel v = FlightGlobals.ActiveVessel;
                if (v == null || EVA.IsDead(v))
                {
                    return;
                }

                // check trait
                if (!reconfigure_cs.Check(v))
                {
                    Message.Post(Localizer.Format("#KERBALISM_Configure_noconfigure"), reconfigure_cs.Warning());
                    return;
                }

                // warn the user about potential resource loss
                if (Resource_loss())
                {
                    Message.Post(Severity.warning, Localizer.Format("#KERBALISM_Configure_dumpexcess"));
                }
            }

            // open the window
            UI.Open(Window_body);
        }
Ejemplo n.º 3
0
        public void ToggleWindow()
        {
            // in flight
            if (Lib.IsFlight())
            {
                // disable for dead eva kerbals
                Vessel v = FlightGlobals.ActiveVessel;
                if (v == null || EVA.IsDead(v))
                {
                    return;
                }

                // check trait
                if (!reconfigure_cs.Check(v))
                {
                    Message.Post("Can't reconfigure the component", reconfigure_cs.Warning());
                    return;
                }

                // warn the user about potential resource loss
                if (Resource_Loss())
                {
                    Message.Post(Severity.warning, "Reconfiguring will dump resources in excess of capacity.");
                }
            }

            // open the window
            UI.Open(Window_Body);
        }
Ejemplo n.º 4
0
        public static void BackgroundUpdate(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot m, Laboratory lab, Resource_Info ec, double elapsed_s)
        {
            // if enabled
            if (Lib.Proto.GetBool(m, "running"))
            {
                // if a researcher is not required, or the researcher is present
                CrewSpecs researcher_cs = new CrewSpecs(lab.researcher);
                int       qtty = 0, crewlvl = 0;
                if (!researcher_cs || researcher_cs.Check(p.protoModuleCrew, out qtty, out crewlvl))
                {
                    // get sample to analyze
                    string sample_filename = Next_sample(v);

                    // if there is a sample to analyze
                    if (sample_filename.Length > 0)
                    {
                        // consume EC
                        ec.Consume(lab.ec_rate * elapsed_s);

                        // if there was ec
                        // - comparing against amount in previous simulation step
                        if (ec.amount > double.Epsilon)
                        {
                            double analysis_rateAVG = lab.analysis_rate;
                            if (researcher_cs)
                            {
                                analysis_rateAVG *= qtty * crewlvl;
                            }
                            // analyze the sample
                            Analyze(v, sample_filename, analysis_rateAVG * elapsed_s);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void BackgroundUpdate(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot m, Laboratory lab, Resource_info ec, double elapsed_s)
        {
            // if enabled
            if (Lib.Proto.GetBool(m, "running"))
            {
                // if a researcher is not required, or the researcher is present
                background_researcher_cs = new CrewSpecs(lab.researcher);
                if (!background_researcher_cs || background_researcher_cs.Check(p.protoModuleCrew))
                {
                    // get sample to analyze
                    background_sample = NextSample(v);

                    // if there is a sample to analyze
                    if (background_sample != null)
                    {
                        // consume EC
                        ec.Consume(lab.ec_rate * elapsed_s);

                        // if there was ec
                        // - comparing against amount in previous simulation step
                        if (ec.amount > double.Epsilon)
                        {
                            // analyze the sample
                            Analyze(v, background_sample, lab.analysis_rate * elapsed_s);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void Update()
        {
            if (Lib.IsFlight())
            {
                // get status text
                SetStatusText();
                Events["Toggle"].guiName = Lib.StatusToggle(localized_toggle, status_txt);

                // if a cleaner and either a researcher is not required, or the researcher is present
                if (cleaner && (!researcher_cs || researcher_cs.Check(part.protoModuleCrew)))
                {
                    Events["CleanExperiments"].active = true;
                }
                else
                {
                    Events["CleanExperiments"].active = false;
                }
            }
            else
            {
                Events["Toggle"].guiName = Lib.StatusToggle(localized_toggle, running ? localized_enabled : localized_disabled);
            }
        }
Ejemplo n.º 7
0
        public bool Reset(bool showMessage)
        {
            // disable for dead eva kerbals
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || EVA.IsDead(v))
            {
                return(false);
            }

            if (reset_cs == null)
            {
                return(false);
            }

            // check trait
            if (!reset_cs.Check(v))
            {
                if (showMessage)
                {
                    Message.Post(
                        Lib.TextVariant
                        (
                            "I'm not qualified for this",
                            "I will not even know where to start",
                            "I'm afraid I can't do that"
                        ),
                        reset_cs.Warning()
                        );
                }
                return(false);
            }

            last_subject_id = string.Empty;
            didPrepare      = false;

            if (showMessage)
            {
                Message.Post(
                    "Reset Done",
                    Lib.TextVariant
                    (
                        "It's good to go again",
                        "Ready for the next bit of science"
                    )
                    );
            }
            return(true);
        }
Ejemplo n.º 8
0
        public void Prepare()
        {
            // disable for dead eva kerbals
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || EVA.IsDead(v))
            {
                return;
            }

            if (prepare_cs == null)
            {
                return;
            }

            // check trait
            if (!prepare_cs.Check(v))
            {
                Message.Post(
                    Lib.TextVariant
                    (
                        "I'm not qualified for this",
                        "I will not even know where to start",
                        "I'm afraid I can't do that"
                    ),
                    reset_cs.Warning()
                    );
            }

            // generate subject id
            var sit   = ScienceUtil.GetExperimentSituation(v);
            var biome = ScienceUtil.GetExperimentBiome(vessel.mainBody, vessel.latitude, vessel.longitude);

            last_subject_id = Science.Generate_subject(exp, vessel.mainBody, sit, biome);
            didPrepare      = true;

            Message.Post(
                "Preparation Complete",
                Lib.TextVariant
                (
                    "Ready to go",
                    "Let's start doing some science!"
                )
                );
        }
Ejemplo n.º 9
0
        public static void BackgroundUpdate(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot m, Laboratory lab, Resource_info ec, double elapsed_s)
        {
            // if enabled
            if (Lib.Proto.GetBool(m, "running"))
            {
                // if a researcher is not required, or the researcher is present
                background_researcher_cs = new CrewSpecs(lab.researcher);
                if (!background_researcher_cs || background_researcher_cs.Check(p.protoModuleCrew))
                {
                    double rate = lab.analysis_rate;
                    if (background_researcher_cs)
                    {
                        int    bonus     = background_researcher_cs.Bonus(p.protoModuleCrew);
                        double crew_gain = 1 + bonus * Settings.LaboratoryCrewLevelBonus;
                        crew_gain = Lib.Clamp(crew_gain, 1, Settings.MaxLaborartoryBonus);
                        rate     *= crew_gain;
                    }

                    // get sample to analyze
                    background_sample = NextSample(v);

                    // if there is a sample to analyze
                    if (background_sample != null)
                    {
                        // consume EC
                        ec.Consume(lab.ec_rate * elapsed_s);

                        // if there was ec
                        // - comparing against amount in previous simulation step
                        if (ec.amount > double.Epsilon)
                        {
                            // analyze the sample
                            var status = Analyze(v, background_sample, rate * elapsed_s);
                            if (status != Status.RUNNING)
                            {
                                Lib.Proto.Set(m, "running", false);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void Prepare()
        {
            // disable for dead eva kerbals
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || EVA.IsDead(v))
            {
                return;
            }

            if (prepare_cs == null)
            {
                return;
            }

            // check trait
            if (!prepare_cs.Check(v))
            {
                Message.Post(
                    Lib.TextVariant
                    (
                        "I'm not qualified for this",
                        "I will not even know where to start",
                        "I'm afraid I can't do that"
                    ),
                    reset_cs.Warning()
                    );
            }

            didPrepare = true;

            Message.Post(
                "Preparation Complete",
                Lib.TextVariant
                (
                    "Ready to go",
                    "Let's start doing some science!"
                )
                );
        }
Ejemplo n.º 11
0
        public void Toggle()
        {
            if (Lib.IsFlight())
            {
                // disable for dead eva kerbals
                Vessel v = FlightGlobals.ActiveVessel;
                if (v == null || EVA.IsDead(v))
                {
                    return;
                }
                if (!deploy_cs.Check(v))
                {
                    Message.Post
                    (
                        Lib.TextVariant
                        (
                            "I don't know how this works!"
                        ),
                        deploy_cs.Warning()
                    );
                    return;
                }
            }

            // switch status
            deployed = !deployed;

            // play animation
            deploy_anim.Play(!deployed, false);

            // refresh VAB/SPH ui
            if (Lib.IsEditor())
            {
                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
            }
        }
Ejemplo n.º 12
0
        private static string TestForIssues(Vessel v, Resource_info ec, Experiment experiment, uint hdId, bool broken,
                                            double remainingSampleMass, bool didPrepare, bool isShrouded, string last_subject_id)
        {
            var subject_id = Science.Generate_subject_id(experiment.experiment_id, v);

            if (broken)
            {
                return("broken");
            }

            if (isShrouded && !experiment.allow_shrouded)
            {
                return("shrouded");
            }

            bool needsReset = experiment.crew_reset.Length > 0 &&
                              !string.IsNullOrEmpty(last_subject_id) && subject_id != last_subject_id;

            if (needsReset)
            {
                return("reset required");
            }

            if (ec.amount < double.Epsilon && experiment.ec_rate > double.Epsilon)
            {
                return("no Electricity");
            }

            if (!string.IsNullOrEmpty(experiment.crew_operate))
            {
                var cs = new CrewSpecs(experiment.crew_operate);
                if (!cs && Lib.CrewCount(v) > 0)
                {
                    return("crew on board");
                }
                else if (cs && !cs.Check(v))
                {
                    return(cs.Warning());
                }
            }

            if (!experiment.sample_collecting && remainingSampleMass < double.Epsilon && experiment.sample_mass > double.Epsilon)
            {
                return("depleted");
            }

            if (!didPrepare && !string.IsNullOrEmpty(experiment.crew_prepare))
            {
                return("not prepared");
            }

            string situationIssue = Science.TestRequirements(experiment.experiment_id, experiment.requires, v);

            if (situationIssue.Length > 0)
            {
                return(Science.RequirementText(situationIssue));
            }

            var    experimentSize = Science.Experiment(subject_id).max_amount;
            double chunkSize      = Math.Min(experiment.data_rate * Kerbalism.elapsed_s, experimentSize);
            Drive  drive          = GetDrive(experiment, v, hdId, chunkSize, subject_id);

            var    isFile    = experiment.sample_mass < double.Epsilon;
            double available = 0;

            if (isFile)
            {
                available  = drive.FileCapacityAvailable();
                available += Cache.WarpCache(v).FileCapacityAvailable();
            }
            else
            {
                available = drive.SampleCapacityAvailable(subject_id);
            }

            if (Math.Min(experiment.data_rate * Kerbalism.elapsed_s, experimentSize) > available)
            {
                return(insufficient_storage);
            }

            return(string.Empty);
        }
Ejemplo n.º 13
0
        private static string TestForIssues(Vessel v, ScienceExperiment exp, Resource_info ec, Experiment experiment, bool broken,
                                            double remainingSampleMass, bool didPrepare, bool isShrouded, string last_subject_id, out string subject_id)
        {
            var sit   = ScienceUtil.GetExperimentSituation(v);
            var biome = ScienceUtil.GetExperimentBiome(v.mainBody, v.latitude, v.longitude);

            subject_id = Science.Generate_subject(exp, v.mainBody, sit, biome);

            if (broken)
            {
                return("broken");
            }

            if (isShrouded && !experiment.allow_shrouded)
            {
                return("shrouded");
            }

            bool needsReset = experiment.crew_reset.Length > 0 &&
                              !string.IsNullOrEmpty(last_subject_id) && subject_id != last_subject_id;

            if (needsReset)
            {
                return("reset required");
            }

            if (ec.amount < double.Epsilon && experiment.ec_rate > double.Epsilon)
            {
                return("no <b>Electricity</b>");
            }

            if (!string.IsNullOrEmpty(experiment.crew_operate))
            {
                var cs = new CrewSpecs(experiment.crew_operate);
                if (!cs.Check(v))
                {
                    return(cs.Warning());
                }
            }

            if (!experiment.sample_collecting && remainingSampleMass < double.Epsilon && experiment.sample_mass > double.Epsilon)
            {
                return("depleted");
            }

            string situationIssue = Science.TestRequirements(experiment.requires, v);

            if (situationIssue.Length > 0)
            {
                return(Science.RequirementText(situationIssue));
            }

            if (!exp.IsAvailableWhile(sit, v.mainBody))
            {
                return("invalid situation");
            }

            if (!didPrepare && !string.IsNullOrEmpty(experiment.crew_prepare))
            {
                return("not prepared");
            }

            var    drive     = DB.Vessel(v).BestDrive();
            double available = experiment.sample_mass < float.Epsilon ? drive.FileCapacityAvailable() : drive.SampleCapacityAvailable();

            if (experiment.data_rate * Kerbalism.elapsed_s > available)
            {
                return("insufficient storage");
            }

            return(string.Empty);
        }
Ejemplo n.º 14
0
        public void Repair()
        {
            // disable for dead eva kerbals
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || EVA.IsDead(v))
            {
                return;
            }

            // check trait
            if (!repair_cs.Check(v))
            {
                Message.Post
                (
                    Lib.TextVariant
                    (
                        "I'm not qualified for this",
                        "I will not even know where to start",
                        "I'm afraid I can't do that"
                    ),
                    repair_cs.Warning()
                );
                return;
            }

            // flag as not broken
            broken = false;

            // reset times
            last = 0.0;
            next = 0.0;

            // re-enable module
            foreach (PartModule m in modules)
            {
                m.isEnabled = true;
                m.enabled   = true;
            }

            // we need to reconfigure the module here, because if all modules of a type
            // share the broken state, and these modules are part of a configure setup,
            // then repairing will enable all of them, messing up with the configuration
            part.FindModulesImplementing <Configure>().ForEach(k => k.DoConfigure());

            // type-specific hacks
            Apply(false);

            // notify user
            Message.Post
            (
                Lib.BuildString("<b>", title, "</b> repaired"),
                Lib.TextVariant
                (
                    "A powerkick did the trick",
                    "Duct tape, is there something it can't fix?",
                    "Fully operational again",
                    "We are back in business"
                )
            );
        }
Ejemplo n.º 15
0
        public void FixedUpdate()
        {
            // do nothing in the editor
            if (Lib.IsEditor())
            {
                return;
            }

            // if enabled
            if (running)
            {
                int qtty = 0, crewlvl = 0;
                // if a researcher is not required, or the researcher is present
                if (!researcher_cs || researcher_cs.Check(part.protoModuleCrew, out qtty, out crewlvl))
                {
                    // get next sample to analyze
                    string sample_filename = Next_sample(vessel);

                    // if there is a sample to analyze
                    if (sample_filename.Length > 0)
                    {
                        // consume EC
                        Resource_Info ec = ResourceCache.Info(vessel, "ElectricCharge");
                        ec.Consume(ec_rate * Kerbalism.elapsed_s);

                        // if there was ec
                        // - comparing against amount in previous simulation step
                        if (ec.amount > double.Epsilon)
                        {
                            analysis_rateAVG = analysis_rate;
                            if (researcher_cs)
                            {
                                analysis_rateAVG *= qtty * crewlvl;
                            }
                            // analyze the sample
                            Analyze(vessel, sample_filename, analysis_rateAVG * Kerbalism.elapsed_s);

                            //Analyze(vessel, sample_filename, analysis_rate * Kerbalism.elapsed_s);

                            // update status
                            status = Science.Experiment(sample_filename).name;
                        }
                        // if there was no ec
                        else
                        {
                            // update status
                            status = "<color=yellow>no electric charge</color>";
                        }
                    }
                    // if there is no sample to analyze
                    else
                    {
                        // update status
                        status = "no samples to analyze";
                    }
                }
                // if a researcher is required, but missing
                else
                {
                    // update status
                    status = Lib.BuildString("<color=yellow>", researcher_cs.Warning(), "</color>");
                }
            }
            // if disabled
            else
            {
                // update status
                status = "disabled";
            }
        }
Ejemplo n.º 16
0
        // repair malfunctioned component
        public void Repair()
        {
            // disable for dead eva kerbals
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || EVA.IsDead(v))
            {
                return;
            }

            // check trait
            if (!repair_cs.Check(v))
            {
                Message.Post
                (
                    Lib.TextVariant
                    (
                        "I'm not qualified for this",
                        "I will not even know where to start",
                        "I'm afraid I can't do that"
                    ),
                    repair_cs.Warning()
                );
                return;
            }

            needMaintenance   = false;
            enforce_breakdown = false;

            // reset times
            last             = 0.0;
            next             = 0.0;
            lastRunningCheck = 0;
            last_inspection  = Planetarium.GetUniversalTime();

            operation_duration = 0;
            ignitions          = 0;
            fail_duration      = 0;
            vessel.KerbalismData().ResetReliabilityStatus();

            if (broken)
            {
                // flag as not broken
                broken = false;

                // re-enable module
                foreach (PartModule m in modules)
                {
                    m.isEnabled = true;
                    m.enabled   = true;
                }

                // we need to reconfigure the module here, because if all modules of a type
                // share the broken state, and these modules are part of a configure setup,
                // then repairing will enable all of them, messing up with the configuration
                part.FindModulesImplementing <Configure>().ForEach(k => k.DoConfigure());

                // type-specific hacks
                Apply(false);

                // notify user
                Message.Post
                (
                    Lib.BuildString("<b>", title, "</b> repaired"),
                    Lib.TextVariant
                    (
                        "A powerkick did the trick.",
                        "Duct tape, is there something it can't fix?",
                        "Fully operational again.",
                        "We are back in business."
                    )
                );
            }
            else
            {
                // notify user
                Message.Post
                (
                    Lib.BuildString("<b>", title, "</b> serviced"),
                    Lib.TextVariant
                    (
                        "I don't know how this was still working.",
                        "Fastened that loose screw.",
                        "Someone forgot a toothpick in there.",
                        "As good as new!"
                    )
                );
            }
        }