/// <summary> /// Generates a random name, composed of prefix + suffix. /// </summary> /// <returns>A name.</returns> public static string GenerateName() { string prefix = prefixes [WarpRNG.GenerateInt(0, prefixes.Length)]; string suffix = suffixes [WarpRNG.GenerateInt(0, suffixes.Length)]; return(prefix + suffix); }
public static double CalculateSOIFromMass(PlanetData body) { if (body.IsSun()) { return(MAX_SEMI_MAJOR_AXIS); } /*double semiMajorAxis = body.semiMajorAxis / KERBAL_ASTRONOMICAL_UNIT; * double mass = body.planet.Mass / KERBIN_MASS; * double parentMass = body.referenceBody.Mass / KERBIN_MASS; * double massRatio = mass / parentMass; * double twoFifths = 2.0 / 5.0; * return semiMajorAxis * Math.Pow (massRatio, twoFifths) * KERBAL_ASTRONOMICAL_UNIT;*/ double gravityMult = body.gravityMultiplier; if (body.IsMoon()) { // All moons have their gravity adjusted according to the following quadratic: // y = (4 * sqrt(7925156250 * x + 3082419716)+499779)/100000 double moonModifier = (double)((4.0f * Mathf.Sqrt((7925156250.0f * (float)gravityMult) + 3082419716.0f) + 499779.0f) / 100000.0f); // This "unskews" the gravity multiplier and allows moons to use the same gravity formula as planets gravityMult *= moonModifier; } // Kerbal Space Program doesn't use a straight 1:1 ratio for Gravity -> SOI // Instead, it uses something along the following quadratic: y = 7.42334 - 9.01415 x + 2.59081 x^2 // Note that the range from 1.25 to 2.15 generates negative values if (gravityMult > 1.25 && gravityMult < 2.15) { gravityMult += 1.0f; } double difference = (2.59081 * gravityMult * gravityMult) - (9.01415 * gravityMult) + 7.42334; double sphereOfInfluence = gravityMult * difference; // No stock moon has a larger SOI than 15% of Kerbin's // If we generate absurdly large or invalid values, we throw them out // This is the "old" formula and may not be perfect if (double.IsNaN(sphereOfInfluence) || body.IsMoon() && sphereOfInfluence > 0.15) { Debugger.LogWarning("Tossing SOI for " + body.name + ": " + sphereOfInfluence + ". Gravity: " + gravityMult); sphereOfInfluence = body.planet.Radius * 1.5; if (body.IsMoon()) { // Sphere of Influence is modified by the Mun's SOI and the gravity of our body sphereOfInfluence += (MUN_SOI * WarpRNG.GenerateFloat(0.0f, 1.5f)); if (sphereOfInfluence * 2 > body.referenceBodyData.sphereOfInfluence) { // Our parent body must have at least double our influence float sphereMult = WarpRNG.GenerateFloat(0.1f, 0.5f); // There is still a minimum of our radius * 1.5, however sphereOfInfluence = body.referenceBodyData.sphereOfInfluence * sphereMult; if (sphereOfInfluence < body.planet.Radius * 1.5) { sphereOfInfluence = body.planet.Radius * 1.5; // Parent body must now have at minimum double that value as its SOI double parentSOI = sphereOfInfluence * WarpRNG.GenerateFloat(2.0f, 3.0f); body.solarSystem.AdjustPlanetSOI(body.referenceBodyData.planetID, parentSOI); // Gravity must also reflect this // Remove the parent's radius from the SOI calculations parentSOI -= body.referenceBodyData.planet.Radius * 1.5; // New gravity multiplier is based on how much stronger this is than Kerbin's SOI double parentGravityMult = parentSOI / KERBIN_SOI; body.solarSystem.AdjustPlanetGravity(body.referenceBodyData.planetID, KERBIN_GRAVITY * parentGravityMult); } } } else { // Planet // Sphere of Influence is modified by Kerbin's SOI and the gravity of our body sphereOfInfluence += (KERBIN_SOI * gravityMult); } } else { if (sphereOfInfluence > 80) { // Jool would have an absurdly large SOI in this formula, but it's capped at 80 sphereOfInfluence = 80; } // Sphere of Influence is presented as a multiplier of Kerbin's SOI sphereOfInfluence *= KERBIN_SOI; } return(sphereOfInfluence); }