Example #1
0
        //thinking about doing this where entity is the sensor component not the ship,
        //that way, a ship can have multiple different sensors which run at different intervals.
        //I'll need to get the parent ship... or maybe just the systemfactionInfo to store the detected ships though.
        //having the ships      what they detect could be usefull info to display though.
        internal override void ProcessEntity(Entity entity, int deltaSeconds)
        {
            EntityManager manager   = entity.Manager;
            Entity        faction   = entity.GetDataBlob <OwnedDB>().OwnedByFaction;
            DateTime      atDate    = manager.ManagerSubpulses.SystemLocalDateTime + TimeSpan.FromSeconds(deltaSeconds);
            var           receverDB = entity.GetDataBlob <SensorReceverAtbDB>();

            var detectableEntitys = manager.GetAllEntitiesWithDataBlob <SensorProfileDB>();

            foreach (var detectableEntity in detectableEntitys)
            {
                //Entity detectableEntity = sensorProfile.OwningEntity;

                if (detectableEntity.HasDataBlob <OwnedDB>())
                {
                    if (detectableEntity.GetDataBlob <OwnedDB>().OwnedByFaction != faction)
                    {
                        SensorProcessorTools.DetectEntites(receverDB, detectableEntity, atDate);
                    }
                    else
                    {
                        //then the sensor profile belongs to the same faction as the recever. don't bother trying to detect it.
                    }
                }
                else
                {
                    SensorProcessorTools.DetectEntites(receverDB, detectableEntity, atDate);
                }
            }



            manager.ManagerSubpulses.AddEntityInterupt(atDate + TimeSpan.FromSeconds(receverDB.ScanTime), this.TypeName, entity);
        }
Example #2
0
        /// <summary>
        /// Creates a star entity in the system.
        /// Does not initialize an orbit.
        /// </summary>
        public Entity CreateStar(StarSystem system, double mass, double radius, double age, string starClass, double temperature, float luminosity, SpectralType spectralType, string starName = null)
        {
            double          tempRange       = temperature / _galaxyGen.Settings.StarTemperatureBySpectralType[spectralType].Max; // temp range from 0 to 1.
            ushort          subDivision     = (ushort)Math.Round((1 - tempRange) * 10);
            LuminosityClass luminosityClass = LuminosityClass.V;

            if (starName == null)
            {
                starName = system.NameDB.DefaultName;
            }

            int starIndex = system.GetAllEntitiesWithDataBlob <StarInfoDB>().Count;

            starName += " " + (char)('A' + starIndex) + " " + spectralType + subDivision + luminosityClass;

            MassVolumeDB starMassVolumeDB = MassVolumeDB.NewFromMassAndRadius(mass, radius);
            StarInfoDB   starInfoDB       = new StarInfoDB {
                Age = age, Class = starClass, Luminosity = luminosity, SpectralType = spectralType, Temperature = temperature, LuminosityClass = luminosityClass, SpectralSubDivision = subDivision
            };
            PositionDB starPositionDB = new PositionDB(new Vector3(0, 0, 0), system.Guid);
            NameDB     starNameDB     = new NameDB(starName);
            OrbitDB    starOrbitDB    = new OrbitDB();

            SensorProfileDB emmisionSignature = SensorProcessorTools.SetStarEmmisionSig(starInfoDB, starMassVolumeDB);

            return(new Entity(system, new List <BaseDataBlob> {
                starOrbitDB, starMassVolumeDB, starInfoDB, starNameDB, starPositionDB, emmisionSignature
            }));
        }
        /*
         * public TimeSpan RunFrequency => TimeSpan.FromMinutes(60);
         *
         * public void ProcessEntity(Entity entity, int deltaSeconds)
         * {
         *  SetEntityProfile(entity);
         * }
         *
         * public void ProcessManager(EntityManager manager, int deltaSeconds)
         * {
         *  Stopwatch timer = new Stopwatch();
         *  timer.Start();
         *  var entites = manager.GetAllEntitiesWithDataBlob<SensorProfileDB>();
         *  foreach (var entity in entites)
         *  {
         *      ProcessEntity(entity, deltaSeconds);
         *  }
         *  var ms = timer.ElapsedMilliseconds;
         *  var numEntites = entites.Count;
         * }
         */

        internal static void SetEntityProfile(Entity entity, DateTime atDate)
        {
            var position  = entity.GetDataBlob <PositionDB>();
            var sensorSig = entity.GetDataBlob <SensorProfileDB>();

            sensorSig.LastPositionOfReflectionSet = position.AbsolutePosition_AU;
            sensorSig.LastDatetimeOfReflectionSet = atDate;

            var emmiters          = entity.Manager.GetAllEntitiesWithDataBlob <SensorProfileDB>();
            int numberOfEmmitters = emmiters.Count;

            sensorSig.ReflectedEMSpectra.Clear();

            PercentValue reflectionPercent = 0.1f; //TODO: this should be calculated from crossSection(size), distance, and a reflectivity value(stealth armor?/ other design factors?).

            foreach (var emittingEntity in emmiters)
            {
                if (emittingEntity != entity) // don't reflect our own emmision.
                {
                    double distance    = PositionDB.GetDistanceBetween(position, emittingEntity.GetDataBlob <PositionDB>());
                    var    emmissionDB = emittingEntity.GetDataBlob <SensorProfileDB>();

                    foreach (var emitedItem in emmissionDB.EmittedEMSpectra)
                    {
                        var reflectedMagnatude = SensorProcessorTools.AttenuationCalc(emitedItem.Value, distance) * reflectionPercent;

                        sensorSig.ReflectedEMSpectra.Add(emitedItem.Key, emitedItem.Value);
                    }
                }
            }
        }
        void UpdateDatablob(SystemBodyInfoDB origionalDB, SensorInfoDB sensorInfo)
        {
            Random rng      = new Random(); //TODO: rand should be deterministic.
            float  accuracy = sensorInfo.HighestDetectionQuality.SignalQuality;

            if (sensorInfo.HighestDetectionQuality.SignalQuality > 0.20)
            {
                BodyType = origionalDB.BodyType;
            }
            else
            {
                BodyType = BodyType.Unknown;
            }
            if (sensorInfo.HighestDetectionQuality.SignalQuality > 0.80)
            {
                Tectonics = origionalDB.Tectonics;
            }
            else
            {
                Tectonics = TectonicActivity.Unknown;
            }
            //TODO: #SensorClone, #TMI more random to the rest of it.
            var tilt = SensorProcessorTools.RndSigmoid(origionalDB.AxialTilt, accuracy, rng);

            AxialTilt           = (float)tilt;
            MagneticField       = origionalDB.MagneticField;
            BaseTemperature     = origionalDB.BaseTemperature;
            RadiationLevel      = origionalDB.RadiationLevel;
            AtmosphericDust     = origionalDB.AtmosphericDust;
            SupportsPopulations = origionalDB.SupportsPopulations;
            LengthOfDay         = origionalDB.LengthOfDay;
            Gravity             = origionalDB.Gravity;
            Minerals            = new Dictionary <Guid, MineralDepositInfo>(origionalDB.Minerals); //This really needs to be handled properly
        }
