예제 #1
0
        public PathfindingCellInfo Dequeue()
        {
            PathfindingCellInfo pathfindingCellInfo = this._nodes[1];

            this.Remove(pathfindingCellInfo);
            return(pathfindingCellInfo);
        }
예제 #2
0
        public PathfindingCellInfo GetPathingCell()
        {
            PathfindingCellInfo pathfindingCellInfo;

            if (this.FreeCellIndex == this.pathingCellPool.Count)
            {
                pathfindingCellInfo           = new PathfindingCellInfo();
                pathfindingCellInfo.PoolIndex = this.FreeCellIndex;
                this.pathingCellPool.Add(pathfindingCellInfo);
            }
            else
            {
                pathfindingCellInfo = this.pathingCellPool[this.FreeCellIndex];
                if (pathfindingCellInfo.Cell != null)
                {
                    pathfindingCellInfo.Cell.PathInfo = null;
                    pathfindingCellInfo.Cell          = null;
                }
                pathfindingCellInfo.InClosedSet = false;
                pathfindingCellInfo.InRange     = false;
                pathfindingCellInfo.PrevCell    = null;
            }
            this.FreeCellIndex++;
            return(pathfindingCellInfo);
        }
예제 #3
0
        private void Swap(PathfindingCellInfo node1, PathfindingCellInfo node2)
        {
            this._nodes[node1.QueueIndex] = node2;
            this._nodes[node2.QueueIndex] = node1;
            int queueIndex = node1.QueueIndex;

            node1.QueueIndex = node2.QueueIndex;
            node2.QueueIndex = queueIndex;
        }
예제 #4
0
 public void Enqueue(PathfindingCellInfo node, int priority)
 {
     node.Priority = priority;
     this._numNodes++;
     this._nodes[this._numNodes] = node;
     node.QueueIndex             = this._numNodes;
     node.InsertionIndex         = this._numNodesEverEnqueued++;
     this.CascadeUp(this._nodes[this._numNodes]);
 }
예제 #5
0
 private void CascadeUp(PathfindingCellInfo node)
 {
     for (int i = node.QueueIndex / 2; i >= 1; i = node.QueueIndex / 2)
     {
         PathfindingCellInfo pathfindingCellInfo = this._nodes[i];
         if (pathfindingCellInfo.Priority < node.Priority || (pathfindingCellInfo.Priority == node.Priority && pathfindingCellInfo.InsertionIndex < node.InsertionIndex))
         {
             break;
         }
         this.Swap(node, pathfindingCellInfo);
     }
 }
예제 #6
0
        private void OnNodeUpdated(PathfindingCellInfo node)
        {
            int num = node.QueueIndex / 2;
            PathfindingCellInfo lower = this._nodes[num];

            if (num > 0 && this.HasHigherPriority(node, lower))
            {
                this.CascadeUp(node);
            }
            else
            {
                this.CascadeDown(node);
            }
        }
예제 #7
0
 public BoardCell(Board parentBoard, int x, int z, FilterComponent defaultFilter, uint defaultFlags)
 {
     this.ParentBoard    = parentBoard;
     this.X              = x;
     this.Z              = z;
     this.children       = null;
     this.flagStamps     = null;
     this.obstacles      = null;
     this.BuildingHealth = null;
     this.defaultFilter  = defaultFilter;
     this.Flags          = defaultFlags;
     this.Clearance      = 0;
     this.PathInfo       = null;
 }
예제 #8
0
        private void CascadeDown(PathfindingCellInfo node)
        {
            int num = node.QueueIndex;

            while (true)
            {
                PathfindingCellInfo pathfindingCellInfo = node;
                int num2 = 2 * num;
                if (num2 > this._numNodes)
                {
                    break;
                }
                PathfindingCellInfo pathfindingCellInfo2 = this._nodes[num2];
                if (pathfindingCellInfo2.Priority < pathfindingCellInfo.Priority || (pathfindingCellInfo2.Priority == pathfindingCellInfo.Priority && pathfindingCellInfo2.InsertionIndex < pathfindingCellInfo.InsertionIndex))
                {
                    pathfindingCellInfo = pathfindingCellInfo2;
                }
                int num3 = num2 + 1;
                if (num3 <= this._numNodes)
                {
                    PathfindingCellInfo pathfindingCellInfo3 = this._nodes[num3];
                    if (pathfindingCellInfo3.Priority < pathfindingCellInfo.Priority || (pathfindingCellInfo3.Priority == pathfindingCellInfo.Priority && pathfindingCellInfo3.InsertionIndex < pathfindingCellInfo.InsertionIndex))
                    {
                        pathfindingCellInfo = pathfindingCellInfo3;
                    }
                }
                if (pathfindingCellInfo == node)
                {
                    goto IL_E9;
                }
                this._nodes[num] = pathfindingCellInfo;
                int queueIndex = pathfindingCellInfo.QueueIndex;
                pathfindingCellInfo.QueueIndex = num;
                num = queueIndex;
            }
            node.QueueIndex  = num;
            this._nodes[num] = node;
            return;

IL_E9:
            node.QueueIndex  = num;
            this._nodes[num] = node;
        }
