コード例 #1
0
        private void setArtificialGravity(float gnat, float g)
        {
            float eff = getAGravEfficacy(gnat);
            float f   = eff <= 0 ? 0 : 1F / eff;

            if (SPLIT_GRAVITY)
            {
                f /= gravGens.Count;
            }
            if (gravDriveOn())
            {
                Echo("Gravity Drive is working, all other gravity disabled.");
                f = 0;
            }
            else
            {
                Echo("Setting gravity generator level to " + f * 100 + "% in direction " + upDirection.ToString());
            }
            foreach (IMyGravityGenerator gen in gravGens)
            {
                if (f <= 0 || g <= 0)
                {
                    gen.Enabled = false;
                }
                else
                {
                    float sign = 0;
                    if (gen.Orientation.Up == upDirection)
                    {
                        sign = 1;
                    }
                    else if (gen.Orientation.Up == Base6Directions.GetFlippedDirection(upDirection))
                    {
                        sign = -1;
                    }
                    float amt = g * 9.81F * f * sign;
                    gen.Enabled             = Math.Abs(amt) > 0;
                    gen.GravityAcceleration = amt;
                }
            }
        }
コード例 #2
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (goodsetup)
            {
                Echo("LastR: " + lastReversePath);
                Echo("Mode: " + mode);
                Echo("DockingDir: " + rcDockingDir.ToString());
                Echo("Password: "******"Argument: " + argument);
                    string[] info = argument.Split(new string[] { "," }, StringSplitOptions.None);

                    if (updateSource != UpdateType.Antenna)
                    {
                        if (info[0].ToLower() == "dock")
                        {
                            if (info.Length == 1)
                            {
                                Boolean sent = antenna.TransmitMessage("requestdock," + password + ",default");
                                if (!sent)
                                {
                                    messageQue.Add("requestdock," + password + ",default");
                                }
                            }
                            else if (info.Length == 2)
                            {
                                Boolean sent = antenna.TransmitMessage("requestdock," + password + "," + info[1]);
                                if (!sent)
                                {
                                    messageQue.Add("requestdock," + password + "," + info[1]);
                                }
                                groupName = info[1];
                            }
                            else if (info.Length == 3)
                            {
                                Boolean sent = antenna.TransmitMessage("requestdock," + password + "," + groupName + "," + info[2]);
                                if (!sent)
                                {
                                    messageQue.Add("requestdock," + password + "," + groupName + "," + info[2]);
                                }
                            }
                            else
                            {
                                Echo("ERROR, ARGUMENT SIZE INVALID");
                            }
                        }
                        else if (info[0].ToLower() == "stop")
                        {
                            Storage             = "";
                            dockingConnectorPos = new Vector3D();
                            dockingDir          = new Vector3D();
                            mode = 0;
                            globalPath.Clear();
                            reversePath.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);
                            }
                        }

                        else if (info[0] == "depart")
                        {
                            if (mode == 5 && connector.Status == MyShipConnectorStatus.Connected)
                            {
                                Main("dock," + groupName + ",leaving", UpdateType.Mod);
                            }
                            else
                            {
                                Echo("ERROR, WRONG MODE OR ALREADY DISCONNECTED");
                            }
                        }

                        else if (info[0].ToLower() == "newpassword")
                        {
                            Random r = new Random();
                            password = r.Next(1000000, 9999999) + "";
                        }
                    }

                    else if (updateSource == UpdateType.Antenna && info[0] == password)
                    {
                        Echo("Message Received: " + argument);
                        if (info[1] == "received" && info.Length == 3) //info[2] is name of spaceport
                        {
                            Echo("Request to '" + info[2] + "' was received, awaiting further instruction.");
                        }
                        else if (info[1] == "fail")
                        {
                            Echo("Request to '" + info[3] + "' failed.");
                        }
                        else if (info[1] == "rejected")
                        {
                            Echo("TOOK TO LONG, DOCKING PERMISSION REJECTED");
                            mode = 0;
                            rc.SetAutoPilotEnabled(false);
                            antenna.CustomName += " ERROR";
                        }
                        else if (info[1] == "wait")
                        {
                            Echo("Request to '" + info[3] + "' success, but placed into waiting que");
                            waiting = true;
                        }
                        else if (info[1] == "dockinginfo")
                        {
                            if (mode == 5)
                            {
                                connector.Disconnect();
                                List <MyWaypointInfo> path = new List <MyWaypointInfo>();
                                string[] strWaypoints      = new string[info.Length - 5];

                                for (int i = 0; i < strWaypoints.Length; i++)
                                {
                                    strWaypoints[i] = info[i + 5];
                                }

                                foreach (string waypoint in strWaypoints)
                                {
                                    MyWaypointInfo newPoint;
                                    Boolean        pass = MyWaypointInfo.TryParse(waypoint, out newPoint);
                                    if (pass)
                                    {
                                        path.Add(newPoint);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                path.Reverse();
                                reversePath = path;
                                EnableRC(reversePath, out path);
                                mode = 6;
                            }
                            else if (info.Length == 5)
                            {
                                linkedConnectorName = info[2];
                                string strConnectorPos = info[3];
                                string strDockingDir   = info[4];

                                //parse str's into their proper values
                                Boolean pass1 = Vector3D.TryParse(strConnectorPos, out dockingConnectorPos);
                                Boolean pass2 = Vector3D.TryParse(strDockingDir, out dockingDir);

                                Dock2(dockingConnectorPos, dockingDir); mode = 2;
                            }
                            else if (info.Length > 5)
                            {
                                linkedConnectorName = info[2];
                                string   strConnectorPos = info[3];
                                string   strDockingDir   = info[4];
                                string[] strWaypoints    = new string[info.Length - 5];
                                for (int i = 0; i < strWaypoints.Length; i++)
                                {
                                    strWaypoints[i] = info[i + 5];
                                }

                                //parse str's into their proper values
                                Boolean pass1 = Vector3D.TryParse(strConnectorPos, out dockingConnectorPos);
                                Boolean pass2 = Vector3D.TryParse(strDockingDir, out dockingDir);
                                pass2 = false;

                                List <MyWaypointInfo> path = new List <MyWaypointInfo>();
                                Boolean pass3 = true;
                                foreach (string waypoint in strWaypoints)
                                {
                                    pass2 = true;
                                    MyWaypointInfo newPoint;
                                    pass3 = MyWaypointInfo.TryParse(waypoint, out newPoint);
                                    if (pass3)
                                    {
                                        path.Add(newPoint);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                if (pass1 && pass2 && pass3)
                                {
                                    EnableRC(path, out globalPath);
                                    reversePath.Reverse();
                                    mode = 1;
                                }
                                else
                                {
                                    Echo(pass1 + " " + pass2 + " " + pass3);
                                }
                            }
                        }
                    }
                    else if (info[0] == "antennapos" && info.Length == 2)
                    {
                        Boolean updated = Vector3D.TryParse(info[1], out antennaPos);
                        if (updated)
                        {
                            antenna.Radius = (float)(Vector3D.Distance(rc.GetPosition(), antennaPos) + 10);
                        }
                        else
                        {
                            Echo("Failed to update antenna position");
                        }
                    }
                    else if (mode == 2 && !rc.IsAutoPilotEnabled && Vector3D.Distance(rc.GetPosition(), rc.CurrentWaypoint.Coords) >= 5)
                    {
                        rc.SetAutoPilotEnabled(true);
                    }
                    else if (mode == 1 && globalPath.Count != 0)
                    {
                        FollowPath(globalPath, true);
                    }
                }
                else if (mode == 1)
                {
                    FollowPath(globalPath, true);
                }
                else if (mode == 2 && rc.IsAutoPilotEnabled && Vector3D.Distance(rc.GetPosition(), rc.CurrentWaypoint.Coords) < 5)
                {
                    Dock3();
                    Boolean sent = antenna.TransmitMessage("freepath," + groupName);
                    if (!sent)
                    {
                        messageQue.Add("freepath," + groupName);
                    }
                }
                else if (mode == 2 && !rc.IsAutoPilotEnabled && Vector3D.Distance(rc.GetPosition(), rc.CurrentWaypoint.Coords) >= 5)
                {
                    rc.SetAutoPilotEnabled(true);
                }
                else if (mode == 3 && Dock3())
                {
                    Echo("DOCKED!");
                }
                else if (mode == 6)
                {
                    FollowPath(reversePath, false);
                }
                else if (updateSource == UpdateType.Update100)
                {
                    shipMass = rc.CalculateShipMass().TotalMass;
                }

                if (waiting)
                {
                    Echo("Waiting for clearance");
                }
            }
            else
            {
                Echo("SETUP FAILED. DO NOT SETUP WHILE CONNECTED TO ANOTHER GRID");
            }
        }
コード例 #3
0
 public override string ToString()
 {
     return(LocalGridPosition.ToString() + " -> " + Direction.ToString());
 }
コード例 #4
0
        void DetailedInfo()
        {
            StringBuilder sb = new StringBuilder();

            //if (false || (InputErrorTimeout > time && InputErrors.Count > 0))
            //{
            //sb.AppendLine("____Input Errors_________");
            //foreach (var item in InputErrors)
            //{
            //	sb.AppendLine(AdjustTextToWidth("- " + item, detailedInfoTextWith));
            //}

            //sb.AppendLine();
            //sb.AppendLine("____Input Options_________");
            //sb.AppendLine("Options within [brackets] are optional.");
            //sb.AppendLine("Several comma separated");
            //sb.AppendLine("commands are allowed.");
            //sb.AppendLine();
            //sb.AppendLine("?");
            //sb.AppendLine("Prints this message.");
            //sb.AppendLine();
            //sb.AppendLine("cruise [on | off] [#]");
            //sb.AppendLine("Toggle or set state and target speed");
            //sb.AppendLine("of cruise control.");
            //sb.AppendLine();
            //sb.AppendLine("align [on | off]");
            //sb.AppendLine("Toggle or set state of alignment.");
            //sb.AppendLine();
            //sb.AppendLine("speed #");
            //sb.AppendLine("Set target speed. Negative values");
            //sb.AppendLine("for descent. (Save before attepting,");
            //sb.AppendLine("there's no guarantee you'll stop in time.)");
            //sb.AppendLine();
            //sb.AppendLine("travel up | down | forward | backward | auto");
            //sb.AppendLine("Direction of travel in relation to");
            //sb.AppendLine("your cockpit/flight seat.");
            //sb.AppendLine();
            //sb.AppendLine("alt-max #");
            //sb.AppendLine("Target altitude to reach when ascending. ");
            //sb.AppendLine("Set to -1 for infinity, space.");
            //sb.AppendLine();
            //sb.AppendLine("alt-min #");
            //sb.AppendLine("Target altitude to reach when decending.");
            //sb.AppendLine("Altitude is measured at center of");
            //sb.AppendLine("mass. There's no guarantee you'll");
            //sb.AppendLine("stop in time.");
            //sb.AppendLine();
            //sb.AppendLine("reference sea | ground");
            //sb.AppendLine("When ascending to a max altitude.");
            //sb.AppendLine("Ground is good for keeping a");
            //sb.AppendLine("distance from the ground.");
            //sb.AppendLine("Sea is good for keeping a");
            //sb.AppendLine("consistent altitude, i.e. an orbit.");
            //sb.AppendLine();
            //sb.AppendLine("0g-align on | off");
            //sb.AppendLine("If align should stay engaged after");
            //sb.AppendLine("leaving the planets gravity.");
            //sb.AppendLine();
            //sb.AppendLine("0g-cruise on | off");
            //sb.AppendLine("If cruise control should stay engaged");
            //sb.AppendLine("after leaving the planets gravity.");


            //}
            //else
            //{

            sb.AppendLine("Blarg's Ascent Cruise Control");
            sb.AppendLine($"Cruise: {(Cruise != null && Cruise.Enabled ? "on" : "off")}   |   Align: {(Align != null && Align.Enabled ? "on" : "off")} ");

            if (Errors.Count > 0)
            {
                sb.AppendLine();
                sb.AppendLine("____Errors_________");
                foreach (var item in Errors)
                {
                    sb.AppendLine(AdjustTextToWidth("- " + item.Value, detailedInfoTextWith));
                }
            }

            if (InputErrorTimeout > time && InputErrors.Count > 0)
            {
                sb.AppendLine();
                sb.AppendLine("____Input Errors_________");
                foreach (var item in InputErrors)
                {
                    sb.AppendLine(AdjustTextToWidth("- " + item, detailedInfoTextWith));
                }
            }



            sb.AppendLine();
            sb.AppendLine("____Start/stop_________");
            sb.AppendLine("Commands:");
            sb.AppendLine("- cruise [on|off][#]");
            sb.AppendLine("- align [on|off]");
            sb.AppendLine("[optional], will toggle if");
            sb.AppendLine("omitted. # is target speed.");


            sb.AppendLine();
            sb.AppendLine("____Settings_________");
            sb.AppendLine("Type 'prefix value' and press");
            sb.AppendLine("run to set, for example 'ts 100'");
            sb.AppendLine("Run just the prefix for details.");

            if (Cruise != null)
            {
                sb.AppendLine();
                sb.AppendLine("____Cruise Control_________");
                sb.AppendLine($"ts    Target speed: {targetSpeed.ToString("n0")} ");
                sb.AppendLine($"cg   Disable at zero-G: {(disableCruiseExitingGravity ? "Yes" : "No")}");
                sb.AppendLine($"td    Travel direction: {(thrustDirection == Base6Directions.Direction.Left ? "Auto (" + Cruise.Forward.ToString() + ")" : thrustDirection.ToString())}");
                sb.AppendLine($"mx  Target altiude max: {(targetAltAscending == double.MaxValue ? "••" : targetAltAscending.ToString("n0") + "m")}");
                sb.AppendLine($"mn  Target altiude min: {targetAltDescending.ToString("n0") + "m"}");
                sb.AppendLine($"rf     Max altiude reference: {(useSeaLevel ? "Sealevel" : "Ground")}");
                sb.AppendLine($"ws  World top speed: {worldTopSpeed.ToString("n0")}");
            }
            if (Align != null)
            {
                sb.AppendLine();
                sb.AppendLine("____Aligner_________");
                sb.AppendLine($"ag   Disable at zero-G: {(disableAlignExitingGravity ? "yes" : "no")}");
            }
            //}

            Echo(sb.ToString());
        }