diff --git a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidSettings.cs b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidSettings.cs index 19d7efe1..5f4ab973 100644 --- a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidSettings.cs +++ b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidSettings.cs @@ -4,6 +4,7 @@ using Invalid.DynamicRoids; using Sandbox.ModAPI; using VRageMath; +using System.Collections.Generic; namespace DynamicAsteroids { @@ -60,16 +61,7 @@ public static class AsteroidSettings public static int[] PlatinumDropRange = { 500, 2500 }; public static int[] UraniniteDropRange = { 500, 2500 }; - public static SpawnableArea[] ValidSpawnLocations = { - new SpawnableArea - { - CenterPosition = new Vector3D(148001024.50, 1024.50, 1024.50), - Normal = new Vector3D(1, 10, 0.5).Normalized(), - Radius = 60268000 * 2.5, - InnerRadius = 60268000 * 1.2, - HeightFromCenter = 1000, - } - }; + public static List ValidSpawnLocations = new List(); public static bool CanSpawnAsteroidAtPoint(Vector3D point, out Vector3D velocity) { @@ -199,6 +191,14 @@ public static void SaveSettings() WriteIntArray(writer, "GoldDropRange", GoldDropRange); WriteIntArray(writer, "PlatinumDropRange", PlatinumDropRange); WriteIntArray(writer, "UraniniteDropRange", UraniniteDropRange); + + writer.WriteLine("[SpawnableAreas]"); + foreach (var area in ValidSpawnLocations) + { + writer.WriteLine($"Name={area.Name}"); + writer.WriteLine($"CenterPosition={area.CenterPosition.X},{area.CenterPosition.Y},{area.CenterPosition.Z}"); + writer.WriteLine($"Radius={area.Radius}"); + } } } catch (Exception ex) @@ -216,6 +216,7 @@ public static void LoadSettings() using (var reader = MyAPIGateway.Utilities.ReadFileInWorldStorage("AsteroidSettings.cfg", typeof(AsteroidSettings))) { string line; + SpawnableArea currentArea = null; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("[") || string.IsNullOrWhiteSpace(line)) @@ -380,10 +381,33 @@ public static void LoadSettings() case "UraniniteDropRange": UraniniteDropRange = ReadIntArray(value); break; + case "Name": + if (currentArea != null) ValidSpawnLocations.Add(currentArea); + currentArea = new SpawnableArea { Name = value }; + break; + case "CenterPosition": + var coords = value.Split(','); + currentArea.CenterPosition = new Vector3D(double.Parse(coords[0]), double.Parse(coords[1]), double.Parse(coords[2])); + break; + case "Radius": + currentArea.Radius = double.Parse(value); + break; } } + if (currentArea != null) ValidSpawnLocations.Add(currentArea); } } + else + { + // Create default configuration if it doesn't exist + ValidSpawnLocations.Add(new SpawnableArea + { + Name = "DefaultArea", + CenterPosition = new Vector3D(0.0, 0.0, 0.0), + Radius = 10000 + }); + SaveSettings(); + } } catch (Exception ex) { @@ -410,26 +434,19 @@ private static int[] ReadIntArray(string value) public class SpawnableArea { - public Vector3D CenterPosition; - public Vector3D Normal; - public double Radius; - public double InnerRadius; - public double HeightFromCenter; + public string Name { get; set; } + public Vector3D CenterPosition { get; set; } + public double Radius { get; set; } public bool ContainsPoint(Vector3D point) { - point -= CenterPosition; - double pointDistanceSq = point.LengthSquared(); - if (pointDistanceSq > Radius * Radius || pointDistanceSq < InnerRadius * InnerRadius) - return false; - if (Math.Abs(Vector3D.Dot(point, Normal)) > HeightFromCenter) - return false; - return true; + double distanceSquared = (point - CenterPosition).LengthSquared(); + return distanceSquared <= Radius * Radius; } public Vector3D VelocityAtPoint(Vector3D point) { - return -(point - CenterPosition).Cross(Normal).Normalized() * AsteroidSettings.AsteroidVelocityBase; + return (point - CenterPosition).Normalized() * AsteroidSettings.AsteroidVelocityBase; } } }