Example #5
0
        void Update(StarInfoDB db, SensorInfoDB sensorInfo)
        {
            Random rng      = new Random();
            float  accuracy = sensorInfo.HighestDetectionQuality.SignalQuality;

            Age         = SensorProcessorTools.RndSigmoid(db.Age, accuracy, rng);
            Temperature = SensorProcessorTools.RndSigmoid(db.Temperature, accuracy, rng);
            Luminosity  = SensorProcessorTools.RndSigmoid(db.Luminosity, accuracy, rng);
            Class       = db.Class;

            SpectralType        = db.SpectralType;
            SpectralSubDivision = db.SpectralSubDivision;
            LuminosityClass     = db.LuminosityClass;
        }
Example #6
0
        public StarSystem CreateTestSystem(Game game, int x = 0, int y = 0)
        {
            StarSystem sol = new StarSystem(game, "something", -1);

            Entity sun = _starFactory.CreateStar(sol, GameConstants.Units.SolarMassInKG, GameConstants.Units.SolarRadiusInAu, 4.6E9, "G", 5778, 1, SpectralType.G, "something");

            sun.GetDataBlob <PositionDB>().X_AU += x;
            sun.GetDataBlob <PositionDB>().Y_AU += x;

            MassVolumeDB sunMVDB = sun.GetDataBlob <MassVolumeDB>();

            SystemBodyInfoDB mercuryBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.068f
            };                                                                                                                                      //Albedo = 0.068f
            MassVolumeDB mercuryMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7));
            NameDB       mercuryNameDB       = new NameDB("LOLXDWTF");
            double       mercurySemiMajAxis  = 0.387098;
            double       mercuryEccentricity = 0.205630;
            double       mercuryInclination  = 0;
            double       mercuryLoAN         = 48.33167;
            double       mercuryLoP          = 77.45645;
            double       mercuryMeanLongd    = 252.25084;
            OrbitDB      mercuryOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, mercuryMVDB.MassDry, mercurySemiMajAxis, mercuryEccentricity, mercuryInclination, mercuryLoAN, mercuryLoP, mercuryMeanLongd, GalaxyGen.Settings.J2000);
            PositionDB   mercuryPositionDB   = new PositionDB(OrbitProcessor.GetPosition_AU(mercuryOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);
            //AtmosphereDB mercuryAtmo = new AtmosphereDB();
            SensorProfileDB sensorProfile = new SensorProfileDB();

            mercuryPositionDB.X_AU += x;
            mercuryPositionDB.Y_AU += x;
            Entity mercury = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, mercuryPositionDB, mercuryBodyDB, mercuryMVDB, mercuryNameDB, mercuryOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, mercury);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, mercuryBodyDB, mercuryMVDB);

            SystemBodyInfoDB venusBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.77f
            };
            MassVolumeDB venusMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(4.8676E24, Distance.KmToAU(6051.8));
            NameDB       venusNameDB       = new NameDB("AYLMAOROFL");
            double       venusSemiMajAxis  = 0.72333199;
            double       venusEccentricity = 0.00677323;
            double       venusInclination  = 0;
            double       venusLoAN         = 76.68069;
            double       venusLoP          = 131.53298;
            double       venusMeanLongd    = 181.97973;
            OrbitDB      venusOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, venusMVDB.MassDry, venusSemiMajAxis, venusEccentricity, venusInclination, venusLoAN, venusLoP, venusMeanLongd, GalaxyGen.Settings.J2000);
            PositionDB   venusPositionDB   = new PositionDB(OrbitProcessor.GetPosition_AU(venusOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);

            sensorProfile = new SensorProfileDB();
            Entity venus = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, venusPositionDB, venusBodyDB, venusMVDB, venusNameDB, venusOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, venus);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, venusBodyDB, venusMVDB);

            SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.306f
            };
            MassVolumeDB earthMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(5.9726E24, Distance.KmToAU(6378.1));
            NameDB       earthNameDB       = new NameDB("OMG");
            double       earthSemiMajAxis  = 1.00000011;
            double       earthEccentricity = 0.01671022;
            double       earthInclination  = 0;
            double       earthLoAN         = -11.26064;
            double       earthLoP          = 102.94719;
            double       earthMeanLongd    = 100.46435;
            OrbitDB      earthOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, earthMVDB.MassDry, earthSemiMajAxis, earthEccentricity, earthInclination, earthLoAN, earthLoP, earthMeanLongd, GalaxyGen.Settings.J2000);

            earthBodyDB.Tectonics = TectonicActivity.EarthLike;
            PositionDB earthPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(earthOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);
            Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>();

            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.78f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.12f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.01f);
            AtmosphereDB earthAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?

            sensorProfile = new SensorProfileDB();
            Entity earth = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, earthPositionDB, earthBodyDB, earthMVDB, earthNameDB, earthOrbitDB, earthAtmosphereDB
            });

            _systemBodyFactory.HomeworldMineralGeneration(game.StaticData, sol, earth);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, earthBodyDB, earthMVDB);


            SystemBodyInfoDB lunaBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Moon, SupportsPopulations = true
            };
            MassVolumeDB lunaMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(0.073E24, Distance.KmToAU(1738.14));
            NameDB       lunaNameDB       = new NameDB("NOWAY");
            double       lunaSemiMajAxis  = Distance.KmToAU(0.3844E6);
            double       lunaEccentricity = 0.0549;
            double       lunaInclination  = 0;//5.1;
            // Next three values are unimportant. Luna's LoAN and AoP regress/progress by one revolution every 18.6/8.85 years respectively.
            // Our orbit code it not advanced enough to deal with LoAN/AoP regression/progression.
            double     lunaLoAN        = 125.08;
            double     lunaAoP         = 318.0634;
            double     lunaMeanAnomaly = 115.3654;
            OrbitDB    lunaOrbitDB     = OrbitDB.FromAsteroidFormat(earth, earthMVDB.MassDry, lunaMVDB.MassDry, lunaSemiMajAxis, lunaEccentricity, lunaInclination, lunaLoAN, lunaAoP, lunaMeanAnomaly, GalaxyGen.Settings.J2000);
            PositionDB lunaPositionDB  = new PositionDB(OrbitProcessor.GetPosition_AU(lunaOrbitDB, StaticRefLib.CurrentDateTime) + earthPositionDB.AbsolutePosition_AU, sol.Guid, earth);

            sensorProfile = new SensorProfileDB();
            Entity luna = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, lunaPositionDB, lunaBodyDB, lunaMVDB, lunaNameDB, lunaOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, luna);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, lunaBodyDB, lunaMVDB);


            SystemBodyInfoDB halleysBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Comet, SupportsPopulations = false, Albedo = 0.04f
            };                                                                                                                                 //Albedo = 0.04f
            MassVolumeDB halleysMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(2.2e14, Distance.KmToAU(11));
            NameDB       halleysNameDB       = new NameDB("ASSHOLE");
            double       halleysSemiMajAxis  = 17.834;                                                                                                     //AU
            double       halleysEccentricity = 0.96714;
            double       halleysInclination  = 180;                                                                                                        //162.26° note retrograde orbit.
            double       halleysLoAN         = 58.42;                                                                                                      //°
            double       halleysAoP          = 111.33;                                                                                                     //°
            double       halleysMeanAnomaly  = 38.38;                                                                                                      //°
            OrbitDB      halleysOrbitDB      = OrbitDB.FromAsteroidFormat(sun, sunMVDB.MassDry, halleysMVDB.MassDry, halleysSemiMajAxis, halleysEccentricity, halleysInclination, halleysLoAN, halleysAoP, halleysMeanAnomaly, new System.DateTime(1994, 2, 17));
            PositionDB   halleysPositionDB   = new PositionDB(OrbitProcessor.GetPosition_AU(halleysOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); // + earthPositionDB.AbsolutePosition_AU, sol.ID);

            sensorProfile = new SensorProfileDB();
            Entity halleysComet = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, halleysPositionDB, halleysBodyDB, halleysMVDB, halleysNameDB, halleysOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, halleysComet);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, halleysBodyDB, halleysMVDB);

            JPSurveyFactory.GenerateJPSurveyPoints(sol);

            game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid);
            return(sol);
        }
