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 } } }
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); }
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 } } }