예제 #1
0
        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);
        }
예제 #2
0
 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();
         }
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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");
            }
        }
예제 #5
0
 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();
     }
 }
예제 #6
0
        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());
        }
예제 #7
0
 public void SayStationDistance(EliteStation est)
 {
     this.Say(est.Name + " is " + est.DistanceFromStar + "light seconds from" + est.System.Name);
 }
예제 #8
0
 public void SayFoundStation(EliteStation est)
 {
     this.Say(est.Name + ", in " + est.System.Name + ", Spelled " + Spell(est.System.Name));
 }
예제 #9
0
 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));
 }
예제 #10
0
        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());
        }
예제 #11
0
 public void SayStationMaxLandingPadSize(EliteStation est)
 {
     this.Say(est.MaxPadSize);
 }
예제 #12
0
 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();
 }
예제 #13
0
        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);
        }
예제 #14
0
 public void SayStationMaxLandingPadSize(EliteStation est)
 {
     this.Say(est.MaxPadSize);
 }
예제 #15
0
        /// <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);
        }
예제 #16
0
 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));
 }
예제 #17
0
        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());
        }
예제 #18
0
 public void SayStationDistance(EliteStation est)
 {
     this.Say(est.Name + " is " + est.DistanceFromStar + "light seconds from" + est.System.Name);
 }
예제 #19
0
        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));
        }
예제 #20
0
        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());
        }
예제 #21
0
파일: AerDB.cs 프로젝트: 4-Dtech/AerSpeech
        /// <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;
            
        }
예제 #22
0
 public void SayStationAllegiance(EliteStation est)
 {
     this.Say(est.Allegiance);
 }
예제 #23
0
 public void SayStationAllegiance(EliteStation est)
 {
     this.Say(est.Allegiance);
 }
예제 #24
0
 public void SayFoundStation(EliteStation est)
 {
     this.Say(est.Name + ", in " + est.System.Name + ", Spelled " + Spell(est.System.Name));
 }