Exemple #1
0
 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 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);
     }
 }
Exemple #3
0
 public override void UpdateOnceBeforeFrame()
 {
     if (!Inited)
     {
         Initialize();
     }
     RadarCore.SaveRegister(Save);
     LCD.OnMarkForClose += LCD_OnMarkForClose;
     NeedsUpdate        |= MyEntityUpdateEnum.EACH_10TH_FRAME;
     ShowTextOnHud       = new AutoSet <bool>(Entity, "ShowTextOnHud", false);
     CoordX              = new AutoSet <float>(Entity, "CoordX", 0, x => x <= 1 && x >= -1);
     CoordY              = new AutoSet <float>(Entity, "CoordY", 0, x => x <= 1 && x >= -1);
     DisplaySize         = new AutoSet <float>(Entity, "Size", 0, x => x <= 1 && x >= 0);
     Load();
 }
 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);
     }
 }
Exemple #5
0
 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;
     }
 }
Exemple #6
0
 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 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);
            }
        }
Exemple #8
0
 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|");
     }
 }
Exemple #9
0
        //Debug.Enabled = true;
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            base.Init(objectBuilder);
            RadarBlock = Entity as IMyUpgradeModule;

            ScanModule        = new GridScanModule(this);
            MarkerModule      = new RadarMarkerModule(this);
            DetectorModule    = new RadarDetectorModule(this);
            PersistenceModule = new RadarPersistenceModule(this);
            PowerModule       = new RadarPowerModule(this);
            RadarCore.SaveRegister(PersistenceModule.Save);

            /*if (!RadarBlock.HasComponent<MyModStorageComponent>())
             * {
             *  RadarBlock.Storage = new MyModStorageComponent();
             *  RadarBlock.Components.Add(RadarBlock.Storage);
             *  RadarCore.DebugWrite($"{RadarBlock.CustomName}.Init()", "Block doesn't have a Storage component!", IsExcessive: false);
             * }*/
        }
Exemple #10
0
 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);
     }
 }
Exemple #11
0
 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);
     }
 }
Exemple #12
0
 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);
     }
 }
Exemple #13
0
 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);
     }
 }
Exemple #14
0
        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);
            }
        }
Exemple #15
0
        public override void UpdateOnceBeforeFrame()
        {
            if (AntennaBlock.CubeGrid.Physics == null)
            {
                NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
                return;
            }

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            if (AntennaBlock is IMyRadioAntenna && !InitedRadioAntennaControls)
            {
                InitRadioAntennaControls();
            }
            if (AntennaBlock is IMyLaserAntenna && !InitedLaserAntennaControls)
            {
                InitLaserAntennaControls();
            }
            SyncAllowReceive = new AutoSet <bool>(Entity, "Receive", true);
            Load();
            AntennaBlock.AppendingCustomInfo += AntennaBlock_AppendingCustomInfo;
            AntennaBlock.OnMarkForClose      += AntennaBlock_OnMarkForClose;
            AntennaGrid = AntennaBlock.GetTopMostParent() as IMyCubeGrid;
            RadarCore.SaveRegister(Save);
        }
Exemple #16
0
 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|");
     }
 }
Exemple #17
0
 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);
     }
 }
Exemple #18
0
        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;
        }
Exemple #19
0
        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);
            }
        }
Exemple #20
0
 /// <summary>
 /// Returns overall distance from which the entity can be spotted by Radar.
 /// </summary>
 public static float GetDetectionRate(this IMyEntity Entity)
 {
     return(RadarCore.VisibilityDistanceByDefaultRule(Entity));
 }
        /// <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);
        }