예제 #1
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);
                }
            }
        }
예제 #2
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
                }
            }
        }
예제 #3
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);
                }
            }
        }