/// <summary> /// This function creates the sector, and initiates it. /// </summary> /// <param name="s">Our sector</param> internal void InitateSector(Sector s) { if (SystemsCreated) { //uhm.. we have one already. MessageBoxResult res = MessageBox.Show("This will reset the sector. Are you OK with that?", "Sector Initalized", MessageBoxButton.YesNo); if (res == MessageBoxResult.Yes) ResetSector(s); if (res == MessageBoxResult.No) return; //do nothing. } //first set the sector name s.SectorName = PrgSettings.GetSectorPrefix() + VelvetBag.rng(1, PrgSettings.GetSectorMaxNum()); //get values double minStellarDistance = PrgSettings.GetMinStellarDistance() * PrgSettings.GetLightYearResolution(); double stellarDensity = PrgSettings.GetStellarDensity(); bool isTwoDGrid = !(PrgSettings.GridTypeIs3D()); int gridLimit = PrgSettings.GetLightYearResolution() * PrgSettings.GetSectorSizePerSide(); //do any alterations now. if (isTwoDGrid) stellarDensity = stellarDensity * PrgSettings.GetTwoDMultiplication(); //list of points time List<Point3D> ourPoints = new List<Point3D>(); //Fixed an intersting bug. Always one under. Now using Ceiling... int numberOfStars = (int)Math.Ceiling(Math.Pow(PrgSettings.GetSectorSizePerSide(), 3) * stellarDensity); for (int i = 0; i < numberOfStars; i++) { Point3D newPoint = new Point3D(0, 0, 0); //generic point. do { newPoint.X = VelvetBag.rng(1, gridLimit); newPoint.Y = VelvetBag.rng(1, gridLimit); newPoint.Z = VelvetBag.rng(1, gridLimit); } while (((from c in ourPoints where c.GetDistance(newPoint) <= minStellarDistance select c).Any())); ourPoints.Add(new Point3D(newPoint.X, newPoint.Y, newPoint.Z)); } //add the point to the systems and display information. foreach (Point3D p in ourPoints) { s.StarfieldData.Add(new Point3D(p.X, p.Y, p.Z)); s.SectorSystems.Add(new StellarSystem(p, StellarCatalog.newUniqueNum(), 0.0)); } s.UpdateNumberOfSystems(); SystemsCreated = true; //done with system creation }
/// <summary> /// This resets the sector. /// </summary> internal void ResetSector(Sector s) { //reset the sector s.Reset(); //reset internal trackers this.StellarCatalog.ResetCatalog(); //finally, reset all indicators this.SystemsCreated = false; /* this.SystemsInitiated = false; this.OrbitsCreated = false; this.PlanetsInitiated = false; */ }