Exemplo n.º 1
0
        public void SaySystem(EliteSystem es)
        {
            string str = es.Name + ", Allegiance ";

            if (es.Allegiance.Equals(""))
            {
                str += "Unknown";
            }
            else
            {
                str += es.Allegiance;
            }
            str += ", Controlling Faction ";
            if (es.Faction.Equals(""))
            {
                str += "Unknown";
            }
            else
            {
                str += es.Faction;
            }
            str += ", Population ";
            if (es.Faction.Equals(""))
            {
                str += "Unknown";
            }
            else
            {
                str += es.Population;
            }

            Say(str);
        }
Exemplo n.º 2
0
 public void AerSetSystem_Handler(AerRecognitionResult result)
 {
     if (result.System != null)
     {
         LocalSystem = result.System;
     }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public double DistanceSqr(EliteSystem es1, EliteSystem es2)
        {
            float x = es1.x - es2.x;
            float y = es1.y - es2.y;
            float z = es1.z - es2.z;

            return(Math.Pow(x, 2) + Math.Pow(y, 2) + Math.Pow(z, 2));
        }
Exemplo n.º 5
0
        public List <EliteSystem> GetSystemsAround(EliteSystem origin, float distance)
        {
            float distanceSqr    = distance * distance;
            var   SystemsInRange = from system in _SystemRegistry.Values
                                   where  DistanceSqr(system, origin) < distanceSqr
                                   select system;

            return(SystemsInRange.ToList <EliteSystem>());
        }
Exemplo n.º 6
0
        public EliteSystem FindClosestAllegiance(string Allegiance, EliteSystem origin)
        {
            List <EliteSystem> nearbySystems = _GetSystemsAround(origin, 500);
            var validSystems = from system in nearbySystems
                               where (system.Allegiance.ToLower().Equals(Allegiance.ToLower()))
                               select system;

            return(_FindClosestSystem(validSystems.ToList(), origin));
        }
Exemplo n.º 7
0
 public void SetLocalSystem_Handler(AerRecognitionResult result)
 {
     if (result.System != null)
     {
         _Talk.SaySetSystem(result.System);
         LocalSystem = result.System;
     }
     else
     {
         _Talk.RandomUnknownAck();
     }
 }
Exemplo n.º 8
0
        public EliteStation FindClosestBlackMarket(EliteSystem origin)
        {
            List <EliteSystem>  nearbySystems           = _GetSystemsAround(origin, 500);
            List <EliteStation> stationsWithBlackMarket = new List <EliteStation>();;

            foreach (EliteSystem sys in nearbySystems)
            {
                var validStations = from stations in sys.Stations
                                    where (stations.HasBlackmarket == true)
                                    select stations;

                stationsWithBlackMarket.AddRange(validStations);
            }

            return(_FindClosestStation(stationsWithBlackMarket, origin));
        }
Exemplo n.º 9
0
        private EliteSystem _FindClosestSystem(List <EliteSystem> inThese, EliteSystem origin)
        {
            double      closestDistance = 1000000; //Infinite
            EliteSystem closest         = null;

            foreach (EliteSystem es in inThese)
            {
                double thisDistance = DistanceSqr(es, origin);
                if (thisDistance <= closestDistance)
                {
                    closest         = es;
                    closestDistance = thisDistance;
                }
            }

            return(closest);
        }
Exemplo n.º 10
0
        public EliteStation FindCommodity(int commodity_id, EliteSystem origin, float distance)
        {
            List <EliteSystem> nearbySystems = _GetSystemsAround(origin, distance);


            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);
            }

            return(_FindClosestStation(stationsWithCommodity, origin));
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
 public void AllegianceDistance_Handler(AerRecognitionResult result)
 {
     if (LocalSystem == null)
     {
         _Talk.SayUnknownLocation();
     }
     else
     {
         EliteSystem es = _Data.FindClosestAllegiance(result.Data, LocalSystem);
         if (es != null)
         {
             LastSystem = es;
             _Talk.SayAndSpell(es.Name);
         }
         else
         {
             _Talk.RandomUnknownAck();
         }
     }
 }
Exemplo n.º 13
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();
     }
 }
