Esempio n. 1
0
        public RelayPath GetCommandPath(RelayNode start)
        {
            double    compare = double.MaxValue;
            RelayPath output  = null;

            foreach (RelayNode node in commandStations)
            {
                if (!start.Equals(node) && node.HasCommand)
                {
                    RelayPath tmp = findShortestRelayPath(start, node);
                    if (tmp != null && tmp.Length < compare)
                    {
                        output  = tmp;
                        compare = tmp.Length;
                    }
                }
            }
            return(output);
        }
Esempio n. 2
0
 public Target(string bodyOrNode)
 {
     foreach (CelestialBody bodies in FlightGlobals.Bodies)
     {
         if (bodies.name.ToLower().Equals(bodyOrNode.ToLower()))
         {
             this.referenceBody = bodies;
             this.isPlanet      = true;
             return;
         }
     }
     foreach (RelayNode nodes in RTGlobals.network.all)
     {
         if (nodes.ID.Equals(bodyOrNode))
         {
             this.node = nodes;
         }
     }
     if (this.referenceBody == null && this.node == null)
     {
         emptytarget = true;
     }
 }
Esempio n. 3
0
 bool InContactWith(RelayNode other)
 {
     return(contacts.Contains(other.ID));
 }
Esempio n. 4
0
        RelayPath findShortestRelayPath(RelayNode start, RelayNode goal)
        {
            HashSet <RelayNode> closedSet = new HashSet <RelayNode>();
            HashSet <RelayNode> openSet   = new HashSet <RelayNode>();

            Dictionary <RelayNode, RelayNode> cameFrom = new Dictionary <RelayNode, RelayNode>();
            Dictionary <RelayNode, double>    gScore   = new Dictionary <RelayNode, double>();
            Dictionary <RelayNode, double>    hScore   = new Dictionary <RelayNode, double>();
            Dictionary <RelayNode, double>    fScore   = new Dictionary <RelayNode, double>();

            openSet.Add(start);

            double startBaseHeuristic = (start.Position - goal.Position).magnitude;

            gScore[start] = 0.0;
            hScore[start] = startBaseHeuristic;
            fScore[start] = startBaseHeuristic;


            HashSet <RelayNode> neighbors = new HashSet <RelayNode>(all);

            neighbors.Add(start);
            neighbors.Add(goal);

            RelayPath path = null;

            while (openSet.Count > 0)
            {
                RelayNode current          = null;
                double    currentBestScore = double.MaxValue;
                foreach (KeyValuePair <RelayNode, double> pair in fScore)
                {
                    if (openSet.Contains(pair.Key) && pair.Value < currentBestScore)
                    {
                        current          = pair.Key;
                        currentBestScore = pair.Value;
                    }
                }
                if (current == goal)
                {
                    path = new RelayPath(reconstructPath(cameFrom, goal));
                    break;
                }
                openSet.Remove(current);
                closedSet.Add(current);
                foreach (RelayNode neighbor in neighbors)
                {
                    if (!closedSet.Contains(neighbor) && inRange(neighbor, current) && lineOfSight(neighbor, current))
                    {
                        //double tentGScore = gScore[current] - (neighbor.Position - current.Position).magnitude;
                        double tentGScore = gScore[current] + (neighbor.Position - current.Position).magnitude;

                        bool tentIsBetter = false;
                        if (!openSet.Contains(neighbor))
                        {
                            openSet.Add(neighbor);
                            hScore[neighbor] = (neighbor.Position - goal.Position).magnitude;
                            tentIsBetter     = true;
                        }
                        else if (tentGScore < gScore[neighbor])
                        {
                            tentIsBetter = true;
                        }

                        if (tentIsBetter)
                        {
                            cameFrom[neighbor] = current;
                            gScore[neighbor]   = tentGScore;
                            fScore[neighbor]   = tentGScore + hScore[neighbor];
                        }
                    }
                }
            }

            return(path);
        }
Esempio n. 5
0
 public bool inContactWith(RelayNode node, RelayNode other)
 {
     return(findShortestRelayPath(node, other) != null);
 }
Esempio n. 6
0
 public Target(RelayNode nodeIn)
 {
     this.node = nodeIn;
 }
Esempio n. 7
0
        public static float maxDistance(RelayNode na, RelayNode nb)
        {
            float aRange = 0, bRange = 0, aSumRange = 0, bSumRange = 0;
            float clamp = 1000f;
            bool  aDish = false, bDish = false;

            // get max-range dish pointed at other node
            if (na.HasDish)
            {
                foreach (DishData naData in na.DishData)
                {
                    if (((naData.pointedAt.Equals(nb.Orbits) && !na.Orbits.Equals(nb.Orbits)) || naData.pointedAt.Equals(nb.ID)))
                    {
                        aDish = true;
                        if (naData.dishRange >= aRange)
                        {
                            aRange = naData.dishRange;
                        }
                        aSumRange += naData.dishRange;
                    }
                }
            }
            if (RTGlobals.useMultiple)
            {
                aRange = (float)Math.Round(aRange + (aSumRange - aRange) * 0.25f);
            }

            if (nb.HasDish)
            {
                foreach (DishData nbData in nb.DishData)
                {
                    if (((nbData.pointedAt.Equals(na.Orbits) && !nb.Orbits.Equals(na.Orbits)) || nbData.pointedAt.Equals(na.ID)))
                    {
                        bDish = true;
                        if (nbData.dishRange >= bRange)
                        {
                            aRange = nbData.dishRange;
                        }
                        bSumRange += nbData.dishRange;
                    }
                }
            }
            if (RTGlobals.useMultiple)
            {
                bRange = (float)Math.Round(bRange + (bSumRange - bRange) * 0.25f);
            }

            // if no dish, get antenna. If neither, fail.
            if (!aDish)
            {
                clamp = 100f;
                if (na.HasAntenna)
                {
                    aRange = na.AntennaRange;
                }
                else
                {
                    return(0f);
                }
            }
            if (!bDish)
            {
                clamp = 100f;
                if (nb.HasAntenna)
                {
                    bRange = nb.AntennaRange;
                }
                else
                {
                    return(0f);
                }
            }

            // return distance using distance function; clamp to 1000x min range if both dishes or 100x if one or both isn't
            if (aRange < bRange)
            {
                return(distFunc(aRange, bRange, clamp * aRange));
            }
            else
            {
                return(distFunc(bRange, aRange, clamp * bRange));
            }
        }
Esempio n. 8
0
 public static float nodeDistance(RelayNode na, RelayNode nb)
 {
     return((float)(na.Position - nb.Position).magnitude);
 }