Search in sources :

Example 11 with SOCFortress

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

the class SOCPlayerTracker method recalcScenario_SC_PIRI_nextPotentialShip.

/**
 * For scenario {@code _SC_PIRI}, get the player's next potential ship towards their Fortress.
 * If fortress was already defeated, or they have no boats, returns {@code null}.
 *<P>
 * This is calculated every time, not cached, because potential-ships list may change often.
 * Calls {@link #updateScenario_SC_PIRI_closestShipToFortress(SOCShip, boolean)} if closest ship not known.
 *
 * @return Next potential ship, or {@code null}
 * @since 2.0.00
 */
SOCPossibleShip recalcScenario_SC_PIRI_nextPotentialShip() {
    // may be null towards end of game
    final SOCFortress fort = player.getFortress();
    if (fort == null)
        // <--- Early return: already defeated fortress ---
        return null;
    final int fortR = fort.getCoordinates() >> 8;
    if (scen_SC_PIRI_closestShipToFortress == null)
        updateScenario_SC_PIRI_closestShipToFortress(null, false);
    final SOCShip closest = scen_SC_PIRI_closestShipToFortress;
    if (closest == null)
        // <--- Early return: no ships ---
        return null;
    final List<Integer> closestAdjacs = ((SOCBoardLarge) game.getBoard()).getAdjacentEdgesToEdge(closest.getCoordinates());
    SOCPossibleShip nextShip = null;
    int nextR = -1, nextC = -1;
    for (Integer edge : closestAdjacs) {
        final SOCPossibleRoad rs = possibleRoads.get(edge);
        if ((rs == null) || !(rs instanceof SOCPossibleShip))
            continue;
        final int shipEdge = rs.getCoordinates();
        final int shipR = shipEdge >> 8, shipC = shipEdge & 0xFF;
        if ((nextShip == null) || (shipC < nextC) || ((shipC == nextC) && (Math.abs(shipR - fortR) < Math.abs(nextR - fortR)))) {
            nextShip = (SOCPossibleShip) rs;
            nextR = shipR;
            nextC = shipC;
        }
    }
    return nextShip;
}
Also used : SOCBoardLarge(soc.game.SOCBoardLarge) SOCShip(soc.game.SOCShip) SOCFortress(soc.game.SOCFortress)

Aggregations

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