Пример #1
0
        private static List <Kerberos.Sots.Data.StarMapFramework.Orbit> PopulateRandomOrbits(
            Random random,
            Kerberos.Sots.Data.StarMapFramework.Orbit parentOrbital)
        {
            List <Kerberos.Sots.Data.StarMapFramework.Orbit> orbitList = StarSystemHelper.PopulateRandomOrbitsCore(random, parentOrbital);

            orbitList.ForEach((Action <Kerberos.Sots.Data.StarMapFramework.Orbit>)(x => x.Parent = parentOrbital.Name));
            return(orbitList);
        }
Пример #2
0
        private static float CalcRadius(Kerberos.Sots.Data.StarMapFramework.Orbit orbital)
        {
            if (orbital is StarOrbit)
            {
                return(StarSystemVars.Instance.StarRadius(StellarClass.Parse((orbital as StarOrbit).StellarClass).Size));
            }
            PlanetInfo planetInfo = StarSystemHelper.InferPlanetInfo(orbital);

            if (planetInfo != null)
            {
                return(StarSystemVars.Instance.SizeToRadius(planetInfo.Size));
            }
            throw new ArgumentException("unexpected type");
        }
Пример #3
0
 private static float CalcOrbitStep(Kerberos.Sots.Data.StarMapFramework.Orbit orbital)
 {
     if (orbital is StarOrbit)
     {
         return(StarSystemVars.Instance.StarOrbitStep);
     }
     if (orbital is GasGiantLargeOrbit || orbital is GasGiantSmallOrbit)
     {
         return(StarSystemVars.Instance.GasGiantOrbitStep);
     }
     if (orbital is PlanetOrbit)
     {
         return(StarSystemVars.Instance.PlanetOrbitStep);
     }
     throw new ArgumentException("unexpected type");
 }
Пример #4
0
 public static IEnumerable <IStellarEntity> CreateOrbiters(
     Random random,
     Kerberos.Sots.Data.StarMapFramework.Orbit orbiterParams,
     bool isOrbitingStar)
 {
     if (orbiterParams.GetType() == typeof(EmptyOrbit))
     {
         return(Enumerable.Empty <IStellarEntity>());
     }
     if (orbiterParams.GetType() == typeof(StarOrbit))
     {
         return(StarSystemHelper.CreateStar(random, orbiterParams as StarOrbit));
     }
     if (orbiterParams.GetType() == typeof(ArtifactOrbit))
     {
         return(StarSystemHelper.CreateArtifact(random, orbiterParams as ArtifactOrbit));
     }
     if (orbiterParams.GetType() == typeof(GasGiantSmallOrbit))
     {
         return(StarSystemHelper.CreateGasGiantSmall(random, orbiterParams as GasGiantSmallOrbit));
     }
     if (orbiterParams.GetType() == typeof(GasGiantLargeOrbit))
     {
         return(StarSystemHelper.CreateGasGiantLarge(random, orbiterParams as GasGiantLargeOrbit));
     }
     if (orbiterParams.GetType() == typeof(MoonOrbit))
     {
         return(StarSystemHelper.CreateMoon(random, orbiterParams as MoonOrbit));
     }
     if (orbiterParams.GetType() == typeof(PlanetaryRingOrbit))
     {
         return(StarSystemHelper.CreatePlanetaryRing(random, orbiterParams as PlanetaryRingOrbit));
     }
     if (orbiterParams.GetType() == typeof(PlanetOrbit))
     {
         return(StarSystemHelper.CreatePlanet(random, orbiterParams as PlanetOrbit, isOrbitingStar));
     }
     if (orbiterParams.GetType() == typeof(AsteroidOrbit))
     {
         return(StarSystemHelper.CreateAsteroidBelt(random, orbiterParams as AsteroidOrbit));
     }
     throw new ArgumentException(string.Format("Unsupported orbit type '{0}'.", (object)orbiterParams.GetType()));
 }
Пример #5
0
 private static List <Kerberos.Sots.Data.StarMapFramework.Orbit> PopulateRandomOrbitsCore(
     Random random,
     Kerberos.Sots.Data.StarMapFramework.Orbit parentOrbital)
 {
     if (parentOrbital is StarOrbit)
     {
         StellarClass stellarClass = StellarClass.Parse((parentOrbital as StarOrbit).StellarClass);
         return(StarHelper.ChooseOrbitContents(random, stellarClass).ToList <Kerberos.Sots.Data.StarMapFramework.Orbit>());
     }
     if (parentOrbital is GasGiantLargeOrbit)
     {
         return(GasGiantHelper.ChooseOrbitContents(random).ToList <Kerberos.Sots.Data.StarMapFramework.Orbit>());
     }
     if (parentOrbital is GasGiantSmallOrbit)
     {
         return(GasGiantHelper.ChooseOrbitContents(random).ToList <Kerberos.Sots.Data.StarMapFramework.Orbit>());
     }
     return(new List <Kerberos.Sots.Data.StarMapFramework.Orbit>());
 }
