private TriggerResult triggerApplyAction(List <string> args)
            {
                if (args.Count < 2)
                {
                    Program.Echo("Expected 2 args: name, action");
                    return(TriggerResult.Error);
                }

                string name       = args[0];
                string actionName = args[1];

                findBlocksOfType <IMyTerminalBlock>(_tempBlocks, b => b.CustomName.Contains(name) && isSameConstructAsMe(b));

                foreach (IMyTerminalBlock b in _tempBlocks)
                {
                    ITerminalAction action = b.GetActionWithName(actionName);
                    if (action == null)
                    {
                        Program.Echo("No action '" + actionName + "' for block of type '" + b.GetType() + "'");
                        return(TriggerResult.Error);
                    }
                    action.Apply(b);
                }

                return(TriggerResult.Ok);
            }
Exemple #2
0
        //Disables all beacons and antennas and deletes the ship.
        public void DeleteShip()
        {
            var lstSlimBlock = new List <IMySlimBlock>();

            _cubeGrid.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRadioAntenna);
            foreach (var block in lstSlimBlock)
            {
                Sandbox.ModAPI.IMyRadioAntenna antenna = (Sandbox.ModAPI.IMyRadioAntenna)block.FatBlock;
                ITerminalAction act = antenna.GetActionWithName("OnOff_Off");
                act.Apply(antenna);
            }

            lstSlimBlock = new List <IMySlimBlock>();
            _cubeGrid.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyBeacon);
            foreach (var block in lstSlimBlock)
            {
                Sandbox.ModAPI.IMyBeacon beacon = (Sandbox.ModAPI.IMyBeacon)block.FatBlock;
                ITerminalAction          act    = beacon.GetActionWithName("OnOff_Off");
                act.Apply(beacon);
            }

            _cubeGrid.SyncObject.SendCloseRequest();
            MyAPIGateway.Entities.RemoveEntity(_cubeGrid as IMyEntity);

            //_cubeGrid = null;
        }
        public override void UpdateBeforeSimulation100()
        {
            if (MyAPIGateway.Session == null || !MyAPIGateway.Session.IsServer)
            {
                return;
            }

            if (wheel.CubeGrid?.Physics == null)
            {
                NeedsUpdate = MyEntityUpdateEnum.NONE;
                return;
            }

            List <ITerminalAction> actions = new List <ITerminalAction>(1);

            MyAPIGateway.TerminalActionsHelper.GetActions(wheel.GetType(), actions, (a) => a.Id == "Add Top Part");
            if (actions.Count > 0)
            {
                addWheel = actions [0];
            }

            if (wheel.TopGrid != null)
            {
                wheel.TopGrid.OnClose += TopGrid_OnClose;
                GetOB(wheel.TopGrid);
                listening = true;
            }
            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
        }
Exemple #4
0
    private void ChangeActionToObject(string _objeto, string _accion)
    {
        IMyTerminalBlock objeto = CaptureCube(_objeto);
        ITerminalAction  accion = objeto.GetActionWithName(_accion);

        accion.Apply(objeto);
    }
        bool SetupToggleAction()
        {
            List <ITerminalAction> actions = new List <ITerminalAction>();

            if (MyAPIGateway.TerminalActionsHelper == null)
            {
                return(false);
            }
            MyAPIGateway.TerminalActionsHelper.GetActions(myDoor.GetType(), actions, null);

            string actionName = null;

            foreach (ITerminalAction item in actions)
            {
                actionName = item.Id;
                if (_DoorToggleActionId.Equals(actionName, StringComparison.InvariantCultureIgnoreCase))
                {
                    toggleAction = item;
                    break;
                }
            }

            if (toggleAction == null)
            {
                LogMessage("Couldn't find toggle action", true);
            }

            return(toggleAction != null);
        }
Exemple #6
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);
        }
