private Body ParseStarMapBody(JObject body, string systemName) { // General items long? bodyId = (long?)body["bodyId"]; long? EDSMID = (long?)body["id"]; string bodyname = (string)body["name"]; BodyType bodyType = BodyType.FromName((string)body["type"]) ?? BodyType.None; decimal? distanceLs = (decimal?)body["distanceToArrival"]; // Light Seconds decimal? temperatureKelvin = (long?)body["surfaceTemperature"]; // Kelvin // Orbital characteristics decimal?orbitalPeriodDays = (decimal?)body["orbitalPeriod"]; // Days decimal?semimajoraxisLs = ConstantConverters.au2ls((decimal?)body["semiMajorAxis"]); // Light seconds decimal?eccentricity = (decimal?)body["orbitalEccentricity"]; decimal?orbitalInclinationDegrees = (decimal?)body["orbitalInclination"]; // Degrees decimal?periapsisDegrees = (decimal?)body["argOfPeriapsis"]; // Degrees decimal?rotationPeriodDays = (decimal?)body["rotationalPeriod"]; // Days decimal?axialTiltDegrees = (decimal?)body["axialTilt"]; // Degrees List <IDictionary <string, object> > parents = new List <IDictionary <string, object> >(); if (body["parents"] != null) { // Parent body types and IDs parents = body["parents"].ToObject <List <IDictionary <string, object> > >() ?? new List <IDictionary <string, object> >(); } List <Ring> rings = new List <Ring>(); if ((JArray)body["rings"] != null || (JArray)body["belts"] != null) { var ringsData = body["rings"] ?? body["belts"]; if (ringsData != null) { foreach (JObject ring in ringsData) { rings.Add(new Ring( (string)ring["name"], RingComposition.FromName((string)ring["type"]), (decimal)ring["mass"], (decimal)ring["innerRadius"], (decimal)ring["outerRadius"] )); } } } if ((string)body["type"] == "Star") { // Star-specific items string stellarclass = ((string)body["subType"]).Split(' ')[0]; // Splits "B (Blue-White) Star" to "B" int? stellarsubclass = null; string endOfStellarClass = stellarclass.ToCharArray().ElementAt(stellarclass.Length - 1).ToString(); if (int.TryParse(endOfStellarClass, out int subclass)) { // If our stellarclass ends in a number, we need to separate the class from the subclass stellarsubclass = subclass; stellarclass = stellarclass.Replace(endOfStellarClass, ""); } long? ageMegaYears = (long?)body["age"]; // Age in megayears string luminosityclass = (string)body["luminosity"]; decimal?absolutemagnitude = (decimal?)body["absoluteMagnitude"]; decimal?stellarMass = (decimal?)body["solarMasses"]; decimal?solarradius = (decimal?)body["solarRadius"]; decimal radiusKm = (decimal)(solarradius != null ? solarradius * Constants.solarRadiusMeters / 1000 : null); Body Body = new Body(bodyname, bodyId, parents, distanceLs, stellarclass, stellarsubclass, stellarMass, radiusKm, absolutemagnitude, ageMegaYears, temperatureKelvin, luminosityclass, semimajoraxisLs, eccentricity, orbitalInclinationDegrees, periapsisDegrees, orbitalPeriodDays, rotationPeriodDays, axialTiltDegrees, rings, true, false, systemName, null) { EDSMID = EDSMID }; DateTime updatedAt = JsonParsing.getDateTime("updateTime", body); Body.updatedat = updatedAt == null ? null : (long?)Dates.fromDateTimeToSeconds(updatedAt); return(Body); } if ((string)body["type"] == "Planet") { // Planet and moon specific items PlanetClass planetClass = PlanetClass.FromName((string)body["subType"]) ?? PlanetClass.None; bool? tidallylocked = (bool?)body["rotationalPeriodTidallyLocked"] ?? false; bool? landable = (bool?)body["isLandable"]; decimal? gravity = (decimal?)body["gravity"]; // G's decimal? earthmass = (decimal?)body["earthMasses"]; decimal? radiusKm = (decimal?)body["radius"]; // Kilometers TerraformState terraformState = TerraformState.FromName((string)body["terraformingState"]) ?? TerraformState.NotTerraformable; Volcanism volcanism = null; if ((string)body["volcanismType"] != null) { volcanism = Volcanism.FromName((string)body["volcanismType"]); } List <AtmosphereComposition> atmosphereCompositions = new List <AtmosphereComposition>(); if (body["atmosphereComposition"] is JObject) { var compositions = body["atmosphereComposition"].ToObject <Dictionary <string, decimal?> >(); foreach (KeyValuePair <string, decimal?> compositionKV in compositions) { string compositionName = compositionKV.Key; decimal?share = compositionKV.Value; if (compositionName != null && share != null) { atmosphereCompositions.Add(new AtmosphereComposition(compositionName, (decimal)share)); } } if (atmosphereCompositions.Count > 0) { atmosphereCompositions = atmosphereCompositions.OrderByDescending(x => x.percent).ToList(); } } decimal? pressureAtm = (decimal?)body["surfacePressure"]; AtmosphereClass atmosphereClass = null; if (((string)body["subType"]).Contains("gas giant") && (string)body["atmosphereType"] == "No atmosphere") { // EDSM classifies any body with an empty string atmosphere property as "No atmosphere". // However, gas giants also receive an empty string. Fix it, since gas giants have atmospheres. atmosphereClass = AtmosphereClass.FromEDName("GasGiant"); } else { atmosphereClass = AtmosphereClass.FromName((string)body["atmosphereType"]); } List <SolidComposition> solidCompositions = new List <SolidComposition>(); if (body["solidComposition"] is JObject) { var compositions = body["solidComposition"].ToObject <Dictionary <string, decimal?> >(); foreach (KeyValuePair <string, decimal?> compositionKV in compositions) { string composition = compositionKV.Key; decimal?share = compositionKV.Value; if (composition != null && share != null) { solidCompositions.Add(new SolidComposition(composition, (decimal)share)); } } if (solidCompositions.Count > 0) { solidCompositions = solidCompositions.OrderByDescending(x => x.percent).ToList(); } } List <MaterialPresence> materials = new List <MaterialPresence>(); if (body["materials"] is JObject) { var materialsData = body["materials"].ToObject <Dictionary <string, decimal?> >(); foreach (KeyValuePair <string, decimal?> materialKV in materialsData) { Material material = Material.FromName(materialKV.Key); decimal? amount = materialKV.Value; if (material != null && amount != null) { materials.Add(new MaterialPresence(material, (decimal)amount)); } } if (materials.Count > 0) { materials = materials.OrderByDescending(o => o.percentage).ToList(); } } ReserveLevel reserveLevel = ReserveLevel.FromName((string)body["reserveLevel"]) ?? ReserveLevel.None; DateTime updatedAt = JsonParsing.getDateTime("updateTime", body); Body Body = new Body(bodyname, bodyId, parents, distanceLs, tidallylocked, terraformState, planetClass, atmosphereClass, atmosphereCompositions, volcanism, earthmass, radiusKm, (decimal)gravity, temperatureKelvin, pressureAtm, landable, materials, solidCompositions, semimajoraxisLs, eccentricity, orbitalInclinationDegrees, periapsisDegrees, orbitalPeriodDays, rotationPeriodDays, axialTiltDegrees, rings, reserveLevel, true, true, systemName, null) { EDSMID = EDSMID, updatedat = updatedAt == null ? null : (long?)Dates.fromDateTimeToSeconds(updatedAt) }; return(Body); } return(null); }
public string DisplayString(int indent = 0, bool includefront = true, MaterialCommoditiesList historicmatlist = null, MaterialCommoditiesList currentmatlist = null) { string inds = new string(' ', indent); StringBuilder scanText = new StringBuilder(); scanText.Append(inds); if (includefront) { scanText.AppendFormat("{0} {1}\n\n", BodyName, IsEDSMBody ? " (EDSM)" : ""); if (IsStar) { scanText.AppendFormat(GetStarTypeName()); } else if (PlanetClass != null) { scanText.AppendFormat("{0}", PlanetClass); if (!PlanetClass.ToLower().Contains("gas")) { scanText.AppendFormat((Atmosphere == null || Atmosphere == String.Empty) ? ", No Atmosphere" : (", " + Atmosphere)); } } if (IsLandable) { scanText.AppendFormat(", Landable"); } scanText.AppendFormat("\n"); if (HasAtmosphericComposition) { scanText.Append("\n" + DisplayAtmosphere(2)); } if (HasPlanetaryComposition) { scanText.Append("\n" + DisplayComposition(2)); } if (HasPlanetaryComposition || HasAtmosphericComposition) { scanText.Append("\n\n"); } if (nAge.HasValue) { scanText.AppendFormat("Age: {0} million years\n", nAge.Value.ToString("N0")); } if (nStellarMass.HasValue) { scanText.AppendFormat("Solar Masses: {0:0.00}\n", nStellarMass.Value); } if (nMassEM.HasValue) { scanText.AppendFormat("Earth Masses: {0:0.0000}\n", nMassEM.Value); } if (nRadius.HasValue) { if (IsStar) { scanText.AppendFormat("Solar Radius: {0:0.00} Sols\n", (nRadius.Value / solarRadius_m)); } else { scanText.AppendFormat("Body Radius: {0:0.00}km\n", (nRadius.Value / 1000)); } } } if (nSurfaceTemperature.HasValue) { scanText.AppendFormat("Surface Temp: {0}K\n", nSurfaceTemperature.Value.ToString("N0")); } if (Luminosity != null) { scanText.AppendFormat("Luminosity: {0}\n", Luminosity); } if (nSurfaceGravity.HasValue) { scanText.AppendFormat("Gravity: {0:0.0}g\n", nSurfaceGravity.Value / oneGee_m_s2); } if (nSurfacePressure.HasValue && nSurfacePressure.Value > 0.00 && !PlanetClass.ToLower().Contains("gas")) { if (nSurfacePressure.Value > 1000) { scanText.AppendFormat("Surface Pressure: {0} Atmospheres\n", (nSurfacePressure.Value / oneAtmosphere_Pa).ToString("N2")); } else { { scanText.AppendFormat("Surface Pressure: {0} Pa\n", (nSurfacePressure.Value).ToString("N2")); } } } if (Volcanism != null) { scanText.AppendFormat("Volcanism: {0}\n", Volcanism == String.Empty ? "No Volcanism" : System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo. ToTitleCase(Volcanism.ToLower())); } if (DistanceFromArrivalLS > 0) { scanText.AppendFormat("Distance from Arrival Point {0:N1}ls\n", DistanceFromArrivalLS); } if (nOrbitalPeriod.HasValue && nOrbitalPeriod > 0) { scanText.AppendFormat("Orbital Period: {0} days\n", (nOrbitalPeriod.Value / oneDay_s).ToString("N1")); } if (nSemiMajorAxis.HasValue) { if (IsStar || nSemiMajorAxis.Value > oneAU_m / 10) { scanText.AppendFormat("Semi Major Axis: {0:0.00}AU\n", (nSemiMajorAxis.Value / oneAU_m)); } else { scanText.AppendFormat("Semi Major Axis: {0}km\n", (nSemiMajorAxis.Value / 1000).ToString("N1")); } } if (nEccentricity.HasValue) { scanText.AppendFormat("Orbital Eccentricity: {0:0.000}\n", nEccentricity.Value); } if (nOrbitalInclination.HasValue) { scanText.AppendFormat("Orbital Inclination: {0:0.000}°\n", nOrbitalInclination.Value); } if (nPeriapsis.HasValue) { scanText.AppendFormat("Arg Of Periapsis: {0:0.000}°\n", nPeriapsis.Value); } if (nAbsoluteMagnitude.HasValue) { scanText.AppendFormat("Absolute Magnitude: {0:0.00}\n", nAbsoluteMagnitude.Value); } if (nAxialTilt.HasValue) { scanText.AppendFormat("Axial tilt: {0:0.00}°\n", nAxialTilt.Value * 180.0 / Math.PI); } if (nRotationPeriod.HasValue) { scanText.AppendFormat("Rotation Period: {0} days\n", (nRotationPeriod.Value / oneDay_s).ToString("N1")); } if (nTidalLock.HasValue && nTidalLock.Value) { scanText.Append("Tidally locked\n"); } if (Terraformable) { scanText.Append("Candidate for terraforming\n"); } if (HasRings) { scanText.Append("\n"); if (IsStar) { scanText.AppendFormat("Belt{0}", Rings.Count() == 1 ? ":" : "s:"); for (int i = 0; i < Rings.Length; i++) { if (Rings[i].MassMT > (oneMoon_MT / 10000)) { scanText.Append("\n" + RingInformation(i, 1.0 / oneMoon_MT, " Moons")); } else { scanText.Append("\n" + RingInformation(i)); } } } else { scanText.AppendFormat("Ring{0}", Rings.Count() == 1 ? ":" : "s:"); for (int i = 0; i < Rings.Length; i++) { scanText.Append("\n" + RingInformation(i)); } } } if (HasMaterials) { scanText.Append("\n" + DisplayMaterials(2, historicmatlist, currentmatlist) + "\n"); } string habzonestring = HabZoneString(); if (habzonestring != null) { scanText.Append("\n" + habzonestring); } if (scanText.Length > 0 && scanText[scanText.Length - 1] == '\n') { scanText.Remove(scanText.Length - 1, 1); } if (EstimatedValue > 0) { scanText.AppendFormat("\nEstimated value: {0:N0}", EstimatedValue); } if (EDSMDiscoveryCommander != null) { scanText.AppendFormat("\n\nDiscovered by " + EDSMDiscoveryCommander + " on " + EDSMDiscoveryUTC.ToStringZulu()); } return(scanText.ToNullSafeString().Replace("\n", "\n" + inds)); }
public static List <Body> BodiesFromEDDP(string systemName, dynamic json) { List <Body> Bodies = new List <Body>(); if (json["bodies"] != null) { foreach (dynamic body in json["bodies"]) { if ((string)body["group_name"] == "Belt") { // Not interested in asteroid belts continue; } Body Body = new Body(); // General items Body.EDDBID = (long)body["id"]; Body.name = (string)body["name"]; Body.systemname = systemName; Body.type = (string)body["group_name"]; Body.distance = (long?)body["distance_to_arrival"]; Body.temperature = (long?)body["surface_temperature"]; Body.tidallylocked = (bool?)body["is_rotational_period_tidally_locked"]; if (Body.type == "Star") { // Star-specific items Body.stellarclass = (string)body["spectral_class"]; Body.solarmass = (decimal?)(double?)body["solar_masses"]; Body.solarradius = (decimal?)(double?)body["solar_radius"]; Body.age = (long?)body["age"]; Body.mainstar = (bool?)body["is_main_star"]; Body.landable = false; } if (Body.type == "Planet") { // Planet-specific items Body.landable = (bool?)body["is_landable"]; Body.periapsis = (decimal?)(double?)body["arg_of_periapsis"]; Body.atmosphere = (string)body["atmosphere_type_name"]; Body.tilt = (decimal?)(double?)body["axis_tilt"]; Body.earthmass = (decimal?)(double?)body["earth_masses"]; Body.gravity = (decimal?)(double?)body["gravity"]; Body.eccentricity = (decimal?)(double?)body["orbital_eccentricity"]; Body.inclination = (decimal?)(double?)body["orbital_inclination"]; decimal?orbitalPeriodSeconds = (decimal?)(double?)body["orbital_period"]; Body.orbitalperiod = orbitalPeriodSeconds / (24.0M * 60.0M * 60.0M); Body.radius = (long?)body["radius"]; Body.rotationalperiod = (decimal?)(double?)body["rotational_period"]; Body.semimajoraxis = (decimal?)(double?)body["semi_major_axis"]; Body.pressure = (decimal?)(double?)body["surface_pressure"]; Body.terraformstate = (string)body["terraforming_state_name"]; Body.planettype = (string)body["type_name"]; // Volcanism might be a simple name or an object if (body["volcanism_type_name"] != null) { Body.volcanism = Volcanism.FromName((string)body["volcanism_type_name"]); } if (body["volcanism"] != null) { Body.volcanism = new Volcanism((string)body["volcanism"]["type"], (string)body["volcanism"]["composition"], (string)body["volcanism"]["amount"]); } if (body["materials"] != null) { List <MaterialPresence> Materials = new List <MaterialPresence>(); foreach (dynamic materialJson in body["materials"]) { Material material = Material.FromName((string)materialJson["material_name"]); decimal? amount = (decimal?)(double?)materialJson["share"]; if (material != null && amount != null) { Materials.Add(new MaterialPresence(material, (decimal)amount)); } } if (Materials.Count > 0) { Body.materials = Materials.OrderByDescending(o => o.percentage).ToList(); } } } Bodies.Add(Body); } } // Sort bodies by distance return(Bodies.OrderBy(o => o.distance).ToList()); }
public BodyScannedEvent(DateTime timestamp, string name, string bodyclass, decimal?earthmass, decimal?radius, decimal gravity, decimal?temperature, decimal?pressure, bool?tidallylocked, bool?landable, string atmosphere, Volcanism volcanism, decimal distancefromarrival, decimal orbitalperiod, decimal rotationperiod, decimal?semimajoraxis, decimal?eccentricity, decimal?orbitalinclination, decimal?periapsis, List <Ring> rings, string reserves, List <MaterialPresence> materials, string terraformstate, decimal?axialtilt) : base(timestamp, NAME) { this.name = name; this.distancefromarrival = distancefromarrival; this.bodyclass = bodyclass; this.earthmass = earthmass; this.radius = radius; this.gravity = gravity; this.temperature = temperature; this.pressure = pressure; this.tidallylocked = tidallylocked; this.landable = landable; this.atmosphere = atmosphere; this.volcanism = volcanism; this.orbitalperiod = orbitalperiod; this.rotationperiod = rotationperiod; this.semimajoraxis = semimajoraxis; this.eccentricity = eccentricity; this.orbitalinclination = orbitalinclination; this.periapsis = periapsis; this.rings = rings; this.reserves = reserves; this.materials = materials; this.terraformstate = terraformstate; this.axialtilt = axialtilt; }
private static Body ParseEddbBody(object response) { JObject bodyJson = ((JObject)response); Body Body = new Body { // General items EDDBID = (long)bodyJson["id"], updatedat = (long)(Dates.fromDateTimeStringToSeconds((string)bodyJson["updated_at"])), name = (string)bodyJson["name"], Type = BodyType.FromEDName((string)bodyJson["group_name"]), systemEDDBID = (long)bodyJson["system_id"], // Orbital data distance = (decimal?)bodyJson["distance_to_arrival"], // Light seconds temperature = (decimal?)bodyJson["surface_temperature"], //Kelvin tidallylocked = (bool?)bodyJson["is_rotational_period_tidally_locked"] ?? false, // Days rotationalperiod = (decimal?)(double?)bodyJson["rotational_period"], // Days tilt = (decimal?)(double?)bodyJson["axis_tilt"], // Degrees semimajoraxis = ConstantConverters.au2ls((decimal?)(double?)bodyJson["semi_major_axis"]), // Light Seconds orbitalperiod = (decimal?)(double?)bodyJson["orbital_period"], // Days periapsis = (decimal?)(double?)bodyJson["arg_of_periapsis"], // Degrees eccentricity = (decimal?)(double?)bodyJson["orbital_eccentricity"], inclination = (decimal?)(double?)bodyJson["orbital_inclination"] // Degrees }; if ((string)bodyJson["group_name"] == "belt") { // Not interested in asteroid belts, // no need to add additional information at this time. } else if ((string)bodyJson["group_name"] == "star") { // Star-specific items Body.stellarclass = ((string)bodyJson["spectral_class"])?.ToUpperInvariant(); Body.luminosityclass = ((string)bodyJson["luminosity_class"])?.ToUpperInvariant(); Body.solarmass = (decimal?)(double?)bodyJson["solar_masses"]; Body.solarradius = (decimal?)(double?)bodyJson["solar_radius"]; Body.age = (long?)bodyJson["age"]; // MegaYears Body.mainstar = (bool?)bodyJson["is_main_star"]; Body.landable = false; Body.setStellarExtras(); } else if ((string)bodyJson["group_name"] == "planet") { // Planet-specific items Body.planetClass = PlanetClass.FromEDName((string)bodyJson["type_name"]); Body.landable = (bool?)bodyJson["is_landable"] ?? false; Body.earthmass = (decimal?)(double?)bodyJson["earth_masses"]; Body.gravity = (decimal?)(double?)bodyJson["gravity"]; // G's Body.radius = (decimal?)bodyJson["radius"]; // Kilometers Body.pressure = (decimal?)(double?)bodyJson["surface_pressure"] ?? 0; Body.terraformState = TerraformState.FromName((string)bodyJson["terraforming_state_name"]); // Per Themroc @ EDDB, "Major" and "Minor" volcanism descriptors are stripped from EDDB data. Body.volcanism = Volcanism.FromName((string)bodyJson["volcanism_type_name"]); Body.atmosphereclass = AtmosphereClass.FromName((string)bodyJson["atmosphere_type_name"]); if (bodyJson["atmosphere_composition"] != null) { List <AtmosphereComposition> atmosphereCompositions = new List <AtmosphereComposition>(); foreach (JObject atmoJson in bodyJson["atmosphere_composition"]) { string composition = (string)atmoJson["atmosphere_component_name"]; decimal?share = (decimal?)atmoJson["share"]; if (composition != null && share != null) { atmosphereCompositions.Add(new AtmosphereComposition(composition, (decimal)share)); } } if (atmosphereCompositions.Count > 0) { atmosphereCompositions = atmosphereCompositions.OrderByDescending(x => x.percent).ToList(); Body.atmospherecompositions = atmosphereCompositions; } } if (bodyJson["solid_composition"] != null) { List <SolidComposition> bodyCompositions = new List <SolidComposition>(); foreach (JObject bodyCompJson in bodyJson["solid_composition"]) { string composition = (string)bodyCompJson["solid_component_name"]; decimal?share = (decimal?)bodyCompJson["share"]; if (composition != null && share != null) { bodyCompositions.Add(new SolidComposition(composition, (decimal)share)); } } if (bodyCompositions.Count > 0) { bodyCompositions = bodyCompositions.OrderByDescending(x => x.percent).ToList(); Body.solidcompositions = bodyCompositions; } } if (bodyJson["materials"] != null) { List <MaterialPresence> Materials = new List <MaterialPresence>(); foreach (JObject materialJson in bodyJson["materials"]) { Material material = Material.FromEDName((string)materialJson["material_name"]); decimal? amount = (decimal?)(double?)materialJson["share"]; if (material != null && amount != null) { Materials.Add(new MaterialPresence(material, (decimal)amount)); } } if (Materials.Count > 0) { Body.materials = Materials.OrderByDescending(o => o.percentage).ToList(); } } } // Rings may be an object or may be a singular List <Ring> rings = new List <Ring>(); if (bodyJson["rings"] != null) { foreach (JObject ringJson in bodyJson["rings"]) { string name = (string)ringJson["name"]; RingComposition composition = RingComposition.FromName((string)ringJson["ring_type_name"]); decimal ringMassMegaTons = (decimal)ringJson["ring_mass"]; decimal innerRadiusKm = (decimal)ringJson["ring_inner_radius"]; decimal outerRadiusKm = (decimal)ringJson["ring_outer_radius"]; Ring ring = new Ring(name, composition, ringMassMegaTons, innerRadiusKm, outerRadiusKm); rings.Add(ring); } } if (bodyJson["ring_type_name"].HasValues) { string name = (string)bodyJson["name"]; RingComposition composition = RingComposition.FromName((string)bodyJson["ring_type_name"]); decimal ringMassMegaTons = (decimal)bodyJson["ring_mass"]; decimal innerRadiusKm = (decimal)bodyJson["ring_inner_radius"]; decimal outerRadiusKm = (decimal)bodyJson["ring_outer_radius"]; Ring ring = new Ring(name, composition, ringMassMegaTons, innerRadiusKm, outerRadiusKm); rings.Add(ring); } if (rings.Count > 0) { Body.rings = rings.OrderBy(o => o.innerradius).ToList(); } return(Body); }
} // One of AutoScan, Basic, Detailed, NavBeacon, NavBeaconDetail // AutoScan events are detailed scans triggered via proximity. public BodyScannedEvent(DateTime timestamp, string scantype, string name, string systemName, PlanetClass planetClass, decimal?earthmass, decimal?radiusKm, decimal gravity, decimal?temperatureKelvin, decimal?pressureAtm, bool?tidallylocked, bool?landable, AtmosphereClass atmosphereClass, List <AtmosphereComposition> atmosphereComposition, List <SolidComposition> solidCompositions, Volcanism volcanism, decimal distancefromarrival_Ls, decimal orbitalperiodDays, decimal rotationperiodDays, decimal?semimajoraxisAU, decimal?eccentricity, decimal?orbitalinclinationDegrees, decimal?periapsisDegrees, List <Ring> rings, string reserves, List <MaterialPresence> materials, TerraformState terraformstate, decimal?axialtiltDegrees) : base(timestamp, NAME) { this.scantype = scantype; this.name = name; this.systemname = systemName; this.distancefromarrival = distancefromarrival_Ls; this.planetClass = planetClass; this.earthmass = earthmass; this.radius = radiusKm; this.gravity = gravity; this.temperature = temperatureKelvin; this.pressure = pressureAtm; this.tidallylocked = tidallylocked; this.landable = landable; this.atmosphereclass = atmosphereClass; this.atmospherecomposition = atmosphereComposition; this.solidcomposition = solidCompositions; this.volcanism = volcanism; this.orbitalperiod = orbitalperiodDays; this.rotationperiod = rotationperiodDays; this.semimajoraxis = semimajoraxisAU; this.eccentricity = eccentricity; this.orbitalinclination = orbitalinclinationDegrees; this.periapsis = periapsisDegrees; this.rings = rings; this.reserves = reserves; this.materials = materials; this.terraformState = terraformstate; this.axialtilt = axialtiltDegrees; this.estimatedvalue = estimateValue(scantype == null ? false : scantype.Contains("Detail")); }
private static Body ParseStarMapBody(JObject body, string system) { Body Body = new Body { // General items EDSMID = (long?)body["id"], name = (string)body["name"], systemname = system, Type = BodyType.FromName((string)body["type"]) ?? BodyType.None, distance = (decimal?)body["distanceToArrival"], // Light Seconds temperature = (long?)body["surfaceTemperature"], // Kelvin // Orbital characteristics orbitalperiod = (decimal?)body["orbitalPeriod"], // Days semimajoraxis = ConstantConverters.au2ls((decimal?)body["semiMajorAxis"]), // Light seconds eccentricity = (decimal?)body["orbitalEccentricity"], inclination = (decimal?)body["orbitalInclination"], // Degrees periapsis = (decimal?)body["argOfPeriapsis"], // Degrees rotationalperiod = (decimal?)body["rotationalPeriod"], // Days tidallylocked = (bool?)body["rotationalPeriodTidallyLocked"] ?? false, tilt = (decimal?)body["axialTilt"] // Degrees }; if ((string)body["type"] == "Belt") { // Not interested in asteroid belts, // no need to add additional information at this time. } if ((string)body["type"] == "Star") { // Star-specific items Body.stellarclass = ((string)body["subType"]).Split(' ')[0]; // Splits "B (Blue-White) Star" to "B" Body.mainstar = (bool?)body["isMainStar"]; Body.age = (long?)body["age"]; // Age in megayears Body.luminosityclass = (string)body["luminosity"]; Body.absoluteMagnitude = (decimal?)body["absoluteMagnitude"]; Body.solarmass = (decimal?)body["solarMasses"]; Body.solarradius = (decimal?)body["solarRadius"]; Body.landable = false; Body.setStellarExtras(); } if ((string)body["type"] == "Planet") { // Planet-specific items Body.planetClass = PlanetClass.FromName((string)body["subType"]) ?? PlanetClass.None; Body.landable = (bool?)body["isLandable"]; Body.gravity = (decimal?)body["gravity"]; // G's Body.earthmass = (decimal?)body["earthMasses"]; Body.radius = (decimal?)body["radius"]; // Kilometers Body.terraformState = TerraformState.FromName((string)body["terraformingState"]) ?? TerraformState.NotTerraformable; if ((string)body["volcanismType"] != null) { Body.volcanism = Volcanism.FromName((string)body["volcanismType"]); } if (body["atmosphereComposition"] is JObject) { List <AtmosphereComposition> atmosphereCompositions = new List <AtmosphereComposition>(); var compositions = body["atmosphereComposition"].ToObject <Dictionary <string, decimal?> >(); foreach (KeyValuePair <string, decimal?> compositionKV in compositions) { string compositionName = compositionKV.Key; decimal?share = compositionKV.Value; if (compositionName != null && share != null) { atmosphereCompositions.Add(new AtmosphereComposition(compositionName, (decimal)share)); } } if (atmosphereCompositions.Count > 0) { atmosphereCompositions = atmosphereCompositions.OrderByDescending(x => x.percent).ToList(); Body.atmospherecompositions = atmosphereCompositions; } } Body.pressure = (decimal?)body["surfacePressure"]; if (((string)body["subType"]).Contains("gas giant") && (string)body["atmosphereType"] == "No atmosphere") { // EDSM classifies any body with an empty string atmosphere property as "No atmosphere". // However, gas giants also receive an empty string. Fix it, since gas giants have atmospheres. Body.atmosphereclass = AtmosphereClass.FromEDName("GasGiant"); } else { Body.atmosphereclass = AtmosphereClass.FromName((string)body["atmosphereType"]); } if (body["solidComposition"] is JObject) { List <SolidComposition> bodyCompositions = new List <SolidComposition>(); var compositions = body["solidComposition"].ToObject <Dictionary <string, decimal?> >(); foreach (KeyValuePair <string, decimal?> compositionKV in compositions) { string composition = compositionKV.Key; decimal?share = compositionKV.Value; if (composition != null && share != null) { bodyCompositions.Add(new SolidComposition(composition, (decimal)share)); } } if (bodyCompositions.Count > 0) { bodyCompositions = bodyCompositions.OrderByDescending(x => x.percent).ToList(); Body.solidcompositions = bodyCompositions; } } if (body["materials"] is JObject) { List <MaterialPresence> Materials = new List <MaterialPresence>(); var materials = body["materials"].ToObject <Dictionary <string, decimal?> >(); foreach (KeyValuePair <string, decimal?> materialKV in materials) { Material material = Material.FromName(materialKV.Key); decimal? amount = materialKV.Value; if (material != null && amount != null) { Materials.Add(new MaterialPresence(material, (decimal)amount)); } } if (Materials.Count > 0) { Body.materials = Materials.OrderByDescending(o => o.percentage).ToList(); } } } if ((JArray)body["rings"] != null || (JArray)body["belts"] != null) { var rings = body["rings"] ?? body["belts"]; if (rings != null) { List <Ring> Rings = new List <Ring>(); foreach (JObject ring in rings) { Rings.Add(new Ring( (string)ring["name"], RingComposition.FromName((string)ring["type"]), (decimal)ring["mass"], (decimal)ring["innerRadius"], (decimal)ring["outerRadius"] )); } Body.rings = Rings; } } Body.reserveLevel = ReserveLevel.FromName((string)body["reserveLevel"]) ?? ReserveLevel.None; DateTime updatedAt = DateTime.SpecifyKind(DateTime.Parse((string)body["updateTime"]), DateTimeKind.Utc); Body.updatedat = updatedAt == null ? null : (long?)(updatedAt.Subtract(new DateTime(1970, 1, 1, 0, 0, 0))).TotalSeconds; return(Body); }
public string DisplayString(int indent = 0, bool includefront = true) { string inds = new string(' ', indent); StringBuilder scanText = new StringBuilder(); scanText.Append(inds); if (includefront) { scanText.AppendFormat("{0}\n\n", BodyName); if (IsStar) { scanText.AppendFormat(GetStarTypeImage().Item2); } else if (PlanetClass != null) { scanText.AppendFormat("{0}", PlanetClass); if (!PlanetClass.ToLower().Contains("gas")) { scanText.AppendFormat((Atmosphere == null || Atmosphere == String.Empty) ? ", No Atmosphere" : (", " + Atmosphere)); } } if (IsLandable) { scanText.AppendFormat(", Landable"); } scanText.AppendFormat("\n"); if (nAge.HasValue) { scanText.AppendFormat("Age: {0} million years\n", nAge.Value.ToString("N0")); } if (nStellarMass.HasValue) { scanText.AppendFormat("Solar Masses: {0:0.00}\n", nStellarMass.Value); } if (nMassEM.HasValue) { scanText.AppendFormat("Earth Masses: {0:0.0000}\n", nMassEM.Value); } if (nRadius.HasValue) { if (IsStar) { scanText.AppendFormat("Solar Radius: {0:0.00} Sols\n", (nRadius.Value / solarRadius_m)); } else { scanText.AppendFormat("Body Radius: {0:0.00}km\n", (nRadius.Value / 1000)); } } } if (nSurfaceTemperature.HasValue) { scanText.AppendFormat("Surface Temp: {0}K\n", nSurfaceTemperature.Value.ToString("N0")); } if (nSurfaceGravity.HasValue) { scanText.AppendFormat("Gravity: {0:0.0}g\n", nSurfaceGravity.Value / 9.8); } if (nSurfacePressure.HasValue && nSurfacePressure.Value > 0.00 && !PlanetClass.ToLower().Contains("gas")) { if (nSurfacePressure.Value > 1000) { scanText.AppendFormat("Surface Pressure: {0} Atmospheres\n", (nSurfacePressure.Value / 100000).ToString("N2")); } else { { scanText.AppendFormat("Surface Pressure: {0} Pa\n", (nSurfacePressure.Value).ToString("N2")); } } } if (Volcanism != null) { scanText.AppendFormat("Volcanism: {0}\n", Volcanism == String.Empty ? "No Volcanism" : System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo. ToTitleCase(Volcanism.ToLower())); } if (DistanceFromArrivalLS > 0) { scanText.AppendFormat("Distance from Arrival Point {0:N1}ls\n", DistanceFromArrivalLS); } if (nOrbitalPeriod.HasValue && nOrbitalPeriod > 0) { scanText.AppendFormat("Orbital Period: {0} days\n", (nOrbitalPeriod.Value / oneDay_s).ToString("N1")); } if (nSemiMajorAxis.HasValue) { if (IsStar || nSemiMajorAxis.Value > oneAU_m / 10) { scanText.AppendFormat("Semi Major Axis: {0:0.00}AU\n", (nSemiMajorAxis.Value / oneAU_m)); } else { scanText.AppendFormat("Semi Major Axis: {0}km\n", (nSemiMajorAxis.Value / 1000).ToString("N1")); } } if (nEccentricity.HasValue) { scanText.AppendFormat("Orbital Eccentricity: {0:0.000}°\n", nEccentricity.Value); } if (nOrbitalInclination.HasValue) { scanText.AppendFormat("Orbital Inclination: {0:0.000}°\n", nOrbitalInclination.Value); } if (nPeriapsis.HasValue) { scanText.AppendFormat("Arg Of Periapsis: {0:0.000}°\n", nPeriapsis.Value); } if (nAbsoluteMagnitude.HasValue) { scanText.AppendFormat("Absolute Magnitude: {0:0.00}\n", nAbsoluteMagnitude.Value); } if (nRotationPeriod.HasValue) { scanText.AppendFormat("Rotation Period: {0} days\n", (nRotationPeriod.Value / oneDay_s).ToString("N1")); } if (nTidalLock.HasValue && nTidalLock.Value) { scanText.Append("Tidally locked\n"); } if (TerraformState != null && TerraformState == "Terraformable") { scanText.Append("Candidate for terraforming\n"); } if (HasRings) { scanText.Append("\n"); if (IsStar) { scanText.AppendFormat("Belt{0}", Rings.Count() == 1 ? ":" : "s:"); for (int i = 0; i < Rings.Length; i++) { if (Rings[i].MassMT > 7342000000) { scanText.Append("\n" + RingInformation(i, 1.0 / oneMoon_MT, " Moons")); } else { scanText.Append("\n" + RingInformation(i)); } } } else { scanText.AppendFormat("Ring{0}", Rings.Count() == 1 ? ":" : "s:"); for (int i = 0; i < Rings.Length; i++) { scanText.Append("\n" + RingInformation(i)); } } } if (HasMaterials) { scanText.Append("\n" + DisplayMaterials(2) + "\n"); } if (IsStar && HabitableZoneInner.HasValue && HabitableZoneOuter.HasValue) { StringBuilder habZone = new StringBuilder(); habZone.AppendFormat("Habitable Zone Approx. {0}ls to {1}ls\n", HabitableZoneInner.Value.ToString("N0"), HabitableZoneOuter.Value.ToString("N0")); if (nSemiMajorAxis.HasValue && nSemiMajorAxis.Value > 0) { habZone.AppendFormat(" (This star only, others not considered)\n"); } scanText.Append("\n" + habZone); } if (scanText.Length > 0 && scanText[scanText.Length - 1] == '\n') { scanText.Remove(scanText.Length - 1, 1); } int estvalue = EstimatedValue(); if (estvalue > 0) { scanText.AppendFormat("\nEstimated value: {0}", estvalue); } return(scanText.ToNullSafeString().Replace("\n", "\n" + inds)); }