示例#1
0
        public DBCommandResult SaveStar(Star s)
        {
            DBCommandResult res = new DBCommandResult();
            try
            {
                var stars = db.GetCollection<Star>("Stars");
                if (s.IsLoaded)
                    res.Tag = stars.ReplaceOne(new BsonDocument("_id", s._id), s, new UpdateOptions { IsUpsert = true });
                else
                {
                    stars.InsertOne(s, new InsertOneOptions { BypassDocumentValidation = false });
                    res.Tag = s;
                }

                s.IsLoaded = s.IsSaved = true;

                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
示例#2
0
 public DBCommandResult GetStarOrbitalBodies(Star s)
 {
     if (s != null)
         return GetStarOrbitalBodies(s._id);
     else
         return new DBCommandResult() { ResultCode = -1, ResultMsg = "Null Star specified as argument." };
 }
示例#3
0
 public StarHelper(Star s)
 {
     //			this._dh = new MySqlDBHelper (SensitiveData.ConnectionString);
     this._mdh = new MongoDBHelper();
     this.Star = s;
     this.log = new Log.Logger("HOO.SvcLib", typeof(StarHelper));
 }
示例#4
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            u = new Universe();
            u.Name = "Test universe";
            u.Descrip = "For testing purposes only...";
            for (int i = 0; i < nudGal.Value; i++)
            {
                Galaxy g = new Galaxy((int)nudGalX.Value, (int)nudGalY.Value, (int)nudGalZ.Value);
                g.Name = "Test Milky Way";
                int j = (int)nudStars.Value;
                while (j > 0)
                {
                    Star s = new Star(g);
                    s.StarSystemName = "Alpha Test";
                    if (g.AddStar(s, ConstantParameters.MinDistanceBetweenStars))
                    {
                        int orbits = MrRandom.rnd.Next(ConstantParameters.MaxOrbitalBodiesForStar);
                        List<int> freeOrbits = new List<int>();
                        freeOrbits.AddRange(Orbits);
                        for (int k = 0; k < orbits; k++)
                        {
                            int bodyType = MrRandom.rnd.Next(3);

                            switch (bodyType)
                            {
                                case 0:
                                    Planet p = new Planet(s._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)];
                                    freeOrbits.Remove(p.OrbitNo);
                                    s.OrbitalBodies.Add(p);
                                    break;
                            case 1:
                                GasGiant gg = new GasGiant (s._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)];
                                    freeOrbits.Remove(gg.OrbitNo);
                                    s.OrbitalBodies.Add(gg);
                                    break;
                                case 2:
                                    AsteroidBelt a = new AsteroidBelt(s._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)];
                                    freeOrbits.Remove(a.OrbitNo);
                                    s.OrbitalBodies.Add(a);
                                    break;
                            }
                        }
                        j = j - 1;
                    }
                }
                u.Galaxies.Add(g);
            }
            ShowStats();
        }
示例#5
0
        public DBCommandResult LoadGalaxy(Galaxy g)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_GetGalaxyById", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spGalID = new MySqlParameter("pGalId", g.OBID);
            com.Parameters.Add(spGalID);

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                g.OBID = Convert.ToInt32(dr["OBID"]);
                g.Name = Convert.ToString(dr["Name"]);
                g.DimensionX = Convert.ToInt32(dr["DimX"]);
                g.DimensionY = Convert.ToInt32(dr["DimY"]);
                g.DimensionZ = Convert.ToInt32(dr["DimZ"]);

                g.Attributes = new List<OAttribute>();
                //g.Attributes.ParentObject = g;
                //g.Attributes.Load(LoadAttributes(ds.Tables[1]));

                foreach (DataRow sRow in ds.Tables[2].Rows)
                {
                    Star s = new Star();
                    s.GalaxyId = g._id;
                    s.OBID = Convert.ToInt32(sRow["OBID"]);
                    s.Coordinates= new HOO.Core.Model.Configuration.Point3D();
                    s.Class = ((StarClass)Convert.ToInt32(sRow["Class"]));
                    s.TemperatureLevel = Convert.ToInt32(sRow["TempLvl"]);
                    s.Size = ((StarSize)Convert.ToInt32(sRow["Size"]));
                    s.StarSystemName = Convert.ToString(sRow["SystemName"]);
                    s.Coordinates.X = Convert.ToInt32(sRow["X"]);
                    s.Coordinates.Y = Convert.ToInt32(sRow["Y"]);
                    s.Coordinates.Z = Convert.ToInt32(sRow["Z"]);

                    g.Stars.Add(s);
                }

                res.Tag = g;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
