Exemple #1
0
        //        void ConnectAnyConnectors(bool bConnect = true, string sAction = "")
        void ConnectAnyConnectors(bool bConnect = true, bool bOn = true)
        {
//            string sAction = "";
            getLocalConnectors();
            //	Echo("CCA:"+ localDockConnectors.Count);
            for (int i = 0; i < localDockConnectors.Count; i++)
            {
                IMyShipConnector sc = localDockConnectors[i] as IMyShipConnector;
                if (sc.Status == MyShipConnectorStatus.Connected)
                {
                    IMyShipConnector sco = sc.OtherConnector;
                    if (sco.CubeGrid == sc.CubeGrid)
                    {
                        //Echo("Locked-but connected to 'us'");
                        continue;     // skip it.
                    }
                }
                if (bConnect)
                {
                    if (sc.Status == MyShipConnectorStatus.Connectable)
                    {
                        sc.ApplyAction("SwitchLock");
                    }
                }
                else
                {
                    if (sc.Status == MyShipConnectorStatus.Connected)
                    {
                        sc.ApplyAction("SwitchLock");
                    }
                }
                sc.Enabled = bOn;

                /*
                 *  if (sAction != "")
                 *  {
                 *      ITerminalAction ita;
                 *      ita = sc.GetActionWithName(sAction);
                 *      if (ita != null) ita.Apply(sc);
                 *  }
                 */
            }
            return;
        }
Exemple #2
0
        /// <summary>
        /// If m_navBlock is a connector, attempt to lock it.
        /// </summary>
        private void LockConnector()
        {
            if (Globals.UpdateCount < next_attemptLock)
            {
                return;
            }
            next_attemptLock = Globals.UpdateCount + 20ul;

            IMyShipConnector connector = m_navBlock.Block as IMyShipConnector;

            if (connector != null && connector.Status == Ingame.MyShipConnectorStatus.Connectable)
            {
                MyAPIGateway.Utilities.TryInvokeOnGameThread(() => {
                    if (connector.Status == Ingame.MyShipConnectorStatus.Connectable)
                    {
                        connector.ApplyAction("Lock");
                    }
                });
            }
        }
Exemple #3
0
            public Torpedo(string GroupName, Program program)
            {
                _program = program;
                Name     = GroupName;
                List <IMyTerminalBlock> templist = new List <IMyTerminalBlock>();

                templist.Clear();

                _program.Echo("Init Connector");
                gts.GetBlocksOfType <IMyShipConnector>(templist, (b) => b.CustomName.Contains(GroupName));
                connector = templist[0] as IMyShipConnector;
                connector.ApplyAction(Actions.TURN_ON);
                if (connector.Status == MyShipConnectorStatus.Connectable)
                {
                    connector.ToggleConnect();
                }
                templist.Clear();

                _program.Echo("Init Merge Block");
                gts.GetBlocksOfType <IMyShipMergeBlock>(templist, (b) => b.CustomName.Contains(GroupName));
                merge = templist[0] as IMyShipMergeBlock;
                merge.ApplyAction(Actions.TURN_ON);
                merge.Enabled = true;
                templist.Clear();

                _program.Echo("Init Remote Control");
                gts.GetBlocksOfType <IMyRemoteControl>(templist, (b) => b.CustomName.Contains(GroupName));
                remcon = templist[0] as IMyRemoteControl;
                //remcon.ApplyAction(Actions.TURN_ON);


                _program.Echo("Init Battery");
                batteries = new List <IMyBatteryBlock>();
                gts.GetBlocksOfType <IMyBatteryBlock>(batteries, (b) => b.CustomName.Contains(GroupName));
                foreach (IMyBatteryBlock battery in batteries)
                {
                    battery.ApplyAction(Actions.TURN_ON);
                    battery.Enabled = true;
                }

                _program.Echo("Init HYDROGEN tANKS");
                hydrogenTanks = new List <IMyGasTank>();
                gts.GetBlocksOfType <IMyGasTank>(hydrogenTanks, (b) => b.CustomName.Contains(GroupName));
                foreach (IMyGasTank hydrogenTank in hydrogenTanks)
                {
                    hydrogenTank.ApplyAction(Actions.TURN_ON);
                    hydrogenTank.Enabled   = true;
                    hydrogenTank.Stockpile = true;                     //Tankowanie zbiorników
                }

                _program.Echo("Init thrusters");
                thrusters = new List <IMyThrust>();
                gts.GetBlocksOfType <IMyThrust>(thrusters, (b) => b.CustomName.Contains(GroupName));
                _program.Echo("Init gyros");
                gyros = new List <IMyGyro>();
                gts.GetBlocksOfType <IMyGyro>(gyros, (b) => b.CustomName.Contains(GroupName));
                _program.Echo("Init warheads");
                warheads = new List <IMyWarhead>();
                gts.GetBlocksOfType <IMyWarhead>(warheads, (b) => b.CustomName.Contains(GroupName));
                _program.Echo("Init decoys");
                decoys = new List <IMyDecoy>();
                gts.GetBlocksOfType <IMyDecoy>(decoys, (b) => b.CustomName.Contains(GroupName));
                status = 1;
            }
