GridPointCircle A collection of GridPoints that is surrounding a given vector3. Allows safespot finding and will iterate thru its sectors to find any safespots contained within.
상속: PointCollection
예제 #1
0
 public GPRectangle(GPRectangle clone)
     : base(clone)
 {
     base.CornerPoints      = clone.CornerPoints;
     this.Quadrant          = clone.Quadrant;
     this.CreationVector    = clone.CreationVector;
     this.searchablepoints_ = clone.searchablepoints_;
 }
예제 #2
0
 public override bool Equals(object obj)
 {
     //Check for null and compare run-time types.
     if (obj == null || this.GetType() != obj.GetType())
     {
         return(false);
     }
     else
     {
         GPRectangle p = (GPRectangle)obj;
         return(CreationVector.Equals(p.CreationVector));
     }
 }
예제 #3
0
        private void iterateGPRectsSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 LOS, PointCheckingFlags Flags)
        {
            //blacklisted a point?.. we advance to next index!
            if (BlacklistedPoint)
            {
                lastGPRectIndexUsed++;
                BlacklistedPoint = false;
            }

            GPRectangle PositionRect = GetGPRectContainingPoint(CurrentPosition);

            if (PositionRect != null)
            {
                PositionRect.UpdateObjectCount();
            }

            GPQuadrant PositionQuadrant = PositionRect.GetQuadrantContainingPoint(CurrentPosition);
            double     CompareWeight    = PositionQuadrant != null ? PositionQuadrant.ThisWeight : PositionRect != null ? PositionRect.Weight : 0;

            safespot = Vector3.Zero;
            Dictionary <Vector3, int> safespotsFound = new Dictionary <Vector3, int>();

            for (int i = lastGPRectIndexUsed; i < gridpointrectangles_.Count - 1; i++)
            {
                GPRectangle item = gridpointrectangles_[i];

                item.UpdateObjectCount(AllGPRectsFailed);
                Vector3 safespotRect;
                if (item.TryFindSafeSpot(CurrentPosition, out safespotRect, LOS, Flags, BlacklistedGridpoints, AllGPRectsFailed, CompareWeight))
                {
                    safespotsFound.Add(safespotRect, i);
                    BlacklistedGridpoints.Add(safespotRect);
                }
            }

            if (safespotsFound.Count > 0)
            {
                lastfoundsafespots.Clear();
                Logger.DBLog.InfoFormat("Found a total of {0} possible safe spots!", safespotsFound.Count);

                List <Vector3> safeVectors = new List <Vector3>(safespotsFound.Keys.OrderBy(o => o.Distance(FunkyGame.Hero.Position)).ToList());
                lastfoundsafespots.AddRange(safeVectors);

                safespot       = lastfoundsafespots.First();
                lastUsedGPRect = gridpointrectangles_[safespotsFound[safespot]];
            }



            lastGPRectIndexUsed = 0;
        }
예제 #4
0
파일: GPArea.cs 프로젝트: herbfunk/Funky
        public GPArea(Vector3 startingLocation)
        {
            StartingLocation=startingLocation;

            //Creation and Cache base
            centerGPRect = new GPRectangle(startingLocation, 5);
            GPRectangle centerClone = centerGPRect.Clone();

            //Get all valid points (besides current point) from our current location GPR
            GridPoint[] SearchPoints = centerGPRect.Points.Keys.Where(gp => !gp.Ignored).ToArray();
            gridpointrectangles_ = new List<GPRectangle>();
            if (SearchPoints.Length > 1)
            {

                Vector3 LastSearchVector3 = FunkyGame.Navigation.LastSearchVector;
                // LastSearchVector3.Normalize();

                //we should check our surrounding points to see if we can even move into any of them first!
                for (int i = 1; i < SearchPoints.Length - 1; i++)
                {
                    GridPoint curGP = SearchPoints[i];
                    Vector3 thisV3 = (Vector3)curGP;
                    //thisV3.Normalize();

                    //Its a valid point for direction testing!
                    float DirectionDegrees = Navigation.FindDirection(LastSearchVector3, thisV3);
                    DirectionPoint P = new DirectionPoint((Vector3)curGP, DirectionDegrees, 125f);

                    if (P.Range > 5f)
                    {
                        gridpointrectangles_.Add(new GPRectangle(P, centerGPRect));
                    }
                }
                gridpointrectangles_.Add(centerClone);
                gridpointrectangles_ = gridpointrectangles_.OrderByDescending(gpr => gpr.Count).ToList();
            }
        }