Example #7
0
        /// <summary>
        /// Creates our own solar system.
        /// This probibly needs to be Json! (since we're getting atmo stuff)
        /// Adds sol to game.StarSystems.
        /// </summary>
        public StarSystem CreateSol(Game game)
        {
            // WIP Function. Not complete.
            StarSystem sol = new StarSystem(game, "Sol", -1);

            Entity sun = _starFactory.CreateStar(sol, GameConstants.Units.SolarMassInKG, GameConstants.Units.SolarRadiusInAu, 4.6E9, "G", 5778, 1, SpectralType.G, "Sol");

            MassVolumeDB sunMVDB = sun.GetDataBlob <MassVolumeDB>();

            SystemBodyInfoDB mercuryBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.068f
            };                                                                                                                                      //Albedo = 0.068f
            MassVolumeDB mercuryMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7));
            NameDB       mercuryNameDB       = new NameDB("Mercury");
            double       mercurySemiMajAxis  = 0.387098;
            double       mercuryEccentricity = 0.205630;
            double       mercuryInclination  = 0;
            double       mercuryLoAN         = 48.33167;
            double       mercuryLoP          = 77.45645;
            double       mercuryMeanLongd    = 252.25084;
            OrbitDB      mercuryOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, mercuryMVDB.MassDry, mercurySemiMajAxis, mercuryEccentricity, mercuryInclination, mercuryLoAN, mercuryLoP, mercuryMeanLongd, GalaxyGen.Settings.J2000);

            mercuryBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, mercuryOrbitDB);
            PositionDB mercuryPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(mercuryOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);
            //AtmosphereDB mercuryAtmo = new AtmosphereDB();
            SensorProfileDB sensorProfile = new SensorProfileDB();
            Entity          mercury       = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, mercuryPositionDB, mercuryBodyDB, mercuryMVDB, mercuryNameDB, mercuryOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, mercury);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, mercuryBodyDB, mercuryMVDB);

            SystemBodyInfoDB venusBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.77f
            };
            MassVolumeDB venusMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(4.8676E24, Distance.KmToAU(6051.8));
            NameDB       venusNameDB       = new NameDB("Venus");
            double       venusSemiMajAxis  = 0.72333199;
            double       venusEccentricity = 0.00677323;
            double       venusInclination  = 0;
            double       venusLoAN         = 76.68069;
            double       venusLoP          = 131.53298;
            double       venusMeanLongd    = 181.97973;

            OrbitDB venusOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, venusMVDB.MassDry, venusSemiMajAxis, venusEccentricity, venusInclination, venusLoAN, venusLoP, venusMeanLongd, GalaxyGen.Settings.J2000);

            venusBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, venusOrbitDB);
            PositionDB venusPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(venusOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);

            sensorProfile = new SensorProfileDB();
            Entity venus = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, venusPositionDB, venusBodyDB, venusMVDB, venusNameDB, venusOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, venus);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, venusBodyDB, venusMVDB);

            SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.306f
            };
            MassVolumeDB earthMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(5.9726E24, Distance.KmToAU(6378.1));
            NameDB       earthNameDB       = new NameDB("Earth");
            double       earthSemiMajAxis  = 1.00000011;
            double       earthEccentricity = 0.01671022;
            double       earthInclination  = 0;
            double       earthLoAN         = -11.26064;
            double       earthLoP          = 102.94719;
            double       earthMeanLongd    = 100.46435;
            OrbitDB      earthOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, earthMVDB.MassDry, earthSemiMajAxis, earthEccentricity, earthInclination, earthLoAN, earthLoP, earthMeanLongd, GalaxyGen.Settings.J2000);

            earthBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, earthOrbitDB);
            earthBodyDB.Tectonics       = TectonicActivity.EarthLike;
            PositionDB earthPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(earthOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);
            Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>();

            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.78f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.12f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.01f);
            AtmosphereDB earthAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?

            sensorProfile = new SensorProfileDB();
            Entity earth = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, earthPositionDB, earthBodyDB, earthMVDB, earthNameDB, earthOrbitDB, earthAtmosphereDB
            });

            _systemBodyFactory.HomeworldMineralGeneration(game.StaticData, sol, earth);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, earthBodyDB, earthMVDB);


            SystemBodyInfoDB lunaBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Moon, SupportsPopulations = true
            };
            MassVolumeDB lunaMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(0.073E24, Distance.KmToAU(1738.14));
            NameDB       lunaNameDB       = new NameDB("Luna");
            double       lunaSemiMajAxis  = Distance.KmToAU(0.3844E6);
            double       lunaEccentricity = 0.0549;
            double       lunaInclination  = 0;//5.1;
            // Next three values are unimportant. Luna's LoAN and AoP regress/progress by one revolution every 18.6/8.85 years respectively.
            // Our orbit code it not advanced enough to deal with LoAN/AoP regression/progression.
            double  lunaLoAN        = 125.08;
            double  lunaAoP         = 318.0634;
            double  lunaMeanAnomaly = 115.3654;
            OrbitDB lunaOrbitDB     = OrbitDB.FromAsteroidFormat(earth, earthMVDB.MassDry, lunaMVDB.MassDry, lunaSemiMajAxis, lunaEccentricity, lunaInclination, lunaLoAN, lunaAoP, lunaMeanAnomaly, GalaxyGen.Settings.J2000);

            lunaBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, earthOrbitDB); //yes, using earth orbit here, since this is the DB it calculates the average distance from.

            PositionDB lunaPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(lunaOrbitDB, StaticRefLib.CurrentDateTime) + earthPositionDB.AbsolutePosition_AU, sol.Guid, earth);

            sensorProfile = new SensorProfileDB();
            Entity luna = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, lunaPositionDB, lunaBodyDB, lunaMVDB, lunaNameDB, lunaOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, luna);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, lunaBodyDB, lunaMVDB);


            SystemBodyInfoDB marsBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.25f
            };
            MassVolumeDB marsMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(0.64174E24, Distance.KmToAU(3396.2));
            NameDB       marsNameDB       = new NameDB("Mars");
            double       marsSemiMajAxis  = Distance.KmToAU(227.92E6);
            double       marsEccentricity = 0.0934; //wiki says .0934
            double       marsInclination  = 0;      //1.85;
            double       marsLoAN         = 49.57854;
            double       marsAoP          = 336.04084;
            double       marsMeanLong     = 355.45332;
            OrbitDB      marsOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, marsMVDB.MassDry, marsSemiMajAxis, marsEccentricity, marsInclination, marsLoAN, marsAoP, marsMeanLong, GalaxyGen.Settings.J2000);

            marsBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, marsOrbitDB);
            Dictionary <AtmosphericGasSD, float> marsAtmoGasses = new Dictionary <AtmosphericGasSD, float>();

            marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(12), 0.95f * 0.01f);   // C02% * Mars Atms
            marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.027f * 0.01f);   // N% * Mars Atms
            marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.007f * 0.01f);   // O% * Mars Atms
            marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.016f * 0.01f);  // Ar% * Mars Atms
            AtmosphereDB marsAtmo       = new AtmosphereDB(0.087f, false, 0, 0, 0, -55, marsAtmoGasses);
            PositionDB   marsPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(marsOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);

            sensorProfile = new SensorProfileDB();
            Entity mars = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, marsPositionDB, marsBodyDB, marsMVDB, marsNameDB, marsOrbitDB, marsAtmo
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, mars);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, marsBodyDB, marsMVDB);


            SystemBodyInfoDB halleysBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Comet, SupportsPopulations = false, Albedo = 0.04f
            };                                                                                                                                 //Albedo = 0.04f
            MassVolumeDB halleysMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(2.2e14, Distance.KmToAU(11));
            NameDB       halleysNameDB       = new NameDB("Halleys Comet");
            double       halleysSemiMajAxis  = 17.834; //AU
            double       halleysEccentricity = 0.96714;
            double       halleysInclination  = 180;    //162.26° note retrograde orbit.
            double       halleysLoAN         = 58.42;  //°
            double       halleysAoP          = 111.33; //°
            double       halleysMeanAnomaly  = 38.38;  //°
            OrbitDB      halleysOrbitDB      = OrbitDB.FromAsteroidFormat(sun, sunMVDB.MassDry, halleysMVDB.MassDry, halleysSemiMajAxis, halleysEccentricity, halleysInclination, halleysLoAN, halleysAoP, halleysMeanAnomaly, new System.DateTime(1994, 2, 17));

            halleysBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, halleysOrbitDB);
            PositionDB halleysPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(halleysOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); // + earthPositionDB.AbsolutePosition_AU, sol.ID);

            sensorProfile = new SensorProfileDB();
            Entity halleysComet = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, halleysPositionDB, halleysBodyDB, halleysMVDB, halleysNameDB, halleysOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, halleysComet);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, halleysBodyDB, halleysMVDB);

            /*
             *
             * SystemBody Jupiter = new SystemBody(sun, SystemBody.PlanetType.GasGiant);
             * Jupiter.Name = "Jupiter";
             * Jupiter.Orbit = Orbit.FromMajorPlanetFormat(1898.3E24, sun.Orbit.Mass, 5.20336301, 0.04839266, 1.30530, 100.55615, 14.75385, 34.40438, GalaxyGen.J2000);
             * Jupiter.Radius = Distance.ToAU(71492);
             * Jupiter.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Jupiter.Position.System = Sol;
             * Jupiter.Position.X = x;
             * Jupiter.Position.Y = y;
             * sun.Planets.Add(Jupiter);
             *
             * SystemBody Saturn = new SystemBody(sun, SystemBody.PlanetType.GasGiant);
             * Saturn.Name = "Saturn";
             * Saturn.Orbit = Orbit.FromMajorPlanetFormat(568.36E24, sun.Orbit.Mass, 9.53707032, 0.05415060, 2.48446, 113.71504, 92.43194, 49.94432, GalaxyGen.J2000);
             * Saturn.Radius = Distance.ToAU(60268);
             * Saturn.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Saturn.Position.System = Sol;
             * Saturn.Position.X = x;
             * Saturn.Position.Y = y;
             * sun.Planets.Add(Saturn);
             *
             * SystemBody Uranus = new SystemBody(sun, SystemBody.PlanetType.IceGiant);
             * Uranus.Name = "Uranus";
             * Uranus.Orbit = Orbit.FromMajorPlanetFormat(86.816E24, sun.Orbit.Mass, 19.19126393, 0.04716771, 0.76986, 74.22988, 170.96424, 313.23218, GalaxyGen.J2000);
             * Uranus.Radius = Distance.ToAU(25559);
             * Uranus.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Uranus.Position.System = Sol;
             * Uranus.Position.X = x;
             * Uranus.Position.Y = y;
             * sun.Planets.Add(Uranus);
             *
             * SystemBody Neptune = new SystemBody(sun, SystemBody.PlanetType.IceGiant);
             * Neptune.Name = "Neptune";
             * Neptune.Orbit = Orbit.FromMajorPlanetFormat(102E24, sun.Orbit.Mass, Distance.ToAU(4495.1E6), 0.011, 1.8, 131.72169, 44.97135, 304.88003, GalaxyGen.J2000);
             * Neptune.Radius = Distance.ToAU(24764);
             * Neptune.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Neptune.Position.System = Sol;
             * Neptune.Position.X = x;
             * Neptune.Position.Y = y;
             * sun.Planets.Add(Neptune);
             *
             * SystemBody Pluto = new SystemBody(sun, SystemBody.PlanetType.DwarfPlanet);
             * Pluto.Name = "Pluto";
             * Pluto.Orbit = Orbit.FromMajorPlanetFormat(0.0131E24, sun.Orbit.Mass, Distance.ToAU(5906.38E6), 0.24880766, 17.14175, 110.30347, 224.06676, 238.92881, GalaxyGen.J2000);
             * Pluto.Radius = Distance.ToAU(1195);
             * Pluto.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Pluto.Position.System = Sol;
             * Pluto.Position.X = x;
             * Pluto.Position.Y = y;
             * sun.Planets.Add(Pluto);
             *
             * GenerateJumpPoints(Sol);
             *
             * // Clean up cached RNG:
             * m_RNG = null;
             * GameState.Instance.StarSystems.Add(Sol);
             * GameState.Instance.StarSystemCurrentIndex++;
             */

            /*
             * double planetSemiMajAxis = 0.387098;
             * double planetEccentricity = 0.205630;
             * double planetInclination = 0;
             * double planetLoAN = 0;//48.33167;
             * double planetLoP = 0;//77.45645;
             * double planetMeanLongd = 252.25084;
             *
             * EMWaveForm waveform;
             *
             * for (int i = 0; i < 8; i++)
             * {
             *  NameDB planetNameDB = new NameDB("planetE" + i);
             *
             *  SystemBodyInfoDB planetBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true };
             *  MassVolumeDB planetMVDB = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7));
             *  PositionDB planetPositionDB = new PositionDB(sol.ID);
             *  planetEccentricity = i * 2 / 16.0;
             *  OrbitDB planetOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, planetMVDB.Mass, planetSemiMajAxis, planetEccentricity, planetInclination, planetLoAN, planetLoP, planetMeanLongd, GalaxyGen.Settings.J2000);
             *  planetPositionDB.AbsolutePosition = OrbitProcessor.GetPosition(planetOrbitDB, game.CurrentDateTime);
             *
             *  waveform = new EMWaveForm()
             *  {
             *      WavelengthAverage_nm = 600,
             *      WavelengthMin_nm = 600 - 400, //4k angstrom, semi arbitrary number pulled outa my ass from 0min of internet research.
             *      WavelengthMax_nm = 600 + 600
             *  };
             *
             *  sensorProfile = new SensorProfileDB();
             *  sensorProfile.EmittedEMSpectra.Add(waveform, 3.827e23);
             *  Entity planet = new Entity(sol, new List<BaseDataBlob> { sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetNameDB, planetOrbitDB });
             * }
             *
             * planetEccentricity = 0.9;
             * for (int i = 0; i < 8; i++)
             * {
             *  NameDB planetNameDB = new NameDB("planetL" + i);
             *  SystemBodyInfoDB planetBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true };
             *  MassVolumeDB planetMVDB = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7));
             *  PositionDB planetPositionDB = new PositionDB(sol.ID);
             *  planetLoP = i * 15;
             *  OrbitDB planetOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, planetMVDB.Mass, planetSemiMajAxis, planetEccentricity, planetInclination, planetLoAN, planetLoP, planetMeanLongd, GalaxyGen.Settings.J2000);
             *  planetPositionDB.AbsolutePosition = OrbitProcessor.GetPosition(planetOrbitDB, game.CurrentDateTime);
             *
             *  waveform = new EMWaveForm()
             *  {
             *      WavelengthAverage_nm = 600,
             *      WavelengthMin_nm = 600 - 400, //4k angstrom, semi arbitrary number pulled outa my ass from 0min of internet research.
             *      WavelengthMax_nm = 600 + 600
             *  };
             *
             *  sensorProfile = new SensorProfileDB();
             *  sensorProfile.EmittedEMSpectra.Add(waveform, 3.827e23);
             *  Entity planet = new Entity(sol, new List<BaseDataBlob> {sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetNameDB, planetOrbitDB });
             * }
             */

            JPSurveyFactory.GenerateJPSurveyPoints(sol);

            game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid);
            return(sol);
        }
