コード例 #1
0
ファイル: StarHelper.cs プロジェクト: zerk-js/SOTSII-SOS
        public static IEnumerable <Kerberos.Sots.Data.StarMapFramework.Orbit> ChooseOrbitContents(
            Random random,
            StellarClass stellarClass)
        {
            Range <int> orbits            = StarHelper.ChooseOrbits(random, stellarClass);
            int         asteroidBeltCount = 0;

            for (int orbitNumber = 1; orbitNumber <= orbits.Max; ++orbitNumber)
            {
                OrbitContents orbitContents = OrbitContents.Empty;
                if (orbitNumber >= orbits.Min)
                {
                    bool flag = false;
                    while (!flag)
                    {
                        flag          = true;
                        orbitContents = WeightedChoices.Choose <OrbitContents>((double)StarHelper.CalcOrbitContentRoll(random, orbitNumber), StarHelper.OrbitContentWeights);
                        if (orbitContents == OrbitContents.AsteroidBelt && asteroidBeltCount >= 2)
                        {
                            flag = false;
                        }
                    }
                }
                if (orbitContents == OrbitContents.AsteroidBelt)
                {
                    ++asteroidBeltCount;
                }
                Kerberos.Sots.Data.StarMapFramework.Orbit orbiter = StarSystemHelper.CreateOrbiterParams(orbitContents);
                orbiter.OrbitNumber = orbitNumber;
                yield return(orbiter);
            }
        }
コード例 #2
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);
        }
コード例 #3
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");
        }
コード例 #4
0
 public static IEnumerable <IStellarEntity> CreateMoon(
     Random random,
     MoonOrbit orbiterParams)
 {
     if (!orbiterParams.Size.HasValue)
     {
         orbiterParams.Size = new float?(StarSystemHelper.ChooseSize(random, StarSystemVars.Instance.MoonMinRadius, StarSystemVars.Instance.MoonMaxRadius));
     }
     return((IEnumerable <IStellarEntity>) new IStellarEntity[1]
     {
         (IStellarEntity) new StellarEntity()
         {
             Params = (Kerberos.Sots.Data.StarMapFramework.Orbit)orbiterParams
         }
     });
 }
コード例 #5
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()));
 }
コード例 #6
0
ファイル: StarSystem.cs プロジェクト: zerk-js/SOTSII-SOS
        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
        public static IEnumerable <Kerberos.Sots.Data.StarMapFramework.Orbit> ChooseOrbitContents(
            Random random)
        {
            Orbits orbits = WeightedChoices.Choose <Orbits>(random.NextDouble(), GasGiantHelper.OrbitCountWeights);
            int    count  = StarSystemHelper.GetOrbitCount(orbits);

            if (count >= 0)
            {
                for (int orbitNumber = 1; orbitNumber <= count; ++orbitNumber)
                {
                    OrbitContents chosenContents = WeightedChoices.Choose <OrbitContents>(random.NextDouble(), GasGiantHelper.OrbitContentWeights);
                    Kerberos.Sots.Data.StarMapFramework.Orbit orbiter = StarSystemHelper.CreateOrbiterParams(chosenContents);
                    orbiter.OrbitNumber = orbitNumber;
                    yield return(orbiter);
                }
            }
            else if (orbits == Orbits.Ring)
            {
                int ringOrbitNumber = 1;
                Kerberos.Sots.Data.StarMapFramework.Orbit orbiter = StarSystemHelper.CreateOrbiterParams(OrbitContents.PlanetaryRing);
                orbiter.OrbitNumber = ringOrbitNumber;
                yield return(orbiter);
            }
        }
コード例 #8
0
 public static float CalcOrbitRadius(Kerberos.Sots.Data.StarMapFramework.Orbit orbitParent, int orbitNumber)
 {
     return(Orbit.CalcOrbitRadius(StarSystemHelper.CalcRadius(orbitParent), StarSystemHelper.CalcOrbitStep(orbitParent), orbitNumber));
 }
コード例 #9
0
 public static IEnumerable <IStellarEntity> CreatePlanet(
     Random random,
     PlanetOrbit orbiterParams,
     bool isOrbitingStar)
 {
     if (!orbiterParams.Size.HasValue)
     {
         orbiterParams.Size = !isOrbitingStar ? new int?(random.NextInclusive(StarSystemVars.Instance.HabitalMoonMinSize, StarSystemVars.Instance.HabitalMoonMaxSize)) : new int?((int)StarSystemHelper.ChooseSize(random, StarSystemVars.Instance.PlanetMinRadius, StarSystemVars.Instance.PlanetMaxRadius));
     }
     return((IEnumerable <IStellarEntity>) new IStellarEntity[1]
     {
         (IStellarEntity) new StellarEntity()
         {
             Params = (Kerberos.Sots.Data.StarMapFramework.Orbit)orbiterParams
         }
     });
 }
コード例 #10
0
 public static float CalcOrbitStep(IStellarEntity orbitParent)
 {
     return(StarSystemHelper.CalcOrbitStep(orbitParent.Params));
 }
コード例 #11
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);
        }