Exemplo n.º 1
0
 public SensorReceverAtbDB(SensorReceverAtbDB db)
 {
     RecevingWaveformCapabilty = db.RecevingWaveformCapabilty;
     BestSensitivity_kW        = db.BestSensitivity_kW;
     WorstSensitivity_kW       = db.WorstSensitivity_kW;
     Resolution = db.Resolution;
     ScanTime   = db.ScanTime;
 }
Exemplo n.º 2
0
        internal static void DetectEntites(SensorReceverAtbDB receverDB, Entity detectableEntity, DateTime atDate)
        {
            Entity receverFaction = receverDB.OwningEntity.GetDataBlob <OwnedDB>().OwnedByFaction;
            var    knownContacts  = receverFaction.GetDataBlob <FactionInfoDB>().SensorEntites;

            SensorProfileDB sensorProfile = detectableEntity.GetDataBlob <SensorProfileDB>();

            TimeSpan   timeSinceLastCalc         = atDate - sensorProfile.LastDatetimeOfReflectionSet;
            PositionDB positionOfSensorProfile   = detectableEntity.GetDataBlob <PositionDB>();//sensorProfile.OwningEntity.GetDataBlob<ComponentInstanceInfoDB>().ParentEntity.GetDataBlob<PositionDB>();
            double     distanceInAUSinceLastCalc = PositionDB.GetDistanceBetween(sensorProfile.LastPositionOfReflectionSet, positionOfSensorProfile);

            //Only set the reflectedEMProfile of the target if it's not been done recently:
            //TODO: is this still neccicary now that I've found and fixed the loop? (refelctions were getting bounced around)
            if (timeSinceLastCalc > TimeSpan.FromMinutes(30) || distanceInAUSinceLastCalc > 0.1) //TODO: move the time and distance numbers here to settings?
            {
                SetReflectedEMProfile.SetEntityProfile(detectableEntity, atDate);
            }

            SensorReturnValues detectionValues = DetectonQuality(receverDB, sensorProfile);
            SensorInfoDB       sensorInfo;

            if (detectionValues.SignalStrength_kW > 0.0)
            {
                if (knownContacts.ContainsKey(detectableEntity.Guid))
                {
                    sensorInfo = knownContacts[detectableEntity.Guid].GetDataBlob <SensorInfoDB>();
                    sensorInfo.LatestDetectionQuality = detectionValues;
                    sensorInfo.LastDetection          = atDate;
                    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(receverFaction, sensorInfo);
                }
                else
                {
                    sensorInfo = new SensorInfoDB(receverFaction, detectableEntity, atDate);

                    //knownContacts.Add(detectableEntity.Guid, SensorEntityFactory.UpdateSensorContact(receverFaction, sensorInfo)); moved this line to the SensorInfoDB constructor
                }
            }
        }
Exemplo n.º 3
0
        public static SensorReturnValues[] GetDetectedEntites(SensorReceverAtbDB sensorAtb, Vector3 position, List <Entity> detectableEntities, DateTime atDate, Guid factionOwner, bool filterSameFaction = true)
        {
            SensorReturnValues[] detectionValues = new SensorReturnValues[detectableEntities.Count];
            for (int i = 0; i < detectableEntities.Count; i++)
            {
                var detectableEntity = detectableEntities[i];
                if (filterSameFaction && detectableEntity.FactionOwner == factionOwner)
                {
                    continue;
                }
                else
                {
                    SensorProfileDB detectableProfile = detectableEntity.GetDataBlob <SensorProfileDB>();
                    PositionDB      detectablePosDB   = detectableEntity.GetDataBlob <PositionDB>();
                    if (detectablePosDB == null)
                    {
                        StaticRefLib.EventLog.AddEvent(new Event("Error: Attempt to get a sensor position on a positionless entity, ID: " + detectableEntity.Guid));
                        continue;
                    }

                    //TODO: check if the below actualy saves us anything. it might be better just to seperatly loop through each of the entites and set the reflection profiles every so often..
                    TimeSpan timeSinceLastCalc     = atDate - detectableProfile.LastDatetimeOfReflectionSet;
                    double   distanceSinceLastCalc = detectablePosDB.GetDistanceTo_m(detectableProfile.LastPositionOfReflectionSet);
                    if (timeSinceLastCalc > TimeSpan.FromMinutes(30) || distanceSinceLastCalc > 5000) //TODO: move the time and distance numbers here to settings?
                    {
                        SetReflectedEMProfile.SetEntityProfile(detectableEntity, atDate);
                    }

                    var distance                      = detectablePosDB.GetDistanceTo_m(position);
                    var attentuatedSignal             = AttenuatedForDistance(detectableProfile, distance);
                    SensorReturnValues detectionValue = DetectonQuality(sensorAtb, attentuatedSignal);
                    //if(detectionValue.SignalStrength_kW > 0)
                    detectionValues[i] = detectionValue;
                }
            }

            return(detectionValues);
        }
