Пример #1
0
 public override void OnUpdate()
 {
     issue        = Lib.Proto.GetString(protoModule, "issue");
     status       = Lib.Proto.GetEnum(protoModule, "status", Experiment.ExpStatus.Stopped);
     subject      = ScienceDB.GetSubjectData(expInfo, Lib.Proto.GetInt(protoModule, "situationId"));
     scienceValue = Experiment.ScienceValue(subject);
 }
Пример #2
0
        public static Sample Load(string integerSubjectId, ConfigNode node)
        {
            SubjectData subjectData;
            string      stockSubjectId = Lib.ConfigValue(node, "stockSubjectId", string.Empty);

            // the stock subject id is stored only if this is an asteroid sample, or a non-standard subject id
            if (stockSubjectId != string.Empty)
            {
                subjectData = ScienceDB.GetSubjectDataFromStockId(stockSubjectId);
            }
            else
            {
                subjectData = ScienceDB.GetSubjectData(integerSubjectId);
            }

            if (subjectData == null)
            {
                return(null);
            }

            double size              = Lib.ConfigValue(node, "size", 0.0);
            string resultText        = Lib.ConfigValue(node, "resultText", "");
            bool   useStockCrediting = Lib.ConfigValue(node, "useStockCrediting", false);

            Sample sample = new Sample(subjectData, size, useStockCrediting, resultText);

            sample.analyze = Lib.ConfigValue(node, "analyze", false);
            sample.mass    = Lib.ConfigValue(node, "mass", 0.0);

            return(sample);
        }
Пример #3
0
        public static File Load(string integerSubjectId, ConfigNode node)
        {
            SubjectData subjectData;
            string      stockSubjectId = Lib.ConfigValue(node, "stockSubjectId", string.Empty);

            // the stock subject id is stored only if this is an asteroid sample, or a non-standard subject id
            if (stockSubjectId != string.Empty)
            {
                subjectData = ScienceDB.GetSubjectDataFromStockId(stockSubjectId);
            }
            else
            {
                subjectData = ScienceDB.GetSubjectData(integerSubjectId);
            }

            if (subjectData == null)
            {
                return(null);
            }

            double size = Lib.ConfigValue(node, "size", 0.0);

            if (double.IsNaN(size))
            {
                Lib.LogStack($"File has a NaN size on load : {subjectData.DebugStateInfo}", Lib.LogLevel.Error);
                return(null);
            }

            string resultText        = Lib.ConfigValue(node, "resultText", "");
            bool   useStockCrediting = Lib.ConfigValue(node, "useStockCrediting", false);

            return(new File(subjectData, size, useStockCrediting, resultText));
        }
