Exemple #1
0
        private void StateWaitForWelderActiviation()
        {
            DrawText("State: WaitForWelderActiviation");

            if (m_updateSource == UpdateType.Terminal)
            {
                String message = ReceiveMessage(m_argument);

                List <String> listSplittedMessage = message.Split('|').ToList();

                // sender|receiver|signature|signaturevalue|messagetype

                if (listSplittedMessage.Count == 5)
                {
                    String senderId       = listSplittedMessage[0];
                    String receiverId     = listSplittedMessage[1];
                    String signature      = listSplittedMessage[2];
                    String signatureValue = listSplittedMessage[3];
                    String messageType    = listSplittedMessage[4];

                    if ((receiverId == m_shipName) && (senderId == m_dockyardName))
                    {
                        if (messageType == "WELDERON")
                        {
                            m_internalState = EInternalState.Assembling;
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void StateSendWelderActiviationRequest()
        {
            // sender|receiver|signature|signaturevalue|messagetype

            String message = m_shipName + "|" + m_dockyardName + "|0|0|ACTIVATEWELDER".ToUpper();

            TransmitMessage(message);

            m_internalState = EInternalState.WaitForWelderActiviation;
        }
Exemple #3
0
        private void StatePrepare()
        {
            DrawText("State: Prepare");

            if (ExtendPiston())
            {
                ToggleOnShipWelder();

                m_internalState = EInternalState.Assembling;
            }
        }
Exemple #4
0
        //------------------------------------------------------------------------

        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10;

            m_listShipPiston   = new List <IMyExtendedPistonBase> ();
            m_listShipWelder   = new List <IMyShipWelder> ();
            m_listRotor        = new List <IMyMotorRotor> ();
            m_listWarningLight = new List <IMyLightingBlock> ();

            m_listError = new List <String> ();

            m_internalState = EInternalState.Idle;
        }
Exemple #5
0
        //------------------------------------------------------------------------

        public void Main(string argument, UpdateType updateSource)
        {
            if (GetShipSystems())
            {
                //------------------------------------------------------------------
                // Environment
                //------------------------------------------------------------------

                m_textPanel.WritePublicText("");

                m_listError.Clear();

                m_argument     = argument;
                m_updateSource = updateSource;
                m_dateTimeNow  = DateTime.Now;

                m_currentPosition = Me.CubeGrid.GridIntegerToWorld(Me.Position);

                //------------------------------------------------------------------

                DrawText("//--------------------------------------------");
                DrawText("// ASSEMBLER2000 BY VX TEK AUTOMATING SYSTEMS ");
                DrawText("//--------------------------------------------");
                DrawText("");

                DrawText("Date " + m_dateTimeNow.ToShortDateString() + " " + m_dateTimeNow.ToLongTimeString());

                DrawText("Current position  : " + m_currentPosition.X + ":" + m_currentPosition.Y + ":" + m_currentPosition.Z);
                DrawText("Last position     : " + m_lastPosition.X + ":" + m_lastPosition.Y + ":" + m_lastPosition.Z);

                DrawText("Current ship speed: " + Vector3D.Distance(m_lastPosition, m_currentPosition));

                //------------------------------------------------------------------
                // State machine
                //------------------------------------------------------------------

                switch (m_internalState)
                {
                case EInternalState.Idle: { StateIdle(); } break;

                case EInternalState.Assembling: { StateAssembling(); } break;

                case EInternalState.Error: { StateAssembling(); } break;
                }
            }
            else
            {
                m_internalState = EInternalState.Error;
            }
        }
Exemple #6
0
        //------------------------------------------------------------------------

        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10;

            m_listThrusterForward = new List <IMyThrust> ();

            m_listError = new List <String> ();

            m_lastPosition = Me.CubeGrid.GridIntegerToWorld(Me.Position);

            m_internalState = EInternalState.Idle;

            for (int nIndex = 0; nIndex < m_alphabet.Length; nIndex++)
            {
                m_dictAlphabet.Add(m_alphabet  [nIndex], nIndex);
            }
        }
Exemple #7
0
        public void Main(String argument, UpdateType updateSource)
        {
            if (InitSystems())
            {
                //------------------------------------------------------------------
                // Environment
                //------------------------------------------------------------------

                m_listError.Clear();             // Clear errorlog

                m_textPanel.WritePublicText(""); // Clear panel

                m_argument     = argument;
                m_updateSource = updateSource;
                m_dateTimeNow  = DateTime.Now;

                //------------------------------------------------------------------

                DrawText("//----------------------------------------------");
                DrawText("// Freddi BY VX TEK AUTOMATING SYSTEMS");
                DrawText("//----------------------------------------------");
                DrawText("");

                DrawText("Date " + m_dateTimeNow.ToShortDateString() + " " + m_dateTimeNow.ToLongTimeString());

                //------------------------------------------------------------------
                // State machine
                //------------------------------------------------------------------

                switch (m_internalState)
                {
                case EInternalState.Idle: { StateIdle(); } break;

                case EInternalState.Prepare: { StatePrepare(); } break;

                case EInternalState.Assembling: { StateAssembling(); } break;

                case EInternalState.Error: { StateError(); } break;
                }
            }
            else
            {
                m_internalState = EInternalState.Error;
            }
        }
Exemple #8
0
        //------------------------------------------------------------------------

        private void StateIdle()
        {
            DrawText("State: Idle");

            if ((m_updateSource == UpdateType.Trigger) && (m_argument == "STARTASSEMBLING"))
            {
                m_lastAssemblingChange = m_dateTimeNow;
                m_lastRemainingBlocks  = m_projector.RemainingBlocks;

                m_lastPosition = Me.CubeGrid.GridIntegerToWorld(Me.Position);

                m_lastPositionTime = m_dateTimeNow;

                m_internalState = EInternalState.Assembling;
            }
            else
            {
                SetThrusterOverride(0.0f);
            }
        }
Exemple #9
0
        //------------------------------------------------------------------------
        // State machine
        //------------------------------------------------------------------------

        private void StateIdle()
        {
            DrawText("State: Idle");

            if ((m_updateSource == UpdateType.Trigger) && (m_argument == "STARTASSEMBLING"))
            {
                if ((m_projector.IsProjecting) && (m_projector.RemainingBlocks > 0))
                {
                    m_lastAssemblingChange = m_dateTimeNow;
                    m_lastRemainingBlocks  = m_projector.RemainingBlocks;

                    m_internalState = EInternalState.Prepare;
                }
            }
            else
            {
                RetractPiston();
                ToggleOffShipWelder();
                ShowIdleLights();
            }
        }
Exemple #10
0
        private void StateAssembling()
        {
            DrawText("State: Assembling");

            DrawText("RemainingBlocks: " + m_projector.RemainingBlocks);

            if (m_projector.RemainingBlocks == 0)
            {
                if (RetractPiston())
                {
                    m_internalState = EInternalState.Idle;
                }
            }
            else
            {
                ShowWarningLights();

                bool bWelding = false;

                List <IMyTerminalBlock> listTerminalBlock = new List <IMyTerminalBlock> ();

                GridTerminalSystem.GetBlocks(listTerminalBlock);

                for (int nIndex = 0; !bWelding && (nIndex < listTerminalBlock.Count); nIndex++)
                {
                    IMyTerminalBlock terminalBlock = listTerminalBlock [nIndex];

                    IMySlimBlock slimBlock = terminalBlock.CubeGrid.GetCubeBlock(terminalBlock.Position);

                    if (slimBlock.BuildLevelRatio < 1.0f)
                    {
                        bWelding = true;
                    }
                }

                if (bWelding)
                {
                    DrawText("Currently welding some blocks...");

                    StopPiston();
                }
                else if (m_projector.RemainingBlocks == m_lastRemainingBlocks)
                {
                    DrawText("Okay lets retract piston to find remaining blocks...");

                    if (RetractPiston())
                    {
                        m_internalState = EInternalState.Idle;
                    }
                }

                //------------------------------------------------------------------
                // Checking timeout
                //------------------------------------------------------------------

                if (m_projector.RemainingBlocks != m_lastRemainingBlocks)
                {
                    DrawText("Progress in work, update block info...");

                    m_lastRemainingBlocks = m_projector.RemainingBlocks;

                    m_lastAssemblingChange = m_dateTimeNow;
                }
                else
                {
                    DrawText("No progress checking timeout...");

                    TimeSpan timeElapsedLastChange = m_dateTimeNow - m_lastAssemblingChange;

                    if (timeElapsedLastChange.Seconds > 60)
                    {
                        m_internalState = EInternalState.Idle;
                    }
                }
            }
        }
Exemple #11
0
        private void StateAssembling()
        {
            DrawText("State: Assembling");

            DrawText("RemainingBlocks: " + m_projector.RemainingBlocks);

            if (m_projector.RemainingBlocks == 0)
            {
                SetThrusterOverride(0.0f);

                m_internalState = EInternalState.Idle;
            }
            else
            {
                bool bWelding = false;

                List <IMyTerminalBlock> listTerminalBlock = new List <IMyTerminalBlock> ();

                GridTerminalSystem.GetBlocks(listTerminalBlock);

                for (int nIndex = 0; !bWelding && (nIndex < listTerminalBlock.Count); nIndex++)
                {
                    IMyTerminalBlock terminalBlock = listTerminalBlock [nIndex];

                    IMySlimBlock slimBlock = terminalBlock.CubeGrid.GetCubeBlock(terminalBlock.Position);

                    if (slimBlock.BuildLevelRatio < 1.0f)
                    {
                        bWelding = true;
                    }
                }

                if (bWelding)
                {
                    SetThrusterOverride(0.0f);

                    m_lastAssemblingChange = m_dateTimeNow;
                }
                else
                {
                    DrawText("XXXXXX");

                    if (m_projector.RemainingBlocks != m_lastRemainingBlocks)
                    {
                        m_lastRemainingBlocks = m_projector.RemainingBlocks;

                        m_lastAssemblingChange = m_dateTimeNow;
                    }

                    //---------------------------------------------------------------
                    // Check speed
                    //---------------------------------------------------------------

                    double distance = Vector3D.Distance(m_currentPosition, m_lastPosition);

                    DrawText("XXXXXX" + distance);

                    TimeSpan timeElapsed = m_dateTimeNow - m_lastPositionTime;

                    if (timeElapsed.TotalSeconds >= m_distanceCheckInterval)
                    {
                        if (distance > m_maxDistancePerSecond)
                        {
                            SetThrusterOverride(0.0f);
                        }
                        else
                        {
                            SetThrusterOverride(m_backThrustPercent);
                        }

                        m_lastPosition     = m_currentPosition;
                        m_lastPositionTime = m_dateTimeNow;
                    }
                }

                //------------------------------------------------------------------
                // Checking progress
                //------------------------------------------------------------------

                TimeSpan timeElapsedLastChange = m_dateTimeNow - m_lastAssemblingChange;

                if (timeElapsedLastChange.Seconds > 60)
                {
                    m_listError.Add("No progress, sthudown engines and go in error state");

                    SetThrusterOverride(0.0f);

                    m_internalState = EInternalState.Error;
                }
            }
        }