Example #1
0
        public Dictionary <int, int> GetDistanceMap(bool highSec = false)
        {
            if (systemDestinations == null || systemDestinations.Count == 0)
            {
                GenerateDestinations();
            }
            Dictionary <int, int> distanceMap = new Dictionary <int, int>();
            List <int>            systems     = new List <int>();

            // Add this system as the seed location.
            distanceMap[solarSystemID] = 0;
            systems.Add(solarSystemID);
            // Start interating the systems.
            while (systems.Count > 0)
            {
                // Get the first unproccessed system.
                int _solarSystemID = systems[0];
                systems.Remove(_solarSystemID);
                // Get the solar system.
                SolarSystem system = GetSystem(_solarSystemID);
                if (system == null)
                {
                    continue;
                }
                // Get the next distance.
                int distance = distanceMap[_solarSystemID] + 1;
                // Iterate the gates in this system.
                List <int> gateSystems = new List <int>();
                if (!systemDestinations.ContainsKey(system.solarSystemID))
                {
                    // No jumps in this system.
                    continue;
                }
                foreach (int destinationSystemID in systemDestinations[system.solarSystemID])
                {
                    if (!highSec)
                    {
                        // We don't care about security.
                        gateSystems.Add(destinationSystemID);
                    }
                    else
                    {
                        // We want to stay safe!
                        SolarSystem destinationSystem = GetSystem(destinationSystemID);
                        if (destinationSystem != null && destinationSystem.IsHighSec())
                        {
                            // Add the system.
                            gateSystems.Add(destinationSystemID);
                        }
                    }
                }
                // Process the destination systems.
                foreach (int destinationSystemID in gateSystems)
                {
                    // Does the system exist in the map?
                    if (distanceMap.ContainsKey(destinationSystemID))
                    {
                        // Was this a shorter route?
                        if (distanceMap[destinationSystemID] > distance)
                        {
                            // Yes, save the new distance.
                            distanceMap[destinationSystemID] = distance;
                            // Are we still waiting to map this system?
                            if (!systems.Contains(destinationSystemID))
                            {
                                // No, so we need to redo this system.
                                systems.Add(destinationSystemID);
                            }
                        }
                    }
                    else
                    {
                        // We have not reached this system before.
                        distanceMap[destinationSystemID] = distance;
                        // Add the system to parse list.
                        systems.Add(destinationSystemID);
                    }
                }
            }
            return(distanceMap);
        }
Example #2
0
 public static void Save(SolarSystem system, BinaryWriter save)
 {
     system.Save(save);
 }