Ejemplo n.º 1
0
        public Star GenerateNewStar(Galaxy g)
        {
            Star s = new Star();
            s._id = g.Stars.Count;

            while (!g.AddStar(s, ConstantParameters.MinDistanceBetweenStars))
            {

            }

            s.StarSystemName = this.GenerateStarName();
            StarOrbitalBodyHelper sobHelper = new StarOrbitalBodyHelper();

            //s.Coordinates = new Point3D() { X = MrRandom.rnd.Next(1000), Y = MrRandom.rnd.Next(800), Z = MrRandom.rnd.Next(600) };
            int orbits = MrRandom.rnd.Next(ConstantParameters.MaxOrbitalBodiesForStar);
            s.OrbitalIDs = new long[orbits];
            List<int> freeOrbits = new List<int>();
            freeOrbits.AddRange(new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            for (int k = 0; k < orbits; k++)
            {
                int bodyType = MrRandom.rnd.Next(3);

                switch (bodyType)
                {
                    case 0:
                        Planet p = new Planet(s._id);
                        p._id = 10 * s._id + s.OrbitalBodies.Count;
                        s.OrbitalIDs[k] = p._id;
                        p.Size = (PlanetSize)MrRandom.rnd.Next((int)PlanetSize.MrRandom);
                        p.Type = (PlanetType)MrRandom.rnd.Next((int)PlanetType.MrRandom);
                        p.OrbitNo = freeOrbits[MrRandom.rnd.Next(freeOrbits.Count)];
                        p.StarSystemName = s.StarSystemName;
                        freeOrbits.Remove(p.OrbitNo);
                        s.OrbitalBodies.Add(p);
                        sobHelper.OrbitalBody = p;
                        break;
                    case 1:
                        GasGiant gg = new GasGiant(s._id);
                        gg._id = 10 * s._id + s.OrbitalBodies.Count;
                        s.OrbitalIDs[k] = gg._id;
                        gg.Class = (GasGiantClass)MrRandom.rnd.Next((int)GasGiantClass.MrRandom);
                        gg.Size = (GasGiantSize)MrRandom.rnd.Next((int)GasGiantSize.MrRandom);
                        gg.OrbitNo = freeOrbits[MrRandom.rnd.Next(freeOrbits.Count)];
                        gg.StarSystemName = s.StarSystemName;
                        freeOrbits.Remove(gg.OrbitNo);
                        s.OrbitalBodies.Add(gg);
                        sobHelper.OrbitalBody = gg;
                        break;
                    case 2:
                        AsteroidBelt a = new AsteroidBelt(s._id);
                        a._id = 10 * s._id + s.OrbitalBodies.Count;
                        s.OrbitalIDs[k] = a._id;
                        a.Density = (AsteroidDensity)MrRandom.rnd.Next((int)AsteroidDensity.MrRandom);
                        a.Type = (AsteroidType)MrRandom.rnd.Next((int)AsteroidType.MrRandom);
                        a.OrbitNo = freeOrbits[MrRandom.rnd.Next(freeOrbits.Count)];
                        a.StarSystemName = s.StarSystemName;
                        freeOrbits.Remove(a.OrbitNo);
                        s.OrbitalBodies.Add(a);
                        sobHelper.OrbitalBody = a;
                        break;
                }
                sobHelper.Save();
            }

            SaveStar(s);
            this.Star = s;
            return s;
        }
Ejemplo n.º 2
0
        public void Save()
        {
            if (this.Universe.IsLoaded && !this.Universe.IsSaved) {
                DBCommandResult res = _dh.SaveUniverse (Universe);
                if (res.ResultCode == 0)
                    this.Universe.IsSaved = true;
            }

            if (this.Universe.Galaxies.Exists (g => g.Stars.Exists (s => s.OrbitalBodies.Exists (ob => !ob.IsSaved)))) {
                Galaxy gal = this.Universe.Galaxies.First (g => g.Stars.Exists (s => s.OrbitalBodies.Exists (ob => !ob.IsSaved)));
                Star st = gal.Stars.First (s => s.OrbitalBodies.Exists (ob => !ob.IsSaved));
                StarOrbitalBody sob = st.OrbitalBodies.First (ob => !ob.IsSaved);
                StarOrbitalBodyHelper sobh = new StarOrbitalBodyHelper (sob);
                sobh.Save ();
            }
        }