Exemple #7
0
    void cambiarAccionObjeto(string _objeto, string _accion)
    {
        IMyTerminalBlock objeto = captureCube(_objeto);
        ITerminalAction  accion = objeto.GetActionWithName(_accion);

        accion.Apply(objeto);
    }
            public DasMenuActionItem createActionItem(ITerminalAction Action)
            {
                DasMenuActionItem BuildItem = new DasMenuActionItem();

                BuildItem.setAction(Action);

                return(BuildItem);
            }
    public void rotorAction(String Name)
    {
        ITerminalAction Action = this.rotor.GetActionWithName(Name);

        if (Action != null)
        {
            Action.Apply(this.rotor);
        }
    }
            private void parseActions(DasMenuBlockItem BlockItem)
            {
                List <ITerminalAction> Actions = getActions(BlockItem.getBlock());

                for (int i_Actions = 0; i_Actions < Actions.Count; i_Actions++)
                {
                    ITerminalAction Action = Actions[i_Actions];
                    parseSingleAction(Action, BlockItem);
                }
            }
Exemple #11
0
        public void ApplyAction(IMyTerminalBlock block, string actionName)
        {
            ITerminalAction action = block.GetActionWithName(actionName);

            if (action == null)
            {
                throw new ArgumentException("Action could not be found: " + actionName);
            }
            action.Apply(block);
        }
        public Program()
        {
            IMyTerminalBlock block;

            if (string.IsNullOrWhiteSpace(lcdName))
            {
                block = Me;
            }
            else
            {
                block = GridTerminalSystem.GetBlockWithName(lcdName);
                if (block == null)
                {
                    throw new Exception("Unable to find lcd.");
                }
            }

            if (block is IMyTextSurface)
            {
                canvas = (IMyTextSurface)block;
            }
            else if (block is IMyTextSurfaceProvider)
            {
                IMyTextSurfaceProvider temp = (IMyTextSurfaceProvider)block;
                lcdIndex = Math.Max(temp.SurfaceCount - 1, lcdIndex);
                canvas   = temp.GetSurface(lcdIndex);
            }
            else
            {
                throw new Exception("Unable to find lcd.");
            }

            if (string.IsNullOrWhiteSpace(projectorName))
            {
                List <IMyTerminalBlock> temp = new List <IMyTerminalBlock>();
                GridTerminalSystem.GetBlocksOfType <IMyProjector>(temp, (b) => temp.Count <= 1);
                projector = (IMyProjector)temp.FirstOrDefault();
            }
            else
            {
                projector = GridTerminalSystem.GetBlockWithName(projectorName) as IMyProjector;
            }

            if (projector == null)
            {
                throw new Exception("Unable to find projector.");
            }

            spawnProjection    = projector.GetActionWithName("BuildGrid");
            projectedGridComps = projector.GetProperty("RequiredComponents").As <Dictionary <MyItemType, int> >();
            projectedGridTimer = projector.GetProperty("GridTimerProjection").As <int>();
            timer = projector.GetProperty("GridTimerCurrent").As <int>();
            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }
Exemple #13
0
            public override void Initialize(IEnumerable <string> arguments)
            {
                _turrets = FindAllTurrets();
                program.logMessages.Enqueue($"Turret mod initialized with {_turrets.Count} turrets");

                if (_turrets.Count > 0)
                {
                    _shootOn  = _turrets[0].guns[0].GetActionWithName("Shoot_On");
                    _shootOff = _turrets[0].guns[0].GetActionWithName("Shoot_Off");
                }
            }
Exemple #14
0
    public EasyBlock ApplyAction(String Name)
    {
        ITerminalAction Action = this.GetAction(Name);

        if (Action != null)
        {
            Action.Apply(this.Block);
        }

        return(this);
    }
 private ChangeInfo UpdateCustomName(ITerminalAction action)
 {
     try
     {
         m_tmpStringBuilder.Clear();
         m_tmpStringBuilder.AppendStringBuilder(m_block.CustomName);
         m_tmpStringBuilder.Append(" - ");
         m_tmpStringBuilder.AppendStringBuilder(action.Name);
         return(SetDisplayName(m_tmpStringBuilder.ToString()));
     }
     finally
     {
         m_tmpStringBuilder.Clear();
     }
 }
