Ejemplo n.º 1
0
    private void ChangeActionToObject(string _objeto, string _accion)
    {
        IMyTerminalBlock objeto = CaptureCube(_objeto);
        ITerminalAction  accion = objeto.GetActionWithName(_accion);

        accion.Apply(objeto);
    }
Ejemplo n.º 2
0
		private static void RunActionOnBlock(Pathfinder pathfinder, string blockName, string actionString, List<Ingame.TerminalActionParameter> termParams)
		{
			blockName = blockName.Trim();
			actionString = actionString.Trim(); // leave spaces in actionString

			foreach (IMyCubeBlock fatblock in AttachedGrid.AttachedCubeBlocks(pathfinder.Mover.Block.CubeGrid, AttachedGrid.AttachmentKind.Permanent, true))
			{
				if (!(fatblock is IMyTerminalBlock))
					continue;

				if (!pathfinder.Mover.Block.Controller.canControlBlock(fatblock))
					continue;

				if (!fatblock.DisplayNameText.Contains(blockName, StringComparison.InvariantCultureIgnoreCase))
					continue;

				IMyTerminalBlock terminalBlock = fatblock as IMyTerminalBlock;
				Sandbox.ModAPI.Interfaces.ITerminalAction actionToRun = terminalBlock.GetActionWithName(actionString); // get actionToRun on every iteration so invalid blocks can be ignored
				if (actionToRun != null)
				{
					if (termParams != null)
						actionToRun.Apply(fatblock, termParams);
					else
						actionToRun.Apply(fatblock);
				}
			}
		}
Ejemplo n.º 3
0
        public void UpdateAfterSimulation100()
        {
            // check name for message from ingame
            if (myProgBlock.DisplayNameText != previousName)
            {
                myProgBlock_CustomNameChanged();
                previousName = myProgBlock.DisplayNameText;
            }

            // handle received message
            if (myMessages.Count == 0)
            {
                return;
            }

            IMyTerminalBlock asTerm = CubeBlock as IMyTerminalBlock;

            if (MessageParser.canWriteTo(asTerm))
            {
                Message toWrite = myMessages.First();
                myMessages.RemoveFirst();
                MessageParser.writeToName(asTerm, toWrite);
            }
            asTerm.GetActionWithName("Run").Apply(CubeBlock);
        }
Ejemplo n.º 4
0
    void cambiarAccionObjeto(string _objeto, string _accion)
    {
        IMyTerminalBlock objeto = captureCube(_objeto);
        ITerminalAction  accion = objeto.GetActionWithName(_accion);

        accion.Apply(objeto);
    }
