Example #1
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;
        }
Example #2
0
        private void UpdateQuadrants()
        {
            QuadrantLocation[] sectors_    = Quadrant.Keys.ToArray();
            string             debugstring = "";

            foreach (var item in sectors_)
            {
                GridPoint   cornerPoint;
                GridPoint[] sectorpoints = this.QuadrantPoints(item, out cornerPoint);
                if (sectorpoints == null || cornerPoint == null)
                {
                    this.Quadrant[item] = null;
                    continue;
                }
                //Logger.DBLog.InfoFormat("Sectorpoints Count {0}", sectorpoints.Length);
                Quadrant[item] = new GPQuadrant(sectorpoints, CreationVector, cornerPoint);

                //item = new Sector(Points.SectorPoints(item.SectorCode, true));
                debugstring += "SectorID: " + item.ToString() + " " + Quadrant[item].ContainedPoints.Count + ",";
            }

            //if (FunkyBaseExtension.SettingsFunky.Debug.FunkyLogFlags.HasFlag(LogLevel.Movement))
            //	 Logger.DBLog.DebugFormat(debugstring);
        }
Example #3
0
        private void UpdateQuadrants()
        {
            QuadrantLocation[] sectors_ = Quadrant.Keys.ToArray();
            string debugstring = "";

            foreach (var item in sectors_)
            {
                GridPoint cornerPoint;
                GridPoint[] sectorpoints = this.QuadrantPoints(item, out cornerPoint);
                if (sectorpoints == null || cornerPoint == null)
                {
                    this.Quadrant[item] = null;
                    continue;
                }
                //Logger.DBLog.InfoFormat("Sectorpoints Count {0}", sectorpoints.Length);
                Quadrant[item] = new GPQuadrant(sectorpoints, CreationVector, cornerPoint);

                //item = new Sector(Points.SectorPoints(item.SectorCode, true));
                debugstring += "SectorID: " + item.ToString() + " " + Quadrant[item].ContainedPoints.Count + ",";
            }

            //if (FunkyBaseExtension.SettingsFunky.Debug.FunkyLogFlags.HasFlag(LogLevel.Movement))
            //	 Logger.DBLog.DebugFormat(debugstring);
        }
Example #4
0
        public bool TryFindSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 los, PointCheckingFlags Flags, List<GridPoint> BlacklistedPoints, bool expandOnFailure = false, double CurrentWeight = 0)
        {
            lastUsedQuadrant = null;
            safespot = Vector3.Zero;

            //Do not continue search if all sectors failed recently.
            if (AllQuadrantsFailed) return false;

            bool CheckingWeight = (CurrentWeight > 0);

            foreach (var item in Quadrant.Values)
            {
                if (item == null) continue;

                if (CheckingWeight && item.ThisWeight > CurrentWeight)
                    continue;

                if (item.FindSafeSpot(CurrentPosition, out safespot, los, Flags, BlacklistedPoints))
                {
                    lastUsedQuadrant = item;
                    return true;
                }
            }

            AllQuadrantsFailed = true;

            if (expandOnFailure && CanExpandFurther)
            {
                //Logger.DBLog.InfoFormat("Expanding GPC due to failure to find a location!");
                this.FullyExpand();
                this.UpdateQuadrants();
                this.UpdateObjectCount();
            }
            return false;
        }