public void RemoveGPSMarkers(bool PurgeAll = false) { List <long> RemoveKeys = new List <long>(); foreach (var MarkerPair in RadarMarkers) { try { if (PurgeAll) { MarkerPair.Value.Remove(); RadarCore.DebugWrite($"{RadarBlock.CustomName}.RemoveGPSMarkers()", $"Removing marker [{MarkerPair.Value.Name}/{MarkerPair.Value.Description}] -> purging all", true); RemoveKeys.Add(MarkerPair.Key); } else { Ingame.MyDetectedEntityInfo RadarInfo = Radar.DetectedEntities.FirstOrDefault(x => x.EntityId == MarkerPair.Key); if (!Radar.DetectedEntities.Any(x => x.EntityId == RadarInfo.EntityId) || !ShouldMarkerExist(RadarInfo)) { MarkerPair.Value.Remove(); RadarCore.DebugWrite($"{RadarBlock.CustomName}.RemoveGPSMarkers()", $"Removing marker [{MarkerPair.Value.Name}/{MarkerPair.Value.Description}] -> entity is no longer detected", true); RemoveKeys.Add(MarkerPair.Key); } } } catch (Exception Scrap) { RadarCore.LogError(RadarBlock.CustomName, Scrap); } } RadarMarkers.RemoveAll(RemoveKeys); }
void UpdateRelays() { IMyCubeGrid OwnGrid = AntennaBlock.GetTopMostParent() as IMyCubeGrid; RelayedReceivers.Clear(); RelayedGridsIngame.Clear(); RelayedChars.Clear(); if (Antenna == null) { RadarCore.LogError(AntennaBlock.DisplayName + ".Update10()", new Exception("Antenna == null")); } if (Antenna.BroadcastersInRange == null) { RadarCore.LogError(AntennaBlock.DisplayName + ".Update10()", new Exception("BroadcastersInRange == null")); } if (Antenna.BroadcastersInRange == null) { return; } foreach (var Receiver in Antenna.BroadcastersInRange.Select(x => x.Entity.GetComponent <MyDataReceiver>())) { TryAddRelay(Receiver); if (Receiver?.BroadcastersInRange == null) { continue; } foreach (var RelayedReceiver in Receiver.BroadcastersInRange.Select(x => x.Entity.GetComponent <MyDataReceiver>())) { TryAddRelay(RelayedReceiver); } } }
public void Load() { try { string Storage = null; if (MyAPIGateway.Utilities.GetVariable($"settings_{LCD.EntityId}", out Storage)) { byte[] Raw = Convert.FromBase64String(Storage); try { RadarCore.DebugWrite($"{LCD.CustomName}.Load()", $"Loading settings. Raw data: {Raw.Count()} bytes", IsExcessive: false); LCDPersistent persistent = MyAPIGateway.Utilities.SerializeFromBinary <LCDPersistent>(Raw); ShowTextOnHud.Set(persistent.ShowTextOnHud); CoordX.Set(persistent.CoordX); CoordY.Set(persistent.CoordY); DisplaySize.Set(persistent.DisplaySize); } catch (Exception Scrap) { RadarCore.LogError($"{LCD.CustomName}.Load()", Scrap); } } else { RadarCore.DebugWrite($"{LCD.CustomName}.Load()", "Storage access failed.", IsExcessive: false); } } catch (Exception Scrap) { RadarCore.LogError($"{LCD.CustomName}.Load().AccessStorage", Scrap); } }
public void Remove() { try { if (AttachedEntity == null) { RadarCore.DebugWrite($"GPSMarker[{Name}].Remove", "AttachedEntity is already removed"); } try { MyVisualScriptLogicProvider.RemoveGPSFromEntity(AttachedEntity.Name, Name, Description, OwnerPlayerID); } catch (Exception Scrap) { RadarCore.LogError($"GPSMarker[{Name}].Remove_VSLP", Scrap); } List <IMyGps> GPSes = MyAPIGateway.Session.GPS.GetGpsList(OwnerPlayerID); IMyGps OurGPS; if (GPSes.Any(x => x.Name == Name && x.Description == Description, out OurGPS)) { MyAPIGateway.Session.GPS.RemoveGps(OwnerPlayerID, OurGPS); } Valid = false; } catch (Exception Scrap) { RadarCore.LogError($"GPSMarker[{Name}].Remove", Scrap); } }
public override void UpdateBeforeSimulation10() { try { UpdateRelays(); AntennaBlock.RefreshCustomInfo(); } catch (Exception Scrap) { RadarCore.LogError(AntennaBlock.DisplayName + ".Update10().General", Scrap); } }
void CalculateTotalPower() { try { TotalRadarPower = 0; Term.GetBlocksOfType <IMyUpgradeModule>(collect: x => Controls.IsRadar(x) && x.IsWorking).ForEach(x => TotalRadarPower += Controls.RadarReturn(x, r => r.PowerModule.EffectiveRadarPower)); } catch (Exception Scrap) { RadarCore.LogError(RadarBlock.CustomName + ".CalculateTotalPower", Scrap); } }
public static bool IsRadar(IMyTerminalBlock Radar) { try { bool isradar = Radar.HasComponent <MyRadar>(); //DebugWrite("IsRadar", $"Block {Radar.CustomName} asked; result={isradar}", IsExcessive: true); return(isradar); } catch (Exception Scrap) { RadarCore.LogError("IsRadar", Scrap); return(false); } }
public void InitResourceSink() { try { MyRadarPowerSink.SetMaxRequiredInputByType(Electricity, 100); MyRadarPowerSink.SetRequiredInputFuncByType(Electricity, PowerConsumptionFunc); MyRadarPowerSink.SetRequiredInputByType(Electricity, PowerConsumptionFunc()); MyRadarPowerSink.Update(); } catch (Exception Scrap) { RadarCore.LogError(RadarBlock.CustomName, Scrap); } }
protected void GetMaxPower() { try { IMyUpgradeModule block = Entity as IMyUpgradeModule; List <MyUpgradeModuleInfo> Info; block.GetUpgradeList(out Info); MaxPower = Info.First(x => x.UpgradeType == "Radar").Modifier; } catch (Exception Scrap) { RadarCore.LogError($"{RadarBlock.CustomName}.Load().GetMaxPower", Scrap); } }
public virtual void Save() { try { AntennaPersistent persistent; persistent.Datagrams = Datagrams.ToList(); persistent.Protocols = Protocols; persistent.Receive = AllowReceive; string Raw = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(persistent)); MyAPIGateway.Utilities.SetVariable($"settings_{Block.EntityId}", Raw); } catch (Exception Scrap) { RadarCore.LogError($"{Block.CustomName}.Save()", Scrap); } }
public static void RadarAction(IMyTerminalBlock RadarBlock, Action <MyRadar> Action) { try { MyRadar Radar; if (!RadarBlock.TryGetComponent(out Radar)) { return; } Action(Radar); } catch (Exception Scrap) { RadarCore.LogError("RadarAction", Scrap); return; } }
public static T RadarReturn <T>(IMyTerminalBlock RadarBlock, Func <MyRadar, T> Getter, T Default = default(T)) { try { MyRadar Radar; if (!RadarBlock.TryGetComponent(out Radar)) { return(Default); } return(Getter(Radar)); } catch (Exception Scrap) { RadarCore.LogError("RadarReturn", Scrap); return(Default); } }
public override void UpdateBeforeSimulation10() { try { if (Grid.Physics == null) { return; } AssertMarkers(); CalculateTotalPower(); ReactorOutput = Grid.GetCurrentReactorPowerOutput(); GetDecoyCount(); GetRelays(); } catch (Exception Scrap) { RadarCore.LogError(Grid.DisplayName, Scrap, DebugPrefix: "RadarableGrid.Upd10|"); } }
public void Save() { try { //RadarCore.DebugWrite($"{RadarBlock.CustomName}.Save()", $"Saving... RadarPower: {Math.Round(RadarPower.Get())}; ShowMarkers: {ShowMarkers.Get()}; ShowRoids: {ShowRoids.Get()}"); //RemoveGPSMarkers(); LCDPersistent persistent; persistent.ShowTextOnHud = ShowTextOnHud.Get(); persistent.CoordX = CoordX.Get(); persistent.CoordY = CoordY.Get(); persistent.DisplaySize = DisplaySize.Get(); string Raw = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(persistent)); MyAPIGateway.Utilities.SetVariable($"settings_{LCD.EntityId}", Raw); RadarCore.DebugWrite($"{LCD.CustomName}.Save()", "Saved to storage.", IsExcessive: false); } catch (Exception Scrap) { RadarCore.LogError($"{LCD.CustomName}.Save()", Scrap); } }
public virtual void Save() { try { RadarPersistent persistent; persistent.ShowMarkers = Radar.ShowMarkers.Get(); persistent.ShowOnlyHostiles = Radar.ShowOnlyHostiles.Get(); persistent.RadarPower = Radar.RadarPower.Get(); persistent.ActiveRadar = Radar.ActiveRadar.Get(); persistent.ShowRoids = Radar.ShowRoids.Get(); persistent.ShowWorkingGridsOnly = Radar.ShowWorkingGridsOnly.Get(); persistent.ShowFloating = Radar.ShowFloating.Get(); string Raw = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(persistent)); MyAPIGateway.Utilities.SetVariable($"settings_{RadarBlock.EntityId}", Raw); } catch (Exception Scrap) { RadarCore.LogError($"{RadarBlock.CustomName}.Save()", Scrap); } }
public override void UpdateBeforeSimulation10() { try { scanx++; if (scanx == 6) { scanx = 0; MarkerModule.RemoveGPSMarkers(); DetectedEntities.Clear(); if (RadarBlock.CubeGrid.Physics == null) { return; } //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); //watch.Start(); PowerModule.MyRadarPowerSink.Update(); if (IsWorking()) { OwnerPlayer = GetOwnerPlayer(); FindOwnerInRelayNetwork(); CalculateTotalPower(); RadarBlock.RefreshCustomInfo(); PerformScan(); } else { HasOwnerInRelay = false; //if (RadarCore.Debug) TestNote.Hide(); } //watch.Stop(); //MyAPIGateway.Utilities.ShowMessage(RadarBlock.CustomName, $"Scan took {(Math.Round(watch.ElapsedTicks * 1000f / System.Diagnostics.Stopwatch.Frequency, 2))}"); } } catch (Exception Scrap) { RadarCore.LogError(RadarBlock.CustomName, Scrap); } }
public virtual void Load() { try { string Storage = null; if (MyAPIGateway.Utilities.GetVariable($"settings_{Radar.Entity.EntityId}", out Storage)) { byte[] Raw = Convert.FromBase64String(Storage); try { RadarCore.DebugWrite($"{RadarBlock.CustomName}.Load()", $"Loading settings. Raw data: {Raw.Count()} bytes", IsExcessive: false); RadarPersistent persistent = MyAPIGateway.Utilities.SerializeFromBinary <RadarPersistent>(Raw); Radar.RadarPower.Set(persistent.RadarPower); Radar.ShowMarkers.Set(persistent.ShowMarkers); Radar.ShowOnlyHostiles.Set(persistent.ShowOnlyHostiles); Radar.ActiveRadar.Set(persistent.ActiveRadar); Radar.ShowRoids.Set(persistent.ShowRoids); Radar.ShowWorkingGridsOnly.Set(persistent.ShowWorkingGridsOnly); Radar.ShowFloating.Set(persistent.ShowFloating); if (Radar.RadarPower.Get() == 0) { Radar.RadarPower.Set(800); } } catch (Exception Scrap) { RadarCore.LogError($"{RadarBlock.CustomName}.Load()", Scrap); } } else { RadarCore.DebugWrite($"{RadarBlock.CustomName}.Load()", "Storage access failed.", IsExcessive: true); } } catch (Exception Scrap) { RadarCore.LogError($"{RadarBlock.CustomName}.Load().AccessStorage", Scrap); } }
void CalculateTotalPower() { try { TotalRadarPower = 0; List <IMyTerminalBlock> Radars = new List <IMyTerminalBlock>(); Term.GetBlocksOfType <IMyTerminalBlock>(Radars, x => Controls.IsRadar(x)); foreach (IMyTerminalBlock RadarBlock in Radars) { MyRadar Radar = RadarBlock.GetComponent <MyRadar>(); if (Radar == null || !Radar.ActiveRadar || !Radar.IsWorking()) { continue; } TotalRadarPower += Radar.PowerModule.EffectiveRadarPower; } } catch (Exception Scrap) { RadarCore.LogError(Grid.DisplayName + ".CalculateTotalPower", Scrap); } }
public virtual void Load() { try { string Storage = null; if (MyAPIGateway.Utilities.GetVariable($"settings_{Entity.EntityId}", out Storage)) { byte[] Raw = Convert.FromBase64String(Storage); try { AntennaPersistent persistent = MyAPIGateway.Utilities.SerializeFromBinary <AntennaPersistent>(Raw); if (persistent.Datagrams != null) { Datagrams = new Queue <MyAntennaDatagram>(persistent.Datagrams); } if (persistent.Protocols != null) { Protocols = persistent.Protocols; } SyncAllowReceive.Set(persistent.Receive); } catch (Exception Scrap) { RadarCore.LogError($"{Block.CustomName}.Load()", Scrap); } } else { RadarCore.DebugWrite($"{Block.CustomName}.Load()", "Storage access failed.", IsExcessive: true); } } catch (Exception Scrap) { RadarCore.LogError($"{Block.CustomName}.Load().AccessStorage", Scrap); } }
public override void UpdateBeforeSimulation100() { try { IsWorkingGrid = Grid.IsFunctionalGrid(); GetCloseVoxels(); CalculateGravityDistortion(); ClosestPlanet = MyGamePruningStructure.GetClosestPlanet(Position); if (ClosestPlanet != null && ClosestPlanet.IsInGravity(Position)) { Gravity = ClosestPlanet.GetGravity(Position); } else { Gravity = Vector3.Zero; ClosestPlanet = null; } GetAntennae(); } catch (Exception Scrap) { RadarCore.LogError(Grid.DisplayName, Scrap, DebugPrefix: "RadarableGrid.Upd100|"); } }
public static void InitRadarControls() { if (InitedRadarControls) { return; } #region Printer try { var EntityPrinter = MyAPIGateway.TerminalControls.CreateProperty <HashSet <Ingame.MyDetectedEntityInfo>, IMyUpgradeModule>("RadarData"); EntityPrinter.Enabled = IsRadar; EntityPrinter.Getter = Block => RadarReturn(Block, Radar => new HashSet <Ingame.MyDetectedEntityInfo>(Radar.DetectedEntities)); EntityPrinter.Setter = (Block, trash) => { if (!IsRadar(Block)) { throw new Exception("Block isn't a Radar."); } throw new Exception("The RadarData property is read-only."); }; if (MyAPIGateway.Session.IsServer) { MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(EntityPrinter); } } catch (Exception Scrap) { RadarCore.LogError("InitControls.EntityPrinter", Scrap); } #endregion #region CanScan try { var CanScanAction = MyAPIGateway.TerminalControls.CreateProperty <Func <Ingame.MyDetectedEntityInfo, bool>, IMyUpgradeModule>("CanScan"); CanScanAction.Enabled = IsRadar; CanScanAction.Getter = Block => { MyRadar Radar; if (Block.TryGetComponent(out Radar)) { return(Radar.ScanModule.CanScan); } return(null); }; CanScanAction.Setter = (Block, trash) => { if (!IsRadar(Block)) { throw new Exception("Block isn't a Radar."); } throw new Exception("The ScanTarget property is a function and cannot be set."); }; if (MyAPIGateway.Session.IsServer) { MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(CanScanAction); } } catch (Exception Scrap) { RadarCore.LogError("InitControls.CanScanTarget", Scrap); } #endregion #region ScanTarget try { var ScanAction = MyAPIGateway.TerminalControls.CreateProperty <Func <Ingame.MyDetectedEntityInfo, List <Dictionary <string, string> > >, IMyUpgradeModule>("ScanTarget"); ScanAction.Enabled = IsRadar; ScanAction.Getter = Block => { MyRadar Radar; if (Block.TryGetComponent(out Radar)) { return(Radar.ScanModule.ScanTarget); } return(null); }; ScanAction.Setter = (Block, trash) => { if (!IsRadar(Block)) { throw new Exception("Block isn't a Radar."); } throw new Exception("The ScanTarget property is a function and cannot be set."); }; if (MyAPIGateway.Session.IsServer) { MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(ScanAction); } } catch (Exception Scrap) { RadarCore.LogError("InitControls.ScanTarget", Scrap); } #endregion #region Power Slider try { var PowerSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyUpgradeModule>("RadarPower"); PowerSlider.Enabled = IsRadar; PowerSlider.Visible = IsRadar; PowerSlider.Title = MyStringId.GetOrCompute("Radar Power"); PowerSlider.Tooltip = MyStringId.GetOrCompute("Supplied power determines how much power is used in Active Radar mode."); PowerSlider.SetLogLimits((Block) => 800, (Block) => RadarReturn(Block, Radar => Radar.MaxPower, 800)); PowerSlider.Getter = (Block) => RadarReturn(Block, Radar => Radar.RadarPower.Get(), 800); PowerSlider.Setter = (Block, Value) => RadarAction(Block, Radar => Radar.RadarPower.Set(Value)); PowerSlider.Writer = (Block, Info) => RadarAction(Block, Radar => { if (Radar.ActiveRadar) { Info.Append($"{Math.Round(Radar.RadarPower.Get())} kW"); } else { Info.Append($"PASSIVE (800 kW)"); } }); MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(PowerSlider); } catch (Exception Scrap) { RadarCore.LogError("InitControls.PowerSlider", Scrap); } #endregion #region Active Mode try { var ActiveMode = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyUpgradeModule>("ActiveMode"); ActiveMode.Enabled = Block => IsRadar(Block); ActiveMode.Visible = Block => IsRadar(Block); ActiveMode.Title = MyStringId.GetOrCompute("Active Mode"); ActiveMode.Tooltip = MyStringId.GetOrCompute("Enables Radar's Active Mode. In Active Mode, Radar will actively scan its surroundings with high-power radiowaves.\nThis allows to vastly improve detection ratio, but also makes you visible to other Radars."); ActiveMode.OnText = MyStringId.GetOrCompute("ACT"); ActiveMode.OffText = MyStringId.GetOrCompute("PSV"); ActiveMode.Getter = Block => RadarReturn(Block, Radar => Radar.ActiveRadar, false); ActiveMode.Setter = (Block, Value) => RadarAction(Block, Radar => Radar.ActiveRadar.Set(Value)); MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(ActiveMode); } catch (Exception Scrap) { RadarCore.LogError("InitControls.ActiveMode", Scrap); } #endregion #region Show Markers try { var ShowMarkers = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyUpgradeModule>("ShowMarkers"); ShowMarkers.Enabled = Block => IsRadar(Block); ShowMarkers.Visible = Block => IsRadar(Block); ShowMarkers.Title = MyStringId.GetOrCompute("Show Markers"); ShowMarkers.Tooltip = MyStringId.GetOrCompute("If you are within the antenna network associated with your Radar,\nit will show detected entities as GPS markers."); ShowMarkers.OnText = MyStringId.GetOrCompute("On"); ShowMarkers.OffText = MyStringId.GetOrCompute("Off"); ShowMarkers.Getter = Block => RadarReturn(Block, Radar => Radar.ShowMarkers.Get(), false); ShowMarkers.Setter = (Block, Value) => RadarAction(Block, Radar => Radar.ShowMarkers.Set(Value)); MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(ShowMarkers); } catch (Exception Scrap) { RadarCore.LogError("InitControls.ShowMarkers", Scrap); } #endregion #region Show Roids try { var ShowRoids = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyUpgradeModule>("ShowRoids"); ShowRoids.Enabled = Block => IsRadar(Block); ShowRoids.Visible = Block => IsRadar(Block); ShowRoids.Title = MyStringId.GetOrCompute("Show Asteroids"); ShowRoids.Tooltip = MyStringId.GetOrCompute("If enabled, Radar will show detected asteroids."); ShowRoids.OnText = MyStringId.GetOrCompute("On"); ShowRoids.OffText = MyStringId.GetOrCompute("Off"); ShowRoids.Getter = Block => RadarReturn(Block, Radar => Radar.ShowRoids.Get(), false); ShowRoids.Setter = (Block, Value) => RadarAction(Block, Radar => Radar.ShowRoids.Set(Value)); MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(ShowRoids); } catch (Exception Scrap) { RadarCore.LogError("InitControls.ShowRoids", Scrap); } #endregion #region Show Only Working Grids try { var ShowOnlyHostiles = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyUpgradeModule>("ShowWorkingGridsOnly"); ShowOnlyHostiles.Enabled = Block => IsRadar(Block); ShowOnlyHostiles.Visible = Block => IsRadar(Block); ShowOnlyHostiles.Title = MyStringId.GetOrCompute("Show Working Grids Only"); ShowOnlyHostiles.Tooltip = MyStringId.GetOrCompute("If enabled, the Radar will filter out non-functional grids.\nFor grid to be considered functional, it must have a functional ship controller, a power source and either be stationary\nor have at least one gyro and one thruster."); ShowOnlyHostiles.OnText = MyStringId.GetOrCompute("On"); ShowOnlyHostiles.OffText = MyStringId.GetOrCompute("Off"); ShowOnlyHostiles.Getter = Block => RadarReturn(Block, Radar => Radar.ShowWorkingGridsOnly.Get(), false); ShowOnlyHostiles.Setter = (Block, Value) => RadarAction(Block, Radar => Radar.ShowWorkingGridsOnly.Set(Value)); MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(ShowOnlyHostiles); } catch (Exception Scrap) { RadarCore.LogError("InitControls.ShowOnlyHostiles", Scrap); } #endregion #region Show Only Hostiles try { var ShowOnlyHostiles = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyUpgradeModule>("ShowOnlyHostiles"); ShowOnlyHostiles.Enabled = Block => IsRadar(Block); ShowOnlyHostiles.Visible = Block => IsRadar(Block); ShowOnlyHostiles.Title = MyStringId.GetOrCompute("Show Only Hostiles"); ShowOnlyHostiles.Tooltip = MyStringId.GetOrCompute("If enabled, markers are limited only to hostile targets."); ShowOnlyHostiles.OnText = MyStringId.GetOrCompute("On"); ShowOnlyHostiles.OffText = MyStringId.GetOrCompute("Off"); ShowOnlyHostiles.Getter = Block => RadarReturn(Block, Radar => Radar.ShowOnlyHostiles.Get(), false); ShowOnlyHostiles.Setter = (Block, Value) => RadarAction(Block, Radar => Radar.ShowOnlyHostiles.Set(Value)); MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(ShowOnlyHostiles); } catch (Exception Scrap) { RadarCore.LogError("InitControls.ShowOnlyHostiles", Scrap); } #endregion #region Show Floating try { var ShowFloating = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyUpgradeModule>("ShowFloating"); ShowFloating.Enabled = Block => IsRadar(Block); ShowFloating.Visible = Block => IsRadar(Block); ShowFloating.Title = MyStringId.GetOrCompute("Show Floating Objects"); ShowFloating.Tooltip = MyStringId.GetOrCompute("If enabled, all floating objects will be shown."); ShowFloating.OnText = MyStringId.GetOrCompute("On"); ShowFloating.OffText = MyStringId.GetOrCompute("Off"); ShowFloating.Getter = Block => RadarReturn(Block, Radar => Radar.ShowFloating.Get(), false); ShowFloating.Setter = (Block, Value) => RadarAction(Block, Radar => Radar.ShowFloating.Set(Value)); MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(ShowFloating); } catch (Exception Scrap) { RadarCore.LogError("InitControls.ShowOnlyHostiles", Scrap); } #endregion #region IsScanReady try { var IsScanReady = MyAPIGateway.TerminalControls.CreateProperty <bool, IMyUpgradeModule>("IsScanReady"); IsScanReady.Enabled = IsRadar; IsScanReady.Getter = Block => RadarReturn(Block, Radar => Radar.ScanModule.IsScanReady); IsScanReady.Setter = (Block, trash) => { if (!IsRadar(Block)) { throw new Exception("Block isn't a Radar."); } throw new Exception("The RadarData property is read-only."); }; if (MyAPIGateway.Session.IsServer) { MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(IsScanReady); } } catch (Exception Scrap) { RadarCore.LogError("InitControls.EntityPrinter", Scrap); } #endregion #region Timestamp try { var Timestamp = MyAPIGateway.TerminalControls.CreateProperty <long, IMyProgrammableBlock>("CurrentTime"); Timestamp.Enabled = Block => true; Timestamp.Getter = Block => { var Info = Sandbox.Game.Entities.MyDetectedEntityInfoHelper.Create(Block.CubeGrid as VRage.Game.Entity.MyEntity, Block.OwnerId); return(Info.TimeStamp); }; Timestamp.Setter = (Block, trash) => { throw new Exception("The CurrentTime property is read-only."); }; MyAPIGateway.TerminalControls.AddControl <IMyProgrammableBlock>(Timestamp); } catch (Exception Scrap) { RadarCore.LogError("InitControls.Timestamp", Scrap); } #endregion RadarCore.DebugWrite("InitControls", "Controls inited."); InitedRadarControls = true; }
public void AddGPSMarker(Ingame.MyDetectedEntityInfo RadarScan, string EntityName, bool DontAddIfDetectedByRadioMarker = true) { try { try { //RadarCore.DebugWrite($"{Radar.CustomName}", $"Trying to add marker for entity {RadarScan.Type.ToString()} {RadarScan.Name}"); if (Radar.OwnerID == 0) { return; } if (!Radar.HasOwnerInRelay) { return; } if (Radar.OwnerGPSes.Any(x => x.Description == $"RadarEntity {RadarScan.EntityId}")) { return; } if (Radar.OwnerEntity?.GetTopMostParent()?.EntityId == RadarScan.EntityId) { return; } if (Radar.MyRadarGrid.RelayedGrids.Any(x => x.EntityId == RadarScan.EntityId)) { return; } if (DontAddIfDetectedByRadioMarker && RadarScan.HitPosition == null) { return; } } catch (Exception Scrap) { RadarCore.LogError("Radar.AddGPSMarker.GetOwnerPlayer", Scrap); return; } if (RadarMarkers.ContainsKey(RadarScan.EntityId)) { return; } IMyEntity AttachTo = MyAPIGateway.Entities.GetEntityById(RadarScan.EntityId); if (AttachTo == null) { return; } StringBuilder MarkerName = new StringBuilder(); if (RadarScan.Type == Ingame.MyDetectedEntityType.Asteroid && EntityName == "Asteroid") { MarkerName.Append("[Asteroid]"); } else if (RadarScan.IsGrid() && (EntityName.StartsWith("Large Grid") || EntityName.StartsWith("Small Grid"))) { if (RadarScan.Type == Ingame.MyDetectedEntityType.LargeGrid) { MarkerName.Append("[Large Grid]"); } else { MarkerName.Append("[Small Grid]"); } } else { MarkerName.Append($"[{RadarScan.Type.ToString()}{(RadarScan.IsAllied() ? $" | {RadarScan.Name.Truncate(50)}" : $"{(!string.IsNullOrWhiteSpace(EntityName) ? " | " + EntityName.Truncate(50) : "")}")}]"); } GPSMarker Marker = GPSMarker.Create(AttachTo, MarkerName.ToString(), $"RadarEntity {RadarScan.EntityId}", RadarScan.GetRelationshipColor(), Radar.OwnerID); RadarMarkers.Add(RadarScan.EntityId, Marker); } catch (Exception Scrap) { RadarCore.LogError("Radar.AddGPSMarker", Scrap); } }
/// <summary> /// Determines if a given entity is on a free line of sight. /// </summary> public bool IsInView(IMyEntity Target, out Vector3D?HitPosition) { HitPosition = null; try { float RayPower = Radar.ActiveRadar ? Radar.PowerModule.EffectiveRadarPower : 800; if (Radar.MyRadarGrid == null || Radar.MyRadarGrid.Grid == null) { RadarCore.LogError("IsInView", new Exception("Radar's RadarableGrid is null!"), IsExcessive: true); return(false); } LineD LineRay = new LineD(Radar.Position, Target.GetPosition()); if (LineRay.Length <= RadarCore.GuaranteedDetectionRange) { return(true); } List <MyLineSegmentOverlapResult <MyEntity> > Overlaps = new List <MyLineSegmentOverlapResult <MyEntity> >(); MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref LineRay, Overlaps); if (Overlaps == null || Overlaps.Count == 0) { return(false); } var TargetTop = Target.GetTopMostParent(); if (TargetTop == null) { RadarCore.LogError("IsInView", new Exception("Target's topmost parent is null!")); return(false); } var RadarTop = Radar.MyRadarGrid.Grid.GetTopMostParent(); if (TargetTop == null) { RadarCore.LogError("IsInView", new Exception("Radar's topmost parent is null!")); return(false); } foreach (var Overlap in Overlaps) { try { if (Overlap.Element == null || Overlap.Element.Physics == null) { continue; } LineD Intersect; var Entity = Overlap.Element as IMyEntity; if (!Entity.WorldAABB.Valid) { RadarCore.DebugWrite("IsInView.Iterate", "Found an entity with invalid WorldAABB. Skipping.", IsExcessive: true); continue; } if (Entity is IMyCubeGrid) { Entity.WorldAABB.Intersect(ref LineRay, out Intersect); } else { Entity.WorldVolume.Intersect(ref LineRay, out Intersect); } var OverlapTop = Entity.GetTopMostParent(); if (OverlapTop == null) { RadarCore.DebugWrite("IsInView.Iterate", "Found an entity with invalid topmost parent. Skipping.", IsExcessive: true); continue; } if (OverlapTop is MyPlanet) { MyPlanet Planet = OverlapTop as MyPlanet; if (Planet.HasAtmosphere) { BoundingSphereD Atmosphere = new BoundingSphereD(Planet.PositionComp.GetPosition(), Planet.AtmosphereRadius); LineD AtmoIntersect; Atmosphere.Intersect(ref LineRay, out AtmoIntersect); float Diminish = (float)(AtmoIntersect.Length * RadarCore.AtmoRayDiminishingCoefficient); RayPower -= Diminish; if (RayPower <= 0) { return(false); } } Vector3D TargetPos = Target.GetPosition(); if (Vector3D.DistanceSquared(Planet.GetClosestSurfacePointGlobal(ref TargetPos), TargetPos) < 1000 * 1000) { return(false); } } else if (OverlapTop == TargetTop) { HitPosition = Intersect.From; return(true); } else if (OverlapTop == RadarTop) { if (OverlapTop.GetPosition().DistanceTo(Radar.Position) > 1000) { List <Vector3I> GridHits = new List <Vector3I>(); Radar.MyRadarGrid.Grid.RayCastCells(Radar.Position, LineRay.To, GridHits); if (GridHits == null || GridHits.Count == 0) { continue; } if (GridHits.Contains(Radar.GridPosition)) { GridHits.Remove(Radar.GridPosition); } float Diminish = GridHits.Count * (Radar.MyRadarGrid.Grid.GridSizeEnum == MyCubeSize.Large ? 2.5f : 0.5f) * RadarCore.RayDiminishingCoefficient; RayPower -= Diminish; if (RayPower <= 0) { return(false); } } } else { float Diminish = (float)(Intersect.Length * RadarCore.RayDiminishingCoefficient); RayPower -= Diminish; if (RayPower <= 0) { return(false); } } } catch (Exception Scrap) { RadarCore.LogError("IsInView.Iterate", Scrap, IsExcessive: true); } } } catch (Exception Scrap) { RadarCore.LogError("IsInView", Scrap); } return(false); }