Пример #1
0
        public string GetFactionStation(string factionSystem)
        {
            if (factionSystem == null)
            {
                return(null);
            }
            StarSystem factionStarSystem = StarSystemSqLiteRepository.Instance.GetOrFetchStarSystem(factionSystem);

            if (factionStarSystem != null)
            {
                // Filter stations within the faction system which meet the station type prioritization,
                // max distance from the main star, game version, and landing pad size requirements
                LandingPadSize padSize         = EDDI.Instance?.CurrentShip?.Size ?? LandingPadSize.Large;
                List <Station> factionStations = !prioritizeOrbitalStations && EDDI.Instance.inHorizons ? factionStarSystem.stations : factionStarSystem.orbitalstations
                                                 .Where(s => s.stationservices.Count > 0).ToList();
                factionStations = factionStations.Where(s => s.distancefromstar <= maxStationDistanceFromStarLs).ToList();
                factionStations = factionStations.Where(s => s.LandingPadCheck(padSize)).ToList();

                // Build list to find the faction station nearest to the main star
                SortedList <decimal, string> nearestList = new SortedList <decimal, string>();
                foreach (Station station in factionStations)
                {
                    if (!nearestList.ContainsKey(station.distancefromstar ?? 0))
                    {
                        nearestList.Add(station.distancefromstar ?? 0, station.name);
                    }
                }

                // Faction station nearest to the main star
                return(nearestList.Values.FirstOrDefault());
            }
            return(null);
        }
Пример #2
0
        public string GetServiceRoute(string serviceType, int maxStationDistance, bool prioritizeOrbitalStations = false)
        {
            searchSystem   = null;
            searchStation  = null;
            searchDistance = 0;
            List <long> missionids = new List <long>();       // List of mission IDs for the next system

            StarSystem currentSystem = EDDI.Instance?.CurrentStarSystem;

            if (currentSystem != null)
            {
                LandingPadSize shipSize = EDDI.Instance?.CurrentShip?.Size ?? LandingPadSize.Large;
                ServiceFilter.TryGetValue(serviceType, out dynamic filter);

                StarSystem ServiceStarSystem = GetServiceSystem(serviceType, maxStationDistance, prioritizeOrbitalStations);
                if (ServiceStarSystem != null)
                {
                    searchSystem   = ServiceStarSystem.systemname;
                    searchDistance = CalculateDistance(currentSystem, ServiceStarSystem);

                    // Filter stations which meet the game version and landing pad size requirements
                    List <Station> ServiceStations = !prioritizeOrbitalStations && EDDI.Instance.inHorizons ? ServiceStarSystem.stations : ServiceStarSystem.orbitalstations
                                                     .Where(s => s.stationservices.Count > 0).ToList();
                    ServiceStations = ServiceStations.Where(s => s.distancefromstar <= maxStationDistance).ToList();
                    if (serviceType == "facilitator")
                    {
                        ServiceStations = ServiceStations.Where(s => s.LandingPadCheck(shipSize)).ToList();
                    }
                    ServiceStations = ServiceStations.Where(s => s.stationServices.Contains(filter.service)).ToList();

                    // Build list to find the station nearest to the main star
                    SortedList <decimal, string> nearestList = new SortedList <decimal, string>();
                    foreach (Station station in ServiceStations)
                    {
                        if (!nearestList.ContainsKey(station.distancefromstar ?? 0))
                        {
                            nearestList.Add(station.distancefromstar ?? 0, station.name);
                        }
                    }

                    // Station is nearest to the main star which meets the service query
                    searchStation = nearestList.Values.FirstOrDefault();

                    // Get mission IDs for 'service' system
                    missionids = ((MissionMonitor)EDDI.Instance.ObtainMonitor("Mission monitor"))?.GetSystemMissionIds(searchSystem);

                    // Set missions route variables
                    missionMonitor.SetMissionsRouteData(searchSystem, searchDistance);
                }
            }
            EDDI.Instance.enqueueEvent(new RouteDetailsEvent(DateTime.Now, serviceType, searchSystem, searchStation, searchSystem, missionids.Count(), searchDistance, searchDistance, missionids));
            return(searchSystem);
        }
Пример #3
0
        public StarSystem GetServiceSystem(string serviceType, int maxStationDistance, bool prioritizeOrbitalStations)
        {
            StarSystem currentSystem = EDDI.Instance?.CurrentStarSystem;

            if (currentSystem != null)
            {
                // Get the filter parameters
                LandingPadSize shipSize = EDDI.Instance?.CurrentShip?.Size ?? LandingPadSize.Large;
                ServiceFilter.TryGetValue(serviceType, out dynamic filter);
                int cubeLy = filter.cubeLy;

                //
                List <string> checkedSystems = new List <string>();
                string        ServiceSystem  = null;
                int           maxTries       = 5;

                while (ServiceSystem == null && maxTries > 0)
                {
                    List <StarSystem> cubeSystems = edsmService.GetStarMapSystemsCube(currentSystem.systemname, cubeLy);
                    if (cubeSystems?.Any() ?? false)
                    {
                        // Filter systems using search parameters
                        cubeSystems = cubeSystems.Where(s => s.population >= filter.population).ToList();
                        cubeSystems = cubeSystems.Where(s => filter.security.Contains(s.securityLevel.invariantName)).ToList();
                        if (serviceType != "facilitator")
                        {
                            cubeSystems = cubeSystems
                                          .Where(s => filter.econ.Contains(s.Economies.FirstOrDefault(e => e.invariantName != "None")?.invariantName))
                                          .ToList();
                        }

                        // Retreive systems in current radius which have not been previously checked
                        List <string> systemNames = cubeSystems.Select(s => s.systemname).Except(checkedSystems).ToList();
                        if (systemNames.Count > 0)
                        {
                            List <StarSystem> StarSystems = StarSystemSqLiteRepository.Instance.GetOrFetchStarSystems(systemNames.ToArray(), true, false);
                            checkedSystems.AddRange(systemNames);

                            SortedList <decimal, string> nearestList = new SortedList <decimal, string>();
                            foreach (StarSystem starsystem in StarSystems)
                            {
                                // Filter stations within the system which meet the station type prioritization,
                                // max distance from the main star, game version, and landing pad size requirements
                                List <Station> stations = !prioritizeOrbitalStations && EDDI.Instance.inHorizons ? starsystem.stations : starsystem.orbitalstations
                                                          .Where(s => s.stationservices.Count > 0).ToList();
                                stations = stations.Where(s => s.distancefromstar <= maxStationDistance).ToList();
                                if (serviceType == "facilitator")
                                {
                                    stations = stations.Where(s => s.LandingPadCheck(shipSize)).ToList();
                                }
                                int stationCount = stations.Where(s => s.stationServices.Contains(filter.service)).Count();

                                // Build list to find the 'service' system nearest to the current system, meeting station requirements
                                if (stationCount > 0)
                                {
                                    decimal distance = CalculateDistance(currentSystem, starsystem);
                                    if (!nearestList.ContainsKey(distance))
                                    {
                                        nearestList.Add(distance, starsystem.systemname);
                                    }
                                }
                            }

                            // Nearest 'service' system
                            ServiceSystem = nearestList.Values.FirstOrDefault();
                            if (ServiceSystem != null)
                            {
                                return(StarSystems.FirstOrDefault(s => s.systemname == ServiceSystem));
                            }
                        }
                    }

                    // Increase search radius in 10 Ly increments (up to 50 Ly)
                    // until the required 'service' is found
                    cubeLy += 10;
                    maxTries--;
                }
            }
            return(null);
        }