Example #1
0
 private static void LinkNodes(int playerId, LinkNodeChild from, int toId, float totalDist)
 {
     if (from == null)
     {
         return;
     }
     foreach (LinkNodeChild from1 in Kerberos.Sots.StarSystemPathing.StarSystemPathing._playerSystemNodes[playerId][from.SystemId])
     {
         float totalDist1 = from1.Distance + totalDist;
         if (!from1.HasBeenChecked || (double)totalDist1 < (double)from1.TotalDistance)
         {
             from1.TotalDistance  = totalDist1;
             from1.ParentLink     = from;
             from1.HasBeenChecked = true;
             if (from1.SystemId != toId)
             {
                 Kerberos.Sots.StarSystemPathing.StarSystemPathing.LinkNodes(playerId, from1, toId, totalDist1);
             }
         }
     }
 }
Example #2
0
        public static List <int> FindClosestPath(
            GameDatabase db,
            int playerId,
            int fromSystemId,
            int toSystemId,
            bool nodeLinesOnly)
        {
            if (!Kerberos.Sots.StarSystemPathing.StarSystemPathing._playerSystemNodes.ContainsKey(playerId) || fromSystemId == 0 || toSystemId == 0)
            {
                return(new List <int>());
            }
            int num1         = Kerberos.Sots.StarSystemPathing.StarSystemPathing.ClosestNodeSystem(db, playerId, fromSystemId);
            int toNodeSystem = Kerberos.Sots.StarSystemPathing.StarSystemPathing.ClosestNodeSystem(db, playerId, toSystemId);

            if (num1 <= 0 || toNodeSystem <= 0 || nodeLinesOnly && (num1 != fromSystemId || toNodeSystem != toSystemId))
            {
                return(new List <int>());
            }
            foreach (KeyValuePair <int, List <LinkNodeChild> > keyValuePair in Kerberos.Sots.StarSystemPathing.StarSystemPathing._playerSystemNodes[playerId])
            {
                foreach (LinkNodeChild linkNodeChild in keyValuePair.Value)
                {
                    linkNodeChild.HasBeenChecked = linkNodeChild.SystemId == num1;
                    linkNodeChild.ParentLink     = (LinkNodeChild)null;
                    linkNodeChild.TotalDistance  = 0.0f;
                }
            }
            LinkNodeChild from = new LinkNodeChild()
            {
                ParentLink     = (LinkNodeChild)null,
                HasBeenChecked = true,
                SystemId       = num1,
                Distance       = 0.0f,
                TotalDistance  = 0.0f,
                NodeId         = 0
            };

            Kerberos.Sots.StarSystemPathing.StarSystemPathing.LinkNodes(playerId, from, toNodeSystem, 0.0f);
            List <LinkNodeChild> linkNodeChildList = new List <LinkNodeChild>();

            foreach (KeyValuePair <int, List <LinkNodeChild> > keyValuePair in Kerberos.Sots.StarSystemPathing.StarSystemPathing._playerSystemNodes[playerId])
            {
                linkNodeChildList.AddRange((IEnumerable <LinkNodeChild>)keyValuePair.Value.Where <LinkNodeChild>((Func <LinkNodeChild, bool>)(x => x.SystemId == toNodeSystem)).ToList <LinkNodeChild>());
            }
            LinkNodeChild linkNodeChild1 = (LinkNodeChild)null;
            float         num2           = float.MaxValue;

            foreach (LinkNodeChild linkNodeChild2 in linkNodeChildList)
            {
                bool flag = false;
                for (LinkNodeChild linkNodeChild3 = linkNodeChild2; linkNodeChild3 != null; linkNodeChild3 = linkNodeChild3.ParentLink)
                {
                    if (linkNodeChild3.SystemId == num1)
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag && (double)linkNodeChild2.TotalDistance < (double)num2)
                {
                    linkNodeChild1 = linkNodeChild2;
                    num2           = linkNodeChild2.TotalDistance;
                }
            }
            List <int> source = new List <int>();

            if (linkNodeChild1 != null)
            {
                if (linkNodeChild1.SystemId != toSystemId)
                {
                    source.Add(toSystemId);
                }
                for (; linkNodeChild1 != null; linkNodeChild1 = linkNodeChild1.ParentLink)
                {
                    source.Add(linkNodeChild1.SystemId);
                }
                if (source.ElementAt <int>(source.Count - 1) != fromSystemId)
                {
                    source.Add(fromSystemId);
                }
            }
            source.Reverse();
            foreach (KeyValuePair <int, List <LinkNodeChild> > keyValuePair in Kerberos.Sots.StarSystemPathing.StarSystemPathing._playerSystemNodes[playerId])
            {
                foreach (LinkNodeChild linkNodeChild2 in keyValuePair.Value)
                {
                    linkNodeChild2.HasBeenChecked = false;
                    linkNodeChild2.ParentLink     = (LinkNodeChild)null;
                    linkNodeChild2.TotalDistance  = 0.0f;
                }
            }
            return(source);
        }