/**
   * Draw the chess piece represented by stone into the given row and column. The actual blocks
   * drawn depend on the board's current chess set.
   *
   * @param row
   * @param col
   * @param stone
   */
  public void paintChessPiece(int row, int col, int stone) {
    // for entity sets, just check that the entity is still at (row,col)
    // for block sets, get the stone and paste its data into the region at (row,col)
    ChessSet cSet = designer != null ? designer.getChessSet() : chessSet;
    if (cSet.hasMovablePieces()) {
      // we don't paint movable pieces; moveChessPiece() can handle those
      return;
    }
    Cuboid region = getPieceRegion(row, col);
    MassBlockUpdate mbu =
        CraftMassBlockUpdate.createMassBlockUpdater(
            ChessCraft.getInstance(), getBoard().getWorld());
    region.fill(0, (byte) 0, mbu);
    if (stone != Chess.NO_STONE) {
      ChessStone cStone = cSet.getStone(stone, getRotation());
      if (cStone != null) {
        cStone.paint(region, mbu);
      } else {
        LogUtils.severe("unknown chess stone " + stone);
      }
    }

    region.expand(CuboidDirection.Down, 1).forceLightLevel(boardStyle.getLightLevel());
    mbu.notifyClients();
    if (ChessCraft.getInstance().getDynmapIntegration() != null) {
      ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(region);
    }
  }
 private void paintFrame(MassBlockUpdate mbu) {
   int fw = boardStyle.getFrameWidth();
   MaterialData fm = boardStyle.getFrameMaterial();
   frameBoard.getFace(CuboidDirection.West).expand(CuboidDirection.East, fw - 1).fill(fm, mbu);
   frameBoard.getFace(CuboidDirection.South).expand(CuboidDirection.North, fw - 1).fill(fm, mbu);
   frameBoard.getFace(CuboidDirection.East).expand(CuboidDirection.West, fw - 1).fill(fm, mbu);
   frameBoard.getFace(CuboidDirection.North).expand(CuboidDirection.South, fw - 1).fill(fm, mbu);
 }
 /**
  * Get the Chesspresso square index of the given location
  *
  * @param loc desired location
  * @return the square index, or Chess.NO_SQUARE if not on the board
  */
 int getSquareAt(Location loc) {
   if (!areaBoard.contains(loc)) {
     return Chess.NO_SQUARE;
   }
   int row = 0, col = 0;
   switch (rotation) {
     case NORTH:
       row = 7 - ((loc.getBlockX() - areaBoard.getLowerX()) / boardStyle.getSquareSize());
       col = 7 - ((loc.getBlockZ() - areaBoard.getLowerZ()) / boardStyle.getSquareSize());
       break;
     case EAST:
       row = 7 - ((loc.getBlockZ() - areaBoard.getLowerZ()) / boardStyle.getSquareSize());
       col = -((areaBoard.getLowerX() - loc.getBlockX()) / boardStyle.getSquareSize());
       break;
     case SOUTH:
       row = -((areaBoard.getLowerX() - loc.getBlockX()) / boardStyle.getSquareSize());
       col = -((areaBoard.getLowerZ() - loc.getBlockZ()) / boardStyle.getSquareSize());
       break;
     case WEST:
       row = -((areaBoard.getLowerZ() - loc.getBlockZ()) / boardStyle.getSquareSize());
       col = 7 - ((loc.getBlockX() - areaBoard.getLowerX()) / boardStyle.getSquareSize());
       break;
   }
   return Chess.coorToSqi(col, row);
 }
示例#4
0
 private void paintBoardSquare(int row, int col, MassBlockUpdate mbu) {
   Cuboid square = getSquare(row, col);
   boolean black = (col + (row % 2)) % 2 == 0;
   if (mbu == null) {
     square.fill(
         black ? boardStyle.getBlackSquareMaterial() : boardStyle.getWhiteSquareMaterial());
   } else {
     square.fill(
         black ? boardStyle.getBlackSquareMaterial() : boardStyle.getWhiteSquareMaterial(), mbu);
   }
 }
 private void highlightSelectedBoardSquare(int sqi) {
   Cuboid sq = getSquare(Chess.sqiToRow(sqi), Chess.sqiToCol(sqi));
   MaterialData squareHighlightColor = boardStyle.getSelectedHighlightMaterial();
   sq.getFace(CuboidDirection.East).fill(squareHighlightColor);
   sq.getFace(CuboidDirection.North).fill(squareHighlightColor);
   sq.getFace(CuboidDirection.West).fill(squareHighlightColor);
   sq.getFace(CuboidDirection.South).fill(squareHighlightColor);
   if (ChessCraft.getInstance().getDynmapIntegration() != null) {
     ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(sq);
   }
 }
  private void paintEnclosure(MassBlockUpdate mbu) {
    aboveFullBoard.getFace(CuboidDirection.North).fill(boardStyle.getEnclosureMaterial(), mbu);
    aboveFullBoard.getFace(CuboidDirection.East).fill(boardStyle.getEnclosureMaterial(), mbu);
    aboveFullBoard.getFace(CuboidDirection.South).fill(boardStyle.getEnclosureMaterial(), mbu);
    aboveFullBoard.getFace(CuboidDirection.West).fill(boardStyle.getEnclosureMaterial(), mbu);

    fullBoard.getFace(CuboidDirection.Up).fill(boardStyle.getEnclosureMaterial(), mbu);

    if (!boardStyle.getEnclosureMaterial().equals(boardStyle.getStrutsMaterial())) {
      paintStruts(mbu);
    }
  }
示例#7
0
 /** Board is in designer mode - paint some markers on unused squares */
 private void paintDesignIndicators(MassBlockUpdate mbu) {
   MaterialWithData marker = MaterialWithData.get("wool:red"); // configurable?
   for (int row = 0; row < 8; ++row) {
     for (int col = 0; col < 8; ++col) {
       if (row < 2 && col < 5) {
         continue;
       }
       Cuboid sq =
           getSquare(row, col).shift(CuboidDirection.Up, 1).inset(CuboidDirection.Horizontal, 1);
       sq.fill(marker, mbu);
     }
   }
 }
 /** Board is in designer mode - paint some markers on unused squares */
 private void paintDesignIndicators(MassBlockUpdate mbu) {
   Wool marker = new Wool(DyeColor.RED); // make configurable?
   for (int row = 0; row < 8; ++row) {
     for (int col = 0; col < 8; ++col) {
       if (row < 2 && col < 5 || row == 6 && col == 0 || row == 7 && col < 5) {
         continue;
       }
       Cuboid sq =
           getSquare(row, col).shift(CuboidDirection.Up, 1).inset(CuboidDirection.Horizontal, 1);
       sq.fill(marker, mbu);
     }
   }
 }
 private void paintBoardSquare(int row, int col, MassBlockUpdate mbu) {
   Cuboid square = getSquare(row, col);
   boolean black = (col + (row % 2)) % 2 == 0;
   if (mbu == null) {
     square.fill(
         black ? boardStyle.getBlackSquareMaterial() : boardStyle.getWhiteSquareMaterial());
   } else {
     square.fill(
         black ? boardStyle.getBlackSquareMaterial() : boardStyle.getWhiteSquareMaterial(), mbu);
   }
   if (ChessCraft.getInstance().getDynmapIntegration() != null) {
     ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(square);
   }
 }
示例#10
0
 /** Paint everything! (board, frame, enclosure, control panel, lighting) */
 void paintAll(MassBlockUpdate mbu) {
   if (designer == null) {
     fullBoard.fill(0, (byte) 0, mbu);
   }
   paintEnclosure(mbu);
   paintFrame(mbu);
   paintBoard(mbu);
   if (designer != null) {
     paintDesignIndicators(mbu);
   }
   if (fromSquare >= 0 || toSquare >= 0) {
     highlightSquares(fromSquare, toSquare);
   }
   fullBoard.forceLightLevel(boardStyle.getLightLevel());
 }
示例#11
0
  /**
   * Get the Cuboid region for this square <i>of the chessboard itself</i>
   *
   * @param row
   * @param col
   * @return a Cuboid representing the square
   */
  public Cuboid getSquare(int row, int col) {
    if (row < 0 || col < 0 || row > 7 || col > 7) {
      throw new ChessException("ChessBoard: getSquare: bad (row, col): (" + row + "," + col + ")");
    }

    Cuboid sq = new Cuboid(a1Corner.getLocation());

    int s = boardStyle.getSquareSize();
    CuboidDirection dir = rotation.getDirection();
    CuboidDirection dirRight = rotation.getRight().getDirection();

    sq = sq.shift(dir, row * s).shift(dirRight, col * s);
    sq = sq.expand(dir, s - 1).expand(dirRight, s - 1);

    return sq;
  }
示例#12
0
  /**
   * Draw the chess piece represented by stone into the given row and column. The actual blocks
   * drawn depend on the board's current chess set.
   *
   * @param row
   * @param col
   * @param stone
   */
  public void paintChessPiece(int row, int col, int stone) {
    Cuboid region = getPieceRegion(row, col);
    MassBlockUpdate mbu = CraftMassBlockUpdate.createMassBlockUpdater(getBoard().getWorld());
    region.fill(0, (byte) 0, mbu);
    ChessSet cSet = designer != null ? designer.getChessSet() : chessPieceSet;
    if (stone != Chess.NO_STONE) {
      ChessStone cStone = cSet.getStone(stone, getRotation());
      if (cStone != null) {
        paintChessPiece(region, cStone, mbu);
      } else {
        LogUtils.severe("unknown piece: " + stone);
      }
    }

    region.expand(CuboidDirection.Down, 1).forceLightLevel(boardStyle.getLightLevel());
    mbu.notifyClients();
  }
示例#13
0
 /** Clear full area associated with this board */
 void clearAll() {
   MassBlockUpdate mbu =
       CraftMassBlockUpdate.createMassBlockUpdater(
           ChessCraft.getInstance(), getBoard().getWorld());
   fullBoard.fill(0, (byte) 0, mbu);
   mbu.notifyClients();
   if (ChessCraft.getInstance().getDynmapIntegration() != null) {
     ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(fullBoard);
   }
 }
示例#14
0
 /**
  * Board constructor.
  *
  * @param origin
  * @param rotation
  * @param boardStyleName
  * @param pieceStyleName
  * @throws ChessException
  */
 public ChessBoard(
     Location origin, BoardRotation rotation, String boardStyleName, String pieceStyleName)
     throws ChessException {
   setBoardStyle(boardStyleName);
   setPieceStyle(pieceStyleName != null ? pieceStyleName : boardStyle.getPieceStyleName());
   this.rotation = rotation;
   a1Center = new PersistableLocation(origin);
   a1Corner = initA1Corner(origin, rotation);
   h8Corner = initH8Corner(a1Corner.getLocation());
   board = new Cuboid(a1Corner.getLocation(), h8Corner.getLocation());
   areaBoard = board.expand(CuboidDirection.Up, boardStyle.getHeight());
   frameBoard = board.outset(CuboidDirection.Horizontal, boardStyle.getFrameWidth());
   aboveFullBoard =
       frameBoard
           .shift(CuboidDirection.Up, 1)
           .expand(CuboidDirection.Up, boardStyle.getHeight() - 1);
   fullBoard = frameBoard.expand(CuboidDirection.Up, boardStyle.getHeight() + 1);
   validateBoardPosition();
 }
示例#15
0
  /**
   * Ensure this board isn't built too high and doesn't intersect any other boards
   *
   * @throws ChessException if an intersection would occur
   */
  private void validateBoardPosition() throws ChessException {
    Cuboid bounds = getFullBoard();

    if (bounds.getUpperSW().getBlock().getLocation().getY()
        > bounds.getUpperSW().getWorld().getMaxHeight()) {
      throw new ChessException(Messages.getString("BoardView.boardTooHigh")); // $NON-NLS-1$
    }
    for (BoardView bv : BoardViewManager.getManager().listBoardViews()) {
      if (bv.getA1Square().getWorld() != bounds.getWorld()) {
        continue;
      }
      for (Block b : bounds.corners()) {
        if (bv.getOuterBounds().contains(b)) {
          throw new ChessException(
              Messages.getString("BoardView.boardWouldIntersect", bv.getName())); // $NON-NLS-1$
        }
      }
    }
  }
示例#16
0
 /** Paint everything! (board, frame, enclosure, control panel, lighting) */
 void paintAll(MassBlockUpdate mbu) {
   if (designer == null) {
     fullBoard.fill(0, (byte) 0, mbu);
   }
   paintEnclosure(mbu);
   paintFrame(mbu);
   paintBoard(mbu);
   if (designer != null) {
     paintDesignIndicators(mbu);
   }
   if (fromSquare >= 0 || toSquare >= 0) {
     highlightSquares(fromSquare, toSquare);
   }
   fullBoard.forceLightLevel(boardStyle.getLightLevel());
   redrawNeeded = false;
   if (ChessCraft.getInstance().getDynmapIntegration() != null) {
     ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(fullBoard);
   }
 }
示例#17
0
 private void highlightBoardSquare(int row, int col, boolean highlight) {
   if (!highlight) {
     paintBoardSquare(row, col, null);
   } else {
     Cuboid sq = getSquare(row, col);
     MaterialWithData squareHighlightColor =
         boardStyle.getHighlightMaterial(col + (row % 2) % 2 == 1);
     switch (boardStyle.getHighlightStyle()) {
       case EDGES:
         sq.getFace(CuboidDirection.East).fill(squareHighlightColor);
         sq.getFace(CuboidDirection.North).fill(squareHighlightColor);
         sq.getFace(CuboidDirection.West).fill(squareHighlightColor);
         sq.getFace(CuboidDirection.South).fill(squareHighlightColor);
         break;
       case CORNERS:
         for (Block b : sq.corners()) {
           squareHighlightColor.applyToBlock(b);
         }
         break;
       case CHECKERED:
       case CHEQUERED:
         for (Block b : sq) {
           if ((b.getLocation().getBlockX() - b.getLocation().getBlockZ()) % 2 == 0) {
             squareHighlightColor.applyToBlock(b.getLocation().getBlock());
           }
         }
         break;
     }
   }
 }
示例#18
0
 private void highlightBoardSquare(int row, int col) {
   Cuboid sq = getSquare(row, col);
   MaterialData squareHighlightColor = boardStyle.getHighlightMaterial(col + (row % 2) % 2 == 1);
   switch (boardStyle.getHighlightStyle()) {
     case EDGES:
       sq.getFace(CuboidDirection.East).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.North).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.West).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.South).fill(squareHighlightColor);
       break;
     case CORNERS:
       for (Block b : sq.corners()) {
         b.setTypeIdAndData(
             squareHighlightColor.getItemTypeId(), squareHighlightColor.getData(), false);
       }
       break;
     case CHECKERED:
     case CHEQUERED:
       for (Block b : sq) {
         if ((b.getLocation().getBlockX() - b.getLocation().getBlockZ()) % 2 == 0) {
           b.setTypeIdAndData(
               squareHighlightColor.getItemTypeId(), squareHighlightColor.getData(), false);
         }
       }
       break;
     default:
       break;
   }
   if (ChessCraft.getInstance().getDynmapIntegration() != null) {
     ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(sq);
   }
 }
示例#19
0
  private void paintChessPiece(Cuboid region, ChessStone stone, MassBlockUpdate mbu) {
    assert region.getSizeX() >= stone.getSizeX();
    assert region.getSizeZ() >= stone.getSizeZ();

    int xOff = (region.getSizeX() - stone.getSizeX()) / 2;
    int zOff = (region.getSizeZ() - stone.getSizeZ()) / 2;

    Map<Block, MaterialWithData> deferred = new HashMap<Block, MaterialWithData>();
    World world = region.getWorld();
    for (int x = 0; x < stone.getSizeX(); x++) {
      for (int y = 0; y < stone.getSizeY(); y++) {
        for (int z = 0; z < stone.getSizeZ(); z++) {
          MaterialWithData mat = stone.getMaterial(x, y, z);
          if (mat.getId() == 0) {
            // the region was pre-cleared, skip placing air a second time
            continue;
          }
          Block b = region.getRelativeBlock(world, x + xOff, y, z + zOff);
          if (BlockType.shouldPlaceLast(mat.getId())) {
            deferred.put(b, mat);
          } else {
            mat.applyToBlock(b, mbu);
          }
        }
      }
    }

    for (Entry<Block, MaterialWithData> e : deferred.entrySet()) {
      e.getValue().applyToBlock(e.getKey(), mbu);
    }
  }
示例#20
0
  /**
   * Use Bresenham's algorithm to draw line between two squares on the board
   *
   * @param from Square index of the first square
   * @param to Square index of the second square
   * @param isHighlighting True if drawing a highlight, false if erasing it
   */
  private void drawHighlightLine(int from, int to, boolean isHighlighting) {
    if (from < 0 || to < 0 || from >= 64 || to >= 64) {
      return;
    }

    Cuboid s1 = getSquare(Chess.sqiToRow(from), Chess.sqiToCol(from));
    Cuboid s2 = getSquare(Chess.sqiToRow(to), Chess.sqiToCol(to));
    Location loc1 = s1.getRelativeBlock(s1.getSizeX() / 2, 0, s1.getSizeZ() / 2).getLocation();
    Location loc2 = s2.getRelativeBlock(s2.getSizeX() / 2, 0, s2.getSizeZ() / 2).getLocation();

    int dx = Math.abs(loc1.getBlockX() - loc2.getBlockX());
    int dz = Math.abs(loc1.getBlockZ() - loc2.getBlockZ());
    int sx = loc1.getBlockX() < loc2.getBlockX() ? 1 : -1;
    int sz = loc1.getBlockZ() < loc2.getBlockZ() ? 1 : -1;
    int err = dx - dz;

    while (loc1.getBlockX() != loc2.getBlockX() || loc1.getBlockZ() != loc2.getBlockZ()) {
      int sqi = getSquareAt(loc1);
      MaterialData m =
          isHighlighting
              ? boardStyle.getHighlightMaterial(Chess.isWhiteSquare(sqi))
              : (Chess.isWhiteSquare(sqi)
                  ? boardStyle.getWhiteSquareMaterial()
                  : boardStyle.getBlackSquareMaterial());
      loc1.getBlock().setTypeIdAndData(m.getItemTypeId(), m.getData(), false);
      int e2 = 2 * err;
      if (e2 > -dz) {
        err -= dz;
        loc1.add(sx, 0, 0);
      }
      if (e2 < dx) {
        err += dx;
        loc1.add(0, 0, sz);
      }
    }
  }
示例#21
0
  private void paintStruts(MassBlockUpdate mbu) {
    MaterialData struts = boardStyle.getStrutsMaterial();

    // vertical struts at the frame corners
    Cuboid c =
        new Cuboid(frameBoard.getLowerNE())
            .shift(CuboidDirection.Up, 1)
            .expand(CuboidDirection.Up, boardStyle.getHeight());
    c.fill(struts, mbu);
    c = c.shift(CuboidDirection.South, frameBoard.getSizeX() - 1);
    c.fill(struts, mbu);
    c = c.shift(CuboidDirection.West, frameBoard.getSizeZ() - 1);
    c.fill(struts, mbu);
    c = c.shift(CuboidDirection.North, frameBoard.getSizeZ() - 1);
    c.fill(struts, mbu);

    // horizontal struts along roof edge
    Cuboid roof = frameBoard.shift(CuboidDirection.Up, boardStyle.getHeight() + 1);
    roof.getFace(CuboidDirection.East).fill(struts, mbu);
    roof.getFace(CuboidDirection.North).fill(struts, mbu);
    roof.getFace(CuboidDirection.West).fill(struts, mbu);
    roof.getFace(CuboidDirection.South).fill(struts, mbu);
  }
示例#22
0
 /** Clear full area associated with this board */
 void clearAll() {
   MassBlockUpdate mbu = CraftMassBlockUpdate.createMassBlockUpdater(getBoard().getWorld());
   fullBoard.fill(0, (byte) 0, mbu);
   mbu.notifyClients();
 }