示例#6
0
文件: Galaxy.cs 项目: GSazheniuk/HOO
        public bool AddStar(Star s, double minDistance)
        {
            int x = ((MrRandom.rnd.Next(2) == 0) ? 1 : -1) * MrRandom.rnd.Next(this.DimensionX);
            int y = ((MrRandom.rnd.Next(2) == 0) ? 1 : -1) * MrRandom.rnd.Next(this.DimensionY);
            int z = ((MrRandom.rnd.Next(2) == 0) ? 1 : -1) * MrRandom.rnd.Next(this.DimensionZ);

                double d = Math.Pow(x, 2) / Math.Pow(this.DimensionX, 2) + Math.Pow(y, 2) / Math.Pow(this.DimensionY, 2) + Math.Pow(z, 2) / Math.Pow(this.DimensionZ, 2);
                double dc = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2) + Math.Pow(z, 2));

                if (d <= 1 && dc > minDistance)
                {
                    if (!Stars.Exists(p => Math.Sqrt(Math.Pow(x - p.Coordinates.X, 2) + Math.Pow(y - p.Coordinates.Y, 2) + Math.Pow(z - p.Coordinates.Z, 2)) <= minDistance))
                    {
                        s.Coordinates = new Point3D {X = x, Y = y, Z = z};
                        Stars.Add(s);
                        return true;
                    }
                }
            return false;
        }