예제 #9
0
        public Path(BoardCell fromCell, BoardCell toCell, BoardCell targetAt, int maxLength, PathTroopParams troopParams, PathBoardParams boardParams)
        {
            this.pathCells     = new BoardCellDynamicArray(64);
            this.scratchCells  = new BoardCellDynamicArray(64);
            this.turns         = new BoardCellDynamicArray(64);
            this.turnDistances = new List <int>(64);
            BoardController boardController = Service.BoardController;

            this.board                 = boardController.Board;
            this.pathingManager        = Service.PathingManager;
            this.startCell             = fromCell;
            this.destCell              = toCell;
            this.targetCell            = targetAt;
            this.NoWall                = (boardParams.IgnoreWall || troopParams.CrushesWalls);
            this.crushesWalls          = troopParams.CrushesWalls;
            this.destructible          = boardParams.Destructible;
            this.isHealer              = troopParams.IsHealer;
            this.TroopWidth            = troopParams.TroopWidth;
            this.damagePerSecond       = troopParams.DPS;
            this.maxShooterRange       = troopParams.MaxRange;
            this.targetInRangeModifier = troopParams.TargetInRangeModifier;
            if (this.isHealer && this.maxShooterRange > troopParams.SupportRange)
            {
                this.maxShooterRange = troopParams.SupportRange;
            }
            this.minShooterRange    = troopParams.MinRange;
            this.maxSpeed           = troopParams.MaxSpeed;
            this.heristicMultiplier = (int)troopParams.PathSearchWidth;
            this.maxPathLength      = ((!this.isHealer) ? maxLength : -1);
            this.melee                        = troopParams.IsMelee;
            this.overWalls                    = troopParams.IsOverWall;
            this.projectileType               = troopParams.ProjectileType;
            this.isTargetShield               = troopParams.IsTargetShield;
            this.openCells                    = new HeapPriorityQueue(boardController.GetPriorityQueueSize());
            this.curPathingCell               = this.pathingManager.GetPathingCell();
            this.curPathingCell.Cell          = this.startCell;
            this.startCell.PathInfo           = this.curPathingCell;
            this.curPathingCell.InRange       = this.InRangeOfTarget(this.startCell);
            this.curPathingCell.RemainingCost = this.HeuristicDiagonal(this.startCell, this.destCell);
            this.curPathingCell.PathLength    = 0;
            this.curPathingCell.PastCost      = 0;
            this.curPathingCell.InClosedSet   = true;
        }
예제 #10
0
        public void Remove(PathfindingCellInfo node)
        {
            if (this._numNodes <= 1)
            {
                this._nodes[1] = null;
                this._numNodes = 0;
                return;
            }
            bool flag = false;
            PathfindingCellInfo pathfindingCellInfo = this._nodes[this._numNodes];

            if (node.QueueIndex != this._numNodes)
            {
                this.Swap(node, pathfindingCellInfo);
                flag = true;
            }
            this._numNodes--;
            this._nodes[node.QueueIndex] = null;
            if (flag)
            {
                this.OnNodeUpdated(pathfindingCellInfo);
            }
        }
예제 #11
0
 public bool Contains(PathfindingCellInfo node)
 {
     return(this._nodes[node.QueueIndex] == node);
 }
예제 #12
0
 public void UpdatePriority(PathfindingCellInfo node, int priority)
 {
     node.Priority = priority;
     this.OnNodeUpdated(node);
 }
예제 #13
0
 private bool HasHigherPriority(PathfindingCellInfo higher, PathfindingCellInfo lower)
 {
     return(higher.Priority < lower.Priority || (higher.Priority == lower.Priority && higher.InsertionIndex < lower.InsertionIndex));
 }