Example #8
0
        /*
         * public TimeSpan RunFrequency => TimeSpan.FromMinutes(60);
         *
         * public void ProcessEntity(Entity entity, int deltaSeconds)
         * {
         *  SetEntityProfile(entity);
         * }
         *
         * public void ProcessManager(EntityManager manager, int deltaSeconds)
         * {
         *  Stopwatch timer = new Stopwatch();
         *  timer.Start();
         *  var entites = manager.GetAllEntitiesWithDataBlob<SensorProfileDB>();
         *  foreach (var entity in entites)
         *  {
         *      ProcessEntity(entity, deltaSeconds);
         *  }
         *  var ms = timer.ElapsedMilliseconds;
         *  var numEntites = entites.Count;
         * }
         */

        public static void SetEntityProfile(Entity entity, DateTime atDate)
        {
            var position  = entity.GetDataBlob <PositionDB>();
            var sensorSig = entity.GetDataBlob <SensorProfileDB>();

            sensorSig.LastPositionOfReflectionSet = position.AbsolutePosition_AU;
            sensorSig.LastDatetimeOfReflectionSet = atDate;

            var emmiters          = entity.Manager.GetAllEntitiesWithDataBlob <SensorProfileDB>();
            int numberOfEmmitters = emmiters.Count;

            sensorSig.ReflectedEMSpectra.Clear();

            //PercentValue reflectionPercent = 0.1f; //TODO: this should be calculated from crossSection(size), and a reflectivity value(stealth armor?/ other design factors?).
            var    surfaceArea          = sensorSig.TargetCrossSection_msq;
            double reflectionCoefficent = surfaceArea * sensorSig.Reflectivity;

            foreach (var emittingEntity in emmiters)
            {
                if (emittingEntity != entity) // don't reflect our own emmision.
                {
                    double distance    = PositionDB.GetDistanceBetween_m(position, emittingEntity.GetDataBlob <PositionDB>());
                    var    emmissionDB = emittingEntity.GetDataBlob <SensorProfileDB>();

                    foreach (var emitedItem in emmissionDB.EmittedEMSpectra)
                    {
                        var attenuated         = SensorProcessorTools.AttenuationCalc(emitedItem.Value, distance);
                        var reflectedMagnatude = attenuated * reflectionCoefficent;

                        if (reflectedMagnatude > 0.001) //ignore it if the signal is less than a watt
                        {
                            if (sensorSig.ReflectedEMSpectra.ContainsKey(emitedItem.Key))
                            {
                                sensorSig.ReflectedEMSpectra[emitedItem.Key] = sensorSig.ReflectedEMSpectra[emitedItem.Key] + reflectedMagnatude;
                            }
                            else
                            {
                                sensorSig.ReflectedEMSpectra.Add(emitedItem.Key, reflectedMagnatude);
                            }
                        }



                        //debug code:
                        if (emitedItem.Value < 0)
                        {
                            throw new Exception("Source should not be less than 0");
                        }
                        if (attenuated > emitedItem.Value)
                        {
                            throw new Exception("Attenuated value shoudl be less than source");
                        }
                        if (reflectedMagnatude > emitedItem.Value)
                        {
                            throw new Exception("final magnitude shoudl not be more than source");
                        }
                        if (reflectedMagnatude < 0)
                        {
                            throw new Exception("Final magnitude should not be less than 0");
                        }
                    }
                }
            }
        }