示例#7
0
        public DBCommandResult GetStarOrbitalBodies(Star s)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_GetStarOrbitalBodies", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spStarId = new MySqlParameter("pStarId", s.OBID);
            com.Parameters.Add(spStarId);

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                s.OrbitalBodies = new List<StarOrbitalBody>();

                foreach(DataRow dr in ds.Tables[0].Rows)
                {
                    switch (Convert.ToInt32(dr["BodyType"]))
                    {
                    case 1:
                        Planet p = new Planet(s._id);
                        p.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                        p.Size = (PlanetSize)Convert.ToInt32(dr["Size"]);
                        p.Type = (PlanetType)Convert.ToInt32(dr["Class"]);
                        p.OBID = Convert.ToInt32(dr["OBID"]);
                        s.OrbitalBodies.Add(p);
                        break;
                    case 2:
                        GasGiant g = new GasGiant(s._id);
                        g.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                        g.Size = (GasGiantSize)Convert.ToInt32(dr["Size"]);
                        g.Class = (GasGiantClass)Convert.ToInt32(dr["Class"]);
                        g.OBID = Convert.ToInt32(dr["OBID"]);
                        s.OrbitalBodies.Add(g);
                        break;
                    case 3:
                        AsteroidBelt a = new AsteroidBelt(s._id);
                        a.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                        a.Density = (AsteroidDensity)Convert.ToInt32(dr["Size"]);
                        a.Type = (AsteroidType)Convert.ToInt32(dr["Class"]);
                        a.OBID = Convert.ToInt32(dr["OBID"]);
                        s.OrbitalBodies.Add(a);
                        break;
                    }
                }

                res.ResultCode = 0;
                res.ResultMsg = "Ok";
                res.Tag = s;
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
示例#8
0
        public DBCommandResult AddStar(Star s)
        {
            DBCommandResult res = new DBCommandResult();
            string pref = "";
            string suff = "";

            switch (MrRandom.rnd.Next (4)) {
            case 0:
                pref = "";
                suff = "";
                break;
            case 1:
                pref = prefixes[MrRandom.rnd.Next(prefixes.Length)];
                suff = "";
                break;
            case 2:
                pref = "";
                suff = suffixes[MrRandom.rnd.Next(suffixes.Length)];
                break;
            case 3:
                pref = prefixes[MrRandom.rnd.Next(prefixes.Length)];
                suff = suffixes[MrRandom.rnd.Next(suffixes.Length)];
                break;
            }

            if (pref != "") {
            int x = MrRandom.rnd.Next (10);
                switch (x) {
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                    pref = pref + "-" + (x + 1).ToString ();
                    break;
                }
                pref += " ";
            }

            if (suff != "")
                suff = " " + suff;

            MySqlCommand com = new MySqlCommand("ADM_AddStar", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;

            MySqlParameter spGalaxyId = new MySqlParameter("pGalaxyId", s.GalaxyId);
            MySqlParameter spX = new MySqlParameter("pX", s.Coordinates.X);
            MySqlParameter spY = new MySqlParameter("pY", s.Coordinates.Y);
            MySqlParameter spZ = new MySqlParameter("pZ", s.Coordinates.Z);
            MySqlParameter spClass = new MySqlParameter("pClass", s.Class);
            MySqlParameter spSize = new MySqlParameter("pSize", s.Size);
            MySqlParameter spTempLvl = new MySqlParameter("pTempLvl", s.TemperatureLevel);

            MySqlParameter spPrefix = new MySqlParameter("pPrefix", pref);
            MySqlParameter spSuffix = new MySqlParameter("pSuffix", suff);

            com.Parameters.AddRange(new MySqlParameter[] { spClass, spGalaxyId, spSize, spTempLvl, spX, spY, spZ,spPrefix, spSuffix });

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                Star rs = new Star();
                rs.OBID = Convert.ToInt32(dr["OBID"]);
                rs.GalaxyId = s.GalaxyId;
                rs.StarSystemName = Convert.ToString(dr["SystemName"]);
                rs.Coordinates = new Core.Model.Configuration.Point3D();
                rs.Coordinates.X = Convert.ToInt32(dr["X"]);
                rs.Coordinates.Y = Convert.ToInt32(dr["Y"]);
                rs.Coordinates.Z = Convert.ToInt32(dr["Z"]);
                rs.Class = (StarClass)Convert.ToInt32(dr["Class"]);
                rs.Size = (StarSize)Convert.ToInt32(dr["Size"]);
                rs.TemperatureLevel = Convert.ToInt32(dr["TempLvl"]);
                res.Tag = rs;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
            }

            return res;
        }
示例#9
0
        private void LoadStarData()
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch ();
            sw.Start ();
            if (this.ActiveUniverse != null && this.ActiveUniverse.Galaxies != null) {
                //				var g = ActiveUniverse.Galaxies.Single (x => x.OBID == _gid);
                //Galaxy g = new Galaxy();
                //List<Star> stars = g.Stars;
                //s = stars.ToArray () [MrRandom.rnd.Next (stars.Count)];
                s = Channel.GenerateNewStar(ActiveUniverse._id, this._gid);
                ltStarName.Text = String.Format("<font style='color:{0}'>{1}</font>", _starColors[(int)s.Class], s.StarSystemName);
                ltStarClass.Text = s.ClassName;
                ltX.Text = s.Coordinates.X.ToString ();
                ltY.Text = s.Coordinates.Y.ToString ();
                ltZ.Text = s.Coordinates.Z.ToString ();
                imgStar.Src = String.Format("Images/Stars/{0}.png", s.Class);

                ltUniverse.Text = ActiveUniverse.Name;
                ltUniverseTick.Text = ActiveUniverse.CurrentTick.ToString ();
                ltUniverseTurn.Text = ActiveUniverse.CurrentTurn.ToString ();
                ltUniversePeriod.Text = ActiveUniverse.CurrentPeriod.ToString ();
                ltGalaxy.Text = "Unknown";//g.Name;

                gvNearestStars.DataSource = ActiveUniverse.Galaxies[0].Stars.Where (p => p._id != s._id).OrderBy (p => Math.Sqrt (Math.Pow (s.Coordinates.X - p.Coordinates.X, 2) + Math.Pow (s.Coordinates.Y - p.Coordinates.Y, 2) + Math.Pow (s.Coordinates.Z - p.Coordinates.Z, 2))).Take (5);
                gvNearestStars.DataBind ();
                /*
                  if (!s.IsLoaded) {
                      _sh = new StarHelper (s);
                      _sh.RefreshOrbitalBodies ();
                      StarOrbitalBodyHelper sobh = new StarOrbitalBodyHelper ();
                      foreach (StarOrbitalBody sob in s.OrbitalBodies) {
                          sobh.OrbitalBody = sob;
                          sobh.LoadOrbitalBody ();
                      }
                  }
                */
                StarOrbitalBody[] sobs = new StarOrbitalBody[10];
                foreach (StarOrbitalBody sob in s.OrbitalBodies) {
                    sobs [sob.OrbitNo] = sob;
                }
                gvOrbits.DataSource = sobs;
                gvOrbits.DataBind ();
            }
            sw.Stop ();
            TimeSpan ts = sw.Elapsed;
            ltLoadTime.Text = String.Format ("loaded in {0}ms", ts);
        }
