Beispiel #1
0
        /// <summary>
        /// Refreshes the experiment cache. THIS IS VERY EXPENSIVE.
        /// CB: Actually doesn't seem much worse than UpdateExperiments()
        /// </summary>
        private void RefreshExperimentCache( )
        {
            // Init
            var StartTime = DateTime.Now;
            BodySituationFilter BodyFilter = new BodySituationFilter( );

            _unlockedInstruments.Clear( );
            _allScienceInstances.Clear( );
//_logger.Info( "RefreshExperimentCache" );


            // Quick check for things we depend on
            if (ResearchAndDevelopment.Instance == null || PartLoader.Instance == null)
            {
                _logger.Debug("ResearchAndDevelopment and PartLoader must be instantiated.");
                return;
            }



            // Loop around all experiments
            foreach (var X in _experiments)
            {
                var experiment = X.Key;


                //_logger.Trace( experiment.experimentTitle );
                // Where the experiment is possible
                uint sitMask   = experiment.situationMask;
                uint biomeMask = experiment.biomeMask;



                /* Need to look at
                 *      public bool BiomeIsRelevantWhile( ExperimentSituations situation );
                 *      public bool IsAvailableWhile( ExperimentSituations situation, CelestialBody body );
                 * On ScienceExperiment
                 */



                // OrbitalScience support - where the experiment is possible
                if (sitMask == 0 && _experiments[experiment] != null)
                {
                    var sitMaskField = _experiments[experiment].GetType( ).GetField("sitMask");
                    if (sitMaskField != null)
                    {
                        sitMask = (uint)(int)sitMaskField.GetValue(_experiments[experiment]);
//_logger.Trace( "Setting sitMask to " + sitMask + " for " + experiment.experimentTitle );
                    }

                    if (biomeMask == 0)
                    {
                        var biomeMaskField = _experiments[experiment].GetType( ).GetField("bioMask");
                        if (biomeMaskField != null)
                        {
                            biomeMask = (uint)(int)biomeMaskField.GetValue(_experiments[experiment]);
//_logger.Trace( "Setting biomeMask to " + biomeMask + " for " + experiment.experimentTitle );
                        }
                    }
                }



                List <ExperimentSituations> SituationList = Enum.GetValues(typeof(ExperimentSituations)).Cast <ExperimentSituations>( ).ToList <ExperimentSituations>( );
                List <Body> bodies = new List <Body>(_bodyList.Values.ToList( ));



                // Check for CelestialBodyFilter
                if (_experiments[experiment] != null)
                {
//_logger.Trace( Experiments[ experiment ].experimentID );
                    if (CelestialBodyFilters.Filters.HasValue(_experiments[experiment].experimentID))
                    {
                        string FilterText = CelestialBodyFilters.Filters.GetValue(_experiments[experiment].experimentID);
                        BodyFilter.Filter(bodies, SituationList, FilterText);
                    }
                }



                // Check this experiment in all biomes on all bodies
                for (int body_index = 0; body_index < bodies.Count; body_index++)
                {
                    if (experiment.requireAtmosphere && !bodies[body_index].HasAtmosphere)
                    {
                        continue;                         // If the whole planet doesn't have an atmosphere, then there's not much point continuing.
                    }
                    for (int situation_index = 0; situation_index < SituationList.Count; situation_index++)
                    {
                        if (SituationList[situation_index] == ExperimentSituations.SrfSplashed && !bodies[body_index].HasOcean)
                        {
                            continue;                             // Some planets don't have an ocean for us to be splashed down in.
                        }
                        if (SituationList[situation_index] == ExperimentSituations.SrfLanded && !bodies[body_index].HasSurface)
                        {
                            continue;                             // Jool and the Sun don't have a surface.
                        }
                        if ((SituationList[situation_index] == ExperimentSituations.FlyingHigh || SituationList[situation_index] == ExperimentSituations.FlyingLow) && !bodies[body_index].HasAtmosphere)
                        {
                            continue;                             // Some planets don't have an atmosphere for us to fly in.
                        }
                        if ((sitMask & (uint)SituationList[situation_index]) == 0)
                        {
                            continue;                             // This experiment isn't valid for our current situation.
                        }
                        if (bodies[body_index].Biomes.Any( ) && (biomeMask & (uint)SituationList[situation_index]) != 0)
                        {
                            for (int biome_index = 0; biome_index < bodies[body_index].Biomes.Count( ); biome_index++)
                            {
                                ScienceInstance S = new ScienceInstance(experiment, new Situation(bodies[body_index], SituationList[situation_index], bodies[body_index].Biomes[biome_index]), this);
                                if (BodyFilter.TextFilter(S))
                                {
                                    if (!_parent.Config.FilterDifficultScience || BodyFilter.DifficultScienceFilter(S))
                                    {
                                        _allScienceInstances.Add(S);
                                    }
                                }
                            }
                        }
                        else
                        {
                            ScienceInstance S = new ScienceInstance(experiment, new Situation(bodies[body_index], SituationList[situation_index]), this);
                            if (BodyFilter.TextFilter(S))
                            {
                                if (!_parent.Config.FilterDifficultScience || BodyFilter.DifficultScienceFilter(S))
                                {
                                    _allScienceInstances.Add(S);
                                }
                            }
                        }
                    }
                }



                if (((sitMask & (uint)ExperimentSituations.SrfLanded) != 0) && ((biomeMask & (uint)ExperimentSituations.SrfLanded) != 0))
                {
                    if (_homeWorld != null && _kscBiomes.Count > 0)
                    {
                        if (bodies.Contains(_bodyList[_homeWorld]))                              // If we haven't filtered it out
                        {
                            if (SituationList.Contains(ExperimentSituations.SrfLanded))
                            {
//_logger.Trace( "BabyBiomes " + experiment.experimentTitle + ": " + sitMask );
                                for (int x = 0; x < _kscBiomes.Count; x++)
                                {
                                    ScienceInstance S = new ScienceInstance(experiment, new Situation(_bodyList[_homeWorld], ExperimentSituations.SrfLanded, _kscBiome, _kscBiomes[x]), this);
                                    if (BodyFilter.TextFilter(S))
                                    {
                                        if (!_parent.Config.FilterDifficultScience || BodyFilter.DifficultScienceFilter(S))
                                        {
                                            _allScienceInstances.Add(S);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }



//			var Elapsed = DateTime.Now - StartTime;
//			_logger.Trace( "RefreshExperimentCache Done - " + Elapsed.ToString( ) + "ms" );
        }
Beispiel #2
0
		/// <summary>
		/// Draws an experiment inside the given Rect.
		/// </summary>
		/// <param name="exp">The experiment to render.</param>
		/// <param name="rect">The rect inside which the experiment should be rendered.</param>
		/// <param name="compact">Whether this experiment is compact.</param>
		/// <param name="labelStyle">The style to use for labels.</param>
		private void DrawExperiment (ScienceInstance exp, Rect rect, bool compact, GUIStyle labelStyle) {
			labelStyle.normal.textColor = exp.IsComplete ? Color.green : Color.yellow;
			var labelRect = new Rect(rect) {
				y = rect.y + (compact ? 1 : 3),
			};
			var progressRect = new Rect(rect) {
				xMin = rect.xMax - (compact ? 75 : 105),
				xMax = rect.xMax - (compact ? 40 : 40),
				y = rect.y + (compact ? 1 : 3),
			};

			GUI.Label(labelRect, exp.Description, labelStyle);
			GUI.skin.horizontalScrollbar.fixedHeight = compact ? 8 : 13;
			GUI.skin.horizontalScrollbarThumb.fixedHeight = compact ? 8 : 13;
			ProgressBar(progressRect, exp.CompletedScience, exp.TotalScience, exp.CompletedScience + exp.OnboardScience, !compact, compact);
		}
Beispiel #3
0
        public void RunExperiment(ScienceInstance s, bool runSingleUse = true)
        {
            _logger.Trace("Finding Module for Science Report: " + s.ScienceExperiment.id);
            ModuleScienceExperiment m = null;



            // If possible run with DMagic new API
            if (_DMModuleScienceAnimateGenerics != null && _DMModuleScienceAnimateGenerics.Count > 0)
            {
                DMModuleScienceAnimateGeneric NewDMagicInstance = _parent.DMagic.GetDMModuleScienceAnimateGeneric( );
                if (NewDMagicInstance != null)
                {
                    IEnumerable <ModuleScienceExperiment> lm = _DMModuleScienceAnimateGenerics.Where(x => (
                                                                                                         x.experimentID == s.ScienceExperiment.id &&
                                                                                                         !x.Inoperable &&
                                                                                                         ((int)x.Fields.GetValue("experimentLimit") > 1 ? NewDMagicInstance.canConduct(x) : NewDMagicInstance.canConduct(x) && (x.rerunnable || runSingleUse))
                                                                                                         ));
                    if (lm.Count() != 0)
                    {
                        m = lm.First();
                    }

                    if (m != null)
                    {
                        _logger.Debug("Running DMModuleScienceAnimateGenerics Experiment " + m.experimentID + " on part " + m.part.partInfo.name);
                        NewDMagicInstance.gatherScienceData(m, !_parent.Config.ShowResultsWindow);
                        return;
                    }
                }
            }



            // If possible run with DMagic DMAPI
            if (_DMModuleScienceAnimates != null && _DMModuleScienceAnimates.Count > 0)
            {
                DMAPI DMAPIInstance = _parent.DMagic.GetDMAPI( );
                if (DMAPIInstance != null)
                {
                    IEnumerable <ModuleScienceExperiment> lm = _DMModuleScienceAnimates.Where(x =>
                    {
                        return(x.experimentID == s.ScienceExperiment.id &&
                               !x.Inoperable &&
                               ((int)x.Fields.GetValue("experimentLimit") > 1 ? DMAPIInstance.experimentCanConduct(x) : DMAPIInstance.experimentCanConduct(x) && (x.rerunnable || runSingleUse)));
                    });
                    if (lm.Count() != 0)
                    {
                        m = lm.First();
                    }

                    if (m != null)
                    {
                        _logger.Trace("Running DMModuleScienceAnimates Experiment " + m.experimentID + " on part " + m.part.partInfo.name);
                        DMAPIInstance.deployDMExperiment(m, !_parent.Config.ShowResultsWindow);
                        return;
                    }
                }
            }



            // Do stock run
            m = FindExperiment(s, runSingleUse);
            if (m != null)
            {
                _logger.Trace("Running Experiment " + m.experimentID + " on part " + m.part.partInfo.name);
                RunStandardModuleScienceExperiment(m);
                return;
            }
        }