Example #9
0
        //TODO: ReWrite this, instead of each component trying to do a scan,
        //multiple components should mix together to form a single suite and the ship itself should scan.
        //maybe the scan freqency /attribute.scanTime should just effect the chance of a detection.
        internal override void ProcessEntity(Entity entity, DateTime atDateTime)
        {
            EntityManager manager = entity.Manager;
            Entity        faction;// = entity.GetDataBlob<OwnedDB>().OwnedByFaction;

            entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction);


            var detectableEntitys = manager.GetAllEntitiesWithDataBlob <SensorProfileDB>();

            var position = entity.GetDataBlob <PositionDB>(); //recever is a componentDB. not a shipDB

            if (position == null)                             //then it's probilby a colony
            {
                position = entity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <PositionDB>();
            }

            if (entity.GetDataBlob <ComponentInstancesDB>().TryGetComponentsByAttribute <SensorReceverAtbDB>(out var recevers))
            {
                foreach (var recever in recevers)
                {
                    var ability   = recever.GetAbilityState <SensorReceverAbility>();
                    var attribute = recever.Design.GetAttribute <SensorReceverAtbDB>();

                    //SensorReceverAtbDB receverDB = designEntity.GetDataBlob<SensorReceverAtbDB>();

                    FactionInfoDB factionInfo = faction.GetDataBlob <FactionInfoDB>();


                    SystemSensorContacts sensorMgr;
                    if (!manager.FactionSensorContacts.ContainsKey(entity.FactionOwner))
                    {
                        sensorMgr = new SystemSensorContacts(manager, faction);
                    }
                    else
                    {
                        sensorMgr = manager.FactionSensorContacts[entity.FactionOwner];
                    }

                    foreach (var detectableEntity in detectableEntitys)
                    {
                        //Entity detectableEntity = sensorProfile.OwningEntity;

                        if (detectableEntity.FactionOwner != Guid.Empty)
                        {
                            if (detectableEntity.FactionOwner != faction.Guid)
                            {
                                SensorProcessorTools.DetectEntites(sensorMgr, factionInfo, position, attribute, detectableEntity, atDateTime);
                            }
                            else
                            {
                                //then the sensor profile belongs to the same faction as the recever. don't bother trying to detect it.
                            }
                        }
                        else
                        {
                            SensorProcessorTools.DetectEntites(sensorMgr, factionInfo, position, attribute, detectableEntity, atDateTime);
                        }
                    }
                    manager.ManagerSubpulses.AddEntityInterupt(atDateTime + TimeSpan.FromSeconds(attribute.ScanTime), this.TypeName, entity);
                }
            }
        }
