예제 #1
0
        public override void OnStart(StartState state)
        {
            // don't break tutorial scenarios
            if (Lib.DisableScenario(this))
            {
                return;
            }

            // set UI text
            Actions["Action"].guiName          = Localizer.Format("#KERBALISM_Laboratory_Action");
            Events["CleanExperiments"].guiName = Localizer.Format("#KERBALISM_Laboratory_Clean");

            // do nothing in the editors and when compiling parts
            if (!Lib.IsFlight())
            {
                return;
            }

            // parse crew specs
            researcher_cs = new CrewSpecs(researcher);

            var hardDrive = part.FindModuleImplementing <HardDrive>();

            if (hardDrive != null)
            {
                drive = hardDrive.GetDrive();
            }
            else
            {
                drive = Drive.FileDrive(vessel);
            }
        }
예제 #2
0
파일: API.cs 프로젝트: valerian/Kerbalism
 // store a file on a vessel
 public static bool StoreFile(Vessel v, string subject_id, double amount)
 {
     if (!Cache.VesselInfo(v).is_valid)
     {
         return(false);
     }
     return(Drive.FileDrive(v, amount).Record_file(subject_id, amount));
 }
예제 #3
0
        private static Drive GetDrive(Experiment experiment, Vessel vessel, uint hdId, double chunkSize, string subject_id)
        {
            bool  isFile = experiment.sample_mass < float.Epsilon;
            Drive drive  = null;

            if (hdId != 0)
            {
                drive = DB.Drive(hdId);
            }
            else
            {
                drive = isFile ? Drive.FileDrive(vessel, chunkSize) : Drive.SampleDrive(vessel, chunkSize, subject_id);
            }
            return(drive);
        }
예제 #4
0
        // analyze a sample
        private static Status Analyze(Vessel v, SubjectData subject, double amount)
        {
            Sample sample      = null;
            Drive  sampleDrive = null;

            foreach (var d in Drive.GetDrives(v, true))
            {
                if (d.samples.ContainsKey(subject) && d.samples[subject].analyze)
                {
                    sample      = d.samples[subject];
                    sampleDrive = d;
                    break;
                }
            }

            bool completed = false;

            if (sample != null)
            {
                completed = amount > sample.size;
                amount    = Math.Min(amount, sample.size);
            }

            Drive fileDrive = Drive.FileDrive(v.KerbalismData(), amount);

            if (fileDrive == null)
            {
                return(Status.NO_STORAGE);
            }

            if (sample != null)
            {
                bool recorded = fileDrive.Record_file(subject, amount, false);

                double massRemoved = 0.0;
                if (recorded)
                {
                    massRemoved = sampleDrive.Delete_sample(subject, amount);
                }
                else
                {
                    Message.Post(
                        Lib.Color(Lib.BuildString(Localizer.Format("#KERBALISM_Laboratory_Analysis"), " stopped"), Lib.Kolor.Red),
                        "Not enough space on hard drive"
                        );

                    return(Status.NO_STORAGE);
                }

                // return sample mass to experiment if needed
                if (massRemoved > 0.0)
                {
                    RestoreSampleMass(v, subject, massRemoved);
                }
            }

            // if the analysis is completed
            if (completed)
            {
                if (!PreferencesScience.Instance.analyzeSamples)
                {
                    // only inform the user if auto-analyze is turned off
                    // otherwise we could be spamming "Analysis complete" messages
                    Message.Post(Lib.BuildString(Lib.Color(Localizer.Format("#KERBALISM_Laboratory_Analysis"), Lib.Kolor.Science, true), "\n",
                                                 Localizer.Format("#KERBALISM_Laboratory_Analyzed", Lib.Bold(v.vesselName), Lib.Bold(subject.FullTitle))), localized_results);
                }

                if (PreferencesScience.Instance.transmitScience)
                {
                    fileDrive.Send(subject.Id, true);
                }

                // record landmark event
                if (!Lib.Landed(v))
                {
                    DB.landmarks.space_analysis = true;
                }
            }

            return(Status.RUNNING);
        }
