示例#1
0
 public override void UpdateOnceBeforeFrame()
 {
     try
     {
         Term = (IMySensorBlock)Entity;
         if (Term.BlockDefinition.SubtypeName.EndsWith("_DS_RADAR"))
         {
             CreateTerminalControls <IMySensorBlock>();
             valid       = true;
             notifyCache = new Dictionary <Vector3D, IMySensorBlock>();
             CoreHolo.Register(Entity.EntityId, this);
             Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;                    //update the block.
         }
         if (MyAPIGateway.Session.OnlineMode == MyOnlineModeEnum.OFFLINE || MyAPIGateway.Multiplayer.IsServer)
         {
             Read();
         }
         else
         {
             CoreHolo.RequestSetting(Entity.EntityId);
         }
     }
     catch (Exception ex)
     {
         Log.DebugWrite(DebugLevel.Error, ex);
     }
 }
示例#2
0
 /// <summary>
 /// init method
 /// </summary>
 public void Init()
 {
     if (init)
     {
         return;                  //script already initialized, abort.
     }
     else
     {
         init = true;
     }
     instance = this;
     settings = new ColorSettings();
     running  = true;
     Log.Info("Initialized");
     isMultiplayer = MyAPIGateway.Session.OnlineMode != MyOnlineModeEnum.OFFLINE;
     isServer      = MyAPIGateway.Session.OnlineMode == MyOnlineModeEnum.OFFLINE || MyAPIGateway.Multiplayer.IsServer;
     isDedicated   = (MyAPIGateway.Utilities.IsDedicated && isServer);
     MyAPIGateway.Multiplayer.RegisterMessageHandler(RADARMESSAGE, RangeUpdateHandler);
     if (isServer)
     {
         MyAPIGateway.Multiplayer.RegisterMessageHandler(REQUESTMESSAGE, RequestHandler);
     }
     TManager = new ThreadManager();
     if (isDedicated)
     {
         return;
     }
     MyAPIGateway.Utilities.MessageEntered += Utilities_MessageEntered;
     loadXML();
 }
示例#3
0
 public override void UpdateBeforeSimulation10()
 {
     //radarinfo
     if (Entity.Closed || Entity.MarkedForClose)
     {
         return;
     }
     if (!valid)
     {
         return;
     }
     if (CoreHolo.instance == null)
     {
         return;
     }
     if (CoreHolo.instance.isDedicated)
     {
         //Entity.NeedsUpdate &= ~MyEntityUpdateEnum.EACH_10TH_FRAME;
         return;
     }
     //MyAPIGateway.Utilities.ShowMessage("Radar", Term.IsRadar().ToString());
     if (!CoreHolo.ClosetoPlayer(Entity.WorldMatrix.Translation, Range * 50 * _resMult))
     {
         return;
     }
     Term.SetValueBool("Detect Enemy", false);
     Term.SetValueBool("Detect Neutral", false);
     Term.SetValueBool("Detect Friendly", false);
     Term.SetValueBool("Detect Owner", false);
     Term.SetValueBool("Detect Asteroids", false);
     Term.SetValueBool("Detect Stations", false);
     Term.SetValueBool("Detect Large Ships", false);
     Term.SetValueBool("Detect Small Ships", false);
     Term.SetValueBool("Detect Floating Objects", false);
     Term.SetValueBool("Detect Players", false);
     setResolution();
     activeMode = Term.GetValueBool("OnOff");
     tick++;
     if (tick < 5)
     {
         return;
     }
     else
     {
         tick = 0;                //slow updates for passive.
     }
     if (activeMode == false)
     {
     }
     if (Term.IsFunctional && (UpdateTask == null || UpdateTask.Added == false || UpdateTask.IsComplete == true))
     {
         var _data = new Dictionary <Vector3D, IMySensorBlock>(notifyCache);
         notifyCache.Clear();
         //enqueue task on a single thread using the thread manager.
         if (CoreHolo.instance?.TManager != null)
         {
             UpdateTask = CoreHolo.instance.TManager.Add(() => refreshRadar(_data, activeMode), calcComplete);
         }
     }
 }
