Beispiel #1
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);
        }
        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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public static Stack <Point> findPathForNPCSchedules(Point startPoint, Point endPoint, GameLocation location, 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));
            PathNode pathNode1 = (PathNode)priorityQueue.Peek();

            while (!priorityQueue.IsEmpty())
            {
                PathNode pathNode2 = priorityQueue.Dequeue();
                if (pathNode2.x == endPoint.X && pathNode2.y == endPoint.Y)
                {
                    return(PathFindController.reconstructPath(pathNode2, closedList));
                }
                if (pathNode2.x == 79)
                {
                    int y = pathNode2.y;
                }
                if (!closedList.ContainsKey(pathNode2))
                {
                    closedList.Add(pathNode2, pathNode2.parent);
                }
                for (int index = 0; index < 4; ++index)
                {
                    PathNode pathNode3 = new PathNode(pathNode2.x + (int)numArray[index, 0], pathNode2.y + (int)numArray[index, 1], pathNode2);
                    pathNode3.g = (byte)((uint)pathNode2.g + 1U);
                    if (!closedList.ContainsKey(pathNode3) && (pathNode3.x == endPoint.X && pathNode3.y == endPoint.Y || pathNode3.x >= 0 && pathNode3.y >= 0 && (pathNode3.x < location.map.Layers[0].LayerWidth && pathNode3.y < location.map.Layers[0].LayerHeight) && !PathFindController.isPositionImpassableForNPCSchedule(location, pathNode3.x, pathNode3.y)))
                    {
                        int priority = (int)pathNode3.g + PathFindController.getPreferenceValueForTerrainType(location, pathNode3.x, pathNode3.y) + (Math.Abs(endPoint.X - pathNode3.x) + Math.Abs(endPoint.Y - pathNode3.y) + (pathNode3.x == pathNode2.x && pathNode3.x == pathNode1.x || pathNode3.y == pathNode2.y && pathNode3.y == pathNode1.y ? -2 : 0));
                        if (!priorityQueue.Contains(pathNode3, priority))
                        {
                            priorityQueue.Enqueue(pathNode3, priority);
                        }
                    }
                }
                pathNode1 = pathNode2;
                ++num;
                if (num >= limit)
                {
                    return((Stack <Point>)null);
                }
            }
            return((Stack <Point>)null);
        }
        public static Stack <Point> findPathForNPCSchedules(Point startPoint, Point endPoint, GameLocation location, 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));
            PathNode pathNode = (PathNode)priorityQueue.Peek();

            while (!priorityQueue.IsEmpty())
            {
                PathNode pathNode2 = priorityQueue.Dequeue();
                if (pathNode2.x == endPoint.X && pathNode2.y == endPoint.Y)
                {
                    return(PathFindController.reconstructPath(pathNode2, dictionary));
                }
                if (pathNode2.x == 79)
                {
                    int arg_B2_0 = pathNode2.y;
                }
                if (!dictionary.ContainsKey(pathNode2))
                {
                    dictionary.Add(pathNode2, pathNode2.parent);
                }
                for (int i = 0; i < 4; i++)
                {
                    PathNode pathNode3 = new PathNode(pathNode2.x + (int)array[i, 0], pathNode2.y + (int)array[i, 1], pathNode2);
                    pathNode3.g = pathNode2.g + 1;
                    if (!dictionary.ContainsKey(pathNode3) && ((pathNode3.x == endPoint.X && pathNode3.y == endPoint.Y) || (pathNode3.x >= 0 && pathNode3.y >= 0 && pathNode3.x < location.map.Layers[0].LayerWidth && pathNode3.y < location.map.Layers[0].LayerHeight && !PathFindController.isPositionImpassableForNPCSchedule(location, pathNode3.x, pathNode3.y))))
                    {
                        int priority = (int)pathNode3.g + PathFindController.getPreferenceValueForTerrainType(location, pathNode3.x, pathNode3.y) + (Math.Abs(endPoint.X - pathNode3.x) + Math.Abs(endPoint.Y - pathNode3.y) + (((pathNode3.x == pathNode2.x && pathNode3.x == pathNode.x) || (pathNode3.y == pathNode2.y && pathNode3.y == pathNode.y)) ? -2 : 0));
                        if (!priorityQueue.Contains(pathNode3, priority))
                        {
                            priorityQueue.Enqueue(pathNode3, priority);
                        }
                    }
                }
                pathNode = pathNode2;
                num++;
                if (num >= limit)
                {
                    return(null);
                }
            }
            return(null);
        }
Beispiel #6
0
        // Token: 0x060002ED RID: 749 RVA: 0x0003C128 File Offset: 0x0003A328
        public static Stack <Point> findPathForNPCSchedules(Point startPoint, Point endPoint, GameLocation location, 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));
            PathNode previousNode = (PathNode)openList.Peek();

            while (!openList.IsEmpty())
            {
                PathNode currentNode = openList.Dequeue();
                if (currentNode.x == endPoint.X && currentNode.y == endPoint.Y)
                {
                    return(PathFindController.reconstructPath(currentNode, closedList));
                }
                if (currentNode.x == 79)
                {
                    int arg_B2_0 = currentNode.y;
                }
                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 && !PathFindController.isPositionImpassableForNPCSchedule(location, neighbor.x, neighbor.y))))
                    {
                        int f = (int)neighbor.g + PathFindController.getPreferenceValueForTerrainType(location, neighbor.x, neighbor.y) + (Math.Abs(endPoint.X - neighbor.x) + Math.Abs(endPoint.Y - neighbor.y) + (((neighbor.x == currentNode.x && neighbor.x == previousNode.x) || (neighbor.y == currentNode.y && neighbor.y == previousNode.y)) ? -2 : 0));
                        if (!openList.Contains(neighbor, f))
                        {
                            openList.Enqueue(neighbor, f);
                        }
                    }
                }
                previousNode = currentNode;
                iterations++;
                if (iterations >= limit)
                {
                    return(null);
                }
            }
            return(null);
        }