Beispiel #1
0
        /// <summary>
        /// Sends entity IDs to a text panel for display. To display GPS or Entity ID on the text panel,
        /// the appropriate command should be enabled on the text panel.
        /// </summary>
        /// <param name="panelName">The name of the text panel</param>
        /// <param name="entityIds">List of entity IDs to display. Order of the list does not affect
        /// the order they will be displayed in.</param>
        void DisplayEntitiesOnPanel(string panelName, List <TerminalActionParameter> entityIds)
        {
            IMyTerminalBlock term = GridTerminalSystem.GetBlockWithName(panelName);

            if (term == null)
            {
                Terminate(panelName + " does not exist or is not accessible");
                return;
            }
            IMyTextPanel panel = term as IMyTextPanel;

            if (panel == null)
            {
                Terminate(panelName + " is not a text panel");
                return;
            }
            ITerminalAction act = panel.GetActionWithName(displayAction);

            if (act == null)
            {
                Terminate("ARMS is not loaded. ARMS is a prerequisite for this script.");
                return;
            }
            panel.ApplyAction(displayAction, entityIds);
        }
        public Program()
        {
            ///Disable Echoing for performance impovement on MP servers
            //Echo = text => { };

            Runtime.UpdateFrequency = UpdateFrequency.Update10;

            IMyBlockGroup targetingSystemGroup = GridTerminalSystem.GetBlockGroupWithName(TARGETING_SYSTEM_GROUP);

            if (targetingSystemGroup == null)
            {
                throw new Exception($"No {TARGETING_SYSTEM_GROUP} group defined.");
            }

            Echo("Configure cameras...");
            cameras = new List <IMyCameraBlock>();
            targetingSystemGroup.GetBlocksOfType(cameras);
            if (cameras.Count == 0)
            {
                throw new Exception("No camera found in group.");
            }

            raycastConeLimit = cameras[0].RaycastConeLimit;

            Echo("Configure displays...");
            displays = new List <IMyTextPanel>();
            targetingSystemGroup.GetBlocksOfType(displays);
            displays = displays.OrderBy(x => x.DisplayNameText).ToList();
            if (displays.Count == 0)
            {
                Echo("No text pannel found in group.");
            }
            else
            {
                InfoDisplay             = displays.FirstOrDefault();
                InfoDisplay.ContentType = ContentType.TEXT_AND_IMAGE;
                InfoDisplay.Font        = "DEBUG";
                InfoDisplay.FontSize    = 0.9f;
                InfoDisplay.ApplyAction(Actions.TURN_ON);
            }

            Echo("Configure ShipController...");
            var cockpits = new List <IMyShipController>();

            targetingSystemGroup.GetBlocksOfType(cockpits);
            if (cockpits.Count == 0)
            {
                throw new Exception("No ship controller found in group.");
            }
            shipcontroller = cockpits.First();

            Echo("Configure triggers...");
            triggers = new List <IMyTimerBlock>();
            targetingSystemGroup.GetBlocksOfType(triggers);
            if (triggers.Count == 0)
            {
                Echo($"No Timmer block found in group {TARGETING_SYSTEM_GROUP}");
            }

            Echo("Configure turrets...");
            turrets = new List <IMyLargeTurretBase>();
            targetingSystemGroup.GetBlocksOfType(turrets);
            foreach (var turret in turrets)
            {
                turret.ApplyAction(Actions.TURN_ON);
            }
            if (maxTurretsPerCycle > turrets.Count)
            {
                maxTurretsPerCycle = turrets.Count;
            }

            //Enable raycast for cameras
            foreach (var camera in cameras)
            {
                camera.EnableRaycast = true;
                camera.ApplyAction(Actions.TURN_ON);
            }

            if (RANGE > cameras.FirstOrDefault().RaycastDistanceLimit)
            {
                //If camera scan range exeeds server setting limit it to server raycast distance limit.
                RANGE = cameras.FirstOrDefault().RaycastDistanceLimit;
            }

            Echo("Init OK.");
        }
            public TargetingSystem(Program program, IMyProgrammableBlock me)
            {
                _program     = program;
                _me          = me;
                detectedList = new Dictionary <long, MyDetectedEntityInfo>();

                IMyBlockGroup targetingSystemGroup = _program.GridTerminalSystem.GetBlockGroupWithName(TARGETING_SYSTEM_GROUP);

                if (targetingSystemGroup == null)
                {
                    throw new Exception($"No {TARGETING_SYSTEM_GROUP} group defined.");
                }

                _program.Echo("Configure cameras...");
                cameras = new List <IMyCameraBlock>();
                targetingSystemGroup.GetBlocksOfType(cameras);
                if (cameras.Count == 0)
                {
                    throw new Exception("No camera found in group.");
                }

                raycastConeLimit = cameras[0].RaycastConeLimit;

                _program.Echo("Configure displays...");
                displays = new List <IMyTextPanel>();
                targetingSystemGroup.GetBlocksOfType(displays);
                displays = displays.OrderBy(x => x.DisplayNameText).ToList();
                if (displays.Count == 0)
                {
                    _program.Echo("No text pannel found in group.");
                }
                else
                {
                    InfoDisplay             = displays.FirstOrDefault();
                    InfoDisplay.ContentType = ContentType.TEXT_AND_IMAGE;
                    InfoDisplay.Font        = "DEBUG";
                    InfoDisplay.FontSize    = 0.9f;
                    InfoDisplay.ApplyAction(Actions.TURN_ON);
                }


                _program.Echo("Configure ShipController...");
                var cockpits = new List <IMyShipController>();

                targetingSystemGroup.GetBlocksOfType(cockpits);
                if (cockpits.Count == 0)
                {
                    throw new Exception("No ship controller found in group.");
                }
                shipcontroller = cockpits.First();

                _program.Echo("Configure triggers...");
                triggers = new List <IMyTimerBlock>();
                targetingSystemGroup.GetBlocksOfType(triggers);
                if (triggers.Count == 0)
                {
                    _program.Echo($"No Timmer block found in group {TARGETING_SYSTEM_GROUP}");
                }

                _program.Echo("Configure turrets...");
                turrets = new List <IMyLargeTurretBase>();
                targetingSystemGroup.GetBlocksOfType(turrets);
                foreach (var turret in turrets)
                {
                    turret.ApplyAction(Actions.TURN_ON);
                }
                if (maxTurretsPerCycle > turrets.Count)
                {
                    maxTurretsPerCycle = turrets.Count;
                }

                //Enable raycast for cameras
                foreach (var camera in cameras)
                {
                    camera.EnableRaycast = true;
                    camera.ApplyAction(Actions.TURN_ON);
                }

                if (RANGE > cameras.FirstOrDefault().RaycastDistanceLimit)
                {
                    //If camera scan range exeeds server setting limit it to server raycast distance limit.
                    RANGE = cameras.FirstOrDefault().RaycastDistanceLimit;
                }

                _program.Echo("Init OK.");
            }
