Пример #1
0
        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);
        }
Пример #2
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);
        }
Пример #3
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);
        }