Example #1
0
 public PathFindController(Character c, GameLocation location, PathFindController.isAtEnd endFunction, int finalFacingDirection, bool eraseOldPathController, PathFindController.endBehavior endBehaviorFunction, int limit, Point endPoint)
 {
     this.limit     = limit;
     this.character = c;
     if (c is NPC && (c as NPC).CurrentDialogue.Count > 0 && (c as NPC).CurrentDialogue.Peek().removeOnNextMove)
     {
         (c as NPC).CurrentDialogue.Pop();
     }
     this.location            = location;
     this.endFunction         = endFunction == null ? new PathFindController.isAtEnd(PathFindController.isAtEndPoint) : endFunction;
     this.endBehaviorFunction = endBehaviorFunction;
     if (endPoint == Point.Zero)
     {
         endPoint = new Point((int)c.getTileLocation().X, (int)c.getTileLocation().Y);
     }
     this.finalFacingDirection = finalFacingDirection;
     if (!(this.character is NPC) && !Game1.currentLocation.Name.Equals(location.Name) && (endFunction == new PathFindController.isAtEnd(PathFindController.isAtEndPoint) && endPoint.X > 0) && endPoint.Y > 0)
     {
         this.character.position = new Vector2((float)(endPoint.X * Game1.tileSize), (float)(endPoint.Y * Game1.tileSize - Game1.tileSize / 2));
     }
     else
     {
         this.pathToEndPoint = PathFindController.findPath(new Point((int)c.getTileLocation().X, (int)c.getTileLocation().Y), endPoint, endFunction, location, this.character, limit);
         if (this.pathToEndPoint != null)
         {
             return;
         }
         FarmHouse farmHouse = location as FarmHouse;
     }
 }
        public static Stack <Point> findPath(Point startPoint, Point endPoint, PathFindController.isAtEnd endPointFunction, GameLocation location, Character character, int limit)
        {
            sbyte[,] array = new sbyte[, ]
            {
                {
                    -1,
                    0
                },
                {
                    1,
                    0
                },
                {
                    0,
                    1
                },
                {
                    0,
                    -1
                }
            };
            PriorityQueue priorityQueue = new PriorityQueue();
            Dictionary <PathNode, PathNode> dictionary = new Dictionary <PathNode, PathNode>();
            int num = 0;

            priorityQueue.Enqueue(new PathNode(startPoint.X, startPoint.Y, 0, null), Math.Abs(endPoint.X - startPoint.X) + Math.Abs(endPoint.Y - startPoint.Y));
            while (!priorityQueue.IsEmpty())
            {
                PathNode pathNode = priorityQueue.Dequeue();
                if (endPointFunction(pathNode, endPoint, location, character))
                {
                    return(PathFindController.reconstructPath(pathNode, dictionary));
                }
                if (!dictionary.ContainsKey(pathNode))
                {
                    dictionary.Add(pathNode, pathNode.parent);
                }
                for (int i = 0; i < 4; i++)
                {
                    PathNode pathNode2 = new PathNode(pathNode.x + (int)array[i, 0], pathNode.y + (int)array[i, 1], pathNode);
                    pathNode2.g = pathNode.g + 1;
                    if (!dictionary.ContainsKey(pathNode2) && ((pathNode2.x == endPoint.X && pathNode2.y == endPoint.Y) || (pathNode2.x >= 0 && pathNode2.y >= 0 && pathNode2.x < location.map.Layers[0].LayerWidth && pathNode2.y < location.map.Layers[0].LayerHeight)) && !location.isCollidingPosition(new Rectangle(pathNode2.x * Game1.tileSize + 1, pathNode2.y * Game1.tileSize + 1, Game1.tileSize - 2, Game1.tileSize - 2), Game1.viewport, false, 0, false, character, true, false, false))
                    {
                        int priority = (int)pathNode2.g + (Math.Abs(endPoint.X - pathNode2.x) + Math.Abs(endPoint.Y - pathNode2.y));
                        if (!priorityQueue.Contains(pathNode2, priority))
                        {
                            priorityQueue.Enqueue(pathNode2, priority);
                        }
                    }
                }
                num++;
                if (num >= limit)
                {
                    return(null);
                }
            }
            return(null);
        }