Exemplo n.º 4
0
        internal static SensorReturnValues DetectonQuality(SensorReceverAtbDB recever, SensorProfileDB target)
        {
            /*
             * Thoughts (spitballing):
             *
             * What we need:
             * detect enough of a signal to get a position
             * decide what "enough" is. probibly get this from the signal strength. - should the target SensorSigDB define what enough is?
             * we could require more than one detection (ie two ships in different locations) to get an acurate position, but that could get tricky to code.
             * and how would we display a non acurate position? maybe a line out to a question mark, showing the angle of detection but not range?
             *
             * detect enough of a signal to get intel if it's a ship
             * decide what "enough" for this is. maybe compare the detected waveform and the emited waveform and compare the angles to see if the triangle is simular.
             *
             * it'd be nifty if we could include background noise in there too, ie so ships close to a sun would be hidden.
             * also have resoulution be required to pick out multiple ships close together instead of just one big signal.
             *
             * With range attenuation, we'll never get the full signal uneless we're right ontop of it.
             * maybe if we get half the emited strength and its a simular triange (all same angles) we get "Full" intel?
             *
             * should we add time into the mix as well? multiple detections over a given time period to get position/velocity/orbitDB?
             *
             *
             * how are multiple components on a ship going to work? they are entitys in and of themselfs, so they could have a SensorSigDB all of thier own.
             * that could help with getting intel on individual components of a target.
             *
             * recever resolution should play into how much gets detected.
             *
             * Note that each entity will(may) have multiple waveforms.
             *
             * Data that can be glened from this detection system:
             * detectedStrength (altitide of the intersecting triangle)
             * detectedArea - the area of the detected intersection, could compare this to the target signal as well.
             * compare angles of the detected intersection and the target signal to see if the shape is simular?
             * if range is known acurately, this could affect the intel gathered.
             */
            var        myPosition = recever.OwningEntity.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity.GetDataBlob <PositionDB>();//recever is a componentDB. not a shipDB
            PositionDB targetPosition;

            if (target.OwningEntity.HasDataBlob <PositionDB>())
            {
                targetPosition = target.OwningEntity.GetDataBlob <PositionDB>();
            }
            else
            {
                targetPosition = target.OwningEntity.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity.GetDataBlob <PositionDB>();//target may be a componentDB. not a shipDB
            }
            double distance = PositionDB.GetDistanceBetween(myPosition, targetPosition);

            var detectionResolution = recever.Resolution;

            var signalAtPosition = AttenuatedForDistance(target, distance);

            double       receverSensitivityFreqMin   = recever.RecevingWaveformCapabilty.WavelengthMin_nm;
            double       receverSensitivityFreqAvg   = recever.RecevingWaveformCapabilty.WavelengthAverage_nm;
            double       receverSensitivityFreqMax   = recever.RecevingWaveformCapabilty.WavelengthMax_nm;
            double       receverSensitivityBest      = recever.BestSensitivity_kW;
            double       receverSensitivityAltitiude = recever.BestSensitivity_kW - recever.WorstSensitivity_kW;
            PercentValue quality           = new PercentValue(0.0f);
            double       detectedMagnatude = 0;

            foreach (var waveSpectra in signalAtPosition)
            {
                double signalWaveSpectraFreqMin      = waveSpectra.Key.WavelengthMin_nm;
                double signalWaveSpectraFreqAvg      = waveSpectra.Key.WavelengthAverage_nm;
                double signalWaveSpectraFreqMax      = waveSpectra.Key.WavelengthMax_nm;
                double signalWaveSpectraMagnatude_kW = waveSpectra.Value;



                if (signalWaveSpectraMagnatude_kW > recever.BestSensitivity_kW) //check if the sensitivy is enough to pick anything up at any frequency.
                {
                    if (Math.Max(receverSensitivityFreqMin, signalWaveSpectraFreqMin) < Math.Max(signalWaveSpectraFreqMin, signalWaveSpectraFreqMax))
                    {
                        //we've got something we can detect
                        double minDetectableWavelength = Math.Min(receverSensitivityFreqMin, signalWaveSpectraFreqMin);
                        double maxDetectableWavelenght = Math.Min(receverSensitivityFreqMax, signalWaveSpectraFreqMax);

                        double detectedAngleA = Math.Atan(receverSensitivityAltitiude / (receverSensitivityFreqAvg - receverSensitivityFreqMin));
                        double receverBaseLen = maxDetectableWavelenght - minDetectableWavelength;
                        double detectedAngleB = Math.Atan(signalWaveSpectraMagnatude_kW / (signalWaveSpectraFreqAvg - signalWaveSpectraFreqMax));

                        bool   doesIntersect;
                        double intersectPointX;
                        double intersectPointY;
                        double distortion;

                        if (signalWaveSpectraFreqAvg < receverSensitivityFreqAvg)  //RightsideDetection (recever's ideal wavelenght is higher than the signal wavelenght at it's loudest)
                        {
                            doesIntersect = Get_line_intersection(
                                signalWaveSpectraFreqAvg, signalWaveSpectraMagnatude_kW,
                                signalWaveSpectraFreqMin, 0,

                                receverSensitivityFreqAvg, recever.BestSensitivity_kW,
                                receverSensitivityFreqMax, recever.WorstSensitivity_kW,

                                out intersectPointX, out intersectPointY);
                            //offsetFromCenter = intersectPointX - signalWaveSpectraFreqAvg; //was going to use this for distortion but decided to simplify.
                            distortion = receverSensitivityFreqAvg - signalWaveSpectraFreqAvg;
                        }
                        else                                                        //LeftSideDetection
                        {
                            doesIntersect = Get_line_intersection(
                                signalWaveSpectraFreqAvg, signalWaveSpectraMagnatude_kW,
                                signalWaveSpectraFreqMax, 0,

                                receverSensitivityFreqAvg, recever.BestSensitivity_kW,
                                receverSensitivityFreqMin, recever.WorstSensitivity_kW,

                                out intersectPointX, out intersectPointY);
                            //offsetFromCenter = intersectPointX - signalWaveSpectraFreqAvg;
                            distortion = signalWaveSpectraFreqAvg - receverSensitivityFreqAvg;
                        }

                        if (doesIntersect) // then we're not detecting the peak of the signal
                        {
                            detectedMagnatude = intersectPointY - recever.BestSensitivity_kW;
                            distortion       *= 2; //pentalty to quality of signal
                        }
                        else
                        {
                            detectedMagnatude = signalWaveSpectraMagnatude_kW - recever.BestSensitivity_kW;
                        }

                        quality = new PercentValue((float)(100 - distortion / signalWaveSpectraFreqMax));
                    }
                }
            }



            return(new SensorReturnValues()
            {
                SignalStrength_kW = detectedMagnatude,
                SignalQuality = quality
            });
        }