예제 #5
0
        public GPArea(Vector3 startingLocation)
        {
            StartingLocation = startingLocation;

            //Creation and Cache base
            centerGPRect = new GPRectangle(startingLocation, 5);
            GPRectangle centerClone = centerGPRect.Clone();

            //Get all valid points (besides current point) from our current location GPR
            GridPoint[] SearchPoints = centerGPRect.Points.Keys.Where(gp => !gp.Ignored).ToArray();
            gridpointrectangles_ = new List <GPRectangle>();
            if (SearchPoints.Length > 1)
            {
                Vector3 LastSearchVector3 = FunkyGame.Navigation.LastSearchVector;
                // LastSearchVector3.Normalize();

                //we should check our surrounding points to see if we can even move into any of them first!
                for (int i = 1; i < SearchPoints.Length - 1; i++)
                {
                    GridPoint curGP  = SearchPoints[i];
                    Vector3   thisV3 = (Vector3)curGP;
                    //thisV3.Normalize();

                    //Its a valid point for direction testing!
                    float          DirectionDegrees = Navigation.FindDirection(LastSearchVector3, thisV3);
                    DirectionPoint P = new DirectionPoint((Vector3)curGP, DirectionDegrees, 125f);

                    if (P.Range > 5f)
                    {
                        gridpointrectangles_.Add(new GPRectangle(P, centerGPRect));
                    }
                }
                gridpointrectangles_.Add(centerClone);
                gridpointrectangles_ = gridpointrectangles_.OrderByDescending(gpr => gpr.Count).ToList();
            }
        }
예제 #6
0
파일: GPArea.cs 프로젝트: herbfunk/Funky
        private void iterateGPRectsSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 LOS, PointCheckingFlags Flags)
        {
            //blacklisted a point?.. we advance to next index!
            if (BlacklistedPoint)
            {
                lastGPRectIndexUsed++;
                BlacklistedPoint = false;
            }

            GPRectangle PositionRect = GetGPRectContainingPoint(CurrentPosition);
            if (PositionRect != null) PositionRect.UpdateObjectCount();

            GPQuadrant PositionQuadrant = PositionRect.GetQuadrantContainingPoint(CurrentPosition);
            double CompareWeight = PositionQuadrant != null ? PositionQuadrant.ThisWeight : PositionRect != null ? PositionRect.Weight : 0;

            safespot = Vector3.Zero;
            Dictionary<Vector3, int> safespotsFound = new Dictionary<Vector3, int>();
            for (int i = lastGPRectIndexUsed; i < gridpointrectangles_.Count - 1; i++)
            {
                GPRectangle item = gridpointrectangles_[i];

                item.UpdateObjectCount(AllGPRectsFailed);
                Vector3 safespotRect;
                if (item.TryFindSafeSpot(CurrentPosition, out safespotRect, LOS, Flags, BlacklistedGridpoints, AllGPRectsFailed, CompareWeight))
                {
                    safespotsFound.Add(safespotRect, i);
                    BlacklistedGridpoints.Add(safespotRect);
                }
            }

            if (safespotsFound.Count>0)
            {
                lastfoundsafespots.Clear();
                Logger.DBLog.InfoFormat("Found a total of {0} possible safe spots!", safespotsFound.Count);

                List<Vector3> safeVectors=new List<Vector3>(safespotsFound.Keys.OrderBy(o => o.Distance(FunkyGame.Hero.Position)).ToList());
                lastfoundsafespots.AddRange(safeVectors);

                safespot = lastfoundsafespots.First();
                lastUsedGPRect = gridpointrectangles_[safespotsFound[safespot]];
            }

            lastGPRectIndexUsed = 0;
        }
