Exemplo n.º 1
0
        private void OnVesselSituationChange(GameEvents.HostedFromToAction <Vessel, Vessel.Situations> arg)
        {
            Debug.Log("OnVesselSituationChanged");
            if (!((arg.from == Vessel.Situations.LANDED || arg.from == Vessel.Situations.PRELAUNCH) &&
                  (arg.to == Vessel.Situations.FLYING || arg.to == Vessel.Situations.SUB_ORBITAL)))
            {
                return;
            }
            if (arg.host.mainBody.theName != "Kerbin")
            {
                return;
            }
            AvailablePart experimentType = StnSciParameter.getExperimentType(this);

            if (experimentType == null)
            {
                return;
            }
            foreach (Part part in arg.host.Parts)
            {
                if (part.name == experimentType.name)
                {
                    StationExperiment e = part.FindModuleImplementing <StationExperiment>();
                    if (e != null && e.launched == 0)
                    {
                        e.launched = (float)Planetarium.GetUniversalTime();
                    }
                }
            }
        }
Exemplo n.º 2
0
 protected override void OnUpdate()
 {
     base.OnUpdate();
     if (lastUpdate > UnityEngine.Time.realtimeSinceStartup + .1)
         return;
     lastUpdate = UnityEngine.Time.realtimeSinceStartup;
     Vessel vessel = FlightGlobals.ActiveVessel;
     AvailablePart experimentType = StnSciParameter.getExperimentType(this);
     if (experimentType == null)
         return;
     if (vessel != null)
         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)
                     {
                         SetComplete();
                         return;
                     }
                 }
             }
         }
     SetIncomplete();
 }
Exemplo n.º 3
0
        public bool CanRunExperiment(ModuleScienceExperiment baseExperiment, float currentScienceValue)
        {
            var currentExperiment = baseExperiment as StationExperiment;
            var isActive          = currentExperiment.Events["StartExperiment"].active;

            if (isActive)
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": StationExperiment didn't start yet! You might want to start it manually!");
                return(false);
            }
            if (StationExperiment.checkBoring(FlightGlobals.ActiveVessel, false))
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": StationExperiment says this location is boring!");
                return(false);
            }
            if (!currentExperiment.finished() && !isActive)
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": StationExperiment isn't finished yet!");
                return(false);
            }
            if (!currentExperiment.experiment.IsAvailableWhile(ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody))//
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": Experiment isn't available in the current situation: ", ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), "_", FlightGlobals.currentMainBody + "_", currentExperiment.experiment.situationMask);
                return(false);
            }
            if (currentExperiment.Inoperable)
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": Experiment is inoperable");
                return(false);
            }
            if (currentExperiment.Deployed)
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": Experiment is deployed");
                return(false);
            }

            if (!currentExperiment.rerunnable && !_AutomatedScienceSamplerInstance.craftSettings.oneTimeOnly)
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": Runing rerunable experiments is disabled");
                return(false);
            }
            if (currentScienceValue < _AutomatedScienceSamplerInstance.craftSettings.threshold)
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": Science value is less than cutoff threshold: ", currentScienceValue, "<", _AutomatedScienceSamplerInstance.craftSettings.threshold);
                return(false);
            }
            if (!currentExperiment.experiment.IsUnlocked())
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": Experiment is locked");
                return(false);
            }
            return(true);
        }
Exemplo n.º 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();
        }
Exemplo n.º 5
0
 private void OnVesselCreate(Vessel vessel)
 {
     AvailablePart experimentType = StnSciParameter.getExperimentType(this);
     if (experimentType == null)
         return;
     foreach (Part part in vessel.Parts)
     {
         if (part.name == experimentType.name)
         {
             StationExperiment e = part.FindModuleImplementing<StationExperiment>();
             if (e != null)
             {
                 e.launched = (float)Planetarium.GetUniversalTime();
             }
         }
     }
 }
Exemplo n.º 6
0
 private void OnLaunch(EventReport report)
 {
     AvailablePart experimentType = StnSciParameter.getExperimentType(this);
     if (experimentType == null)
         return;
     Vessel vessel = FlightGlobals.ActiveVessel;
     foreach (Part part in vessel.Parts)
     {
         if (part.name == experimentType.name)
         {
             StationExperiment e = part.FindModuleImplementing<StationExperiment>();
             if (e != null && e.launched == 0)
             {
                 e.launched = (float)Planetarium.GetUniversalTime();
             }
         }
     }
 }
Exemplo n.º 7
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();
        }