Ejemplo n.º 5
0
        bool IsLocked(IMyTerminalBlock block)
        {
            var builder = new StringBuilder();

            block.GetActionWithName("SwitchLock").WriteValue(block, builder);

            return(builder.ToString() == "Locked");
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        void blockApplyAction(IMyTerminalBlock sBlock, string sAction)
        {
            ITerminalAction ita; ita = sBlock.GetActionWithName(sAction); if (ita != null)

            {
                ita.Apply(sBlock);
            }
            else
            {
                Echo("Unsupported action:" + sAction);
            }
        }
Ejemplo n.º 8
0
            public static void ApplyAction(IMyTerminalBlock block, string actionName)
            {
                ITerminalAction act;

                if (_terminalActionDict.TryGetValue(actionName, out act))
                {
                    act.Apply(block);
                    return;
                }

                act = block.GetActionWithName(actionName);
                _terminalActionDict[actionName] = act;
                act.Apply(block);
            }
Ejemplo n.º 9
0
        bool filterInventories(IMyTerminalBlock block)
        {
            //Skip reactors, generators, engines, and tanks, all of which have inventories that cannot hold ore
            //Skip cockpits, as the conveyor system does not push to cockpits
            string type = getDetailedInfoValue(block, "Type");

            if (block.CubeGrid != Me.CubeGrid || !block.HasInventory ||
                type.EndsWith("Engine") ||
                type.EndsWith("Reactor") ||
                type.EndsWith("Generator") ||
                type.EndsWith("Tank") ||
                block.GetActionWithName("MainCockpit") != null
                )
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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;
		}
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
0
	void ToggleOff(IMyTerminalBlock block) {
		block.GetActionWithName("OnOff_Off").Apply(block);
	}
Ejemplo n.º 14
0
        /// <summary>
        /// Try to match instruction against keywords.
        /// </summary>
        /// <param name="instruction">unparsed instruction</param>
        /// <returns>true iff successful</returns>
        private bool getAction_word(string instruction, out Action wordAction)
        {
            string lowerCase = instruction.ToLower();

            switch (lowerCase)
            {
            case "asteroid":
            {
                wordAction = () => { CNS.ignoreAsteroids = true; };
                return(true);
            }

            case "exit":
            {
                wordAction = () => {
                    owner.CNS.EXIT = true;
                    owner.reportState(Navigator.ReportableState.Off);
                    owner.fullStop("EXIT");
                };
                return(true);
            }

            case "harvest":
            {
                wordAction = () => { owner.myHarvester.Start(); };
                return(true);
            }

            case "jump":
            {
                wordAction = () => {
                    log("setting jump", "getAction_word()", Logger.severity.DEBUG);
                    owner.CNS.jump_to_dest = true;
                    return;
                };
                return(true);
            }

            case "line":
            {
                wordAction = () => {
                    owner.CNS.SpecialFlyingInstructions = NavSettings.SpecialFlying.Line_SidelForward;
                    myLogger.debugLog("Set FlyTheLine", "getAction_word()");
                };
                return(true);
            }

            case "lock":
            {
                wordAction = () => {
                    if (owner.CNS.landingState == NavSettings.LANDING.LOCKED)
                    {
                        log("staying locked. local=" + owner.CNS.landingSeparateBlock.DisplayNameText, "getAction_word()", Logger.severity.TRACE);                                        // + ", target=" + CNS.closestBlock + ", grid=" + CNS.gridDestination);
                        owner.CNS.landingState            = NavSettings.LANDING.OFF;
                        owner.CNS.landingSeparateBlock    = null;
                        owner.CNS.landingSeparateWaypoint = null;
                        owner.EnableDampeners();                                         // dampeners will have been turned off for docking
                    }
                };
                return(true);
            }

            case "reset":
            {
                IMyTerminalBlock RCterminal = owner.currentRCterminal;
                wordAction = () => {
                    if ((owner.currentRCblock as Ingame.IMyRemoteControl).ControlThrusters)
                    {
                        RCterminal.GetActionWithName("ControlThrusters").Apply(RCterminal);
                    }
                    Core.remove(owner);
                };
                return(true);
            }
            }
            wordAction = null;
            return(false);
        }
Ejemplo n.º 15
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);
                }
            }
        }
Ejemplo n.º 16
0
 // copy of Sandbox.ModAPI.Ingame.TerminalBlockExtentions, but without Ingame.
 public static void ApplyAction(this IMyTerminalBlock block, string actionName)
 {
     block.GetActionWithName(actionName).Apply(block);
 }
Ejemplo n.º 17
0
 public static Sandbox.ModAPI.Interfaces.ITerminalAction GetAction(this IMyTerminalBlock block, string name)
 {
     return(block.GetActionWithName(name));
 }
Ejemplo n.º 18
0
 public static bool HasAction(this IMyTerminalBlock block, string actionName) =>
 (block.GetActionWithName(actionName) != null);
Ejemplo n.º 19
0
            private void Action(IMyTerminalBlock block, string actionName)
            {
                var action = block.GetActionWithName(actionName);

                action.Apply(block);
            }
Ejemplo n.º 20
0
        public static void ApplyAction(this VRage.Game.ModAPI.Ingame.IMyCubeBlock block, string actionName)
        {
            IMyTerminalBlock asTerm = block as IMyTerminalBlock;

            asTerm.GetActionWithName(actionName).Apply(asTerm);
        }
Ejemplo n.º 21
0
 public static void ApplyAction(this IMyTerminalBlock block, string actionName, List <TerminalActionParameter> parameters)
 {
     block.GetActionWithName(actionName).Apply(block, parameters);
 }
Ejemplo n.º 22
0
        public static void TurnOn(IMyTerminalBlock block)
        {
            var action = block.GetActionWithName("OnOff_On");

            action.Apply(block);
        }