Package net.sf.freecol.client.control
Class InGameController
- java.lang.Object
-
- net.sf.freecol.client.control.FreeColClientHolder
-
- net.sf.freecol.client.control.InGameController
-
public final class InGameController extends FreeColClientHolder
The controller that will be used while the game is played.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classInGameController.MoveModeSelecting next unit depends on mode--- either from the active list, from the going-to list, or flush going-to and end the turn.
-
Field Summary
Fields Modifier and Type Field Description private static StringTemplateabortTradeA template to use as a magic cookie for aborted trades.private static java.util.logging.Loggerloggerprivate java.util.Map<java.lang.String,java.lang.Integer>messagesToIgnoreA map of messages to be ignored.private InGameController.MoveModemoveModeCurrent mode for moving units.private static java.util.Comparator<Unit>tradeRouteUnitComparatorA comparator for ordering trade route units.private java.util.List<ModelMessage>turnReportMessagesThe messages in the last turn report.private static shortUNIT_LAST_MOVE_DELAY
-
Constructor Summary
Constructors Constructor Description InGameController(FreeColClient freeColClient)The constructor to use.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanabandonColony(Colony colony)Abandon a colony with no units.voidaddPlayerHandler(java.util.List<Player> players)Handle an addPlayer message.voidanimateAttackHandler(Unit attacker, Unit defender, Tile attackerTile, Tile defenderTile, boolean success)Animate an attack.voidanimateMoveHandler(Unit unit, Tile oldTile, Tile newTile)Animate a move.private booleanaskAssignTradeRoute(Unit unit, TradeRoute tradeRoute)Ask the server to assign a trade route.private booleanaskClaimTile(Player player, Tile tile, FreeColGameObject claimant, int price)Claim a tile.private booleanaskClearGotoOrders(Unit unit)Clears the goto orders of the given unit by setting its destination to null.private booleanaskEmbark(Unit unit, Unit carrier)Embark onto a carrier.private UnitaskEmigrate(Europe europe, int slot)A unit in Europe emigrates.private booleanaskLoadGoods(Location loc, GoodsType type, int amount, Unit carrier)Load some goods onto a carrier.private booleanaskSetDestination(Unit unit, Location destination)Set a destination for a unit.private booleanaskUnloadGoods(GoodsType type, int amount, Unit carrier)Unload some goods from a carrier.booleanassignTeacher(Unit student, Unit teacher)Assigns a student to a teacher.booleanassignTradeRoute(Unit unit, TradeRoute tradeRoute)Assigns a trade route to a unit.private voidautoSaveGame()Creates at least one autosave game file of the currently played game in the autosave directory.booleanboardShip(Unit unit, Unit carrier)Boards a specified unit onto a carrier.booleanbuildColony(Unit unit)Use the active unit to build a colony.booleanbuyGoods(GoodsType type, int amount, Unit carrier)Buy goods in Europe.booleanchangeState(Unit unit, Unit.UnitState state)Changes the state of thisUnit.private voidchangeView(Tile tile)Wrapper for GUI.changeView.private voidchangeView(Unit unit, boolean force)Wrapper for GUI.changeView.booleanchangeWorkImprovementType(Unit unit, TileImprovementType improvementType)Changes the work type of thisUnit.booleanchangeWorkType(Unit unit, GoodsType workType)Changes the work type of thisUnit.booleanchat(java.lang.String chat)Sends a public chat message.voidchatHandler(java.lang.String sender, java.lang.String message, java.awt.Color color, boolean pri)Chat with another player.booleancheckCashInTreasureTrain(Unit unit)Check if a unit is a treasure train, and if it should be cashed in.private booleanchooseFoundingFather(java.util.List<FoundingFather> ffs, FoundingFather ff)Choose a founding father from an offered list.voidchooseFoundingFatherHandler(java.util.List<FoundingFather> ffs)Choose a founding father from an offered list.booleanclaimTile(Tile tile, FreeColGameObject claimant)Claim a tile.booleanclearGotoOrders(Unit unit)Clears the goto orders of the given unit by setting its destination to null.booleanclearOrders(Unit unit)Clears the orders of the given unit.booleanclearSpeciality(Unit unit)Clear the speciality of a Unit, making it a Free Colonist.voidcloseColony(Colony colony, boolean abandon)Special handling when we close a colony panel.voidcloseHandler(java.lang.String panel)Close any open GUI menus.private booleancontinueIgnoreMessage(java.lang.String key, Turn turn)See if messages with a given key were ignored last turn.booleandeclareIndependence()Declares independence for the home country.booleandeleteTradeRoute(TradeRoute tradeRoute)Delete a trade route.voiddiplomacyHandler(FreeColGameObject our, FreeColGameObject other, DiplomaticTrade agreement)Handle a diplomatic offer.booleandisbandUnit(Unit unit)Disbands the active unit.private voiddisplayChat(java.lang.String sender, java.lang.String message, java.awt.Color color, boolean pri)Wrapper for GUI.displayChat.private booleandisplayModelMessages(boolean allMessages, boolean endOfTurn)Displays pendingModelMessages.voiddisplayTurnReportMessages()Displays the messages in the current turn report.private booleandoEndTurn(boolean showDialog)End the turn.private booleandoExecuteGotoOrders()Do the goto orders operation.private voidemigrate(Player player, int slot, int n, boolean foY)Emigrate a unit from Europe.private voidemigration(Player player, int n, boolean fountainOfYouth)Select all the units to emigrate from Europe.booleanendTurn(boolean showDialog)End the turn command.booleanequipUnitForRole(Unit unit, Role role, int roleCount)Change the role-equipment a unit has.private voiderror(StringTemplate template, java.lang.String message)Wrapper for GUI.showErrorPanel.voiderrorHandler(StringTemplate template, java.lang.String message)Handle an error.booleanexecuteGotoOrders()Execute goto orders command.voidfeatureChangeHandler(FreeColGameObject parent, java.util.List<FreeColObject> children, boolean add)Handle feature changes.private booleanfirstContact(Player player, Player other, Tile tile, boolean result)A player makes first contact with a native player.voidfirstContactHandler(Player player, Player other, Tile tile, int n)A player makes first contact with a native player.private booleanfollowTradeRoute(Unit unit, java.util.List<ModelMessage> messages)Follows a trade route, doing load/unload actions, moving the unit, and updating the stop and destination.voidfountainOfYouthHandler(int n)Handle a fountain of youth event.voidgameEndedHandler(java.lang.String score)The player has won, show the high scores and victory dialog.private voidgetMissionaryChoice(Unit unit, IndianSettlement is, Direction direction)Wrapper for GUI.getMissionaryChoiceprivate StringTemplategetNationAt(Tile tile, Direction direction)Convenience function to find the nation controlling an adjacent settlement.private java.lang.StringgetSaveGameString(Game game)Get the trunk of the save game string.private SettlementgetSettlementAt(Tile tile, Direction direction)Convenience function to find an adjacent settlement.booleangoToTile(Unit unit, PathNode path)Go to a tile.booleanhighScore(java.lang.Boolean high)Display the high scores.voidhighScoresHandler(java.lang.String key, java.util.List<HighScore> scores)Display the high scores.booleanignoreMessage(ModelMessage message, boolean flag)Ignore this ModelMessage from now on until it is not generated in a turn.voidinciteHandler(Unit unit, IndianSettlement is, Player enemy, int gold)Handle an incite response.voidindianDemandHandler(Unit unit, Colony colony, GoodsType type, int amount)Handle a native demand at a colony.private voidinvokeLater(java.lang.Runnable runnable)Defer execution to the event thread.private booleanjoinColony(Unit unit)Join the colony at a unit's current location.booleanleaveShip(Unit unit)Leave a ship.booleanloadCargo(Goods goods, Unit carrier)Loads a cargo onto a carrier.voidloadGame()Opens a dialog where the user should specify the filename and loads the game.private booleanloadUnitAtStop(Unit unit, LogBuilder lb)Work out what goods to load onto a unit at a stop, and load them.voidlogoutHandler(Player player, Game.LogoutReason reason)Log out the current player.private booleanlootCargo(Unit unit, java.util.List<Goods> goods, java.lang.String defenderId)Loot some cargo.voidlootCargoHandler(Unit unit, java.util.List<Goods> goods, java.lang.String loserId)Loot some cargo.booleanmonarchAction(Monarch.MonarchAction action, boolean accept)Accept or reject a monarch action.voidmonarchActionHandler(Monarch.MonarchAction action, StringTemplate template, java.lang.String monarchKey)Do a monarch interaction.private booleanmoveAttack(Unit unit, Direction direction)Confirm attack or demand a tribute from a native settlement, following an attacking move.private booleanmoveAttackSettlement(Unit unit, Direction direction)Confirm attack or demand a tribute from a settlement, following an attacking move.private booleanmoveAutoload(Unit carrier, java.util.List<Unit> embark)Primitive to handle autoloading of a list of units onto a carrier.private booleanmoveAwayFromEurope(Unit unit, Location destination)Move a unit from off map to an on map location.private booleanmoveDiplomacy(Unit unit, Direction direction, DiplomaticTrade dt)Initiates diplomacy with a foreign power.booleanmoveDirection(Unit unit, Direction direction, boolean interactive)Move a unit in a given direction.private booleanmoveDisembark(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.private booleanmoveEmbark(Unit unit, Direction direction)Embarks the specified unit onto a carrier in a specified direction following a move of MoveType.EMBARK.private booleanmoveExplore(Unit unit, Direction direction)Confirm exploration of a lost city rumour, following a move of MoveType.EXPLORE_LOST_CITY_RUMOUR.private booleanmoveHighSeas(Unit unit, Direction direction)Moves a unit onto the "high seas" in a specified direction following a move of MoveType.MOVE_HIGH_SEAS.private booleanmoveLearnSkill(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.private booleanmovePath(Unit unit, PathNode path)Follow a path.private booleanmoveScoutColony(Unit unit, Direction direction)Move to a foreign colony and either attack, negotiate with the foreign power or spy on them.private booleanmoveScoutIndianSettlement(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.private booleanmoveSpy(Unit unit, Direction direction)Spy on a foreign colony.private booleanmoveTile(Unit unit, Direction direction)Move a unit in a specified direction on the map, following a move of MoveType.MOVE.booleanmoveTo(Unit unit, Location destination)Moves the specified unit somewhere that requires crossing the high seas.private booleanmoveToDestination(Unit unit, java.util.List<ModelMessage> messages)Moves the given unit towards its destination/s if possible.private booleanmoveTowardEurope(Unit unit, Europe europe)Move a unit from on map towards Europe.private booleanmoveTrade(Unit unit, Direction direction)Arrive at a settlement with a laden carrier following a move of MoveType.ENTER_SETTLEMENT_WITH_CARRIER_AND_GOODS.private booleanmoveTribute(Unit unit, int amount, Direction direction)Demand a tribute.booleanmoveUnit(Unit unit, Direction direction)Moves the active unit in a specified direction.private booleanmoveUseMissionary(Unit unit, Direction direction)Move a missionary into a native settlement, following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_MISSIONARY.booleannameNewRegion(Tile tile, Unit unit, Region region, java.lang.String name)The player names a new region.NationSummarynationSummary(Player player)Get the nation summary for a player.voidnationSummaryHandler(Player other, NationSummary ns)Handle a nation summary update.private voidnativeTrade(NativeTrade nt, Constants.TradeAction act, NativeTradeItem nti, StringTemplate prompt)Execute the native trade.voidnativeTradeHandler(NativeTrade.NativeTradeAction action, NativeTrade nt)Cache a native trade update.private booleannewLandName(Unit unit, java.lang.String name)A player names the New World.voidnewLandNameHandler(Unit unit, java.lang.String defaultName)Ask the player to name the new land.private booleannewRegionName(Region region, Tile tile, Unit unit, java.lang.String name)The player names a new region.voidnewRegionNameHandler(Region region, Tile tile, Unit unit, java.lang.String name)Handle new region naming.TradeRoutenewTradeRoute(Player player)Gets a new trade route for a player.voidnewTradeRouteHandler(TradeRoute tr)Handle a new trade route.private booleannewTurn(int turn)Switch to a new turn.voidnewTurnHandler(int turn)Handle the new turn.booleannextActiveUnit()Makes a new unit active.booleannextModelMessage()Displays the nextModelMessage.voidpartialHandler(FreeColGameObject fcgo, java.util.Map<java.lang.String,java.lang.String> fields)Handle partial updates.booleanpayArrears(GoodsType type)Pays the tax arrears on this type of goods.booleanpayForBuilding(Colony colony)Buys the remaining hammers and tools for theBuildingcurrently being built in the givenColony.booleanputOutsideColony(Unit unit)Puts the specified unit outside the colony.private voidreapIgnoredMessages(Turn turn)Reap all ignored message keys that are older than the given turn.voidreconnect()Query whether the user wants to reconnect? Called from ReconnectAction.voidreconnectHandler()Handle a reconnect message.booleanrecruitUnitInEurope(int index)Recruit a unit from a specified index in Europe.voidremoveHandler(java.util.List<FreeColGameObject> objects, FreeColGameObject divert)Remove game objects.booleanrename(Nameable object)Renames aNameable.private booleanrequireOurTurn()Require that it is this client's player's turn.booleansaveAndQuit()Save and quit the game.booleansaveGame()Opens a dialog where the user should specify the filename and saves the game.private booleansaveGame(java.io.File file)Saves the game to the given file.voidscoutSpeakToChiefHandler(Unit unit, IndianSettlement is, java.lang.String result)Display the results of speaking to a chief.booleanselectDestination(Unit unit)Selects a destination for this unit.booleansellGoods(Goods goods)Sells goods in Europe.voidsetAIHandler(Player player, boolean ai)Handle setting the AI state of a player.booleansetBuildQueue(Colony colony, java.util.List<BuildableType> buildQueue)Changes the current construction project of aColony.private booleansetCurrentPlayer(Player player)Set a player to be the new current player.voidsetCurrentPlayerHandler(Player currentPlayer)Handle a current player setting.private booleansetDead()This player has died.voidsetDeadHandler(Player dead)Set a player to be dead.voidsetGameConnected()Informs this controller that a game has been newly loaded.booleansetGoodsLevels(Colony colony, GoodsType goodsType)Sets the export settings of the custom house.booleansetInDebugMode()Sets the debug mode to include the extra menu commands.booleansetStanceHandler(Stance stance, Player first, Player second)Notify the player that the stance between two players has changed.private voidshowColonyPanel(Colony colony, Unit unit)Wrapper for GUI.showColonyPanel.private voidshowColonyPanelWithCarrier(Colony colony, Unit unit)Display the colony panel for a colony, and select the unit that just arrived there if it is a carrier.private voidshowEmigrationDialog(Player player, boolean foy, int n)Wrapper for GUI.showEmigrationDialogprivate voidshowEventPanel(java.lang.String header, java.lang.String imageKey, java.lang.String footer)Wrapper for GUI.showEventPanel.private voidshowInformationPanel(FreeColObject disp, java.lang.String messageId)Wrapper for GUI.showInformationPanel.private voidshowInformationPanel(FreeColObject disp, StringTemplate template)Wrapper for GUI.showInformationPanel.private voidshowNamingDialog(StringTemplate template, java.lang.String defaultName, Unit unit, DialogHandler<java.lang.String> handler)Wrapper for GUI.showNamingDialog.private voidshowNegotiationDialog(Unit unit, Settlement settlement, DiplomaticTrade agreement, StringTemplate comment, Direction direction)Wrapper for GUI.showNegotiationDialog and followup.private voidshowStatusPanel(java.lang.String message)Wrapper for GUI.showStatusPanel, but clear on null.voidsound(java.lang.String soundKey)Play a sound.voidspySettlementHandler(Tile tile)Spy on a settlement.private voidstartIgnoringMessage(java.lang.String key, Turn turn)Start ignoring a kind of message.private voidstopIgnoringMessage(java.lang.String key)Stop ignoring a kind of message.booleantrainUnitInEurope(UnitType unitType)Trains a unit of a specified type in Europe.booleanunload(Unit unit)Unload, including dumping cargo.booleanunloadCargo(Goods goods, boolean dump)Unload cargo.private booleanunloadUnitAtStop(Unit unit, LogBuilder lb)Work out what goods to unload from a unit at a stop, and unload them.private booleanupdateActiveUnit(Tile tile)Makes a new unit active if any, or focus on a tile (useful if the current unit just died).private voidupdateGUI(Tile tile, boolean updateUnit)Update the GUI and the active unit, with a fallback tile.voidupdateHandler(java.util.List<FreeColObject> objects)Handle updates.booleanupdateTradeRoute(TradeRoute route)Updates a trade route.private booleanvictory(java.lang.Boolean quit)The player has won!booleanwaitUnit()Tell a unit to wait.booleanwork(Unit unit, WorkLocation workLocation)Moves aUnitto aWorkLocation.-
Methods inherited from class net.sf.freecol.client.control.FreeColClientHolder
askServer, currentPlayerIsMyPlayer, getClientOptions, getConnectController, getFreeColClient, getFreeColServer, getGame, getGUI, getMap, getMyPlayer, getSpecification, igc, pgc
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
UNIT_LAST_MOVE_DELAY
private static final short UNIT_LAST_MOVE_DELAY
- See Also:
- Constant Field Values
-
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.
-
moveMode
private InGameController.MoveMode moveMode
Current mode for moving 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- TheFreeColClientfor 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- TheTileto start at.direction- TheDirectionto 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- TheTileto start at.direction- TheDirectionto 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- TheRunnableto run.
-
changeView
private void changeView(Unit unit, boolean force)
Wrapper for GUI.changeView.- Parameters:
unit- TheUnitto 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 optionalTileto 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- TheColonyto show.unit- An optionalUnitto 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- TheColonyto display.unit- An optionalUnitto select.
-
error
private void error(StringTemplate template, java.lang.String message)
Wrapper for GUI.showErrorPanel.- Parameters:
template- AStringTemplateto 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- ThePlayerwho 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- AStringTemplateto display.
-
getMissionaryChoice
private void getMissionaryChoice(Unit unit, IndianSettlement is, Direction direction)
Wrapper for GUI.getMissionaryChoice- Parameters:
unit- TheUnitthat will enter the settlement.is- TheIndianSettlementto check.direction- TheDirectionto 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- TheUnitthat 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- TheUnitthat is negotiating.settlement- TheSettlementthat is negotiating.agreement- The proposed agreement.comment- An optionalStringTemplatecontaining a commentary message.direction- An optionalDirectionto 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 newModelMessages withnextModelMessage().- Parameters:
tile- TheTileto 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 fallbackTile.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- TheUnitto assign to.tradeRoute- TheTradeRouteto assign.- Returns:
- True if the assignment succeeds.
-
askClaimTile
private boolean askClaimTile(Player player, Tile tile, FreeColGameObject claimant, int price)
Claim a tile.- Parameters:
player- ThePlayerthat is claiming.tile- TheTileto claim.claimant- TheUnitorColonyclaiming.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- TheUnitto 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- TheUnitto embark.carrier- The carrierUnitto 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- TheEuropewhere the unit appears.slot- The slot to choose, [0..RECRUIT_COUNT].- Returns:
- The new
Unitor 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- ThePlayerthat 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- TheLocationto load from.type- TheGoodsTypeto load.amount- The amount of goods to load.carrier- TheUnitto load onto.- Returns:
- True if the load succeeded.
-
askSetDestination
private boolean askSetDestination(Unit unit, Location destination)
Set a destination for a unit.- Parameters:
unit- TheUnitto direct.destination- The destinationLocation.- 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- TheGoodsTypeto unload.amount- The amount of goods to unload.carrier- TheUnitcarrying 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- TheGameto 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- TheFile.- 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 currentTurn.
-
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- TheTurnvalue 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 currentTurn.- 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 pendingModelMessages.- 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 nextModelMessage. 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- TheUnitto move.messages- An optional list in which to retain any trade routeModelMessages 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- TheUnitto 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- TheUnitto move.direction- TheDirectionto 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- TheUnitto be moved.destination- TheLocationto 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- TheUnitto be moved.europe- TheEuropeto 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- TheUnitto 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- TheUnitto 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 carrierUnitto load onto.embark- A list ofUnits 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- TheUnitnegotiating.direction- The direction of a settlement to negotiate with.dt- The baseDiplomaticTradeagreement 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- TheUnitthat 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- TheUnitthat 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- TheUnitto 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- TheUnitto 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- TheUnitto 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- TheUnitthat 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- TheUnitthat is spying.direction- TheDirectionof 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- TheUnitto 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- TheUnitthat 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- TheUniton the route.messages- An optional list in which to retain anyModelMessages 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- TheUnitto load.lb- ALogBuilderto 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- TheUnitto unload.lb- ALogBuilderto 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- TheColonyto be abandoned.- Returns:
- True if the colony was abandoned.
-
addPlayerHandler
public void addPlayerHandler(java.util.List<Player> players)
Handle an addPlayer message.- Parameters:
players- ThePlayers to add.
-
animateAttackHandler
public void animateAttackHandler(Unit attacker, Unit defender, Tile attackerTile, Tile defenderTile, boolean success)
Animate an attack.- Parameters:
attacker- The attackingUnit.defender- The defendingUnit.attackerTile- TheTilethe attack originates from.defenderTile- TheTilethe 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- TheUnitthat moves.oldTile- TheTilethe move begins at.newTile- TheTilethe move ends at.
-
assignTeacher
public boolean assignTeacher(Unit student, Unit teacher)
Assigns a student to a teacher. Called from UnitLabel- Parameters:
student- The studentUnit.teacher- The teacherUnit.- 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- TheUnitto assign a trade route to.tradeRoute- TheTradeRouteto 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- TheUnitwhich 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- TheUnitto 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- TheUnitacting 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 thisUnit. Called from FortifyAction, SentryAction, TilePopup, UnitLabel- Parameters:
unit- TheUnitstate- 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 thisUnit. Called from ImprovementAction.- Parameters:
unit- TheUnitimprovementType- aTileImprovementTypevalue- Returns:
- True if the improvement was changed.
-
changeWorkType
public boolean changeWorkType(Unit unit, GoodsType workType)
Changes the work type of thisUnit. Called from ColonyPanel.tryWork, UnitLabel- Parameters:
unit- TheUnitworkType- The newGoodsTypeto 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 theowner. Called from TilePopup- Parameters:
unit- TheUnitto 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 ofFoundingFathers to choose from.ff- The chosenFoundingFather(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 ofFoundingFathers to choose from.
-
claimTile
public boolean claimTile(Tile tile, FreeColGameObject claimant)
Claim a tile. Called from ColonyPanel.ASingleTilePanel, UnitLabel and work()- Parameters:
tile- TheTileto claim.claimant- TheUnitorColonyclaiming.- 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- TheUnitto 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- TheUnitto 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- TheUnitto 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- TheColonyto 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- TheTradeRouteto 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- OurFreeColGameObjectthat is negotiating.other- The otherFreeColGameObject.agreement- TheDiplomaticTradeagreement.
-
disbandUnit
public boolean disbandUnit(Unit unit)
Disbands the active unit. Called from DisbandUnitAction.- Parameters:
unit- TheUnitto 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- ThePlayerthat 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- TheUnit.role- TheRoleto 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- AStringTemplateto 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 parentFreeColGameObjectto add to.children- The childFreeColObjects 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- ThePlayermaking contact.other- The nativePlayerbeing contacted.tile- An optionalTileto 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- ThePlayermaking contact.other- The nativePlayerbeing contacted.tile- An optionalTileto 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- TheUnitto move.path- ThePathto 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- ABooleanwhose 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 ofHighScorerecords 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- aModelMessagevalueflag- 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- TheUnitthat is inciting.is- TheIndianSettlementbeing incited.enemy- ThePlayerincited 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 nativeUnitmaking the demand.colony- TheColonydemanded of.type- TheGoodsTypedemanded (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- TheUnitto 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- TheUnitwhich 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- TheGoodswhich are going aboard the carrier.carrier- TheUnitacting 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- ThePlayerthat 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- TheUnitthat is looting.goods- A list ofGoodsto 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- TheUnitthat is looting.goods- A list ofGoodsto 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- TheMonarchActionperformed.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- TheMonarchActionto perform.template- AStringTemplatedescribing 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- TheUnitto be moved.destination- TheLocationto 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- TheUnitto move.direction- TheDirectionin 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- TheTilewithin the region.unit- TheUnitthat has discovered the region.region- TheRegionto 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- ThePlayerto 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- ThePlayerto update.ns- TheNationSummaryfor the other player.
-
nativeTradeHandler
public void nativeTradeHandler(NativeTrade.NativeTradeAction action, NativeTrade nt)
Cache a native trade update.- Parameters:
action- TheNativeTradeActionto handle.nt- TheNativeTradeunderway.
-
nativeTrade
private void nativeTrade(NativeTrade nt, Constants.TradeAction act, NativeTradeItem nti, StringTemplate prompt)
Execute the native trade.- Parameters:
nt- TheNativeTradeunderway.act- TheTradeActionto perform.nti- TheNativeTradeItembeing 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- TheUnitthat 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- TheUnitthat 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- TheTilewithin the region.unit- TheUnitthat has discovered the region.region- TheRegionto 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- TheRegionto name.tile- TheTilethe unit landed at.unit- TheUnitthat 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- ThePlayerto get a new trade route for.- Returns:
- A new
TradeRoute.
-
newTradeRouteHandler
public void newTradeRouteHandler(TradeRoute tr)
Handle a new trade route.- Parameters:
tr- TheTradeRouteto 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- TheFreeColGameObjectto 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 theBuildingcurrently being built in the givenColony. Called from BuildQueuePanel- Parameters:
colony- TheColonywhere 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- TheUnit- 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 ofFreeColGameObjects to remove.divert- An object to divert to when the original disappears.
-
rename
public boolean rename(Nameable object)
Renames aNameable. 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- TheUnitthat was speaking.is- TheIndianSettlementspoken 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- ThePlayerto set.ai- The new AI state.
-
setBuildQueue
public boolean setBuildQueue(Colony colony, java.util.List<BuildableType> buildQueue)
Changes the current construction project of aColony. Called from BuildQueuePanel- Parameters:
colony- TheColonybuildQueue- List ofBuildableType- 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- ThePlayerto 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 currentPlayer.
-
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 deadPlayer.
-
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 changedStance.first- The firstPlayer.second- The secondPlayer.- Returns:
- True if the stance change succeeds.
-
spySettlementHandler
public void spySettlementHandler(Tile tile)
Spy on a settlement.- Parameters:
tile- A special copy of theTilewith 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- TheUnitthat 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- TheGoodsto 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- TheFreeColObjects 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 aUnitto aWorkLocation. Called from ColonyPanel.tryWork, UnitLabel- Parameters:
unit- TheUnit.workLocation- The newWorkLocation.- Returns:
- True if the unit is now working at the new work location.
-
-