Exemplo n.º 1
0
        public void Main(string input, UpdateType updateSource)
        {
            input = input == "" ? "OBSERVE" : input;

            if (input == "RESTART" || state == null)
            {
                var config = new Config(Me.CustomData);

                config.Set(ref closeConnectorName, "closeConnectorName");
                config.Set(ref grabberGroupName, "grabberGroupName");
                config.Set(ref grabberVelocity, "grabberVelocity");
                config.Set(ref grinderGroupName, "grinderGroupName");
                config.Set(ref namePrefix, "namePrefix");
                config.Set(ref openConnectorName, "openConnectorName");
                config.Set(ref rotorGroupName, "rotorGroupName");
                config.Set(ref rotorVelocity, "rotorVelocity");
                config.Set(ref welderGroupName, "welderGroupName");

                var lookup = new LookupHelper {
                    GridTerminalSystem = GridTerminalSystem,
                    NamePrefix         = namePrefix,
                };

                // init
                accessCodes = new List <string>(config.Get("accessCodes", "").Split(','));

                closeConnector         = lookup.GetBlockWithName <IMyShipConnector>(closeConnectorName);
                closeConnector.Enabled = true;

                openConnector         = lookup.GetBlockWithName <IMyShipConnector>(openConnectorName);
                openConnector.Enabled = true;

                grinders = lookup.GetBlocksInGroup <IMyShipGrinder>(grinderGroupName);
                grinders.ForEach(grinder => grinder.Enabled = false);
                welders = lookup.GetBlocksInGroup <IMyShipWelder>(welderGroupName);
                welders.ForEach(welder => welder.Enabled = false);

                rotorController = new RotorController(lookup.GetBlocksInGroup <IMyMotorStator>(rotorGroupName), rotorVelocity);
                rotorController.Stop();
                grabberController = new RotorController(lookup.GetBlocksInGroup <IMyMotorStator>(grabberGroupName), grabberVelocity);
                grabberController.Go("BACKWARD"); // Open grabber

                state = "UNKNOWN";
                Runtime.UpdateFrequency = UpdateFrequency.Update100;
                Observe();
            }

            if (input == "radioCommand" && broadcastListener.HasPendingMessage)
            {
                var message = broadcastListener.AcceptMessage();

                while (broadcastListener.HasPendingMessage)
                {
                    message = broadcastListener.AcceptMessage();
                }

                var data = BlastDoorRadioMessage.Deserialize(message.Data as string);

                if (!accessCodes.Contains(data.AccessCode))
                {
                    return;
                }

                input = data.Command;
            }

            if (input == "OBSERVE")
            {
                Observe();
            }
            else if (input == "CLOSE" && state != "CLOSING" && state != "CLOSED")
            {
                openConnector.Enabled  = false;
                closeConnector.Enabled = true;
                grinders.ForEach(grinder => grinder.Enabled = false);
                welders.ForEach(welder => welder.Enabled    = true);
                rotorController.Go("FORWARD");
                grabberController.Go("FORWARD"); // Grab
                state = "CLOSING";
                Runtime.UpdateFrequency = UpdateFrequency.Update100;
            }
            else if (input == "OPEN" && state != "OPENING" && state != "OPEN")
            {
                openConnector.Enabled  = true;
                closeConnector.Enabled = false;
                welders.ForEach(welder => welder.Enabled    = false);
                grinders.ForEach(grinder => grinder.Enabled = true);
                rotorController.Go("BACKWARD");
                grabberController.Go("FORWARD"); // Grab
                state = "OPENING";
                Runtime.UpdateFrequency = UpdateFrequency.Update100;
            }
        }
Exemplo n.º 2
0
        public bool init()
        {
            IMyBlockGroup group = GridTerminalSystem.GetBlockGroupWithName(groupName_);

            if (group != null)
            {
                pistons_.Clear();
                drills_.Clear();

                group.GetBlocksOfType <IMyTerminalBlock>(null, (block) =>
                {
                    IMyPistonBase piston = block as IMyPistonBase;
                    if (piston != null)
                    {
                        PistonController controller = new PistonController(this, piston);
                        pistons_.Add(controller);
                        return(false);
                    }

                    IMyMotorStator stator = block as IMyMotorStator;
                    if (stator != null)
                    {
                        drillRotor_ = new RotorController(this, stator);
                        return(false);
                    }

                    IMyShipDrill drill = block as IMyShipDrill;
                    if (drill != null)
                    {
                        drills_.Add(drill);
                        return(false);
                    }

                    // production block
                    IMyProductionBlock pu = block as IMyProductionBlock;
                    if (pu != null)
                    {
                        production_ = new ProductionUnit(this, pu);
                        return(false);
                    }

                    IMyCargoContainer container = block as IMyCargoContainer;
                    if (container != null)
                    {
                        containers_.Add(container);
                        return(false);
                    }

                    return(false);
                });
            }
            else
            {
                addMessageLine("Error: Minig Group not found!");
                return(false);
            }

            // check drills
            if (drills_.Count == 0)
            {
                addMessageLine("Error: No drills found!");
                return(false);
            }

            // read config
            miningDepth_ = GetConfigMiningDepth();

            return(true);
        }