Пример #4
0
        public void FixedUpdate()
        {
            if (scanner == null)
            {
                return;
            }
            if (!Features.Science)
            {
                return;
            }

            IsScanning = SCANsat.IsScanning(scanner);
            double new_coverage = SCANsat.Coverage(sensorType, vessel.mainBody);

            if (body_name == vessel.mainBody.name && new_coverage < body_coverage)
            {
                // SCANsat sometimes reports a coverage of 0, which is wrong
                new_coverage = body_coverage;
            }

            if (vessel.mainBody.name != body_name)
            {
                body_name     = vessel.mainBody.name;
                body_coverage = new_coverage;
            }
            else
            {
                double coverage_delta = new_coverage - body_coverage;
                body_coverage = new_coverage;
                VesselData vd = vessel.KerbalismData();

                if (IsScanning)
                {
                    Situation   scanSatSituation = new Situation(vessel.mainBody.flightGlobalsIndex, ScienceSituation.InSpaceHigh);
                    SubjectData subject          = ScienceDB.GetSubjectData(expInfo, scanSatSituation);
                    if (subject == null)
                    {
                        return;
                    }

                    double size = expInfo.DataSize * coverage_delta / 100.0;                     // coverage is 0-100%
                    size += warp_buffer;
                    size  = Drive.StoreFile(vessel, subject, size);
                    if (size > double.Epsilon)
                    {
                        // we filled all drives up to the brim but were unable to store everything
                        if (warp_buffer < double.Epsilon)
                        {
                            // warp buffer is empty, so lets store the rest there
                            warp_buffer = size;
                            size        = 0;
                        }
                        else
                        {
                            // warp buffer not empty. that's ok if we didn't get new data
                            if (coverage_delta < double.Epsilon)
                            {
                                size = 0;
                            }
                            // else we're scanning too fast. stop.
                        }

                        // cancel scanning and annoy the user
                        if (size > double.Epsilon)
                        {
                            warp_buffer = 0;
                            StopScan();
                            vd.scansat_id.Add(part.flightID);
                            Message.Post(Lib.Color(Local.Scansat_Scannerhalted, Lib.Kolor.Red, true), Local.Scansat_Scannerhalted_text.Format("<b>" + vessel.vesselName + "</b>"));                            //"Scanner halted""Scanner halted on <<1>>. No storage left on vessel."
                        }
                    }
                }
                else if (vd.scansat_id.Contains(part.flightID))
                {
                    if (vd.DrivesFreeSpace / vd.DrivesCapacity > 0.9)                     // restart when 90% of capacity is available
                    {
                        StartScan();
                        vd.scansat_id.Remove(part.flightID);
                        if (vd.cfg_ec)
                        {
                            Message.Post(Local.Scansat_sensorresumed.Format("<b>" + vessel.vesselName + "</b>"));                                   //Lib.BuildString("SCANsat sensor resumed operations on <<1>>)
                        }
                    }
                }
            }
        }