示例#10
0
        public DBCommandResult AddStar(Star s)
        {
            DBCommandResult res = new DBCommandResult();

            SqlCommand com = new SqlCommand("ADM.AddStar", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;

            SqlParameter spGalaxyId = new SqlParameter("@GalaxyId", s.GalaxyId);
            SqlParameter spSystemName = new SqlParameter("@SystemName", s.StarSystemName);
            SqlParameter spX = new SqlParameter("@X", s.Coordinates.X);
            SqlParameter spY = new SqlParameter("@Y", s.Coordinates.Y);
            SqlParameter spZ = new SqlParameter("@Z", s.Coordinates.Z);
            SqlParameter spClass = new SqlParameter("@Class", s.Class);
            SqlParameter spSize = new SqlParameter("@Size", s.Size);
            SqlParameter spTempLvl = new SqlParameter("@TempLvl", s.TemperatureLevel);

            com.Parameters.AddRange(new SqlParameter[] { spClass, spGalaxyId, spSize, spSystemName, spTempLvl, spX, spY, spZ });

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                Star rs = new Star();
                rs.OBID = Convert.ToInt32(dr["OBID"]);
                rs.GalaxyId = s.GalaxyId;
                rs.StarSystemName = Convert.ToString(dr["SystemName"]);
                rs.Coordinates = new Core.Model.Configuration.Point3D();
                rs.Coordinates.X = Convert.ToInt32(dr["X"]);
                rs.Coordinates.Y = Convert.ToInt32(dr["Y"]);
                rs.Coordinates.Z = Convert.ToInt32(dr["Z"]);
                rs.Class = (StarClass)Convert.ToInt32(dr["Class"]);
                rs.Size = (StarSize)Convert.ToInt32(dr["Size"]);
                rs.TemperatureLevel = Convert.ToInt32(dr["TempLvl"]);
                res.Tag = rs;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, ex.InnerException.Message);
            }

            return res;
        }
示例#11
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;
        }
示例#12
0
        public void SaveStar(Star s)
        {
            DBCommandResult res = _mdh.SaveStar(s);

            if (res.ResultCode != 0)
            {
                log.Error(new Exception(res.ResultMsg));
            }
        }
示例#13
0
 public void RefreshOrbitalBodies()
 {
     DBCommandResult res = _dh.GetStarOrbitalBodies (this.Star);
     if (res.ResultCode == 0) {
         this.Star = (Star)res.Tag;
         this.Star.IsLoaded = this.Star.IsSaved = true;
         if (this.Star.Attributes.Count == 0)
             InitDefaultParameters ();
         //ELSE add missing attributes, if any exists.
     }
 }
示例#14
0
 public void LoadStar(Star s)
 {
     LoadStar(s._id);
 }