Exemple #1
0
        public static StellarClass ResolveStellarClass(
            Random random,
            string typeStr,
            string subTypeStr,
            string sizeStr)
        {
            StellarType type;

            if (!StellarClass.TryParseType(typeStr, out type))
            {
                type = StarHelper.ChooseStellarType(random);
            }
            int subtype;

            if (!StellarClass.TryParseSubType(subTypeStr, out subtype))
            {
                subtype = StarHelper.ChooseStellarSubType(random);
            }
            StellarSize size;

            if (!StellarClass.TryParseSize(sizeStr, out size))
            {
                size = StarHelper.ChooseStellarSize(random, type, subtype);
            }
            return(new StellarClass(type, subtype, size));
        }
Exemple #2
0
 private static Vector4 CalcColor(
     StellarType type,
     int subtype,
     KeyValuePair <StellarType, Vector4>[] colorTable)
 {
     return(Vector4.Lerp(StarHelper.CalcColor(type, colorTable), StarHelper.CalcColor((StellarType)Math.Min(6, (int)(type + 1)), colorTable), (float)subtype / 10f));
 }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        public static StellarClass ChooseStellarClass(Random random)
        {
            StellarType type    = StarHelper.ChooseStellarType(random);
            int         subtype = StarHelper.ChooseStellarSubType(random);
            StellarSize size    = StarHelper.ChooseStellarSize(random, type, subtype);

            return(new StellarClass(type, subtype, size));
        }
Exemple #5
0
        public static int CalcMinOrbit(StellarClass value)
        {
            int num = StarHelper.CalcMinOrbitCore(value);

            if (num > 1)
            {
                StarSystem.Trace("Invalidating orbits below {0} due to size and heat of {1} star.", (object)num, (object)value);
            }
            return(num);
        }
Exemple #6
0
        private static void AssignOrbitNumbers(StellarClass stellarClass, List <Kerberos.Sots.Data.StarMapFramework.Orbit> orbitals)
        {
            int orbitNumber = StarHelper.CalcMinOrbit(stellarClass);

            foreach (Kerberos.Sots.Data.StarMapFramework.Orbit orbit in orbitals.Where <Kerberos.Sots.Data.StarMapFramework.Orbit>((Func <Kerberos.Sots.Data.StarMapFramework.Orbit, bool>)(x => x.OrbitNumber < 1)))
            {
                while (orbitals.Any <Kerberos.Sots.Data.StarMapFramework.Orbit>((Func <Kerberos.Sots.Data.StarMapFramework.Orbit, bool>)(x => x.OrbitNumber == orbitNumber)))
                {
                    ++orbitNumber;
                }
                orbit.OrbitNumber = orbitNumber;
                ++orbitNumber;
            }
        }
Exemple #7
0
        private static Range <int> ChooseOrbits(Random random, StellarClass stellarClass)
        {
            Range <int> range = new Range <int>(0, 0);
            int         num   = StarHelper.ChooseOrbitCount(random, stellarClass);

            if (num <= 0)
            {
                return(range);
            }
            int max = num;
            int min = StarHelper.CalcMinOrbit(stellarClass);

            if (min > max)
            {
                return(range);
            }
            return(new Range <int>(min, max));
        }
Exemple #8
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>());
 }
Exemple #9
0
 public static Vector4 CalcModelColor(StellarClass stellarClass)
 {
     return(StarHelper.CalcColor(stellarClass.Type, stellarClass.SubType, StarHelper.ModelColorTable));
 }
Exemple #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);
        }