Exemple #16
0
        internal void SetBroadcasting(bool broadcastingEnabled)
        {
            FindBeacons();
            ITerminalAction power = broadcastingEnabled ? _blockOn : _blockOff;

            foreach (var v in beacons)
            {
                power.Apply(v);
            }
            FindAntennas();
            foreach (var v in antennas)
            {
                power.Apply(v);
            }
        }
Exemple #17
0
        /// <summary>
        /// Sends commands to the autopilot.
        /// </summary>
        /// <param name="content">The commands for the autopilot.</param>
        void SendMessageToAutopilot(string content)
        {
            Echo("AP: " + content);

            parameters[2] = TerminalActionParameter.Get(content);

            ITerminalAction action = Me.GetActionWithName("SendMessage");

            if (action == null)
            {
                Echo("ARMS is not loaded. ARMS is a prerequisite for this script.");
            }
            else
            {
                Me.ApplyAction("SendMessage", parameters);
            }
        }
Exemple #18
0
        /// <summary>
        /// Sends a message to one or more blocks. All matching Programmable blocks and Autopilot blocks
        /// will be sent a message.
        /// </summary>
        /// <param name="targetGrid">Every grid with targetGrid in the name will receive a message</param>
        /// <param name="targetBlock">Every Programmable Block or Autopilot block with targetBlock in
        /// the name will receive a message</param>
        /// <param name="content">The content of the message</param>
        void SendMessage(string targetGrid, string targetBlock, string content)
        {
            arguments.Clear();
            arguments.Add(TerminalActionParameter.Get(targetGrid));
            arguments.Add(TerminalActionParameter.Get(targetBlock));
            arguments.Add(TerminalActionParameter.Get(content));

            ITerminalAction action = Me.GetActionWithName("SendMessage");

            if (action == null)
            {
                Echo("ARMS is not loaded. ARMS is a prerequisite for this script.");
            }
            else
            {
                Me.ApplyAction("SendMessage", arguments);
            }
        }
Exemple #19
0
		private static bool CheckParams(ITerminalAction termAction, out string message, out List<Ingame.TerminalActionParameter> termParams, params string[] termParamStrings)
		{
			ListReader<Ingame.TerminalActionParameter> parameterDefinitions = termAction.GetParameterDefinitions();
			if (parameterDefinitions.Count != termParamStrings.Length)
			{
				message = "wrong number of parameters: " + termParamStrings.Length + ", expected: " + parameterDefinitions.Count;
				termParams = null;
				return false;
			}
			termParams = new List<Ingame.TerminalActionParameter>(parameterDefinitions.Count);
			Logger.DebugLog("counts: " + parameterDefinitions.Count + ", " + termParamStrings.Length + ", " + termParams.Count);
			for (int index = 0; index < parameterDefinitions.Count; index++)
			{
				object obj;
				try
				{
					obj = Convert.ChangeType(termParamStrings[index], parameterDefinitions[index].TypeCode);
				}
				catch (InvalidCastException)
				{
					message = termParamStrings[index] + " cannot be cast to " + parameterDefinitions[index].TypeCode;
					return false;
				}
				catch (FormatException)
				{
					message = termParamStrings[index] + " is not in a format recognized by " + parameterDefinitions[index].TypeCode;
					return false;
				}
				catch (OverflowException)
				{
					message = termParamStrings[index] + " is out of range of " + parameterDefinitions[index].TypeCode;
					return false;
				}
				catch (ArgumentException)
				{
					message = "type code is invalid: " + parameterDefinitions[index].TypeCode;
					return false;
				}

				termParams.Add(Ingame.TerminalActionParameter.Get(obj));
			}
			message = null;
			return true;
		}
Exemple #20
0
        public JsValue ApplyAction(JsValue obj, JsValue[] arguments)
        {
            if (arguments.Length < 1)
            {
                return(false);
            }
            var name = TypeConverter.ToString(arguments.At(0));

            ITerminalAction action = tb.GetActionWithName(name);

            if (action == null)
            {
                return(false);
            }

            // TODO - handle parameters

            action.Apply(tb);
            return(true);
        }