Exemplo n.º 14
0
//This is getting out of hand for the AerDB file, perhaps a static AerJSON should be created
// As a container for all of these darn utility methods
//TODO: Make AerEddb or AerJSON and create an interface between AerDB and it. -SingularTier
//WARNING: THE CODE IN THE JSON PARSING REGION WILL MAKE YOU VOMIT.
        #region JSON Parsing
        /// <summary>
        /// Populates the System Registry with data from the eddb json string
        /// </summary>
        /// <param name="json">Json string of EDDB systems.json data</param>
        private void _ParseSystems(string json)
        {
            AerDebug.Log("Loading Systems...");
            Stopwatch timer = new Stopwatch();

            timer.Start();
            JArray ja = JArray.Parse(json);

            foreach (JObject jo in ja)
            {
                try
                {
                    EliteSystem es = new EliteSystem();
                    es.Name           = jo["name"].ToString();
                    es.id             = int.Parse(jo["id"].ToString());
                    es.x              = float.Parse(jo["x"].ToString());
                    es.y              = float.Parse(jo["y"].ToString());
                    es.z              = float.Parse(jo["z"].ToString());
                    es.Faction        = jo["faction"].ToString();
                    es.Population     = jo["population"].ToString();
                    es.Government     = jo["government"].ToString();
                    es.Allegiance     = jo["allegiance"].ToString();
                    es.State          = jo["state"].ToString();
                    es.Security       = jo["security"].ToString();
                    es.PrimaryEconomy = jo["primary_economy"].ToString();

                    string permit = jo["needs_permit"].ToString();
                    es.PermitRequired = permit.Equals("1");

                    _SystemRegistry.Add(es.id, es);
                    _SystemNameRegistry.Add(es.Name.ToLower(), es.id);
                }
                catch (FormatException e)
                {
                    AerDebug.LogError("Malformed/Unexpected System JSON data, " + e.Message);
                }
            }
            timer.Stop();
        }
Exemplo n.º 15
0
        public EliteStation GetStation(EliteSystem es, string stationName)
        {
            List <EliteStation> matchingStations;

            var est = from station in es.Stations
                      where station.Name.Equals(stationName)
                      select station;

            matchingStations = est.ToList <EliteStation>();

            if (matchingStations.Count > 1)
            {
                AerDebug.LogError(@"Found " + matchingStations.Count + " stations with the name '" + stationName + "' in system '" + es.Name + "'");
            }
            if (matchingStations.Count > 0)
            {
                return(matchingStations[0]);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 16
0
 public void SaySetSystem(EliteSystem es)
 {
     Say("Setting Current System to " + es.Name);
 }
Exemplo n.º 17
0
        public void SaySystem(EliteSystem es)
        {

            string str = es.Name + ", Allegiance ";
            if(es.Allegiance.Equals(""))
            {
                str+= "Unknown";
            }
            else
            {
                str += es.Allegiance;
            }
            str += ", Controlling Faction ";
            if (es.Faction.Equals(""))
            {
                str += "Unknown";
            }
            else
            {
                str += es.Faction;
            }
            str += ", Population ";
            if (es.Faction.Equals(""))
            {
                str += "Unknown";
            }
            else
            {
                str += es.Population;
            }

            Say(str);
        }
Exemplo n.º 18
0
        private List<EliteSystem> _GetSystemsAround(EliteSystem origin, float distance)
        {
            float distanceSqr = distance * distance;
            var SystemsInRange = from system in _SystemRegistry.Values
                                 where  DistanceSqr(system, origin) < distanceSqr
                                 select system;

            return SystemsInRange.ToList<EliteSystem>();
        }
Exemplo n.º 19
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;
        }
Exemplo n.º 20
0
 public void AerSetSystem_Handler(AerRecognitionResult result)
 {
     if (result.System != null)
     {
         LocalSystem = result.System;
     }
 }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        public EliteStation FindClosestBlackMarket(EliteSystem origin)
        {
            List<EliteSystem> nearbySystems = _GetSystemsAround(origin, 500);
            List<EliteStation> stationsWithBlackMarket = new List<EliteStation>(); ;
            foreach (EliteSystem sys in nearbySystems)
            {
                var validStations = from stations in sys.Stations
                                    where (stations.HasBlackmarket == true)
                                    select stations;

                stationsWithBlackMarket.AddRange(validStations);
            }

            return _FindClosestStation(stationsWithBlackMarket, origin);
        }
Exemplo n.º 23
0
        public EliteStation GetStation(EliteSystem es, string stationName)
        {
            List<EliteStation> matchingStations;

            var est = from station in es.Stations
                               where station.Name.Equals(stationName)
                               select station;

            matchingStations = est.ToList<EliteStation>();

            if (matchingStations.Count > 1)
            {
                AerDebug.LogError(@"Found " + matchingStations.Count +" stations with the name '" + stationName + "' in system '" + es.Name + "'");
            }
            if (matchingStations.Count > 0)
                return matchingStations[0];
            else
                return null;
        }
Exemplo n.º 24
0
        public double DistanceSqr(EliteSystem es1, EliteSystem es2)
        {
            float x = es1.x - es2.x;
            float y = es1.y - es2.y;
            float z = es1.z - es2.z;

            return (Math.Pow(x, 2) + Math.Pow(y, 2) + Math.Pow(z, 2));
        }
Exemplo n.º 25
0
 public void SetLocalSystem_Handler(AerRecognitionResult result)
 {
     if (result.System != null)
     {
         _Talk.SaySetSystem(result.System);
         LocalSystem = result.System;
     }
     else
         _Talk.RandomUnknownAck();
 }
Exemplo n.º 26
0
 public void SaySetSystem(EliteSystem es)
 {
     Say("Setting Current System to " + es.Name);
 }
Exemplo n.º 27
0
 public void SaySelectSystem(EliteSystem es)
 {
     this.Say("Selected " + es.Name);
 }
Exemplo n.º 28
0
 public void SaySelectSystem(EliteSystem es)
 {
     this.Say("Selected " + es.Name);
 }
Exemplo n.º 29
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();
 }
