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 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 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); }
protected void ScanGrid(RadarableGrid RGrid) { //if (DetectedEntities.Any(x => x.EntityId == RGrid.Grid.EntityId)) return; float Distance = this.DistanceTo(RGrid); if (Distance <= RadarCore.GuaranteedDetectionRange) { AddEntity(RGrid.Grid, RGrid.Position); return; } Vector3D?Hit; if (!DetectorModule.IsInView(RGrid.Grid, out Hit)) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.ScanGrid({RGrid.DisplayName})", "discarded: invisible by ray", true); return; } RadarCore.DebugWrite($"{RadarBlock.CustomName}.ScanGrid({RGrid.DisplayName})", $"Grid rate={RGrid.ActiveDetectionRate}, rate/dist={Math.Round(MyRadarGrid.TotalRadarPower / Position.DistanceTo(RGrid.Position), 2)}", true); float RayPower = ActiveRadar ? PowerModule.EffectiveRadarPower : 800; if (RGrid.HasMarker && RGrid.MarkerRange >= Distance) { AddEntity(RGrid.Grid, null); return; } else if (DetectorModule.CanDetectUsingActiveRadar(RGrid) || DetectorModule.CanDetectByRadar(RGrid) || DetectorModule.CanDetectByHeat(RGrid) || DetectorModule.CanDetectByGravity(RGrid)) { AddEntity(RGrid.Grid, RGrid.Position); return; } }
public override void UpdateOnceBeforeFrame() { try { if (RadarBlock.CubeGrid.Physics == null) { NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; return; } if (!Networker.Inited) { Networker.Init(907384096); } if (!Controls.InitedRadarControls) { Controls.InitRadarControls(); } NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; GetMaxPower(); Term = RadarBlock.CubeGrid.GetTerminalSystem(); RadarPower = new AutoSet <float>(RadarBlock, "Power", 1000, x => x >= 0 && x <= MaxPower); ShowMarkers = new AutoSet <bool>(RadarBlock, "ShowMarkers", true, null); ShowRoids = new AutoSet <bool>(RadarBlock, "ShowRoids", true, null); ActiveRadar = new AutoSet <bool>(RadarBlock, "Active", false, null); ShowOnlyHostiles = new AutoSet <bool>(RadarBlock, "OnlyHostiles", true, null); ShowFloating = new AutoSet <bool>(RadarBlock, "Floating", false, null); ShowWorkingGridsOnly = new AutoSet <bool>(RadarBlock, "ShowWorkingGridsOnly", false, null); PowerModule.InitResourceSink(); PersistenceModule.Load(); RadarBlock.AppendingCustomInfo += RadarBlock_AppendingCustomInfo; RadarBlock.OnMarkForClose += OnMarkForClose; Debug.Write($"Added radar {RadarBlock.EntityId}"); if (RadarCore.Debug) { TestNote = MyAPIGateway.Utilities.CreateNotification($"{RadarBlock.CustomName}: enabled;", int.MaxValue, "Green"); } if (RadarCore.Debug) { TestNote.Show(); } RadarCore.DebugWrite("Testing", "TESTING", true); //MyRadarGrid = RadarBlock.CubeGrid.Components.Get<RadarableGrid>(); if (MyRadarGrid == null) { throw new Exception($"{RadarBlock.CustomName}.MyRadarGrid is null!"); } } catch { } }
public bool CanScan(Ingame.MyDetectedEntityInfo Target) { try { if (RadarCore.AllowScanningTargets == false) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Scanning disabled in settings"); return(false); } if (!Radar.IsWorking()) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Radar is disabled"); return(false); } if (!IsScanReady) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Scan cooldown not expired"); return(false); } if (Target.IsEmpty()) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Target struct is empty"); return(false); } if (!Radar.DetectedEntities.Any(x => x.EntityId == Target.EntityId)) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Target not found"); return(false); } if (!Target.IsGrid()) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Target is not a grid"); return(false); } IMyCubeGrid Grid = MyAPIGateway.Entities.GetEntityById(Target.EntityId) as IMyCubeGrid; if (Grid == null) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Cannot resolve EntityID"); return(false); } float Distance = Radar.Position.DistanceTo(Target.Position); float MaxScanDistance = 3000 / (float)Math.Pow(RadarCore.DecoyScanDisruptionCoefficient, Grid.AsRadarable().DecoysCount); if (Distance > RadarCore.GuaranteedDetectionRange && Distance > MaxScanDistance) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Out of range: dist={Distance}; scanrange={MaxScanDistance}"); return(false); } return(true); } catch { return(false); } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; if (!Entity.HasComponent <MyModStorageComponent>()) { Entity.Storage = new MyModStorageComponent(); Entity.Components.Add(Entity.Storage); RadarCore.DebugWrite($"{Block.CustomName}.Init()", "Block doesn't have a Storage component!", IsExcessive: false); } }
/*public override void UpdatingStopped() * { * TotalRadarPower = 0; * DetectedEntities.Clear(); * RemoveGPSMarkers(true); * }*/ public bool IsWorking() { if (RadarBlock.Closed || RadarBlock.MarkedForClose) { MarkForClose(); return(false); } RadarCore.DebugWrite($"{RadarBlock.CustomName}", $"Functional={RadarBlock.IsFunctional};Enabled={RadarBlock.Enabled};PowerAvailable={PowerModule.MyRadarPowerSink.IsPowerAvailable(RadarPowerModule.Electricity, 0.8f)}", true); return(RadarBlock.IsFunctional && RadarBlock.Enabled && PowerModule.MyRadarPowerSink.IsPowerAvailable(RadarPowerModule.Electricity, 0.8f)); }
public bool CanDetectByRadar(RadarableGrid Grid) { try { if (Grid.Grid.Physics == null) { return(false); } float Distance = Radar.Position.DistanceTo(Grid.Position); return(Grid.TotalRadarPower >= Distance * 1.5f); } catch (Exception Scrap) { RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanDetectByRadar()", $"Crash: {Scrap.Message}", false); return(false); } }
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 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); } }
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 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; }
/// <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); }