Exemple #21
0
		private static bool CheckParams(VRage.Game.ModAPI.IMyCubeBlock autopilot, string blockName, string actionName, string[] parameters, out string message, out List<Ingame.TerminalActionParameter> termParams)
		{
			int needParams = -1;
			message = actionName + " not found";

			foreach (IMyCubeBlock block in AttachedGrid.AttachedCubeBlocks((IMyCubeGrid)autopilot.CubeGrid, AttachedGrid.AttachmentKind.Permanent, true))
			{
				if (!block.DisplayNameText.Contains(blockName, StringComparison.InvariantCultureIgnoreCase))
					continue;
				IMyTerminalBlock term = block as IMyTerminalBlock;
				if (term == null)
					continue;
				ITerminalAction terminalAction = (ITerminalAction)term.GetActionWithName(actionName);
				if (terminalAction != null)
				{
					int paramCount = terminalAction.GetParameterDefinitions().Count;
					if (Math.Abs(parameters.Length - paramCount) > (Math.Abs(parameters.Length - needParams)))
						continue;

					needParams = paramCount;
					if (parameters.Length == needParams && CheckParams(terminalAction, out message, out termParams, parameters))
						return true;
				}
			}

			if (needParams < 0)
			{
				message = actionName + " has no parameters";
				termParams = null;
				return false;
			}
			if (parameters.Length != needParams)
			{
				message = actionName + " requires " + needParams + " parameters, got " + parameters.Length;
				termParams = null;
				return false;
			}

			termParams = null;
			return false;
		}
Exemple #22
0
        private void SetupActions()
        {
            if (_fireGun == null && _allWeapons.Count > 0 && _allWeapons[0] != null)
            {
                var actions = new List <ITerminalAction>();

                ((Sandbox.ModAPI.IMyUserControllableGun)_allWeapons[0].FatBlock).GetActions(actions);
                if (_fireRocket == null)
                {
                    foreach (var act in actions)
                    {
                        Util.GetInstance().Log("[Drone.IsAlive] Action Name " + act.Name.Replace(" ", "_"), "weapons.txt");
                        switch (act.Name.ToString())
                        {
                        case "Shoot_once":
                            _fireRocket = act;
                            break;

                        case "Shoot_On":
                            _fireGun = act;
                            break;

                        case "Toggle_block_Off":
                            _blockOff = act;
                            break;

                        case "Toggle_block_On":
                            _blockOn = act;
                            break;
                        }
                    }

                    Util.GetInstance()
                    .Log(
                        "[Drone.IsAlive] Has Missile attack -> " + (_fireRocket != null) + " Has Gun Attack " +
                        (_fireRocket != null) + " off " + (_blockOff != null) + " on " + (_blockOn != null),
                        "weapons.txt");
                }
            }
        }
Exemple #23
0
        private void Init()
        {
            if (_action == null)
            {
                if (!_parent.HasEntity)
                {
                    return;
                }

                var actions = new List <ITerminalAction>();
                _parent.Entity.GetActions(actions, _ => _.Id == _name);

                if (actions.Count == 0)
                {
                    Log.Write("ERROR Unable to find terminal action {0} on entity {1}", _name, _parent.EntityTypeName, _parent.EntityName);
                }
                else
                {
                    _action = actions[0];
                }
            }
        }
