Beispiel #1
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, page.xmitDataScalar);

                if (meta.subjectData == null)
                {
                    continue;
                }

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

                bool recorded       = false;
                bool partial_record = false;

                if (!meta.is_sample)
                {
                    var remaining = RecordData(data, meta);
                    if (remaining > 0)
                    {
                        partial_record = true;
                    }
                    recorded = remaining < data.dataAmount;
                }
                else
                {
                    Drive drive = Drive.SampleDrive(meta.vessel.KerbalismData(), data.dataAmount, meta.subjectData);
                    if (drive != null)
                    {
                        recorded = drive.Record_sample(meta.subjectData, data.dataAmount, meta.subjectData.ExpInfo.MassPerMB * data.dataAmount, true);
                    }
                }

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

                        // inform the user
                        Message.Post(
                            Lib.BuildString("<b>", meta.subjectData.FullTitle, "</b> recorded"),
                            !meta.is_rerunnable ? Local.Science_inoperable : string.Empty
                            );
                    }

                    // dump the data
                    page.OnDiscardData(data);
                }
                else
                {
                    Message.Post(
                        Lib.Color(Lib.BuildString(meta.subjectData.FullTitle, " can not be stored"), Lib.Kolor.Red),
                        "Not enough space on hard drive"
                        );
                }
            }

            // dismiss the dialog
            dialog.Dismiss();
        }
Beispiel #2
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 (meta.subjectData == null)
            {
                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;
            bool partial_record = false;

            if (!meta.is_sample)
            {
                var remaining = MiniHijacker.RecordData(data, meta);
                if (remaining > 0)
                {
                    partial_record = true;
                }
                recorded = remaining < data.dataAmount;
            }
            else
            {
                Drive drive = Drive.SampleDrive(meta.vessel.KerbalismData(), data.dataAmount, meta.subjectData);
                if (drive != null)
                {
                    recorded = drive.Record_sample(meta.subjectData, data.dataAmount, meta.subjectData.ExpInfo.MassPerMB * data.dataAmount, true);
                }
            }

            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 && !partial_record)
                {
                    meta.experiment.SetInoperable();
                }

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

                if (!partial_record)
                {
                    // inform the user
                    Message.Post(
                        Lib.BuildString("<b>", meta.subjectData.FullTitle, "</b> recorded"),
                        !meta.is_rerunnable ? Localizer.Format("#KERBALISM_Science_inoperable") : string.Empty
                        );
                }
            }
            else
            {
                Message.Post(
                    Lib.Color(Lib.BuildString(meta.subjectData.FullTitle, " can not be stored"), Lib.Kolor.Red),
                    "Not enough space on hard drive"
                    );
            }
        }