Exemplo n.º 1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Map"/> class.
            /// </summary>
            /// <param name="celestialBodies">The celestialBodies<see cref="List{CelestialBody}"/>.</param>
            public Map(Program program, List <CelestialBody> celestialBodies)
            {
                this.program = program;
                Inverted     = program._ini.Get(program.ScriptPrefixTag, "Inverted").ToBoolean(false);
                StarRadius   = program._ini.Get(program.ScriptPrefixTag, "StarRadius").ToInt32(100000);
                string         starGpsPos = program._ini.Get(program.ScriptPrefixTag, "StarPosition").ToString();
                MyWaypointInfo starGps    = new MyWaypointInfo();

                if (MyWaypointInfo.TryParse(starGpsPos, out starGps))
                {
                    StarPosition = starGps.Coords;
                }

                CelestialBodies = celestialBodies;
                Planets         = celestialBodies.FindAll(cb => cb.Type == CelestialType.Planet);
                Planets.Sort(SortByDistance);

                minX = StarPosition.X;
                maxX = StarPosition.X;
                minZ = StarPosition.Z;
                maxZ = StarPosition.Z;

                foreach (CelestialBody planet in CelestialBodies)
                {
                    // Sets the maximum distance of the solar system.
                    maxX = planet.Position.X > maxX ? planet.Position.X : maxX;
                    maxZ = planet.Position.Z > maxZ ? planet.Position.Z : maxZ;

                    minX = planet.Position.X < minX ? planet.Position.X : minX;
                    minZ = planet.Position.Z < minZ ? planet.Position.Z : minZ;
                }
            }
Exemplo n.º 2
0
 /// <summary>Creates a new waypoint from an ini string, possibly connected to other waypoints</summary>
 /// <param name="ini">ini that contains the waypoints</param>
 /// <param name="section">name of the section containing information about the waypoints</param>
 public APWaypoint(MyIni ini, string section)
 {
     MyWaypointInfo.TryParse(ini.Get(section, "gps").ToString(), out this.WP);
     Enum.TryParse(ini.Get(section, "type").ToString(), out this.Type);
     Enum.TryParse(ini.Get(section, "terrain").ToString(), out this.Terrain);
     this.waypointsNames = ini.Get(section, "linked-wp").ToString().Split(IniHelper.SEP, StringSplitOptions.RemoveEmptyEntries).ToList();
 }
Exemplo n.º 3
0
 public void Main(string argument, UpdateType updateSource)
 {
     try
     {
         if ((updateSource & (UpdateType.Trigger | UpdateType.Terminal | UpdateType.Script)) != 0)
         {
             UpdateSettings();
             if (argument.Contains("launch"))
             {
                 var            coord = argument.Replace("launch ", "");
                 MyWaypointInfo wp;
                 if (MyWaypointInfo.TryParse(coord, out wp))
                 {
                     LaunchMissiles(wp);
                 }
                 else
                 {
                     LogLine($"Invalid GPS coordinates \"{coord}\", cannot initiate launch.");
                 }
             }
             else if (argument.Contains("abort"))
             {
                 AbortMissiles(detonate: false);
             }
             else if (argument.Contains("detonate"))
             {
                 AbortMissiles(detonate: true);
             }
         }
         if ((updateSource & UpdateType.IGC) != 0)
         {
             if (missileMsgListener.HasPendingMessage)
             {
                 var msg = missileMsgListener.AcceptMessage();
                 LogLine($">: {msg.Data}");
             }
             if (missileStatusListener.HasPendingMessage)
             {
                 var msg = missileStatusListener.AcceptMessage();
                 statusLogger.OutputLine(msg.Data.ToString());
             }
             messageHandler.Tick();
         }
         if ((updateSource & UpdateType.Update100) != 0)
         {
             if (this.directing && this.directorTurret.IsUnderControl)
             {
                 var azimuth = this.directorTurret.Azimuth;
                 var elev    = this.directorTurret.Elevation;
             }
         }
     }
     catch (Exception ex)
     {
         LogLine($"Launch main expection: {ex}\nStacktrace: \n{ex.StackTrace}");
     }
 }
Exemplo n.º 4
0
        public ContestedZone(string gpsCenter, int contestRange)
        {
            _gpsCenter    = gpsCenter;
            _contestRange = contestRange;

            MyWaypointInfo temp_waypoint;

            //..set up the contested zone
            if (MyWaypointInfo.TryParse(_gpsCenter, out temp_waypoint))
            {
                _contestOrigin = temp_waypoint.Coords;
                _contestSphere = new BoundingSphereD(_contestOrigin, _contestRange);
            }
        }
