Class InGameController


  • public final class InGameController
    extends FreeColClientHolder
    The controller that will be used while the game is played.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • abortTrade

        private static final StringTemplate abortTrade
        A template to use as a magic cookie for aborted trades.
      • tradeRouteUnitComparator

        private static final java.util.Comparator<Unit> tradeRouteUnitComparator
        A comparator for ordering trade route units.
      • messagesToIgnore

        private final java.util.Map<java.lang.String,​java.lang.Integer> messagesToIgnore
        A map of messages to be ignored.
      • turnReportMessages

        private final java.util.List<ModelMessage> turnReportMessages
        The messages in the last turn report.
    • Constructor Detail

      • InGameController

        public InGameController​(FreeColClient freeColClient)
        The constructor to use.
        Parameters:
        freeColClient - The FreeColClient for the game.
    • Method Detail

      • sound

        public void sound​(java.lang.String soundKey)
        Play a sound.
        Parameters:
        soundKey - The sound resource key.
      • requireOurTurn

        private boolean requireOurTurn()
        Require that it is this client's player's turn. Put up the notYourTurn message if not.
        Returns:
        True if it is our turn.
      • getSettlementAt

        private Settlement getSettlementAt​(Tile tile,
                                           Direction direction)
        Convenience function to find an adjacent settlement. Intended to be called in contexts where we are expecting a settlement to be there, such as when handling a particular move type.
        Parameters:
        tile - The Tile to start at.
        direction - The Direction to step.
        Returns:
        A settlement on the adjacent tile if any.
      • getNationAt

        private StringTemplate getNationAt​(Tile tile,
                                           Direction direction)
        Convenience function to find the nation controlling an adjacent settlement. Intended to be called in contexts where we are expecting a settlement or unit to be there, such as when handling a particular move type.
        Parameters:
        tile - The Tile to start at.
        direction - The Direction to step.
        Returns:
        The name of the nation controlling a settlement on the adjacent tile if any.
      • invokeLater

        private void invokeLater​(java.lang.Runnable runnable)
        Defer execution to the event thread.
        Parameters:
        runnable - The Runnable to run.
      • changeView

        private void changeView​(Unit unit,
                                boolean force)
        Wrapper for GUI.changeView.
        Parameters:
        unit - The Unit to select.
        force - Set true if the unit is the same, but *has* changed in some way (e.g. moves left).
      • changeView

        private void changeView​(Tile tile)
        Wrapper for GUI.changeView.
        Parameters:
        tile - An optional Tile to select.
      • displayChat

        private void displayChat​(java.lang.String sender,
                                 java.lang.String message,
                                 java.awt.Color color,
                                 boolean pri)
        Wrapper for GUI.displayChat.
        Parameters:
        sender - The sender of the chat message.
        message - What to say.
        color - The message color.
        pri - If true, the message is private.
      • showColonyPanel

        private void showColonyPanel​(Colony colony,
                                     Unit unit)
        Wrapper for GUI.showColonyPanel.
        Parameters:
        colony - The Colony to show.
        unit - An optional Unit to select within the panel.
      • showColonyPanelWithCarrier

        private void showColonyPanelWithCarrier​(Colony colony,
                                                Unit unit)
        Display the colony panel for a colony, and select the unit that just arrived there if it is a carrier.
        Parameters:
        colony - The Colony to display.
        unit - An optional Unit to select.
      • error

        private void error​(StringTemplate template,
                           java.lang.String message)
        Wrapper for GUI.showErrorPanel.
        Parameters:
        template - A StringTemplate to display.
        message - An extra non-i18n message to display if debugging.
      • showEmigrationDialog

        private void showEmigrationDialog​(Player player,
                                          boolean foy,
                                          int n)
        Wrapper for GUI.showEmigrationDialog
        Parameters:
        player - The Player who has migrating units.
        foy - True if this is a fountain of youth event.
        n - The number of migrants available.
      • showEventPanel

        private void showEventPanel​(java.lang.String header,
                                    java.lang.String imageKey,
                                    java.lang.String footer)
        Wrapper for GUI.showEventPanel.
        Parameters:
        header - The title.
        imageKey - A resource key for the image to display.
        footer - Optional footer text.
      • showInformationPanel

        private void showInformationPanel​(FreeColObject disp,
                                          java.lang.String messageId)
        Wrapper for GUI.showInformationPanel.
        Parameters:
        disp - An optional object to display in the panel.
        messageId - A message identifier.
      • showInformationPanel

        private void showInformationPanel​(FreeColObject disp,
                                          StringTemplate template)
        Wrapper for GUI.showInformationPanel.
        Parameters:
        disp - An optional object to display in the panel.
        template - A StringTemplate to display.
      • getMissionaryChoice

        private void getMissionaryChoice​(Unit unit,
                                         IndianSettlement is,
                                         Direction direction)
        Wrapper for GUI.getMissionaryChoice
        Parameters:
        unit - The Unit that will enter the settlement.
        is - The IndianSettlement to check.
        direction - The Direction to move the unit.
      • showNamingDialog

        private void showNamingDialog​(StringTemplate template,
                                      java.lang.String defaultName,
                                      Unit unit,
                                      DialogHandler<java.lang.String> handler)
        Wrapper for GUI.showNamingDialog.
        Parameters:
        template - A message template.
        defaultName - The default name for the object.
        unit - The Unit that is naming.
        handler - A callback to handle the user response.
      • showNegotiationDialog

        private void showNegotiationDialog​(Unit unit,
                                           Settlement settlement,
                                           DiplomaticTrade agreement,
                                           StringTemplate comment,
                                           Direction direction)
        Wrapper for GUI.showNegotiationDialog and followup.
        Parameters:
        unit - The Unit that is negotiating.
        settlement - The Settlement that is negotiating.
        agreement - The proposed agreement.
        comment - An optional StringTemplate containing a commentary message.
        direction - An optional Direction to move the unit to the settlement on success.
      • showStatusPanel

        private void showStatusPanel​(java.lang.String message)
        Wrapper for GUI.showStatusPanel, but clear on null.
        Parameters:
        message - The text message to display on the status panel.
      • updateActiveUnit

        private boolean updateActiveUnit​(Tile tile)
        Makes a new unit active if any, or focus on a tile (useful if the current unit just died). Displays any new ModelMessages with nextModelMessage().
        Parameters:
        tile - The Tile to select if no new unit can be made active.
        Returns:
        True if the active unit changes.
      • updateGUI

        private void updateGUI​(Tile tile,
                               boolean updateUnit)
        Update the GUI and the active unit, with a fallback tile.
        Parameters:
        tile - An optional fallback Tile.
        updateUnit - An override setting which if true forces a new active unit to be selected (useful for the Wait command).
      • askAssignTradeRoute

        private boolean askAssignTradeRoute​(Unit unit,
                                            TradeRoute tradeRoute)
        Ask the server to assign a trade route.
        Parameters:
        unit - The Unit to assign to.
        tradeRoute - The TradeRoute to assign.
        Returns:
        True if the assignment succeeds.
      • askClaimTile

        private boolean askClaimTile​(Player player,
                                     Tile tile,
                                     FreeColGameObject claimant,
                                     int price)
        Claim a tile.
        Parameters:
        player - The Player that is claiming.
        tile - The Tile to claim.
        claimant - The Unit or Colony claiming.
        price - The price required.
        Returns:
        True if the claim succeeded.
      • askClearGotoOrders

        private boolean askClearGotoOrders​(Unit unit)
        Clears the goto orders of the given unit by setting its destination to null.
        Parameters:
        unit - The Unit to clear the destination for.
        Returns:
        True if the unit now has no destination or trade route.
      • askEmbark

        private boolean askEmbark​(Unit unit,
                                  Unit carrier)
        Embark onto a carrier.
        Parameters:
        unit - The Unit to embark.
        carrier - The carrier Unit to board.
        Returns:
        True if boarding succeeded.
      • askEmigrate

        private Unit askEmigrate​(Europe europe,
                                 int slot)
        A unit in Europe emigrates. This is unusual for an ask* routine in that it uses a *Was structure, but it is needed to extract the unit.
        Parameters:
        europe - The Europe where the unit appears.
        slot - The slot to choose, [0..RECRUIT_COUNT].
        Returns:
        The new Unit or null on failure.
      • emigration

        private void emigration​(Player player,
                                int n,
                                boolean fountainOfYouth)
        Select all the units to emigrate from Europe. If they are all the same they can be picked automatically, but otherwise use the emigration dialog. Only to be called if the player is allowed to select the unit type (i.e. FoY or has Brewster). The server contains the count of available FoY-units, and maintains the immigration/immigrationRequired amounts, so this routine will fail harmlessly if it asks for too much.
        Parameters:
        player - The Player that owns the unit.
        n - The number of units known to be eligible to emigrate.
        fountainOfYouth - True if this migration if due to a FoY.
      • askLoadGoods

        private boolean askLoadGoods​(Location loc,
                                     GoodsType type,
                                     int amount,
                                     Unit carrier)
        Load some goods onto a carrier.
        Parameters:
        loc - The Location to load from.
        type - The GoodsType to load.
        amount - The amount of goods to load.
        carrier - The Unit to load onto.
        Returns:
        True if the load succeeded.
      • askSetDestination

        private boolean askSetDestination​(Unit unit,
                                          Location destination)
        Set a destination for a unit.
        Parameters:
        unit - The Unit to direct.
        destination - The destination Location.
        Returns:
        True if the destination was set.
      • askUnloadGoods

        private boolean askUnloadGoods​(GoodsType type,
                                       int amount,
                                       Unit carrier)
        Unload some goods from a carrier.
        Parameters:
        type - The GoodsType to unload.
        amount - The amount of goods to unload.
        carrier - The Unit carrying the goods.
        Returns:
        True if the unload succeeded.
      • getSaveGameString

        private java.lang.String getSaveGameString​(Game game)
        Get the trunk of the save game string.
        Parameters:
        game - The Game to query.
        Returns:
        The trunk of the file name to use for saved games.
      • autoSaveGame

        private void autoSaveGame()
        Creates at least one autosave game file of the currently played game in the autosave directory. Does nothing if there is no game running.
      • saveGame

        private boolean saveGame​(java.io.File file)
        Saves the game to the given file.
        Parameters:
        file - The File.
        Returns:
        True if the game was saved.
      • startIgnoringMessage

        private void startIgnoringMessage​(java.lang.String key,
                                          Turn turn)
        Start ignoring a kind of message.
        Parameters:
        key - The key for a message to ignore.
        turn - The current Turn.
      • stopIgnoringMessage

        private void stopIgnoringMessage​(java.lang.String key)
        Stop ignoring a kind of message.
        Parameters:
        key - The key for a message to stop ignoring.
      • reapIgnoredMessages

        private void reapIgnoredMessages​(Turn turn)
        Reap all ignored message keys that are older than the given turn.
        Parameters:
        turn - The Turn value to test against.
      • continueIgnoreMessage

        private boolean continueIgnoreMessage​(java.lang.String key,
                                              Turn turn)
        See if messages with a given key were ignored last turn. If so, continue to ignore them.
        Parameters:
        key - The key to check.
        turn - The current Turn.
        Returns:
        True if the message should continue to be ignored.
      • displayTurnReportMessages

        public void displayTurnReportMessages()
        Displays the messages in the current turn report.
      • displayModelMessages

        private boolean displayModelMessages​(boolean allMessages,
                                             boolean endOfTurn)
        Displays pending ModelMessages.
        Parameters:
        allMessages - Display all messages or just the undisplayed ones.
        endOfTurn - Use a turn report panel if necessary.
        Returns:
        True if any messages were displayed.
      • nextModelMessage

        public boolean nextModelMessage()
        Displays the next ModelMessage. Called from CC.reconnect, CargoPanel, ColonyPanel.closeColonyPanel, EuropePanel.exitAction, EuropePanel.MarketPanel
        Returns:
        True if any messages were displayed.
      • doExecuteGotoOrders

        private boolean doExecuteGotoOrders()
        Do the goto orders operation.
        Returns:
        True if all goto orders have been performed and no units reached their destination and are free to move again.
      • doEndTurn

        private boolean doEndTurn​(boolean showDialog)
        End the turn.
        Parameters:
        showDialog - Show the end turn dialog?
        Returns:
        True if the turn ended.
      • moveToDestination

        private boolean moveToDestination​(Unit unit,
                                          java.util.List<ModelMessage> messages)
        Moves the given unit towards its destination/s if possible.
        Parameters:
        unit - The Unit to move.
        messages - An optional list in which to retain any trade route ModelMessages generated.
        Returns:
        True if all is well with the unit, false if the unit should be selected and examined by the user.
      • movePath

        private boolean movePath​(Unit unit,
                                 PathNode path)
        Follow a path.
        Parameters:
        unit - The Unit to move.
        path - The path to follow.
        Returns:
        True if automatic movement of the unit can proceed.
      • moveDirection

        public boolean moveDirection​(Unit unit,
                                     Direction direction,
                                     boolean interactive)
        Move a unit in a given direction. Public for the test suite.
        Parameters:
        unit - The Unit to move.
        direction - The Direction to move in.
        interactive - Interactive mode: play sounds and emit errors.
        Returns:
        True if automatic movement of the unit can proceed.
      • moveAwayFromEurope

        private boolean moveAwayFromEurope​(Unit unit,
                                           Location destination)
        Move a unit from off map to an on map location.
        Parameters:
        unit - The Unit to be moved.
        destination - The Location to be moved to.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveTowardEurope

        private boolean moveTowardEurope​(Unit unit,
                                         Europe europe)
        Move a unit from on map towards Europe.
        Parameters:
        unit - The Unit to be moved.
        europe - The Europe to be moved to.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveAttack

        private boolean moveAttack​(Unit unit,
                                   Direction direction)
        Confirm attack or demand a tribute from a native settlement, following an attacking move.
        Parameters:
        unit - The Unit to perform the attack.
        direction - The direction in which to attack.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveAttackSettlement

        private boolean moveAttackSettlement​(Unit unit,
                                             Direction direction)
        Confirm attack or demand a tribute from a settlement, following an attacking move.
        Parameters:
        unit - The Unit to perform the attack.
        direction - The direction in which to attack.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveAutoload

        private boolean moveAutoload​(Unit carrier,
                                     java.util.List<Unit> embark)
        Primitive to handle autoloading of a list of units onto a carrier.
        Parameters:
        carrier - The carrier Unit to load onto.
        embark - A list of Units to load.
        Returns:
        True if automatic movement of the carrier can proceed.
      • moveDiplomacy

        private boolean moveDiplomacy​(Unit unit,
                                      Direction direction,
                                      DiplomaticTrade dt)
        Initiates diplomacy with a foreign power.
        Parameters:
        unit - The Unit negotiating.
        direction - The direction of a settlement to negotiate with.
        dt - The base DiplomaticTrade agreement to begin the negotiation with.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveDisembark

        private boolean moveDisembark​(Unit unit,
                                      Direction direction)
        Check the carrier for passengers to disembark, possibly snatching a useful result from the jaws of a MOVE_NO_ACCESS_LAND failure.
        Parameters:
        unit - The carrier containing the unit to disembark.
        direction - The direction in which to disembark the unit.
        Returns:
        True if the disembark "succeeds" (which deliberately includes declined disembarks).
      • moveEmbark

        private boolean moveEmbark​(Unit unit,
                                   Direction direction)
        Embarks the specified unit onto a carrier in a specified direction following a move of MoveType.EMBARK.
        Parameters:
        unit - The Unit that wishes to embark.
        direction - The direction in which to embark.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveExplore

        private boolean moveExplore​(Unit unit,
                                    Direction direction)
        Confirm exploration of a lost city rumour, following a move of MoveType.EXPLORE_LOST_CITY_RUMOUR.
        Parameters:
        unit - The Unit that is exploring.
        direction - The direction of a rumour.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveHighSeas

        private boolean moveHighSeas​(Unit unit,
                                     Direction direction)
        Moves a unit onto the "high seas" in a specified direction following a move of MoveType.MOVE_HIGH_SEAS. This may result in a move to Europe, no move, or an ordinary move.
        Parameters:
        unit - The Unit to be moved.
        direction - The direction in which to move.
        Returns:
        True if automatic movement of the unit can proceed.
      • moveLearnSkill

        private boolean moveLearnSkill​(Unit unit,
                                       Direction direction)
        Move a free colonist to a native settlement to learn a skill following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_FREE_COLONIST. The colonist does not physically get into the village, it will just stay where it is and gain the skill.
        Parameters:
        unit - The Unit to learn the skill.
        direction - The direction in which the Indian settlement lies.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveTile

        private boolean moveTile​(Unit unit,
                                 Direction direction)
        Move a unit in a specified direction on the map, following a move of MoveType.MOVE.
        Parameters:
        unit - The Unit to be moved.
        direction - The direction in which to move the Unit.
        Returns:
        True if automatic movement of the unit can proceed.
      • moveScoutColony

        private boolean moveScoutColony​(Unit unit,
                                        Direction direction)
        Move to a foreign colony and either attack, negotiate with the foreign power or spy on them. Follows a move of MoveType.ENTER_FOREIGN_COLONY_WITH_SCOUT. FIXME: Unify trade and negotiation.
        Parameters:
        unit - The unit that will spy, negotiate or attack.
        direction - The direction in which the foreign colony lies.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveScoutIndianSettlement

        private boolean moveScoutIndianSettlement​(Unit unit,
                                                  Direction direction)
        Move a scout into an Indian settlement to speak with the chief, or demand a tribute following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_SCOUT. The scout does not physically get into the village, it will just stay where it is.
        Parameters:
        unit - The Unit that is scouting.
        direction - The direction in which the Indian settlement lies.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveSpy

        private boolean moveSpy​(Unit unit,
                                Direction direction)
        Spy on a foreign colony.
        Parameters:
        unit - The Unit that is spying.
        direction - The Direction of a colony to spy on.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveTrade

        private boolean moveTrade​(Unit unit,
                                  Direction direction)
        Arrive at a settlement with a laden carrier following a move of MoveType.ENTER_SETTLEMENT_WITH_CARRIER_AND_GOODS.
        Parameters:
        unit - The carrier.
        direction - The direction to the settlement.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveTribute

        private boolean moveTribute​(Unit unit,
                                    int amount,
                                    Direction direction)
        Demand a tribute.
        Parameters:
        unit - The Unit to perform the attack.
        amount - An amount of tribute to demand.
        direction - The direction in which to attack.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • moveUseMissionary

        private boolean moveUseMissionary​(Unit unit,
                                          Direction direction)
        Move a missionary into a native settlement, following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_MISSIONARY.
        Parameters:
        unit - The Unit that will enter the settlement.
        direction - The direction in which the Indian settlement lies.
        Returns:
        True if automatic movement of the unit can proceed (never).
      • followTradeRoute

        private boolean followTradeRoute​(Unit unit,
                                         java.util.List<ModelMessage> messages)
        Follows a trade route, doing load/unload actions, moving the unit, and updating the stop and destination.
        Parameters:
        unit - The Unit on the route.
        messages - An optional list in which to retain any ModelMessages generated.
        Returns:
        True if automatic movement can proceed.
      • loadUnitAtStop

        private boolean loadUnitAtStop​(Unit unit,
                                       LogBuilder lb)
        Work out what goods to load onto a unit at a stop, and load them.
        Parameters:
        unit - The Unit to load.
        lb - A LogBuilder to update.
        Returns:
        True if goods were loaded.
      • unloadUnitAtStop

        private boolean unloadUnitAtStop​(Unit unit,
                                         LogBuilder lb)
        Work out what goods to unload from a unit at a stop, and unload them.
        Parameters:
        unit - The Unit to unload.
        lb - A LogBuilder to update.
        Returns:
        True if something was unloaded.
      • abandonColony

        public boolean abandonColony​(Colony colony)
        Abandon a colony with no units. Called from ColonyPanel.closeColonyPanel
        Parameters:
        colony - The Colony to be abandoned.
        Returns:
        True if the colony was abandoned.
      • addPlayerHandler

        public void addPlayerHandler​(java.util.List<Player> players)
        Handle an addPlayer message.
        Parameters:
        players - The Players to add.
      • animateAttackHandler

        public void animateAttackHandler​(Unit attacker,
                                         Unit defender,
                                         Tile attackerTile,
                                         Tile defenderTile,
                                         boolean success)
        Animate an attack.
        Parameters:
        attacker - The attacking Unit.
        defender - The defending Unit.
        attackerTile - The Tile the attack originates from.
        defenderTile - The Tile the defence takes place on.
        success - True if the attack succeeds.
      • animateMoveHandler

        public void animateMoveHandler​(Unit unit,
                                       Tile oldTile,
                                       Tile newTile)
        Animate a move.
        Parameters:
        unit - The Unit that moves.
        oldTile - The Tile the move begins at.
        newTile - The Tile the move ends at.
      • assignTeacher

        public boolean assignTeacher​(Unit student,
                                     Unit teacher)
        Assigns a student to a teacher. Called from UnitLabel
        Parameters:
        student - The student Unit.
        teacher - The teacher Unit.
        Returns:
        True if the student was assigned.
      • assignTradeRoute

        public boolean assignTradeRoute​(Unit unit,
                                        TradeRoute tradeRoute)
        Assigns a trade route to a unit. Called from EuropePanel.DestinationPanel, TradeRoutePanel(), TradeRoutePanel.newRoute
        Parameters:
        unit - The Unit to assign a trade route to.
        tradeRoute - The TradeRoute to assign.
        Returns:
        True if the route was successfully assigned.
      • boardShip

        public boolean boardShip​(Unit unit,
                                 Unit carrier)
        Boards a specified unit onto a carrier. The carrier must be at the same location as the boarding unit. Called from CargoPanel, TilePopup.
        Parameters:
        unit - The Unit which is to board the carrier.
        carrier - The location of this Unit.
        Returns:
        True if the unit boards the carrier.
      • buildColony

        public boolean buildColony​(Unit unit)
        Use the active unit to build a colony. Called from BuildColonyAction.
        Parameters:
        unit - The Unit to build the colony.
        Returns:
        True if a colony was built.
      • buyGoods

        public boolean buyGoods​(GoodsType type,
                                int amount,
                                Unit carrier)
        Buy goods in Europe. The amount of goods is adjusted to the space in the carrier. Called from CargoPanel, TilePopup, loadCargo()
        Parameters:
        type - The type of goods to buy.
        amount - The amount of goods to buy.
        carrier - The Unit acting as carrier.
        Returns:
        True if the purchase succeeds.
      • chat

        public boolean chat​(java.lang.String chat)
        Sends a public chat message. Called from ChatPanel
        Parameters:
        chat - The text of the message.
        Returns:
        True if the message was sent.
      • chatHandler

        public void chatHandler​(java.lang.String sender,
                                java.lang.String message,
                                java.awt.Color color,
                                boolean pri)
        Chat with another player.
        Parameters:
        sender - The sender of the chat message.
        message - What to say.
        color - The message color.
        pri - If true, the message is private.
      • changeState

        public boolean changeState​(Unit unit,
                                   Unit.UnitState state)
        Changes the state of this Unit. Called from FortifyAction, SentryAction, TilePopup, UnitLabel
        Parameters:
        unit - The Unit
        state - The state of the unit.
        Returns:
        True if the state was changed.
      • changeWorkImprovementType

        public boolean changeWorkImprovementType​(Unit unit,
                                                 TileImprovementType improvementType)
        Changes the work type of this Unit. Called from ImprovementAction.
        Parameters:
        unit - The Unit
        improvementType - a TileImprovementType value
        Returns:
        True if the improvement was changed.
      • changeWorkType

        public boolean changeWorkType​(Unit unit,
                                      GoodsType workType)
        Changes the work type of this Unit. Called from ColonyPanel.tryWork, UnitLabel
        Parameters:
        unit - The Unit
        workType - The new GoodsType to produce.
        Returns:
        True if the work type was changed.
      • checkCashInTreasureTrain

        public boolean checkCashInTreasureTrain​(Unit unit)
        Check if a unit is a treasure train, and if it should be cashed in. Transfers the gold carried by this unit to the owner. Called from TilePopup
        Parameters:
        unit - The Unit to be checked.
        Returns:
        True if the unit was cashed in (and disposed).
      • chooseFoundingFather

        private boolean chooseFoundingFather​(java.util.List<FoundingFather> ffs,
                                             FoundingFather ff)
        Choose a founding father from an offered list.
        Parameters:
        ffs - A list of FoundingFathers to choose from.
        ff - The chosen FoundingFather (may be null).
        Returns:
        True if a father was chosen.
      • chooseFoundingFatherHandler

        public void chooseFoundingFatherHandler​(java.util.List<FoundingFather> ffs)
        Choose a founding father from an offered list.
        Parameters:
        ffs - A list of FoundingFathers to choose from.
      • claimTile

        public boolean claimTile​(Tile tile,
                                 FreeColGameObject claimant)
        Claim a tile. Called from ColonyPanel.ASingleTilePanel, UnitLabel and work()
        Parameters:
        tile - The Tile to claim.
        claimant - The Unit or Colony claiming.
        Returns:
        True if the claim succeeded.
      • clearGotoOrders

        public boolean clearGotoOrders​(Unit unit)
        Clears the goto orders of the given unit by setting its destination to null. Called from CanvasMouseListener
        Parameters:
        unit - The Unit to clear the destination for.
        Returns:
        True if the unit has no destination.
      • clearOrders

        public boolean clearOrders​(Unit unit)
        Clears the orders of the given unit. Make the unit active and set a null destination and trade route. Called from ClearOrdersAction, TilePopup, TradeRoutePanel, UnitLabel
        Parameters:
        unit - The Unit to clear the orders of
        Returns:
        boolean true if the orders were cleared
      • clearSpeciality

        public boolean clearSpeciality​(Unit unit)
        Clear the speciality of a Unit, making it a Free Colonist. Called from UnitLabel
        Parameters:
        unit - The Unit to clear the speciality of.
        Returns:
        True if the speciality was cleared.
      • closeColony

        public void closeColony​(Colony colony,
                                boolean abandon)
        Special handling when we close a colony panel.
        Parameters:
        colony - The Colony to close.
        abandon - True if abandoning, otherwise just update.
      • closeHandler

        public void closeHandler​(java.lang.String panel)
        Close any open GUI menus.
        Parameters:
        panel - The identifier for the panel to close.
      • declareIndependence

        public boolean declareIndependence()
        Declares independence for the home country. Called from DeclareIndependenceAction
        Returns:
        True if independence was declared.
      • deleteTradeRoute

        public boolean deleteTradeRoute​(TradeRoute tradeRoute)
        Delete a trade route. Called from TradeRoutePanel button.
        Parameters:
        tradeRoute - The TradeRoute to delete.
        Returns:
        True if the route was successfully deleted.
      • diplomacyHandler

        public void diplomacyHandler​(FreeColGameObject our,
                                     FreeColGameObject other,
                                     DiplomaticTrade agreement)
        Handle a diplomatic offer.
        Parameters:
        our - Our FreeColGameObject that is negotiating.
        other - The other FreeColGameObject.
        agreement - The DiplomaticTrade agreement.
      • disbandUnit

        public boolean disbandUnit​(Unit unit)
        Disbands the active unit. Called from DisbandUnitAction.
        Parameters:
        unit - The Unit to disband.
        Returns:
        True if the unit was disbanded.
      • emigrate

        private void emigrate​(Player player,
                              int slot,
                              int n,
                              boolean foY)
        Emigrate a unit from Europe.
        Parameters:
        player - The Player that owns the unit.
        slot - The slot to emigrate from, [0..RECRUIT_COUNT].
        n - The number of remaining units known to be eligible to migrate.
        foY - True if this migration is due to a fountain of youth event.
      • endTurn

        public boolean endTurn​(boolean showDialog)
        End the turn command. Called from EndTurnAction, GUI.showEndTurnDialog
        Parameters:
        showDialog - If false, suppress showing the end turn dialog.
        Returns:
        True if the turn was ended.
      • equipUnitForRole

        public boolean equipUnitForRole​(Unit unit,
                                        Role role,
                                        int roleCount)
        Change the role-equipment a unit has. Called from DefaultTransferHandler, QuickActionMenu
        Parameters:
        unit - The Unit.
        role - The Role to assume.
        roleCount - The role count.
        Returns:
        True if the role is taken.
      • errorHandler

        public void errorHandler​(StringTemplate template,
                                 java.lang.String message)
        Handle an error.
        Parameters:
        template - A StringTemplate to display.
        message - An extra non-i18n message to display if debugging.
      • executeGotoOrders

        public boolean executeGotoOrders()
        Execute goto orders command. Called from ExecuteGotoOrdersAction.
        Returns:
        True if all goto orders have been performed and no units reached their destination and are free to move again.
      • featureChangeHandler

        public void featureChangeHandler​(FreeColGameObject parent,
                                         java.util.List<FreeColObject> children,
                                         boolean add)
        Handle feature changes.
        Parameters:
        parent - The parent FreeColGameObject to add to.
        children - The child FreeColObjects that change.
        add - If true, add the child, otherwise remove it.
      • firstContact

        private boolean firstContact​(Player player,
                                     Player other,
                                     Tile tile,
                                     boolean result)
        A player makes first contact with a native player.
        Parameters:
        player - The Player making contact.
        other - The native Player being contacted.
        tile - An optional Tile to offer the player if they have made a first landing.
        result - Whether the initial treaty was accepted.
        Returns:
        True if first contact occurs.
      • firstContactHandler

        public void firstContactHandler​(Player player,
                                        Player other,
                                        Tile tile,
                                        int n)
        A player makes first contact with a native player.
        Parameters:
        player - The Player making contact.
        other - The native Player being contacted.
        tile - An optional Tile to offer the player if they have made a first landing.
        n - The number of settlements claimed by the native player.
      • fountainOfYouthHandler

        public void fountainOfYouthHandler​(int n)
        Handle a fountain of youth event.
        Parameters:
        n - The number of migrants available for selection.
      • gameEndedHandler

        public void gameEndedHandler​(java.lang.String score)
        The player has won, show the high scores and victory dialog.
        Parameters:
        score - If "true", a new high score was reached.
      • goToTile

        public boolean goToTile​(Unit unit,
                                PathNode path)
        Go to a tile. Called from CanvasMouseListener, TilePopup
        Parameters:
        unit - The Unit to move.
        path - The Path to move along.
        Returns:
        True if the destination change was successful.
      • highScore

        public boolean highScore​(java.lang.Boolean high)
        Display the high scores. Called from ReportHighScoresAction
        Parameters:
        high - A Boolean whose values indicates whether a new high score has been achieved, or no information if null.
        Returns:
        True if the server interaction succeeded.
      • highScoresHandler

        public void highScoresHandler​(java.lang.String key,
                                      java.util.List<HighScore> scores)
        Display the high scores.
        Parameters:
        key - An optional message key.
        scores - The list of HighScore records to display.
      • ignoreMessage

        public boolean ignoreMessage​(ModelMessage message,
                                     boolean flag)
        Ignore this ModelMessage from now on until it is not generated in a turn. Called from ReportTurnPanel
        Parameters:
        message - a ModelMessage value
        flag - whether to ignore the ModelMessage or not
        Returns:
        True, ignore message status changes can not fail.
      • inciteHandler

        public void inciteHandler​(Unit unit,
                                  IndianSettlement is,
                                  Player enemy,
                                  int gold)
        Handle an incite response.
        Parameters:
        unit - The Unit that is inciting.
        is - The IndianSettlement being incited.
        enemy - The Player incited against.
        gold - The gold required by the natives to become hostile.
      • indianDemandHandler

        public void indianDemandHandler​(Unit unit,
                                        Colony colony,
                                        GoodsType type,
                                        int amount)
        Handle a native demand at a colony.
        Parameters:
        unit - The native Unit making the demand.
        colony - The Colony demanded of.
        type - The GoodsType demanded (null means gold).
        amount - The amount of goods/gold demanded.
      • joinColony

        private boolean joinColony​(Unit unit)
        Join the colony at a unit's current location.
        Parameters:
        unit - The Unit to use.
        Returns:
        True if the unit joined a colony.
      • leaveShip

        public boolean leaveShip​(Unit unit)
        Leave a ship. The ship must be in harbour. Called from CargoPanel, ColonyPanel, EuropePanel.unloadAction, UnitLabel
        Parameters:
        unit - The Unit which is to leave the ship.
        Returns:
        True if the unit left the ship.
      • loadCargo

        public boolean loadCargo​(Goods goods,
                                 Unit carrier)
        Loads a cargo onto a carrier. Called from CargoPanel, ColonyPanel, LoadAction, TilePopup.
        Parameters:
        goods - The Goods which are going aboard the carrier.
        carrier - The Unit acting as carrier.
        Returns:
        True if the goods were loaded.
      • loadGame

        public void loadGame()
        Opens a dialog where the user should specify the filename and loads the game. Called from OpenAction. Returns no status as this game is stopped.
      • logoutHandler

        public void logoutHandler​(Player player,
                                  Game.LogoutReason reason)
        Log out the current player.
        Parameters:
        player - The Player that is logging out.
        reason - The reason for logging out.
      • lootCargo

        private boolean lootCargo​(Unit unit,
                                  java.util.List<Goods> goods,
                                  java.lang.String defenderId)
        Loot some cargo. Called from GUI.showCaptureGoodsDialog
        Parameters:
        unit - The Unit that is looting.
        goods - A list of Goods to choose from.
        defenderId - The identifier of the defender unit (may have sunk).
        Returns:
        True if looting occurs.
      • lootCargoHandler

        public void lootCargoHandler​(Unit unit,
                                     java.util.List<Goods> goods,
                                     java.lang.String loserId)
        Loot some cargo.
        Parameters:
        unit - The Unit that is looting.
        goods - A list of Goods to choose from.
        loserId - The identifier of the defender unit (may have sunk).
      • monarchAction

        public boolean monarchAction​(Monarch.MonarchAction action,
                                     boolean accept)
        Accept or reject a monarch action. Called from GUI.showMonarchDialog
        Parameters:
        action - The MonarchAction performed.
        accept - If true, accept the action.
        Returns:
        True if the monarch was answered.
      • monarchActionHandler

        public void monarchActionHandler​(Monarch.MonarchAction action,
                                         StringTemplate template,
                                         java.lang.String monarchKey)
        Do a monarch interaction.
        Parameters:
        action - The MonarchAction to perform.
        template - A StringTemplate describing the action.
        monarchKey - A key for the monarch involved.
      • moveTo

        public boolean moveTo​(Unit unit,
                              Location destination)
        Moves the specified unit somewhere that requires crossing the high seas. Called from EuropePanel.DestinationPanel, TilePopup
        Parameters:
        unit - The Unit to be moved.
        destination - The Location to be moved to.
        Returns:
        True if automatic movement of the unit can proceed.
      • moveUnit

        public boolean moveUnit​(Unit unit,
                                Direction direction)
        Moves the active unit in a specified direction. This may result in an attack, move... action. Called from MoveAction, CornerMapControls
        Parameters:
        unit - The Unit to move.
        direction - The Direction in which to move the active unit.
        Returns:
        True if the unit may move further.
      • nameNewRegion

        public boolean nameNewRegion​(Tile tile,
                                     Unit unit,
                                     Region region,
                                     java.lang.String name)
        The player names a new region. Called from newRegionName, GUI.showNameNewRegionDialog
        Parameters:
        tile - The Tile within the region.
        unit - The Unit that has discovered the region.
        region - The Region to name.
        name - The name to offer.
        Returns:
        True if the new region was named.
      • nationSummary

        public NationSummary nationSummary​(Player player)
        Get the nation summary for a player. Called from DiplomaticTradePanel, ReportForeignAffairsPanel, ReportIndianPanel
        Parameters:
        player - The Player to summarize.
        Returns:
        A summary of that nation, or null on error.
      • nationSummaryHandler

        public void nationSummaryHandler​(Player other,
                                         NationSummary ns)
        Handle a nation summary update.
        Parameters:
        other - The Player to update.
        ns - The NationSummary for the other player.
      • nativeTradeHandler

        public void nativeTradeHandler​(NativeTrade.NativeTradeAction action,
                                       NativeTrade nt)
        Cache a native trade update.
        Parameters:
        action - The NativeTradeAction to handle.
        nt - The NativeTrade underway.
      • nativeTrade

        private void nativeTrade​(NativeTrade nt,
                                 Constants.TradeAction act,
                                 NativeTradeItem nti,
                                 StringTemplate prompt)
        Execute the native trade.
        Parameters:
        nt - The NativeTrade underway.
        act - The TradeAction to perform.
        nti - The NativeTradeItem being haggled over, if any.
        prompt - An action-specific base prompt, if any.
      • newLandName

        private boolean newLandName​(Unit unit,
                                    java.lang.String name)
        A player names the New World. Called from GUI.showNameNewLandDialog
        Parameters:
        unit - The Unit that landed.
        name - The name to use.
        Returns:
        True if the new land was named.
      • newLandNameHandler

        public void newLandNameHandler​(Unit unit,
                                       java.lang.String defaultName)
        Ask the player to name the new land.
        Parameters:
        unit - The Unit that has landed.
        defaultName - The default name to use.
      • newRegionName

        private boolean newRegionName​(Region region,
                                      Tile tile,
                                      Unit unit,
                                      java.lang.String name)
        The player names a new region.
        Parameters:
        tile - The Tile within the region.
        unit - The Unit that has discovered the region.
        region - The Region to name.
        name - The name to offer.
        Returns:
        True if the new region was named.
      • newRegionNameHandler

        public void newRegionNameHandler​(Region region,
                                         Tile tile,
                                         Unit unit,
                                         java.lang.String name)
        Handle new region naming.
        Parameters:
        region - The Region to name.
        tile - The Tile the unit landed at.
        unit - The Unit that has landed.
        name - The default name to use.
      • newTradeRoute

        public TradeRoute newTradeRoute​(Player player)
        Gets a new trade route for a player. Called from TradeRoutePanel.newRoute. Relies on new trade routes being added at the end of the trade route list.
        Parameters:
        player - The Player to get a new trade route for.
        Returns:
        A new TradeRoute.
      • newTradeRouteHandler

        public void newTradeRouteHandler​(TradeRoute tr)
        Handle a new trade route.
        Parameters:
        tr - The TradeRoute to add.
      • newTurn

        private boolean newTurn​(int turn)
        Switch to a new turn.
        Parameters:
        turn - The turn number.
        Returns:
        True if the new turn occurs.
      • newTurnHandler

        public void newTurnHandler​(int turn)
        Handle the new turn.
        Parameters:
        turn - The new turn number.
      • nextActiveUnit

        public boolean nextActiveUnit()
        Makes a new unit active. Called from PGC.startGame, ColonyPanel.closeColonyPanel
        Returns:
        True unless it was not our turn.
      • partialHandler

        public void partialHandler​(FreeColGameObject fcgo,
                                   java.util.Map<java.lang.String,​java.lang.String> fields)
        Handle partial updates.
        Parameters:
        fcgo - The FreeColGameObject to update.
        fields - A map of fields to update.
      • payArrears

        public boolean payArrears​(GoodsType type)
        Pays the tax arrears on this type of goods. Called from CargoPanel, EuropePanel.MarketPanel, EuropePanel.unloadAction, QuickActionMenu
        Parameters:
        type - The type of goods for which to pay arrears.
        Returns:
        True if the arrears were paid.
      • payForBuilding

        public boolean payForBuilding​(Colony colony)
        Buys the remaining hammers and tools for the Building currently being built in the given Colony. Called from BuildQueuePanel
        Parameters:
        colony - The Colony where the building should be bought.
        Returns:
        True if the building was bought.
      • putOutsideColony

        public boolean putOutsideColony​(Unit unit)
        Puts the specified unit outside the colony. Called from ColonyPanel.OutsideColonyPanel, UnitLabel
        Parameters:
        unit - The Unit
        Returns:
        True if the unit was successfully put outside the colony.
      • reconnect

        public void reconnect()
        Query whether the user wants to reconnect? Called from ReconnectAction. Returns no status, this game is going away.
      • reconnectHandler

        public void reconnectHandler()
        Handle a reconnect message.
      • recruitUnitInEurope

        public boolean recruitUnitInEurope​(int index)
        Recruit a unit from a specified index in Europe. Called from RecruitPanel
        Parameters:
        index - The index in Europe to recruit from, [0..RECRUIT_COUNT).
        Returns:
        True if a unit was recruited.
      • removeHandler

        public void removeHandler​(java.util.List<FreeColGameObject> objects,
                                  FreeColGameObject divert)
        Remove game objects.
        Parameters:
        objects - A list of FreeColGameObjects to remove.
        divert - An object to divert to when the original disappears.
      • rename

        public boolean rename​(Nameable object)
        Renames a Nameable. Apparently this can be done while it is not your turn. Called from RenameAction, TilePopup.
        Parameters:
        object - The object to rename.
        Returns:
        True if the object was renamed.
      • saveAndQuit

        public boolean saveAndQuit()
        Save and quit the game. Called from and SaveAndQuitAction.
        Returns:
        False if the game was not saved, otherwise the game quits.
      • saveGame

        public boolean saveGame()
        Opens a dialog where the user should specify the filename and saves the game. Called from SaveAction and SaveAndQuitAction.
        Returns:
        True if the game was saved.
      • scoutSpeakToChiefHandler

        public void scoutSpeakToChiefHandler​(Unit unit,
                                             IndianSettlement is,
                                             java.lang.String result)
        Display the results of speaking to a chief.
        Parameters:
        unit - The Unit that was speaking.
        is - The IndianSettlement spoken to.
        result - The result.
      • selectDestination

        public boolean selectDestination​(Unit unit)
        Selects a destination for this unit. Europe and the player's colonies are valid destinations. Called from GotoAction.
        Parameters:
        unit - The unit for which to select a destination.
        Returns:
        True if the destination change succeeds.
      • sellGoods

        public boolean sellGoods​(Goods goods)
        Sells goods in Europe. Called from EuropePanel.MarketPanel, EuropePanel.unloadAction, unload(), unloadCargo()
        Parameters:
        goods - The goods to be sold.
        Returns:
        True if the sale succeeds.
      • setAIHandler

        public void setAIHandler​(Player player,
                                 boolean ai)
        Handle setting the AI state of a player.
        Parameters:
        player - The Player to set.
        ai - The new AI state.
      • setBuildQueue

        public boolean setBuildQueue​(Colony colony,
                                     java.util.List<BuildableType> buildQueue)
        Changes the current construction project of a Colony. Called from BuildQueuePanel
        Parameters:
        colony - The Colony
        buildQueue - List of BuildableType
        Returns:
        True if the build queue was changed.
      • setCurrentPlayer

        private boolean setCurrentPlayer​(Player player)
        Set a player to be the new current player.
        Parameters:
        player - The Player to be the new current player.
        Returns:
        True if the current player changes.
      • setCurrentPlayerHandler

        public void setCurrentPlayerHandler​(Player currentPlayer)
        Handle a current player setting.
        Parameters:
        currentPlayer - The new current Player.
      • setDead

        private boolean setDead()
        This player has died.
        Returns:
        True if the player has risen as the undead.
      • setDeadHandler

        public void setDeadHandler​(Player dead)
        Set a player to be dead.
        Parameters:
        dead - The dead Player.
      • setGameConnected

        public void setGameConnected()
        Informs this controller that a game has been newly loaded. Called from ConnectController.startSavedGame No status returned to connect controller.
      • setGoodsLevels

        public boolean setGoodsLevels​(Colony colony,
                                      GoodsType goodsType)
        Sets the export settings of the custom house. Called from WarehouseDialog
        Parameters:
        colony - The colony with the custom house.
        goodsType - The goods for which to set the settings.
        Returns:
        True if the levels were set.
      • setInDebugMode

        public boolean setInDebugMode()
        Sets the debug mode to include the extra menu commands. Called from DebugAction
        Returns:
        True, always succeeds.
      • setStanceHandler

        public boolean setStanceHandler​(Stance stance,
                                        Player first,
                                        Player second)
        Notify the player that the stance between two players has changed.
        Parameters:
        stance - The changed Stance.
        first - The first Player.
        second - The second Player.
        Returns:
        True if the stance change succeeds.
      • spySettlementHandler

        public void spySettlementHandler​(Tile tile)
        Spy on a settlement.
        Parameters:
        tile - A special copy of the Tile with the settlement.
      • trainUnitInEurope

        public boolean trainUnitInEurope​(UnitType unitType)
        Trains a unit of a specified type in Europe. Called from NewUnitPanel.
        Parameters:
        unitType - The type of unit to be trained.
        Returns:
        True if a new unit was trained.
      • unload

        public boolean unload​(Unit unit)
        Unload, including dumping cargo. Called from UnloadAction, UnitLabel
        Parameters:
        unit - The Unit that is dumping.
        Returns:
        True if the unit unloaded.
      • unloadCargo

        public boolean unloadCargo​(Goods goods,
                                   boolean dump)
        Unload cargo. If the unit carrying the cargo is not in a harbour, or if the given boolean is true, the goods will be dumped. Called from CargoPanel, ColonyPanel, EuropePanel.MarketPanel, GUI.showDumpCargoDialog, QuickActionMenu, unload()
        Parameters:
        goods - The Goods to unload.
        dump - If true, dump the goods.
        Returns:
        True if the unload succeeds.
      • updateHandler

        public void updateHandler​(java.util.List<FreeColObject> objects)
        Handle updates.
        Parameters:
        objects - The FreeColObjects to update.
      • updateTradeRoute

        public boolean updateTradeRoute​(TradeRoute route)
        Updates a trade route. Called from TradeRoutePanel(), TradeRoutePanel.newRoute
        Parameters:
        route - The trade route to update.
        Returns:
        True if the trade route was updated.
      • victory

        private boolean victory​(java.lang.Boolean quit)
        The player has won!
        Parameters:
        quit - If true, leave this game and start a new one.
        Returns:
        True.
      • waitUnit

        public boolean waitUnit()
        Tell a unit to wait. Called from WaitAction.
        Returns:
        True, this can not fail.
      • work

        public boolean work​(Unit unit,
                            WorkLocation workLocation)
        Moves a Unit to a WorkLocation. Called from ColonyPanel.tryWork, UnitLabel
        Parameters:
        unit - The Unit.
        workLocation - The new WorkLocation.
        Returns:
        True if the unit is now working at the new work location.