Пример #6
0
        internal static Orbit SetOrbit(Random random, Kerberos.Sots.Data.StarMapFramework.Orbit orbitParent, Kerberos.Sots.Data.StarMapFramework.Orbit orbiter)
        {
            if (orbiter.OrbitNumber < 1)
            {
                throw new ArgumentOutOfRangeException(string.Format("Orbit numbers start at 1."));
            }
            float eccentricity  = orbiter.Eccentricity.HasValue ? orbiter.Eccentricity.Value : (random == null ? 0.0f : random.NextNormal(StarSystemVars.Instance.OrbitEccentricityRange));
            float num1          = orbiter.Inclination.HasValue ? orbiter.Inclination.Value : (random == null ? 0.0f : random.NextNormal(StarSystemVars.Instance.OrbitInclinationRange));
            float semiMajorAxis = StarSystemHelper.CalcOrbitRadius(orbitParent, orbiter.OrbitNumber);
            float num2          = Ellipse.CalcSemiMinorAxis(semiMajorAxis, eccentricity);

            return(new Orbit()
            {
                Parent = orbitParent,
                SemiMajorAxis = semiMajorAxis,
                SemiMinorAxis = num2,
                OrbitNumber = orbiter.OrbitNumber,
                Inclination = num1,
                Position = random.NextInclusive(0.0f, 1f)
            });
        }
Пример #7
0
 private static bool IsRandomOrbitName(Kerberos.Sots.Data.StarMapFramework.Orbit orbital)
 {
     return(string.IsNullOrWhiteSpace(orbital.Name) || orbital.Name.Contains("NewOrbit") || orbital.Name.Contains("RandomOrbital"));
 }
Пример #8
0
        public static PlanetInfo InferPlanetInfo(Kerberos.Sots.Data.StarMapFramework.Orbit orbit)
        {
            if (orbit is PlanetOrbit)
            {
                PlanetOrbit planetOrbit = orbit as PlanetOrbit;
                Random      safeRandom  = App.GetSafeRandom();
                float       num1        = planetOrbit.Size.HasValue ? (float)planetOrbit.Size.Value : (float)safeRandom.Next(1, 10);
                string      str         = !string.IsNullOrEmpty(planetOrbit.PlanetType) ? planetOrbit.PlanetType : (safeRandom.NextNormal(0.0, 1.0) > 0.75 ? StellarBodyTypes.Normal : StellarBodyTypes.SpecialTerrestrialTypes[safeRandom.Next(0, ((IEnumerable <string>)StellarBodyTypes.SpecialTerrestrialTypes).Count <string>())]);
                float       num2        = planetOrbit.Suitability.HasValue ? planetOrbit.Suitability.Value : (float)safeRandom.Next(-1000, 1000);
                int         num3        = planetOrbit.Biosphere.HasValue ? planetOrbit.Biosphere.Value : safeRandom.Next(500, 1500);
                int         num4        = planetOrbit.Resources.HasValue ? planetOrbit.Resources.Value : safeRandom.Next(1500, 8000);
                return(new PlanetInfo()
                {
                    Size = num1,
                    Type = str,
                    Suitability = num2,
                    Biosphere = num3,
                    Resources = num4
                });
            }
            if (orbit is MoonOrbit)
            {
                MoonOrbit moonOrbit  = orbit as MoonOrbit;
                Random    safeRandom = App.GetSafeRandom();
                float     num1       = moonOrbit.Size.HasValue ? moonOrbit.Size.Value : (float)(0.100000001490116 + (double)safeRandom.NextSingle() * 0.400000005960464);
                int       num2       = safeRandom.Next(1000, 7000);
                return(new PlanetInfo()
                {
                    Size = num1,
                    Resources = num2,
                    Type = StellarBodyTypes.Barren
                });
            }
            if (orbit is GasGiantSmallOrbit)
            {
                GasGiantSmallOrbit gasGiantSmallOrbit = orbit as GasGiantSmallOrbit;
                Random             safeRandom         = App.GetSafeRandom();
                float num = gasGiantSmallOrbit.Size.HasValue ? gasGiantSmallOrbit.Size.Value : (float)safeRandom.Next(13, 18);
                return(new PlanetInfo()
                {
                    Size = num,
                    Type = StellarBodyTypes.Gaseous
                });
            }
            if (!(orbit is GasGiantLargeOrbit))
            {
                return((PlanetInfo)null);
            }
            GasGiantLargeOrbit gasGiantLargeOrbit = orbit as GasGiantLargeOrbit;
            Random             safeRandom1        = App.GetSafeRandom();

            if (!gasGiantLargeOrbit.Size.HasValue)
            {
                safeRandom1.Next(19, 30);
            }
            else
            {
                double num5 = (double)gasGiantLargeOrbit.Size.Value;
            }
            return(new PlanetInfo()
            {
                Size = gasGiantLargeOrbit.Size.Value,
                Type = StellarBodyTypes.Gaseous
            });
        }
