Exemple #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;
                }
            }
Exemple #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();
 }
Exemple #3
0
            public override void DoOnDirectMasterMsg(MyIGCMessage msg)
            {
                p.Echo("Getting msg from master");
                if (msg.Tag == ShipFormationMaster.TAG_FORMATION)
                {
                    GPS center = new GPS(msg.Data.ToString());
                    p.Echo("Getting formation msg from master : ");

                    IMyRemoteControl r = GetRemote();

                    r.ClearWaypoints();

                    int    nbWP     = 18;
                    double angleTmp = 0;
                    double angleDeg = 360 / nbWP;
                    for (int i = 0; i < nbWP; ++i)
                    {
                        GPS            wp   = center.ComputeCoordinate(ShipFormationMaster.DISTANCE, DegreeToRadian(angleTmp));
                        MyWaypointInfo dest = new MyWaypointInfo("WP_" + i, wp.x, wp.y, wp.z);
                        r.AddWaypoint(dest);
                        angleTmp += angleDeg;
                    }

                    GetLight().SetValue("Color", new Color(0, 255, 0));

                    r.FlightMode = FlightMode.Circle;
                    r.SetCollisionAvoidance(false);
                    r.SetAutoPilotEnabled(true);
                }
            }
Exemple #4
0
            private bool RemoveReachedObjective()
            {
                this.Objective = null;
                List <MyWaypointInfo> route = new List <MyWaypointInfo>();

                remotePilot.GetWaypointInfo(route);
                if (route.Count > 0)
                {
                    MyWaypointInfo nextWaypoint = route.First();
                    route.RemoveAt(0);
                    remotePilot.ClearWaypoints();
                    switch (remotePilot.FlightMode)
                    {
                    case FlightMode.OneWay:
                        break;

                    case FlightMode.Circle:
                        route.Add(nextWaypoint);
                        break;

                    case FlightMode.Patrol:     // behave as one way
                        uIManager.printOnScreens("service", "[AP] Patrol not implemented yet!");
                        break;
                    }
                    foreach (MyWaypointInfo wp in route)
                    {
                        remotePilot.AddWaypoint(wp);
                    }
                    //Need to reset the autopilot status to true after clearing the queue
                    remotePilot.SetAutoPilotEnabled(true);
                }
                return(route.Count > 0);
            }
Exemple #5
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}");
     }
 }
Exemple #6
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);
            }
        }
Exemple #7
0
        List <MyWaypointInfo> TranslateToWorldCoords(List <MyWaypointInfo> list, IMyRemoteControl reference)
        {
            List <MyWaypointInfo> newList = new List <MyWaypointInfo>();
            int i = 1;

            foreach (MyWaypointInfo point in list)
            {
                Vector3D       worldPosition = Vector3D.Transform(point.Coords, reference.WorldMatrix);
                MyWaypointInfo newPoint      = new MyWaypointInfo(i + "", worldPosition);
                newList.Add(newPoint);
                i++;
            }
            return(newList);
        }
Exemple #8
0
 private Vector3D?getCurrentObjective()
 {
     if (this.Objective == null)
     {
         List <MyWaypointInfo> route = new List <MyWaypointInfo>();
         remotePilot.GetWaypointInfo(route);
         if (route.Count > 0)
         {
             MyWaypointInfo nextWaypoint = route.First();
             return(nextWaypoint.Coords);
         }
     }
     return(this.Objective);
 }
Exemple #9
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");
            }
        }
Exemple #11
0
            /// <summary>Adds a new waypoint or updates the position of an existing waypoint</summary>
            /// <param name="wp">Waypoint to add / update</param>
            public void Add(MyWaypointInfo wp)
            {
                APWaypoint apwp;

                if (this.waypoints.TryGetValue(wp.Name, out apwp))
                {
                    apwp.WP = wp;
                    this.logger?.Invoke($"Updated waypoint {wp.Name}");
                    this.save();
                }
                else
                {
                    this.waypoints[wp.Name] = new APWaypoint(wp);
                    this.logger?.Invoke($"Added waypoint {wp.Name}");
                    this.save();
                }
            }
