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 class
InGameController.MoveMode
Selecting 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 StringTemplate
abortTrade
A template to use as a magic cookie for aborted trades.private static java.util.logging.Logger
logger
private java.util.Map<java.lang.String,java.lang.Integer>
messagesToIgnore
A map of messages to be ignored.private InGameController.MoveMode
moveMode
Current mode for moving units.private static java.util.Comparator<Unit>
tradeRouteUnitComparator
A comparator for ordering trade route units.private java.util.List<ModelMessage>
turnReportMessages
The messages in the last turn report.private static short
UNIT_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 boolean
abandonColony(Colony colony)
Abandon a colony with no units.void
addPlayerHandler(java.util.List<Player> players)
Handle an addPlayer message.void
animateAttackHandler(Unit attacker, Unit defender, Tile attackerTile, Tile defenderTile, boolean success)
Animate an attack.void
animateMoveHandler(Unit unit, Tile oldTile, Tile newTile)
Animate a move.private boolean
askAssignTradeRoute(Unit unit, TradeRoute tradeRoute)
Ask the server to assign a trade route.private boolean
askClaimTile(Player player, Tile tile, FreeColGameObject claimant, int price)
Claim a tile.private boolean
askClearGotoOrders(Unit unit)
Clears the goto orders of the given unit by setting its destination to null.private boolean
askEmbark(Unit unit, Unit carrier)
Embark onto a carrier.private Unit
askEmigrate(Europe europe, int slot)
A unit in Europe emigrates.private boolean
askLoadGoods(Location loc, GoodsType type, int amount, Unit carrier)
Load some goods onto a carrier.private boolean
askSetDestination(Unit unit, Location destination)
Set a destination for a unit.private boolean
askUnloadGoods(GoodsType type, int amount, Unit carrier)
Unload some goods from a carrier.boolean
assignTeacher(Unit student, Unit teacher)
Assigns a student to a teacher.boolean
assignTradeRoute(Unit unit, TradeRoute tradeRoute)
Assigns a trade route to a unit.private void
autoSaveGame()
Creates at least one autosave game file of the currently played game in the autosave directory.boolean
boardShip(Unit unit, Unit carrier)
Boards a specified unit onto a carrier.boolean
buildColony(Unit unit)
Use the active unit to build a colony.boolean
buyGoods(GoodsType type, int amount, Unit carrier)
Buy goods in Europe.boolean
changeState(Unit unit, Unit.UnitState state)
Changes the state of thisUnit
.private void
changeView(Tile tile)
Wrapper for GUI.changeView.private void
changeView(Unit unit, boolean force)
Wrapper for GUI.changeView.boolean
changeWorkImprovementType(Unit unit, TileImprovementType improvementType)
Changes the work type of thisUnit
.boolean
changeWorkType(Unit unit, GoodsType workType)
Changes the work type of thisUnit
.boolean
chat(java.lang.String chat)
Sends a public chat message.void
chatHandler(java.lang.String sender, java.lang.String message, java.awt.Color color, boolean pri)
Chat with another player.boolean
checkCashInTreasureTrain(Unit unit)
Check if a unit is a treasure train, and if it should be cashed in.private boolean
chooseFoundingFather(java.util.List<FoundingFather> ffs, FoundingFather ff)
Choose a founding father from an offered list.void
chooseFoundingFatherHandler(java.util.List<FoundingFather> ffs)
Choose a founding father from an offered list.boolean
claimTile(Tile tile, FreeColGameObject claimant)
Claim a tile.boolean
clearGotoOrders(Unit unit)
Clears the goto orders of the given unit by setting its destination to null.boolean
clearOrders(Unit unit)
Clears the orders of the given unit.boolean
clearSpeciality(Unit unit)
Clear the speciality of a Unit, making it a Free Colonist.void
closeColony(Colony colony, boolean abandon)
Special handling when we close a colony panel.void
closeHandler(java.lang.String panel)
Close any open GUI menus.private boolean
continueIgnoreMessage(java.lang.String key, Turn turn)
See if messages with a given key were ignored last turn.boolean
declareIndependence()
Declares independence for the home country.boolean
deleteTradeRoute(TradeRoute tradeRoute)
Delete a trade route.void
diplomacyHandler(FreeColGameObject our, FreeColGameObject other, DiplomaticTrade agreement)
Handle a diplomatic offer.boolean
disbandUnit(Unit unit)
Disbands the active unit.private void
displayChat(java.lang.String sender, java.lang.String message, java.awt.Color color, boolean pri)
Wrapper for GUI.displayChat.private boolean
displayModelMessages(boolean allMessages, boolean endOfTurn)
Displays pendingModelMessage
s.void
displayTurnReportMessages()
Displays the messages in the current turn report.private boolean
doEndTurn(boolean showDialog)
End the turn.private boolean
doExecuteGotoOrders()
Do the goto orders operation.private void
emigrate(Player player, int slot, int n, boolean foY)
Emigrate a unit from Europe.private void
emigration(Player player, int n, boolean fountainOfYouth)
Select all the units to emigrate from Europe.boolean
endTurn(boolean showDialog)
End the turn command.boolean
equipUnitForRole(Unit unit, Role role, int roleCount)
Change the role-equipment a unit has.private void
error(StringTemplate template, java.lang.String message)
Wrapper for GUI.showErrorPanel.void
errorHandler(StringTemplate template, java.lang.String message)
Handle an error.boolean
executeGotoOrders()
Execute goto orders command.void
featureChangeHandler(FreeColGameObject parent, java.util.List<FreeColObject> children, boolean add)
Handle feature changes.private boolean
firstContact(Player player, Player other, Tile tile, boolean result)
A player makes first contact with a native player.void
firstContactHandler(Player player, Player other, Tile tile, int n)
A player makes first contact with a native player.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.void
fountainOfYouthHandler(int n)
Handle a fountain of youth event.void
gameEndedHandler(java.lang.String score)
The player has won, show the high scores and victory dialog.private void
getMissionaryChoice(Unit unit, IndianSettlement is, Direction direction)
Wrapper for GUI.getMissionaryChoiceprivate StringTemplate
getNationAt(Tile tile, Direction direction)
Convenience function to find the nation controlling an adjacent settlement.private java.lang.String
getSaveGameString(Game game)
Get the trunk of the save game string.private Settlement
getSettlementAt(Tile tile, Direction direction)
Convenience function to find an adjacent settlement.boolean
goToTile(Unit unit, PathNode path)
Go to a tile.boolean
highScore(java.lang.Boolean high)
Display the high scores.void
highScoresHandler(java.lang.String key, java.util.List<HighScore> scores)
Display the high scores.boolean
ignoreMessage(ModelMessage message, boolean flag)
Ignore this ModelMessage from now on until it is not generated in a turn.void
inciteHandler(Unit unit, IndianSettlement is, Player enemy, int gold)
Handle an incite response.void
indianDemandHandler(Unit unit, Colony colony, GoodsType type, int amount)
Handle a native demand at a colony.private void
invokeLater(java.lang.Runnable runnable)
Defer execution to the event thread.private boolean
joinColony(Unit unit)
Join the colony at a unit's current location.boolean
leaveShip(Unit unit)
Leave a ship.boolean
loadCargo(Goods goods, Unit carrier)
Loads a cargo onto a carrier.void
loadGame()
Opens a dialog where the user should specify the filename and loads the game.private boolean
loadUnitAtStop(Unit unit, LogBuilder lb)
Work out what goods to load onto a unit at a stop, and load them.void
logoutHandler(Player player, Game.LogoutReason reason)
Log out the current player.private boolean
lootCargo(Unit unit, java.util.List<Goods> goods, java.lang.String defenderId)
Loot some cargo.void
lootCargoHandler(Unit unit, java.util.List<Goods> goods, java.lang.String loserId)
Loot some cargo.boolean
monarchAction(Monarch.MonarchAction action, boolean accept)
Accept or reject a monarch action.void
monarchActionHandler(Monarch.MonarchAction action, StringTemplate template, java.lang.String monarchKey)
Do a monarch interaction.private boolean
moveAttack(Unit unit, Direction direction)
Confirm attack or demand a tribute from a native settlement, following an attacking move.private boolean
moveAttackSettlement(Unit unit, Direction direction)
Confirm attack or demand a tribute from a settlement, following an attacking move.private boolean
moveAutoload(Unit carrier, java.util.List<Unit> embark)
Primitive to handle autoloading of a list of units onto a carrier.private boolean
moveAwayFromEurope(Unit unit, Location destination)
Move a unit from off map to an on map location.private boolean
moveDiplomacy(Unit unit, Direction direction, DiplomaticTrade dt)
Initiates diplomacy with a foreign power.boolean
moveDirection(Unit unit, Direction direction, boolean interactive)
Move a unit in a given direction.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.private boolean
moveEmbark(Unit unit, Direction direction)
Embarks the specified unit onto a carrier in a specified direction following a move of MoveType.EMBARK.private boolean
moveExplore(Unit unit, Direction direction)
Confirm exploration of a lost city rumour, following a move of MoveType.EXPLORE_LOST_CITY_RUMOUR.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.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.private boolean
movePath(Unit unit, PathNode path)
Follow a path.private boolean
moveScoutColony(Unit unit, Direction direction)
Move to a foreign colony and either attack, negotiate with the foreign power or spy on them.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.private boolean
moveSpy(Unit unit, Direction direction)
Spy on a foreign colony.private boolean
moveTile(Unit unit, Direction direction)
Move a unit in a specified direction on the map, following a move of MoveType.MOVE.boolean
moveTo(Unit unit, Location destination)
Moves the specified unit somewhere that requires crossing the high seas.private boolean
moveToDestination(Unit unit, java.util.List<ModelMessage> messages)
Moves the given unit towards its destination/s if possible.private boolean
moveTowardEurope(Unit unit, Europe europe)
Move a unit from on map towards Europe.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.private boolean
moveTribute(Unit unit, int amount, Direction direction)
Demand a tribute.boolean
moveUnit(Unit unit, Direction direction)
Moves the active unit in a specified direction.private boolean
moveUseMissionary(Unit unit, Direction direction)
Move a missionary into a native settlement, following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_MISSIONARY.boolean
nameNewRegion(Tile tile, Unit unit, Region region, java.lang.String name)
The player names a new region.NationSummary
nationSummary(Player player)
Get the nation summary for a player.void
nationSummaryHandler(Player other, NationSummary ns)
Handle a nation summary update.private void
nativeTrade(NativeTrade nt, Constants.TradeAction act, NativeTradeItem nti, StringTemplate prompt)
Execute the native trade.void
nativeTradeHandler(NativeTrade.NativeTradeAction action, NativeTrade nt)
Cache a native trade update.private boolean
newLandName(Unit unit, java.lang.String name)
A player names the New World.void
newLandNameHandler(Unit unit, java.lang.String defaultName)
Ask the player to name the new land.private boolean
newRegionName(Region region, Tile tile, Unit unit, java.lang.String name)
The player names a new region.void
newRegionNameHandler(Region region, Tile tile, Unit unit, java.lang.String name)
Handle new region naming.TradeRoute
newTradeRoute(Player player)
Gets a new trade route for a player.void
newTradeRouteHandler(TradeRoute tr)
Handle a new trade route.private boolean
newTurn(int turn)
Switch to a new turn.void
newTurnHandler(int turn)
Handle the new turn.boolean
nextActiveUnit()
Makes a new unit active.boolean
nextModelMessage()
Displays the nextModelMessage
.void
partialHandler(FreeColGameObject fcgo, java.util.Map<java.lang.String,java.lang.String> fields)
Handle partial updates.boolean
payArrears(GoodsType type)
Pays the tax arrears on this type of goods.boolean
payForBuilding(Colony colony)
Buys the remaining hammers and tools for theBuilding
currently being built in the givenColony
.boolean
putOutsideColony(Unit unit)
Puts the specified unit outside the colony.private void
reapIgnoredMessages(Turn turn)
Reap all ignored message keys that are older than the given turn.void
reconnect()
Query whether the user wants to reconnect? Called from ReconnectAction.void
reconnectHandler()
Handle a reconnect message.boolean
recruitUnitInEurope(int index)
Recruit a unit from a specified index in Europe.void
removeHandler(java.util.List<FreeColGameObject> objects, FreeColGameObject divert)
Remove game objects.boolean
rename(Nameable object)
Renames aNameable
.private boolean
requireOurTurn()
Require that it is this client's player's turn.boolean
saveAndQuit()
Save and quit the game.boolean
saveGame()
Opens a dialog where the user should specify the filename and saves the game.private boolean
saveGame(java.io.File file)
Saves the game to the given file.void
scoutSpeakToChiefHandler(Unit unit, IndianSettlement is, java.lang.String result)
Display the results of speaking to a chief.boolean
selectDestination(Unit unit)
Selects a destination for this unit.boolean
sellGoods(Goods goods)
Sells goods in Europe.void
setAIHandler(Player player, boolean ai)
Handle setting the AI state of a player.boolean
setBuildQueue(Colony colony, java.util.List<BuildableType> buildQueue)
Changes the current construction project of aColony
.private boolean
setCurrentPlayer(Player player)
Set a player to be the new current player.void
setCurrentPlayerHandler(Player currentPlayer)
Handle a current player setting.private boolean
setDead()
This player has died.void
setDeadHandler(Player dead)
Set a player to be dead.void
setGameConnected()
Informs this controller that a game has been newly loaded.boolean
setGoodsLevels(Colony colony, GoodsType goodsType)
Sets the export settings of the custom house.boolean
setInDebugMode()
Sets the debug mode to include the extra menu commands.boolean
setStanceHandler(Stance stance, Player first, Player second)
Notify the player that the stance between two players has changed.private void
showColonyPanel(Colony colony, Unit unit)
Wrapper for GUI.showColonyPanel.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.private void
showEmigrationDialog(Player player, boolean foy, int n)
Wrapper for GUI.showEmigrationDialogprivate void
showEventPanel(java.lang.String header, java.lang.String imageKey, java.lang.String footer)
Wrapper for GUI.showEventPanel.private void
showInformationPanel(FreeColObject disp, java.lang.String messageId)
Wrapper for GUI.showInformationPanel.private void
showInformationPanel(FreeColObject disp, StringTemplate template)
Wrapper for GUI.showInformationPanel.private void
showNamingDialog(StringTemplate template, java.lang.String defaultName, Unit unit, DialogHandler<java.lang.String> handler)
Wrapper for GUI.showNamingDialog.private void
showNegotiationDialog(Unit unit, Settlement settlement, DiplomaticTrade agreement, StringTemplate comment, Direction direction)
Wrapper for GUI.showNegotiationDialog and followup.private void
showStatusPanel(java.lang.String message)
Wrapper for GUI.showStatusPanel, but clear on null.void
sound(java.lang.String soundKey)
Play a sound.void
spySettlementHandler(Tile tile)
Spy on a settlement.private void
startIgnoringMessage(java.lang.String key, Turn turn)
Start ignoring a kind of message.private void
stopIgnoringMessage(java.lang.String key)
Stop ignoring a kind of message.boolean
trainUnitInEurope(UnitType unitType)
Trains a unit of a specified type in Europe.boolean
unload(Unit unit)
Unload, including dumping cargo.boolean
unloadCargo(Goods goods, boolean dump)
Unload cargo.private boolean
unloadUnitAtStop(Unit unit, LogBuilder lb)
Work out what goods to unload from a unit at a stop, and unload them.private boolean
updateActiveUnit(Tile tile)
Makes a new unit active if any, or focus on a tile (useful if the current unit just died).private void
updateGUI(Tile tile, boolean updateUnit)
Update the GUI and the active unit, with a fallback tile.void
updateHandler(java.util.List<FreeColObject> objects)
Handle updates.boolean
updateTradeRoute(TradeRoute route)
Updates a trade route.private boolean
victory(java.lang.Boolean quit)
The player has won!boolean
waitUnit()
Tell a unit to wait.boolean
work(Unit unit, WorkLocation workLocation)
Moves aUnit
to 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
- TheFreeColClient
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
- TheTile
to start at.direction
- TheDirection
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
- TheTile
to start at.direction
- TheDirection
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
- TheRunnable
to run.
-
changeView
private void changeView(Unit unit, boolean force)
Wrapper for GUI.changeView.- Parameters:
unit
- TheUnit
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 optionalTile
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
- TheColony
to show.unit
- An optionalUnit
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
- TheColony
to display.unit
- An optionalUnit
to select.
-
error
private void error(StringTemplate template, java.lang.String message)
Wrapper for GUI.showErrorPanel.- Parameters:
template
- AStringTemplate
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
- ThePlayer
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
- AStringTemplate
to display.
-
getMissionaryChoice
private void getMissionaryChoice(Unit unit, IndianSettlement is, Direction direction)
Wrapper for GUI.getMissionaryChoice- Parameters:
unit
- TheUnit
that will enter the settlement.is
- TheIndianSettlement
to check.direction
- TheDirection
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
- TheUnit
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
- TheUnit
that is negotiating.settlement
- TheSettlement
that is negotiating.agreement
- The proposed agreement.comment
- An optionalStringTemplate
containing a commentary message.direction
- An optionalDirection
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 newModelMessage
s withnextModelMessage()
.- Parameters:
tile
- TheTile
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 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
- TheUnit
to assign to.tradeRoute
- TheTradeRoute
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
- ThePlayer
that is claiming.tile
- TheTile
to claim.claimant
- TheUnit
orColony
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
- TheUnit
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
- TheUnit
to embark.carrier
- The carrierUnit
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
- TheEurope
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
- ThePlayer
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
- TheLocation
to load from.type
- TheGoodsType
to load.amount
- The amount of goods to load.carrier
- TheUnit
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
- TheUnit
to 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
- TheGoodsType
to unload.amount
- The amount of goods to unload.carrier
- TheUnit
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
- TheGame
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
- 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
- TheTurn
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 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 pendingModelMessage
s.- 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
- TheUnit
to move.messages
- An optional list in which to retain any trade routeModelMessage
s 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
- TheUnit
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
- TheUnit
to move.direction
- TheDirection
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
- TheUnit
to be moved.destination
- TheLocation
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
- TheUnit
to be moved.europe
- TheEurope
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
- TheUnit
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
- TheUnit
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 carrierUnit
to load onto.embark
- A list ofUnit
s 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
- TheUnit
negotiating.direction
- The direction of a settlement to negotiate with.dt
- The baseDiplomaticTrade
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
- TheUnit
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
- TheUnit
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
- TheUnit
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
- TheUnit
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
- TheUnit
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
- TheUnit
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
- TheUnit
that is spying.direction
- TheDirection
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
- TheUnit
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
- TheUnit
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
- TheUnit
on the route.messages
- An optional list in which to retain anyModelMessage
s 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
- TheUnit
to load.lb
- ALogBuilder
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
- TheUnit
to unload.lb
- ALogBuilder
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
- TheColony
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
- ThePlayer
s 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
- TheTile
the attack originates from.defenderTile
- TheTile
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
- TheUnit
that moves.oldTile
- TheTile
the move begins at.newTile
- TheTile
the 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
- TheUnit
to assign a trade route to.tradeRoute
- TheTradeRoute
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
- TheUnit
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
- TheUnit
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
- TheUnit
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 thisUnit
. Called from FortifyAction, SentryAction, TilePopup, UnitLabel- Parameters:
unit
- TheUnit
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 thisUnit
. Called from ImprovementAction.- Parameters:
unit
- TheUnit
improvementType
- aTileImprovementType
value- 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
- TheUnit
workType
- The newGoodsType
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 theowner
. Called from TilePopup- Parameters:
unit
- TheUnit
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 ofFoundingFather
s 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 ofFoundingFather
s to choose from.
-
claimTile
public boolean claimTile(Tile tile, FreeColGameObject claimant)
Claim a tile. Called from ColonyPanel.ASingleTilePanel, UnitLabel and work()- Parameters:
tile
- TheTile
to claim.claimant
- TheUnit
orColony
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
- TheUnit
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
- TheUnit
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
- TheUnit
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
- TheColony
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
- TheTradeRoute
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
- OurFreeColGameObject
that is negotiating.other
- The otherFreeColGameObject
.agreement
- TheDiplomaticTrade
agreement.
-
disbandUnit
public boolean disbandUnit(Unit unit)
Disbands the active unit. Called from DisbandUnitAction.- Parameters:
unit
- TheUnit
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
- ThePlayer
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
- TheUnit
.role
- TheRole
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
- AStringTemplate
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 parentFreeColGameObject
to add to.children
- The childFreeColObject
s 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
- ThePlayer
making contact.other
- The nativePlayer
being contacted.tile
- An optionalTile
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
- ThePlayer
making contact.other
- The nativePlayer
being contacted.tile
- An optionalTile
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
- TheUnit
to move.path
- ThePath
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
- ABoolean
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 ofHighScore
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
- aModelMessage
valueflag
- 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
- TheUnit
that is inciting.is
- TheIndianSettlement
being incited.enemy
- ThePlayer
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 nativeUnit
making the demand.colony
- TheColony
demanded of.type
- TheGoodsType
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
- TheUnit
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
- TheUnit
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
- TheGoods
which are going aboard the carrier.carrier
- TheUnit
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
- ThePlayer
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
- TheUnit
that is looting.goods
- A list ofGoods
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
- TheUnit
that is looting.goods
- A list ofGoods
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
- TheMonarchAction
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
- TheMonarchAction
to perform.template
- AStringTemplate
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
- TheUnit
to be moved.destination
- TheLocation
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
- TheUnit
to move.direction
- TheDirection
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
- TheTile
within the region.unit
- TheUnit
that has discovered the region.region
- TheRegion
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
- ThePlayer
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
- ThePlayer
to update.ns
- TheNationSummary
for the other player.
-
nativeTradeHandler
public void nativeTradeHandler(NativeTrade.NativeTradeAction action, NativeTrade nt)
Cache a native trade update.- Parameters:
action
- TheNativeTradeAction
to handle.nt
- TheNativeTrade
underway.
-
nativeTrade
private void nativeTrade(NativeTrade nt, Constants.TradeAction act, NativeTradeItem nti, StringTemplate prompt)
Execute the native trade.- Parameters:
nt
- TheNativeTrade
underway.act
- TheTradeAction
to perform.nti
- TheNativeTradeItem
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
- TheUnit
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
- TheUnit
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
- TheTile
within the region.unit
- TheUnit
that has discovered the region.region
- TheRegion
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
- TheRegion
to name.tile
- TheTile
the unit landed at.unit
- TheUnit
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
- ThePlayer
to get a new trade route for.- Returns:
- A new
TradeRoute
.
-
newTradeRouteHandler
public void newTradeRouteHandler(TradeRoute tr)
Handle a new trade route.- Parameters:
tr
- TheTradeRoute
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
- TheFreeColGameObject
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 theBuilding
currently being built in the givenColony
. Called from BuildQueuePanel- Parameters:
colony
- TheColony
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
- 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 ofFreeColGameObject
s 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
- TheUnit
that was speaking.is
- TheIndianSettlement
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
- ThePlayer
to 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
- TheColony
buildQueue
- 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
- ThePlayer
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 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 theTile
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
- TheUnit
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
- TheGoods
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
- TheFreeColObject
s 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 aUnit
to 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.
-
-