RelayPath findShortestRelayPath()
    {
        Vector3d baseRelay = computeBaseRelayPosition();

        List<RelayPath> paths = new List<RelayPath>();
        paths.Add(new RelayPath(this.vessel));

        List<Vessel> routedVessels = new List<Vessel>();

        while (true)
        {
            //find shortest path in list
            RelayPath shortestPath = null;
            foreach (RelayPath path in paths)
            {
                if (shortestPath == null || path.Length < shortestPath.Length) shortestPath = path;
            }

            if (shortestPath == null) return null;

            if (shortestPath.Terminated) return shortestPath;

            paths.Remove(shortestPath);

            if (routedVessels.Contains(shortestPath.Endpoint))
            {
                print("ARRemotePod: pathing error?");
            }
            else
            {
                routedVessels.Add(shortestPath.Endpoint);
            }

            if (lineOfSight(shortestPath.Endpoint.transform.position, baseRelay))
            {
                RelayPath newPath = new RelayPath(shortestPath);
                newPath.terminate(baseRelay);
                paths.Add(newPath);
            }

            foreach (Vessel v in FlightGlobals.Vessels)
            {
                if (isComsat(v) && !routedVessels.Contains(v) && lineOfSight(v.transform.position, shortestPath.Endpoint.transform.position))
                {
                    RelayPath newPath = new RelayPath(shortestPath);
                    newPath.Add(v);
                    paths.Add(newPath);
                }
            }
        }
    }
 public RelayPath(RelayPath rhs)
 {
     this.relays = new List<Vessel>(rhs.relays);
     this.terminated = rhs.terminated;
     this.lastLegLength = rhs.lastLegLength;
 }
    protected override void onPartFixedUpdate()
    {
        if (ticksSinceContactCheck++ > 100)
        {
            ticksSinceContactCheck = 0;

            controlPath = findShortestRelayPath();
            if (controlPath == null)
            {
                inRadioContact = false;
                print("ARRemotePod: no radio contact!!");
            }
            else
            {
                inRadioContact = true;
                controlDelay = 2 * controlPath.Length / speedOfLight;
                print("ARRemotePod: radio contact: " + controlPath.ToString());
                print("ARRemotePod: signal path length (km) = " + controlPath.Length / 1000.0 + "; round trip time (s) = " + controlDelay);
            }
        }

        base.onPartFixedUpdate();
    }