public BaseDataBlob SensorClone(SensorInfoDB sensorInfo) { if (this.Parent != null) { Entity cloneParent; if (this.Parent.HasDataBlob <SensorInfoDB>()) { cloneParent = this.Parent; } else { if (sensorInfo.Faction.GetDataBlob <FactionInfoDB>().SensorEntites.ContainsKey(this.Parent.Guid)) { cloneParent = sensorInfo.Faction.GetDataBlob <FactionInfoDB>().SensorEntites[this.Parent.Guid]; } else { SensorInfoDB parentSensorInfo = new SensorInfoDB(sensorInfo.Faction, this.Parent, sensorInfo.LastDetection); cloneParent = SensorEntityFactory.UpdateSensorContact(sensorInfo.Faction, parentSensorInfo); } } return(new OrbitDB(this, sensorInfo, cloneParent)); } return(new OrbitDB(this, sensorInfo, null)); //the root sun will not have an orbitDB parent. }
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 } } }
internal SensorInfoDB(Entity factionEntity, Entity detectedEntity, DateTime atDate) { Faction = factionEntity; DetectedEntity = detectedEntity; LastDetection = atDate; factionEntity.GetDataBlob <FactionInfoDB>().SensorEntites.Add(detectedEntity.Guid, SensorEntityFactory.UpdateSensorContact(factionEntity, this)); }
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 } } }
//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); } } }