private EliteStation _FindClosestStation(List <EliteStation> inThese, EliteSystem origin) { EliteStation closest = null; double closestDistance = 1000000; //Infinite foreach (EliteStation es in inThese) { double thisDistance = DistanceSqr(es.System, origin); if (thisDistance <= closestDistance) { //If the two stations are in the same system, choose the one closest to the star if ((closest != null) && (es.System.id == closest.System.id)) { if (es.DistanceFromStar < closest.DistanceFromStar) { closest = es; closestDistance = thisDistance; } } else { closest = es; closestDistance = thisDistance; } } } return(closest); }
public void NearestBlackMarket_Handler(AerRecognitionResult result) { if (LocalSystem == null) { _Talk.SayUnknownLocation(); } else { EliteStation est = _Data.FindClosestBlackMarket(LocalSystem); if (est != null) { _Talk.SayFoundStation(est); } else { _Talk.RandomUnknownAck(); } } }
public EliteStation FindCommodity(int commodity_id, EliteSystem origin, float distance) { List <EliteSystem> nearbySystems = GetSystemsAround(origin, distance); EliteStation closest = null; List <EliteStation> stationsWithCommodity = new List <EliteStation>();; foreach (EliteSystem sys in nearbySystems) { var validStations = from stations in sys.Stations from listing in stations.Listings where ((listing.Commodity.id == commodity_id) && (listing.Supply > 0) && ((listing.SellPrice > 0))) select stations; stationsWithCommodity.AddRange(validStations); } double closestDistance = 1000000; //Infinite foreach (EliteStation es in stationsWithCommodity) { double thisDistance = DistanceSqr(es.System, origin); if (thisDistance <= closestDistance) { //If the two stations are in the same system, choose the one closest to the star if ((closest != null) && (es.System.id == closest.System.id)) { if (es.DistanceFromStar < closest.DistanceFromStar) { closest = es; closestDistance = thisDistance; } } else { closest = es; closestDistance = thisDistance; } } } return(closest); }
/// <summary> /// Populates the Station Data with data from the eddb json string /// </summary> /// <param name="json">Json string of EDDB stations.json data</param> private void _ParseStations(string json) { JsonTextReader jsonReader = new JsonTextReader(new StringReader(json)); int arrayDepth = 0; while (jsonReader.Read()) { switch (jsonReader.TokenType) { case JsonToken.StartArray: arrayDepth++; break; case JsonToken.StartObject: try { EliteStation es = _ParseJsonStation(jsonReader); es.System.Stations.Add(es); } catch (Exception e) { AerDebug.LogError("Encountered a problem parsing stations."); AerDebug.LogException(e); } break; case JsonToken.EndArray: arrayDepth--; break; default: AerDebug.LogError("Unknown JSON TokenType: " + jsonReader.TokenType); break; } } if (arrayDepth != 0) { AerDebug.LogError("Malformed JSON parsing - arrayDepth == " + arrayDepth + " at end of parse"); } }
public void FindCommodity_Handler(AerRecognitionResult result) { if (LocalSystem != null) { EliteStation est = _Eddb.FindCommodity(result.Commodity.id, LocalSystem, 250); if (est != null) { _Talk.SayFoundCommodity(result.Commodity, est); _LastStation = est; _LastSystem = est.System; } else { _Talk.SayCannotFindCommodity(result.Commodity); } } else { _Talk.SayUnknownLocation(); } }
public void SayStationServices(EliteStation est) { StringBuilder stationInfo = new StringBuilder(); stationInfo.Append("Known Available Services"); if (est.HasCommodities) { stationInfo.Append(", Commodities"); } if (est.HasRefuel) { stationInfo.Append(", Refuel"); } if (est.HasRepair) { stationInfo.Append(", Repair"); } if (est.HasRearm) { stationInfo.Append(", Rearm"); } if (est.HasOutfitting) { stationInfo.Append(", Outfitting"); } if (est.HasShipyard) { stationInfo.Append(", Shipyard"); } if (est.HasBlackmarket) { stationInfo.Append(", Black Market"); } this.Say(stationInfo.ToString()); }
public void SayStationDistance(EliteStation est) { this.Say(est.Name + " is " + est.DistanceFromStar + "light seconds from" + est.System.Name); }
public void SayFoundStation(EliteStation est) { this.Say(est.Name + ", in " + est.System.Name + ", Spelled " + Spell(est.System.Name)); }
public void SayFoundCommodity(EliteCommodity ec, EliteStation est) { this.Say("You can find " + ec.Name + ", at " + est.Name + ", in " + est.System.Name + ", Spelled " + Spell(est.System.Name)); }
public void SayStationServices(EliteStation est) { StringBuilder stationInfo = new StringBuilder(); stationInfo.Append("Known Available Services"); if (est.HasCommodities) stationInfo.Append(", Commodities"); if (est.HasRefuel) stationInfo.Append(", Refuel"); if (est.HasRepair) stationInfo.Append(", Repair"); if (est.HasRearm) stationInfo.Append(", Rearm"); if (est.HasOutfitting) stationInfo.Append(", Outfitting"); if (est.HasShipyard) stationInfo.Append(", Shipyard"); if (est.HasBlackmarket) stationInfo.Append(", Black Market"); this.Say(stationInfo.ToString()); }
public void SayStationMaxLandingPadSize(EliteStation est) { this.Say(est.MaxPadSize); }
public void FindCommodity_Handler(AerRecognitionResult result) { if (LocalSystem != null) { EliteStation est = _Data.FindCommodity(result.Commodity.id, LocalSystem, 250); if (est != null) { _Talk.SayFoundCommodity(result.Commodity, est); LastStation = est; LastSystem = est.System; } else _Talk.SayCannotFindCommodity(result.Commodity); } else _Talk.SayUnknownLocation(); }
public AerRecognitionResult BuildAerRecognition(RecognitionResult input) { int numberOfSemantics = 0; AerRecognitionResult output = new AerRecognitionResult(); output.Confidence = input.Confidence; try { if (input.Semantics.ContainsKey("Command") && input.Semantics["Command"] != null) { output.Command = input.Semantics["Command"].Value.ToString(); numberOfSemantics++; } if (input.Semantics.ContainsKey("Data") && input.Semantics["Data"] != null) { output.Data = input.Semantics["Data"].Value.ToString(); numberOfSemantics++; } if (input.Semantics.ContainsKey("CommodityId") && input.Semantics["CommodityId"] != null) { int commodityId = int.Parse(input.Semantics["CommodityId"].Value.ToString()); output.Commodity = _Eddb.GetCommodity(commodityId); numberOfSemantics++; } if (input.Semantics.ContainsKey("SystemName") && input.Semantics["SystemName"] != null) { string systemName = input.Semantics["SystemName"].Value.ToString(); if (systemName.Equals("__last__")) { output.System = _LastSystem; } else { if (systemName.Equals("__local__")) { output.System = LocalSystem; } else { output.System = _Eddb.GetSystem(systemName); } } _LastSystem = output.System; numberOfSemantics++; } if (input.Semantics.ContainsKey("FromSystem") && input.Semantics["FromSystem"] != null) { string systemName = input.Semantics["FromSystem"].Value.ToString(); if (systemName.Equals("__last__")) { output.FromSystem = _LastSystem; } else { if (systemName.Equals("__local__")) { output.FromSystem = LocalSystem; } else { output.FromSystem = _Eddb.GetSystem(systemName); } } numberOfSemantics++; } if (input.Semantics.ContainsKey("ToSystem") && input.Semantics["ToSystem"] != null) { string systemName = input.Semantics["ToSystem"].Value.ToString(); if (systemName.Equals("__last__")) { output.ToSystem = _LastSystem; } else { if (systemName.Equals("__local__")) { output.ToSystem = LocalSystem; } else { output.ToSystem = _Eddb.GetSystem(systemName); } } numberOfSemantics++; } if (input.Semantics.ContainsKey("StationName") && input.Semantics["StationName"] != null) { string station = input.Semantics["StationName"].Value.ToString(); if (station.Equals("__last__")) { output.Station = _LastStation; } if (output.System != null) { output.Station = _Eddb.GetStation(output.System, station); _LastStation = output.Station; } numberOfSemantics++; } } catch (Exception e) { AerDebug.LogError("Could not parse grammar semantics, " + e.Message); AerDebug.LogException(e); } output.RequiredConfidence = 0.92f - 0.02 * (numberOfSemantics * numberOfSemantics); return(output); }
/// <summary> /// Returns an EliteStation from a EDDB Json Object. /// JsonReader MUST currently point to the StartObject token for the Station object. /// </summary> /// <param name="jsonReader">JsonReader populated with the Station Object</param> /// <returns>Populated EliteStation data</returns> private EliteStation _ParseJsonStation(JsonTextReader jsonReader) { EliteStation es = new EliteStation(); if (jsonReader.TokenType != JsonToken.StartObject) { AerDebug.LogError("Malformed JSON parsing - _ParseJsonStation must be called on a StartObject token"); } while (jsonReader.TokenType != JsonToken.EndObject) { jsonReader.Read(); switch (jsonReader.TokenType) { case JsonToken.PropertyName: switch (jsonReader.Value.ToString()) { case "id": es.id = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "name": es.Name = jsonReader.ReadAsString(); break; case "system_id": es.System = GetSystem(jsonReader.ReadAsInt32().GetValueOrDefault()); break; case "max_landing_pad_size": es.MaxPadSize = jsonReader.ReadAsString(); break; case "distance_to_star": es.DistanceFromStar = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "faction": es.Faction = jsonReader.ReadAsString(); break; case "government": es.Government = jsonReader.ReadAsString(); break; case "allegiance": es.Allegiance = jsonReader.ReadAsString(); break; case "state": es.State = jsonReader.ReadAsString(); break; case "type": es.StarportType = jsonReader.ReadAsString(); break; case "has_blackmarket": es.HasBlackmarket = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_commodities": es.HasCommodities = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_refuel": es.HasRefuel = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_repear": es.HasRepair = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_rearm": es.HasRearm = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_outfitting": es.HasOutfitting = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_shipyard": es.HasShipyard = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "import_commodities": jsonReader.Read(); es.Imports = _ParseJsonCommodities(jsonReader); break; case "export_commodities": jsonReader.Read(); es.Exports = _ParseJsonCommodities(jsonReader); break; case "prohibited_commodities": jsonReader.Read(); es.Prohibited = _ParseJsonCommodities(jsonReader); break; case "economies": jsonReader.Read(); es.Economies = _ParseJsonEconomies(jsonReader); break; case "updated_at": es.UpdatedAt = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "listings": jsonReader.Read(); es.Listings = _ParseJsonListing(jsonReader); break; default: break; } break; case JsonToken.EndObject: break; } } return(es); }
public void SayStation(EliteStation est) { //This could be faster, it is also more elegant StringBuilder stationInfo = new StringBuilder(); double daysSinceUpdate = DaysSince(est.UpdatedAt); if (daysSinceUpdate > 7) { stationInfo.Append("This information was last updated, " + daysSinceUpdate.ToString("0") + " days ago, ,"); } stationInfo.Append(@"" + _BlanksToUnknown(est.Name) + ", Faction, " + _BlanksToUnknown(est.Faction) + ", Allegiance, " + _BlanksToUnknown(est.Allegiance) + ", Government, " + _BlanksToUnknown(est.Government) + ", State, " + _BlanksToUnknown(est.State) + ", StarportType, " + _BlanksToUnknown(est.StarportType)); stationInfo.Append(". Its distance from the star is" + est.DistanceFromStar + "light seconds. "); stationInfo.Append("Maximum Landing Pad Size, "); switch (est.MaxPadSize) { case ("S"): stationInfo.Append("Small"); break; case ("M"): stationInfo.Append("Medium"); break; case ("L"): stationInfo.Append("Large"); break; default: stationInfo.Append("Unknown"); break; } stationInfo.Append(", Known Available Services"); if (est.HasCommodities) { stationInfo.Append(", Commodities"); } if (est.HasRefuel) { stationInfo.Append(", Refuel"); } if (est.HasRepair) { stationInfo.Append(", Repair"); } if (est.HasRearm) { stationInfo.Append(", Rearm"); } if (est.HasOutfitting) { stationInfo.Append(", Outfitting"); } if (est.HasShipyard) { stationInfo.Append(", Shipyard"); } if (est.HasBlackmarket) { stationInfo.Append(", Black Market"); } stationInfo.Append("."); this.Say(stationInfo.ToString()); }
public void SayFoundCommodity(EliteCommodity ec, EliteStation est) { string spellName = Regex.Replace(est.System.Name, @"(?<=.)(?!$)", ","); this.Say("You can find " + ec.Name + ", at " + est.Name + ", in " + est.System.Name + ", Spelled " + Spell(est.System.Name)); }
public void SayStation(EliteStation est) { //This could be faster, it is also more elegant StringBuilder stationInfo = new StringBuilder(); double daysSinceUpdate = DaysSince(est.UpdatedAt); if(daysSinceUpdate > 7) { stationInfo.Append("This information was last updated, " + daysSinceUpdate.ToString("0") + " days ago, ,"); } stationInfo.Append(@"" + _BlanksToUnknown(est.Name) + ", Faction, " + _BlanksToUnknown(est.Faction) + ", Allegiance, " + _BlanksToUnknown(est.Allegiance) + ", Government, " + _BlanksToUnknown(est.Government) + ", State, " + _BlanksToUnknown(est.State) + ", StarportType, " + _BlanksToUnknown(est.StarportType)); stationInfo.Append(". Its distance from the star is " + est.DistanceFromStar + " light seconds. "); stationInfo.Append("Maximum Landing Pad Size, "); switch(est.MaxPadSize) { case ("S"): stationInfo.Append("Small"); break; case ("M"): stationInfo.Append("Medium"); break; case ("L"): stationInfo.Append("Large"); break; default: stationInfo.Append("Unknown"); break; } stationInfo.Append(", Known Available Services"); if (est.HasCommodities) stationInfo.Append(", Commodities"); if (est.HasRefuel) stationInfo.Append(", Refuel"); if (est.HasRepair) stationInfo.Append(", Repair"); if (est.HasRearm) stationInfo.Append(", Rearm"); if (est.HasOutfitting) stationInfo.Append(", Outfitting"); if (est.HasShipyard) stationInfo.Append(", Shipyard"); if (est.HasBlackmarket) stationInfo.Append(", Black Market"); stationInfo.Append("."); this.Say(stationInfo.ToString()); }
/// <summary> /// Returns an EliteStation from a EDDB Json Object. /// JsonReader MUST currently point to the StartObject token for the Station object. /// </summary> /// <param name="jsonReader">JsonReader populated with the Station Object</param> /// <returns>Populated EliteStation data</returns> private EliteStation _ParseJsonStation(JsonTextReader jsonReader) { EliteStation es = new EliteStation(); if (jsonReader.TokenType != JsonToken.StartObject) AerDebug.LogError("Malformed JSON parsing - _ParseJsonStation must be called on a StartObject token"); while(jsonReader.TokenType != JsonToken.EndObject) { jsonReader.Read(); switch(jsonReader.TokenType) { case JsonToken.PropertyName: switch(jsonReader.Value.ToString()) { case "id": es.id = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "name": es.Name = jsonReader.ReadAsString(); break; case "system_id": es.System = GetSystem(jsonReader.ReadAsInt32().GetValueOrDefault()); break; case "max_landing_pad_size": es.MaxPadSize = jsonReader.ReadAsString(); break; case "distance_to_star": es.DistanceFromStar = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "faction": es.Faction = jsonReader.ReadAsString(); break; case "government": es.Government = jsonReader.ReadAsString(); break; case "allegiance": es.Allegiance = jsonReader.ReadAsString(); break; case "state": es.State = jsonReader.ReadAsString(); break; case "type": es.StarportType = jsonReader.ReadAsString(); break; case "has_blackmarket": es.HasBlackmarket = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_commodities": es.HasCommodities = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_refuel": es.HasRefuel = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_repear": es.HasRepair = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_rearm": es.HasRearm = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_outfitting": es.HasOutfitting = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "has_shipyard": es.HasShipyard = (jsonReader.ReadAsInt32().GetValueOrDefault() == 1); break; case "import_commodities": jsonReader.Read(); es.Imports = _ParseJsonCommodities(jsonReader); break; case "export_commodities": jsonReader.Read(); es.Exports = _ParseJsonCommodities(jsonReader); break; case "prohibited_commodities": jsonReader.Read(); es.Prohibited = _ParseJsonCommodities(jsonReader); break; case "economies": jsonReader.Read(); es.Economies = _ParseJsonEconomies(jsonReader); break; case "updated_at": es.UpdatedAt = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "listings": jsonReader.Read(); es.Listings = _ParseJsonListing(jsonReader); break; default: break; } break; case JsonToken.EndObject: break; } } return es; }
public void SayStationAllegiance(EliteStation est) { this.Say(est.Allegiance); }