diff --git a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidEntity.cs b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidEntity.cs index 03536667..1859579e 100644 --- a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidEntity.cs +++ b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidEntity.cs @@ -24,14 +24,19 @@ public enum AsteroidType { Ice, Stone, - Ore // We'll define specific ore types as needed + Iron, + Nickel, + Cobalt, + Magnesium, + Silicon, + Silver, + Gold, + Platinum, + Uraninite } public class AsteroidEntity : MyEntity, IMyDestroyableObject { - private const double VelocityVariability = 10; - private const double AngularVelocityVariability = 0.1; - private static readonly string[] IceAsteroidModels = { @"Models\IceAsteroid_1.mwm", @"Models\IceAsteroid_2.mwm", @@ -58,18 +63,15 @@ public class AsteroidEntity : MyEntity, IMyDestroyableObject @"Models\StoneAsteroid_16.mwm" }; - // Placeholder for Ore Asteroids - private static readonly string[] OreAsteroidModels = { - // @"Models\OreAsteroid_Iron.mwm", - // @"Models\OreAsteroid_Nickel.mwm", - // @"Models\OreAsteroid_Cobalt.mwm", - // @"Models\OreAsteroid_Magnesium.mwm", - // @"Models\OreAsteroid_Silicon.mwm", - // @"Models\OreAsteroid_Silver.mwm", - // @"Models\OreAsteroid_Gold.mwm", - // @"Models\OreAsteroid_Platinum.mwm", - // @"Models\OreAsteroid_Uraninite.mwm" - }; + private static readonly string[] IronAsteroidModels = { @"Models\OreAsteroid_Iron.mwm" }; + private static readonly string[] NickelAsteroidModels = { @"Models\OreAsteroid_Nickel.mwm" }; + private static readonly string[] CobaltAsteroidModels = { @"Models\OreAsteroid_Cobalt.mwm" }; + private static readonly string[] MagnesiumAsteroidModels = { @"Models\OreAsteroid_Magnesium.mwm" }; + private static readonly string[] SiliconAsteroidModels = { @"Models\OreAsteroid_Silicon.mwm" }; + private static readonly string[] SilverAsteroidModels = { @"Models\OreAsteroid_Silver.mwm" }; + private static readonly string[] GoldAsteroidModels = { @"Models\OreAsteroid_Gold.mwm" }; + private static readonly string[] PlatinumAsteroidModels = { @"Models\OreAsteroid_Platinum.mwm" }; + private static readonly string[] UraniniteAsteroidModels = { @"Models\OreAsteroid_Uraninite.mwm" }; public static AsteroidEntity CreateAsteroid(Vector3D position, float size, Vector3D initialVelocity, AsteroidType type) { @@ -95,7 +97,7 @@ public void SplitAsteroid() if (newSize <= 1) { - MyPhysicalItemDefinition item = MyDefinitionManager.Static.GetPhysicalItemDefinition(new MyDefinitionId(typeof(MyObjectBuilder_Ore), "Stone")); + MyPhysicalItemDefinition item = MyDefinitionManager.Static.GetPhysicalItemDefinition(new MyDefinitionId(typeof(MyObjectBuilder_Ore), Type.ToString())); var newObject = MyObjectBuilderSerializer.CreateNewObject(item.Id.TypeId, item.Id.SubtypeId.ToString()) as MyObjectBuilder_PhysicalObject; for (int i = 0; i < splits; i++) { @@ -145,9 +147,32 @@ private void Init(Vector3D position, float size, Vector3D initialVelocity, Aster case AsteroidType.Stone: ModelString = Path.Combine(modPath, StoneAsteroidModels[MainSession.I.Rand.Next(StoneAsteroidModels.Length)]); break; - case AsteroidType.Ore: - // Placeholder logic for ore asteroids, use the correct models when ready - // ModelString = Path.Combine(modPath, OreAsteroidModels[MainSession.I.Rand.Next(OreAsteroidModels.Length)]); + case AsteroidType.Iron: + ModelString = Path.Combine(modPath, IronAsteroidModels[MainSession.I.Rand.Next(IronAsteroidModels.Length)]); + break; + case AsteroidType.Nickel: + ModelString = Path.Combine(modPath, NickelAsteroidModels[MainSession.I.Rand.Next(NickelAsteroidModels.Length)]); + break; + case AsteroidType.Cobalt: + ModelString = Path.Combine(modPath, CobaltAsteroidModels[MainSession.I.Rand.Next(CobaltAsteroidModels.Length)]); + break; + case AsteroidType.Magnesium: + ModelString = Path.Combine(modPath, MagnesiumAsteroidModels[MainSession.I.Rand.Next(MagnesiumAsteroidModels.Length)]); + break; + case AsteroidType.Silicon: + ModelString = Path.Combine(modPath, SiliconAsteroidModels[MainSession.I.Rand.Next(SiliconAsteroidModels.Length)]); + break; + case AsteroidType.Silver: + ModelString = Path.Combine(modPath, SilverAsteroidModels[MainSession.I.Rand.Next(SilverAsteroidModels.Length)]); + break; + case AsteroidType.Gold: + ModelString = Path.Combine(modPath, GoldAsteroidModels[MainSession.I.Rand.Next(GoldAsteroidModels.Length)]); + break; + case AsteroidType.Platinum: + ModelString = Path.Combine(modPath, PlatinumAsteroidModels[MainSession.I.Rand.Next(PlatinumAsteroidModels.Length)]); + break; + case AsteroidType.Uraninite: + ModelString = Path.Combine(modPath, UraniniteAsteroidModels[MainSession.I.Rand.Next(UraniniteAsteroidModels.Length)]); break; } Size = size; @@ -170,8 +195,8 @@ private void Init(Vector3D position, float size, Vector3D initialVelocity, Aster MyEntities.Add(this); CreatePhysics(); - Physics.LinearVelocity = initialVelocity + RandVector() * VelocityVariability; - Physics.AngularVelocity = RandVector() * AngularVelocityVariability; // Set initial angular velocity + Physics.LinearVelocity = initialVelocity + RandVector() * AsteroidSettings.VelocityVariability; + Physics.AngularVelocity = RandVector() * AsteroidSettings.AngularVelocityVariability; // Set initial angular velocity Log.Info($"Asteroid model {ModelString} loaded successfully with initial angular velocity: {Physics.AngularVelocity}"); } @@ -210,3 +235,4 @@ private Vector3D RandVector() } } } + \ No newline at end of file diff --git a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs index 973bd765..f2fb17d5 100644 --- a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs +++ b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs @@ -60,7 +60,7 @@ public void UpdateTick() } // Determine asteroid type to spawn - AsteroidType type = DetermineAsteroidType(); + AsteroidType type = AsteroidSettings.GetRandomAsteroidType(MainSession.I.Rand); _asteroids.Add(AsteroidEntity.CreateAsteroid(newPosition, RandAsteroidSize, newVelocity, type)); asteroidsSpawned++; @@ -103,14 +103,5 @@ private Vector3D RandVector() } private float RandAsteroidSize => (float)(MainSession.I.Rand.NextDouble() * MainSession.I.Rand.NextDouble() * MainSession.I.Rand.NextDouble() * 500) + 1.5f; - - // This function determines the type of asteroid to spawn - private AsteroidType DetermineAsteroidType() - { - // Here you can add logic to determine the type of asteroid. - // For example, randomly selecting a type or using some other logic. - int randValue = MainSession.I.Rand.Next(0, 2); // Adjust as needed for more types - return (AsteroidType)randValue; - } } } diff --git a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidSettings.cs b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidSettings.cs index 9e3c3506..973f6440 100644 --- a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidSettings.cs +++ b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidSettings.cs @@ -1,4 +1,5 @@ -using System; +using DynamicAsteroids.AsteroidEntities; +using System; using VRageMath; namespace DynamicAsteroids @@ -8,6 +9,21 @@ internal static class AsteroidSettings public static int MaxAsteroidCount = 1000; public static int AsteroidSpawnRadius = 10000; public static int AsteroidVelocityBase = 0; + public static double VelocityVariability = 10; // New setting for velocity variability + public static double AngularVelocityVariability = 0.1; // New setting for angular velocity variability + + // Weights for asteroid type frequencies + public static double IceWeight = 0.45; // 45% + public static double StoneWeight = 0.45; // 45% + public static double IronWeight = 0.01; + public static double NickelWeight = 0.01; + public static double CobaltWeight = 0.01; + public static double MagnesiumWeight = 0.01; + public static double SiliconWeight = 0.01; + public static double SilverWeight = 0.01; + public static double GoldWeight = 0.01; + public static double PlatinumWeight = 0.01; + public static double UraniniteWeight = 0.01; public static SpawnableArea[] ValidSpawnLocations = { @@ -43,6 +59,35 @@ public static bool PlayerCanSeeRings(Vector3D point) return true; return false; } + + public static AsteroidType GetRandomAsteroidType(Random rand) + { + double totalWeight = IceWeight + StoneWeight + IronWeight + NickelWeight + CobaltWeight + MagnesiumWeight + + SiliconWeight + SilverWeight + GoldWeight + PlatinumWeight + UraniniteWeight; + double randomValue = rand.NextDouble() * totalWeight; + + if (randomValue < IceWeight) return AsteroidType.Ice; + randomValue -= IceWeight; + if (randomValue < StoneWeight) return AsteroidType.Stone; + randomValue -= StoneWeight; + if (randomValue < IronWeight) return AsteroidType.Iron; + randomValue -= IronWeight; + if (randomValue < NickelWeight) return AsteroidType.Nickel; + randomValue -= NickelWeight; + if (randomValue < CobaltWeight) return AsteroidType.Cobalt; + randomValue -= CobaltWeight; + if (randomValue < MagnesiumWeight) return AsteroidType.Magnesium; + randomValue -= MagnesiumWeight; + if (randomValue < SiliconWeight) return AsteroidType.Silicon; + randomValue -= SiliconWeight; + if (randomValue < SilverWeight) return AsteroidType.Silver; + randomValue -= SilverWeight; + if (randomValue < GoldWeight) return AsteroidType.Gold; + randomValue -= GoldWeight; + if (randomValue < PlatinumWeight) return AsteroidType.Platinum; + randomValue -= PlatinumWeight; + return AsteroidType.Uraninite; + } } internal class SpawnableArea diff --git a/Dynamic Asteroids/Models/IceAsteroid_1.mwm b/Dynamic Asteroids/Models/IceAsteroid_1.mwm index aa4c103f..f12f6302 100644 Binary files a/Dynamic Asteroids/Models/IceAsteroid_1.mwm and b/Dynamic Asteroids/Models/IceAsteroid_1.mwm differ diff --git a/Dynamic Asteroids/Models/IceAsteroid_2.mwm b/Dynamic Asteroids/Models/IceAsteroid_2.mwm index 812b8bc9..4e99912c 100644 Binary files a/Dynamic Asteroids/Models/IceAsteroid_2.mwm and b/Dynamic Asteroids/Models/IceAsteroid_2.mwm differ diff --git a/Dynamic Asteroids/Models/IceAsteroid_3.mwm b/Dynamic Asteroids/Models/IceAsteroid_3.mwm index 3f0285e7..e5dcbbb5 100644 Binary files a/Dynamic Asteroids/Models/IceAsteroid_3.mwm and b/Dynamic Asteroids/Models/IceAsteroid_3.mwm differ diff --git a/Dynamic Asteroids/Models/IceAsteroid_4.mwm b/Dynamic Asteroids/Models/IceAsteroid_4.mwm index 7de8e456..0ce8aeeb 100644 Binary files a/Dynamic Asteroids/Models/IceAsteroid_4.mwm and b/Dynamic Asteroids/Models/IceAsteroid_4.mwm differ diff --git a/Dynamic Asteroids/Models/OreAsteroid_Cobalt.mwm b/Dynamic Asteroids/Models/OreAsteroid_Cobalt.mwm new file mode 100644 index 00000000..6d8d7d1a Binary files /dev/null and b/Dynamic Asteroids/Models/OreAsteroid_Cobalt.mwm differ diff --git a/Dynamic Asteroids/Models/OreAsteroid_Gold.mwm b/Dynamic Asteroids/Models/OreAsteroid_Gold.mwm new file mode 100644 index 00000000..e90baeb3 Binary files /dev/null and b/Dynamic Asteroids/Models/OreAsteroid_Gold.mwm differ diff --git a/Dynamic Asteroids/Models/OreAsteroid_Iron.mwm b/Dynamic Asteroids/Models/OreAsteroid_Iron.mwm new file mode 100644 index 00000000..80f4f0ce Binary files /dev/null and b/Dynamic Asteroids/Models/OreAsteroid_Iron.mwm differ diff --git a/Dynamic Asteroids/Models/OreAsteroid_Magnesium.mwm b/Dynamic Asteroids/Models/OreAsteroid_Magnesium.mwm new file mode 100644 index 00000000..bf9476ad Binary files /dev/null and b/Dynamic Asteroids/Models/OreAsteroid_Magnesium.mwm differ diff --git a/Dynamic Asteroids/Models/OreAsteroid_Nickel.mwm b/Dynamic Asteroids/Models/OreAsteroid_Nickel.mwm new file mode 100644 index 00000000..b5d678e4 Binary files /dev/null and b/Dynamic Asteroids/Models/OreAsteroid_Nickel.mwm differ diff --git a/Dynamic Asteroids/Models/OreAsteroid_Platinum.mwm b/Dynamic Asteroids/Models/OreAsteroid_Platinum.mwm new file mode 100644 index 00000000..7c010cd0 Binary files /dev/null and b/Dynamic Asteroids/Models/OreAsteroid_Platinum.mwm differ diff --git a/Dynamic Asteroids/Models/OreAsteroid_Silicon.mwm b/Dynamic Asteroids/Models/OreAsteroid_Silicon.mwm new file mode 100644 index 00000000..8a49b452 Binary files /dev/null and b/Dynamic Asteroids/Models/OreAsteroid_Silicon.mwm differ diff --git a/Dynamic Asteroids/Models/OreAsteroid_Silver.mwm b/Dynamic Asteroids/Models/OreAsteroid_Silver.mwm new file mode 100644 index 00000000..13000ef1 Binary files /dev/null and b/Dynamic Asteroids/Models/OreAsteroid_Silver.mwm differ diff --git a/Dynamic Asteroids/Models/OreAsteroid_Uraninite.mwm b/Dynamic Asteroids/Models/OreAsteroid_Uraninite.mwm new file mode 100644 index 00000000..e3ec9abb Binary files /dev/null and b/Dynamic Asteroids/Models/OreAsteroid_Uraninite.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_1.mwm b/Dynamic Asteroids/Models/StoneAsteroid_1.mwm index 21be1e77..9d2d52a0 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_1.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_1.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_10.mwm b/Dynamic Asteroids/Models/StoneAsteroid_10.mwm index 9b7d83ab..3fd769b6 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_10.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_10.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_11.mwm b/Dynamic Asteroids/Models/StoneAsteroid_11.mwm index ba272cfe..58474cd4 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_11.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_11.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_12.mwm b/Dynamic Asteroids/Models/StoneAsteroid_12.mwm index a2c3dc22..2b30f071 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_12.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_12.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_13.mwm b/Dynamic Asteroids/Models/StoneAsteroid_13.mwm index 2dd57228..4dfc6877 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_13.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_13.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_14.mwm b/Dynamic Asteroids/Models/StoneAsteroid_14.mwm index 9b71d921..775485f2 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_14.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_14.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_15.mwm b/Dynamic Asteroids/Models/StoneAsteroid_15.mwm index bca11ab4..57cfc332 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_15.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_15.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_16.mwm b/Dynamic Asteroids/Models/StoneAsteroid_16.mwm index c8505b3e..d50f5d75 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_16.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_16.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_2.mwm b/Dynamic Asteroids/Models/StoneAsteroid_2.mwm index 855e206f..706e56bf 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_2.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_2.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_3.mwm b/Dynamic Asteroids/Models/StoneAsteroid_3.mwm index c8c5d86a..460ff79c 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_3.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_3.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_4.mwm b/Dynamic Asteroids/Models/StoneAsteroid_4.mwm index 99dce4e2..61ce24bd 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_4.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_4.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_5.mwm b/Dynamic Asteroids/Models/StoneAsteroid_5.mwm index 7453d41a..1cc3f7d0 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_5.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_5.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_6.mwm b/Dynamic Asteroids/Models/StoneAsteroid_6.mwm index bc70aed4..4a4b0c70 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_6.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_6.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_7.mwm b/Dynamic Asteroids/Models/StoneAsteroid_7.mwm index 9cc97bcb..529f7011 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_7.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_7.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_8.mwm b/Dynamic Asteroids/Models/StoneAsteroid_8.mwm index 87790fa9..dc30938b 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_8.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_8.mwm differ diff --git a/Dynamic Asteroids/Models/StoneAsteroid_9.mwm b/Dynamic Asteroids/Models/StoneAsteroid_9.mwm index ba37a993..a3424299 100644 Binary files a/Dynamic Asteroids/Models/StoneAsteroid_9.mwm and b/Dynamic Asteroids/Models/StoneAsteroid_9.mwm differ