Exemple #24
0
        private void Lock(IMyCubeBlock obj)
        {
            IMyLargeTurretBase Turret = Entity as IMyLargeTurretBase;

            if (obj.OwnerId == 0 && Turret.IsWorking)
            {
                Turret.Enabled = false;
                Turret.RefreshCustomInfo();
                return;
            }
            ITerminalAction TargetLarge = Turret.GetActionWithName("TargetLargeShips_Off");

            if (TargetLarge != null)
            {
                TargetLarge.Apply(Turret);
            }

            ITerminalAction TargetSmall = Turret.GetActionWithName("TargetSmallShips_Off");

            if (TargetSmall != null)
            {
                TargetSmall.Apply(Turret);
            }

            ITerminalAction TargetStation = Turret.GetActionWithName("TargetStations_Off");

            if (TargetStation != null)
            {
                TargetStation.Apply(Turret);
            }

            ITerminalAction TargetMoving = Turret.GetActionWithName("TargetMoving_Off");

            if (TargetMoving != null)
            {
                TargetMoving.Apply(Turret);
            }
        }
Exemple #25
0
        public Program()
        {
            this.Runtime.UpdateFrequency = UpdateFrequency.Update1;
            this.manager = Process.CreateManager(this.Echo);
            var screen = this.GridTerminalSystem.GetBlockWithName("LCD (Rear Seat)") as IMyTextPanel;
            var logger = new Logger(this.manager, this.Me.GetSurface(0), size: 0.25f);

            this.logger = logger.Log;
            this.manager.SetLogger(logger.Log);
            this.cmd = new CommandLine("Small Mobile Base", logger.Log, this.manager);
            IMyTerminalBlock wheel  = this.GridTerminalSystem.GetBlockWithName("Wheel test");
            ITerminalAction  attach = wheel.GetActionWithName("Add Top Part");
            var             proj    = this.GridTerminalSystem.GetBlockWithName("Projector test") as IMyProjector;
            ITerminalAction spawn   = proj.GetActionWithName("SpawnProjection");
            //attach.Apply(wheel);
            //var param = TerminalActionParameter.Get("Blueprints/cloud/Boring Machine Drill/bp.sbc");
            //var param = TerminalActionParameter.Get("Boring Machine Drill");
            //var param = TerminalActionParameter.Get("Blueprints/cloud/Boring Machine Drill");
            var param = TerminalActionParameter.Get("Welder");

            proj.ApplyAction("SpawnProjection", new List <TerminalActionParameter> {
                param
            });
            this.logger(spawn.Name.ToString());
            var sb = new StringBuilder("");

            spawn.WriteValue(proj, sb);
            this.logger(sb.ToString());
            var list = new List <IMyShipToolBase>();

            GridTerminalSystem.GetBlocksOfType(list, c => c.CubeGrid == this.Me.CubeGrid);
            this.logger("=====");
            foreach (var t in list)
            {
                this.logger(t.CustomName);
            }
        }
Exemple #26
0
        //Disables all beacons and antennas and deletes the ship.
        public void DeleteShip()
        {
            var lstSlimBlock = new List <IMySlimBlock>();

            Ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRadioAntenna);
            foreach (var block in lstSlimBlock)
            {
                Sandbox.ModAPI.IMyRadioAntenna antenna = (Sandbox.ModAPI.IMyRadioAntenna)block.FatBlock;
                ITerminalAction act = antenna.GetActionWithName("OnOff_Off");
                act.Apply(antenna);
            }

            lstSlimBlock = new List <IMySlimBlock>();
            Ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyBeacon);
            foreach (var block in lstSlimBlock)
            {
                Sandbox.ModAPI.IMyBeacon beacon = (Sandbox.ModAPI.IMyBeacon)block.FatBlock;
                ITerminalAction          act    = beacon.GetActionWithName("OnOff_Off");
                act.Apply(beacon);
            }

            MyAPIGateway.Entities.RemoveEntity(Ship as IMyEntity);
            Ship = null;
        }
        public void Main(string argument, UpdateType updateSource)
        {
            // clear console
            logger.clear();

            List <IMyMotorStator> rotors = GetRotors();

            foreach (var rotor in rotors.OrderBy(r => r.CustomName).ToList())
            {
                logger.log(rotor.CustomName.ToString());
                if (rotor.LowerLimitDeg != float.MinValue || rotor.UpperLimitDeg != float.MaxValue)
                {
                    resetLimits(rotor);
                }
                else
                {
                    updateLimits(rotor);
                }

                List <ITerminalAction> actions = new List <ITerminalAction>();
                ITerminalAction        turnOn  = rotor.GetActionWithName("OnOff_On");
                turnOn.Apply(rotor);
            }
        } //main
