private MyPlanetMoonItem[] GenerateMoons(float planetSize, float surfaceGravity, string planetName, long distance) { if (MyRandom.Instance.NextFloat() > m_settings.PlanetSettings.MoonProbability) { return(new MyPlanetMoonItem[0]); } int numMoons = MyRandom.Instance.Next(0, GetMaxMoonCount(surfaceGravity)); MyPlanetMoonItem[] moons = new MyPlanetMoonItem[numMoons]; for (int i = 0; i < numMoons; i++) { var dist = planetSize * (i + 1) + planetSize / 2 * MyRandom.Instance.GetRandomFloat(0.5f, 1.5f); var def = GetPlanetMoonDefinition(planetSize * 0.8f); if (dist + distance > m_settings.WorldSize) { return(moons); } MyPlanetMoonItem item = new MyPlanetMoonItem(); item.Type = SystemObjectType.MOON; item.DefName = def.Id.SubtypeName.ToString(); item.Distance = dist; item.Size = SizeByGravity(def.SurfaceGravity); item.DisplayName = planetName + " " + (char)('A' + i); moons[i] = item; } return(moons); }
/// <summary> /// Generates moon datas for a planet of the given size, gravity, name and distance from the world center. /// The moon has to have a size smaller than the planet /// </summary> /// <param name="planetSize">Size of the parent planet</param> /// <param name="surfaceGravity">Surface gravity of the parent planet</param> /// <param name="planetName">Name of the planet, used for naming the moon</param> /// <param name="distance">Distance</param> /// <returns>An array of all generated moons</returns> private MyPlanetMoonItem[] GenerateMoons(float planetSize, float surfaceGravity, string planetName, long distance) { if (MyRandom.Instance.NextFloat() > m_settings.PlanetSettings.MoonProbability) { return(new MyPlanetMoonItem[0]); } int maxMoons = GetMaxMoonCount(surfaceGravity); int numMoons = MyRandom.Instance.Next(maxMoons > 0 ? 1 : 0, maxMoons + 1); MyPlanetMoonItem[] moons = new MyPlanetMoonItem[numMoons]; for (int i = 0; i < numMoons; i++) { var dist = planetSize * (i + 1) + planetSize * MyRandom.Instance.GetRandomFloat(0.5f, 1.5f); var def = GetPlanetMoonDefinition(planetSize * 0.8f); bool isGasGiant = GasGiants.Contains(def); if (dist + distance > m_settings.WorldSize && m_settings.WorldSize > 0) { return(moons); } string name = SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.MoonNameFormat .SetProperty("ObjectNumber", i + 1) .SetProperty("ObjectNumberGreek", greek_letters[i % greek_letters.Length]) .SetProperty("ObjectNumberRoman", ConvertNumberToRoman(i + 1)) .SetProperty("ObjectLetterLower", (char)('a' + (i % 26))) .SetProperty("ObjectLetterUpper", (char)('A' + (i % 26))) .SetProperty("ObjectId", def.Id.SubtypeId.String) .SetProperty("MoonPlanetName", planetName); MyPlanetMoonItem item = new MyPlanetMoonItem(); item.Type = SystemObjectType.MOON; item.DefName = def.Id.SubtypeName.ToString(); item.Distance = dist; item.Size = SizeByGravity(def.SurfaceGravity, isGasGiant); item.DisplayName = name; moons[i] = item; } return(moons); }
public void GeneratePlanets() { foreach (var obj in SystemGenerator.Static.m_objects) { if (obj == null) { continue; } if (obj.Type != SystemObjectType.PLANET) { continue; } MyPlanetItem planet = (MyPlanetItem)obj; if (planet.Generated) { continue; } MyPlanetGeneratorDefinition definition = GetDefinition(planet.DefName); if (definition == null) { continue; } long id = MyRandom.Instance.NextLong(); string name = (planet.DisplayName + " - " + definition.Id.SubtypeId).Replace(" ", "_"); if (planet.CenterPosition.Equals(Vector3D.Zero)) { planet.CenterPosition = planet.OffsetPosition; } MyPlanet generatedPlanet = MyWorldGenerator.AddPlanet(name, planet.DisplayName, planet.DefName, planet.CenterPosition - GetPlanetOffset(definition, planet.Size), m_seed, planet.Size, true, id, false, true); if (generatedPlanet == null) { continue; } planet.CenterPosition = generatedPlanet.PositionComp.GetPosition(); generatedPlanet.DisplayNameText = planet.DisplayName; generatedPlanet.AsteroidName = planet.DisplayName; if (planet.PlanetRing != null) { planet.PlanetRing.Center = planet.CenterPosition; } List <Vector3D> spawnedMoons = new List <Vector3D>(); for (int i = 0; i < planet.PlanetMoons.Length; i++) { MyPlanetMoonItem moon = planet.PlanetMoons[i]; if (moon == null) { continue; } MyPlanetGeneratorDefinition moonDef = GetDefinition(moon.DefName); if (moonDef == null) { continue; } var position = new Vector3D(0, 0, 0); long mId = MyRandom.Instance.NextLong(); string storageNameMoon = ("Moon " + moon.DisplayName + " - " + moonDef.Id.SubtypeId).Replace(" ", "_"); var threshold = 0; do { double angle = MyRandom.Instance.GetRandomFloat(0, (float)Math.PI * 2f); position = new Vector3D(moon.Distance * Math.Sin(angle), moon.Distance * Math.Cos(angle), moon.Distance * Math.Sin(MyRandom.Instance.GetRandomFloat((float)-Math.PI / 2, (float)Math.PI / 2))); position = Vector3D.Add(planet.CenterPosition, position); threshold++; } while (ObstructedPlace(position, spawnedMoons, planet.Size, planet.PlanetRing) && threshold < 10000); MyPlanet spawnedMoon = MyWorldGenerator.AddPlanet(storageNameMoon, moon.DisplayName, moon.DefName, position, m_seed, moon.Size, true, mId, false, true); spawnedMoons.Add(spawnedMoon.PositionComp.GetPosition()); if (SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.ShowMoonGPS) { GlobalGpsManager.Static.AddGps(moon.DisplayName, Color.Aqua, spawnedMoon.PositionComp.GetPosition()); } } planet.Generated = true; if (SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.ShowPlanetGPS) { GlobalGpsManager.Static.AddGps(planet.DisplayName, Color.Aqua, generatedPlanet.PositionComp.GetPosition()); } } }
static void SendGetMoonClient(bool success, MyPlanetMoonItem item, ulong callback) { Static.m_getActionCallbacks[callback](success, item); Static.m_getActionCallbacks.Remove(callback); }