Esempio n. 1
0
    public void Main(string argument)
    {
        if (argument == "Start")
        {
            GravOn = true;
        }
        if (argument == "Stop")
        {
            foreach (IMyGravityGenerator grav in gravigenlist)
            {
                grav.ApplyAction("OnOff_Off");
            }

            foreach (IMyArtificialMassBlock mass in MassList)
            {
                mass.ApplyAction("OnOff_Off");
            }

            gyroscope.GyroOverride = false;
            gyroscope.ApplyAction("OnOff_Off");

            GravOn = false;
        }

        if (GravOn)
        {
            UpdateGravDrive();
        }
    }
    void GyroOverride(bool isOverride, Vector3 v, float power = 1)
    {
        var gyros = new List <IMyTerminalBlock>();

        GridTerminalSystem.SearchBlocksOfName("Gyro", gyros);
        for (int i = 0; i < gyros.Count; i++)
        {
            IMyGyro gyro = gyros[i] as IMyGyro;
            if (gyro != null)
            {
                if ((!gyro.GyroOverride && isOverride) || (gyro.GyroOverride && !isOverride))
                {
                    gyro.ApplyAction("Override");
                }

                gyro.SetValue("Power", power);
                gyro.SetValue("Yaw", v.GetDim(0));
                gyro.SetValue("Pitch", v.GetDim(1));
                gyro.SetValue("Roll", v.GetDim(2));
            }
        }
    }
Esempio n. 3
0
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10 | UpdateFrequency.Update100;
            ini.TryParse(Storage);

            antenna   = GridTerminalSystem.GetBlockWithName("Antenna Miner#1") as IMyRadioAntenna;
            rc        = GridTerminalSystem.GetBlockWithName("rc") as IMyRemoteControl;
            gyro      = GridTerminalSystem.GetBlockWithName("Gyroscope") as IMyGyro;
            connector = GridTerminalSystem.GetBlockWithName("Connector") as IMyShipConnector;
            connector.PullStrength = float.PositiveInfinity;

            if (connector.Status == MyShipConnectorStatus.Connected)
            {
                goodsetup = false;
            }

            shipMass = rc.CalculateShipMass().TotalMass;

            if (connector.Orientation.Forward == rc.Orientation.Forward)
            {
                rcDockingDir = Base6Directions.Direction.Forward;
            }
            else if (connector.Orientation.Forward == Base6Directions.GetFlippedDirection(rc.Orientation.Forward))
            {
                rcDockingDir = Base6Directions.Direction.Backward;
            }
            else if (connector.Orientation.Forward == rc.Orientation.Left)
            {
                rcDockingDir = Base6Directions.Direction.Left;
            }
            else if (connector.Orientation.Forward == Base6Directions.GetFlippedDirection(rc.Orientation.Left))
            {
                rcDockingDir = Base6Directions.Direction.Right;
            }
            else if (connector.Orientation.Forward == rc.Orientation.Up)
            {
                rcDockingDir = Base6Directions.Direction.Up;
            }
            else if (connector.Orientation.Forward == Base6Directions.GetFlippedDirection(rc.Orientation.Up))
            {
                rcDockingDir = Base6Directions.Direction.Down;
            }
            else
            {
                Echo("ERROR: ORIENTATION MATCHING FAILED");
            }

            BoundingBoxD boundingBox = rc.CubeGrid.WorldAABB;

            lengthOfShip = Vector3D.Distance(boundingBox.Max, boundingBox.Min);


            gyros = new List <IMyGyro>();
            GridTerminalSystem.GetBlocksOfType(gyros);

            foreach (IMyGyro gyro in gyros)
            {
                gyro.Pitch        = 0;
                gyro.Yaw          = 0;
                gyro.GyroOverride = false;
                gyro.ApplyAction("OnOff_On");
            }

            if (ini.ContainsKey("save", "password"))
            {
                password = ini.Get("save", "password").ToString();
            }
            else if (customPasswordMode)
            {
                password = customPassword;
            }
            else
            {
                Random r = new Random();
                password = r.Next(1000000, 9999999) + "";
            }

            allThrusters = new List <IMyThrust>();
            GridTerminalSystem.GetBlocksOfType(allThrusters);

            allThrustGroups.Add(leftThrusterGroup);
            allThrustGroups.Add(rightThrusterGroup);
            allThrustGroups.Add(upThrusterGroup);
            allThrustGroups.Add(downThrusterGroup);
            allThrustGroups.Add(backThrusterGroup);

            foreach (IMyThrust thruster in allThrusters)
            {
                if (thruster.Orientation.Forward == Base6Directions.GetFlippedDirection(connector.Orientation.Up))
                {
                    downThrusterGroup.Add(thruster);
                }
                else if (thruster.Orientation.Forward == connector.Orientation.Up)
                {
                    upThrusterGroup.Add(thruster);
                }
                else if (thruster.Orientation.Forward == connector.Orientation.Left)
                {
                    leftThrusterGroup.Add(thruster);
                }
                else if (thruster.Orientation.Forward == Base6Directions.GetFlippedDirection(connector.Orientation.Left))
                {
                    rightThrusterGroup.Add(thruster);
                }
                else if (thruster.Orientation.Forward == Base6Directions.GetFlippedDirection(connector.Orientation.Forward))
                {
                    backThrusterGroup.Add(thruster);
                    totalBackForce += thruster.MaxEffectiveThrust;
                }
            }

            if (ini.ContainsKey("save", "linkedConnectorName"))
            {
                linkedConnectorName = ini.Get("save", "linkedConnectorName").ToString();
            }
            if (ini.ContainsKey("save", "groupName"))
            {
                linkedConnectorName = ini.Get("save", "groupName").ToString();
            }
            if (ini.ContainsKey("save", "dockingConnectorPos"))
            {
                Vector3D.TryParse(ini.Get("save", "dockingConnectorPos").ToString(), out dockingConnectorPos);
            }
            if (ini.ContainsKey("save", "dockingDir"))
            {
                Vector3D.TryParse(ini.Get("save", "dockingDir").ToString(), out dockingDir);
            }

            if (ini.ContainsKey("save", "mode"))
            {
                Int32.TryParse(ini.Get("save", "mode").ToString(), out mode);
            }
            var            k = 0;
            MyWaypointInfo element;

            globalPath.Clear();
            while (ini.ContainsKey("save", "globalPath_" + k))
            {
                MyWaypointInfo.TryParse(ini.Get("save", "globalPath_" + k).ToString(), out element);
                globalPath.Add(element);
                k++;
            }

            reversePath.Clear();
            reversePath = globalPath;
            reversePath.Reverse();
        }
