Search in sources :

Example 6 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCRobotBrain method handleCANCELBUILDREQUEST.

/**
 * Handle a CANCELBUILDREQUEST for this game.
 *<P>
 *<b> During game startup</b> (START1B, START2B, or START3B): <BR>
 *    When sent from server to client, CANCELBUILDREQUEST means the current
 *    player wants to undo the placement of their initial settlement.
 *    This handler method calls {@link SOCGame#undoPutInitSettlement(SOCPlayingPiece)}
 *    and {@link SOCPlayerTracker#setPendingInitSettlement(SOCSettlement) tracker.setPendingInitSettlement(null)}.
 *<P>
 *<b> During piece placement</b> (PLACING_ROAD, PLACING_CITY, PLACING_SETTLEMENT,
 *                         PLACING_FREE_ROAD1, or PLACING_FREE_ROAD2): <BR>
 *    When sent from server to client, CANCELBUILDREQUEST means the player
 *    has sent an illegal PUTPIECE (bad building location).
 *    Humans can probably decide a better place to put their road,
 *    but robots must cancel the build request and decide on a new plan.
 *
 * @since 1.1.08
 */
private void handleCANCELBUILDREQUEST(SOCCancelBuildRequest mes) {
    final int gstate = game.getGameState();
    switch(gstate) {
        case SOCGame.START1A:
        case SOCGame.START2A:
        case SOCGame.START3A:
            if (ourTurn) {
                cancelWrongPiecePlacement(mes);
            }
            break;
        case SOCGame.START1B:
        case SOCGame.START2B:
        case SOCGame.START3B:
            if (ourTurn) {
                cancelWrongPiecePlacement(mes);
            } else {
                // 
                // Human player placed, then cancelled placement
                // (assume mes.getPieceType() == SOCPlayingPiece.SETTLEMENT).
                // Our robot wouldn't do that, and if it's ourTurn,
                // the cancel happens only if we try an illegal placement.
                // 
                final int pnum = game.getCurrentPlayerNumber();
                SOCPlayer pl = game.getPlayer(pnum);
                SOCSettlement pp = new SOCSettlement(pl, pl.getLastSettlementCoord(), null);
                game.undoPutInitSettlement(pp);
                // 
                // "forget" to track this cancelled initial settlement.
                // Wait for human player to place a new one.
                // 
                SOCPlayerTracker tr = playerTrackers.get(Integer.valueOf(pnum));
                tr.setPendingInitSettlement(null);
            }
            break;
        // asked to build, hasn't given location yet -> resources
        case SOCGame.PLAY1:
        // has given location -> is bad location
        case SOCGame.PLACING_ROAD:
        case SOCGame.PLACING_SETTLEMENT:
        case SOCGame.PLACING_CITY:
        case SOCGame.PLACING_SHIP:
        // JM TODO how to break out?
        case SOCGame.PLACING_FREE_ROAD1:
        // JM TODO how to break out?
        case SOCGame.PLACING_FREE_ROAD2:
        case SOCGame.SPECIAL_BUILDING:
            // 
            // We've asked for an illegal piece placement.
            // (Must be a bug.) Cancel and invalidate this
            // planned piece, make a new plan.
            // 
            // Can also happen in special building, if another
            // player has placed since we requested special building.
            // If our PUTPIECE request is denied, server sends us
            // CANCELBUILDREQUEST.  We need to ask to cancel the
            // placement, and also set variables to end our SBP turn.
            // 
            cancelWrongPiecePlacement(mes);
            break;
        default:
            if (game.isSpecialBuilding()) {
                cancelWrongPiecePlacement(mes);
            } else {
                // Should not occur
                System.err.println("L2521 SOCRobotBrain: " + client.getNickname() + ": Unhandled CANCELBUILDREQUEST at state " + gstate);
            }
    }
// switch (gameState)
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCPlayer(soc.game.SOCPlayer)

Example 7 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCRobotBrain method cancelWrongPiecePlacement.

/**
 *  We've asked for an illegal piece placement.
 *  Cancel and invalidate this planned piece, make a new plan.
 *  If {@link SOCGame#isSpecialBuilding()}, will set variables to
 *  force the end of our special building turn.
 *  Also handles illegal requests to buy development cards
 *  (piece type -2 in {@link SOCCancelBuildRequest}).
 *<P>
 *  Must update game data by calling {@link SOCGame#setGameState(int)} before calling this method.
 *<P>
 *  This method increments {@link #failedBuildingAttempts},
 *  but won't leave the game if we've failed too many times.
 *  The brain's run loop should make that decision.
 *<UL>
 * <LI> If {@link SOCGame#getGameState()} is {@link SOCGame#PLAY1},
 *   server likely denied us due to resources, not due to building plan
 *   being interrupted by another player's building before our special building phase.
 *   (Could also be due to a bug in the chosen building plan.)
 *   Will clear our building plan so we'll make a new one.
 * <LI> In other gamestates, assumes requested piece placement location was illegal.
 *   Will call {@link #cancelWrongPiecePlacementLocal(SOCPlayingPiece)}
 *   so we don't try again to build there.
 * <LI> Either way, sends a {@link CancelBuildRequest} message to the server.
 *</UL>
 *
 * @param mes  Cancel message from server, including piece type
 */
protected void cancelWrongPiecePlacement(SOCCancelBuildRequest mes) {
    // == -2
    final boolean cancelBuyDevCard = (mes.getPieceType() == SOCPossiblePiece.CARD);
    if (cancelBuyDevCard) {
        waitingForDevCard = false;
    } else {
        whatWeFailedToBuild = whatWeWantToBuild;
        ++failedBuildingAttempts;
    }
    waitingForGameState = false;
    final int gameState = game.getGameState();
    /**
     * if true, server likely denied us due to resources, not due to building plan
     * being interrupted by another player's building before our special building phase.
     * (Could also be due to a bug in the chosen building plan.)
     */
    final boolean gameStateIsPLAY1 = (gameState == SOCGame.PLAY1);
    if (!(gameStateIsPLAY1 || cancelBuyDevCard)) {
        int coord = -1;
        switch(gameState) {
            case SOCGame.START1A:
            case SOCGame.START1B:
            case SOCGame.START2A:
            case SOCGame.START2B:
            case SOCGame.START3A:
            case SOCGame.START3B:
                coord = lastStartingPieceCoord;
                break;
            default:
                if (whatWeWantToBuild != null)
                    coord = whatWeWantToBuild.getCoordinates();
        }
        if (coord != -1) {
            SOCPlayingPiece cancelPiece;
            /**
             * First, invalidate that piece in trackers, so we don't try again to
             * build it. If we treat it like another player's new placement, we
             * can remove any of our planned pieces depending on this one.
             */
            switch(mes.getPieceType()) {
                case SOCPlayingPiece.ROAD:
                    cancelPiece = new SOCRoad(dummyCancelPlayerData, coord, null);
                    break;
                case SOCPlayingPiece.SETTLEMENT:
                    cancelPiece = new SOCSettlement(dummyCancelPlayerData, coord, null);
                    break;
                case SOCPlayingPiece.CITY:
                    cancelPiece = new SOCCity(dummyCancelPlayerData, coord, null);
                    break;
                case SOCPlayingPiece.SHIP:
                    cancelPiece = new SOCShip(dummyCancelPlayerData, coord, null);
                    break;
                default:
                    // To satisfy javac
                    cancelPiece = null;
            }
            cancelWrongPiecePlacementLocal(cancelPiece);
        }
    } else {
        /**
         *  stop trying to build it now, but don't prevent
         *  us from trying later to build it.
         */
        whatWeWantToBuild = null;
        buildingPlan.clear();
    }
    if (gameStateIsPLAY1 || game.isSpecialBuilding()) {
        // Shouldn't have asked to build this piece at this time.
        // End our confusion by ending our current turn. Can re-plan on next turn.
        failedBuildingAttempts = MAX_DENIED_BUILDING_PER_TURN;
        expectPLACING_ROAD = false;
        expectPLACING_SETTLEMENT = false;
        expectPLACING_CITY = false;
        expectPLACING_SHIP = false;
        decidedIfSpecialBuild = true;
        if (!cancelBuyDevCard) {
            // special building, currently in state PLACING_* ;
            // get our resources back, get state PLAY1 or SPECIALBUILD
            waitingForGameState = true;
            expectPLAY1 = true;
            client.cancelBuildRequest(game, mes.getPieceType());
        }
    } else if (gameState <= SOCGame.START3B) {
        switch(gameState) {
            case SOCGame.START1A:
                expectPUTPIECE_FROM_START1A = false;
                expectSTART1A = true;
                break;
            case SOCGame.START1B:
                expectPUTPIECE_FROM_START1B = false;
                expectSTART1B = true;
                break;
            case SOCGame.START2A:
                expectPUTPIECE_FROM_START2A = false;
                expectSTART2A = true;
                break;
            case SOCGame.START2B:
                expectPUTPIECE_FROM_START2B = false;
                expectSTART2B = true;
                break;
            case SOCGame.START3A:
                expectPUTPIECE_FROM_START3A = false;
                expectSTART3A = true;
                break;
            case SOCGame.START3B:
                expectPUTPIECE_FROM_START3B = false;
                expectSTART3B = true;
                break;
        }
    // The run loop will check if failedBuildingAttempts > (2 * MAX_DENIED_BUILDING_PER_TURN).
    // This bot will leave the game there if it can't recover.
    } else {
        expectPLAY1 = true;
        waitingForGameState = true;
        counter = 0;
        client.cancelBuildRequest(game, mes.getPieceType());
    // Now wait for the play1 message, then can re-plan another piece.
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCCity(soc.game.SOCCity) SOCPlayingPiece(soc.game.SOCPlayingPiece) SOCShip(soc.game.SOCShip) SOCRoad(soc.game.SOCRoad)

Example 8 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCBoardAtServer method startGame_putInitPieces.

/**
 * For scenario game option {@link SOCGameOption#K_SC_PIRI _SC_PIRI},
 * place each player's initial pieces.  For {@link SOCGameOption#K_SC_FTRI _SC_FTRI},
 * set aside some dev cards to be claimed later at Special Edges.
 * Otherwise do nothing.
 *<P>
 * For {@code _SC_PIRI}, also calls each player's {@link SOCPlayer#addLegalSettlement(int, boolean)}
 * for their Lone Settlement location (adds layout part "LS").
 * Vacant player numbers get 0 for their {@code "LS"} element.
 *<P>
 * Called only at server. For a method called during game start
 * at server and clients, see {@link SOCGame#updateAtBoardLayout()}.
 *<P>
 * Called from {@link SOCGameHandler#startGame(SOCGame)} for those
 * scenario game options; if you need it called for your game, add
 * a check there for your scenario's {@link SOCGameOption}.
 *<P>
 * This is called after {@link #makeNewBoard(Map)} and before
 * {@link SOCGameHandler#getBoardLayoutMessage}.  So if needed,
 * it can call {@link SOCBoardLarge#setAddedLayoutPart(String, int[])}.
 *<P>
 * If ship placement is restricted by the scenario, please call each player's
 * {@link SOCPlayer#setRestrictedLegalShips(int[])} before calling this method,
 * so the legal and potential arrays will be initialized.
 *
 * @see #getLegalSeaEdges(SOCGame, int)
 */
public void startGame_putInitPieces(SOCGame ga) {
    if (ga.isGameOptionSet(SOCGameOption.K_SC_FTRI)) {
        // Set aside dev cards for players to be given when reaching "CE" Special Edges.
        final int cpn = ga.getCurrentPlayerNumber();
        // to call buyDevCard without giving it to a player
        ga.setCurrentPlayerNumber(-1);
        drawStack = new Stack<Integer>();
        final int n = FOR_TRI_DEV_CARD_EDGES[(ga.maxPlayers > 4) ? 1 : 0].length;
        for (int i = 0; i < n; ++i) drawStack.push(ga.buyDevCard());
        ga.setCurrentPlayerNumber(cpn);
        return;
    }
    if (!ga.isGameOptionSet(SOCGameOption.K_SC_PIRI))
        return;
    final int gstate = ga.getGameState();
    // prevent ga.putPiece from advancing turn
    ga.setGameState(SOCGame.READY);
    final int[] inits = PIR_ISL_INIT_PIECES[(ga.maxPlayers > 4) ? 1 : 0];
    // lone possible-settlement node on the way to the island.
    int[] possiLoneSettles = new int[ga.maxPlayers];
    // vacant players will get 0 here, will not get free settlement, ship, or pirate fortress.
    // iterate i only when player present, to avoid spacing gaps from vacant players
    int i = 0;
    for (int pn = 0; pn < ga.maxPlayers; ++pn) {
        if (ga.isSeatVacant(pn))
            continue;
        SOCPlayer pl = ga.getPlayer(pn);
        ga.putPiece(new SOCSettlement(pl, inits[i], this));
        ++i;
        ga.putPiece(new SOCShip(pl, inits[i], this));
        ++i;
        ga.putPiece(new SOCFortress(pl, inits[i], this));
        ++i;
        possiLoneSettles[pn] = inits[i];
        ga.getPlayer(pn).addLegalSettlement(inits[i], false);
        ++i;
    }
    setAddedLayoutPart("LS", possiLoneSettles);
    ga.setGameState(gstate);
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCFortress(soc.game.SOCFortress)

Example 9 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCBoardPanel method drawBoard.

/**
 * Draw the whole board, including pieces and tooltip ({@link #hilight}, {@link #hoverTip}) if applicable.
 * The basic board without pieces is drawn just once, then buffered.
 * If the board layout changes (at start of game, for example),
 * call {@link #flushBoardLayoutAndRepaint()} to clear the buffered copy.
 *
 * @see #drawBoardEmpty(Graphics)
 */
private void drawBoard(Graphics g) {
    Image ebb = emptyBoardBuffer;
    if (scaledMissedImage || ebb == null) {
        if (ebb == null) {
            ebb = createImage(scaledPanelW, scaledPanelH);
            emptyBoardBuffer = ebb;
        }
        drawnEmptyAt = System.currentTimeMillis();
        // drawBoardEmpty, drawHex will set this flag if missed
        scaledMissedImage = false;
        drawBoardEmpty(ebb.getGraphics());
        ebb.flush();
        if (scaledMissedImage && (scaledAt != 0) && (RESCALE_MAX_RETRY_MS < (drawnEmptyAt - scaledAt)))
            // eventually give up scaling it
            scaledMissedImage = false;
    }
    // draw ebb from local variable, not emptyBoardBuffer field, to avoid occasional NPE
    g.setPaintMode();
    g.drawImage(ebb, 0, 0, this);
    // ask for antialiasing if available
    if (g instanceof Graphics2D)
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    final boolean xlat = (panelMarginX != 0) || (panelMarginY != 0);
    if (xlat)
        g.translate(panelMarginX, panelMarginY);
    final int gameState = game.getGameState();
    if (board.getRobberHex() != -1) {
        drawRobber(g, board.getRobberHex(), (gameState != SOCGame.PLACING_ROBBER), true);
    }
    if (board.getPreviousRobberHex() != -1) {
        drawRobber(g, board.getPreviousRobberHex(), (gameState != SOCGame.PLACING_ROBBER), false);
    }
    if (isLargeBoard) {
        int hex = ((SOCBoardLarge) board).getPirateHex();
        if (hex > 0) {
            drawRoadOrShip(g, hex, -2, (gameState == SOCGame.PLACING_PIRATE), false, false);
        }
        hex = ((SOCBoardLarge) board).getPreviousPirateHex();
        if (hex > 0) {
            drawRoadOrShip(g, hex, -3, (gameState == SOCGame.PLACING_PIRATE), false, false);
        }
    }
    /**
     * draw the roads and ships
     */
    if (!game.isGameOptionSet(SOCGameOption.K_SC_PIRI)) {
        for (SOCRoad r : board.getRoads()) {
            drawRoadOrShip(g, r.getCoordinates(), r.getPlayerNumber(), false, !(r instanceof SOCShip), false);
        }
    } else {
        for (int pn = 0; pn < game.maxPlayers; ++pn) {
            final SOCPlayer pl = game.getPlayer(pn);
            // count warships here, for efficiency, instead of calling SOCGame.isShipWarship for each one
            int numWarships = pl.getNumWarships();
            for (SOCRoad r : pl.getRoads()) {
                final boolean isShip = (r instanceof SOCShip);
                final boolean isWarship = isShip && (numWarships > 0);
                drawRoadOrShip(g, r.getCoordinates(), pn, false, !isShip, isWarship);
                if (isWarship)
                    // this works since warships begin with player's 1st-placed ship in getRoads()
                    --numWarships;
            }
            /**
             * draw the player's fortress, if any
             */
            SOCFortress fo = pl.getFortress();
            if (fo != null)
                drawFortress(g, fo, pn, false);
        }
    }
    /**
     * draw the settlements
     */
    for (SOCSettlement s : board.getSettlements()) {
        drawSettlement(g, s.getCoordinates(), s.getPlayerNumber(), false, false);
    }
    /**
     * draw the cities
     */
    for (SOCCity c : board.getCities()) {
        drawCity(g, c.getCoordinates(), c.getPlayerNumber(), false);
    }
    if (xlat)
        g.translate(-panelMarginX, -panelMarginY);
    /**
     * draw the current-player arrow after ("above") pieces,
     * but below any hilighted piece, in case of overlap at
     * edge of board. More likely on 6-player board for the
     * two players whose handpanels are vertically centered.
     */
    if (gameState != SOCGame.NEW) {
        drawArrow(g, game.getCurrentPlayerNumber(), game.getCurrentDice());
    }
    if (player != null) {
        if (xlat)
            g.translate(panelMarginX, panelMarginY);
        /**
         * Draw the hilight when in interactive mode;
         * No hilight when null player (before game started).
         * The "hovering" road/settlement/city are separately painted
         * in {@link soc.client.SOCBoardPanel.BoardToolTip#paint()}.
         */
        switch(mode) {
            case MOVE_SHIP:
                if (moveShip_fromEdge != 0)
                    drawRoadOrShip(g, moveShip_fromEdge, -1, false, false, moveShip_isWarship);
            case PLACE_ROAD:
            case PLACE_INIT_ROAD:
            case PLACE_FREE_ROAD_OR_SHIP:
                if (hilight != 0) {
                    drawRoadOrShip(g, hilight, playerNumber, true, !hilightIsShip, (moveShip_isWarship && (moveShip_fromEdge != 0)));
                }
                break;
            case PLACE_SETTLEMENT:
            case PLACE_INIT_SETTLEMENT:
                if (hilight > 0) {
                    drawSettlement(g, hilight, playerNumber, true, false);
                }
                break;
            case PLACE_CITY:
                if (hilight > 0) {
                    drawCity(g, hilight, playerNumber, true);
                }
                break;
            case PLACE_SHIP:
                if (hilight > 0) {
                    drawRoadOrShip(g, hilight, playerNumber, true, false, false);
                }
                break;
            case CONSIDER_LM_SETTLEMENT:
            case CONSIDER_LT_SETTLEMENT:
                if (hilight > 0) {
                    drawSettlement(g, hilight, otherPlayer.getPlayerNumber(), true, false);
                }
                break;
            case CONSIDER_LM_ROAD:
            case CONSIDER_LT_ROAD:
                if (hilight != 0) {
                    drawRoadOrShip(g, hilight, otherPlayer.getPlayerNumber(), false, true, false);
                }
                break;
            case CONSIDER_LM_CITY:
            case CONSIDER_LT_CITY:
                if (hilight > 0) {
                    drawCity(g, hilight, otherPlayer.getPlayerNumber(), true);
                }
                break;
            case PLACE_ROBBER:
                if (hilight > 0) {
                    drawRobber(g, hilight, true, true);
                }
                break;
            case PLACE_PIRATE:
                if (hilight > 0) {
                    drawRoadOrShip(g, hilight, -2, false, false, false);
                }
                break;
            case SC_FTRI_PLACE_PORT:
                drawBoard_SC_FTRI_placePort(g);
                break;
        }
        if (xlat)
            g.translate(-panelMarginX, -panelMarginY);
    }
    if (superText1 != null) {
        drawSuperText(g);
    }
    if (superTextTop != null) {
        drawSuperTextTop(g);
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCBoardLarge(soc.game.SOCBoardLarge) SOCCity(soc.game.SOCCity) SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCFortress(soc.game.SOCFortress) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) SOCRoad(soc.game.SOCRoad) Graphics2D(java.awt.Graphics2D)

Example 10 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCBoardPanel method mouseClicked.

/**
 * DOCUMENT ME!
 *
 * @param evt DOCUMENT ME!
 */
public void mouseClicked(MouseEvent evt) {
    try {
        int x = evt.getX();
        int y = evt.getY();
        if (evt.isPopupTrigger()) {
            popupMenuSystime = evt.getWhen();
            evt.consume();
            doBoardMenuPopup(x, y);
            // <--- Pop up menu, nothing else to do ---
            return;
        }
        if (evt.getWhen() < (popupMenuSystime + POPUP_MENU_IGNORE_MS)) {
            // <--- Ignore click: too soon after popup click ---
            return;
        }
        boolean tempChangedMode = false;
        if ((mode == NONE) && hoverTip.isVisible()) {
            if (game.isDebugFreePlacement()) {
                if (hoverTip.hoverSettlementID != 0) {
                    hilight = hoverTip.hoverSettlementID;
                    hilightIsShip = false;
                    mode = PLACE_SETTLEMENT;
                    tempChangedMode = true;
                } else if (hoverTip.hoverCityID != 0) {
                    hilight = hoverTip.hoverCityID;
                    hilightIsShip = false;
                    mode = PLACE_CITY;
                    tempChangedMode = true;
                } else if (hoverTip.hoverRoadID != 0) {
                    hilight = hoverTip.hoverRoadID;
                    hilightIsShip = false;
                    mode = PLACE_ROAD;
                    tempChangedMode = true;
                } else if (hoverTip.hoverShipID != 0) {
                    hilight = hoverTip.hoverShipID;
                    hilightIsShip = true;
                    mode = PLACE_SHIP;
                    tempChangedMode = true;
                }
            } else if (((evt.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) && (player != null) && (game.getCurrentPlayerNumber() == playerNumber) && (player.getPublicVP() == 2) && (hintShownCount_RightClickToBuild < 2)) {
                // To help during the start of the game, display a hint message
                // reminding new users to right-click to build (OSX: control-click).
                // Show it at most twice to avoid annoying the user.
                ++hintShownCount_RightClickToBuild;
                final String prompt = (SOCPlayerClient.isJavaOnOSX) ? "board.popup.hint_build_click.osx" : // "To build pieces, hold Control while clicking the build location."
                "board.popup.hint_build_click";
                // "To build pieces, right-click the build location."
                NotifyDialog.createAndShow(playerInterface.getGameDisplay(), playerInterface, "\n" + strings.get(prompt), null, true);
            // start prompt with \n to prevent it being a lengthy popup-dialog title
            }
        }
        if ((hilight != 0) && (player != null) && (x == ptrOldX) && (y == ptrOldY)) {
            SOCPlayerClient client = playerInterface.getClient();
            switch(mode) {
                case NONE:
                    break;
                case TURN_STARTING:
                    break;
                case PLACE_INIT_ROAD:
                case PLACE_ROAD:
                case PLACE_FREE_ROAD_OR_SHIP:
                    if (hilight == -1)
                        // Road on edge 0x00
                        hilight = 0;
                    if (player.isPotentialRoad(hilight) && !hilightIsShip) {
                        client.getGameManager().putPiece(game, new SOCRoad(player, hilight, board));
                        // Now that we've placed, clear the mode and the hilight.
                        clearModeAndHilight(SOCPlayingPiece.ROAD);
                        if (tempChangedMode)
                            hoverTip.hideHoverAndPieces();
                    } else if (// checks isPotentialShip, pirate ship
                    game.canPlaceShip(player, hilight)) {
                        if (game.isGameOptionSet(SOCGameOption.K_SC_FTRI) && ((SOCBoardLarge) board).canRemovePort(hilight)) {
                            java.awt.EventQueue.invokeLater(new ConfirmPlaceShipDialog(hilight, false, -1));
                        } else {
                            client.getGameManager().putPiece(game, new SOCShip(player, hilight, board));
                            // Now that we've placed, clear the mode and the hilight.
                            clearModeAndHilight(SOCPlayingPiece.SHIP);
                        }
                        if (tempChangedMode)
                            hoverTip.hideHoverAndPieces();
                    }
                    break;
                case MOVE_SHIP:
                    // check and move ship to hilight from fromEdge;
                    // also sets moveShip_fromEdge = 0, calls clearModeAndHilight.
                    moveShip_toEdge = hilight;
                    tryMoveShipToEdge();
                    break;
                case PLACE_INIT_SETTLEMENT:
                    if (playerNumber == playerInterface.getClientPlayerNumber()) {
                        initSettlementNode = hilight;
                    }
                case PLACE_SETTLEMENT:
                    if (player.canPlaceSettlement(hilight)) {
                        client.getGameManager().putPiece(game, new SOCSettlement(player, hilight, board));
                        clearModeAndHilight(SOCPlayingPiece.SETTLEMENT);
                        if (tempChangedMode)
                            hoverTip.hideHoverAndPieces();
                    }
                    break;
                case PLACE_CITY:
                    if (player.isPotentialCity(hilight)) {
                        client.getGameManager().putPiece(game, new SOCCity(player, hilight, board));
                        clearModeAndHilight(SOCPlayingPiece.CITY);
                        if (tempChangedMode)
                            hoverTip.hideHoverAndPieces();
                    }
                    break;
                case PLACE_SHIP:
                    if (// checks isPotentialShip, pirate ship
                    game.canPlaceShip(player, hilight)) {
                        if (game.isGameOptionSet(SOCGameOption.K_SC_FTRI) && ((SOCBoardLarge) board).canRemovePort(hilight)) {
                            java.awt.EventQueue.invokeLater(new ConfirmPlaceShipDialog(hilight, false, -1));
                        } else {
                            client.getGameManager().putPiece(game, new SOCShip(player, hilight, board));
                            clearModeAndHilight(SOCPlayingPiece.SHIP);
                        }
                        if (tempChangedMode)
                            hoverTip.hideHoverAndPieces();
                    }
                    break;
                case PLACE_ROBBER:
                    if (hilight != board.getRobberHex()) {
                        // do we have an adjacent settlement/city?
                        boolean cliAdjacent = false;
                        {
                            for (SOCPlayer pl : game.getPlayersOnHex(hilight)) {
                                if (pl.getPlayerNumber() == playerNumber) {
                                    cliAdjacent = true;
                                    break;
                                }
                            }
                        }
                        if (cliAdjacent) {
                            // ask player to confirm first
                            java.awt.EventQueue.invokeLater(new MoveRobberConfirmDialog(player, hilight));
                        } else {
                            // ask server to move it
                            client.getGameManager().moveRobber(game, player, hilight);
                            clearModeAndHilight(-1);
                        }
                    }
                    break;
                case PLACE_PIRATE:
                    if (hilight != ((SOCBoardLarge) board).getPirateHex()) {
                        // do we have an adjacent ship?
                        boolean cliAdjacent = false;
                        {
                            for (SOCPlayer pl : game.getPlayersShipsOnHex(hilight)) {
                                if (pl.getPlayerNumber() == playerNumber) {
                                    cliAdjacent = true;
                                    break;
                                }
                            }
                        }
                        if (cliAdjacent) {
                            // ask player to confirm first
                            java.awt.EventQueue.invokeLater(new MoveRobberConfirmDialog(player, -hilight));
                        } else {
                            // ask server to move it
                            client.getGameManager().moveRobber(game, player, -hilight);
                            clearModeAndHilight(-1);
                        }
                    }
                    break;
                case SC_FTRI_PLACE_PORT:
                    if (hilight != 0) {
                        int edge = hilight;
                        if (edge == -1)
                            edge = 0;
                        if (game.canPlacePort(player, edge)) {
                            // Ask server to place here.
                            client.getGameManager().sendSimpleRequest(player, SOCSimpleRequest.TRADE_PORT_PLACE, hilight, 0);
                            hilight = 0;
                        }
                    }
                    break;
                case CONSIDER_LM_SETTLEMENT:
                    if (otherPlayer.canPlaceSettlement(hilight)) {
                        client.getGameManager().considerMove(game, otherPlayer.getName(), new SOCSettlement(otherPlayer, hilight, board));
                        clearModeAndHilight(SOCPlayingPiece.SETTLEMENT);
                    }
                    break;
                case CONSIDER_LM_ROAD:
                    if (otherPlayer.isPotentialRoad(hilight)) {
                        client.getGameManager().considerMove(game, otherPlayer.getName(), new SOCRoad(otherPlayer, hilight, board));
                        clearModeAndHilight(SOCPlayingPiece.ROAD);
                    }
                    break;
                case CONSIDER_LM_CITY:
                    if (otherPlayer.isPotentialCity(hilight)) {
                        client.getGameManager().considerMove(game, otherPlayer.getName(), new SOCCity(otherPlayer, hilight, board));
                        clearModeAndHilight(SOCPlayingPiece.CITY);
                    }
                    break;
                case CONSIDER_LT_SETTLEMENT:
                    if (otherPlayer.canPlaceSettlement(hilight)) {
                        client.getGameManager().considerTarget(game, otherPlayer.getName(), new SOCSettlement(otherPlayer, hilight, board));
                        clearModeAndHilight(SOCPlayingPiece.SETTLEMENT);
                    }
                    break;
                case CONSIDER_LT_ROAD:
                    if (otherPlayer.isPotentialRoad(hilight)) {
                        client.getGameManager().considerTarget(game, otherPlayer.getName(), new SOCRoad(otherPlayer, hilight, board));
                        clearModeAndHilight(SOCPlayingPiece.ROAD);
                    }
                    break;
                case CONSIDER_LT_CITY:
                    if (otherPlayer.isPotentialCity(hilight)) {
                        client.getGameManager().considerTarget(game, otherPlayer.getName(), new SOCCity(otherPlayer, hilight, board));
                        clearModeAndHilight(SOCPlayingPiece.CITY);
                    }
                    break;
            }
        } else if ((player != null) && ((game.getCurrentPlayerNumber() == playerNumber) || game.isDebugFreePlacement())) {
            // No hilight. But, they clicked the board, expecting something.
            // It's possible the mode is incorrect.
            // Update and wait for the next click.
            updateMode();
            ptrOldX = 0;
            ptrOldY = 0;
            // mouseMoved will establish hilight using click's x,y
            mouseMoved(evt);
        }
        evt.consume();
        if (tempChangedMode)
            mode = NONE;
    } catch (Throwable th) {
        playerInterface.chatPrintStackTrace(th);
    }
}
Also used : SOCBoardLarge(soc.game.SOCBoardLarge) SOCShip(soc.game.SOCShip) SOCRoad(soc.game.SOCRoad) SOCSettlement(soc.game.SOCSettlement) SOCCity(soc.game.SOCCity) SOCPlayer(soc.game.SOCPlayer)

Aggregations

SOCSettlement (soc.game.SOCSettlement)18 SOCPlayer (soc.game.SOCPlayer)11 SOCShip (soc.game.SOCShip)11 SOCCity (soc.game.SOCCity)10 SOCRoad (soc.game.SOCRoad)10 SOCFortress (soc.game.SOCFortress)4 SOCPlayingPiece (soc.game.SOCPlayingPiece)3 SOCBoardLarge (soc.game.SOCBoardLarge)2 SOCVillage (soc.game.SOCVillage)2 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 SOCBoard (soc.game.SOCBoard)1 SOCGame (soc.game.SOCGame)1 SOCInventoryItem (soc.game.SOCInventoryItem)1