示例#1
0
        public static List<Vector2D> FindPath(RoomUser User, bool Diag, Gamemap Map, Vector2D Start, Vector2D End)
        {
            List<Vector2D> Path = new List<Vector2D>();

            PathFinderNode Nodes = FindPathReversed(User, Diag, Map, Start, End);

            if (Nodes != null)
            {
                Path.Add(End);

                while (Nodes.Next != null)
                {
                    Path.Add(Nodes.Next.Position);
                    Nodes = Nodes.Next;
                }
            }

            return Path;
        }
示例#2
0
        internal bool IsValidStep2(RoomUser User, Vector2D From, Vector2D To, bool EndOfPath, bool Override)
        {
            if (!ValidTile(To.X, To.Y))
            {
                return false;
            }

            if (Override)
            {
                return true;
            }

            /*
             * 0 = blocked
             * 1 = open
             * 2 = last step
             * 3 = door
             * */
            if ((this.mGameMap[To.X, To.Y] == 3 && !EndOfPath) ||
                    this.mGameMap[To.X, To.Y] == 0 || (this.mGameMap[To.X, To.Y] == 2 && !EndOfPath))
            {
                //User.Path.Clear();
                User.PathRecalcNeeded = true;

                return false;
            }

            var Userx = room.GetRoomUserManager().GetUserForSquare(To.X, To.Y);
            if (Userx != null)
            {
                if(!Userx.IsWalking && EndOfPath)
                    return false;
            }

            double HeightDiff = this.SqAbsoluteHeight(To.X, To.Y) - this.SqAbsoluteHeight(From.X, From.Y);

            if (HeightDiff > 1.5)
            {
                return false;
            }

            return true;
        }
示例#3
0
        internal bool IsValidStep( Vector2D From, Vector2D To, bool EndOfPath, bool Override)
        {
            if (!ValidTile(To.X, To.Y))
            {
                return false;
            }

            if (Override)
            {
                return true;
            }

            /*
             * 0 = blocked
             * 1 = open
             * 2 = last step
             * 3 = door
             * */
            if ((this.mGameMap[To.X, To.Y] == 3 && !EndOfPath) ||
                    this.mGameMap[To.X, To.Y] == 0 || (this.mGameMap[To.X, To.Y] == 2 && !EndOfPath))
            {
                return false;
            }

            double HeightDiff = this.SqAbsoluteHeight(To.X, To.Y) - this.SqAbsoluteHeight(From.X, From.Y);

            if (HeightDiff > 1.5)
            {
                return false;
            }

            return true;
        }
示例#4
0
        public static PathFinderNode FindPathReversed(RoomUser User, bool Diag, Gamemap Map, Vector2D Start, Vector2D End)
        {
            MinHeap<PathFinderNode> OpenList = new MinHeap<PathFinderNode>(256);

            PathFinderNode[,] PfMap = new PathFinderNode[Map.Model.MapSizeX, Map.Model.MapSizeY];
            PathFinderNode Node;
            Vector2D Tmp;
            int Cost;
            int Diff;

            PathFinderNode Current = new PathFinderNode(Start);
            Current.Cost = 0;

            PathFinderNode Finish = new PathFinderNode(End);
            PfMap[Current.Position.X, Current.Position.Y] = Current;
            OpenList.Add(Current);

            while (OpenList.Count > 0)
            {
                Current = OpenList.ExtractFirst();
                Current.InClosed = true;

                for (int i = 0; Diag ? i < DiagMovePoints.Length : i < NoDiagMovePoints.Length; i++)
                {
                    Tmp = Current.Position + (Diag ? DiagMovePoints[i] : NoDiagMovePoints[i]);
                    bool IsFinalMove = (Tmp.X == End.X && Tmp.Y == End.Y);

                    if (Map.IsValidStep(new Vector2D(Current.Position.X, Current.Position.Y), Tmp, IsFinalMove, User.AllowOverride))
                    {
                        if (PfMap[Tmp.X, Tmp.Y] == null)
                        {
                            Node = new PathFinderNode(Tmp);
                            PfMap[Tmp.X, Tmp.Y] = Node;
                        }
                        else
                        {
                            Node = PfMap[Tmp.X, Tmp.Y];
                        }

                        if (!Node.InClosed)
                        {
                            Diff = 0;

                            if (Current.Position.X != Node.Position.X)
                            {
                                Diff += 1;
                            }

                            if (Current.Position.Y != Node.Position.Y)
                            {
                                Diff += 1;
                            }

                            Cost = Current.Cost + Diff + Node.Position.GetDistanceSquared(End);

                            if (Cost < Node.Cost)
                            {
                                Node.Cost = Cost;
                                Node.Next = Current;
                            }

                            if (!Node.InOpen)
                            {
                                if (Node.Equals(Finish))
                                {
                                    Node.Next = Current;
                                    return Node;
                                }

                                Node.InOpen = true;
                                OpenList.Add(Node);
                            }
                        }
                    }
                }
            }

            return null;
        }
示例#5
0
 public int GetDistanceSquared(Vector2D Point)
 {
     int dx = this.X - Point.X;
     int dy = this.Y - Point.Y;
     return (dx * dx) + (dy * dy);
 }