public override void Render() { switch (m_oSystemContect.SSEntity) { case StarSystemEntityType.TaskGroup: TaskGroupTN TaskGroup = m_oSystemContect.Entity as TaskGroupTN; /// <summary> /// Update this contact's sensor elements. /// </summary> if (TaskGroup.SensorUpdateAck != _LastSensorUpdateAck) { /// <summary> /// Get rid of all sensors if this taskgroup is empty. a SensorUpdateAck should be sent upon emptying a tg into another tg. /// </summary> if (TaskGroup.Ships.Count == 0) { _SensorContactElements.Clear(); } /// <summary> /// Remove those sensors that are no longer active. /// </summary> BindingList <Guid> SensorRemoveList = new BindingList <Guid>(); foreach (KeyValuePair <Guid, SensorElement> SCE in _SensorContactElements) { switch (SCE.Value._sensorType) { case ComponentTypeTN.ActiveSensor: ActiveSensorTN aSensor = (SCE.Value.SceenEntity as ActiveSensorTN); if (aSensor.isActive == false || aSensor.isDestroyed == true || ParentSceen.ShowActives == false) { SensorRemoveList.Add(SCE.Key); } break; case ComponentTypeTN.PassiveSensor: PassiveSensorTN pSensor = (SCE.Value.SceenEntity as PassiveSensorTN); /// <summary> /// Remove this sensor if it is destroyed, or if it isn't the current best thermal/em sensor. if a sensor is destroyed it should be replaced as the best em/thermal. /// </summary> if (pSensor != null) { if (pSensor.isDestroyed == true || ParentSceen.ShowPassives == false) { SensorRemoveList.Add(SCE.Key); } else { if (pSensor.pSensorDef.thermalOrEM == PassiveSensorType.Thermal) { if (pSensor != TaskGroup.BestThermal) { SensorRemoveList.Add(SCE.Key); } } else { if (pSensor != TaskGroup.BestEM) { SensorRemoveList.Add(SCE.Key); } } } } else { /// <summary> /// default passives will be null, so that should be handled here. if show passives is off, or a better passive shows up, remove the default passives. /// </summary> if (ParentSceen.ShowPassives == false || TaskGroup.BestThermal != null || TaskGroup.BestEM != null) { SensorRemoveList.Add(SCE.Key); } } break; } } if (SensorRemoveList.Count != 0) { foreach (Guid SCE in SensorRemoveList) { _SensorContactElements.Remove(SCE); } } if (ParentSceen.ShowPassives == true) { if (TaskGroup.Ships.Count != 0) { /// <summary> /// A taskgroup with no sensors still has the default package, so handle that. A taskgroup with no ships should not have a sensor presence however. /// </summary> if (TaskGroup.BestEM == null && _SensorContactElements.ContainsKey(TaskGroup.Id) == false) { PassiveSensorDefTN pSensorDef = TaskGroup.TaskGroupFaction.ComponentList.DefaultPassives; double factor = Constants.Units.KmPerAu / Constants.GameConstants.BasicUnitOfDistance; double AURadius = (double)pSensorDef.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 TGPos = new Vector3((float)TaskGroup.Contact.Position.X, (float)TaskGroup.Contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, TGPos, (float)AURadius, System.Drawing.Color.Blue, "", null, ComponentTypeTN.PassiveSensor, ParentSceen); //definitely a kludge here to make SCE work with default passives. _SensorContactElements.Add(TaskGroup.Id, NSE); } else if (TaskGroup.BestEM != null && _SensorContactElements.ContainsKey(TaskGroup.BestEM.pSensorDef.Id) == false) { PassiveSensorDefTN pSensorDef = TaskGroup.BestEM.pSensorDef; double factor = Constants.Units.KmPerAu / Constants.GameConstants.BasicUnitOfDistance; double AURadius = (double)pSensorDef.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 TGPos = new Vector3((float)TaskGroup.Contact.Position.X, (float)TaskGroup.Contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, TGPos, (float)AURadius, System.Drawing.Color.Blue, TaskGroup.BestEM.Name, TaskGroup.BestEM, TaskGroup.BestEM.pSensorDef.componentType, ParentSceen); _SensorContactElements.Add(TaskGroup.BestEM.pSensorDef.Id, NSE); } /// <summary> /// A taskgroup with no sensors still has the default package, so handle that. /// </summary> if (TaskGroup.BestThermal == null && _SensorContactElements.ContainsKey(TaskGroup.Ships[0].Id) == false) { PassiveSensorDefTN pSensorDef = TaskGroup.TaskGroupFaction.ComponentList.DefaultPassives; double factor = Constants.Units.KmPerAu / Constants.GameConstants.BasicUnitOfDistance; double AURadius = (double)pSensorDef.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 TGPos = new Vector3((float)TaskGroup.Contact.Position.X, (float)TaskGroup.Contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, TGPos, (float)AURadius, System.Drawing.Color.Red, "", null, ComponentTypeTN.PassiveSensor, ParentSceen); //yep, its a kludge. _SensorContactElements.Add(TaskGroup.Ships[0].Id, NSE); } else if (TaskGroup.BestThermal != null && _SensorContactElements.ContainsKey(TaskGroup.BestThermal.pSensorDef.Id) == false) { PassiveSensorDefTN pSensorDef = TaskGroup.BestThermal.pSensorDef; double factor = Constants.Units.KmPerAu / Constants.GameConstants.BasicUnitOfDistance; double AURadius = (double)pSensorDef.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 TGPos = new Vector3((float)TaskGroup.Contact.Position.X, (float)TaskGroup.Contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, TGPos, (float)AURadius, System.Drawing.Color.Red, TaskGroup.BestThermal.Name, TaskGroup.BestThermal, TaskGroup.BestThermal.pSensorDef.componentType, ParentSceen); _SensorContactElements.Add(pSensorDef.Id, NSE); } } } /// <summary> /// Check for newly activated sensors. /// </summary> if (ParentSceen.ShowActives == true) { foreach (ActiveSensorTN Sensor in TaskGroup.ActiveSensorQue) { /// <summary> /// This sensor survived the above cleanup, and is in the sensor contact element list, so don't re check whether it should be here. /// </summary> if (_SensorContactElements.ContainsKey(Sensor.aSensorDef.Id) == true) { continue; } ActiveSensorDefTN SensorDef = Sensor.aSensorDef; double factor = Constants.Units.KmPerAu / Constants.GameConstants.BasicUnitOfDistance; double AURadius = (double)SensorDef.maxRange / factor; Vector3 TGPos = new Vector3((float)TaskGroup.Contact.Position.X, (float)TaskGroup.Contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, TGPos, (float)AURadius, System.Drawing.Color.Turquoise, Sensor.Name, Sensor, Sensor.aSensorDef.componentType, ParentSceen); _SensorContactElements.Add(SensorDef.Id, NSE); } } _LastSensorUpdateAck = TaskGroup.SensorUpdateAck; } break; case StarSystemEntityType.Population: Population CurrentPop = (m_oSystemContect.Entity as Population); /// <summary> /// Populations only have one sensor element. /// </summary> if (CurrentPop._sensorUpdateAck != _LastSensorUpdateAck) { _SensorContactElements.Clear(); int DSTS = (int)Math.Floor(CurrentPop.Installations[(int)Installation.InstallationType.DeepSpaceTrackingStation].Number); if (ParentSceen.ShowPassives == true && DSTS != 0) { /// <summary> /// This calculates the default detection distance for strength 1000 signatures. /// </summary> int SensorTech = CurrentPop.Faction.FactionTechLevel[(int)Faction.FactionTechnology.DSTSSensorStrength]; if (SensorTech > Constants.Colony.DeepSpaceMax) { SensorTech = Constants.Colony.DeepSpaceMax; } #warning if EM strength differs from Thermal handle that here. int ScanStrength = DSTS * Constants.Colony.ThermalDeepSpaceStrength[SensorTech] * 100; double factor = Constants.Units.KmPerAu / Constants.GameConstants.BasicUnitOfDistance; double AURadius = (double)ScanStrength * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 PopPosition = new Vector3((float)CurrentPop.Contact.Position.X, (float)CurrentPop.Contact.Position.Y, 0.0f); /// <summary> /// Type is set to TypeCount because only the taskgroup section requires it. Likewise for CurrentPop, and CurrentPop.Id, these aren't strictly necessary, but the /// taskgroup section requires more information as more sensor contact elements can be associated with a taskgroup. /// </summary> SensorElement NSE = new SensorElement(_DefaultEffect, PopPosition, (float)AURadius, System.Drawing.Color.Purple, CurrentPop.Name + " DSTS Coverage", CurrentPop, ComponentTypeTN.TypeCount, ParentSceen); _SensorContactElements.Add(CurrentPop.Id, NSE); } _LastSensorUpdateAck = CurrentPop._sensorUpdateAck; } break; case StarSystemEntityType.Missile: OrdnanceGroupTN MissileGroup = (m_oSystemContect.Entity as OrdnanceGroupTN); /// <summary> /// This ordnance group was just created, so check whether or not any sensors need to be displayed. Or the display could request that passives or actives not be displayed. /// </summary> if (_LastSensorUpdateAck != MissileGroup._sensorUpdateAck) { _SensorContactElements.Clear(); OrdnanceDefTN OrdDef = MissileGroup.missiles[0].missileDef; if (OrdDef.aSD != null && ParentSceen.ShowActives == true) { double factor = Constants.Units.KmPerAu / Constants.GameConstants.BasicUnitOfDistance; double AURadius = (double)OrdDef.aSD.maxRange / factor; Vector3 MGPos = new Vector3((float)MissileGroup.contact.Position.X, (float)MissileGroup.contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, MGPos, (float)AURadius, System.Drawing.Color.Turquoise, MissileGroup.missiles[0].missileDef.Name + " Active Sensor", MissileGroup, ComponentTypeTN.TypeCount, ParentSceen); _SensorContactElements.Add(OrdDef.aSD.Id, NSE); } if (OrdDef.tHD != null && ParentSceen.ShowPassives == true) { double factor = Constants.Units.KmPerAu / Constants.GameConstants.BasicUnitOfDistance; double AURadius = (double)OrdDef.tHD.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 MGPos = new Vector3((float)MissileGroup.contact.Position.X, (float)MissileGroup.contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, MGPos, (float)AURadius, System.Drawing.Color.Red, MissileGroup.missiles[0].missileDef.Name + " Thermal Sensor", MissileGroup, ComponentTypeTN.TypeCount, ParentSceen); _SensorContactElements.Add(OrdDef.tHD.Id, NSE); } if (OrdDef.eMD != null && ParentSceen.ShowPassives == true) { double factor = Constants.Units.KmPerAu / Constants.GameConstants.BasicUnitOfDistance; double AURadius = (double)OrdDef.eMD.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 MGPos = new Vector3((float)MissileGroup.contact.Position.X, (float)MissileGroup.contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, MGPos, (float)AURadius, System.Drawing.Color.Blue, MissileGroup.missiles[0].missileDef.Name + " EM Sensor", MissileGroup, ComponentTypeTN.TypeCount, ParentSceen); _SensorContactElements.Add(OrdDef.eMD.Id, NSE); } _LastSensorUpdateAck = MissileGroup._sensorUpdateAck; } break; } foreach (GLPrimitive oPrimitive in m_lPrimitives) { oPrimitive.Render(); } /// <summary> /// Adding sensor elements to children causes wierd behavior that I'd rather not deal with. /// </summary> foreach (KeyValuePair <Guid, SensorElement> sElement in _SensorContactElements) { sElement.Value.Render(); } if (RenderChildren == true) { foreach (SceenElement oElement in m_lChildren) { oElement.Render(); } } // render lable: if (m_oLable != null) { m_oLable.Render(); } }
public override void Render() { switch (m_oSystemContect.SSEntity) { case StarSystemEntityType.TaskGroup: TaskGroupTN TaskGroup = m_oSystemContect.Entity as TaskGroupTN; /// <summary> /// Update this contact's sensor elements. /// </summary> if (TaskGroup.SensorUpdateAck != _LastSensorUpdateAck) { /// <summary> /// Remove those sensors that are no longer active. /// </summary> BindingList<Guid> SensorRemoveList = new BindingList<Guid>(); foreach (KeyValuePair<Guid,SensorElement> SCE in _SensorContactElements) { switch(SCE.Value._sensorType) { case ComponentTypeTN.ActiveSensor: ActiveSensorTN aSensor = (SCE.Value.SceenEntity as ActiveSensorTN); if (aSensor.isActive == false || aSensor.isDestroyed == true || ParentSceen.ShowActives == false) { SensorRemoveList.Add(SCE.Key); } break; case ComponentTypeTN.PassiveSensor: PassiveSensorTN pSensor = (SCE.Value.SceenEntity as PassiveSensorTN); /// <summary> /// Remove this sensor if it is destroyed, or if it isn't the current best thermal/em sensor. if a sensor is destroyed it should be replaced as the best em/thermal. /// </summary> if (pSensor.isDestroyed == true || ParentSceen.ShowPassives == false) { SensorRemoveList.Add(SCE.Key); } else { if (pSensor.pSensorDef.thermalOrEM == PassiveSensorType.Thermal) { if (pSensor != TaskGroup.BestThermal) { SensorRemoveList.Add(SCE.Key); } } else { if (pSensor != TaskGroup.BestEM) { SensorRemoveList.Add(SCE.Key); } } } break; } } if (SensorRemoveList.Count != 0) { foreach (Guid SCE in SensorRemoveList) _SensorContactElements.Remove(SCE); } if (_SensorContactElements.ContainsKey(TaskGroup.BestEM.pSensorDef.Id) == false && ParentSceen.ShowPassives == true) { PassiveSensorDefTN pSensorDef = TaskGroup.BestEM.pSensorDef; #warning all of these 10000.0's are related to the fact that distance is done by 10k km in Aurora. double factor = Constants.Units.KmPerAu / 10000.0; double AURadius = (double)pSensorDef.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 TGPos = new Vector3((float)TaskGroup.Contact.Position.X, (float)TaskGroup.Contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, TGPos, (float)AURadius, System.Drawing.Color.Blue, TaskGroup.BestEM.Name, TaskGroup.BestEM, TaskGroup.BestEM.pSensorDef.componentType, ParentSceen); _SensorContactElements.Add(TaskGroup.BestEM.pSensorDef.Id, NSE); } if (_SensorContactElements.ContainsKey(TaskGroup.BestThermal.pSensorDef.Id) == false && ParentSceen.ShowPassives == true) { PassiveSensorDefTN pSensorDef = TaskGroup.BestThermal.pSensorDef; double factor = Constants.Units.KmPerAu / 10000.0; double AURadius = (double)pSensorDef.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 TGPos = new Vector3((float)TaskGroup.Contact.Position.X, (float)TaskGroup.Contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, TGPos, (float)AURadius, System.Drawing.Color.Red, TaskGroup.BestThermal.Name, TaskGroup.BestThermal, TaskGroup.BestThermal.pSensorDef.componentType, ParentSceen); _SensorContactElements.Add(TaskGroup.BestThermal.pSensorDef.Id, NSE); } /// <summary> /// Check for newly activated sensors. /// </summary> if (ParentSceen.ShowActives == true) { foreach (ActiveSensorTN Sensor in TaskGroup.ActiveSensorQue) { /// <summary> /// This sensor survived the above cleanup, and is in the sensor contact element list, so don't re check whether it should be here. /// </summary> if (_SensorContactElements.ContainsKey(Sensor.aSensorDef.Id) == true) continue; ActiveSensorDefTN SensorDef = Sensor.aSensorDef; double factor = Constants.Units.KmPerAu / 10000.0; double AURadius = (double)SensorDef.maxRange / factor; Vector3 TGPos = new Vector3((float)TaskGroup.Contact.Position.X, (float)TaskGroup.Contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, TGPos, (float)AURadius, System.Drawing.Color.Turquoise, Sensor.Name, Sensor, Sensor.aSensorDef.componentType, ParentSceen); _SensorContactElements.Add(SensorDef.Id, NSE); } } _LastSensorUpdateAck = TaskGroup.SensorUpdateAck; } break; case StarSystemEntityType.Population: Population CurrentPop = (m_oSystemContect.Entity as Population); /// <summary> /// Populations only have one sensor element. /// </summary> _SensorContactElements.Clear(); if (CurrentPop._sensorUpdateAck != _LastSensorUpdateAck && ParentSceen.ShowPassives == true) { /// <summary> /// This calculates the default detection distance for strength 1000 signatures. /// </summary> int DSTS = (int)Math.Floor(CurrentPop.Installations[(int)Installation.InstallationType.DeepSpaceTrackingStation].Number); int SensorTech = CurrentPop.Faction.FactionTechLevel[(int)Faction.FactionTechnology.DSTSSensorStrength]; if (SensorTech > Constants.Colony.DeepSpaceMax) SensorTech = Constants.Colony.DeepSpaceMax; #warning if EM strength differs from Thermal handle that here. int ScanStrength = DSTS * Constants.Colony.ThermalDeepSpaceStrength[SensorTech] * 100; double factor = Constants.Units.KmPerAu / 10000.0; double AURadius = (double)ScanStrength * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 PopPosition = new Vector3((float)CurrentPop.Contact.Position.X, (float)CurrentPop.Contact.Position.Y, 0.0f); /// <summary> /// Type is set to TypeCount because only the taskgroup section requires it. Likewise for CurrentPop, and CurrentPop.Id, these aren't strictly necessary, but the /// taskgroup section requires more information as more sensor contact elements can be associated with a taskgroup. /// </summary> SensorElement NSE = new SensorElement(_DefaultEffect, PopPosition, (float)AURadius, System.Drawing.Color.Purple, CurrentPop.Name + " DSTS Coverage", CurrentPop, ComponentTypeTN.TypeCount, ParentSceen); _SensorContactElements.Add(CurrentPop.Id, NSE); } break; case StarSystemEntityType.Missile: OrdnanceGroupTN MissileGroup = (m_oSystemContect.Entity as OrdnanceGroupTN); /// <summary> /// This ordnance group was just created, so check whether or not any sensors need to be displayed. Or the display could request that passives or actives not be displayed. /// </summary> if (_LastSensorUpdateAck != MissileGroup._sensorUpdateAck) { _SensorContactElements.Clear(); OrdnanceDefTN OrdDef = MissileGroup.missiles[0].missileDef; if (OrdDef.aSD != null && ParentSceen.ShowActives == true) { double factor = Constants.Units.KmPerAu / 10000.0; double AURadius = (double)OrdDef.aSD.maxRange / factor; Vector3 MGPos = new Vector3((float)MissileGroup.contact.Position.X, (float)MissileGroup.contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, MGPos, (float)AURadius, System.Drawing.Color.Turquoise, MissileGroup.missiles[0].missileDef.Name + " Active Sensor", MissileGroup, ComponentTypeTN.TypeCount, ParentSceen); _SensorContactElements.Add(OrdDef.aSD.Id, NSE); } if (OrdDef.tHD != null && ParentSceen.ShowPassives == true) { double factor = Constants.Units.KmPerAu / 10000.0; double AURadius = (double)OrdDef.tHD.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 MGPos = new Vector3((float)MissileGroup.contact.Position.X, (float)MissileGroup.contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, MGPos, (float)AURadius, System.Drawing.Color.Red, MissileGroup.missiles[0].missileDef.Name + " Thermal Sensor", MissileGroup, ComponentTypeTN.TypeCount, ParentSceen); _SensorContactElements.Add(OrdDef.tHD.Id, NSE); } if (OrdDef.eMD != null && ParentSceen.ShowPassives == true) { double factor = Constants.Units.KmPerAu / 10000.0; double AURadius = (double)OrdDef.eMD.range * ((float)Constants.SensorTN.DefaultPassiveSignature / (float)ParentSceen.ShowPassiveSignatureRange) / factor; Vector3 MGPos = new Vector3((float)MissileGroup.contact.Position.X, (float)MissileGroup.contact.Position.Y, 0.0f); SensorElement NSE = new SensorElement(_DefaultEffect, MGPos, (float)AURadius, System.Drawing.Color.Blue, MissileGroup.missiles[0].missileDef.Name + " EM Sensor", MissileGroup, ComponentTypeTN.TypeCount, ParentSceen); _SensorContactElements.Add(OrdDef.eMD.Id, NSE); } _LastSensorUpdateAck = MissileGroup._sensorUpdateAck; } break; } foreach (GLPrimitive oPrimitive in m_lPrimitives) { oPrimitive.Render(); } /// <summary> /// Adding sensor elements to children causes wierd behavior that I'd rather not deal with. /// </summary> foreach ( KeyValuePair<Guid,SensorElement> sElement in _SensorContactElements) { sElement.Value.Render(); } if (RenderChildren == true) { foreach (SceenElement oElement in m_lChildren) { oElement.Render(); } } // render lable: if (m_oLable != null) { m_oLable.Render(); } }