Example #1
0
        private void SetStatusText()
        {
            switch (status)
            {
            case Status.DISABLED:
                status_txt = localized_disabled;
                break;

            case Status.NO_EC:
                status_txt = localized_noEC;
                break;

            case Status.NO_STORAGE:
                status_txt = localized_noStorage;
                break;

            case Status.NO_RESEARCHER:
                status_txt = Lib.Color("yellow", researcher_cs.Warning());
                break;

            case Status.NO_SAMPLE:
                status_txt = localized_noSample;
                break;

            case Status.RUNNING:
                status_txt = Lib.Color("green", Science.Experiment(current_sample).name);
                break;
            }
        }
        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);
        }
Example #3
0
        private void SetStatusText()
        {
            switch (status)
            {
            case Status.DISABLED:
                status_txt = localized_disabled;
                break;

            case Status.NO_EC:
                status_txt = localized_noEC;
                break;

            case Status.NO_STORAGE:
                status_txt = localized_noStorage;
                break;

            case Status.NO_RESEARCHER:
                status_txt = Lib.Color(researcher_cs.Warning(), Lib.Kolor.Orange);
                break;

            case Status.NO_SAMPLE:
                status_txt = localized_noSample;
                break;

            case Status.RUNNING:
                status_txt = Lib.Color(current_sample.FullTitle, Lib.Kolor.Green);
                break;
            }
        }
        [KSPEvent(guiActive = true, guiActiveUnfocused = true, guiActiveEditor = true, guiName = "_", active = false, groupName = "Configuration", groupDisplayName = "#KERBALISM_Group_Configuration")]        //Configuration
        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(Local.Configure_noconfigure, reconfigure_cs.Warning());
                    return;
                }

                // warn the user about potential resource loss
                if (Resource_loss())
                {
                    Message.Post(Severity.warning, Local.Configure_dumpexcess);
                }
            }

            // open the window
            UI.Open(Window_body);
        }
Example #5
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!"
                )
                );
        }
Example #6
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!"
                )
                );
        }
Example #7
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);
            }
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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"
                )
            );
        }
Example #11
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";
            }
        }
Example #12
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!"
                    )
                );
            }
        }