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;
}
Aggregations