Beispiel #1
0
        ///<summary>
        ///Using a direction point. Center will be established at the DirectionPoint center, with an area covering the start/end points.
        ///</summary>
        public GPRectangle(DirectionPoint Direction, PointCollection baseCache)
            : base(baseCache)
        {
            // Logger.DBLog.InfoFormat("StartPoint: {0} EndPoint {1} Range: {2}", Direction.StartingPoint.ToString(), Direction.EndingPoint.ToString(), Direction.Range);

            CreationVector = (Vector3)Direction.Center;
            GridPoint center_ = Direction.Center;

            searchablepoints_ = new List <GridPoint>();
            searchablepoints_.Add(center_);            //this is our first "surrounding" point to expand upon..
            this.centerpoint = Direction.Center;


            int expansion = (int)(Math.Round(Math.Sqrt(Direction.Range), MidpointRounding.AwayFromZero));             //Get the radius value and square it to get # of expansions we want..

            //Logger.DBLog.InfoFormat("Expansion count == {0}, Diameter == {1}", expansion, Diameter);

            //This will expand by finding new surrounding points
            for (int i = 0; i < expansion; i++)
            {
                if (searchablepoints_.Count == 0)
                {
                    break;                                               //no remaining searchable points..
                }
                this.FullyExpand();
            }

            this.UpdateQuadrants();

            UpdateObjectCount();
            lastRefreshedObjectContents = DateTime.Now;
        }
Beispiel #2
0
        ///<summary>
        ///Using a direction point. Center will be established at the DirectionPoint center, with an area covering the start/end points.
        ///</summary>
        public GPRectangle(DirectionPoint Direction)
            : base()
        {
            // Logger.DBLog.InfoFormat("StartPoint: {0} EndPoint {1} Range: {2}", Direction.StartingPoint.ToString(), Direction.EndingPoint.ToString(), Direction.Range);

            CreationVector = (Vector3)Direction.Center;
            GridPoint center_ = Direction.Center;
            searchablepoints_ = new List<GridPoint>();
            searchablepoints_.Add(center_);//this is our first "surrounding" point to expand upon..
            this.centerpoint = Direction.Center;

            int expansion = (int)(Math.Round(Math.Sqrt(Direction.Range), MidpointRounding.AwayFromZero)); //Get the radius value and square it to get # of expansions we want..
            //Logger.DBLog.InfoFormat("Expansion count == {0}, Diameter == {1}", expansion, Diameter);

            //This will expand by finding new surrounding points
            for (int i = 0; i < expansion; i++)
            {
                if (searchablepoints_.Count == 0) break; //no remaining searchable points..

                this.FullyExpand();
            }

            this.UpdateQuadrants();

            UpdateObjectCount();
            lastRefreshedObjectContents = DateTime.Now;
        }
Beispiel #3
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();
            }
        }
Beispiel #4
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();
            }
        }
Beispiel #5
0
        public Vector3 FindLocationBehindObject(CacheObject obj)
        {
            float rotation=FindDirection(FunkyGame.Hero.Position, obj.Position, true);
            Vector3 startLocation=MathEx.GetPointAt(obj.Position, obj.Radius, rotation);

            DirectionPoint dp = new DirectionPoint(startLocation, rotation, 35f);
            LocationalRects.Add(new GPRectangle(dp));

            DirectionPoint dp2 = new DirectionPoint(startLocation, MathEx.WrapAngle(rotation + 0.7f), 35f);
            LocationalRects.Add(new GPRectangle(dp2));

            DirectionPoint dp3 = new DirectionPoint(startLocation, MathEx.WrapAngle(rotation - 0.7f), 35f);
            LocationalRects.Add(new GPRectangle(dp3));

            List<GridPoint> blacklisted = new List<GridPoint>();
            Vector3 safespot=Vector3.Zero;
            foreach (var gpr in LocationalRects)
            {
                bool found=gpr.TryFindSafeSpot(FunkyGame.Hero.Position, out safespot, Vector3.Zero, PointCheckingFlags.AvoidanceIntersection | PointCheckingFlags.RaycastWalkable, blacklisted);
                if (found)
                {
                    break;
                }
            }

            return safespot;
        }