Пример #1
0
        public static void BackgroundUpdate(Vessel v, ProtoPartModuleSnapshot m, Experiment experiment, Resource_info ec, Vessel_resources resources, double elapsed_s)
        {
            bool   didPrepare          = Lib.Proto.GetBool(m, "didPrepare", false);
            bool   shrouded            = Lib.Proto.GetBool(m, "shrouded", false);
            string last_subject_id     = Lib.Proto.GetString(m, "last_subject_id", "");
            double remainingSampleMass = Lib.Proto.GetDouble(m, "remainingSampleMass", 0);
            bool   broken      = Lib.Proto.GetBool(m, "broken", false);
            bool   forcedRun   = Lib.Proto.GetBool(m, "forcedRun", false);
            bool   recording   = Lib.Proto.GetBool(m, "recording", false);
            uint   privateHdId = Lib.Proto.GetUInt(m, "privateHdId", 0);

            string issue = TestForIssues(v, ec, experiment, privateHdId, broken,
                                         remainingSampleMass, didPrepare, shrouded, last_subject_id);

            if (string.IsNullOrEmpty(issue))
            {
                issue = TestForResources(v, KerbalismProcess.ParseResources(experiment.resources), elapsed_s, resources);
            }

            Lib.Proto.Set(m, "issue", issue);

            if (!string.IsNullOrEmpty(issue))
            {
                return;
            }

            var subject_id = Science.Generate_subject_id(experiment.experiment_id, v);

            Lib.Proto.Set(m, "last_subject_id", subject_id);

            double dataSampled = Lib.Proto.GetDouble(m, "dataSampled");

            if (last_subject_id != subject_id)
            {
                dataSampled = 0;
                Lib.Proto.Set(m, "forcedRun", false);
            }

            double scienceValue = Science.Value(last_subject_id);

            Lib.Proto.Set(m, "scienceValue", scienceValue);

            var state = GetState(scienceValue, issue, recording, forcedRun);

            if (state != State.RUNNING)
            {
                return;
            }
            if (dataSampled >= Science.Experiment(subject_id).max_amount)
            {
                return;
            }

            var stored = DoRecord(experiment, subject_id, v, ec, privateHdId,
                                  resources, KerbalismProcess.ParseResources(experiment.resources),
                                  remainingSampleMass, dataSampled, out dataSampled, out remainingSampleMass);

            if (!stored)
            {
                Lib.Proto.Set(m, "issue", insufficient_storage);
            }

            Lib.Proto.Set(m, "dataSampled", dataSampled);
            Lib.Proto.Set(m, "remainingSampleMass", remainingSampleMass);
        }