Esempio n. 4
0
        Boolean Dock3()
        {
            mode = 3;

            foreach (IMyThrust thruster in allThrusters)
            {
                thruster.ThrustOverridePercentage = 0;
            }

            rc.SetAutoPilotEnabled(false);
            foreach (IMyGyro gyro in gyros)
            {
                gyro.ApplyAction("OnOff_On");
            }

            double yaw;
            double pitch;

            Boolean yawLock   = false;
            Boolean pitchLock = false;

            GetRotationAngles(Vector3D.Negate(dockingDir), connector, out yaw, out pitch);
            ApplyGyroOverride(pitch, yaw, 0, gyros, connector);

            if (yaw < 0.01)
            {
                yawLock = true;
            }
            if (pitch < 0.01)
            {
                pitchLock = true;
            }

            Echo("yawLock:" + yawLock);
            Echo("pitchLock" + pitchLock);

            if (pitchLock && yawLock)
            {
                Vector3D closestPoint;
                double   distanceFromDockingVector = DistanceFromVector(dockingConnectorPos, dockingDir, connector.GetPosition(), out closestPoint);

                Echo("Distance from docking vector:" + distanceFromDockingVector);

                if (distanceFromDockingVector > 0.35)
                {
                    NewAdjustTest(closestPoint, connector, distanceFromDockingVector);
                }
                else if (distanceFromDockingVector == -1)
                {
                    Echo("Error in docking vector distance calculation");
                }
                else
                {
                    float shipmass = rc.CalculateShipMass().TotalMass;
                    if (rc.GetShipSpeed() < 1.5)
                    {
                        foreach (IMyThrust thruster in backThrusterGroup)
                        {
                            thruster.ThrustOverride = shipmass;
                        }
                    }
                    else
                    {
                        foreach (IMyThrust thruster in backThrusterGroup)
                        {
                            thruster.ThrustOverridePercentage = 0;
                        }
                    }

                    if (Vector3D.Distance(dockingConnectorPos, rc.GetPosition()) > errorDistance)
                    {
                        Storage             = "";
                        dockingConnectorPos = new Vector3D();
                        dockingDir          = new Vector3D();
                        mode = 0;
                        globalPath.Clear();
                        rc.ClearWaypoints();
                        foreach (IMyThrust thrust in allThrusters)
                        {
                            thrust.ThrustOverridePercentage = 0;
                        }

                        foreach (IMyGyro gyro in gyros)
                        {
                            gyro.GyroOverride = false;
                            gyro.Pitch        = 0;
                            gyro.Yaw          = 0;
                            gyro.Roll         = 0;
                        }

                        Boolean sent = antenna.TransmitMessage("canceldock," + password);
                        if (!sent)
                        {
                            messageQue.Add("canceldock," + password);
                        }
                        antenna.CustomName += " ERROR";
                    }
                }
            }

            if (connector.Status == MyShipConnectorStatus.Connectable)
            {
                connector.Connect(); mode = 5;
                globalPath.Clear();

                foreach (IMyThrust thruster in allThrusters)
                {
                    thruster.ThrustOverridePercentage = 0;
                }

                foreach (IMyGyro gyro in gyros)
                {
                    gyro.Pitch = 0;
                    gyro.Yaw   = 0;
                    gyro.Roll  = 0;
                }
                return(true);
            }
            return(false);
        }