예제 #7
0
        ///<summary>
        ///Checks if the position is total blocked from adjacent movements either by objects or non navigation
        ///</summary>
        private bool IsVectorBlocked(Vector3 location)
        {
            //Reset Navigationally Blocked GPs
            LastNavigationBlockedPoints = new List<GridPoint>();

            //Create Local GPRect!
            if (LastUsedBlockCheckGPRect == null || LastUsedBlockCheckGPRect.centerpoint != (GridPoint)location)
            {
                //Clear lists
                LastObjectblockCounter.Clear();
                LastObjectOccupiedGridPoints.Clear();
                LastUsedBlockCheckGPRect = new GPRectangle(location);
            }

            if (LastUsedBlockCheckGPRect.Count == 0)
            {
                //Logger.DBLog.DebugFormat("Current Location GP Rect has no valid Grid Points!");
                return false;
            }

            GridPoint[] CurrentLocationGridPoints = LastUsedBlockCheckGPRect.Keys.ToArray();
            List<GridPoint> SurroundingPoints = new List<GridPoint>();
            int SurroundingMaxCount = LastUsedBlockCheckGPRect.Count >= 8 ? 8 : LastUsedBlockCheckGPRect.Count;
            for (int i = 0; i < SurroundingMaxCount; i++)
            {
                GridPoint gp = CurrentLocationGridPoints[i];
                if (!gp.Ignored)
                    SurroundingPoints.Add(gp);
                else
                    LastNavigationBlockedPoints.Add(gp);
            }

            List<int> NearbyObjectRAGUIDs = new List<int>();
            List<CacheServerObject> NearbyObjects = FunkyGame.Targeting.Cache.Environment.NearbyObstacleObjects.Where(obj => obj.RadiusDistance <= 6f).ToList();//ObjectCache.Obstacles.Navigations.Where(obj => obj.RadiusDistance<=5f).ToList();

            //no nearby objects passed distance check..
            if (NearbyObjects.Count == 0)
            {
                //Clear list, and return pure navigational check (Zero means we are completely stuck in a non-navigable location?)
                LastObjectblockCounter.Clear();
                LastObjectOccupiedGridPoints.Clear();

                //Logger.DBLog.InfoFormat("Current Location Point has {0} usable points (NoNewObjs)", SurroundingPoints.Count);

                return (SurroundingPoints.Count == 0);
            }

            //Update ObjectBlockCounter Collection
            if (LastObjectblockCounter.Count > 0)
            {
                //Add current nearby object RAGUIDs to collection
                NearbyObjectRAGUIDs.AddRange((from objs in NearbyObjects
                                              select objs.RAGUID).ToArray());

                //Generate Removal List for ObjectBlockCounter Collections
                List<int> RemovalRAGUIDList = (from raguids in LastObjectblockCounter.Keys
                                               where !NearbyObjectRAGUIDs.Contains(raguids)
                                               select raguids).ToList();

                //Removal
                foreach (var item in RemovalRAGUIDList)
                {
                    LastObjectblockCounter.Remove(item);
                    LastObjectOccupiedGridPoints.Remove(item);
                }
            }

            //Check any exisiting block entries
            if (LastObjectblockCounter.Count > 0)
            {
                foreach (var item in LastObjectOccupiedGridPoints.Values)
                {
                    LastNavigationBlockedPoints.AddRange(item);
                }

                //Update Surrounding Points
                SurroundingPoints = SurroundingPoints.Except(LastNavigationBlockedPoints).ToList();

                if (SurroundingPoints.Count == 0)
                {
                    //Logger.DBLog.InfoFormat("NavBlocked -- No available surrounding points.");

                    return true;
                }
            }

            //Generate new object list that contains objects that are not already accounted for
            List<CacheServerObject> NewObjects = NearbyObjects.Where(obj => !LastObjectblockCounter.ContainsKey(obj.RAGUID) || LastObjectblockCounter[obj.RAGUID] < 4).ToList();

            //No new objects to test..
            if (NewObjects.Count == 0)
            {
                //Logger.DBLog.InfoFormat("No new Objects Unaccounted");

                return (SurroundingPoints.Count == 0);
            }

            foreach (GridPoint item in SurroundingPoints)
            {
                //Find any objects that contain this GP
                CacheServerObject[] ContainedObjs = NewObjects.Where(Obj => Obj.PointInside(item)			   //only objects that have hit there maximum block count.
                                                                                && (!LastObjectblockCounter.ContainsKey(Obj.RAGUID) || Math.Round(Obj.PointRadius) < LastObjectblockCounter[Obj.RAGUID])).ToArray();
                if (ContainedObjs.Length > 0)
                {
                    //if (ContainedObjs.Length > 1 && FunkyBaseExtension.Settings.Debugging.FunkyLogFlags.HasFlag(LogLevel.Movement))
                        //Logger.DBLog.InfoFormat("Multiple Objects Found Occuping Grid Point!");

                    CacheServerObject ThisObjBlocking = ContainedObjs[0];
                    int ObjRAGUID = ThisObjBlocking.RAGUID;

                    if (LastObjectblockCounter.ContainsKey(ObjRAGUID))
                    {
                        int GPCount = LastObjectOccupiedGridPoints[ObjRAGUID].Length;
                        LastObjectblockCounter[ObjRAGUID]++;
                        GridPoint[] newArrayGPs = new GridPoint[GPCount];
                        LastObjectOccupiedGridPoints[ObjRAGUID].CopyTo(newArrayGPs, 0);
                        newArrayGPs[GPCount - 1] = item.Clone();
                        LastObjectOccupiedGridPoints[ObjRAGUID] = newArrayGPs;
                    }
                    else
                    {
                        LastObjectblockCounter.Add(ObjRAGUID, 1);
                        GridPoint[] NewArrayGP = new GridPoint[1] { item.Clone() };
                        LastObjectOccupiedGridPoints.Add(ObjRAGUID, NewArrayGP);
                    }

                    LastNavigationBlockedPoints.Add(item);
                }
            }

            //Update Surrounding Points
            SurroundingPoints = SurroundingPoints.Except(LastNavigationBlockedPoints).ToList();

            //Logger.DBLog.InfoFormat("Current Location Point has {0} usable points", SurroundingPoints.Count);

            return (SurroundingPoints.Count == 0);
        }