Пример #2
0
        // specifics support
        public Specifics Specs()
        {
            var specs = new Specifics();
            var exp   = Science.Experiment(experiment_id);

            if (exp == null)
            {
                specs.Add(Localizer.Format("#KERBALISM_ExperimentInfo_Unknown"));
                return(specs);
            }

            specs.Add(Lib.BuildString("<b>", exp.name, "</b>"));
            if (!string.IsNullOrEmpty(experiment_desc))
            {
                specs.Add(Lib.BuildString("<i>", experiment_desc, "</i>"));
            }

            specs.Add(string.Empty);
            double expSize = exp.max_amount;

            if (sample_mass < float.Epsilon)
            {
                specs.Add("Data", Lib.HumanReadableDataSize(expSize));
                specs.Add("Data rate", Lib.HumanReadableDataRate(data_rate));
                specs.Add("Duration", Lib.HumanReadableDuration(expSize / data_rate));
            }
            else
            {
                specs.Add("Sample size", Lib.HumanReadableSampleSize(expSize));
                specs.Add("Sample mass", Lib.HumanReadableMass(sample_mass));
                if (!sample_collecting && Math.Abs(sample_reservoir - sample_mass) > double.Epsilon && sample_mass > double.Epsilon)
                {
                    specs.Add("Experiments", "" + Math.Round(sample_reservoir / sample_mass, 0));
                }
                specs.Add("Duration", Lib.HumanReadableDuration(expSize / data_rate));
            }

            List <string> situations = exp.Situations();

            if (situations.Count > 0)
            {
                specs.Add(string.Empty);
                specs.Add("<color=#00ffff>Situations:</color>", string.Empty);
                foreach (string s in situations)
                {
                    specs.Add(Lib.BuildString("• <b>", s, "</b>"));
                }
            }

            specs.Add(string.Empty);
            specs.Add("<color=#00ffff>Needs:</color>");

            specs.Add("EC", Lib.HumanReadableRate(ec_rate));
            foreach (var p in KerbalismProcess.ParseResources(resources))
            {
                specs.Add(p.Key, Lib.HumanReadableRate(p.Value));
            }

            if (crew_prepare.Length > 0)
            {
                var cs = new CrewSpecs(crew_prepare);
                specs.Add("Preparation", cs ? cs.Info() : "none");
            }
            if (crew_operate.Length > 0)
            {
                var cs = new CrewSpecs(crew_operate);
                specs.Add("Operation", cs ? cs.Info() : "unmanned");
            }
            if (crew_reset.Length > 0)
            {
                var cs = new CrewSpecs(crew_reset);
                specs.Add("Reset", cs ? cs.Info() : "none");
            }

            if (!string.IsNullOrEmpty(requires))
            {
                specs.Add(string.Empty);
                specs.Add("<color=#00ffff>Requires:</color>", string.Empty);
                var tokens = Lib.Tokenize(requires, ',');
                foreach (string s in tokens)
                {
                    specs.Add(Lib.BuildString("• <b>", Science.RequirementText(s), "</b>"));
                }
            }

            return(specs);
        }
Пример #3
0
        public override void OnStart(StartState state)
        {
            // don't break tutorial scenarios
            if (Lib.DisableScenario(this))
            {
                return;
            }

            // initialize the remaining sample mass in case it was not configured in the cfg.
            if (remainingSampleMass < float.Epsilon && string.IsNullOrEmpty(issue) && !sample_collecting)
            {
                remainingSampleMass = sample_mass;
                if (sample_reservoir > float.Epsilon)
                {
                    remainingSampleMass = sample_reservoir;
                }
            }

            // create animators
            deployAnimator          = new Animator(part, anim_deploy);
            deployAnimator.reversed = anim_deploy_reverse;

            loopAnimator          = new Animator(part, anim_loop);
            loopAnimator.reversed = anim_loop_reverse;

            // set initial animation states
            deployAnimator.Still(recording ? 1.0 : 0.0);
            loopAnimator.Still(recording ? 1.0 : 0.0);
            if (recording)
            {
                loopAnimator.Play(false, true);
            }

            // parse crew specs
            if (!string.IsNullOrEmpty(crew_operate))
            {
                operator_cs = new CrewSpecs(crew_operate);
            }
            if (!string.IsNullOrEmpty(crew_reset))
            {
                reset_cs = new CrewSpecs(crew_reset);
            }
            if (!string.IsNullOrEmpty(crew_prepare))
            {
                prepare_cs = new CrewSpecs(crew_prepare);
            }

            resourceDefs = KerbalismProcess.ParseResources(resources);

            foreach (var hd in part.FindModulesImplementing <HardDrive>())
            {
                if (hd.experiment_id == experiment_id)
                {
                    privateHdId = part.flightID;
                }
            }

            Events["Toggle"].guiActiveUncommand = true;
            Events["Toggle"].externalToEVAOnly  = true;
            Events["Toggle"].requireFullControl = false;

            Events["Prepare"].guiActiveUncommand = true;
            Events["Prepare"].externalToEVAOnly  = true;
            Events["Prepare"].requireFullControl = false;

            Events["Reset"].guiActiveUncommand = true;
            Events["Reset"].externalToEVAOnly  = true;
            Events["Reset"].requireFullControl = false;
        }