Exemple #4
0
        /*
         * 0 init
         * 1 build in progress.
         * 10 completed. check for power, etc. turn off projector
         * 20 Start cut
         * 25 cut in progress.
         *
         */
        void doModeUnderconstruction()
        {
            StatusLog("clear", textPanelReport);
            StatusLog(moduleName + ":Under Construction!", textPanelReport);
            Echo("Under Contruction: " + current_state);

            if (AnyConnectorIsLocked())
            {
                ConnectAnyConnectors();
            }

            if (current_state == 0)
            {
                powerDownThrusters(thrustAllList, thrustAll, true);
                antennaLowPower();
                SensorsSleepAll();
                initCutters();
                initProjectors();
                // turn gyos off?
                current_state = 1;
            }
            else if (current_state == 1)
            {
                // recreate getLocalConnectors, but don't ignore connectors that are connected to 'us'
                connectorsInit();

                for (int i = 0; i < localDockConnectors.Count; i++)
                {
                    IMyShipConnector sc = localDockConnectors[i] as IMyShipConnector;
                    if (sc.Status == MyShipConnectorStatus.Connectable)
                    {
                        sc.ApplyAction("SwitchLock");
                    }
                    if (sc.Status == MyShipConnectorStatus.Connected)
                    {
                        Echo("Connected to Print Head!");
                        // try to pull stuff?

                        // or maybe use TIM?
                    }
                }
                // TODO:
                // Try to pull stuff
                //  Uranium to reactors
                initReactors();

                //  Ice to Gas Gens.
                gasgenInit();

                // Turn batteries to recharge
                initBatteries();
                batteryDischargeSet(true, false);

                // put tanks to "Stockpile"
                tanksInit();
                TanksStockpile(true);

                if (doProjectorCheck())
                { // we are done projecting.
                    current_state = 10;
                }
            }
            else if (current_state == 10)
            { // turn off projectors.
                turnoffProjectors();
                //TODO:
                // check for 'enough' power to continue alone.
                {
                    // when 'enough':
                    // turn tanks off stockpile
                    TanksStockpile(false);

                    // turn batteries off recharge
                    batteryDischargeSet(true, true);
                    // (request to) turn off welders

                    // then change state:
                    current_state = 20;
                }
            }
            else if (current_state == 20)
            { // start the cut
                doCut();
                current_state = 25;
            }
            else if (current_state == 25)
            { // cut-off in progress
                doCut();
                if (calcGridSystemChanged())
                {
                    doCut(false);
                    current_state = 100;
                    if (AnyConnectorIsConnected())
                    {
                        setMode(MODE_DOCKED);
                    }
                }
                // maybe need a time-out?
            }
            else if (current_state == 100)
            { // cut-off done.
                if (AnyConnectorIsConnected())
                {
                    setMode(MODE_DOCKED);
                }
                // TODo: autolaunch if not connected?
            }
        }