Пример #9
0
 public static float CalcOrbitRadius(Kerberos.Sots.Data.StarMapFramework.Orbit orbitParent, int orbitNumber)
 {
     return(Orbit.CalcOrbitRadius(StarSystemHelper.CalcRadius(orbitParent), StarSystemHelper.CalcOrbitStep(orbitParent), orbitNumber));
 }
Пример #10
0
        public static StarSystem CreateStarSystem(Random random, Matrix worldTransform, Kerberos.Sots.Data.StarMapFramework.StarSystem systemParams, LegacyTerrain parentTerrain)
        {
            StellarClass stellarClass = StarHelper.ResolveStellarClass(random, systemParams.Type, systemParams.SubType, systemParams.Size);

            Kerberos.Sots.Data.StarMapFramework.StarOrbit starOrbit = new StarOrbit();
            starOrbit.Name         = systemParams.Name;
            starOrbit.StellarClass = stellarClass.ToString();
            int randomOrbital = 1;
            List <Kerberos.Sots.Data.StarMapFramework.Orbit> list = new List <Kerberos.Sots.Data.StarMapFramework.Orbit>();

            list.Add(starOrbit);
            for (int i = 0; i < list.Count; i++)
            {
                Kerberos.Sots.Data.StarMapFramework.Orbit thisOrbital = list[i];
                if (!(thisOrbital is EmptyOrbit))
                {
                    List <Kerberos.Sots.Data.StarMapFramework.Orbit> predefinedOrbitals = new List <Kerberos.Sots.Data.StarMapFramework.Orbit>();
                    predefinedOrbitals.AddRange(systemParams.Orbits.Where(delegate(Kerberos.Sots.Data.StarMapFramework.Orbit x)
                    {
                        if (string.IsNullOrEmpty(x.Parent))
                        {
                            return(thisOrbital is StarOrbit);
                        }
                        return(x.Parent == thisOrbital.Name);
                    }));
                    if (thisOrbital is StarOrbit)
                    {
                        StarSystemHelper.AssignOrbitNumbers(stellarClass, predefinedOrbitals);
                    }
                    else
                    {
                        int orbitNumber = 1;
                        predefinedOrbitals.ForEach(delegate(Kerberos.Sots.Data.StarMapFramework.Orbit x)
                        {
                            x.OrbitNumber = orbitNumber++;
                        });
                    }
                    List <Kerberos.Sots.Data.StarMapFramework.Orbit> list2 = StarSystemHelper.PopulateRandomOrbits(random, thisOrbital);
                    list2.RemoveAll((Kerberos.Sots.Data.StarMapFramework.Orbit x) => predefinedOrbitals.Any((Kerberos.Sots.Data.StarMapFramework.Orbit y) => y.OrbitNumber == x.OrbitNumber));
                    list2.ForEach(delegate(Kerberos.Sots.Data.StarMapFramework.Orbit x)
                    {
                        x.Name = string.Format("RandomOrbital{0}", ++randomOrbital);
                    });
                    list.AddRange(predefinedOrbitals);
                    list.AddRange(list2);
                }
            }
            StarSystem starSystem = new StarSystem();

            starSystem.Params          = systemParams;
            starSystem.WorldTransform  = worldTransform;
            starSystem.DisplayName     = systemParams.Name;
            starSystem.IsStartPosition = systemParams.isStartLocation;
            starSystem.WorldTransform  = worldTransform;
            starSystem.Terrain         = parentTerrain;
            foreach (Kerberos.Sots.Data.StarMapFramework.Orbit orbit in list)
            {
                bool isOrbitingStar        = orbit.Parent == starOrbit.Name;
                List <IStellarEntity> objs = new List <IStellarEntity>(StarSystemHelper.CreateOrbiters(random, orbit, isOrbitingStar));
                starSystem.AddRange(objs);
            }
            foreach (IStellarEntity stellarEntity in starSystem.Objects)
            {
                IStellarEntity stellarEntity2 = StarSystemHelper.FindOrbitParent(starSystem, stellarEntity);
                if (stellarEntity2 != null)
                {
                    stellarEntity.Orbit = StarSystem.SetOrbit(random, stellarEntity2.Params, stellarEntity.Params);
                }
            }
            return(starSystem);
        }