Search in sources :

Example 1 with SOCSettlement

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

the class SOCGameMessageHandler method handlePUTPIECE.

/**
 * handle "put piece" message.
 *<P>
 * Because the current player changes during initial placement,
 * this method has a simplified version of some of the logic from
 * {@link SOCGameHandler#endGameTurn(SOCGame, SOCPlayer, boolean)}
 * to detect and announce the new turn.
 *
 * @param c  the connection that sent the message
 * @param mes  the message
 * @since 1.0.0
 */
private void handlePUTPIECE(SOCGame ga, Connection c, SOCPutPiece mes) {
    ga.takeMonitor();
    try {
        final String gaName = ga.getName();
        final String plName = c.getData();
        SOCPlayer player = ga.getPlayer(plName);
        /**
         * make sure the player can do it
         */
        if (handler.checkTurn(c, ga)) {
            boolean sendDenyReply = false;
            /*
                   if (D.ebugOn) {
                   D.ebugPrintln("BEFORE");
                   for (int pn = 0; pn < SOCGame.MAXPLAYERS; pn++) {
                   SOCPlayer tmpPlayer = ga.getPlayer(pn);
                   D.ebugPrintln("Player # "+pn);
                   for (int i = 0x22; i < 0xCC; i++) {
                   if (tmpPlayer.isPotentialRoad(i))
                   D.ebugPrintln("### POTENTIAL ROAD AT "+Integer.toHexString(i));
                   }
                   }
                   }
                 */
            int gameState = ga.getGameState();
            final int coord = mes.getCoordinates();
            final int pieceType = mes.getPieceType();
            final int pn = player.getPlayerNumber();
            final boolean isBuyAndPut = (gameState == SOCGame.PLAY1) || (gameState == SOCGame.SPECIAL_BUILDING);
            if (isBuyAndPut) {
                if (!handleBUILDREQUEST(ga, player, c, pieceType, false)) {
                    // <--- Can't build right now ---
                    return;
                // will call ga.releaseMonitor() in finally-block before returning
                }
                // updated by handleBUILDREQUEST
                gameState = ga.getGameState();
            }
            switch(pieceType) {
                case SOCPlayingPiece.ROAD:
                    if ((gameState == SOCGame.START1B) || (gameState == SOCGame.START2B) || (gameState == SOCGame.START3B) || (gameState == SOCGame.PLACING_ROAD) || (gameState == SOCGame.PLACING_FREE_ROAD1) || (gameState == SOCGame.PLACING_FREE_ROAD2)) {
                        if (player.isPotentialRoad(coord) && (player.getNumPieces(SOCPlayingPiece.ROAD) >= 1)) {
                            final SOCRoad rd = new SOCRoad(player, coord, null);
                            // Changes game state and (if initial placement) player
                            ga.putPiece(rd);
                            // If placing this piece reveals a fog hex, putPiece will call srv.gameEvent
                            // which will send a SOCRevealFogHex message to the game.
                            /*
                               if (D.ebugOn) {
                               D.ebugPrintln("AFTER");
                               for (int pn = 0; pn < SOCGame.MAXPLAYERS; pn++) {
                               SOCPlayer tmpPlayer = ga.getPlayer(pn);
                               D.ebugPrintln("Player # "+pn);
                               for (int i = 0x22; i < 0xCC; i++) {
                               if (tmpPlayer.isPotentialRoad(i))
                               D.ebugPrintln("### POTENTIAL ROAD AT "+Integer.toHexString(i));
                               }
                               }
                               }
                             */
                            srv.gameList.takeMonitorForGame(gaName);
                            // "Joe built a road."
                            srv.messageToGameKeyed(ga, false, "action.built.road", plName);
                            srv.messageToGameWithMon(gaName, new SOCPutPiece(gaName, pn, SOCPlayingPiece.ROAD, coord));
                            if (!ga.pendingMessagesOut.isEmpty())
                                handler.sendGamePendingMessages(ga, false);
                            srv.gameList.releaseMonitorForGame(gaName);
                            // If needed, call sendTurn or send SOCRollDicePrompt
                            handler.sendTurnStateAtInitialPlacement(ga, player, c, gameState);
                            int newState = ga.getGameState();
                            if ((newState == SOCGame.STARTS_WAITING_FOR_PICK_GOLD_RESOURCE) || (newState == SOCGame.WAITING_FOR_PICK_GOLD_RESOURCE)) {
                                // gold hex revealed from fog (scenario SC_FOG)
                                handler.sendGameState_sendGoldPickAnnounceText(ga, gaName, c, null);
                            }
                        } else {
                            D.ebugPrintln("ILLEGAL ROAD: 0x" + Integer.toHexString(coord) + ": player " + pn);
                            if (player.isRobot() && D.ebugOn) {
                                D.ebugPrintln(" - pl.isPotentialRoad: " + player.isPotentialRoad(coord));
                                SOCPlayingPiece pp = ga.getBoard().roadAtEdge(coord);
                                D.ebugPrintln(" - roadAtEdge: " + ((pp != null) ? pp : "none"));
                            }
                            srv.messageToPlayerKeyed(c, gaName, "action.build.cannot.there.road");
                            // "You can't build a road there."
                            sendDenyReply = true;
                        }
                    } else {
                        srv.messageToPlayerKeyed(c, gaName, "action.build.cannot.now.road");
                    // "You can't build a road now."
                    }
                    break;
                case SOCPlayingPiece.SETTLEMENT:
                    if ((gameState == SOCGame.START1A) || (gameState == SOCGame.START2A) || (gameState == SOCGame.START3A) || (gameState == SOCGame.PLACING_SETTLEMENT)) {
                        if (player.canPlaceSettlement(coord) && (player.getNumPieces(SOCPlayingPiece.SETTLEMENT) >= 1)) {
                            final SOCSettlement se = new SOCSettlement(player, coord, null);
                            // Changes game state and (if initial placement) player
                            ga.putPiece(se);
                            srv.gameList.takeMonitorForGame(gaName);
                            // "Joe built a settlement."
                            srv.messageToGameKeyed(ga, false, "action.built.stlmt", plName);
                            srv.messageToGameWithMon(gaName, new SOCPutPiece(gaName, pn, SOCPlayingPiece.SETTLEMENT, coord));
                            if (!ga.pendingMessagesOut.isEmpty())
                                handler.sendGamePendingMessages(ga, false);
                            srv.gameList.releaseMonitorForGame(gaName);
                            // Check player and send new game state
                            if (!handler.checkTurn(c, ga))
                                // Announce new state and new current player
                                handler.sendTurn(ga, false);
                            else
                                handler.sendGameState(ga);
                            if (ga.hasSeaBoard && (ga.getGameState() == SOCGame.STARTS_WAITING_FOR_PICK_GOLD_RESOURCE)) {
                                // Prompt to pick from gold: send text and SOCSimpleRequest(PROMPT_PICK_RESOURCES)
                                handler.sendGameState_sendGoldPickAnnounceText(ga, gaName, c, null);
                            }
                        } else {
                            D.ebugPrintln("ILLEGAL SETTLEMENT: 0x" + Integer.toHexString(coord) + ": player " + pn);
                            if (player.isRobot() && D.ebugOn) {
                                D.ebugPrintln(" - pl.isPotentialSettlement: " + player.isPotentialSettlement(coord));
                                SOCPlayingPiece pp = ga.getBoard().settlementAtNode(coord);
                                D.ebugPrintln(" - settlementAtNode: " + ((pp != null) ? pp : "none"));
                            }
                            srv.messageToPlayerKeyed(c, gaName, "action.build.cannot.there.stlmt");
                            // "You can't build a settlement there."
                            sendDenyReply = true;
                        }
                    } else {
                        srv.messageToPlayerKeyed(c, gaName, "action.build.cannot.now.stlmt");
                    // "You can't build a settlement now."
                    }
                    break;
                case SOCPlayingPiece.CITY:
                    if (gameState == SOCGame.PLACING_CITY) {
                        if (player.isPotentialCity(coord) && (player.getNumPieces(SOCPlayingPiece.CITY) >= 1)) {
                            boolean houseRuleFirstCity = ga.isGameOptionSet("N7C") && !ga.hasBuiltCity();
                            if (houseRuleFirstCity && ga.isGameOptionSet("N7") && (ga.getRoundCount() < ga.getGameOptionIntValue("N7"))) {
                                // If "No 7s for first # rounds" is active, and this isn't its last round, 7s won't
                                // be rolled soon: Don't announce "Starting next turn, dice rolls of 7 may occur"
                                houseRuleFirstCity = false;
                            }
                            final SOCCity ci = new SOCCity(player, coord, null);
                            // changes game state and maybe player
                            ga.putPiece(ci);
                            srv.gameList.takeMonitorForGame(gaName);
                            // "Joe built a city."
                            srv.messageToGameKeyed(ga, false, "action.built.city", plName);
                            srv.messageToGameWithMon(gaName, new SOCPutPiece(gaName, pn, SOCPlayingPiece.CITY, coord));
                            if (!ga.pendingMessagesOut.isEmpty())
                                handler.sendGamePendingMessages(ga, false);
                            if (houseRuleFirstCity)
                                srv.messageToGameKeyed(ga, false, "action.built.nextturn.7.houserule");
                            // "Starting next turn, dice rolls of 7 may occur (house rule)."
                            srv.gameList.releaseMonitorForGame(gaName);
                            // Check player and send new game state
                            if (!handler.checkTurn(c, ga))
                                // Announce new state and new current player
                                handler.sendTurn(ga, false);
                            else
                                handler.sendGameState(ga);
                        } else {
                            D.ebugPrintln("ILLEGAL CITY: 0x" + Integer.toHexString(coord) + ": player " + pn);
                            if (player.isRobot() && D.ebugOn) {
                                D.ebugPrintln(" - pl.isPotentialCity: " + player.isPotentialCity(coord));
                                SOCPlayingPiece pp = ga.getBoard().settlementAtNode(coord);
                                D.ebugPrintln(" - city/settlementAtNode: " + ((pp != null) ? pp : "none"));
                            }
                            srv.messageToPlayerKeyed(c, gaName, "action.build.cannot.there.city");
                            // "You can't build a city there."
                            sendDenyReply = true;
                        }
                    } else {
                        srv.messageToPlayerKeyed(c, gaName, "action.build.cannot.now.city");
                    // "You can't build a city now."
                    }
                    break;
                case SOCPlayingPiece.SHIP:
                    if ((gameState == SOCGame.START1B) || (gameState == SOCGame.START2B) || (gameState == SOCGame.START3B) || (gameState == SOCGame.PLACING_SHIP) || (gameState == SOCGame.PLACING_FREE_ROAD1) || (gameState == SOCGame.PLACING_FREE_ROAD2)) {
                        // Place it if we can; canPlaceShip checks potentials and pirate ship location
                        if (ga.canPlaceShip(player, coord) && (player.getNumPieces(SOCPlayingPiece.SHIP) >= 1)) {
                            final SOCShip sh = new SOCShip(player, coord, null);
                            // Changes game state and (during initial placement) sometimes player
                            ga.putPiece(sh);
                            srv.gameList.takeMonitorForGame(gaName);
                            // "Joe built a ship."
                            srv.messageToGameKeyed(ga, false, "action.built.ship", plName);
                            srv.messageToGameWithMon(gaName, new SOCPutPiece(gaName, pn, SOCPlayingPiece.SHIP, coord));
                            if (!ga.pendingMessagesOut.isEmpty())
                                handler.sendGamePendingMessages(ga, false);
                            srv.gameList.releaseMonitorForGame(gaName);
                            // If needed, call sendTurn or send SOCRollDicePrompt
                            handler.sendTurnStateAtInitialPlacement(ga, player, c, gameState);
                            int newState = ga.getGameState();
                            if ((newState == SOCGame.STARTS_WAITING_FOR_PICK_GOLD_RESOURCE) || (newState == SOCGame.WAITING_FOR_PICK_GOLD_RESOURCE)) {
                                // gold hex revealed from fog (scenario SC_FOG)
                                handler.sendGameState_sendGoldPickAnnounceText(ga, gaName, c, null);
                            }
                        } else {
                            D.ebugPrintln("ILLEGAL SHIP: 0x" + Integer.toHexString(coord) + ": player " + pn);
                            if (player.isRobot() && D.ebugOn) {
                                D.ebugPrintln(" - pl.isPotentialShip: " + player.isPotentialShip(coord));
                                SOCPlayingPiece pp = ga.getBoard().roadAtEdge(coord);
                                D.ebugPrintln(" - ship/roadAtEdge: " + ((pp != null) ? pp : "none"));
                            }
                            srv.messageToPlayerKeyed(c, gaName, "action.build.cannot.there.ship");
                            // "You can't build a ship there."
                            sendDenyReply = true;
                        }
                    } else {
                        srv.messageToPlayerKeyed(c, gaName, "action.build.cannot.now.ship");
                    // "You can't build a ship now."
                    }
                    break;
            }
            if (sendDenyReply) {
                if (isBuyAndPut)
                    // is probably now PLACING_*, was PLAY1 or SPECIAL_BUILDING
                    handler.sendGameState(ga);
                srv.messageToPlayer(c, new SOCCancelBuildRequest(gaName, mes.getPieceType()));
                if (player.isRobot()) {
                    // Set the "force end turn soon" field
                    ga.lastActionTime = 0L;
                }
            }
        } else {
            // "It's not your turn."
            srv.messageToPlayerKeyed(c, gaName, "reply.not.your.turn");
        }
    } catch (Exception e) {
        D.ebugPrintStackTrace(e, "Exception caught in handlePUTPIECE");
    } finally {
        ga.releaseMonitor();
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCCity(soc.game.SOCCity) SOCPlayingPiece(soc.game.SOCPlayingPiece) SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCRoad(soc.game.SOCRoad)

Example 2 with SOCSettlement

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

the class SOCGameMessageHandler method handleDEBUGFREEPLACE.

/**
 * Handle the client's debug Free Placement putpiece request.
 * @since 1.1.12
 */
private void handleDEBUGFREEPLACE(final SOCGame ga, final Connection c, final SOCDebugFreePlace mes) {
    if (!ga.isDebugFreePlacement())
        return;
    final String gaName = ga.getName();
    final int coord = mes.getCoordinates();
    final SOCPlayer player = ga.getPlayer(mes.getPlayerNumber());
    if (player == null)
        return;
    boolean didPut = false;
    final int pieceType = mes.getPieceType();
    final boolean initialDeny = ga.isInitialPlacement() && !player.canBuildInitialPieceType(pieceType);
    switch(pieceType) {
        case SOCPlayingPiece.ROAD:
            if (player.isPotentialRoad(coord) && !initialDeny) {
                ga.putPiece(new SOCRoad(player, coord, null));
                didPut = true;
            }
            break;
        case SOCPlayingPiece.SETTLEMENT:
            if (player.canPlaceSettlement(coord) && !initialDeny) {
                ga.putPiece(new SOCSettlement(player, coord, null));
                didPut = true;
            }
            break;
        case SOCPlayingPiece.CITY:
            if (player.isPotentialCity(coord) && !initialDeny) {
                ga.putPiece(new SOCCity(player, coord, null));
                didPut = true;
            }
            break;
        case SOCPlayingPiece.SHIP:
            if (ga.canPlaceShip(player, coord) && !initialDeny) {
                ga.putPiece(new SOCShip(player, coord, null));
                didPut = true;
            }
            break;
        default:
            srv.messageToPlayer(c, gaName, "* Unknown piece type: " + pieceType);
    }
    if (didPut) {
        srv.messageToGame(gaName, new SOCPutPiece(gaName, mes.getPlayerNumber(), pieceType, coord));
        // Check for initial settlement next to gold hex
        if (pieceType == SOCPlayingPiece.SETTLEMENT) {
            final int numGoldRes = player.getNeedToPickGoldHexResources();
            if (numGoldRes > 0)
                srv.messageToPlayer(c, new SOCSimpleRequest(gaName, player.getPlayerNumber(), SOCSimpleRequest.PROMPT_PICK_RESOURCES, numGoldRes));
        }
        if (ga.getGameState() >= SOCGame.OVER) {
            // exit debug mode, announce end of game
            handler.processDebugCommand_freePlace(c, gaName, "0");
            handler.sendGameState(ga, false, false);
        }
    } else {
        if (initialDeny) {
            final String pieceTypeFirst = ((player.getPieces().size() % 2) == 0) ? "settlement" : "road";
            srv.messageToPlayer(c, gaName, "Place a " + pieceTypeFirst + " before placing that.");
        } else {
            srv.messageToPlayer(c, gaName, "Not a valid location to place that.");
        }
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCCity(soc.game.SOCCity) SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCRoad(soc.game.SOCRoad)

Example 3 with SOCSettlement

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

the class SOCRobotBrain method buildRequestPlannedPiece.

/**
 * Have the client ask to build our top planned piece
 * (calls {@link #buildingPlan}{@link Stack#pop() .pop()}),
 * unless we've already been told by the server to not build it.
 * Sets {@link #whatWeWantToBuild}, {@link #waitingForDevCard},
 * or {@link #waitingForPickSpecialItem}.
 * Called from {@link #buildOrGetResourceByTradeOrCard()}.
 *<P>
 * Checks against {@link #whatWeFailedToBuild} to see if server has rejected this already.
 * Calls <tt>client.buyDevCard()</tt> or <tt>client.buildRequest()</tt>.
 * Sets {@link #waitingForDevCard} or {@link #waitingForPickSpecialItem},
 * or sets {@link #waitingForGameState} and a flag like {@link #expectPLACING_SETTLEMENT} (etc).
 *<P>
 * Preconditions: Call only when:
 *<UL>
 * <LI> Gamestate is {@link SOCGame#PLAY1} or {@link SOCGame#SPECIAL_BUILDING}
 * <LI> <tt>! ({@link #waitingForTradeMsg} || {@link #waitingForTradeResponse})</tt>
 * <LI> ourPlayerData.getResources().{@link SOCResourceSet#contains(soc.game.ResourceSet) contains}(targetPieceResources)
 *</UL>
 *
 * @see #placeIfExpectPlacing()
 * @since 1.1.08
 */
private void buildRequestPlannedPiece() {
    final SOCPossiblePiece targetPiece = buildingPlan.pop();
    D.ebugPrintln("$ POPPED " + targetPiece);
    lastMove = targetPiece;
    currentDRecorder = (currentDRecorder + 1) % 2;
    negotiator.setTargetPiece(ourPlayerNumber, targetPiece);
    switch(targetPiece.getType()) {
        case SOCPossiblePiece.CARD:
            client.buyDevCard(game);
            waitingForDevCard = true;
            break;
        case SOCPossiblePiece.ROAD:
            waitingForGameState = true;
            counter = 0;
            expectPLACING_ROAD = true;
            whatWeWantToBuild = new SOCRoad(ourPlayerData, targetPiece.getCoordinates(), null);
            if (!whatWeWantToBuild.equals(whatWeFailedToBuild)) {
                D.ebugPrintln("!!! BUILD REQUEST FOR A ROAD AT " + Integer.toHexString(targetPiece.getCoordinates()) + " !!!");
                client.buildRequest(game, SOCPlayingPiece.ROAD);
            } else {
                // We already tried to build this.
                cancelWrongPiecePlacementLocal(whatWeWantToBuild);
            // cancel sets whatWeWantToBuild = null;
            }
            break;
        case SOCPlayingPiece.SETTLEMENT:
            waitingForGameState = true;
            counter = 0;
            expectPLACING_SETTLEMENT = true;
            whatWeWantToBuild = new SOCSettlement(ourPlayerData, targetPiece.getCoordinates(), null);
            if (!whatWeWantToBuild.equals(whatWeFailedToBuild)) {
                D.ebugPrintln("!!! BUILD REQUEST FOR A SETTLEMENT " + Integer.toHexString(targetPiece.getCoordinates()) + " !!!");
                client.buildRequest(game, SOCPlayingPiece.SETTLEMENT);
            } else {
                // We already tried to build this.
                cancelWrongPiecePlacementLocal(whatWeWantToBuild);
            // cancel sets whatWeWantToBuild = null;
            }
            break;
        case SOCPlayingPiece.CITY:
            waitingForGameState = true;
            counter = 0;
            expectPLACING_CITY = true;
            whatWeWantToBuild = new SOCCity(ourPlayerData, targetPiece.getCoordinates(), null);
            if (!whatWeWantToBuild.equals(whatWeFailedToBuild)) {
                D.ebugPrintln("!!! BUILD REQUEST FOR A CITY " + Integer.toHexString(targetPiece.getCoordinates()) + " !!!");
                client.buildRequest(game, SOCPlayingPiece.CITY);
            } else {
                // We already tried to build this.
                cancelWrongPiecePlacementLocal(whatWeWantToBuild);
            // cancel sets whatWeWantToBuild = null;
            }
            break;
        case SOCPlayingPiece.SHIP:
            waitingForGameState = true;
            counter = 0;
            expectPLACING_SHIP = true;
            whatWeWantToBuild = new SOCShip(ourPlayerData, targetPiece.getCoordinates(), null);
            if (!whatWeWantToBuild.equals(whatWeFailedToBuild)) {
                System.err.println("L2733: " + ourPlayerData.getName() + ": !!! BUILD REQUEST FOR A SHIP AT " + Integer.toHexString(targetPiece.getCoordinates()) + " !!!");
                D.ebugPrintln("!!! BUILD REQUEST FOR A SHIP AT " + Integer.toHexString(targetPiece.getCoordinates()) + " !!!");
                client.buildRequest(game, SOCPlayingPiece.SHIP);
            } else {
                // We already tried to build this.
                cancelWrongPiecePlacementLocal(whatWeWantToBuild);
            // cancel sets whatWeWantToBuild = null;
            }
            break;
        case SOCPossiblePiece.PICK_SPECIAL:
            {
                final SOCPossiblePickSpecialItem psi = (SOCPossiblePickSpecialItem) targetPiece;
                waitingForPickSpecialItem = psi.typeKey;
                // targetPiece isn't a SOCPlayingPiece
                whatWeWantToBuild = null;
                counter = 0;
                client.pickSpecialItem(game, psi.typeKey, psi.gi, psi.pi);
            }
            break;
        default:
            // shouldn't occur: print for debugging
            System.err.println(ourPlayerData.getName() + ": buildRequestPlannedPiece: Unknown piece type " + targetPiece.getType());
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCCity(soc.game.SOCCity) SOCShip(soc.game.SOCShip) SOCRoad(soc.game.SOCRoad)

Example 4 with SOCSettlement

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

the class SOCRobotBrain method handlePUTPIECE_updateGameData.

/**
 * Handle a PUTPIECE for this game, by updating game data.
 * For initial roads, also track their initial settlement in SOCPlayerTracker.
 * In general, most tracking is done a bit later in {@link #handlePUTPIECE_updateTrackers(int, int, int)}.
 * @since 1.1.08
 */
private void handlePUTPIECE_updateGameData(SOCPutPiece mes) {
    switch(mes.getPieceType()) {
        // fall through to ROAD
        case SOCPlayingPiece.SHIP:
        case SOCPlayingPiece.ROAD:
            if (// START1B, START2B, START3B
            game.isInitialPlacement()) {
                // 
                // Before processing this road/ship, track the settlement that goes with it.
                // This was deferred until road placement, in case a human player decides
                // to cancel their settlement and place it elsewhere.
                // 
                SOCPlayerTracker tr = playerTrackers.get(Integer.valueOf(mes.getPlayerNumber()));
                SOCSettlement se = tr.getPendingInitSettlement();
                if (se != null)
                    trackNewSettlement(se, false);
            }
        default:
            SOCDisplaylessPlayerClient.handlePUTPIECE(mes, game);
            break;
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement)

Example 5 with SOCSettlement

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

the class SOCRobotBrain method handlePUTPIECE_updateTrackers.

/**
 * Handle a PUTPIECE for this game, by updating {@link SOCPlayerTracker}s.
 * Also handles the "move piece to here" part of MOVEPIECE.
 *<P>
 * For initial placement of our own pieces, this method also checks
 * and clears expectPUTPIECE_FROM_START1A, and sets expectSTART1B, etc.
 * The final initial putpiece clears expectPUTPIECE_FROM_START2B and sets expectROLL_OR_CARD.
 * As part of the PUTPIECE request, brain set those expectPUTPIECE flags in {@link #placeIfExpectPlacing()}.
 *<P>
 * For initial settlements, won't track here:
 * Delay tracking until the corresponding road is placed,
 * in {@link #handlePUTPIECE_updateGameData(SOCPutPiece)}.
 * This prevents the need for tracker "undo" work if a human
 * player changes their mind on where to place the settlement.
 *
 * @param pn  Piece's player number
 * @param coord  Piece coordinate
 * @param pieceType  Piece type, as in {@link SOCPlayingPiece#SETTLEMENT}
 * @since 1.1.08
 */
private void handlePUTPIECE_updateTrackers(final int pn, final int coord, final int pieceType) {
    switch(pieceType) {
        case SOCPlayingPiece.ROAD:
            SOCRoad newRoad = new SOCRoad(game.getPlayer(pn), coord, null);
            trackNewRoadOrShip(newRoad, false);
            break;
        case SOCPlayingPiece.SETTLEMENT:
            SOCPlayer newSettlementPl = game.getPlayer(pn);
            SOCSettlement newSettlement = new SOCSettlement(newSettlementPl, coord, null);
            if ((game.getGameState() == SOCGame.START1B) || (game.getGameState() == SOCGame.START2B) || (game.getGameState() == SOCGame.START3B)) {
                // Track it soon, after the road is placed
                // (in handlePUTPIECE_updateGameData)
                // but not yet, in case player cancels placement.
                SOCPlayerTracker tr = playerTrackers.get(Integer.valueOf(newSettlementPl.getPlayerNumber()));
                tr.setPendingInitSettlement(newSettlement);
            } else {
                // Track it now
                trackNewSettlement(newSettlement, false);
            }
            break;
        case SOCPlayingPiece.CITY:
            SOCCity newCity = new SOCCity(game.getPlayer(pn), coord, null);
            trackNewCity(newCity, false);
            break;
        case SOCPlayingPiece.SHIP:
            SOCShip newShip = new SOCShip(game.getPlayer(pn), coord, null);
            trackNewRoadOrShip(newShip, false);
            break;
        case SOCPlayingPiece.VILLAGE:
            // <--- Early return: Piece is part of board initial layout, not tracked player info ---
            return;
    }
    if (D.ebugOn) {
        SOCPlayerTracker.playerTrackersDebug(playerTrackers);
    }
    if (pn != ourPlayerNumber) {
        // <---- Not our piece ----
        return;
    }
    if (expectPUTPIECE_FROM_START1A && (pieceType == SOCPlayingPiece.SETTLEMENT) && (coord == ourPlayerData.getLastSettlementCoord())) {
        expectPUTPIECE_FROM_START1A = false;
        expectSTART1B = true;
    }
    if (expectPUTPIECE_FROM_START1B && ((pieceType == SOCPlayingPiece.ROAD) || (pieceType == SOCPlayingPiece.SHIP)) && (coord == ourPlayerData.getLastRoadCoord())) {
        expectPUTPIECE_FROM_START1B = false;
        expectSTART2A = true;
    }
    if (expectPUTPIECE_FROM_START2A && (pieceType == SOCPlayingPiece.SETTLEMENT) && (coord == ourPlayerData.getLastSettlementCoord())) {
        expectPUTPIECE_FROM_START2A = false;
        expectSTART2B = true;
    }
    if (expectPUTPIECE_FROM_START2B && ((pieceType == SOCPlayingPiece.ROAD) || (pieceType == SOCPlayingPiece.SHIP)) && (coord == ourPlayerData.getLastRoadCoord())) {
        expectPUTPIECE_FROM_START2B = false;
        if (!game.isGameOptionSet(SOCGameOption.K_SC_3IP))
            // wait for regular game play to start; other players might still place first
            expectROLL_OR_CARD = true;
        else
            expectSTART3A = true;
    }
    if (expectPUTPIECE_FROM_START3A && (pieceType == SOCPlayingPiece.SETTLEMENT) && (coord == ourPlayerData.getLastSettlementCoord())) {
        expectPUTPIECE_FROM_START3A = false;
        expectSTART3B = true;
    }
    if (expectPUTPIECE_FROM_START3B && ((pieceType == SOCPlayingPiece.ROAD) || (pieceType == SOCPlayingPiece.SHIP)) && (coord == ourPlayerData.getLastRoadCoord())) {
        expectPUTPIECE_FROM_START3B = false;
        expectROLL_OR_CARD = true;
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCCity(soc.game.SOCCity) SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCRoad(soc.game.SOCRoad)

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