예제 #5
0
        void Record(MetaData meta, ScienceData data, bool send)
        {
            // if amount is zero, warn the user and do nothing else
            if (data.dataAmount <= double.Epsilon)
            {
                Message.Post("There is no more useful data here");
                return;
            }

            // if this is a sample and we are trying to send it, warn the user and do nothing else
            if (meta.is_sample && send)
            {
                Message.Post("We can't transmit a sample", "It needs to be recovered, or analyzed in a lab");
                return;
            }

            // record data in the drive
            bool recorded = false;

            if (!meta.is_sample)
            {
                Drive drive = Drive.FileDrive(meta.vessel, data.dataAmount);
                recorded = drive.Record_file(data.subjectID, data.dataAmount);
            }
            else
            {
                Drive drive = Drive.SampleDrive(meta.vessel, data.dataAmount, data.subjectID);

                var experimentInfo = Science.Experiment(data.subjectID);
                var sampleMass     = Science.GetSampleMass(data.subjectID);
                var mass           = sampleMass / experimentInfo.max_amount * data.dataAmount;

                recorded = drive.Record_sample(data.subjectID, data.dataAmount, mass);
            }

            if (recorded)
            {
                // flag for sending if specified
                if (!meta.is_sample && send)
                {
                    foreach (var d in Drive.GetDrives(meta.vessel))
                    {
                        d.Send(data.subjectID, true);
                    }
                }

                // render experiment inoperable if necessary
                if (!meta.is_rerunnable)
                {
                    meta.experiment.SetInoperable();
                }

                // dismiss the dialog and popups
                Dismiss(data);

                var exp = Science.Experiment(data.subjectID);
                // inform the user
                Message.Post(
                    Lib.BuildString("<b>", exp.FullName(data.subjectID), "</b> recorded"),
                    !meta.is_rerunnable ? Localizer.Format("#KERBALISM_Science_inoperable") : string.Empty
                    );
            }
            else
            {
                var exp = Science.Experiment(data.subjectID);
                Message.Post(
                    Lib.Color("red", Lib.BuildString(exp.FullName(data.subjectID), " can not be stored")),
                    "Not enough space on hard drive"
                    );
            }
        }
예제 #6
0
        void Start()
        {
            // get dialog
            dialog = gameObject.GetComponentInParent <ExperimentsResultDialog>();
            if (dialog == null)
            {
                Destroy(gameObject); return;
            }

            // prevent rendering
            dialog.gameObject.SetActive(false);

            // for each page
            // - some mod may collect multiple experiments at once
            while (dialog.pages.Count > 0)
            {
                // get page
                var page = dialog.pages[0];

                // get science data
                ScienceData data = page.pageData;

                // collect and deduce all info necessary
                MetaData meta = new MetaData(data, page.host);

                // ignore non-collectable experiments
                if (!meta.is_collectable)
                {
                    page.OnKeepData(data);
                    continue;
                }

                // record data
                bool recorded = false;
                if (!meta.is_sample)
                {
                    Drive drive = Drive.FileDrive(meta.vessel, data.dataAmount);
                    recorded = drive.Record_file(data.subjectID, data.dataAmount);
                }
                else
                {
                    Drive drive = Drive.SampleDrive(meta.vessel, data.dataAmount, data.subjectID);

                    var experimentInfo = Science.Experiment(data.subjectID);
                    var sampleMass     = Science.GetSampleMass(data.subjectID);
                    var mass           = sampleMass / experimentInfo.max_amount * data.dataAmount;

                    recorded = drive.Record_sample(data.subjectID, data.dataAmount, mass);
                }

                if (recorded)
                {
                    // render experiment inoperable if necessary
                    if (!meta.is_rerunnable)
                    {
                        meta.experiment.SetInoperable();
                    }

                    // dump the data
                    page.OnDiscardData(data);

                    // inform the user
                    var exp = Science.Experiment(data.subjectID);
                    Message.Post(
                        Lib.BuildString("<b>", exp.FullName(data.subjectID), "</b> recorded"),
                        !meta.is_rerunnable ? Localizer.Format("#KERBALISM_Science_inoperable") : string.Empty
                        );
                }
                else
                {
                    var exp = Science.Experiment(data.subjectID);
                    Message.Post(
                        Lib.Color("red", Lib.BuildString(exp.FullName(data.subjectID), " can not be stored")),
                        "Not enough space on hard drive"
                        );
                }
            }

            // dismiss the dialog
            dialog.Dismiss();
        }