Exemplo n.º 5
0
        void RetrieveCustomSetting()
        {
            // init settings
            _ini.TryParse(Me.CustomData);

            ParkingPeriodAtWaypoint = TimeSpan.FromSeconds(_ini.Get(ScriptPrefixTag, "ParkingPeriod").ToDouble(ParkingPeriodAtWaypoint.TotalSeconds));
            ManageBattery           = _ini.Get(ScriptPrefixTag, "ManageBattery").ToBoolean(ManageBattery);
            MinBatteryCapacity      = _ini.Get(ScriptPrefixTag, "MinBatteryCapacity").ToSingle(MinBatteryCapacity);
            CriticalBatteryCapacity = _ini.Get(ScriptPrefixTag, "CriticalBatteryCapacity").ToSingle(CriticalBatteryCapacity);

            #region Waypoints Settings
            string customDataWaypoints = _ini.Get(ScriptPrefixTag, "Waypoints").ToString();
            if (customDataWaypoints != "")
            {
                string[] _waypoints = customDataWaypoints.Split(',');
                foreach (string waypointData in _waypoints)
                {
                    MyWaypointInfo waypointInfo;
                    if (MyWaypointInfo.TryParse(waypointData, out waypointInfo))
                    {
                        var w = new Waypoint(waypointInfo.Name, waypointInfo.Coords);
                        waypoints.Add(w);
                    }
                }
            }
            #endregion

            #region Orbit Settings
            OrbitMode = _ini.Get(ScriptPrefixTag, "OrbitMode").ToBoolean(false);
            EchoR($"OrbitMode: {OrbitMode}");
            if (OrbitMode)
            {
                OrbitRadius = _ini.Get(ScriptPrefixTag, "OrbitRadius").ToDouble(DefaultOrbitRadius);
                if (OrbitRadius < 100)
                {
                    OrbitRadius = DefaultOrbitRadius;
                }
                EchoR($"OrbitRadius: {OrbitRadius}");
                string         orbitCenterPositionUserData = _ini.Get(ScriptPrefixTag, "OrbitCenterPosition").ToString();
                MyWaypointInfo _tmp;
                if (MyWaypointInfo.TryParse(orbitCenterPositionUserData, out _tmp))
                {
                    OrbitCenterPosition = _tmp.Coords;
                }
                EchoR($"OrbitCenterPosition: {OrbitCenterPosition}");
            }
            #endregion
        }
        void AddWaypoint()
        {
            var            waypointData = int.Parse(_commandLine.Argument(1)).ToString();
            MyWaypointInfo waypointInfo;

            if (MyWaypointInfo.TryParse(waypointData, out waypointInfo))
            {
                var w = new Waypoint(waypointInfo.Name, waypointInfo.Coords);
                waypoints.Add(w);
                EchoR($"New waypoint added: {w}");
            }
            else
            {
                EchoR("Waypoint not recognized");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a location instance from string. Following formats are supported:
        /// <para>- Location.ToString() serialization</para>
        /// <para>- GPS strings</para>
        /// <para>- Vector3D.ToString() serialization</para>
        /// <para>Throws <see cref="ArgumentException"/> if string fails to match any of the above.</para>
        /// </summary>
        /// <param name="source">String to parse.</param>
        /// <returns>Location instance described by the string.</returns>
        public static Location FromString(string source)
        {
            Location       result;
            MyWaypointInfo wp;
            Vector3D       v;

            if (source.StartsWith("LOCATION/") && TryParse(source, out result))
            {
                return(result);
            }
            if (source.StartsWith("GPS:") && MyWaypointInfo.TryParse(source, out wp))
            {
                return(new Location(wp));
            }
            if (Vector3D.TryParse(source, out v))
            {
                return(new Location(v));
            }
            throw new ArgumentException("Not a valid string format: " + source, "source");
        }
Exemplo n.º 8
0
        List <MyWaypointInfo> StringArraytoWaypoint(string[] strList)
        {
            List <MyWaypointInfo> waypointList = new List <MyWaypointInfo>();

            foreach (string coord in strList)
            {
                Echo(coord);
                MyWaypointInfo newWaypointInfo;
                Boolean        passed = MyWaypointInfo.TryParse(coord, out newWaypointInfo);

                if (!passed)
                {
                    return(null);
                }

                waypointList.Add(newWaypointInfo);
            }

            return(waypointList);
        }
            public override void LoadData()
            {
                //..we only need to set up the contested zone for the server
                if (MyAPIGateway.Session.IsServer)
                {
                    MyWaypointInfo temp_waypoint;

                    //..set up the contested zone
                    if (MyWaypointInfo.TryParse((!debug) ? gps_center : gps_debug, out temp_waypoint))
                    {
                        ContestOrigin = temp_waypoint.Coords;
                        ContestZone   = new BoundingSphereD(ContestOrigin, ContestRange);
                    }
                }

                //..we only need to handle messages for clients. the server doesn't need to know
                if (!MyAPIGateway.Session.IsServer || debug)
                {
                    MyAPIGateway.Multiplayer.RegisterMessageHandler(packetId, HandleServerMessage);
                }
            }
Exemplo n.º 10
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();
        }
Exemplo n.º 11
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");
            }
        }