Пример #5
0
        public static void BackgroundUpdate(Vessel vessel, ProtoPartSnapshot p, ProtoPartModuleSnapshot m, KerbalismScansat kerbalismScansat,
                                            Part part_prefab, VesselData vd, ResourceInfo ec, double elapsed_s)
        {
            List <ProtoPartModuleSnapshot> scanners = Cache.VesselObjectsCache <List <ProtoPartModuleSnapshot> >(vessel, "scansat_" + p.flightID);

            if (scanners == null)
            {
                scanners = Lib.FindModules(p, "SCANsat");
                if (scanners.Count == 0)
                {
                    scanners = Lib.FindModules(p, "ModuleSCANresourceScanner");
                }
                Cache.SetVesselObjectsCache(vessel, "scansat_" + p.flightID, scanners);
            }

            if (scanners.Count == 0)
            {
                return;
            }
            var scanner = scanners[0];

            bool is_scanning = Lib.Proto.GetBool(scanner, "scanning");

            if (is_scanning && kerbalismScansat.ec_rate > double.Epsilon)
            {
                ec.Consume(kerbalismScansat.ec_rate * elapsed_s, ResourceBroker.Scanner);
            }

            if (!Features.Science)
            {
                if (is_scanning && ec.Amount < double.Epsilon)
                {
                    SCANsat.StopScanner(vessel, scanner, part_prefab);
                    is_scanning = false;

                    // remember disabled scanner
                    vd.scansat_id.Add(p.flightID);

                    // give the user some feedback
                    if (vd.cfg_ec)
                    {
                        Message.Post(Local.Scansat_sensordisabled.Format("<b>" + vessel.vesselName + "</b>"));                           //Lib.BuildString("SCANsat sensor was disabled on <<1>>)
                    }
                }
                else if (vd.scansat_id.Contains(p.flightID))
                {
                    // if there is enough ec
                    // note: comparing against amount in previous simulation step
                    // re-enable at 25% EC
                    if (ec.Level > 0.25)
                    {
                        // re-enable the scanner
                        SCANsat.ResumeScanner(vessel, m, part_prefab);
                        is_scanning = true;

                        // give the user some feedback
                        if (vd.cfg_ec)
                        {
                            Message.Post(Local.Scansat_sensorresumed.Format("<b>" + vessel.vesselName + "</b>"));                               //Lib.BuildString("SCANsat sensor resumed operations on <<1>>)
                        }
                    }
                }

                // forget active scanners
                if (is_scanning)
                {
                    vd.scansat_id.Remove(p.flightID);
                }

                return;
            }             // if(!Feature.Science)

            string body_name     = Lib.Proto.GetString(m, "body_name");
            int    sensorType    = (int)Lib.Proto.GetUInt(m, "sensorType");
            double body_coverage = Lib.Proto.GetDouble(m, "body_coverage");
            double warp_buffer   = Lib.Proto.GetDouble(m, "warp_buffer");

            double new_coverage = SCANsat.Coverage(sensorType, vessel.mainBody);

            if (body_name == vessel.mainBody.name && new_coverage < body_coverage)
            {
                // SCANsat sometimes reports a coverage of 0, which is wrong
                new_coverage = body_coverage;
            }

            if (vessel.mainBody.name != body_name)
            {
                body_name     = vessel.mainBody.name;
                body_coverage = new_coverage;
            }
            else
            {
                double coverage_delta = new_coverage - body_coverage;
                body_coverage = new_coverage;

                if (is_scanning)
                {
                    ExperimentInfo expInfo = ScienceDB.GetExperimentInfo(kerbalismScansat.experimentType);
                    SubjectData    subject = ScienceDB.GetSubjectData(expInfo, vd.VesselSituations.GetExperimentSituation(expInfo));
                    if (subject == null)
                    {
                        return;
                    }

                    double size = expInfo.DataSize * coverage_delta / 100.0;                     // coverage is 0-100%
                    size += warp_buffer;

                    if (size > double.Epsilon)
                    {
                        // store what we can
                        foreach (var d in Drive.GetDrives(vd))
                        {
                            var available = d.FileCapacityAvailable();
                            var chunk     = Math.Min(size, available);
                            if (!d.Record_file(subject, chunk, true))
                            {
                                break;
                            }
                            size -= chunk;

                            if (size < double.Epsilon)
                            {
                                break;
                            }
                        }
                    }

                    if (size > double.Epsilon)
                    {
                        // we filled all drives up to the brim but were unable to store everything
                        if (warp_buffer < double.Epsilon)
                        {
                            // warp buffer is empty, so lets store the rest there
                            warp_buffer = size;
                            size        = 0;
                        }
                        else
                        {
                            // warp buffer not empty. that's ok if we didn't get new data
                            if (coverage_delta < double.Epsilon)
                            {
                                size = 0;
                            }
                            // else we're scanning too fast. stop.
                        }
                    }

                    // we filled all drives up to the brim but were unable to store everything
                    // cancel scanning and annoy the user
                    if (size > double.Epsilon || ec.Amount < double.Epsilon)
                    {
                        warp_buffer = 0;
                        SCANsat.StopScanner(vessel, scanner, part_prefab);
                        vd.scansat_id.Add(p.flightID);
                        if (vd.cfg_ec)
                        {
                            Message.Post(Local.Scansat_sensordisabled.Format("<b>" + vessel.vesselName + "</b>"));                               //Lib.BuildString("SCANsat sensor was disabled on <<1>>)
                        }
                    }
                }
                else if (vd.scansat_id.Contains(p.flightID))
                {
                    if (ec.Level >= 0.25 && (vd.DrivesFreeSpace / vd.DrivesCapacity > 0.9))
                    {
                        SCANsat.ResumeScanner(vessel, scanner, part_prefab);
                        vd.scansat_id.Remove(p.flightID);
                        if (vd.cfg_ec)
                        {
                            Message.Post(Local.Scansat_sensorresumed.Format("<b>" + vessel.vesselName + "</b>"));                               //Lib.BuildString("SCANsat sensor resumed operations on <<1>>)
                        }
                    }
                }
            }

            Lib.Proto.Set(m, "warp_buffer", warp_buffer);
            Lib.Proto.Set(m, "body_coverage", body_coverage);
            Lib.Proto.Set(m, "body_name", body_name);
        }