Example #3
0
        public static Stack <Point> findPath(Point startPoint, Point endPoint, PathFindController.isAtEnd endPointFunction, GameLocation location, Character character, int limit)
        {
            sbyte[,] numArray = new sbyte[4, 2]
            {
                {
                    (sbyte)-1,
                    (sbyte)0
                },
                {
                    (sbyte)1,
                    (sbyte)0
                },
                {
                    (sbyte)0,
                    (sbyte)1
                },
                {
                    (sbyte)0,
                    (sbyte)-1
                }
            };
            PriorityQueue priorityQueue = new PriorityQueue();
            Dictionary <PathNode, PathNode> closedList = new Dictionary <PathNode, PathNode>();
            int num = 0;

            priorityQueue.Enqueue(new PathNode(startPoint.X, startPoint.Y, (byte)0, (PathNode)null), Math.Abs(endPoint.X - startPoint.X) + Math.Abs(endPoint.Y - startPoint.Y));
            while (!priorityQueue.IsEmpty())
            {
                PathNode pathNode1 = priorityQueue.Dequeue();
                if (endPointFunction(pathNode1, endPoint, location, character))
                {
                    return(PathFindController.reconstructPath(pathNode1, closedList));
                }
                if (!closedList.ContainsKey(pathNode1))
                {
                    closedList.Add(pathNode1, pathNode1.parent);
                }
                for (int index = 0; index < 4; ++index)
                {
                    PathNode pathNode2 = new PathNode(pathNode1.x + (int)numArray[index, 0], pathNode1.y + (int)numArray[index, 1], pathNode1);
                    pathNode2.g = (byte)((uint)pathNode1.g + 1U);
                    if (!closedList.ContainsKey(pathNode2) && (pathNode2.x == endPoint.X && pathNode2.y == endPoint.Y || pathNode2.x >= 0 && pathNode2.y >= 0 && (pathNode2.x < location.map.Layers[0].LayerWidth && pathNode2.y < location.map.Layers[0].LayerHeight)) && !location.isCollidingPosition(new Rectangle(pathNode2.x * Game1.tileSize + 1, pathNode2.y * Game1.tileSize + 1, Game1.tileSize - 2, Game1.tileSize - 2), Game1.viewport, false, 0, false, character, true, false, false))
                    {
                        int priority = (int)pathNode2.g + (Math.Abs(endPoint.X - pathNode2.x) + Math.Abs(endPoint.Y - pathNode2.y));
                        if (!priorityQueue.Contains(pathNode2, priority))
                        {
                            priorityQueue.Enqueue(pathNode2, priority);
                        }
                    }
                }
                ++num;
                if (num >= limit)
                {
                    return((Stack <Point>)null);
                }
            }
            return((Stack <Point>)null);
        }
Example #4
0
        // Token: 0x060002E9 RID: 745 RVA: 0x0003B7F0 File Offset: 0x000399F0
        public static Stack <Point> findPath(Point startPoint, Point endPoint, PathFindController.isAtEnd endPointFunction, GameLocation location, Character character, int limit)
        {
            sbyte[,] directions = new sbyte[, ]
            {
                {
                    -1,
                    0
                },
                {
                    1,
                    0
                },
                {
                    0,
                    1
                },
                {
                    0,
                    -1
                }
            };
            PriorityQueue openList = new PriorityQueue();
            Dictionary <PathNode, PathNode> closedList = new Dictionary <PathNode, PathNode>();
            int iterations = 0;

            openList.Enqueue(new PathNode(startPoint.X, startPoint.Y, 0, null), Math.Abs(endPoint.X - startPoint.X) + Math.Abs(endPoint.Y - startPoint.Y));
            while (!openList.IsEmpty())
            {
                PathNode currentNode = openList.Dequeue();
                if (endPointFunction(currentNode, endPoint, location, character))
                {
                    return(PathFindController.reconstructPath(currentNode, closedList));
                }
                if (!closedList.ContainsKey(currentNode))
                {
                    closedList.Add(currentNode, currentNode.parent);
                }
                for (int i = 0; i < 4; i++)
                {
                    PathNode neighbor = new PathNode(currentNode.x + (int)directions[i, 0], currentNode.y + (int)directions[i, 1], currentNode);
                    neighbor.g = currentNode.g + 1;
                    if (!closedList.ContainsKey(neighbor) && ((neighbor.x == endPoint.X && neighbor.y == endPoint.Y) || (neighbor.x >= 0 && neighbor.y >= 0 && neighbor.x < location.map.Layers[0].LayerWidth && neighbor.y < location.map.Layers[0].LayerHeight)) && !location.isCollidingPosition(new Rectangle(neighbor.x * Game1.tileSize + 1, neighbor.y * Game1.tileSize + 1, Game1.tileSize - 2, Game1.tileSize - 2), Game1.viewport, false, 0, false, character, true, false, false))
                    {
                        int f = (int)neighbor.g + (Math.Abs(endPoint.X - neighbor.x) + Math.Abs(endPoint.Y - neighbor.y));
                        if (!openList.Contains(neighbor, f))
                        {
                            openList.Enqueue(neighbor, f);
                        }
                    }
                }
                iterations++;
                if (iterations >= limit)
                {
                    return(null);
                }
            }
            return(null);
        }