Example #10
0
        //TODO: ReWrite this, instead of each component trying to do a scan,
        //multiple components should mix together to form a single suite and the ship itself should scan.
        //maybe the scan freqency /attribute.scanTime should just effect the chance of a detection.
        internal override void ProcessEntity(Entity entity, DateTime atDateTime)
        {
            EntityManager manager = entity.Manager;
            Entity        faction;// = entity.GetDataBlob<OwnedDB>().OwnedByFaction;

            entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction);


            var detectableEntitys = manager.GetAllEntitiesWithDataBlob <SensorProfileDB>();

            var position = entity.GetDataBlob <PositionDB>(); //recever is a componentDB. not a shipDB

            if (position == null)                             //then it's probilby a colony
            {
                position = entity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <PositionDB>();
            }

            if (entity.GetDataBlob <ComponentInstancesDB>().TryGetComponentsByAttribute <SensorReceverAtbDB>(out var recevers))
            {
                foreach (var recever in recevers)
                {
                    var sensorAbl = recever.GetAbilityState <SensorReceverAbility>();
                    var sensorAtb = recever.Design.GetAttribute <SensorReceverAtbDB>();

                    FactionInfoDB factionInfo = faction.GetDataBlob <FactionInfoDB>();


                    SystemSensorContacts sensorMgr;
                    if (!manager.FactionSensorContacts.ContainsKey(entity.FactionOwner))
                    {
                        sensorMgr = new SystemSensorContacts(manager, faction);
                    }
                    else
                    {
                        sensorMgr = manager.FactionSensorContacts[entity.FactionOwner];
                    }


                    var          detections = SensorProcessorTools.GetDetectedEntites(sensorAtb, position.AbsolutePosition_m, detectableEntitys, atDateTime, faction.Guid, true);
                    SensorInfoDB sensorInfo;
                    for (int i = 0; i < detections.Length; i++)
                    {
                        SensorProcessorTools.SensorReturnValues detectionValues;
                        detectionValues = detections[i];
                        var detectableEntity = detectableEntitys[i];
                        if (detectionValues.SignalStrength_kW > 0.0)
                        {
                            if (sensorMgr.SensorContactExists(detectableEntity.Guid))
                            {
                                //sensorInfo = knownContacts[detectableEntity.ID].GetDataBlob<SensorInfoDB>();
                                sensorInfo = sensorMgr.GetSensorContact(detectableEntity.Guid).SensorInfo;
                                sensorInfo.LatestDetectionQuality = detectionValues;
                                sensorInfo.LastDetection          = atDateTime;
                                if (sensorInfo.HighestDetectionQuality.SignalQuality < detectionValues.SignalQuality)
                                {
                                    sensorInfo.HighestDetectionQuality.SignalQuality = detectionValues.SignalQuality;
                                }

                                if (sensorInfo.HighestDetectionQuality.SignalStrength_kW < detectionValues.SignalStrength_kW)
                                {
                                    sensorInfo.HighestDetectionQuality.SignalStrength_kW = detectionValues.SignalStrength_kW;
                                }
                                SensorEntityFactory.UpdateSensorContact(faction, sensorInfo);
                            }
                            else
                            {
                                SensorContact contact = new SensorContact(faction, detectableEntity, atDateTime);
                                sensorMgr.AddContact(contact);
                                sensorAbl.CurrentContacts[detectableEntity.Guid] = detectionValues;

                                //knownContacts.Add(detectableEntity.ID, SensorEntityFactory.UpdateSensorContact(receverFaction, sensorInfo)); moved this line to the SensorInfoDB constructor
                            }
                        }
                        else if (sensorMgr.SensorContactExists(detectableEntity.Guid) && sensorAbl.CurrentContacts.ContainsKey(detectableEntity.Guid))
                        {
                            sensorAbl.CurrentContacts.Remove(detectableEntity.Guid);
                            sensorAbl.OldContacts[detectableEntity.Guid] = detectionValues;
                        }
                    }

                    manager.ManagerSubpulses.AddEntityInterupt(atDateTime + TimeSpan.FromSeconds(sensorAtb.ScanTime), this.TypeName, entity);
                }
            }
        }
