Exemplo n.º 1
0
        private void SmoothThePath(ref BoardCellDynamicArray rawTurns, ref BoardCellDynamicArray pathCells, ref BoardCellDynamicArray turns, List <int> turnDistances)
        {
            if (rawTurns.Length == 0)
            {
                Service.Logger.Error("SmoothThePath: Not expecting empty path!");
                return;
            }
            pathCells.Add(rawTurns.Array[0]);
            turns.Add(rawTurns.Array[0]);
            turnDistances.Add(0);
            if (rawTurns.Length == 1)
            {
                return;
            }
            if (rawTurns.Length == 2)
            {
                this.AddTurn(rawTurns.Array[0], rawTurns.Array[1], ref pathCells, ref turns, turnDistances);
                return;
            }
            BoardCell boardCell  = rawTurns.Array[0];
            BoardCell boardCell2 = rawTurns.Array[1];

            for (int i = 2; i < rawTurns.Length; i++)
            {
                BoardCell boardCell3 = rawTurns.Array[i];
                if (!BoardUtils.HasLineOfClearance(this.board, boardCell.X, boardCell.Z, boardCell3.X, boardCell3.Z, this.TroopWidth))
                {
                    this.AddTurn(boardCell, boardCell2, ref pathCells, ref turns, turnDistances);
                    boardCell = boardCell2;
                }
                boardCell2 = boardCell3;
            }
            this.AddTurn(boardCell, boardCell2, ref pathCells, ref turns, turnDistances);
        }
Exemplo n.º 2
0
        private void AddTurn(BoardCell legStart, BoardCell legEnd, ref BoardCellDynamicArray pathCells, ref BoardCellDynamicArray turns, List <int> turnDistances)
        {
            turns.Add(legEnd);
            int num  = 0;
            int num2 = 0;

            this.RasterLine(legStart.X, legStart.Z, legEnd.X, legEnd.Z, ref pathCells, out num, out num2);
            turnDistances.Add(num * 1000 + num2 * 1414);
        }
Exemplo n.º 3
0
 private void AddCell(int x, int y, ref BoardCellDynamicArray cells)
 {
     x += 23;
     if (x >= 0 && x < 46)
     {
         y += 23;
         if (y >= 0 && y < 46)
         {
             BoardCell element = this.board.Cells[x, y];
             cells.Add(element);
         }
     }
 }
Exemplo n.º 4
0
        private BoardCellDynamicArray FindTheTurns(ref BoardCellDynamicArray path)
        {
            BoardCellDynamicArray result = new BoardCellDynamicArray(64);
            int length = path.Length;

            result.Add(path.Array[length - 1]);
            for (int i = length - 2; i > 0; i--)
            {
                BoardCell boardCell  = path.Array[i];
                BoardCell boardCell2 = path.Array[i + 1];
                BoardCell boardCell3 = path.Array[i - 1];
                if (boardCell.X - boardCell2.X != boardCell3.X - boardCell.X || boardCell.Z - boardCell2.Z != boardCell3.Z - boardCell.Z)
                {
                    result.Add(boardCell);
                }
            }
            if (length >= 2)
            {
                result.Add(path.Array[0]);
            }
            return(result);
        }
Exemplo n.º 5
0
        public BoardCellDynamicArray GetCellsInSquare(int distFromCenter, int centerX, int centerZ)
        {
            BoardCellDynamicArray result = new BoardCellDynamicArray(distFromCenter * distFromCenter);
            int num  = centerX - distFromCenter;
            int num2 = centerX + distFromCenter;
            int num3 = centerZ - distFromCenter;
            int num4 = centerZ + distFromCenter;

            for (int i = num; i <= num2; i++)
            {
                for (int j = num3; j <= num4; j++)
                {
                    BoardCell cellAt = this.GetCellAt(i, j);
                    if (cellAt != null)
                    {
                        result.Add(cellAt);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 6
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();
        }