Exemplo n.º 1
0
        public static void GenerateAllPlanets(GalaxyData galaxy, StarData star, GameDesc gameDesc, List <PlanetForGenerator> planetsToGenerate)
        {
            Patch.Debug("Recap of what have to be generated : \n", LogLevel.Debug, Patch.DebugStarGen);
            var finalIndex = 0;

            foreach (var planet in planetsToGenerate)
            {
                var debugLine = "A ";

                planet.planetIndex = finalIndex;
                foreach (var planetForGenerator in planet.moons)
                {
                    planetForGenerator.orbitAround = finalIndex + 1;
                }

                if (planet.isGasGiant)
                {
                    debugLine += " Gas Giant :" + planet.planetIndex + "with values : \n";
                }
                else
                {
                    debugLine += " Telluric Planet :" + planet.planetIndex + "with values : \n";
                }

                //planet.ToString();

                //planet.GenerateThePlanet(ref galaxy,ref star,ref gameDesc);
                //  Debug.Log();
                PlanetGen.CreatePlanet(galaxy, star, gameDesc, planet.planetIndex, planet.orbitAround, planet.orbitIndex, planet.number, planet.isGasGiant, planet.infoSeed, planet.genSeed);
                star.planets[finalIndex].name = star.name + " - " + RomanNumbers.roman[planet.number];
                planet.name = star.planets[finalIndex].name;

                if (planet.moons.Count >= 2)
                {
                    star.planets[finalIndex].HasMultipleSatellites();
                }

                Patch.Debug(star.planets[finalIndex].name, LogLevel.Debug, Patch.DebugStarNamingGen);
                finalIndex++;
                //debugLine += planet.ToString() + "\n\n";
                if (planet.moons.Count != 0)
                {
                    debugLine += "with " + planet.moons.Count + " Moons  : \n\n";
                    foreach (var moon in planet.moons)
                    {
                        moon.planetIndex = finalIndex;
                        debugLine       += " Moon : " + moon.planetIndex + "\n";
                        PlanetGen.CreatePlanet(galaxy, star, gameDesc, moon.planetIndex, moon.orbitAround, moon.orbitIndex, moon.number, moon.isGasGiant, moon.infoSeed, moon.genSeed);
                        star.planets[moon.planetIndex].name = planet.name + " - " + RomanNumbers.roman[moon.number];
                        Patch.Debug(star.planets[moon.planetIndex].name, LogLevel.Debug, Patch.DebugStarNamingGen);

                        finalIndex++;
                    }
                }



                Patch.Debug(debugLine, LogLevel.Debug, Patch.DebugStarGen);
            }
        }
