net.sf.colossus.client
Class Client

java.lang.Object
  extended by net.sf.colossus.client.Client
All Implemented Interfaces:
IClient, IOracle, OptionObjectProvider, IVariant

public final class Client
extends java.lang.Object
implements IClient, IOracle, IVariant, OptionObjectProvider

Lives on the client side and handles all communication with the server. It talks to the Server via the network protocol and to Client side classes locally, but to all GUI related classes it should only communicate via ClientGUI class. There is one client per player. TODO Handle GUI related issues purely via ClientGUI TODO All GUI classes should talk to the server purely through ClientGUI which handles it via the Client. TODO the logic for the battles could probably be separated from the rest of this code. At the moment the battle logic seems to bounce back and forth between BattleBoard (which is really a GUI class) and this class. TODO this class also has the functionality of a GameClientSide class, which should be separated and ideally moved up into the Game class. The whole IOracle interface is part of that. One approach would be moving code from GameServerSide up into Game and then reuse it here in the matching methods, then inlining it into the calling code. Another one would be creating the GameClientSide for now and relocating code there. ==> Clemens march 2009: I started the GameClientSide approach :)

Author:
David Ripton, Romain Dolbeau

Nested Class Summary
private static class Client.ClosedByConstant
          Constants modelling the party who closed this client.
static class Client.ConnectionInitException
           
 
Field Summary
private  AI ai
           
private  BattleMovement battleMovement
           
private  java.util.List<CritterMove> bestMoveOrder
          For battle AI.
private  Client.ClosedByConstant closedBy
           
private  PlayerColor color
          Starting marker color of player who owns this client.
private  IServerConnection connection
          The object that actually handles the physical server communication for this client.
private  java.lang.String currentLegionMarkerId
           
private  int delay
           
private  boolean disposeInProgress
           
private  boolean failed
          Client constructor sets this to true if something goes wrong with the SocketClientThread initialization.
private  java.util.List<CritterMove> failedBattleMoves
           
private  GameClientSide game
          The game in progress.
private  boolean gotDisposeAlready
          Once we got dispose from server (or user initiated it himself), we'll ignore it if we we get it from server again - it's then up to the user to do some "disposing" action.
