Ejemplo n.º 1
0
		/// <summary>
		/// Refreshes the experiment cache. THIS IS VERY EXPENSIVE.
		/// CB: Actually doesn't seem much worse than UpdateExperiments()
		/// </summary>
		public void RefreshExperimentCache( )
		{
			// Init
				var StartTime = DateTime.Now;
				ScienceContext Sci = new ScienceContext( );
				BodySituationFilter BodyFilter = new BodySituationFilter( );
//				_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." );
					AllScienceInstances = new List<ScienceInstance>( );
					UpdateFilter( );
					return;
				}



			// Temporary experiment list
				var exps = new List<ScienceInstance>( );



			// Unlocked experiment list
				UnlockedInstrumentList.Clear( );



			// Loop around all experiments
				foreach( var X in Sci.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 && Sci.Experiments[ experiment ] != null )
						{
							var sitMaskField = Sci.Experiments[ experiment ].GetType( ).GetField( "sitMask" );
							if( sitMaskField != null )
							{
								sitMask = (uint)(int)sitMaskField.GetValue( Sci.Experiments[ experiment ] );
//								_logger.Trace( "Setting sitMask to " + sitMask + " for " + experiment.experimentTitle );
							}

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



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



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

						
		
					// Check this experiment in all biomes on all bodies
						foreach( var body in BodyList )
						{
							if( experiment.requireAtmosphere && !body.HasAtmosphere )
								continue; // If the whole planet doesn't have an atmosphere, then there's not much point continuing.
							foreach( var situation in SituationList )
							{
								if( situation == ExperimentSituations.SrfSplashed && !body.HasOcean )
									continue; // Some planets don't have an ocean for us to be splashed down in.

								if( situation == ExperimentSituations.SrfLanded && !body.HasSurface )
									continue; // Jool and the Sun don't have a surface.

								if( ( situation == ExperimentSituations.FlyingHigh || situation == ExperimentSituations.FlyingLow ) && !body.HasAtmosphere )
									continue; // Some planets don't have an atmosphere for us to fly in.

								if( ( sitMask & (uint)situation ) == 0 )
									continue; // This experiment isn't valid for our current situation.

								if( body.Biomes.Any( ) && ( biomeMask & (uint)situation ) != 0 )
								{
									foreach( var biome in body.Biomes )
										exps.Add( new ScienceInstance( experiment, new Situation( body, situation, biome ), Sci ) );
								}
								else
									exps.Add( new ScienceInstance( experiment, new Situation( body, situation ), Sci ) );
							}
						}




				// Can't really avoid magic constants here - Kerbin and Shores
				if( ( ( sitMask & (uint)ExperimentSituations.SrfLanded ) != 0 ) && ( ( biomeMask & (uint)ExperimentSituations.SrfLanded ) != 0 ) )
				{
					if( Sci.Kerbin != null && Sci.KscBiomes.Count > 0 )
					{
						if( BodyList.Contains( Sci.BodyList[ Sci.Kerbin ] ) ) // If we haven't filtered it out
						{
//							_logger.Trace( "BabyBiomes " + experiment.experimentTitle + ": " + sitMask );
							foreach( var kscBiome in Sci.KscBiomes ) // Ew.
								exps.Add( new ScienceInstance( experiment, new Situation( Sci.BodyList[ Sci.Kerbin ], ExperimentSituations.SrfLanded, "Shores", kscBiome ), Sci ) );
						}
					}
				}
				}


				// Done replace the old list with the new one
				AllScienceInstances = exps;

			// We need to redo the filter
				UpdateFilter( );



			var Elapsed = DateTime.Now - StartTime;
			_logger.Trace( "RefreshExperimentCache Done - " + Elapsed.ToString( ) + "ms" );
		}
Ejemplo n.º 2
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++)
                            {
                                _allScienceInstances.Add(new ScienceInstance(experiment, new Situation(bodies[body_index], SituationList[situation_index], bodies[body_index].Biomes[biome_index]), this));
                            }
                        }
                        else
                        {
                            _allScienceInstances.Add(new ScienceInstance(experiment, new Situation(bodies[body_index], SituationList[situation_index]), this));
                        }
                    }
                }



                // Can't really avoid magic constants here - Kerbin and Shores
                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++)                                  // Ew.
                                {
                                    _allScienceInstances.Add(new ScienceInstance(experiment, new Situation(_bodyList[_homeWorld], ExperimentSituations.SrfLanded, _kscBiome, _kscBiomes[x]), this));
                                }
                            }
                        }
                    }
                }
            }



