getTargetBody() static public method

static public getTargetBody ( ContractParameter o ) : CelestialBody
o ContractParameter
return CelestialBody
        private void OnRecovered(ProtoVessel pv, bool dummy)
        {
            CelestialBody targetBody     = StnSciParameter.getTargetBody(this);
            AvailablePart experimentType = StnSciParameter.getExperimentType(this);

            if (targetBody == null || experimentType == null)
            {
                return;
            }
            foreach (ProtoPartSnapshot part in pv.protoPartSnapshots)
            {
                if (part.partName == experimentType.name)
                {
                    foreach (ProtoPartModuleSnapshot module in part.modules)
                    {
                        if (module.moduleName == "StationExperiment")
                        {
                            ConfigNode cn = module.moduleValues;
                            if (!cn.HasValue("launched") || !cn.HasValue("completed"))
                            {
                                continue;
                            }
                            float launched, completed;
                            try
                            {
                                launched  = float.Parse(cn.GetValue("launched"));
                                completed = float.Parse(cn.GetValue("completed"));
                            }
                            catch (Exception e)
                            {
                                StnSciScenario.LogError(e.ToString());
                                continue;
                            }
                            if (launched >= this.Root.DateAccepted && completed >= launched)
                            {
                                foreach (ConfigNode datum in cn.GetNodes("ScienceData"))
                                {
                                    if (!datum.HasValue("subjectID"))
                                    {
                                        continue;
                                    }
                                    string subjectID = datum.GetValue("subjectID");
                                    if (subjectID.ToLower().Contains("@" + targetBody.name.ToLower() + "inspace"))
                                    {
                                        StnSciParameter parent = this.Parent as StnSciParameter;
                                        SetComplete();
                                        if (parent != null)
                                        {
                                            parent.Complete();
                                        }
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 protected override string GetTitle()
 {
     CelestialBody targetBody = StnSciParameter.getTargetBody(this);
     if (targetBody == null)
         return Localizer.Format("#autoLOC_StatSciDoExp_TitleA");
     else
         return Localizer.Format("#autoLOC_StatSciDoExp_TitleB", targetBody.GetDisplayName());
 }
Example #3
0
        protected override string GetTitle()
        {
            CelestialBody targetBody = StnSciParameter.getTargetBody(this);

            if (targetBody == null)
            {
                return("Complete in orbit");
            }
            else
            {
                return("Complete in orbit around " + targetBody.theName);
            }
        }
Example #4
0
        protected override void OnUpdate()
        {
            base.OnUpdate();
            if (lastUpdate > UnityEngine.Time.realtimeSinceStartup + .1)
            {
                return;
            }
            CelestialBody targetBody     = StnSciParameter.getTargetBody(this);
            AvailablePart experimentType = StnSciParameter.getExperimentType(this);

            if (targetBody == null || experimentType == null)
            {
                if (targetBody == null || experimentType == null)
                {
                    Debug.Log("targetBody or experimentType is null");
                    return;
                }
            }
            lastUpdate = UnityEngine.Time.realtimeSinceStartup;
            Vessel vessel = FlightGlobals.ActiveVessel;

            if (vessel != null)
            {
                foreach (Part part in vessel.Parts)
                {
                    if (part.name == experimentType.name)
                    {
                        StationExperiment e = part.FindModuleImplementing <StationExperiment>();
                        if (e != null)
                        {
                            if (e.completed >= this.Root.DateAccepted && e.completed > e.launched)
                            {
                                ScienceData[] data = e.GetData();
                                foreach (ScienceData datum in data)
                                {
                                    if (datum.subjectID.ToLower().Contains("@" + targetBody.name.ToLower() + "inspace"))
                                    {
                                        SetComplete();
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            SetIncomplete();
        }
Example #5
0
        private void OnRecovery(Vessel vessel)
        {
            Debug.Log("Recovering " + vessel.vesselName);
            CelestialBody targetBody     = StnSciParameter.getTargetBody(this);
            AvailablePart experimentType = StnSciParameter.getExperimentType(this);

            if (targetBody == null || experimentType == null)
            {
                Debug.Log("targetBody or experimentType is null");
                return;
            }
            foreach (Part part in vessel.Parts)
            {
                if (part.name == experimentType.name)
                {
                    StationExperiment e = part.FindModuleImplementing <StationExperiment>();
                    if (e != null)
                    {
                        if (e.launched >= this.Root.DateAccepted && e.completed >= e.launched)
                        {
                            ScienceData[] data = e.GetData();
                            foreach (ScienceData datum in data)
                            {
                                if (datum.subjectID.ToLower().Contains("@" + targetBody.name.ToLower() + "inspace"))
                                {
                                    StnSciParameter parent = this.Parent as StnSciParameter;
                                    SetComplete();
                                    if (parent != null)
                                    {
                                        parent.Complete();
                                    }
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            SetIncomplete();
        }