Example #11
0
        /*
         * public TimeSpan RunFrequency => TimeSpan.FromMinutes(60);
         *
         * public void ProcessEntity(Entity entity, int deltaSeconds)
         * {
         *  SetEntityProfile(entity);
         * }
         *
         * public void ProcessManager(EntityManager manager, int deltaSeconds)
         * {
         *  Stopwatch timer = new Stopwatch();
         *  timer.Start();
         *  var entites = manager.GetAllEntitiesWithDataBlob<SensorProfileDB>();
         *  foreach (var entity in entites)
         *  {
         *      ProcessEntity(entity, deltaSeconds);
         *  }
         *  var ms = timer.ElapsedMilliseconds;
         *  var numEntites = entites.Count;
         * }
         */

        public static void SetEntityProfile(Entity entity, DateTime atDate)
        {
            var position  = entity.GetDataBlob <PositionDB>();
            var sensorSig = entity.GetDataBlob <SensorProfileDB>();

            sensorSig.LastPositionOfReflectionSet = position.AbsolutePosition_AU;
            sensorSig.LastDatetimeOfReflectionSet = atDate;

            var emmiters          = entity.Manager.GetAllEntitiesWithDataBlob <SensorProfileDB>();
            int numberOfEmmitters = emmiters.Count;

            sensorSig.ReflectedEMSpectra.Clear();

            //PercentValue reflectionPercent = 0.1f; //TODO: this should be calculated from crossSection(size), and a reflectivity value(stealth armor?/ other design factors?).
            //var surfaceArea = sensorSig.TargetCrossSection_msq;

            double tRad = 500;

            if (entity.HasDataBlob <MassVolumeDB>())
            {
                tRad = entity.GetDataBlob <MassVolumeDB>().RadiusInM;
            }



            foreach (var emittingEntity in emmiters)
            {
                if (emittingEntity != entity) // don't reflect our own emmision.
                {
                    double distance = PositionDB.GetDistanceBetween_m(position, emittingEntity.GetDataBlob <PositionDB>());
                    if (distance < 1)
                    {
                        distance = 1;
                    }

                    var    drad                 = Math.Sin(tRad / distance);
                    var    srad                 = Math.Sin(drad) * tRad;
                    var    surfaceArea          = Math.PI * srad * srad;
                    double reflectionCoefficent = surfaceArea * sensorSig.Reflectivity;


                    var emmissionDB = emittingEntity.GetDataBlob <SensorProfileDB>();

                    foreach (var emitedItem in emmissionDB.EmittedEMSpectra)
                    {
                        var attenuated         = SensorProcessorTools.AttenuationCalc(emitedItem.Value, distance);//per meter^2
                        var reflectedMagnatude = attenuated * reflectionCoefficent;


                        //debug code:
                        if (emitedItem.Value < 0)
                        {
                            throw new Exception("Source should not be less than 0");
                        }
                        if (attenuated > emitedItem.Value)
                        {
                            throw new Exception("Attenuated value shoudl be less than source");
                        }
                        if (reflectedMagnatude > emitedItem.Value)
                        {
                            var source  = Stringify.Power(emitedItem.Value);
                            var reflec  = Stringify.Power(reflectedMagnatude);
                            var dist    = Stringify.Distance(distance);
                            var surface = Stringify.Distance(surfaceArea);
                            var dif     = Stringify.Power(emitedItem.Value - reflectedMagnatude);
                            //throw new Exception("final magnitude shoudl not be more than source");
                            //TODO: there's got to be a better way of calculating this. for now I'm just going to hack it.

                            reflectedMagnatude = emitedItem.Value * sensorSig.Reflectivity;
                        }
                        if (reflectedMagnatude < 0)
                        {
                            throw new Exception("Final magnitude should not be less than 0");
                        }



                        if (reflectedMagnatude > 0.001) //ignore it if the signal is less than a watt
                        {
                            if (sensorSig.ReflectedEMSpectra.ContainsKey(emitedItem.Key))
                            {
                                sensorSig.ReflectedEMSpectra[emitedItem.Key] = sensorSig.ReflectedEMSpectra[emitedItem.Key] + reflectedMagnatude;
                            }
                            else
                            {
                                sensorSig.ReflectedEMSpectra.Add(emitedItem.Key, reflectedMagnatude);
                            }
                        }
                    }
                }
            }
        }