예제 #14
0
        private void CalculatePath(out bool found, ref BoardCellDynamicArray scratchCells)
        {
            int num = 46 - this.TroopWidth;

            while (!this.curPathingCell.InRange)
            {
                if (this.maxPathLength < 0 || this.curPathingCell.PathLength < this.maxPathLength)
                {
                    BoardCell cell = this.curPathingCell.Cell;
                    int       x    = cell.X;
                    int       z    = cell.Z;
                    for (int i = 0; i < 8; i++)
                    {
                        int num2 = x + Path.dirX[i];
                        if (num2 >= 0 && num2 <= num)
                        {
                            int num3 = z + Path.dirY[i];
                            if (num3 >= 0 && num3 <= num)
                            {
                                BoardCell boardCell = this.board.Cells[num2, num3];
                                if ((boardCell.Flags & 64u) == 0u)
                                {
                                    if (!this.destructible)
                                    {
                                        int num4 = (!this.NoWall) ? boardCell.Clearance : boardCell.ClearanceNoWall;
                                        if (this.TroopWidth > num4)
                                        {
                                            goto IL_29A;
                                        }
                                    }
                                    int num5 = this.CostToNeighbor(cell, boardCell, ref scratchCells);
                                    if (num5 != 2147483647)
                                    {
                                        int num6       = this.curPathingCell.PastCost + num5;
                                        int pathLength = this.curPathingCell.PathLength + 1;
                                        PathfindingCellInfo pathfindingCellInfo = boardCell.PathInfo;
                                        if (pathfindingCellInfo != null && pathfindingCellInfo.PoolIndex < this.pathingManager.FreeCellIndex)
                                        {
                                            if (!pathfindingCellInfo.InClosedSet)
                                            {
                                                if (!this.openCells.Contains(pathfindingCellInfo))
                                                {
                                                    Service.Logger.ErrorFormat("Allocated cell not in close/open sets,PoolIndex:{0}, FreeIndex:{1}", new object[]
                                                    {
                                                        pathfindingCellInfo.PoolIndex,
                                                        this.pathingManager.FreeCellIndex
                                                    });
                                                }
                                                else if (num6 < pathfindingCellInfo.PastCost)
                                                {
                                                    pathfindingCellInfo.PastCost   = num6;
                                                    pathfindingCellInfo.PathLength = pathLength;
                                                    this.openCells.UpdatePriority(pathfindingCellInfo, pathfindingCellInfo.PastCost + pathfindingCellInfo.RemainingCost);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            pathfindingCellInfo          = this.pathingManager.GetPathingCell();
                                            pathfindingCellInfo.PrevCell = this.curPathingCell;
                                            if (boardCell.PathInfo != null)
                                            {
                                                PathfindingCellInfo pathInfo = boardCell.PathInfo;
                                                pathInfo.Cell = null;
                                            }
                                            pathfindingCellInfo.Cell          = boardCell;
                                            boardCell.PathInfo                = pathfindingCellInfo;
                                            pathfindingCellInfo.InRange       = this.InRangeOfTarget(boardCell);
                                            pathfindingCellInfo.RemainingCost = this.HeuristicDiagonal(boardCell, this.destCell);
                                            pathfindingCellInfo.PastCost      = num6;
                                            pathfindingCellInfo.PathLength    = pathLength;
                                            this.openCells.Enqueue(pathfindingCellInfo, pathfindingCellInfo.PastCost + pathfindingCellInfo.RemainingCost);
                                        }
                                    }
                                }
                            }
                        }
                        IL_29A :;
                    }
                }
                if (this.openCells.Count == 0)
                {
                    this.pathingManager.RecycleAllPathingCells();
                    this.openCells = null;
                    found          = false;
                    scratchCells.Clear();
                    return;
                }
                this.curPathingCell             = this.openCells.Dequeue();
                this.curPathingCell.InClosedSet = true;
            }
            if (!this.curPathingCell.InRange)
            {
                this.pathingManager.RecycleAllPathingCells();
                this.openCells = null;
                found          = false;
                scratchCells.Clear();
                return;
            }
            do
            {
                scratchCells.Add(this.curPathingCell.Cell);
                this.curPathingCell = this.curPathingCell.PrevCell;
            }while (this.curPathingCell != null);
            int length = scratchCells.Length;

            if (length == 0)
            {
                Service.Logger.ErrorFormat("Empth Path from {0} to {1} within range {2}", new object[]
                {
                    this.startCell,
                    this.destCell,
                    this.maxShooterRange
                });
            }
            if (scratchCells.Array[length - 1] != this.startCell)
            {
                Service.Logger.ErrorFormat("First cell doesn't match: {0} and {1}", new object[]
                {
                    this.startCell,
                    scratchCells.Array[length - 1]
                });
            }
            BoardCellDynamicArray boardCellDynamicArray = this.FindTheTurns(ref scratchCells);

            this.SmoothThePath(ref boardCellDynamicArray, ref this.pathCells, ref this.turns, this.turnDistances);
            this.pathingManager.RecycleAllPathingCells();
            this.openCells = null;
            found          = true;
            scratchCells.Clear();
        }