//			var Elapsed = DateTime.Now - StartTime;
//			_logger.Trace( "RefreshExperimentCache Done - " + Elapsed.ToString( ) + "ms" );
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Refreshes the experiment cache. THIS IS VERY EXPENSIVE.
        /// CB: Actually doesn't seem much worse than UpdateExperiments()
        /// </summary>
        public void RefreshExperimentCache( )
        {
            // Init
            var                 StartTime  = DateTime.Now;
            ScienceContext      Sci        = new ScienceContext( );
            BodySituationFilter BodyFilter = new BodySituationFilter( );

//				_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.");
                AllScienceInstances = new List <ScienceInstance>( );
                UpdateFilter( );
                return;
            }



            // Temporary experiment list
            var exps = new List <ScienceInstance>( );



            // Unlocked experiment list
            UnlockedInstrumentList.Clear( );



            // Loop around all experiments
            foreach (var X in Sci.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 && Sci.Experiments[experiment] != null)
                {
                    var sitMaskField = Sci.Experiments[experiment].GetType( ).GetField("sitMask");
                    if (sitMaskField != null)
                    {
                        sitMask = (uint)(int)sitMaskField.GetValue(Sci.Experiments[experiment]);
//								_logger.Trace( "Setting sitMask to " + sitMask + " for " + experiment.experimentTitle );
                    }

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



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



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



                // Check this experiment in all biomes on all bodies
                foreach (var body in BodyList)
                {
                    if (experiment.requireAtmosphere && !body.HasAtmosphere)
                    {
                        continue;                                         // If the whole planet doesn't have an atmosphere, then there's not much point continuing.
                    }
                    foreach (var situation in SituationList)
                    {
                        if (situation == ExperimentSituations.SrfSplashed && !body.HasOcean)
                        {
                            continue;                                             // Some planets don't have an ocean for us to be splashed down in.
                        }
                        if (situation == ExperimentSituations.SrfLanded && !body.HasSurface)
                        {
                            continue;                                             // Jool and the Sun don't have a surface.
                        }
                        if ((situation == ExperimentSituations.FlyingHigh || situation == ExperimentSituations.FlyingLow) && !body.HasAtmosphere)
                        {
                            continue;                                             // Some planets don't have an atmosphere for us to fly in.
                        }
                        if ((sitMask & (uint)situation) == 0)
                        {
                            continue;                                             // This experiment isn't valid for our current situation.
                        }
                        if (body.Biomes.Any( ) && (biomeMask & (uint)situation) != 0)
                        {
                            foreach (var biome in body.Biomes)
                            {
                                exps.Add(new ScienceInstance(experiment, new Situation(body, situation, biome), Sci));
                            }
                        }
                        else
                        {
                            exps.Add(new ScienceInstance(experiment, new Situation(body, situation), Sci));
                        }
                    }
                }



                // Can't really avoid magic constants here - Kerbin and Shores
                if (((sitMask & (uint)ExperimentSituations.SrfLanded) != 0) && ((biomeMask & (uint)ExperimentSituations.SrfLanded) != 0))
                {
                    if (Sci.Kerbin != null && Sci.KscBiomes.Count > 0)
                    {
                        if (BodyList.Contains(Sci.BodyList[Sci.Kerbin]))                              // If we haven't filtered it out
                        {
//							_logger.Trace( "BabyBiomes " + experiment.experimentTitle + ": " + sitMask );
                            foreach (var kscBiome in Sci.KscBiomes)                              // Ew.
                            {
                                exps.Add(new ScienceInstance(experiment, new Situation(Sci.BodyList[Sci.Kerbin], ExperimentSituations.SrfLanded, "Shores", kscBiome), Sci));
                            }
                        }
                    }
                }
            }


            // Done replace the old list with the new one
            AllScienceInstances = exps;

            // We need to redo the filter
            UpdateFilter( );



            var Elapsed = DateTime.Now - StartTime;

            _logger.Trace("RefreshExperimentCache Done - " + Elapsed.ToString( ) + "ms");
        }