Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public string
- panelKey = "[pgps]", //This controls what panels get the points written to
- prefix = "OM"; //This is the prefix for the generated points
- //These control the absolute north, south, and so on
- public List<Vector3D> points = new List<Vector3D>
- {
- new Vector3D(0, 1, 0), //Up (north)
- new Vector3D(1, 0, 0), //Right
- new Vector3D(0, 0, 1) //Forward
- };
- public List<IMyTextPanel> panels = new List<IMyTextPanel>();
- public Vector3D planetPosition = new Vector3D(0, 0, 0);
- public double radius = 50000;
- Program()
- {
- Runtime.UpdateFrequency = UpdateFrequency.Update100;
- points.Insert(1, points[0] * -1.0);
- points.Insert(3, points[2] * -1.0);
- points.Add(points[4] * -1.0);
- Scan();
- }
- void Main(string argument)
- {
- Echo($"-Panel Tag: {panelKey}");
- Echo("-Enter the command 'auto' to generate points for the current planet");
- Echo("-Enter the planet's coordinates using the copy to clipboard function to set the planet's position manually");
- Echo("-Enter a number to set the point's distance from the center of the planet manually");
- Echo("-Enter the command 'scan' to look for panels");
- try { Commands(argument); } catch { Echo($"Error caught running command: {argument}"); }
- Echo($"Panels: {panels.Count}");
- Echo($"Planet Position: {planetPosition}");
- Echo($"Point Radius: {radius:N0}");
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < points.Count; i++)
- builder.AppendLine(GPSConvert((points[i] * radius) + planetPosition, $"{prefix}{i + 1}"));
- foreach (IMyTextPanel panel in panels)
- panel.WriteText(builder);
- }
- public void Commands(string argument)
- {
- string arg = argument.ToLower();
- Vector3D tempPosition;
- double tempDouble;
- if (TryGetGPS(arg, out tempPosition))
- planetPosition = tempPosition;
- else
- if (double.TryParse(arg, out tempDouble))
- radius = tempDouble;
- else
- switch (arg)
- {
- case "auto":
- List<IMyShipController> controllers = new List<IMyShipController>();
- GridTerminalSystem.GetBlocksOfType<IMyShipController>(controllers);
- if (controllers.Count > 0 && controllers[0].TryGetPlanetPosition(out tempPosition))
- {
- planetPosition = tempPosition;
- controllers[0].TryGetPlanetElevation(MyPlanetElevation.Sealevel, out tempDouble);
- tempDouble = Vector3D.Distance(controllers[0].GetPosition(), planetPosition) - tempDouble;
- radius = tempDouble * 1.7182;
- }
- break;
- case "scan":
- Scan();
- break;
- }
- }
- public void Scan()
- {
- panels.Clear();
- GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(panels, b => b.CustomName.ToLower().Contains(panelKey.ToLower()));
- foreach (IMyTextPanel panel in panels)
- panel.ContentType = ContentType.TEXT_AND_IMAGE;
- }
- public string GPSConvert(Vector3D vector, string name)
- {
- return $"GPS:{name}:{Math.Floor(vector.X)}:{Math.Floor(vector.Y)}:{Math.Floor(vector.Z)}:";
- }
- public bool TryGetGPS(string gpsString, out Vector3D vector)
- {
- vector = new Vector3D(0, 0, 0);
- try
- {
- string[] gpsArgs = gpsString.Split(':');
- if (gpsArgs.Length >= 5)
- {
- double x, y, z;
- if (double.TryParse(gpsArgs[2], out x) &&
- double.TryParse(gpsArgs[3], out y) &&
- double.TryParse(gpsArgs[4], out z))
- {
- vector = new Vector3D(x, y, z);
- return true;
- }
- }
- }
- catch { }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement