Example #1
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);
        }
Example #2
0
 public Board(int boardSize, int flaggableBoardSize, uint defaultCellFlags)
 {
     this.boardSize       = boardSize;
     this.flaggableMinAbs = (boardSize - flaggableBoardSize) / 2;
     this.flaggableMaxAbs = boardSize - this.flaggableMinAbs;
     this.centerOffset    = boardSize / 2;
     this.Cells           = new BoardCell <T> [boardSize, boardSize];
     for (int i = 0; i < boardSize; i++)
     {
         for (int j = 0; j < boardSize; j++)
         {
             this.Cells[i, j] = new BoardCell <T>(this, this.AbsToRel(i), this.AbsToRel(j), null, defaultCellFlags);
         }
     }
     this.upperRightX = (this.upperRightZ = (this.upperRightXNoWall = (this.upperRightZNoWall = boardSize - 1)));
     this.Cells[this.upperRightX, this.upperRightZ].Clearance = 1;
     this.Cells[this.upperRightXNoWall, this.upperRightZNoWall].ClearanceNoWall = 1;
     this.clearanceMapDirty       = true;
     this.clearanceMapNoWallDirty = true;
     this.RefreshClearanceMap();
     this.RefreshClearanceMapNoWall();
     this.children = new LinkedList <BoardItem <T> >();
 }
Example #3
0
 private static bool CheckIfCellShieldBorderIsFromShieldTarget(SmartEntity target, BoardCell cell)
 {
     if (GameUtils.IsEntityShieldGenerator(target))
     {
         SmartEntity   smartEntity = (SmartEntity)target.ShieldGeneratorComp.ShieldBorderEntity;
         List <Entity> obstacles   = cell.Obstacles;
         if (obstacles != null)
         {
             int i     = 0;
             int count = obstacles.Count;
             while (i < count)
             {
                 if (obstacles[i] == smartEntity)
                 {
                     return(true);
                 }
                 i++;
             }
         }
     }
     return(false);
 }
Example #4
0
        public static bool HasLineOfClearance(Board board, int x0, int y0, int x1, int y1, int troopWidth)
        {
            int num  = (x1 <= x0) ? -1 : 1;
            int num2 = (x1 - x0) * num;
            int num3 = (y1 <= y0) ? -1 : 1;
            int num4 = (y1 - y0) * num3;

            if (num2 > num4)
            {
                int num5 = num4 * 2 - num2;
                int num6 = num4 * 2;
                int num7 = (num4 - num2) * 2;
                int num8 = x0;
                int num9 = y0;
                while (num8 != x1)
                {
                    if (num5 <= 0)
                    {
                        num5 += num6;
                        num8 += num;
                    }
                    else
                    {
                        num5 += num7;
                        num8 += num;
                        num9 += num3;
                    }
                    if (num8 == x1)
                    {
                        return(true);
                    }
                    BoardCell cellAt = board.GetCellAt(num8, num9);
                    if (cellAt.Clearance < troopWidth)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                int num10 = num2 * 2 - num4;
                int num11 = num2 * 2;
                int num12 = (num2 - num4) * 2;
                int num13 = x0;
                int num14 = y0;
                while (num14 != y1)
                {
                    if (num10 <= 0)
                    {
                        num10 += num11;
                        num14 += num3;
                    }
                    else
                    {
                        num10 += num12;
                        num13 += num;
                        num14 += num3;
                    }
                    if (num14 == y1)
                    {
                        return(true);
                    }
                    BoardCell cellAt = board.GetCellAt(num13, num14);
                    if (cellAt.Clearance < troopWidth)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #5
0
        public static bool HasLineOfSight(Board board, int x0, int y0, int x1, int y1, SmartEntity troop, SmartEntity target, out BoardCell hitShieldCell)
        {
            bool overWalls = troop.ShooterComp.ShooterVO.OverWalls;
            bool isFlying  = troop.TroopComp.TroopType.IsFlying;

            hitShieldCell = null;
            int num  = (x1 <= x0) ? -1 : 1;
            int num2 = (x1 - x0) * num;
            int num3 = (y1 <= y0) ? -1 : 1;
            int num4 = (y1 - y0) * num3;

            if (num2 > num4)
            {
                int num5 = num4 * 2 - num2;
                int num6 = num4 * 2;
                int num7 = (num4 - num2) * 2;
                int num8 = x0;
                int num9 = y0;
                while (num8 != x1)
                {
                    if (num5 <= 0)
                    {
                        num5 += num6;
                        num8 += num;
                    }
                    else
                    {
                        num5 += num7;
                        num8 += num;
                        num9 += num3;
                    }
                    BoardCell cellAt = board.GetCellAt(num8, num9);
                    if (BoardUtils.UpdateHitShieldCellAndReturnIfItIsFromTarget(target, cellAt, ref hitShieldCell))
                    {
                        return(true);
                    }
                    if (num8 == x1)
                    {
                        return(true);
                    }
                    if (BoardUtils.IsCellBlockingLineOfSight(cellAt, overWalls, isFlying))
                    {
                        return(BoardUtils.CheckIfCellContainsTarget(target, cellAt));
                    }
                }
            }
            else
            {
                int num10 = num2 * 2 - num4;
                int num11 = num2 * 2;
                int num12 = (num2 - num4) * 2;
                int num13 = x0;
                int num14 = y0;
                while (num14 != y1)
                {
                    if (num10 <= 0)
                    {
                        num10 += num11;
                        num14 += num3;
                    }
                    else
                    {
                        num10 += num12;
                        num13 += num;
                        num14 += num3;
                    }
                    BoardCell cellAt = board.GetCellAt(num13, num14);
                    if (BoardUtils.UpdateHitShieldCellAndReturnIfItIsFromTarget(target, cellAt, ref hitShieldCell))
                    {
                        return(true);
                    }
                    if (num14 == y1)
                    {
                        return(true);
                    }
                    if (BoardUtils.IsCellBlockingLineOfSight(cellAt, overWalls, isFlying))
                    {
                        return(BoardUtils.CheckIfCellContainsTarget(target, cellAt));
                    }
                }
            }
            return(true);
        }
Example #6
0
 private static bool IsCellBlockingLineOfSight(BoardCell cell, bool isOverWalls, bool isFlying)
 {
     return(!cell.IsWalkableNoWall() || (!isOverWalls && !isFlying && !cell.IsWalkable()));
 }
Example #7
0
 private static bool UpdateHitShieldCellAndReturnIfItIsFromTarget(SmartEntity target, BoardCell cell, ref BoardCell hitShieldCell)
 {
     if ((cell.Flags & 8u) != 0u)
     {
         if (hitShieldCell == null)
         {
             hitShieldCell = cell;
         }
         if (BoardUtils.CheckIfCellShieldBorderIsFromShieldTarget(target, cell))
         {
             return(true);
         }
     }
     return(false);
 }
Example #8
0
        public static BoardCell WhereDoesLineCrossFlag(Board board, int x0, int y0, int x1, int y1, uint crossFlag)
        {
            int num  = (x1 <= x0) ? -1 : 1;
            int num2 = (x1 - x0) * num;
            int num3 = (y1 <= y0) ? -1 : 1;
            int num4 = (y1 - y0) * num3;

            if (num2 > num4)
            {
                int num5 = num4 * 2 - num2;
                int num6 = num4 * 2;
                int num7 = (num4 - num2) * 2;
                int num8 = x0;
                int num9 = y0;
                while (num8 != x1)
                {
                    if (num5 <= 0)
                    {
                        num5 += num6;
                        num8 += num;
                    }
                    else
                    {
                        num5 += num7;
                        num8 += num;
                        num9 += num3;
                    }
                    BoardCell cellAt = board.GetCellAt(num8, num9);
                    if ((cellAt.Flags & crossFlag) != 0u)
                    {
                        return(cellAt);
                    }
                }
            }
            else
            {
                int num10 = num2 * 2 - num4;
                int num11 = num2 * 2;
                int num12 = (num2 - num4) * 2;
                int num13 = x0;
                int num14 = y0;
                while (num14 != y1)
                {
                    if (num10 <= 0)
                    {
                        num10 += num11;
                        num14 += num3;
                    }
                    else
                    {
                        num10 += num12;
                        num13 += num;
                        num14 += num3;
                    }
                    BoardCell cellAt = board.GetCellAt(num13, num14);
                    if ((cellAt.Flags & crossFlag) != 0u)
                    {
                        return(cellAt);
                    }
                }
            }
            return(null);
        }
Example #9
0
 internal void Internal_InformRemovedFromBoard()
 {
     this.currentBoard = null;
     this.currentCell  = null;
 }
Example #10
0
 internal void Internal_InformAddedToBoard(Board board, int x, int y)
 {
     this.currentBoard = board;
     this.currentCell  = board.GetCellAt(x, y);
 }
Example #11
0
        public void TraverseCellNeighbors(int x, int z, Board.NeighborTraverseCallback callback)
        {
            BoardCell cellAt = this.GetCellAt(x, z);

            this.TraverseCellNeighbors(cellAt, callback);
        }
Example #12
0
 private void RemoveFlagStampFromCell(BoardCell cell, FlagStamp flagStamp)
 {
     cell.RemoveFlagStamp(flagStamp);
 }
Example #13
0
 private void AddFlagStampToCell(BoardCell cell, FlagStamp flagStamp)
 {
     cell.AddFlagStamp(flagStamp);
 }
Example #14
0
 private void GetCellsInSquareCallback(BoardCell <T> cell, List <BoardCell <T> > cookie)
 {
     cookie.Add(cell);
 }