/// <summary> /// This method should receive the Universe to add Points of Interest to and a set of POIDefaultSettings /// /// Default values are handled in POICreation.AddPOI /// </summary> /// <param name="universe"></param> /// <param name="poiDefaultSettings"></param> /// <returns> /// Return the newly edited Universe /// </returns> /// <exception cref="FileNotFoundException"></exception> public Universe CreatePoi(Universe universe, PoiDefaultSettings poiDefaultSettings) { // If there are no Planets or Locations for the Problems to be tied to then throw an exception if (universe.Stars == null || universe.Stars.Count == 0) { throw new FileNotFoundException("No locations have been loaded."); } // Set the Universe to the Universe return from ProblemCreation.AddProblems and serialize/return it universe = new PoiCreation().AddPoi(universe, poiDefaultSettings, PoiData); SerializeData(universe); return(universe); }
public Universe AddPoi(Universe universe, PoiDefaultSettings poiDefaultSettings, PoiData poiData) { universe.PointsOfInterest ??= new List <PointOfInterest>(); var starId = string.IsNullOrEmpty(poiDefaultSettings.StarId) ? null : poiDefaultSettings.StarId; if (starId == null) { foreach (var star in universe.Stars) { var max = poiDefaultSettings.PoiRange == null || poiDefaultSettings.PoiRange.Length == 0 || poiDefaultSettings.PoiRange[0] == -1 || poiDefaultSettings.PoiRange[1] == -1 ? Rand.Next(2, 5) : Rand.Next(poiDefaultSettings.PoiRange[0], poiDefaultSettings.PoiRange[1] + 1); var poiCount = 0; while (poiCount < max) { var poi = new PointOfInterest(); // Generate a POI ID IdGen.GenerateId(poi); if (universe.PointsOfInterest.Exists(a => a.Id == poi.Id)) { continue; } // Set the POI information with randomized data poi.StarId = star.Id; universe.Zones.Single(a => a.StarId == star.Id).PointsOfInterest.Add(poi.Id); poi.Name = star.Name + " " + ToRoman(poiCount + 1); var type = poiData.PointsOfInterest[Rand.Next(0, poiData.PointsOfInterest.Count)]; poi.Type = type.Type; poi.OccupiedBy = type.OccupiedBy[Rand.Next(0, type.OccupiedBy.Count)]; poi.Situation = type.Situation[Rand.Next(0, type.Situation.Count)]; universe.PointsOfInterest.Add(poi); poiCount++; } } } else { var locId = (from stars in universe.Stars select new { ID = stars.Id }) .Single(a => a.ID == starId).ID; if (string.IsNullOrEmpty(locId)) { throw new FileNotFoundException("No locations with ID " + starId + " found"); } var max = poiDefaultSettings.PoiRange == null || poiDefaultSettings.PoiRange.Length == 0 || poiDefaultSettings.PoiRange[0] == -1 || poiDefaultSettings.PoiRange[1] == -1 ? Rand.Next(1, 5) : Rand.Next(poiDefaultSettings.PoiRange[0], poiDefaultSettings.PoiRange[1] + 1); var poiCount = 0; while (poiCount < max) { var poi = new PointOfInterest(); // Generate a POI ID IdGen.GenerateId(poi); if (universe.PointsOfInterest.Exists(a => a.Id == poi.Id)) { continue; } // Set the POI information with randomized data poi.StarId = starId; universe.Zones.Single(a => a.StarId == starId).PointsOfInterest.Add(poi.Id); poi.Name = universe.Stars.Single(a => a.Id == starId).Name + " " + ToRoman(poiCount + 1); var type = poiData.PointsOfInterest[Rand.Next(0, poiData.PointsOfInterest.Count)]; poi.Type = type.Type; poi.OccupiedBy = type.OccupiedBy[Rand.Next(0, type.OccupiedBy.Count)]; poi.Situation = type.Situation[Rand.Next(0, type.Situation.Count)]; universe.PointsOfInterest.Add(poi); poiCount++; } } return(universe); }