示例#4
0
        private void updateRadar()
        {
            m_radar = null;
            if (cockpit.CustomName == null)
            {
                return;
            }
            string title = cockpit.CustomName;
            Regex  reg   = new Regex("(.*?)!(.*)");

            if (title == null || title.Length == 0)
            {
                return;
            }
            var res = reg.Split(title);

            if (res.Length > 2)
            {
                foreach (var word in res)
                {
                    Log.DebugWrite(DebugLevel.Info, word);
                }
                radarname = res[2].ToLowerInvariant().Trim();
            }
            else
            {
                return;                //nothing
            }
            system = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)cockpit.CubeGrid);
            List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();

            system.GetBlocksOfType <IMySensorBlock>(blocks, null);
            //getRadarValues();
            foreach (var block in blocks)
            {
                var sens = (IMySensorBlock)block;
                if (sens.OwnerId == cockpit.OwnerId)
                {
                    if (sens.CustomName.ToLowerInvariant().Trim() == radarname)
                    {
                        ent = sens.EntityId;
                        //ActiveAdjust = PrivateAdjust;
                        break;
                    }
                }
            }
            Log.DebugWrite(DebugLevel.Verbose, "Entityid " + ent.ToString());
            if (ent != 0)
            {
                m_radar = CoreHolo.GetRadar(ent);
            }
        }
示例#5
0
 private void calcComplete()
 {
     //MyAPIGateway.Utilities.ShowMessage("CalcDone", T_result.ColorData.Count.ToString());
     _result = new RadarResult(T_result);
     T_result.Clear();
     if (!Entity.MarkedForClose || Entity.Closed)
     {
         foreach (KeyValuePair <Vector3I, IMySensorBlock> pingblocks in pingResult)
         {
             var radar = CoreHolo.GetRadar(pingblocks.Value.EntityId);
             if (radar != null)
             {
                 radar.Notify(Term.WorldMatrix.Translation, Term);
             }
         }
         pingResult.Clear();
         //projection = p_grid;
     }
 }
示例#6
0
 public override void Close()
 {
     CoreHolo.UnRegister(Entity.EntityId);
 }
示例#7
0
        public override void UpdateBeforeSimulation10()
        {
            if (Entity == null)
            {
                return;
            }
            if (panel == null)
            {
                return;
            }
            if (CoreHolo.instance == null)
            {
                return;
            }
            if (!valid)
            {
                return;
            }
            if (CoreHolo.instance.isDedicated)
            {
                //cleanProjections();
                return;
            }
            if (!panel.IsWorking)
            {
                //cleanProjections();
                return;
            }
            if (!CoreHolo.ClosetoPlayer(Entity.WorldMatrix.Translation, 30))
            {
                //cleanProjections();
                return;
            }
            long ent = 0;

            //refresh
            system = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)panel.CubeGrid);
            List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();

            system.GetBlocksOfType <IMySensorBlock>(blocks, null);
            getRadarValues();
            foreach (var block in blocks)
            {
                var sens = (IMySensorBlock)block;
                if (sens.OwnerId == panel.OwnerId)
                {
                    if (sens.CustomName.ToLowerInvariant().Trim() == privateradarid)
                    {
                        ent          = sens.EntityId;
                        ActiveAdjust = PrivateAdjust;
                        break;
                    }
                    if (sens.CustomName.ToLowerInvariant().Trim() == publicradarid)
                    {
                        //allow public title to get the entity id as well.
                        ActiveAdjust = PublicAdjust;
                        ent          = sens.EntityId;
                    }
                }
            }
            Log.DebugWrite(DebugLevel.Verbose, "Entityid " + ent.ToString());
            if (ent != 0)
            {
                var data = CoreHolo.GetRadar(ent);
                //MyAPIGateway.Utilities.ShowMessage("Radar?", (data?.RadarData == null).ToString());
                if (data != null && data.RadarData != null)
                {
                    color = data.RadarData.ColorData;
                    //MyAPIGateway.Utilities.ShowMessage("Count", color.Count.ToString());
                }
                else
                {
                    cleanDraws();
                }
            }
            else
            {
                cleanDraws();
            }
        }