Exemplo n.º 5
0
        internal static void DetectEntites(SystemSensorContacts sensorMgr, FactionInfoDB factionInfo, PositionDB receverPos, SensorReceverAtbDB receverDB, Entity detectableEntity, DateTime atDate)
        {
            Entity receverFaction = sensorMgr.FactionEntity;
            //Entity receverFaction;// = receverDB.OwningEntity.GetDataBlob<OwnedDB>().OwnedByFaction;
            //detectableEntity.Manager.FindEntityByGuid(receverDB.OwningEntity.FactionOwner, out receverFaction);
            var knownContacts  = factionInfo.SensorContacts; //receverFaction.GetDataBlob<FactionInfoDB>().SensorEntites;
            var knownContacts1 = sensorMgr.GetAllContacts();


            SensorProfileDB sensorProfile = detectableEntity.GetDataBlob <SensorProfileDB>();

            TimeSpan   timeSinceLastCalc       = atDate - sensorProfile.LastDatetimeOfReflectionSet;
            PositionDB positionOfSensorProfile = detectableEntity.GetDataBlob <PositionDB>();//sensorProfile.OwningEntity.GetDataBlob<ComponentInstanceInfoDB>().ParentEntity.GetDataBlob<PositionDB>();
            double     distanceSinceLastCalc   = PositionDB.GetDistanceBetween_m(sensorProfile.LastPositionOfReflectionSet, positionOfSensorProfile);

            //Only set the reflectedEMProfile of the target if it's not been done recently:
            //TODO: is this still neccicary now that I've found and fixed the loop? (refelctions were getting bounced around)
            if (timeSinceLastCalc > TimeSpan.FromMinutes(30) || distanceSinceLastCalc > 5000) //TODO: move the time and distance numbers here to settings?
            {
                SetReflectedEMProfile.SetEntityProfile(detectableEntity, atDate);
            }



            PositionDB targetPosition;

            if (detectableEntity.HasDataBlob <PositionDB>())
            {
                targetPosition = detectableEntity.GetDataBlob <PositionDB>();
            }
            else
            {
                throw new NotImplementedException("This might be a colony on a planet, not sure how I'll handle that yet");
            }

            var distance = PositionDB.GetDistanceBetween_AU(receverPos, targetPosition);
            SensorReturnValues detectionValues = DetectonQuality(receverDB, AttenuatedForDistance(sensorProfile, distance));
            SensorInfoDB       sensorInfo;

            if (detectionValues.SignalStrength_kW > 0.0)
            {
                if (sensorMgr.SensorContactExists(detectableEntity.Guid))
                {
                    //sensorInfo = knownContacts[detectableEntity.Guid].GetDataBlob<SensorInfoDB>();
                    sensorInfo = sensorMgr.GetSensorContact(detectableEntity.Guid).SensorInfo;
                    sensorInfo.LatestDetectionQuality = detectionValues;
                    sensorInfo.LastDetection          = atDate;
                    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(receverFaction, sensorInfo);
                }
                else
                {
                    SensorContact contact = new SensorContact(receverFaction, detectableEntity, atDate);
                    sensorMgr.AddContact(contact);


                    //knownContacts.Add(detectableEntity.Guid, SensorEntityFactory.UpdateSensorContact(receverFaction, sensorInfo)); moved this line to the SensorInfoDB constructor
                }
            }
        }