Exemplo n.º 12
0
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update100;
            antenna = GridTerminalSystem.GetBlockWithName("Antenna") as IMyRadioAntenna;
            lcd     = GridTerminalSystem.GetBlockWithName("lcd") as IMyTextPanel;
            rc      = GridTerminalSystem.GetBlockWithName("rc spaceport") as IMyRemoteControl;

            connectorGroupDict.Add("default", defaultConnectorList);

            ini.TryParse(Storage);

            int i = 0;

            messageQue.Clear();
            while (ini.ContainsKey("save", "messageQue_" + i))
            {
                string element = ini.Get("save", "messageQue_" + i).ToString();
                messageQue.Add(element);
                i++;
            }

            i = 0;
            argumentQue.Clear();
            while (ini.ContainsKey("save", "argumentQue_" + i))
            {
                string element = ini.Get("save", "argumentQue_" + i).ToString();
                argumentQue.Add(element);
                i++;
            }

            i = 0;
            dockingQue.Clear();
            while (ini.ContainsKey("save", "dockingQue_" + i))
            {
                QuePos  element = new QuePos("ERROR");
                Boolean success = QuePos.TryParse(ini.Get("save", "dockingQue_" + i).ToString(), out element);
                if (success)
                {
                    dockingQue.Add(element);
                }
                //else add to debug panel
                i++;
            }

            i = 0;
            connectorGroupDict.Clear();
            while (ini.ContainsKey("save", "connectorGroupDict_" + i))
            {
                string   str     = ini.Get("save", "connectorGroupDict_" + i).ToString();
                string[] info    = str.Split(new string[] { "|" }, StringSplitOptions.None);
                string   key     = info[0];
                string[] subInfo = info[1].Split(new string[] { ":" }, StringSplitOptions.None);
                foreach (string data in subInfo)
                {
                    try
                    {
                        string[] subData = data.Split(new string[] { ";" }, StringSplitOptions.None);
                        string   customName = subData[0];
                        Boolean  free; Boolean freeSuccess = Boolean.TryParse(subData[1], out free);
                        int      freeCounter; Boolean freeCounterSuccess = Int32.TryParse(subData[2], out freeCounter);
                        string   reservedPassword = subData[3];

                        if (freeSuccess && freeCounterSuccess)
                        {
                            AddConnector(customName, key, free, freeCounter, reservedPassword);
                        }
                        else
                        {
                            //add info to debug panel
                        }
                    }
                    catch
                    {
                        //add info to debug panel
                    }
                }
                i++;
            }

            i = 0;
            connectorGroupPath.Clear();
            while (ini.ContainsKey("save", "connectorGroupPath_" + i))
            {
                string   str     = ini.Get("save", "connectorGroupPath_" + i).ToString();
                string[] info    = str.Split(new string[] { "|" }, StringSplitOptions.None);
                string   key     = info[0];
                string[] subInfo = info[1].Split(new string[] { ";" }, StringSplitOptions.None);
                List <MyWaypointInfo> waypointInfos = new List <MyWaypointInfo>();
                foreach (string data in subInfo)
                {
                    try
                    {
                        MyWaypointInfo newWaypoint = new MyWaypointInfo();
                        Boolean        success     = MyWaypointInfo.TryParse(data, out newWaypoint);
                        if (success)
                        {
                            waypointInfos.Add(newWaypoint);
                        }
                        else
                        {
                            lcd.WritePublicText("\nFAILED DATA (E): " + data, true);
                        }
                    }
                    catch
                    {
                        lcd.WritePublicText("\nFAILED DATA (C): " + data, true);
                    }
                }
                SetGroupPath(key, waypointInfos);
                i++;
            }
        }