Exemple #28
0
        private void runActionOnBlock(string blockName, string actionString)
        {
            //log("entered runActionOnBlock("+blockName+", "+actionString+")", "runActionOnBlock()", Logger.severity.TRACE);
            blockName    = blockName.ToLower().Replace(" ", "");
            actionString = actionString.Trim();

            List <IMySlimBlock> blocksWithName = new List <IMySlimBlock>();

            owner.myGrid.GetBlocks(blocksWithName);
            foreach (IMySlimBlock block in blocksWithName)
            {
                IMyCubeBlock fatblock = block.FatBlock;
                if (fatblock == null)
                {
                    continue;
                }

                Sandbox.Common.MyRelationsBetweenPlayerAndBlock relationship = fatblock.GetUserRelationToOwner(owner.currentRCblock.OwnerId);
                if (relationship != Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Owner && relationship != Sandbox.Common.MyRelationsBetweenPlayerAndBlock.FactionShare)
                {
                    //log("failed relationship test for " + fatblock.DisplayNameText + ", result was " + relationship.ToString(), "runActionOnBlock()", Logger.severity.TRACE);
                    continue;
                }
                //log("passed relationship test for " + fatblock.DisplayNameText + ", result was " + relationship.ToString(), "runActionOnBlock()", Logger.severity.TRACE);

                //log("testing: " + fatblock.DisplayNameText, "runActionOnBlock()", Logger.severity.TRACE);
                // name test
                if (fatblock is Ingame.IMyRemoteControl)
                {
                    string nameOnly = fatblock.getNameOnly();
                    if (nameOnly == null || !nameOnly.Contains(blockName))
                    {
                        continue;
                    }
                }
                else
                {
                    if (!fatblock.DisplayNameText.looseContains(blockName))
                    {
                        //log("testing failed " + fatblock.DisplayNameText + " does not contain " + blockName, "runActionOnBlock()", Logger.severity.TRACE);
                        continue;
                    }
                    //log("testing successfull " + fatblock.DisplayNameText + " contains " + blockName, "runActionOnBlock()", Logger.severity.TRACE);
                }

                if (!(fatblock is IMyTerminalBlock))
                {
                    //log("not a terminal block: " + fatblock.DisplayNameText, "runActionOnBlock()", Logger.severity.TRACE);
                    continue;
                }
                IMyTerminalBlock terminalBlock = fatblock as IMyTerminalBlock;
                ITerminalAction  actionToRun   = terminalBlock.GetActionWithName(actionString);              // get actionToRun on every iteration so invalid blocks can be ignored
                if (actionToRun != null)
                {
                    log("running action: " + actionString + " on block: " + fatblock.DisplayNameText, "runActionOnBlock()", Logger.severity.DEBUG);
                    actionToRun.Apply(fatblock);
                }
                else
                {
                    log("could not get action: " + actionString + " for: " + fatblock.DisplayNameText, "runActionOnBlock()", Logger.severity.TRACE);
                }
            }
        }
 public void setAction(ITerminalAction value)
 {
     Action = value;
     setLabel(getAction().Id);
 }
            private void parseSingleAction(ITerminalAction Action, DasMenuItem Parent)
            {
                DasMenuActionItem ActionItem = (new DasMenuItemFactory()).createActionItem(Action);

                Parent.addChild(ActionItem);
            }
 private ChangeInfo UpdateCustomName(ITerminalAction action)
 {
     try
     {
         m_tmpStringBuilder.Clear();
         m_tmpStringBuilder.AppendStringBuilder(m_block.CustomName);
         m_tmpStringBuilder.Append(" - ");
         m_tmpStringBuilder.AppendStringBuilder(action.Name);
         return SetDisplayName(m_tmpStringBuilder.ToString());
     }
     finally
     {
         m_tmpStringBuilder.Clear();
     }
 }