Exemplo n.º 6
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, DateTime atDateTime)
        {
            EntityManager manager = entity.Manager;
            Entity        faction;// = entity.GetDataBlob<OwnedDB>().OwnedByFaction;

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

            var designEntity             = entity.GetDataBlob <ComponentInstanceInfoDB>().DesignEntity;
            SensorReceverAtbDB receverDB = designEntity.GetDataBlob <SensorReceverAtbDB>();

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

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

            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)
                    {
                        var position = entity.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity.GetDataBlob <PositionDB>(); //recever is a componentDB. not a shipDB
                        if (position == null)                                                                                  //then it's probilby a colony
                        {
                            position = entity.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <PositionDB>();
                        }

                        SensorProcessorTools.DetectEntites(sensorMgr, factionInfo, position, receverDB, detectableEntity, atDateTime);
                    }
                    else
                    {
                        //then the sensor profile belongs to the same faction as the recever. don't bother trying to detect it.
                    }
                }
                else
                {
                    var position = entity.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity.GetDataBlob <PositionDB>(); //recever is a componentDB. not a shipDB
                    if (position == null)                                                                                  //then it's probilby a colony
                    {
                        position = entity.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <PositionDB>();
                    }

                    SensorProcessorTools.DetectEntites(sensorMgr, factionInfo, position, receverDB, detectableEntity, atDateTime);
                }
            }



            manager.ManagerSubpulses.AddEntityInterupt(atDateTime + TimeSpan.FromSeconds(receverDB.ScanTime), this.TypeName, entity);
        }