private  IClientGUI gui
          This can be an actual ClientGUI, or a NullClientGUI (which does simply nothing, so that we don't need to check for null everywhere).
private  Server localServer
           
private static java.util.logging.Logger LOGGER
           
private  MovementClientSide movement
           
private  int numSplitsThisTurn
           
private  Options options
           
private  PlayerClientSide owningPlayer
          Player who owns this client.
private  boolean paused
           
private  boolean playerAlive
           
private  boolean playersNotInitialized
          At first time we get "all player info", they are created; at all later calls just update them.
private  java.util.Hashtable<CreatureType,java.lang.Integer> recruitReservations
           
private  boolean redoOngoing
          Redo of the events since last commit phase is ongoing.
private  boolean replayOngoing
          Replay during load of a saved game is ongoing.
private  ResourceLoader resourceLoader
          A first start to get rid of the static-access-everywhere to ResourceLoader.
private  IServer server
          This "server" is the access to the connector object which actually acts for us as server.
private  boolean tookMulligan
           
 
Constructor Summary
Client(java.lang.String playerName, java.lang.String playerType, WhatNextManager whatNextMgr, Server theServer, boolean byWebClient, boolean noOptionsFile, boolean createGUI, ResourceLoader resLoader, IServerConnection conn, Variant variant)
          Client is the main hub for info exchange on client side.
 
Method Summary
 void acquireAngelCallback(Legion legion, CreatureType angelType)
           
 void addCreature(Legion legion, CreatureType creature, java.lang.String reason)
          Add a new creature to this legion.
 void aiDoneWithStrikes()
           
private  void aiPause()
          Wait for aiDelay.
 void answerConcede(Legion legion, boolean answer)
           
 void answerFlee(Legion ally, boolean answer)
           
 void applyCarries(BattleHex hex)
          Attempt to apply carries to the critter in hex.
 void askAcquireAngel(Legion legion, java.util.List<CreatureType> recruits)
          recruits is the list of acquirables that can be chosen from for a certain point value reached.
 void askChooseStrikePenalty(java.util.List<java.lang.String> choices)
          Allow the player to choose whether to take a penalty (fewer dice or higher strike number) in order to be allowed to carry.
 void askConcede(Legion ally, Legion enemy)
           
 void askFlee(Legion ally, Legion enemy)
           
 void askNegotiate(Legion attacker, Legion defender)
           
 void askPickColor(java.util.List<PlayerColor> colorsLeft)
           
 void askPickFirstMarker()
           
 void assignStrikePenalty(java.lang.String prompt)
           
 boolean canRecruit(Legion legion)
           
 CreatureType chooseBestPotentialRecruit(LegionClientSide legion, MasterHex hex, java.util.List<CreatureType> recruits)
           
private  boolean chooseWhetherToTeleport(MasterHex hex)
          Present a dialog allowing the player to enter via land or teleport.
 void cleanupBattle()
           
 void concede()
           
private  void concede(Legion legion)
           
 void confirmWhenCaughtUp()
           
private  AI createAI(java.lang.String playerType)
          Create the AI for this Client.
static Client createClient(java.lang.String host, int port, java.lang.String playerName, java.lang.String playerType, WhatNextManager whatNextMgr, Server theServer, boolean byWebClient, boolean noOptionsFile, boolean createGUI)
          Create a Client object and other related objects
 void createSummonAngel(Legion legion)
           
private  boolean decideWhetherClose()
           
 void didMove(Legion legion, MasterHex startingHex, MasterHex currentHex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord, boolean splitLegionHasForcedMove)
           
 void didRecruit(Legion legion, CreatureType recruit, CreatureType recruiter, int numRecruiters)
           
 void didSplit(MasterHex hex, Legion parent, Legion child, int childHeight, java.util.List<CreatureType> splitoffs, int turn)
          Callback from server after any successful split.
 void didSummon(Legion summoner, Legion donor, CreatureType summon)
           
 void dispose()
           
private  void disposeAll()
           
 void disposeClientOriginated()
           
private  void disposeWholeClient()
           
 void doAdditionalCleanup()
           
private  void doAutoMoves()
           
private  void doAutoStrikes()
          Handle both forced strikes and AI strikes.
 void doBattleMove(int tag, BattleHex hex)
           
 void doCheckServerConnection()
           
 void doFight(MasterHex hex)
           
 boolean doMove(Legion mover, MasterHex hex)
          If the move looks legal, forward it to server and return true; otherwise returns false.
 void doneWithBattleMoves()
           
 void doneWithEngagements()
           
 void doneWithMoves()
           
 void doneWithRecruits()
           
 void doneWithSplits()
           
 void doneWithStrikes()
           
private  void doNotConcede(Legion legion)
           
 void doRecruit(Legion legion)
          Used for human players only.
 void doRecruit(Legion legion, java.lang.String recruitName, java.lang.String recruiterName)
           
 void doReinforce(Legion legion)
          Always needs to call server.doRecruit(), even if no recruit is wanted, to get past the reinforcing phase.
 void doSplit(Legion parent)
          Called by MasterBoard.actOnLegion() when human user clicked on a legion to split it.
 void doSplit(Legion parent, java.lang.String childMarkerId, java.util.List<CreatureType> results)
          Called by AI and by doSplit()
private  void doSummon(SummonInfo summonInfo)
          Legion target summons unit from Legion donor.
 void engage(MasterHex hex)
          Resolve engagement in land.
private  void fight(MasterHex hex)
          Cease negotiations and fight a battle in land.
private  CreatureType figureTeleportingLord(Legion legion, MasterHex hex)
           
 java.util.Set<BattleHex> findCrittersWithTargets()
           
 java.util.List<java.lang.String> findEligibleRecruiters(Legion legion, CreatureType recruit)
          Return a list of creature name strings.
 java.util.List<CreatureType> findEligibleRecruits(Legion legion, MasterHex hex)
          Return a list of Creatures (ignore reservations).
 java.util.List<CreatureType> findEligibleRecruits(Legion legion, MasterHex hex, boolean considerReservations)
          Return a list of Creatures and consider reservations if wanted.
 java.util.Set<BattleUnit> findMobileBattleUnits()
          Return a set of BattleUnits.
 java.util.Set<BattleHex> findMobileCritterHexes()
          Return a set of hexLabels.
private  java.lang.String findRecruiterName(Legion legion, CreatureType recruit, java.lang.String hexDescription)
          null means cancel.
 java.util.Set<BattleHex> findStrikes(int tag)
           
 java.util.Set<MasterHex> findTallLegionHexes()
          Return a set of hexLabels for the active player's legions with 7 or more creatures, and which are not marked as skip this turn.
 java.util.Set<MasterHex> findTallLegionHexes(int minHeight, boolean ignoreSkipFlag)
          Return a set of hexLabels for the active player's legions with minHeight or more creatures.
 java.util.Set<MasterHex> findUnmovedLegionHexes(boolean considerSkippedAsMoved, java.util.HashSet<Legion> pendingLegions)
           
 java.util.List<BattleUnit> getActiveBattleUnits()
           
 Player getActivePlayer()
           
 Legion getAttacker()
           
 Player getBattleActivePlayer()
           
 BattleClientSide getBattleCS()
           
 BattlePhase getBattlePhase()
           
 MasterHex getBattleSite()
           
 int getBattleTurnNumber()
           
 PlayerColor getColor()
           
 java.lang.String getCurrentLegionMarkerId()
           
 Legion getDefender()
           
 Engagement getEngagement()
           
 boolean getFailed()
           
 Game getGame()
           
 GameClientSide getGameClientSide()
           
 IClientGUI getGUI()
           
 java.util.List<BattleUnit> getInactiveBattleUnits()
           
 LegionClientSide getLegion(java.lang.String markerId)
          Get this legion's info or create if necessary.
 java.util.List<java.lang.Boolean> getLegionCreatureCertainties(Legion legion)
           
 int getLegionHeight(java.lang.String markerId)
           
 java.util.List<java.lang.String> getLegionImageNames(Legion legion)
           
 MovementClientSide getMovement()
           
 Legion getMyEngagedLegion()
           
 int getNumPlayers()
           
 Options getOptions()
           
 PlayerClientSide getOwningPlayer()
           
 Phase getPhase()
           
 Player getPlayerByName(java.lang.String name)
           
private  java.util.Set<MasterHex> getPossibleRecruitActionHexes()
          Return a set of hexLabels with legions that could do a recruit or undo recruit.
 java.util.Set<MasterHex> getPossibleRecruitHexes()
          Return a set of hexes with legions that can (still) muster anything and are not marked as skip.
 java.util.List<CreatureType> getPossibleRecruits(MasterBoardTerrain terrain, MasterHex hex)
          TODO get from Variant instead of static TerrainRecruitLoader access Just forwarding the query, to get at least the GUI classes get rid of dependency to static TerrainRecruitLoader access.
 int getReservedRemain(CreatureType recruitType)
           
 java.lang.String getShortColor()
           
 java.util.Collection<MasterBoardTerrain> getTerrains()
          Return a collection of all possible terrains.
 int getTurnNumber()
           
private  void handleFailedBattleMove()
           
 void initBattle(MasterHex hex, int battleTurnNumber, Player battleActivePlayer, BattlePhase battlePhase, Legion attacker, Legion defender)
           
 void initBoard()
           
 boolean isAlive()
           
 boolean isInContact(BattleCritter critter, boolean countDead)
           
 boolean isMyBattlePhase()
           
 boolean isMyLegion(Legion legion)
           
 boolean isMyTurn()
           
 boolean isPaused()
           
 boolean isRedoOngoing()
           
 boolean isRemote()
           
 boolean isReplayOngoing()
           
 boolean isSctAlreadyDown()
           
private  void kickBattleMove()
           
private  void kickFight()
           
private  void kickMoves()
           
private  void kickMuster()
           
 void kickPhase()
           
private  void kickSplit()
           
 void leaveCarryMode()
          Called from BattleBoard to leave carry mode.
 void legionsNotMoved(int[] legionStatus, boolean have_roll)
          Returns status of client's legions
 java.util.Set<MasterHex> listNormalMoves(Legion legion)
          Return a set of hexLabels.
private  java.util.List<CreatureType> listTeleportingLords(Legion legion, MasterHex hex)
          List the lords eligible to teleport this legion to hexLabel.
 java.util.Set<MasterHex> listTeleportMoves(Legion legion)
          Return a set of hexLabels.
 void locallyInitiateSaveGame(java.lang.String filename)
           
 void log(java.lang.String message)
           
private  boolean makeForcedStrikes()
          Return true if any strikes were taken.
private  void makeProposal(Proposal proposal)
           
private  void markBattleMoveSuccessful(int tag, BattleHex endingHex)
           
 void mulligan()
          Take a mulligan.
 void nak(java.lang.String reason, java.lang.String errmsg)
           
 void negotiateCallback(Proposal proposal, boolean respawn)
          Called from both Negotiate and ReplyToProposal.
 void nextEngagement()
           
 boolean noRecruitActionPossible()
          Check whether any legion has possibility to recruit at all, no matter whether it could or has already.
 void notifyServer()
           
 int numberOfRecruiterNeeded(CreatureType recruiter, CreatureType recruit, MasterBoardTerrain terrain, MasterHex hex)
          TODO get from Variant instead of static TerrainRecruitLoader access Just forwarding the query, to get at least the GUI classes get rid of dependency to static TerrainRecruitLoader access.
private  void pickCarries(int carryDamage, java.util.Set<java.lang.String> carryTargetDescriptions)
           
 void pingRequest()
           
 void placeNewChit(java.lang.String bareImageName, boolean inverted, int tag, BattleHex hex)
          Create a new BattleUnit and (if GUI) a new GUIBattleChit with the given parameters.
private  void recoverFromNak(java.lang.String reason, java.lang.String errmsg)
           
 void removeCreature(Legion legion, CreatureType creature, java.lang.String reason)
           
 void removeDeadBattleChits()
           
 void removeLegion(Legion legion)
          Remove this eliminated legion, and clean up related stuff.
 boolean reserveRecruit(CreatureType recruitType)
           
private  void resetLegionMovesAndRecruitData()
           
 void resetRecruitReservations()
           
private  void retryFailedBattleMoves()
           
 void revealCreatures(Legion legion, java.util.List<CreatureType> creatures, java.lang.String reason)
          Reveal creatures in this legion, some of which already may be known.
 void revealEngagedCreatures(Legion legion, java.util.List<CreatureType> names, boolean isAttacker, java.lang.String reason)
           
private  boolean sansLordAutoBattleApplies()
           
 void serverConfirmsConnection()
          Upon request with checkServerConnection, server sends a confirmation.
 void setBoardActive(boolean val)
           
(package private)  void setClosedByServer()
           
 void setColor(PlayerColor color)
           
 void setCurrentLegionMarkerId(java.lang.String MarkerId)
           
 void setLegionStatus(Legion legion, boolean moved, boolean teleported, EntrySide entrySide, CreatureType lastRecruit)
          Needed when loading a game outside split phase.
 void setPauseState(boolean newState)
           
 void setPlayerName(java.lang.String playerName)
           
 void setPreferencesCheckBoxValue(java.lang.String name, boolean value)
           
 void setPreferencesRadioButtonValue(java.lang.String name, boolean value)
           
 void setupBattleFight(BattlePhase battlePhase, Player battleActivePlayer)
          Used for both strike and strikeback.
 void setupBattleMove(Player battleActivePlayer, int battleTurnNumber)
           
 void setupBattleRecruit(Player battleActivePlayer, int battleTurnNumber)
           
 void setupBattleSummon(Player battleActivePlayer, int battleTurnNumber)
           
private  void setupDelay()
           
 void setupFight()
           
 void setupMove()
           
 void setupMuster()
           
 void setupSplit(Player activePlayer, int turnNumber)
           
 void setupTurnState(Player activePlayer, int turnNumber)
          Called by server when activePlayer changes
 java.util.Set<BattleHex> showBattleMoves(BattleCritter battleCritter)
           
 void showMessageDialog(java.lang.String message)
           
 void strike(int tag, BattleHex hex)
          Attempt to have critter tag strike the critter in hex.
private  boolean strikeMakeForcedStrikes(boolean autoRangeSingle)
           
 void syncOption(java.lang.String optname, java.lang.String value)
          Server sends Client some option setting (e.g.
 void tellBattleMove(int tag, BattleHex startingHex, BattleHex endingHex, boolean undo)
           
 void tellEngagement(MasterHex hex, Legion attacker, Legion defender)
           
 void tellEngagementResults(Legion winner, java.lang.String method, int points, int turns)
           
 void tellGameOver(java.lang.String message, boolean disposeFollows)
           
 void tellLegionLocation(Legion legion, MasterHex hex)
          Create marker if necessary, and place it in hexLabel.
 void tellMovementRoll(int roll)
           
 void tellPlayerElim(Player deadPlayer, Player slayer)
           
 void tellProposal(java.lang.String proposalString)
          Inform this player about the other player's proposal.
 void tellRedo(boolean val)
           
 void tellReplay(boolean val, int maxTurn)
           
 void tellSlowResults(int targetTag, int slowValue)
           
 void tellStrikeResults(int strikerTag, int targetTag, int strikeNumber, java.util.List<java.lang.String> rolls, int damage, boolean killed, boolean wasCarry, int carryDamageLeft, java.util.Set<java.lang.String> carryTargetDescriptions)
           
 void tellWhatsHappening(java.lang.String message)
           
 boolean testBattleMove(BattleCritter battleUnit, BattleHex hex)
           
 boolean tookMulligan()
           
 void tryBattleMove(CritterMove cm)
           
 void undidMove(Legion legion, MasterHex formerHex, MasterHex currentHex, boolean splitLegionHasForcedMove)
           
 void undidRecruit(Legion legion, CreatureType recruit)
           
 void undidSplit(Legion splitoff, Legion survivor, int turn)
           
 void undoBattleMove(BattleHex hex)
           
 void undoMove(Legion legion)
           
 void undoRecruit(Legion legion)
           
 void undoSplit(Legion splitoff)
           
 void updateCreatureCount(CreatureType type, int count, int deadCount)
           
 void updatePlayerInfo(java.util.List<java.lang.String> infoStrings)
           
 void withdrawFromGame()
          This player quits the whole game.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

server

private IServer server
This "server" is the access to the connector object which actually acts for us as server. Right now this is always a SocketClientThread as deputy (relay) which forwards everything that we do/tell, to the Server. Perhaps one day this could either be a SocketConnection or e.g. a Queue type of connection for local Clients...


connection

private IServerConnection connection
The object that actually handles the physical server communication for this client. Issues related to set up and tear down of the connection are handled via this access to the (right now) SocketClientThread.


resourceLoader

private final ResourceLoader resourceLoader
A first start to get rid of the static-access-everywhere to ResourceLoader. ResourceLoader is used to "load" images, variant files, readme files physically (from disk, or from remote file server thread).


failed

private final boolean failed
Client constructor sets this to true if something goes wrong with the SocketClientThread initialization. I wanted to avoid have the Client constructor throw an exception, because that caused problems in Java 1.4 with a "created but not run thread" which was then never cleaned up and thus JVM did not exit by itself. TODO perhaps that is now fixed in Java 1.5 ? I plan to change the whole "when/how SCT is created" soon anyway...

See Also:
Constant Field Values

replayOngoing

private boolean replayOngoing
Replay during load of a saved game is ongoing. Client must NOT react (not even redraw) on any of those messages, they are mostly sent to rebuild the predict split data.


redoOngoing

private boolean redoOngoing
Redo of the events since last commit phase is ongoing. Needed right now only for "if redo ends, set flag to prevent the setupXxxxxPhase methods to clear the undo stack.


gui

private final IClientGUI gui
This can be an actual ClientGUI, or a NullClientGUI (which does simply nothing, so that we don't need to check for null everywhere).


options

private final Options options

playersNotInitialized

private boolean playersNotInitialized
At first time we get "all player info", they are created; at all later calls just update them. So this flag here tells us whether it's the first time (=true) or not any more (=false).


owningPlayer

private PlayerClientSide owningPlayer
Player who owns this client. TODO should be final but can't be until the constructor gets all the data needed


playerAlive

private boolean playerAlive

game

private final GameClientSide game
The game in progress.


color

private PlayerColor color
Starting marker color of player who owns this client. TODO most likely redundant with owningPlayer.getColor()


ai

private final AI ai

movement

private MovementClientSide movement

battleMovement

private BattleMovement battleMovement

localServer

private final Server localServer

closedBy

private Client.ClosedByConstant closedBy

tookMulligan

private boolean tookMulligan

numSplitsThisTurn

private int numSplitsThisTurn

delay

private int delay

bestMoveOrder

private java.util.List<CritterMove> bestMoveOrder
For battle AI.


failedBattleMoves

private java.util.List<CritterMove> failedBattleMoves

recruitReservations

private final java.util.Hashtable<CreatureType,java.lang.Integer> recruitReservations

gotDisposeAlready

private boolean gotDisposeAlready
Once we got dispose from server (or user initiated it himself), we'll ignore it if we we get it from server again - it's then up to the user to do some "disposing" action.


disposeInProgress

private boolean disposeInProgress

paused

private boolean paused

currentLegionMarkerId

private java.lang.String currentLegionMarkerId
Constructor Detail

Client

public Client(java.lang.String playerName,
              java.lang.String playerType,
              WhatNextManager whatNextMgr,
              Server theServer,
              boolean byWebClient,
              boolean noOptionsFile,
              boolean createGUI,
              ResourceLoader resLoader,
              IServerConnection conn,
              Variant variant)
Client is the main hub for info exchange on client side.

Parameters:
playerName - Name of the player (might still be one of the templates
playerType - Type of player, e.g. Human, Network, or some concrete AI type (but not "AnyAI"). Given type must include the package name.
whatNextMgr - The main controller over which to handle what to do next when this game is over and exiting
theServer - The Server object, if this is a local client
byWebClient - If true, this was instantiated by a WebClient
noOptionsFile - E.g. AIs should not read/save any options file
createGUI - Whether to create a GUI (AI's usually not, but server might override that e.g. in stresstest)
resLoader - The ResourceLoader object that gives us access to load images, files etc (from disk or from server)
conn - The connection to server (so far, SocketClientThread)
variant - The variant instance
Method Detail

createClient

public static Client createClient(java.lang.String host,
                                  int port,
                                  java.lang.String playerName,
                                  java.lang.String playerType,
                                  WhatNextManager whatNextMgr,
                                  Server theServer,
                                  boolean byWebClient,
                                  boolean noOptionsFile,
                                  boolean createGUI)
                           throws Client.ConnectionInitException
Create a Client object and other related objects

Parameters:
host - The host to which SocketClientThread shall connect
port - The port to which SocketClientThread shall connect
playerName - Name of the player (might still be one of the templates
playerType - Type of player, e.g. Human, Network, or some concrete AI type (but not "AnyAI"). Given type must include the package name.
whatNextMgr - The main controller over which to handle what to do next when this game is over and exiting
theServer - The Server object, if this is a local client
byWebClient - If true, this was instantiated by a WebClient
noOptionsFile - E.g. AIs should not read/save any options file
createGUI - Whether to create a GUI (AI's usually not, but server might override that e.g. in stresstest)
Throws:
Client.ConnectionInitException

isRemote

public boolean isRemote()

isAlive

public boolean isAlive()

isPaused

public boolean isPaused()

setCurrentLegionMarkerId

public void setCurrentLegionMarkerId(java.lang.String MarkerId)

getCurrentLegionMarkerId

public java.lang.String getCurrentLegionMarkerId()

setPauseState

public void setPauseState(boolean newState)

doCheckServerConnection

public void doCheckServerConnection()

serverConfirmsConnection

public void serverConfirmsConnection()
Upon request with checkServerConnection, server sends a confirmation. This method here processes the confirmation.

Specified by:
serverConfirmsConnection in interface IClient

locallyInitiateSaveGame

public void locallyInitiateSaveGame(java.lang.String filename)

getFailed

public boolean getFailed()

undoSplit

public void undoSplit(Legion splitoff)

mulligan

public void mulligan()
Take a mulligan.


tookMulligan

public boolean tookMulligan()

engage

public void engage(MasterHex hex)
Resolve engagement in land.


getMyEngagedLegion

public Legion getMyEngagedLegion()

concede

public void concede()

concede

private void concede(Legion legion)

doNotConcede

private void doNotConcede(Legion legion)

fight

private void fight(MasterHex hex)
Cease negotiations and fight a battle in land.


tellEngagement

public void tellEngagement(MasterHex hex,
                           Legion attacker,
                           Legion defender)
Specified by:
tellEngagement in interface IClient

tellEngagementResults

public void tellEngagementResults(Legion winner,
                                  java.lang.String method,
                                  int points,
                                  int turns)
Specified by:
tellEngagementResults in interface IClient

doSummon

private void doSummon(SummonInfo summonInfo)
Legion target summons unit from Legion donor.

Parameters:
summonInfo - A SummonInfo object that contains the values for target, donor and unit.

didSummon

public void didSummon(Legion summoner,
                      Legion donor,
                      CreatureType summon)
Specified by:
didSummon in interface IClient

withdrawFromGame

public void withdrawFromGame()
This player quits the whole game. The server needs to always honor this request, because if it doesn't players will just drop connections when they want to quit in a hurry.


tellMovementRoll

public void tellMovementRoll(int roll)
Specified by:
tellMovementRoll in interface IClient

tellWhatsHappening

public void tellWhatsHappening(java.lang.String message)
Specified by:
tellWhatsHappening in interface IClient

kickPhase

public void kickPhase()
Specified by:
kickPhase in interface IClient

kickMoves

private void kickMoves()

doAutoMoves

private void doAutoMoves()

syncOption

public void syncOption(java.lang.String optname,
                       java.lang.String value)
Server sends Client some option setting (e.g. AI type, autoPlay for stresstest (also AIs (????), ...)

Specified by:
syncOption in interface IClient

getNumPlayers

public int getNumPlayers()
Specified by:
getNumPlayers in interface IOracle

updatePlayerInfo

public void updatePlayerInfo(java.util.List<java.lang.String> infoStrings)
Specified by:
updatePlayerInfo in interface IClient

getOwningPlayer

public PlayerClientSide getOwningPlayer()

setColor

public void setColor(PlayerColor color)
Specified by:
setColor in interface IClient

updateCreatureCount

public void updateCreatureCount(CreatureType type,
                                int count,
                                int deadCount)
Specified by:
updateCreatureCount in interface IClient

setClosedByServer

void setClosedByServer()

disposeClientOriginated

public void disposeClientOriginated()

dispose

public void dispose()
Specified by:
dispose in interface IClient

disposeWholeClient

private void disposeWholeClient()

decideWhetherClose

private boolean decideWhetherClose()

disposeAll

private void disposeAll()

doAdditionalCleanup

public void doAdditionalCleanup()

leaveCarryMode

public void leaveCarryMode()
Called from BattleBoard to leave carry mode.


doneWithBattleMoves

public void doneWithBattleMoves()

getActiveBattleUnits

public java.util.List<BattleUnit> getActiveBattleUnits()

sansLordAutoBattleApplies

private boolean sansLordAutoBattleApplies()

getInactiveBattleUnits

public java.util.List<BattleUnit> getInactiveBattleUnits()

aiDoneWithStrikes

public void aiDoneWithStrikes()

doneWithStrikes

public void doneWithStrikes()

makeForcedStrikes

private boolean makeForcedStrikes()
Return true if any strikes were taken.


strikeMakeForcedStrikes

private boolean strikeMakeForcedStrikes(boolean autoRangeSingle)

doAutoStrikes

private void doAutoStrikes()
Handle both forced strikes and AI strikes.


getLegion

public LegionClientSide getLegion(java.lang.String markerId)
Get this legion's info or create if necessary. TODO move legion creation into a factory on Player


removeLegion

public void removeLegion(Legion legion)
Remove this eliminated legion, and clean up related stuff.

Specified by:
removeLegion in interface IClient

getLegionHeight

public int getLegionHeight(java.lang.String markerId)

setLegionStatus

public void setLegionStatus(Legion legion,
                            boolean moved,
                            boolean teleported,
                            EntrySide entrySide,
                            CreatureType lastRecruit)
Needed when loading a game outside split phase.

Specified by:
setLegionStatus in interface IClient

getLegionImageNames

public java.util.List<java.lang.String> getLegionImageNames(Legion legion)
Specified by:
getLegionImageNames in interface IOracle

getLegionCreatureCertainties

public java.util.List<java.lang.Boolean> getLegionCreatureCertainties(Legion legion)
Specified by:
getLegionCreatureCertainties in interface IOracle

addCreature

public void addCreature(Legion legion,
                        CreatureType creature,
                        java.lang.String reason)
Add a new creature to this legion.

Specified by:
addCreature in interface IClient

removeCreature

public void removeCreature(Legion legion,
                           CreatureType creature,
                           java.lang.String reason)
Specified by:
removeCreature in interface IClient

revealCreatures

public void revealCreatures(Legion legion,
                            java.util.List<CreatureType> creatures,
                            java.lang.String reason)
Reveal creatures in this legion, some of which already may be known. - this "reveal" is related to data coming from server being revealed to the split prediction

Specified by:
revealCreatures in interface IClient

revealEngagedCreatures

public void revealEngagedCreatures(Legion legion,
                                   java.util.List<CreatureType> names,
                                   boolean isAttacker,
                                   java.lang.String reason)
Specified by:
revealEngagedCreatures in interface IClient

removeDeadBattleChits

public void removeDeadBattleChits()
Specified by:
removeDeadBattleChits in interface IClient

placeNewChit

public void placeNewChit(java.lang.String bareImageName,
                         boolean inverted,
                         int tag,
                         BattleHex hex)
Create a new BattleUnit and (if GUI) a new GUIBattleChit with the given parameters. Place them in given hex, and add them to the lists of BattleUnits (in Battle[ClientSide]) and GUIBattleChits (in GUI)

Specified by:
placeNewChit in interface IClient

chooseBestPotentialRecruit

public CreatureType chooseBestPotentialRecruit(LegionClientSide legion,
                                               MasterHex hex,
                                               java.util.List<CreatureType> recruits)

getGUI

public IClientGUI getGUI()

tellReplay

public void tellReplay(boolean val,
                       int maxTurn)
Specified by:
tellReplay in interface IClient

isReplayOngoing

public boolean isReplayOngoing()

tellRedo

public void tellRedo(boolean val)
Specified by:
tellRedo in interface IClient

isRedoOngoing

public boolean isRedoOngoing()

confirmWhenCaughtUp

public void confirmWhenCaughtUp()
Specified by:
confirmWhenCaughtUp in interface IClient

initBoard

public void initBoard()
Specified by:
initBoard in interface IClient

setPlayerName

public void setPlayerName(java.lang.String playerName)
Specified by:
setPlayerName in interface IClient

createSummonAngel

public void createSummonAngel(Legion legion)
Specified by:
createSummonAngel in interface IClient

askAcquireAngel

public void askAcquireAngel(Legion legion,
                            java.util.List<CreatureType> recruits)
recruits is the list of acquirables that can be chosen from for a certain point value reached. E.g. for getting 180 points, going from 380 + 180 = 560, game would first call this for 400: recruits = [Angel] and then call it once more for 500: recruits = [Angel, Archangel]

Specified by:
askAcquireAngel in interface IClient

acquireAngelCallback

public void acquireAngelCallback(Legion legion,
                                 CreatureType angelType)

chooseWhetherToTeleport

private boolean chooseWhetherToTeleport(MasterHex hex)
Present a dialog allowing the player to enter via land or teleport. Return true if the player chooses to teleport.


askChooseStrikePenalty

public void askChooseStrikePenalty(java.util.List<java.lang.String> choices)
Allow the player to choose whether to take a penalty (fewer dice or higher strike number) in order to be allowed to carry.

Specified by:
askChooseStrikePenalty in interface IClient

assignStrikePenalty

public void assignStrikePenalty(java.lang.String prompt)

tellPlayerElim

public void tellPlayerElim(Player deadPlayer,
                           Player slayer)
Specified by:
tellPlayerElim in interface IClient

tellGameOver

public void tellGameOver(java.lang.String message,
                         boolean disposeFollows)
Specified by:
tellGameOver in interface IClient

doFight

public void doFight(MasterHex hex)

askConcede

public void askConcede(Legion ally,
                       Legion enemy)
Specified by:
askConcede in interface IClient

askFlee

public void askFlee(Legion ally,
                    Legion enemy)
Specified by:
askFlee in interface IClient

answerFlee

public void answerFlee(Legion ally,
                       boolean answer)

answerConcede

public void answerConcede(Legion legion,
                          boolean answer)

askNegotiate

public void askNegotiate(Legion attacker,
                         Legion defender)
Specified by:
askNegotiate in interface IClient

tellProposal

public void tellProposal(java.lang.String proposalString)
Inform this player about the other player's proposal.

Specified by:
tellProposal in interface IClient

negotiateCallback

public void negotiateCallback(Proposal proposal,
                              boolean respawn)
Called from both Negotiate and ReplyToProposal.


makeProposal

private void makeProposal(Proposal proposal)

tellSlowResults

public void tellSlowResults(int targetTag,
                            int slowValue)
Specified by:
tellSlowResults in interface IClient

tellStrikeResults

public void tellStrikeResults(int strikerTag,
                              int targetTag,
                              int strikeNumber,
                              java.util.List<java.lang.String> rolls,
                              int damage,
                              boolean killed,
                              boolean wasCarry,
                              int carryDamageLeft,
                              java.util.Set<java.lang.String> carryTargetDescriptions)
Specified by:
tellStrikeResults in interface IClient

nak

public void nak(java.lang.String reason,
                java.lang.String errmsg)
Specified by:
nak in interface IClient

recoverFromNak

private void recoverFromNak(java.lang.String reason,
                            java.lang.String errmsg)

pickCarries

private void pickCarries(int carryDamage,
                         java.util.Set<java.lang.String> carryTargetDescriptions)

initBattle

public void initBattle(MasterHex hex,
                       int battleTurnNumber,
                       Player battleActivePlayer,
                       BattlePhase battlePhase,
                       Legion attacker,
                       Legion defender)
Specified by:
initBattle in interface IClient

showMessageDialog

public void showMessageDialog(java.lang.String message)

cleanupBattle

public void cleanupBattle()
Specified by:
cleanupBattle in interface IClient

canRecruit

public boolean canRecruit(Legion legion)

doRecruit

public void doRecruit(Legion legion)
Used for human players only.


doRecruit

public void doRecruit(Legion legion,
                      java.lang.String recruitName,
                      java.lang.String recruiterName)

doReinforce

public void doReinforce(Legion legion)
Always needs to call server.doRecruit(), even if no recruit is wanted, to get past the reinforcing phase.

Specified by:
doReinforce in interface IClient

didRecruit

public void didRecruit(Legion legion,
                       CreatureType recruit,
                       CreatureType recruiter,
                       int numRecruiters)
Specified by:
didRecruit in interface IClient

undoRecruit

public void undoRecruit(Legion legion)

undidRecruit

public void undidRecruit(Legion legion,
                         CreatureType recruit)
Specified by:
undidRecruit in interface IClient

findRecruiterName

private java.lang.String findRecruiterName(Legion legion,
                                           CreatureType recruit,
                                           java.lang.String hexDescription)
null means cancel. "none" means no recruiter (tower creature).


resetLegionMovesAndRecruitData

private void resetLegionMovesAndRecruitData()

setBoardActive

public void setBoardActive(boolean val)
Specified by:
setBoardActive in interface IClient

setupTurnState

public void setupTurnState(Player activePlayer,
                           int turnNumber)
Called by server when activePlayer changes

Specified by:
setupTurnState in interface IClient

setupSplit

public void setupSplit(Player activePlayer,
                       int turnNumber)
Specified by:
setupSplit in interface IClient

kickSplit

private void kickSplit()

setupMove

public void setupMove()
Specified by:
setupMove in interface IClient

setupFight

public void setupFight()
Specified by:
setupFight in interface IClient

kickFight

private void kickFight()

nextEngagement

public void nextEngagement()
Specified by:
nextEngagement in interface IClient

setupMuster

public void setupMuster()
Specified by:
setupMuster in interface IClient

kickMuster

private void kickMuster()

setupBattleSummon

public void setupBattleSummon(Player battleActivePlayer,
                              int battleTurnNumber)
Specified by:
setupBattleSummon in interface IClient

setupBattleRecruit

public void setupBattleRecruit(Player battleActivePlayer,
                               int battleTurnNumber)
Specified by:
setupBattleRecruit in interface IClient

setupBattleMove

public void setupBattleMove(Player battleActivePlayer,
                            int battleTurnNumber)
Specified by:
setupBattleMove in interface IClient

kickBattleMove

private void kickBattleMove()

tryBattleMove

public void tryBattleMove(CritterMove cm)

retryFailedBattleMoves

private void retryFailedBattleMoves()

getBattleCS

public BattleClientSide getBattleCS()
Specified by:
getBattleCS in interface IOracle

setupBattleFight

public void setupBattleFight(BattlePhase battlePhase,
                             Player battleActivePlayer)
Used for both strike and strikeback.

Specified by:
setupBattleFight in interface IClient

tellLegionLocation

public void tellLegionLocation(Legion legion,
                               MasterHex hex)
Create marker if necessary, and place it in hexLabel.

Specified by:
tellLegionLocation in interface IClient

getColor

public PlayerColor getColor()

getShortColor

public java.lang.String getShortColor()

getBattleActivePlayer

public Player getBattleActivePlayer()
Specified by:
getBattleActivePlayer in interface IOracle

getEngagement

public Engagement getEngagement()
Specified by:
getEngagement in interface IOracle

getDefender

public Legion getDefender()

getAttacker

public Legion getAttacker()

getBattleSite

public MasterHex getBattleSite()

getBattlePhase

public BattlePhase getBattlePhase()
Specified by:
getBattlePhase in interface IOracle

getBattleTurnNumber

public int getBattleTurnNumber()

doBattleMove

public void doBattleMove(int tag,
                         BattleHex hex)

undoBattleMove

public void undoBattleMove(BattleHex hex)

markBattleMoveSuccessful

private void markBattleMoveSuccessful(int tag,
                                      BattleHex endingHex)

handleFailedBattleMove

private void handleFailedBattleMove()

tellBattleMove

public void tellBattleMove(int tag,
                           BattleHex startingHex,
                           BattleHex endingHex,
                           boolean undo)
Specified by:
tellBattleMove in interface IClient

strike

public void strike(int tag,
                   BattleHex hex)
Attempt to have critter tag strike the critter in hex.


applyCarries

public void applyCarries(BattleHex hex)
Attempt to apply carries to the critter in hex.


isInContact

public boolean isInContact(BattleCritter critter,
                           boolean countDead)

findMobileCritterHexes

public java.util.Set<BattleHex> findMobileCritterHexes()
Return a set of hexLabels.


findMobileBattleUnits

public java.util.Set<BattleUnit> findMobileBattleUnits()
Return a set of BattleUnits.


showBattleMoves

public java.util.Set<BattleHex> showBattleMoves(BattleCritter battleCritter)

findCrittersWithTargets

public java.util.Set<BattleHex> findCrittersWithTargets()

findStrikes

public java.util.Set<BattleHex> findStrikes(int tag)

getPlayerByName

public Player getPlayerByName(java.lang.String name)

getActivePlayer

public Player getActivePlayer()
Specified by:
getActivePlayer in interface IOracle

getPhase

public Phase getPhase()

getTurnNumber

public int getTurnNumber()
Specified by:
getTurnNumber in interface IOracle

figureTeleportingLord

private CreatureType figureTeleportingLord(Legion legion,
                                           MasterHex hex)

listTeleportingLords

private java.util.List<CreatureType> listTeleportingLords(Legion legion,
                                                          MasterHex hex)
List the lords eligible to teleport this legion to hexLabel.


doMove

public boolean doMove(Legion mover,
                      MasterHex hex)
If the move looks legal, forward it to server and return true; otherwise returns false. Also let user or AI pick teleporting Lord and/or entry side, if relevant.


didMove

public void didMove(Legion legion,
                    MasterHex startingHex,
                    MasterHex currentHex,
                    EntrySide entrySide,
                    boolean teleport,
                    CreatureType teleportingLord,
                    boolean splitLegionHasForcedMove)
Specified by:
didMove in interface IClient

undoMove

public void undoMove(Legion legion)

undidMove

public void undidMove(Legion legion,
                      MasterHex formerHex,
                      MasterHex currentHex,
                      boolean splitLegionHasForcedMove)
Specified by:
undidMove in interface IClient

resetRecruitReservations

public void resetRecruitReservations()

reserveRecruit

public boolean reserveRecruit(CreatureType recruitType)

getReservedRemain

public int getReservedRemain(CreatureType recruitType)

findEligibleRecruits

public java.util.List<CreatureType> findEligibleRecruits(Legion legion,
                                                         MasterHex hex)
Return a list of Creatures (ignore reservations).


findEligibleRecruits

public java.util.List<CreatureType> findEligibleRecruits(Legion legion,
                                                         MasterHex hex,
                                                         boolean considerReservations)
Return a list of Creatures and consider reservations if wanted.

Parameters:
legion - The legion to recruit with.
hex - The hex in which to recruit (not necessarily the same as the legion's position). Not null.
considerReservations - Flag to determine if reservations should be considered.
Returns:
A list of possible recruits for the legion in the hex.

findEligibleRecruiters

public java.util.List<java.lang.String> findEligibleRecruiters(Legion legion,
                                                               CreatureType recruit)
Return a list of creature name strings. TODO return List


getPossibleRecruitHexes

public java.util.Set<MasterHex> getPossibleRecruitHexes()
Return a set of hexes with legions that can (still) muster anything and are not marked as skip.


getPossibleRecruitActionHexes

private java.util.Set<MasterHex> getPossibleRecruitActionHexes()
Return a set of hexLabels with legions that could do a recruit or undo recruit. Used for "if there is nothing to do in this recruit phase, muster phase can immediately be "doneWithRecruit".


noRecruitActionPossible

public boolean noRecruitActionPossible()
Check whether any legion has possibility to recruit at all, no matter whether it could or has already. If there is none, autoDone can automatically be done with recruit phase; but if there is something (e.g. autoRecruit has recruited something, allow human to override/force him to really confirm "Done".

Returns:
Whether there is any legion that could recruit or undoRecruit

getMovement

public MovementClientSide getMovement()

listTeleportMoves

public java.util.Set<MasterHex> listTeleportMoves(Legion legion)
Return a set of hexLabels.


listNormalMoves

public java.util.Set<MasterHex> listNormalMoves(Legion legion)
Return a set of hexLabels.


legionsNotMoved

public void legionsNotMoved(int[] legionStatus,
                            boolean have_roll)
Returns status of client's legions

Parameters:
legionStatus - an array of integers with various status states to be set. Array should be initialized to all zeroes Current array contents: [Constants.legionStatusCount] == count of legions [Constants.legionStatusMoved] == legions that have moved [Constants.legionStatusBlocked] == unmoved legions with no legal move [Constants.legionStatusNotVisitedSkippedBlocked] == legions that have not been moved, are not blocked and have not been skipped

findUnmovedLegionHexes

public java.util.Set<MasterHex> findUnmovedLegionHexes(boolean considerSkippedAsMoved,
                                                       java.util.HashSet<Legion> pendingLegions)

findTallLegionHexes

public java.util.Set<MasterHex> findTallLegionHexes()
Return a set of hexLabels for the active player's legions with 7 or more creatures, and which are not marked as skip this turn.


findTallLegionHexes

public java.util.Set<MasterHex> findTallLegionHexes(int minHeight,
                                                    boolean ignoreSkipFlag)
Return a set of hexLabels for the active player's legions with minHeight or more creatures.

Parameters:
ignoreSkipFlag - Set to true, legion will be considered even if it was marked as "skip this time".

notifyServer

public void notifyServer()

isSctAlreadyDown

public boolean isSctAlreadyDown()

undidSplit

public void undidSplit(Legion splitoff,
                       Legion survivor,
                       int turn)
Specified by:
undidSplit in interface IClient

doneWithSplits

public void doneWithSplits()

doneWithMoves

public void doneWithMoves()

doneWithEngagements

public void doneWithEngagements()

doneWithRecruits

public void doneWithRecruits()

isMyLegion

public boolean isMyLegion(Legion legion)

isMyTurn

public boolean isMyTurn()

isMyBattlePhase

public boolean isMyBattlePhase()

doSplit

public void doSplit(Legion parent)
Called by MasterBoard.actOnLegion() when human user clicked on a legion to split it. This method here then: Verifies that splitting is legal and possible at all; Then get a child marker selected (either by dialog, or if autoPickMarker set, ask AI to pick one); If childMarkerId selection was not canceled (returned non-null), bring up the split dialog (which creatures go into which legion); and if that returns a list (not null) then call doSplit(...,...,...) which sends the request to server.

Parameters:
parent - The legion selected to split

doSplit

public void doSplit(Legion parent,
                    java.lang.String childMarkerId,
                    java.util.List<CreatureType> results)
Called by AI and by doSplit()


didSplit

public void didSplit(MasterHex hex,
                     Legion parent,
                     Legion child,
                     int childHeight,
                     java.util.List<CreatureType> splitoffs,
                     int turn)
Callback from server after any successful split. TODO childHeight is probably redundant now that we pass the legion object

Specified by:
didSplit in interface IClient

askPickColor

public void askPickColor(java.util.List<PlayerColor> colorsLeft)
Specified by:
askPickColor in interface IClient

askPickFirstMarker

public void askPickFirstMarker()
Specified by:
askPickFirstMarker in interface IClient

log

public void log(java.lang.String message)
Specified by:
log in interface IClient

pingRequest

public void pingRequest()
Specified by:
pingRequest in interface IClient

testBattleMove

public boolean testBattleMove(BattleCritter battleUnit,
                              BattleHex hex)

createAI

private AI createAI(java.lang.String playerType)
Create the AI for this Client. If type is some (concrete) AI type, create that type of AI (then this is an AI player). Otherwise, create a SimpleAI as default (used by Human or Remote clients for the autoplay functionality).

Parameters:
playerType - Type of player for which to create an AI
Returns:
Some AI object, according to the situation

aiPause

private void aiPause()
Wait for aiDelay.


setupDelay

private void setupDelay()

getGame

public Game getGame()

getGameClientSide

public GameClientSide getGameClientSide()

getOptions

public Options getOptions()
Specified by:
getOptions in interface OptionObjectProvider

getPossibleRecruits

public java.util.List<CreatureType> getPossibleRecruits(MasterBoardTerrain terrain,
                                                        MasterHex hex)
TODO get from Variant instead of static TerrainRecruitLoader access Just forwarding the query, to get at least the GUI classes get rid of dependency to static TerrainRecruitLoader access. TerrainRecruitLoader.getPossibleRecruits(MasterBoardTerrain, MasterHex)

Specified by:
getPossibleRecruits in interface IVariant

numberOfRecruiterNeeded

public int numberOfRecruiterNeeded(CreatureType recruiter,
                                   CreatureType recruit,
                                   MasterBoardTerrain terrain,
                                   MasterHex hex)
TODO get from Variant instead of static TerrainRecruitLoader access Just forwarding the query, to get at least the GUI classes get rid of dependency to static TerrainRecruitLoader access. TerrainRecruitLoader.numberOfRecruiterNeeded(CreatureType, CreatureType, MasterBoardTerrain, MasterHex)

Specified by:
numberOfRecruiterNeeded in interface IVariant

getTerrains

public java.util.Collection<MasterBoardTerrain> getTerrains()
Return a collection of all possible terrains.

Returns:
A collection containing all instances of MasterBoardTerrain.

setPreferencesCheckBoxValue

public void setPreferencesCheckBoxValue(java.lang.String name,
                                        boolean value)

setPreferencesRadioButtonValue

public void setPreferencesRadioButtonValue(java.lang.String name,
                                           boolean value)