Exemplo n.º 13
0
            /// <summary>
            /// The OnCycle.
            /// </summary>
            /// <param name="lcd">The lcd<see cref="IMyTextPanel"/>.</param>
            public override void OnCycle(IMyTerminalBlock block)
            {
                base.OnCycle(block);
                // Call the TryParse method on the custom data. This method will
                // return false if the source wasn't compatible with the parser.
                MyIni _ini = new MyIni();

                _ini.TryParse(block.CustomData);
                short display           = _ini.Get(Program.ScriptPrefixTag, "Display").ToInt16();
                bool  displayGridName   = _ini.Get(Program.ScriptPrefixTag, "DisplayGridName").ToBoolean(true);
                bool  displayInfoPanel  = _ini.Get(Program.ScriptPrefixTag, "DisplayInfoPanel").ToBoolean(true);
                bool  displaySun        = _ini.Get(Program.ScriptPrefixTag, "DisplaySun").ToBoolean(true);
                bool  displayOrbit      = _ini.Get(Program.ScriptPrefixTag, "DisplayOrbit").ToBoolean(true);
                bool  displayGPS        = _ini.Get(Program.ScriptPrefixTag, "DisplayGPS").ToBoolean(false);
                float stretchFactor     = _ini.Get(Program.ScriptPrefixTag, "StretchFactor").ToSingle(1);
                float stretchFactorV    = _ini.Get(Program.ScriptPrefixTag, "StretchFactorV").ToSingle(1);
                float stretchFactorH    = _ini.Get(Program.ScriptPrefixTag, "StretchFactorH").ToSingle(stretchFactor);
                float mapRadius         = _ini.Get(Program.ScriptPrefixTag, "MapRadius").ToSingle();
                float planetScaleFactor = _ini.Get(Program.ScriptPrefixTag, "PlanetScaleFactor").ToSingle(1);
                bool  followGrid        = _ini.Get(Program.ScriptPrefixTag, "FollowGrid").ToBoolean();
                bool  displayGrid       = _ini.Get(Program.ScriptPrefixTag, "DisplayGrid").ToBoolean();

                Vector3        mapCenterPosition = Vector3.Zero;
                MyWaypointInfo centerPosition;

                if (MyWaypointInfo.TryParse(_ini.Get(Program.ScriptPrefixTag, "CenterPosition").ToString(), out centerPosition))
                {
                    mapCenterPosition = centerPosition.Coords;
                }

                gridWorldPosition = Program.Me.GetPosition();
                if (followGrid)
                {
                    mapCenterPosition = gridWorldPosition;
                }

                IMyTextSurface lcd;

                if (block is IMyTextSurfaceProvider)
                {
                    lcd = (block as IMyTextSurfaceProvider).GetSurface(display);
                }
                else
                {
                    lcd = block as IMyTextPanel;
                }

                lcd.ContentType = ContentType.SCRIPT;
                lcd.Script      = "";

                RectangleF _viewport = new RectangleF((lcd.TextureSize - lcd.SurfaceSize) / 2f, lcd.SurfaceSize);

                using (MySpriteDrawFrame frame = lcd.DrawFrame())
                {
                    if (GetRefreshCount(block) % 2 == 0)
                    {
                        frame.Add(new MySprite());
                    }

                    Vector2 positionMult    = new Vector2(0.8f / stretchFactorH, 0.8f / stretchFactorV);
                    Vector2 infoPanelOffset = Vector2.Zero;
                    if (displayInfoPanel)
                    {
                        positionMult    = new Vector2(0.6f / stretchFactorH, 0.8f / stretchFactorV);
                        infoPanelOffset = new Vector2(180, 0);
                    }
                    Vector2 lcdSize        = lcd.SurfaceSize - infoPanelOffset;
                    Vector2 positionOffset = (lcdSize - lcdSize * positionMult) / 2f + infoPanelOffset + _viewport.Position;
                    Vector2 starPosition   = map.GetMapPosition(map.StarPosition, mapCenterPosition, mapRadius) * lcdSize * positionMult + positionOffset;

                    {  // display radar style
                       //for (var i = 5; i > 0; i--)
                       //{
                       //    var position = lcdSize * map.GetMapPosition(mapCenterPosition, mapCenterPosition, mapRadius) * positionMult + positionOffset;
                       //    var radarSize = new Vector2(lcd.SurfaceSize.Y * 0.18f * i);
                       //    frame.Add(new MySprite(SpriteType.TEXTURE, "CircleHollow", position, radarSize + 2, new Color(lcd.ScriptForegroundColor, 0.1f)));
                       //    frame.Add(new MySprite(SpriteType.TEXTURE, "CircleHollow", position, radarSize, lcd.ScriptBackgroundColor));
                       //}
                       //frame.Add(new MySprite(SpriteType.TEXTURE, "Grid", starPosition, new Vector2(20), lcd.ScriptForegroundColor));
                    }

                    foreach (CelestialBody celestialBody in map.Planets)
                    {
                        celestialBody.PlanetPosition = map.GetMapPosition(celestialBody.Position, mapCenterPosition, mapRadius) * lcdSize * positionMult + positionOffset;
                        celestialBody.OrbitSize      = new Vector2(Vector2.Distance(celestialBody.PlanetPosition, starPosition)) * 2;

                        // Celestial orbits.
                        if (displayOrbit)
                        {
                            // Border and fill.
                            frame.Add(new MySprite(SpriteType.TEXTURE, "Circle", starPosition, celestialBody.OrbitSize + 3, new Color(lcd.ScriptForegroundColor, 0.2f)));
                            frame.Add(new MySprite(SpriteType.TEXTURE, "Circle", starPosition, celestialBody.OrbitSize, lcd.ScriptBackgroundColor));
                        }
                    }

                    // Celestial bodies.
                    foreach (CelestialBody celestialBody in map.Planets)
                    {
                        celestialBody.PlanetSize     = new Vector2(lcd.SurfaceSize.Y * celestialBody.Radius * 0.000001f * planetScaleFactor);
                        celestialBody.LblTitlePos    = new Vector2(celestialBody.PlanetPosition.X, celestialBody.PlanetPosition.Y - 40 - celestialBody.PlanetSize.Y * 0.5f);
                        celestialBody.LblDistancePos = new Vector2(celestialBody.PlanetPosition.X, celestialBody.PlanetPosition.Y - 20 - celestialBody.PlanetSize.Y * 0.5f);

                        // Border and fill.
                        frame.Add(new MySprite(SpriteType.TEXTURE, "Circle", celestialBody.PlanetPosition, celestialBody.PlanetSize + 3, lcd.ScriptForegroundColor));
                        frame.Add(new MySprite(SpriteType.TEXTURE, "Circle", celestialBody.PlanetPosition, celestialBody.PlanetSize, lcd.ScriptBackgroundColor));

                        // Text.
                        frame.Add(new MySprite(SpriteType.TEXT, celestialBody.Name, celestialBody.LblTitlePos, null, lcd.ScriptForegroundColor, null, rotation: 0.7f));
                        frame.Add(new MySprite(SpriteType.TEXT, (Vector3.Distance(celestialBody.Position, gridWorldPosition) / 1000).ToString("F1") + " km", celestialBody.LblDistancePos, null, lcd.ScriptForegroundColor, null, rotation: 0.55f));
                    }

                    // Grid dot or arrow.
                    {
                        var position = lcdSize * map.GetMapPosition(gridWorldPosition, mapCenterPosition, mapRadius) * positionMult + positionOffset;
                        if (Program.shipController?.Main != null && !Program.Me.CubeGrid.IsStatic)
                        {
                            // float rotation = -(float)(Math.Acos(program.shipController.Main.WorldMatrix.Forward.Z) + (Math.PI / 2f));
                            float azimuth, elevation;
                            Vector3.GetAzimuthAndElevation(Program.shipController.Main.WorldMatrix.Forward, out azimuth, out elevation);
                            frame.Add(new MySprite(SpriteType.TEXTURE, "AH_BoreSight", position, new Vector2(lcdSize.Y * 0.05f + 3), Color.Red, null, rotation: -azimuth + (float)(Math.PI / 2f)));
                        }
                        else
                        {
                            frame.Add(new MySprite(SpriteType.TEXTURE, "Circle", position, new Vector2(lcdSize.Y * 0.01f), Color.Red));
                        }
                        if (displayGridName)
                        {
                            frame.Add(new MySprite(SpriteType.TEXT, Program.Me.CubeGrid.DisplayName, position - 10, null, Color.Red, null, TextAlignment.RIGHT, 0.55f));
                        }
                    }

                    if (displayGPS)
                    {
                        foreach (var gps in map.CelestialBodies.FindAll(body => body.Type == CelestialType.GPS))
                        {
                            var _gpsPos = map.GetMapPosition(gps.Position, mapCenterPosition, mapRadius) * lcdSize * positionMult + positionOffset;
                            frame.Add(new MySprite(SpriteType.TEXTURE, "Circle", _gpsPos, new Vector2(lcdSize.Y * 0.01f), lcd.ScriptForegroundColor));
                            frame.Add(new MySprite(SpriteType.TEXT, gps.Name, _gpsPos - 10, null, lcd.ScriptForegroundColor, null, TextAlignment.RIGHT, 0.55f));
                        }
                    }

                    if (displayInfoPanel)
                    {
                        int maxColumns = 2;
                        if (lcd.SurfaceSize.X <= 512)
                        {
                            maxColumns = 1;
                        }
                        int infoPanelPerColumn = 6;
                        if (lcd.SurfaceSize.Y < 512)
                        {
                            infoPanelPerColumn = 3;
                        }
                        if (lcd.SurfaceSize.Y > 512)
                        {
                            infoPanelPerColumn = 12;
                        }

                        // Information panel background.
                        int xOffsetIncrement = 190;
                        var planetsAndMoons  = map.CelestialBodies.FindAll(obj => obj.Type == CelestialType.Planet || obj.Type == CelestialType.Moon);
                        for (int i = 0; i < Math.Min(Math.Ceiling(planetsAndMoons.Count * 1f / infoPanelPerColumn), maxColumns); i++)
                        {
                            frame.Add(new MySprite(SpriteType.TEXTURE, "SquareSimple", new Vector2(95 + i * xOffsetIncrement, lcd.SurfaceSize.Y / 2) + _viewport.Position, new Vector2(183, lcd.SurfaceSize.Y - 5), new Color(0, 0, 0, 50)));
                        }

                        // Information panel content.
                        for (int i = 0; i < planetsAndMoons.Count; i++)
                        {
                            if (i >= infoPanelPerColumn * maxColumns)
                            {
                                break;
                            }
                            CelestialBody cb = planetsAndMoons[i];

                            int yOffset = 83 * (i % infoPanelPerColumn);
                            int xOffset = i / infoPanelPerColumn * xOffsetIncrement;

                            // Title: Background and text.
                            frame.Add(new MySprite(SpriteType.TEXTURE, "SquareSimple", new Vector2(infoPosition.X + (infoSize.X / 2) + xOffset, (infoSize.Y / 2) + infoPosition.Y + yOffset) + _viewport.Position, infoSize, new Color(0, 0, 0, 150)));
                            frame.Add(new MySprite(SpriteType.TEXT, cb.Name, new Vector2(3 + infoPosition.X + xOffset, infoPosition.Y + yOffset) + _viewport.Position, null, lcd.ScriptForegroundColor, null, TextAlignment.LEFT, 0.6f));
                            frame.Add(new MySprite(SpriteType.TEXT, (Vector3.Distance(cb.Position, gridWorldPosition) / 1000).ToString("F1") + " km", new Vector2(172 + infoPosition.X + xOffset, 2 + infoPosition.Y + yOffset) + _viewport.Position, null, lcd.ScriptForegroundColor, null, TextAlignment.RIGHT, 0.5f));

                            // Body: Content.
                            string txt = "Radius: " + (cb.Radius / 1000).ToString("F1") + " km\n" +
                                         "Gravity: " + cb.Gravity.ToString("F1") + " G\n" +
                                         "Atmosphere: " + cb.HasAtmosphere + "\n" +
                                         "Oxygen: " + cb.Oxygen + "\n" +
                                         "Resources: " + cb.Resources + "\n";
                            frame.Add(new MySprite(SpriteType.TEXT, txt, new Vector2(3 + infoPosition.X + xOffset, infoPosition.Y + infoSize.Y + yOffset) + _viewport.Position, null, lcd.ScriptForegroundColor, null, TextAlignment.LEFT, 0.4f));
                        }
                    }

                    if (displaySun)
                    {
                        frame.Add(new MySprite(SpriteType.TEXTURE, "Circle", starPosition, new Vector2(lcd.SurfaceSize.Y * map.StarRadius * 0.000001f), Color.Yellow));
                    }

                    if (displayGrid)
                    {
                        frame.Add(new MySprite(SpriteType.TEXTURE, "Grid"));
                    }
                }
            }