Beispiel #4
0
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.None;

            IMyBlockGroup targetingSystemGroup = GridTerminalSystem.GetBlockGroupWithName(TARGETING_SYSTEM_GROUP);

            if (targetingSystemGroup == null)
            {
                throw new Exception($"No {TARGETING_SYSTEM_GROUP} group defined.");
            }

            Echo("Configure cameras...");
            cameras = new List <IMyCameraBlock>();
            targetingSystemGroup.GetBlocksOfType(cameras);
            if (cameras.Count == 0)
            {
                throw new Exception("No camera found in group.");
            }
            //Enable raycast for cameras
            foreach (var camera in cameras)
            {
                camera.EnableRaycast = true;
                camera.ApplyAction(Actions.TURN_ON);
            }
            raycastConeLimit = cameras[0].RaycastConeLimit;
            if (RANGE > cameras[0].RaycastDistanceLimit)
            {
                //If camera scan range exeeds server setting limit it to server raycast distance limit.
                RANGE = cameras[0].RaycastDistanceLimit;
            }
            Echo($"Cameras {cameras.Count} OK at range {RANGE}");

            Echo("Configure displays...");
            var displays = new List <IMyTextPanel>();

            targetingSystemGroup.GetBlocksOfType(displays);
            displays = displays.OrderBy(x => x.DisplayNameText).ToList();
            if (displays.Count == 0)
            {
                Echo("No text pannel found in group.");
            }
            if (displays.Count > 0)
            {
                InfoDisplay             = displays[0];
                InfoDisplay.ContentType = ContentType.TEXT_AND_IMAGE;
                InfoDisplay.Font        = "DEBUG";
                InfoDisplay.FontSize    = 0.9f;
                InfoDisplay.ApplyAction(Actions.TURN_ON);

                Echo($"Display {InfoDisplay.DisplayNameText} OK");
            }
            if (displays.Count > 1)
            {
                GPSLogDisplay             = displays[1];
                GPSLogDisplay.ContentType = ContentType.TEXT_AND_IMAGE;
                GPSLogDisplay.Font        = "DEBUG";
                GPSLogDisplay.FontSize    = 0.9f;
                GPSLogDisplay.WriteText(string.Empty);
                GPSLogDisplay.ApplyAction(Actions.TURN_ON);

                Echo($"Display GPSLog {GPSLogDisplay.DisplayNameText} OK");
            }
            if (displays.Count > 2)
            {
                ErrorLogDisplay             = displays[2];
                ErrorLogDisplay.ContentType = ContentType.TEXT_AND_IMAGE;
                ErrorLogDisplay.Font        = "DEBUG";
                ErrorLogDisplay.FontSize    = 0.9f;
                ErrorLogDisplay.FontColor   = Color.Red;
                ErrorLogDisplay.WriteText(string.Empty);
                ErrorLogDisplay.ApplyAction(Actions.TURN_ON);

                Echo($"Display ErrorLog {ErrorLogDisplay.DisplayNameText} OK");
            }

            Echo("Configure turrets...");
            turrets = new List <IMyLargeTurretBase>();
            targetingSystemGroup.GetBlocksOfType(turrets);
            foreach (var turret in turrets)
            {
                turret.ApplyAction(Actions.TURN_ON);
            }
            Echo($"Turrets {turrets.Count} OK.");

            Echo("Configure ShipController...");
            var cockpits = new List <IMyShipController>();

            targetingSystemGroup.GetBlocksOfType(cockpits);
            if (cockpits.Count == 0)
            {
                throw new Exception("No ship controller found in group.");
            }
            shipcontroller = cockpits[0];

            Echo("Configuration OK.");
        }