Beispiel #1
0
        /// <summary>Gets the position of a RemoteTech target from its id</summary>
        /// <returns>The absolute position or null if <paramref name="targetable"/> is neither
        /// a satellite nor a celestial body.</returns>
        /// <param name="targetable">The id of the satellite or celestial body whose position is
        ///     desired. May be the active vessel Guid.</param>
        ///
        /// <exceptsafe>The program state is unchanged in the event of an exception.</exceptsafe>
        internal Vector3d?GetPositionFromGuid(Guid targetable)
        {
            ISatellite targetSat = this[targetable];

            if (targetSat != null)
            {
                return(targetSat.Position);
            }

            if (Planets.ContainsKey(targetable))
            {
                return(Planets[targetable].position);
            }

            return(null);
        }
Beispiel #2
0
 public PlanetServerData GetPlanet(int id)
 {
     return(Planets.ContainsKey(id) ? Planets[id] : null);
 }
        private EdgeType IsConnectedTo(ISatellite a, ISatellite b)
        {
            bool los = LineOfSight(a, b) || CheatOptions.InfiniteEVAFuel;

            if (a == b || !los)
            {
                return(EdgeType.None);
            }

            float distance = Distance(a, b);

            if (distance < (a.Omni + b.Omni) / 2 && a.Omni > 0 && b.Omni > 0)
            {
                return(EdgeType.Omni);
            }

            float a_range = 0.0f;
            float b_range = 0.0f;

            foreach (Dish dish in a.Dishes.Where(d => d.Target == b.Guid))
            {
                a_range = Math.Max(a_range, dish.Distance);
            }

            foreach (Dish dish in a.Dishes.Where(d => Planets.ContainsKey(d.Target) &&
                                                 Planets[d.Target] == b.Body))
            {
                Vector3 dir_cb = (Planets[dish.Target].position - a.Position);
                Vector3 dir_b  = (b.Position - a.Position);
                if (Vector3.Dot(dir_cb.normalized, dir_b.normalized) >= dish.Factor)
                {
                    a_range = Math.Max(a_range, dish.Distance);
                }
            }

            foreach (Dish dish in b.Dishes.Where(d => d.Target == a.Guid))
            {
                b_range = Math.Max(b_range, dish.Distance);
            }

            foreach (Dish dish in b.Dishes.Where(d => Planets.ContainsKey(d.Target) &&
                                                 Planets[d.Target] == a.Body))
            {
                Vector3 dir_cb = (Planets[dish.Target].position - b.Position);
                Vector3 dir_a  = (a.Position - b.Position);
                if (Vector3.Dot(dir_cb.normalized, dir_a.normalized) >= dish.Factor)
                {
                    b_range = Math.Max(b_range, dish.Distance);
                }
            }

            if ((distance < (a_range + b_range) / 2 && a_range > 0 && b_range > 0) ||
                (distance < (a.Omni + b_range) / 2 && a.Omni > 0 && b_range > 0) ||
                (distance < (a_range + b.Omni) / 2 && a_range > 0 && b.Omni > 0))
            {
                return(EdgeType.Dish);
            }


            return(EdgeType.None);
        }