Example #1
0
        /// <summary>
        /// Returns the Unit that is closest within the given Radius around this Object
        /// TODO: Should add visibility test?
        /// </summary>
        public static Unit GetNearestUnit(this IWorldLocation wObj, float radius)
        {
            Unit unit   = null;
            var  sqDist = float.MaxValue;

            wObj.IterateEnvironment <Unit>(radius, obj =>
            {
                var curSqDist = obj.GetDistanceSq(wObj);
                if (curSqDist < sqDist)
                {
                    sqDist = curSqDist;
                    unit   = obj;
                }
                return(true);
            }
                                           );
            return(unit);
        }
Example #2
0
        /// <summary>
        /// Returns the Unit that is closest within the given Radius around this Object
        /// TODO: Should add visibility test?
        /// </summary>
        public static Unit GetNearestUnit(this IWorldLocation wObj, float radius)
        {
            Unit  unit   = (Unit)null;
            float sqDist = float.MaxValue;

            wObj.IterateEnvironment <Unit>(radius, (Func <Unit, bool>)(obj =>
            {
                float distanceSq = obj.GetDistanceSq((IHasPosition)wObj);
                if ((double)distanceSq < (double)sqDist)
                {
                    sqDist = distanceSq;
                    unit   = obj;
                }

                return(true);
            }));
            return(unit);
        }
Example #3
0
        /// <summary>
        /// Returns the Unit that is closest within the given Radius around this Object and passes the filter
        /// </summary>
        public static Unit GetNearestUnit(this IWorldLocation wObj, float radius, Func <Unit, bool> filter)
        {
            Unit target = null;
            var  sqDist = float.MaxValue;

            wObj.IterateEnvironment <Unit>(radius, unit =>
            {
                if (filter(unit))
                {
                    var curSqDist = unit.GetDistanceSq(wObj);
                    if (curSqDist < sqDist)
                    {
                        sqDist = curSqDist;
                        target = unit;
                    }
                }
                return(true);
            }
                                           );
            return(target);
        }
Example #4
0
        /// <summary>
        /// Returns the Unit that is closest within the given Radius around this Object and passes the filter
        /// </summary>
        public static Unit GetNearestUnit(this IWorldLocation wObj, float radius, Func <Unit, bool> filter)
        {
            Unit  target = (Unit)null;
            float sqDist = float.MaxValue;

            wObj.IterateEnvironment <Unit>(radius, (Func <Unit, bool>)(unit =>
            {
                if (filter(unit))
                {
                    float distanceSq = unit.GetDistanceSq((IHasPosition)wObj);
                    if ((double)distanceSq < (double)sqDist)
                    {
                        sqDist = distanceSq;
                        target = unit;
                    }
                }

                return(true);
            }));
            return(target);
        }