/* * 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_AU(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); } } } }
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 } } }