Exemplo n.º 30
0
        public EliteSystem FindClosestAllegiance(string Allegiance, EliteSystem origin)
        {
            List<EliteSystem> nearbySystems = _GetSystemsAround(origin, 500);
            var validSystems = from system in nearbySystems
                               where(system.Allegiance.ToLower().Equals(Allegiance.ToLower()))
                               select system;

            return _FindClosestSystem(validSystems.ToList(), origin);
        }
Exemplo n.º 31
0
 public void AllegianceDistance_Handler(AerRecognitionResult result)
 {
     if (LocalSystem == null)
         _Talk.SayUnknownLocation();
     else
     {
         EliteSystem es = _Data.FindClosestAllegiance(result.Data, LocalSystem);
         if (es != null)
         {
             LastSystem = es;
             _Talk.SayAndSpell(es.Name);
         }
         else
         {
             _Talk.RandomUnknownAck();
         }
     }
 }
Exemplo n.º 32
0
        public EliteStation FindCommodity(int commodity_id, EliteSystem origin, float distance)
        {
            List<EliteSystem> nearbySystems = _GetSystemsAround(origin, distance);


            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);
            }

            return _FindClosestStation(stationsWithCommodity, origin);
        }
Exemplo n.º 33
0
//This is getting out of hand for the AerDB file, perhaps a AerJSON should be created
// As a container for all of these darn utility methods
//TODO: Make AerEddb or AerJSON and create an interface between AerDB and it. -SingularTier
//WARNING: THE CODE IN THE JSON PARSING REGION WILL MAKE YOU VOMIT.
#region JSON Parsing
        /// <summary>
        /// Populates the System Registry with data from the eddb json string
        /// </summary>
        /// <param name="json">Json string of EDDB systems.json data</param>
        private void _ParseSystems(string json)
        {
            AerDebug.Log("Loading Systems...");
            Stopwatch timer = new Stopwatch();
            timer.Start();
            JArray ja = JArray.Parse(json);

            foreach (JObject jo in ja)
            {
                try
                {
                    EliteSystem es = new EliteSystem();
                    es.Name = jo["name"].ToString();
                    es.id = int.Parse(jo["id"].ToString());
                    es.x = float.Parse(jo["x"].ToString());
                    es.y = float.Parse(jo["y"].ToString());
                    es.z = float.Parse(jo["z"].ToString());
                    es.Faction = jo["faction"].ToString();
                    es.Population = jo["population"].ToString();
                    es.Government = jo["government"].ToString();
                    es.Allegiance = jo["allegiance"].ToString();
                    es.State = jo["state"].ToString();
                    es.Security = jo["security"].ToString();
                    es.PrimaryEconomy = jo["primary_economy"].ToString();

                    string permit = jo["needs_permit"].ToString();
                    es.PermitRequired = permit.Equals("1");

                    _SystemRegistry.Add(es.id, es);
                    _SystemNameRegistry.Add(es.Name.ToLower(), es.id);
                }
                catch (FormatException e)
                {
                    AerDebug.LogError("Malformed/Unexpected System JSON data, " + e.Message);
                }
            
            }
            timer.Stop();
        }
Exemplo n.º 34
0
        private EliteSystem _FindClosestSystem(List<EliteSystem> inThese, EliteSystem origin)
        {
            double closestDistance = 1000000; //Infinite
            EliteSystem closest = null;
            foreach (EliteSystem es in inThese)
            {
                double thisDistance = DistanceSqr(es, origin);
                if (thisDistance <= closestDistance)
                {
                    closest = es;
                    closestDistance = thisDistance;
                }
            }

            return closest;
        }