예제 #8
0
 public GPRectangle(GPRectangle clone)
     : base(clone)
 {
     base.CornerPoints = clone.CornerPoints;
     this.Quadrant = clone.Quadrant;
     this.CreationVector = clone.CreationVector;
     this.searchablepoints_ = clone.searchablepoints_;
 }
예제 #9
0
 ///<summary>
 ///Used to recreate from temp into obstacle object.
 ///</summary>
 public CacheObject(CacheObject parent)
     : base(parent)
 {
     WorldID = parent.WorldID;
     LevelAreaID = parent.LevelAreaID;
     CreationTime=parent.CreationTime;
     AcdGuid = parent.AcdGuid;
     BlacklistFlag = parent.BlacklistFlag;
     BlacklistLoops_ = parent.BlacklistLoops_;
     gprect_ = parent.gprect_;
     InteractionAttempts = parent.InteractionAttempts;
     lineofsight = new LOSInfo(this);
     LoopsUnseen_ = parent.LoopsUnseen_;
     losv3_ = parent.losv3_;
     LosSearchRetryMilliseconds_ = parent.LosSearchRetryMilliseconds_;
     NeedsRemoved = parent.NeedsRemoved;
     NeedsUpdate = parent.NeedsUpdate;
     PrioritizedDate = parent.PrioritizedDate;
     PriorityCounter = parent.PriorityCounter;
     position_ = parent.Position;
     radius_ = parent.Radius;
     RAGUID = parent.RAGUID;
     ref_DiaObject = parent.ref_DiaObject;
     removal_ = parent.removal_;
     RequiresLOSCheck = parent.RequiresLOSCheck;
     SummonerID = parent.SummonerID;
     weight_ = parent.Weight;
     HandleAsAvoidanceObject = parent.HandleAsAvoidanceObject;
     Properties = parent.Properties;
     QuestMonster=parent.QuestMonster;
     _skillsUsedOnObject = new Dictionary<SNOPower, DateTime>();
 }