Exemple #12
0
        private void LaunchMissiles(MyWaypointInfo tgt)
        {
            int launchCount = 0;

            foreach (var kvp in portToMissileStatus)
            {
                if (kvp.Value.State == LaunchState.PreLaunch)
                {
                    IGC.SendUnicast(kvp.Key, new LaunchCommand()
                    {
                        Destination = tgt.Coords
                    });
                    ++launchCount;
                }
            }
            LogLine($"Launched {launchCount} missiles to {tgt.Name} at {tgt.Coords}");
        }
Exemple #13
0
        public void Main(string argument, UpdateType updateSource)
        {
            IMyTextPanel lcdWriteScreen = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(lcdName);


            IMyRemoteControl remoteControl = (IMyRemoteControl)GridTerminalSystem.GetBlockWithName(remoteControllerName);

            List <MyWaypointInfo> mywaypoint = new List <MyWaypointInfo>();

            remoteControl.GetWaypointInfo(mywaypoint);

            foreach (MyWaypointInfo item in mywaypoint)
            {
                Echo(item.Coords.ToString());
            }
            wayPoint = mywaypoint[0];

            Echo(wayPoint.ToString());

            // If setupcomplete is false, run Setup method.
            if (!setupcomplete)
            {
                Echo("Running setup.");
                Setup();
            }
            else
            {
                // Create our message. We first make it a string, and then we "box" it as an object type.
                string sendCords = lcdWriteScreen.GetText();

                // Through the IGC variable we issue the broadcast method. IGC is "pre-made",
                // so we don't have to declare it ourselves, just go ahead and use it.
                if (sendCords.ToLower() == "send" && wayPoint.Coords != null)
                {
                    IGC.SendBroadcastMessage(broadcastChannel, wayPoint.ToString(), TransmissionDistance.TransmissionDistanceMax);
                }
                else
                {
                    Echo("Broadcasting failed.");
                }
                // To create a listener, we use IGC to access the relevant method.
                // We pass the same tag argument we used for our message.
                IGC.RegisterBroadcastListener(broadcastChannel);
            }
        }
Exemple #14
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);
                }
            }
Exemple #16
0
        List <MyWaypointInfo> TranslateToRelativeCoords(List <MyWaypointInfo> list, IMyRemoteControl reference)
        {
            List <MyWaypointInfo> newList = new List <MyWaypointInfo>();
            Boolean one = list == null;
            Boolean two = reference == null;

            Echo(one + " ... " + two);

            int i = 1;

            foreach (MyWaypointInfo point in list)
            {
                Vector3D referenceWorldPosition = reference.WorldMatrix.Translation;

                Vector3D worldDirection = point.Coords - referenceWorldPosition;

                Vector3D       bodyPosition = Vector3D.TransformNormal(worldDirection, MatrixD.Transpose(reference.WorldMatrix));
                MyWaypointInfo newPoint     = new MyWaypointInfo("" + i, bodyPosition);
                newList.Add(newPoint);
                i++;
            }
            return(newList);
        }
Exemple #17
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");
            }
        }
Exemple #18
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"));
                    }
                }
            }
Exemple #19
0
 private void HandleSpecific(ChangeTarget command, long source)
 {
     finalTarget = new MyWaypointInfo("Final-Destination", command.NewTarget);
     LogLine($"New final target at {finalTarget.Coords}");
 }
Exemple #20
0
 private void HandleSpecific(LaunchCommand command, long source)
 {
     finalTarget = new MyWaypointInfo("Final-Destination", command.Destination);
     Launch();
 }
Exemple #21
0
 /// <summary>Create a new waypoint, not connected to any other waypoint</summary>
 /// <param name="wp">Coordinates and name of the waypoint</param>
 /// <param name="terrain">Information about how rough the terrain is</param>
 /// <param name="type">How close to the waypoint the autopilot should try to be</param>
 public APWaypoint(MyWaypointInfo wp, Terrain terrain = Terrain.Normal, WPType type = WPType.Path)
 {
     this.WP      = wp;
     this.Terrain = terrain;
     this.Type    = type;
 }
 public void AddWaypoint(MyWaypointInfo coords)
 {
     this.Waypoints.Add(coords);
 }
Exemple #23
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++;
            }
        }