Exemplo n.º 2
0
        public static PlanetData ReworkCreatePlanet(
            ref GalaxyData galaxy,
            ref StarData star,
            ref GameDesc gameDesc,
            int index,
            int orbitAround,
            int orbitIndex,
            int number,
            bool gasGiant,
            int info_seed,
            int gen_seed)
        {
            Patch.Debug("ReworkCreatePlanet", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);

            var planetData = new PlanetData();
            var mainSeed   = new Random(info_seed);

            //Base data of the planet :
            planetData.index  = index;
            planetData.galaxy = star.galaxy;
            planetData.star   = star;
            planetData.seed   = gen_seed;
            // Index of the thing it's orbiting around , 0 for star , anything else mean it's a moon
            planetData.orbitAround = orbitAround;
            // Current orbit Index around the planet
            planetData.orbitIndex = orbitIndex;
            // index of the planet in the system ?
            planetData.number = number;
            // Global Id of the entity
            planetData.id = star.id * 100 + planetData.index + 1;

            var stars = galaxy.stars;

            Patch.Debug("Basic Information Setup", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);

            var randomNumber1  = mainSeed.NextDouble();
            var randomNumber2  = mainSeed.NextDouble();
            var randomNumber3  = mainSeed.NextDouble();
            var randomNumber4  = mainSeed.NextDouble();
            var randomNumber5  = mainSeed.NextDouble();
            var randomNumber6  = mainSeed.NextDouble();
            var randomNumber7  = mainSeed.NextDouble();
            var randomNumber8  = mainSeed.NextDouble();
            var randomNumber9  = mainSeed.NextDouble();
            var randomNumber10 = mainSeed.NextDouble();
            var randomNumber11 = mainSeed.NextDouble();
            var randomNumber12 = mainSeed.NextDouble();
            var randomNumber13 = mainSeed.NextDouble();
            var randomNumber14 = mainSeed.NextDouble();


            // Orbit definition
            Patch.Debug("Orbit definition", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            var baselineOrbitVariation = Mathf.Pow(1.2f, (float)(randomNumber1 * (randomNumber2 - 0.5) * 0.5));
            var orbitInclination       =
                UnityRandom.Range(0, Patch.MaxOrbitInclination.Value) * MathUtils.RangePlusMinusOne(mainSeed);

            Patch.Debug("Rotation definition", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            // rotation period
            planetData.rotationPeriod = randomNumber8 * randomNumber9 * Patch.RotationPeriodVariabilityFactor.Value +
                                        Patch.RotationPeriodBaseTime.Value;

            // Planet
            Patch.Debug("Body Stuff", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);

            //orbit longitude
            planetData.orbitLongitude = (float)(randomNumber4 * 360.0);
            //runtimeOrbitRotation
            planetData.runtimeOrbitRotation = Quaternion.AngleAxis(planetData.orbitLongitude, Vector3.up) *
                                              Quaternion.AngleAxis(orbitInclination, Vector3.forward);

            planetData.runtimeSystemRotation = planetData.runtimeOrbitRotation * Quaternion.AngleAxis(planetData.obliquity, Vector3.forward);

            if (planetData.IsNotAMoon())
            {
                Patch.Debug("Planets Stuff", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
                //orbit
                var baselineOrbitSize = Patch.OrbitRadiusPlanetArray[orbitIndex] * star.orbitScaler;
                var orbitSize         = (float)((baselineOrbitVariation - 1.0) / Mathf.Max(1f, baselineOrbitSize) + 1.0);
                planetData.orbitRadius = baselineOrbitSize * orbitSize;

                // orbit Inclination + periods
                planetData.orbitInclination = orbitInclination;
                planetData.orbitalPeriod    = Math.Sqrt(pi2Rad * planetData.orbitRadius *
                                                        planetData.orbitRadius * planetData.orbitRadius /
                                                        (1.35385519905204E-06 * star.mass));

                //rotation period
                if (planetData.IsGasGiant() || planetData.star.type == EStarType.NeutronStar)
                {
                    planetData.rotationPeriod *= 0.200000002980232;
                }
                else if (planetData.star.type == EStarType.BlackHole)
                {
                    planetData.rotationPeriod *= 0.150000005960464;
                }

                planetData.sunDistance = planetData.orbitRadius;

                // rotation period
                planetData.rotationPeriod = 1.0 / (1.0 / planetData.orbitalPeriod * 2);

                //Tidal Lock Management
                if (randomNumber13 < Patch.ChanceTidalLock.Value)
                {
                    if (randomNumber13 < Patch.ChanceTidalLock1.Value)
                    {
                        planetData.obliquity     *= 0.01f;
                        planetData.rotationPeriod = planetData.orbitalPeriod;
                        planetData.IsTidallyLocked(TidalLevel.TidalLocked);
                    }
                    else if (randomNumber13 < Patch.ChanceTidalLock2.Value)
                    {
                        planetData.obliquity     *= 0.1f;
                        planetData.rotationPeriod = planetData.orbitalPeriod * 0.5;
                        planetData.IsTidallyLocked(TidalLevel.TidalLocked2);
                    }
                    else
                    {
                        planetData.obliquity     *= 0.2f;
                        planetData.rotationPeriod = planetData.orbitalPeriod * 0.25;
                        planetData.IsTidallyLocked(TidalLevel.TidalLocked4);
                    }
                }

                Patch.Debug("Planets Stuff Done", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
            }

            // Moon
            else
            {
                // the previous algo is using the number of the planet it's orbiting around, not the actual index --> so minus 1
                orbitAround -= 1;

                Patch.Debug("Moon Stuff", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
                //affect the data of the planet of the moon
                Patch.Debug("orbitAround " + orbitAround, LogLevel.Debug, Patch.DebugReworkPlanetGen);

                planetData.orbitAroundPlanet = star.planets[orbitAround];
                Patch.Debug("orbitAround id : " + star.planets[orbitAround].index, LogLevel.Debug, Patch.DebugReworkPlanetGen);
                var orbitRadiusScaled = Patch.OrbitRadiusArrayMoons[orbitIndex] * star.orbitScaler *
                                        Mathf.Lerp(baselineOrbitVariation, 1f, 0.5f) *
                                        planetData.orbitAroundPlanet.GetGasGiantOrbitScaler();
                //orbit
                planetData.orbitRadius = orbitRadiusScaled;
                Patch.Debug("orbitRadius " + planetData.orbitRadius, LogLevel.Debug, Patch.DebugReworkPlanetGen);
                // orbit Inclination + periods
                planetData.orbitInclination = orbitInclination * Patch.MoonOrbitInclinationFactor.Value;
                Patch.Debug("orbitInclination " + planetData.orbitInclination, LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);

                planetData.orbitalPeriod = Math.Sqrt(pi2Rad * planetData.orbitRadius *
                                                     planetData.orbitRadius * planetData.orbitRadius / 1.08308421068537E-08);
                Patch.Debug("orbitalPeriod " + planetData.orbitalPeriod, LogLevel.Debug, Patch.DebugReworkPlanetGen);

                planetData.rotationPeriod *= Mathf.Pow(planetData.orbitRadius, 0.25f);
                Patch.Debug("rotationPeriod " + planetData.rotationPeriod, LogLevel.Debug, Patch.DebugReworkPlanetGen);


                // distance = planet of the moon
                planetData.sunDistance = planetData.orbitAroundPlanet.orbitRadius;

                Patch.Debug("sunDistance " + planetData.sunDistance, LogLevel.Debug, Patch.DebugReworkPlanetGen);

                // rotation period
                planetData.rotationPeriod =
                    1.0 / (1.0 / planetData.orbitAroundPlanet.orbitalPeriod + 1.0 / planetData.rotationPeriod);
                Patch.Debug("rotationPeriod - 2 " + planetData.rotationPeriod, LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);


                Patch.Debug("Tidal Lock " + planetData.rotationPeriod, LogLevel.Debug, Patch.DebugReworkPlanetGen);
                //Tidal Lock Management
                if (randomNumber13 < Patch.ChanceTidalLock.Value)
                {
                    if (randomNumber13 < Patch.ChanceTidalLock1.Value)
                    {
                        planetData.obliquity     *= 0.01f;
                        planetData.rotationPeriod = planetData.orbitAroundPlanet.orbitalPeriod;
                        planetData.IsTidallyLocked(TidalLevel.TidalLocked);
                    }
                    else if (randomNumber13 < Patch.ChanceTidalLock2.Value)
                    {
                        planetData.obliquity     *= 0.1f;
                        planetData.rotationPeriod = planetData.orbitAroundPlanet.orbitalPeriod * 0.5;
                        planetData.IsTidallyLocked(TidalLevel.TidalLocked2);
                    }
                    else
                    {
                        planetData.obliquity     *= 0.2f;
                        planetData.rotationPeriod = planetData.orbitAroundPlanet.orbitalPeriod * 0.25;
                        planetData.IsTidallyLocked(TidalLevel.TidalLocked4);
                    }
                }

                Patch.Debug("End Tidal Lock " + planetData.rotationPeriod, LogLevel.Debug, Patch.DebugReworkPlanetGen);

                //runtimeOrbitRotation

                planetData.runtimeOrbitRotation = planetData.orbitAroundPlanet.runtimeOrbitRotation *
                                                  planetData.runtimeOrbitRotation;
                Patch.Debug("runtimeOrbitRotation " + planetData.runtimeOrbitRotation, LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
                Patch.Debug("Moon Stuff Done", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
            }

            Patch.Debug("Body orbit Phase", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            // orbit phase
            planetData.orbitPhase = (float)(randomNumber5 * 360.0);

            Patch.Debug("Body Rotation Phase", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            //rotation phase
            planetData.rotationPhase = (float)(randomNumber10 * 360.0);

            Patch.Debug("Body Orbit Obliquity", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            // orbit obliquity
            Patch.Debug("Body Obliquity Modification", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            if (randomNumber13 < Patch.ChancePlanetLaySide.Value)
            {
                planetData.obliquity = (float)randomNumber6 * MathUtils.RangePlusMinusOne(mainSeed) *
                                       Patch.LaySideBaseAngle.Value;
                planetData.obliquity += Patch.LaySideAddingAngle.Value * MathUtils.RangePlusMinusOne(mainSeed);
                planetData.HasLayingObliquity();
            }
            else if (randomNumber13 < Patch.ChanceBigObliquity.Value)
            {
                planetData.obliquity = (float)randomNumber6 * MathUtils.RangePlusMinusOne(mainSeed) *
                                       Patch.BigObliquityBaseAngle.Value;
                planetData.obliquity += Patch.BigObliquityAddingAngle.Value * MathUtils.RangePlusMinusOne(mainSeed);
            }
            else
            {
                planetData.obliquity = (float)randomNumber6 * MathUtils.RangePlusMinusOne(mainSeed) *
                                       Patch.StandardObliquityAngle.Value;
            }

            Patch.Debug("Body runtimeSystemRotation", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            //runtimeOrbitRotation obliquity adjustment
            planetData.runtimeSystemRotation = planetData.runtimeOrbitRotation *
                                               Quaternion.AngleAxis(planetData.obliquity, Vector3.forward);


            Patch.Debug("Body Retrograde", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            //Define if the orbit is retrograde
            if (randomNumber14 < Patch.ChanceRetrogradeOrbit.Value)
            {
                planetData.HasRetrogradeOrbit();
            }

            Patch.Debug("Body Neutron Star", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            // Anomaly around neutron stars
            if (planetData.star.type == EStarType.NeutronStar)
            {
                planetData.OrbitAroundNeutronStar();
            }

            Patch.Debug("Body Type Definition", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            // type of the planet :
            if (gasGiant)
            {
                Patch.Debug("Body is Gas Giant", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
                planetData.type          = EPlanetType.Gas;
                planetData.habitableBias = 100f;
            }
            else
            {
                Patch.Debug("Body TypeDefinition ( planet / Moon )", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
                var sunDistance            = planetData.sunDistance;
                var ratioHabitableDistance = Patch.HabitabilityBaseConstant.Value;
                Patch.Debug("Body Habitability", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
                if (star.habitableRadius > 0.0 && sunDistance > 0.0)
                {
                    ratioHabitableDistance = sunDistance / star.habitableRadius;
                }

                Patch.Debug("Star Habitability radius ", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
                var minRadiusHabitable = star.habitableRadius - Patch.HabitableRadiusAreaBaseline.Value;
                var maxRadiusHabitable = star.habitableRadius + Patch.HabitableRadiusAreaBaseline.Value;

                if (planetData.sunDistance < maxRadiusHabitable && planetData.sunDistance > minRadiusHabitable)
                {
                    planetData.habitableBias = Patch.ChanceBeingHabitable.Value;
                }

                Patch.Debug("Body Temperature ( planet / Moon )", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
                planetData.temperatureBias =
                    (float)(1.20000004768372 / (ratioHabitableDistance + 0.200000002980232) - 1.0);


                if (randomNumber11 < planetData.habitableBias)
                {
                    Patch.Debug("Body Type Ocean ( planet / Moon )", LogLevel.Debug,
                                Patch.DebugReworkPlanetGen);
                    planetData.type = EPlanetType.Ocean;
                    ++star.galaxy.habitableCount;
                }
                else if (ratioHabitableDistance < Patch.VolcanoPlanetDistanceRatio.Value)
                {
                    Patch.Debug("Body Type Volcano ( planet / Moon )", LogLevel.Debug,
                                Patch.DebugReworkPlanetGen);
                    planetData.type = EPlanetType.Vocano;
                }
                else if (ratioHabitableDistance > Patch.IcePlanetDistanceRatio.Value)
                {
                    Patch.Debug("Body Type Ice ( planet / Moon )", LogLevel.Debug,
                                Patch.DebugReworkPlanetGen);
                    planetData.type = EPlanetType.Ice;
                }
                else
                {
                    Patch.Debug("Body Type Desert ( planet / Moon )", LogLevel.Debug,
                                Patch.DebugReworkPlanetGen);
                    planetData.type = EPlanetType.Desert;
                }

                Patch.Debug("Body Type Defined ( planet / Moon )", LogLevel.Debug,
                            Patch.DebugReworkPlanetGen);
            }

            Patch.Debug("Body Luminosity( planet / Moon )", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            //Luminosity
            planetData.luminosity = Mathf.Pow(planetData.star.lightBalanceRadius / (planetData.sunDistance + 0.01f), 0.6f);
            if (planetData.luminosity > 1.0)
            {
                planetData.luminosity = Mathf.Log(planetData.luminosity) + 1f;
                planetData.luminosity = Mathf.Log(planetData.luminosity) + 1f;
                planetData.luminosity = Mathf.Log(planetData.luminosity) + 1f;
            }

            planetData.luminosity = Mathf.Round(planetData.luminosity * 100f) / 100f;

            Patch.Debug("Body Size Def ( planet / Moon )", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);
            //Size related stuff :
            if (planetData.type == EPlanetType.Gas)
            {
                var radiusGasGiantWanted = PatchSize.VanillaGasGiantSize;
                if (PatchSize.EnableResizingFeature.Value)
                {
                    //Default : 0.25
                    var minScalingGasGiantRatio =
                        (PatchSize.BaseGasGiantSize.Value - PatchSize.BaseGasGiantSizeVariationFactor.Value) /
                        (PatchSize.BaseGasGiantSize.Value + PatchSize.BaseGasGiantSizeVariationFactor.Value);

                    radiusGasGiantWanted = PatchSize.BaseGasGiantSize.Value +
                                           MathUtils.RangePlusMinusOne(mainSeed) *
                                           PatchSize.BaseGasGiantSizeVariationFactor.Value;
                    radiusGasGiantWanted -= radiusGasGiantWanted % 10;
                }

                planetData.scale  = PatchSize.VanillaGasGiantScale;
                planetData.radius = radiusGasGiantWanted / planetData.scale;

                planetData.precision = 64;
                planetData.segment   = 2;
            }
            else if (planetData.type != EPlanetType.None)
            {
                if (PatchSize.EnableResizingFeature.Value)
                {
                    var radiusTelluricWanted = PatchSize.VanillaTelluricSize;
                    if (planetData.IsNotAMoon())
                    {
                        radiusTelluricWanted = PatchSize.BaseTelluricSize.Value +
                                               MathUtils.RangePlusMinusOne(mainSeed) *
                                               PatchSize.BaseTelluricSizeVariationFactor.Value;
                    }
                    else
                    {
                        //A moon can only be smaller than it's host
                        if (planetData.orbitAroundPlanet.type != EPlanetType.Gas)
                        {
                            radiusTelluricWanted = planetData.orbitAroundPlanet.radius -
                                                   (float)mainSeed.NextDouble() *
                                                   PatchSize.BaseTelluricSizeVariationFactor.Value;
                            // clamp to avoid weird sizes
                            radiusTelluricWanted = Mathf.Clamp(radiusTelluricWanted,
                                                               PatchSize.MinTelluricSize.Value,
                                                               planetData.orbitAroundPlanet.radius);
                        }
                        else
                        {
                            radiusTelluricWanted = PatchSize.BaseTelluricSize.Value +
                                                   MathUtils.RangePlusMinusOne(mainSeed) *
                                                   PatchSize.BaseTelluricSizeVariationFactor.Value;
                        }
                    }

                    radiusTelluricWanted -= radiusTelluricWanted % 10;
                    planetData.radius     = Mathf.RoundToInt(radiusTelluricWanted);
                    Patch.Debug(" planetData.radius" + planetData.radius, LogLevel.Debug,
                                Patch.DebugReworkPlanetGenDeep);

                    planetData.scale = planetData.GetScaleFactored();
                    Patch.Debug(" planetData.scale" + planetData.scale, LogLevel.Debug,
                                Patch.DebugReworkPlanetGenDeep);

                    planetData.precision = planetData.GetPrecisionFactored();
                    Patch.Debug(" planetData.precision" + planetData.precision, LogLevel.Debug,
                                Patch.DebugReworkPlanetGenDeep);
                }
                else
                {
                    planetData.radius    = PatchSize.VanillaTelluricSize;
                    planetData.scale     = PatchSize.VanillaTelluricScale;
                    planetData.precision = PatchSize.VanillaTelluricPrecision;
                }

                planetData.segment = 5;
            }
            else
            {
                planetData.radius    = PatchSize.VanillaTelluricSize;
                planetData.precision = 64;
                planetData.segment   = 2;
            }

            star.planets[planetData.index] = planetData;
            planetData.star = star;

            Patch.Debug("Body Theme Def ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen);
            Patch.Debug("planetData \n" +
                        "planetData.star.index " + planetData.star.index + "\n" +
                        "planetData.index " + planetData.index + "\n" +
                        "planetData.temperatureBias " + planetData.temperatureBias + "\n" +
                        "planetData.planets " + planetData.star.planets + "\n" +
                        "planetData.planets index : " + planetData.star.planets[planetData.index].type + "\n" +
                        "planetData.planets Lenght " + planetData.star.planets.Length + "\n" +
                        "planetData.type " + planetData.type + "\n" +
                        "planetData.mod_x " + planetData.mod_x + "\n" +
                        "planetData.mod_y " + planetData.mod_y + "\n" +
                        "planetData.algoId " + planetData.algoId + "\n"
                        , LogLevel.Debug, Patch.DebugReworkPlanetGen);

            star.galaxy.astroPoses[planetData.id].uRadius = planetData.realRadius;


            Patch.Debug("ReworkCreatePlanet Done !", LogLevel.Debug,
                        Patch.DebugReworkPlanetGen);

            return(planetData);
        }
Exemplo n.º 3
0
        public static void CreateStarPlanetsRework(GalaxyData galaxy, StarData star, GameDesc gameDesc, PlanetGeneratorSettings genSettings)
        {
            star.name = SystemsNames.systems[star.index];

            Patch.Debug("System " + star.name + " - " + star.type + " - " + star.spectr, LogLevel.Debug,
                        Patch.DebugStarGen);

            // Random Generators Inits
            UnityRandom.InitState(star.seed);
            var mainSeed  = new Random(star.seed);
            var annexSeed = new Random(mainSeed.Next());

            // InnerCount for the System
            var planetsToGenerate = new List <PlanetForGenerator>();

            // settings from the config
            PatchForStarSystemGeneration.StarSystemSetting currentSettings;

            if (star.type == EStarType.BlackHole || star.type == EStarType.GiantStar ||
                star.type == EStarType.NeutronStar || star.type == EStarType.WhiteDwarf)
            {
                currentSettings = Patch.GeneratorSpecialsSystemConfig[star.type];
            }
            else
            {
                currentSettings = Patch.GeneratorMainSystemConfig[star.spectr];
            }

            //Debugging configs
            Patch.Debug("*************************** : \n" +
                        "ChanceMoonGasGiant : " + currentSettings.ChanceGasGiantMoon + "\n" +
                        "ChanceMoonTelluric : " + currentSettings.ChanceMoonTelluric + "\n" +
                        "ChancePlanetTelluric : " + currentSettings.ChanceTelluricPlanet + "\n" +
                        "ChancePlanetGasGiant : " + currentSettings.ChanceGasGiant + "\n" +
                        "MaxMoonNb : " + currentSettings.MaxMoonNb + "\n" +
                        "MaxPlanetNb : " + currentSettings.MaxPlanetNb + "\n" +
                        "ChanceJumpOrbitMoons : " + currentSettings.ChanceJumpOrbitMoons + "\n" +
                        "ChanceJumpOrbitPlanets : " + currentSettings.ChanceJumpOrbitPlanets + "\n" +
                        "*************************** ", LogLevel.Debug, Patch.DebugStarGenDeep);

            Patch.Debug("Definition of Nb of planets In the system :", LogLevel.Debug, Patch.DebugStarGenDeep);

            DefineNumberOfBodies(currentSettings, annexSeed, genSettings);

            if (star.IsStartingStar())
            {
                // check if minimum number of planet is met
                genSettings.nbOfTelluricPlanets = genSettings.nbOfTelluricPlanets < Patch.StartingSystemMinPlanetTelluricNb.Value ? Patch.StartingSystemMinPlanetTelluricNb.Value : genSettings.nbOfTelluricPlanets;
                genSettings.nbOfMoonsTelluric   = genSettings.nbOfMoonsTelluric < Patch.StartingSystemMinTelluricMoonNb.Value ? Patch.StartingSystemMinTelluricMoonNb.Value : genSettings.nbOfMoonsTelluric;
                genSettings.nbOfGasGiantPlanets = genSettings.nbOfGasGiantPlanets < Patch.StartingSystemMinGasGiantNb.Value ? Patch.StartingSystemMinGasGiantNb.Value : genSettings.nbOfGasGiantPlanets;
                genSettings.nbOfMoonsGasGiant   = genSettings.nbOfMoonsGasGiant < Patch.StartingSystemMinGasGiantMoonNb.Value ? Patch.StartingSystemMinGasGiantMoonNb.Value : genSettings.nbOfMoonsGasGiant;

                genSettings.nbOfMoons         = genSettings.nbOfMoonsTelluric + genSettings.nbOfMoonsGasGiant;
                genSettings.nbOfPlanets       = genSettings.nbOfTelluricPlanets + genSettings.nbOfGasGiantPlanets;
                genSettings.nbOfStellarBodies = genSettings.nbOfPlanets + genSettings.nbOfMoons;
            }

            star.planets = new PlanetData[genSettings.nbOfStellarBodies];

            Patch.Debug("*************************** :", LogLevel.Debug, Patch.DebugStarGen);
            Patch.Debug("\nSystem Presets : ", LogLevel.Debug, Patch.DebugStarGen);

            var preset =
                "nbOfPlanets : " + genSettings.nbOfPlanets + "\n" +
                "nbOfTelluricPlanets : " + genSettings.nbOfTelluricPlanets + "\n" +
                "nbOfGasGiantPlanets : " + genSettings.nbOfGasGiantPlanets + "\n" +
                "nbOfMoons : " + genSettings.nbOfMoons + "\n" +
                "nbOfMoonsTelluric : " + genSettings.nbOfMoonsTelluric + "\n" +
                "nbOfMoonsGasGiant : " + genSettings.nbOfMoonsGasGiant + "\n\n";

            Patch.Debug(preset, LogLevel.Debug, Patch.DebugStarGen);

            PreGenerateAllBodies(star, planetsToGenerate, annexSeed, genSettings, currentSettings);

            GenerateAllPlanets(galaxy, star, gameDesc, planetsToGenerate);


            if (star.IsStartingStar())
            {
                Patch.Debug(star.name + " --recap-- : ", LogLevel.Debug, Patch.DebugStarGen);
                var nbOfHabitablePlanets = 0;
                foreach (var planet in star.planets)
                {
                    if (planet.orbitAround != 0)
                    {
                        Patch.Debug("moon type : " + planet.type, LogLevel.Debug, Patch.DebugStarGen);
                    }
                    else
                    {
                        Patch.Debug("planet type : " + planet.type, LogLevel.Debug, Patch.DebugStarGen);
                    }

                    if (planet.type == EPlanetType.Ocean)
                    {
                        nbOfHabitablePlanets++;
                    }
                }

                if (nbOfHabitablePlanets == 0)
                {
                    Patch.Debug("Nb of habitable == 0 --> Override one planet ", LogLevel.Debug, Patch.DebugStarGen);
                    bool @override = true;
                    while (@override)
                    {
                        var indexStartingPlanet = UnityRandom.Range(0, star.planets.Length - 1);

                        if (star.planets[indexStartingPlanet].type != EPlanetType.Gas)
                        {
                            star.planets[indexStartingPlanet].ShouldBeHabitable();
                            galaxy.birthPlanetId = star.planets[indexStartingPlanet].id;
                            @override            = false;
                        }
                    }


                    Patch.Debug(" galaxy.birthPlanetId --> " + galaxy.birthPlanetId, LogLevel.Debug, Patch.DebugStarGen);
                }
            }

            // Apply themes
            foreach (var planet in star.planets)
            {
                PlanetGen.SetPlanetTheme(planet, star, gameDesc, 0, 0, mainSeed.NextDouble(), mainSeed.NextDouble(), mainSeed.NextDouble(), mainSeed.NextDouble(), mainSeed.Next());
                Patch.Debug("planet.algoId --> " + planet.algoId, LogLevel.Debug, Patch.DebugStarGen);
            }

            star.planetCount = star.planets.Length;
        }
Exemplo n.º 4
0
        public static void PreGenerateAllBodies(StarData star, List <PlanetForGenerator> planetsToGenerate, Random annexSeed, PlanetGeneratorSettings genSettings, PatchForStarSystemGeneration.StarSystemSetting currentSettings)
        {
            //
            //preparation of the planet creation :
            Patch.Debug("Define the belts for whatever they are for :", LogLevel.Debug, Patch.DebugStarGenDeep);
            //Define where the 2 asteroids belts are ( maybe not implemented )
            var asterBelt1OrbitIndex = UnityRandom.Range(1, genSettings.nbOfPlanets - 1);
            var asterBelt2OrbitIndex = UnityRandom.Range(asterBelt1OrbitIndex + 1, genSettings.nbOfPlanets);

            Patch.Debug("asterBelt1OrbitIndex :" + asterBelt1OrbitIndex, LogLevel.Debug, Patch.DebugStarGenDeep);
            Patch.Debug("asterBelt2OrbitIndex :" + asterBelt2OrbitIndex, LogLevel.Debug, Patch.DebugStarGenDeep);


            //Attach the information to the star
            star.asterBelt1OrbitIndex = asterBelt1OrbitIndex;
            star.asterBelt2OrbitIndex = asterBelt2OrbitIndex;
            star.asterBelt1Radius     = Patch.OrbitRadiusPlanetArray[asterBelt1OrbitIndex];
            star.asterBelt2Radius     = Patch.OrbitRadiusPlanetArray[asterBelt2OrbitIndex];


            int infoSeed;
            int genSeed;

            // planets pre-generation
            var nbOfBodiesPreGenerated    = 0;
            var nbOfPlanetsPreGenerated   = 0;
            var planetsPreGeneratedNumber = 1;
            var nbOfMoonsPreGenerated     = 0;

            var currentOrbitPlanetIndex  = 1;
            var previousOrbitPlanetIndex = 0;
            int currentOrbitMoonIndex;

            var beltGenerated = 0;

            int jumpOrbitMargin;

            for (var i = 0; i < genSettings.nbOfStellarBodies; i++)
            {
                infoSeed = annexSeed.Next();
                genSeed  = annexSeed.Next();

                int planetInfoSeed = 0 + infoSeed;
                int planetGenSeed  = 0 + genSeed;
                Patch.Debug("bodies generated !" + nbOfBodiesPreGenerated, LogLevel.Debug, Patch.DebugStarGenDeep);
                Patch.Debug("genSettings.nbOfPlanets + genSettings.nbOfMoons !" + (genSettings.nbOfPlanets + genSettings.nbOfMoons), LogLevel.Debug, Patch.DebugStarGenDeep);
                bool isGasGiant;
                var  orbitAround = 0;

                if (asterBelt1OrbitIndex == currentOrbitPlanetIndex)
                {
                    Patch.Debug("Jump Belt 1 Orbit :", LogLevel.Debug, Patch.DebugStarGenDeep);
                    currentOrbitPlanetIndex++;
                    nbOfBodiesPreGenerated++;
                    beltGenerated++;
                }

                if (asterBelt2OrbitIndex == currentOrbitPlanetIndex)
                {
                    Patch.Debug("Jump Belt 2 Orbit :", LogLevel.Debug, Patch.DebugStarGenDeep);
                    currentOrbitPlanetIndex++;
                    nbOfBodiesPreGenerated++;
                    beltGenerated++;
                }

                Patch.Debug("nbOfPlanetsPreGenerated : " + nbOfPlanetsPreGenerated, LogLevel.Debug, Patch.DebugStarGenDeep);
                Patch.Debug("nbOfPlanets : " + genSettings.nbOfPlanets, LogLevel.Debug, Patch.DebugStarGenDeep);
                if (nbOfPlanetsPreGenerated < genSettings.nbOfPlanets)
                {
                    //planets
                    // jumporbit planet

                    jumpOrbitMargin = Patch.OrbitRadiusArrayPlanetNb.Value - (genSettings.nbOfPlanets - nbOfPlanetsPreGenerated);

                    if (currentOrbitPlanetIndex < jumpOrbitMargin && jumpOrbitMargin < currentSettings.JumpOrbitPlanetMax)
                    {
                        if (annexSeed.NextDouble() < currentSettings.ChanceJumpOrbitPlanets) // can jump orbit up to JumpOrbitPlanetIndex
                        {
                            currentOrbitPlanetIndex = UnityRandom.Range(currentOrbitPlanetIndex, currentOrbitPlanetIndex + currentSettings.JumpOrbitPlanetMax);
                        }
                    }

                    previousOrbitPlanetIndex = currentOrbitPlanetIndex;


                    orbitAround = 0;

                    if (nbOfBodiesPreGenerated < genSettings.nbOfTelluricPlanets + beltGenerated) //telluric
                    {
                        isGasGiant = false;
                    }
                    else //gasgiant
                    {
                        isGasGiant = true;
                    }


                    planetsToGenerate.Add(new PlanetForGenerator(nbOfBodiesPreGenerated - beltGenerated, orbitAround, currentOrbitPlanetIndex, planetsPreGeneratedNumber, isGasGiant, planetInfoSeed, planetGenSeed, null));
                    Patch.Debug("planetsToGenerate -->   \n" + planetsToGenerate[nbOfPlanetsPreGenerated].ToStringDebug(), LogLevel.Debug, Patch.DebugStarGen);
                    nbOfPlanetsPreGenerated++;
                    planetsPreGeneratedNumber++;
                    currentOrbitPlanetIndex++;
                    if (isGasGiant)
                    {
                        Patch.Debug("gas Giant generated !", LogLevel.Debug, Patch.DebugStarGen);
                    }
                    else
                    {
                        Patch.Debug("planet generated !", LogLevel.Debug, Patch.DebugStarGen);
                    }
                }
                else if (nbOfBodiesPreGenerated < genSettings.nbOfPlanets + genSettings.nbOfMoons + beltGenerated)
                {
                    Patch.Debug("Moon in generation!", LogLevel.Debug, Patch.DebugStarGen);

                    isGasGiant = false;

                    if (genSettings.nbOfTelluricPlanets != 0 && nbOfBodiesPreGenerated < genSettings.nbOfPlanets + genSettings.nbOfMoonsTelluric + beltGenerated)
                    {
                        // telluric moon
                        orbitAround = UnityRandom.Range(1, genSettings.nbOfTelluricPlanets);
                        Patch.Debug("telluric moon! orbit around : " + orbitAround, LogLevel.Debug, Patch.DebugStarGenDeep);
                    }
                    else
                    {
                        if (genSettings.nbOfGasGiantPlanets != 0)
                        {
                            //gasgiant moon
                            orbitAround = UnityRandom.Range(genSettings.nbOfTelluricPlanets + 1, genSettings.nbOfTelluricPlanets + genSettings.nbOfGasGiantPlanets);
                            Patch.Debug("gas moon! orbit around : " + orbitAround, LogLevel.Debug, Patch.DebugStarGenDeep);
                        }
                    }

                    if (orbitAround <= 0)
                    {
                        Patch.Debug("Issue in moon generation : " + orbitAround, LogLevel.Debug, Patch.DebugStarGen);
                    }

                    jumpOrbitMargin = Patch.OrbitRadiusArrayMoonsNb.Value - (genSettings.nbOfMoons - nbOfMoonsPreGenerated);

                    Patch.Debug("orbitAround - 1 : " + (orbitAround - 1), LogLevel.Debug, Patch.DebugStarGenDeep);
                    Patch.Debug("planetsToGenerate.Count :" + planetsToGenerate.Count, LogLevel.Debug, Patch.DebugStarGenDeep);
                    Patch.Debug("planetsToGenerate[orbitAround - 1] :" + planetsToGenerate[orbitAround - 1].orbitIndex, LogLevel.Debug, Patch.DebugStarGenDeep);


                    int currentPlanetMoonsNb;
                    var currentPlanet = planetsToGenerate[orbitAround - 1];
                    Patch.Debug("planetsToGenerate nb  :" + planetsToGenerate.Count, LogLevel.Debug, Patch.DebugStarGenDeep);
                    currentPlanetMoonsNb = currentPlanet.moons.Count;


                    Patch.Debug("currentPlanetMoonsNb :" + currentPlanetMoonsNb, LogLevel.Debug, Patch.DebugStarGenDeep);
                    if (currentPlanetMoonsNb != 0)
                    {
                        currentOrbitMoonIndex = currentPlanet.moons[currentPlanetMoonsNb - 1].orbitIndex + 1;
                    }
                    else
                    {
                        currentOrbitMoonIndex = 0;
                    }

                    Patch.Debug("currentOrbitMoonIndex : " + currentOrbitMoonIndex, LogLevel.Debug, Patch.DebugStarGenDeep);

                    if (currentOrbitMoonIndex < jumpOrbitMargin && jumpOrbitMargin < currentSettings.JumpOrbitMoonMax)
                    {
                        if (annexSeed.NextDouble() < currentSettings.ChanceJumpOrbitMoons)
                        {
                            // can jump orbit up to JumpOrbitPlanetIndex
                            var oldOrbitIndex = currentOrbitMoonIndex;
                            currentOrbitMoonIndex += UnityRandom.Range(currentOrbitMoonIndex, currentOrbitMoonIndex + currentSettings.JumpOrbitMoonMax);
                        }
                    }

                    currentPlanet.AddMoonInOrbit(nbOfBodiesPreGenerated, currentOrbitMoonIndex, planetGenSeed, planetInfoSeed);


                    nbOfMoonsPreGenerated++;
                    Patch.Debug("moonToGenerate --> +" + genSettings.nbOfMoons + " --> nbOfMoonsPreGenerated : " + nbOfMoonsPreGenerated, LogLevel.Debug, Patch.DebugStarGenDeep);
                }

                nbOfBodiesPreGenerated++;
            }
        }
Exemplo n.º 5
0
        public static void DefineNumberOfBodies(PatchForStarSystemGeneration.StarSystemSetting currentSettings, Random annexSeed, PlanetGeneratorSettings genSettings)
        {
            // Define how much planets the system have
            for (var i = 0; i < currentSettings.MaxPlanetNb; i++)
            {
                if (annexSeed.NextDouble() <= currentSettings.ChanceTelluricPlanet)
                {
                    genSettings.nbOfTelluricPlanets++;
                    genSettings.nbOfPlanets++;
                    genSettings.nbOfStellarBodies++;
                }
            }

            // Define how much of the planets are GasGiant
            for (var j = genSettings.nbOfPlanets; j < currentSettings.MaxPlanetNb; j++)
            {
                if (annexSeed.NextDouble() <= currentSettings.ChanceGasGiant)
                {
                    genSettings.nbOfGasGiantPlanets++;
                    genSettings.nbOfPlanets++;
                    genSettings.nbOfStellarBodies++;
                }
            }

            Patch.Debug("*************************** : \n" +
                        "nbOfPlanets : " + genSettings.nbOfPlanets + "\n" +
                        "nbOfTelluricPlanets : " + genSettings.nbOfTelluricPlanets + "\n" +
                        "nbOfGasGiantPlanets : " + genSettings.nbOfGasGiantPlanets + "\n" +
                        "*************************** ", LogLevel.Debug, Patch.DebugStarGenDeep);

            Patch.Debug("Definition of Nb of Moons In the system :", LogLevel.Debug, Patch.DebugStarGenDeep);
            // Define how much moons the system have
            // Define how much moons the telluric  planets have
            if (genSettings.nbOfTelluricPlanets != 0)
            {
                for (var i = 0; i < currentSettings.MaxMoonNb; i++)
                {
                    if (annexSeed.NextDouble() <= currentSettings.ChanceMoonTelluric)
                    {
                        genSettings.nbOfMoonsTelluric++;
                        genSettings.nbOfMoons++;
                        genSettings.nbOfStellarBodies++;
                    }
                }
            }
            else
            {
                Patch.Debug("No Telluric in the system :", LogLevel.Debug, Patch.DebugStarGenDeep);
            }

            // Define how much moons the gasGiants planets have
            if (genSettings.nbOfGasGiantPlanets != 0)
            {
                for (var i = genSettings.nbOfMoons; i < currentSettings.MaxMoonNb; i++)
                {
                    if (annexSeed.NextDouble() <= currentSettings.ChanceGasGiantMoon)
                    {
                        genSettings.nbOfMoonsGasGiant++;
                        genSettings.nbOfMoons++;
                        genSettings.nbOfStellarBodies++;
                    }
                }
            }
            else
            {
                Patch.Debug("No Gas Giant in the system :", LogLevel.Debug, Patch.DebugStarGenDeep);
            }

            Patch.Debug("*************************** : \n" +
                        "nbOfMoons : " + genSettings.nbOfMoons + "\n" +
                        "nbOfMoonsTelluric : " + genSettings.nbOfMoonsTelluric + "\n" +
                        "nbOfMoonsGasGiant : " + genSettings.nbOfMoonsGasGiant + "\n" +
                        "*************************** ", LogLevel.Debug, Patch.DebugStarGenDeep);

            Patch.Debug("*************************** :", LogLevel.Debug, Patch.DebugStarGenDeep);
        }