Package net.sf.freecol.server.model
Class DiplomacySession
- java.lang.Object
-
- net.sf.freecol.server.model.Session
-
- net.sf.freecol.server.model.TimedSession
-
- net.sf.freecol.server.model.DiplomacySession
-
public class DiplomacySession extends TimedSession
A type of session to handle diplomacy. Diplomacy may involve human players, so it *must* be a TimedSession.
-
-
Field Summary
Fields Modifier and Type Field Description private DiplomaticTradeagreementThe agreement under consideration.private static java.util.logging.Loggerloggerprivate UnitotherUnitThe other player's unit (only non-null in first contact cases).private SettlementsettlementThe other player's settlement.private UnitunitThe initiating unit.
-
Constructor Summary
Constructors Constructor Description DiplomacySession(Unit unit, Settlement settlement, long timeout)Start a new diplomacy session with our unit and another player settlement.DiplomacySession(Unit unit, Unit otherUnit, long timeout)Start a new diplomacy session with our unit and another player unit.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancomplete(boolean result)Complete this task with the given result.booleancomplete(boolean result, ChangeSet cs)Explicit completion of the session with a given result.booleancomplete(ChangeSet cs)All transaction types must implement a completion action.booleancompleteFirstContact(ChangeSet cs)Complete first contact session.private voidcompleteInternal(boolean result, ChangeSet cs)Primitive level to finishing the session with the given result.private static DiplomacySessionfindContactSession(Player p1, Player p2)Find any contact session already underway between the given players.static DiplomacySessionfindContactSession(Unit unit, Settlement settlement)Find any contact session already underway between the owners of a given unit and settlement.static DiplomacySessionfindContactSession(Unit unit, Unit other)Find any contact session already underway between the owners of the given units.DiplomaticTradegetAgreement()Get the session agreement.private ServerGamegetGame()Get the game this session is in.DiplomacyMessagegetMessage(Player destination)Utility to create a message using the current session parameters and trade agreement, given a desired destination player.private ServerPlayergetOtherPlayer()Get the owner of the other settlement or unit.ServerPlayergetOtherPlayer(ServerPlayer serverPlayer)Utility to find the other player in this session from a given one.UnitgetOtherUnit()Get the other unit if any.private ServerPlayergetOwner()Get the owner of the initiating unit.SettlementgetSettlement()Get the settlement if any.UnitgetUnit()Get the initiating unit.booleanisCompatible(FreeColGameObject fcgo1, FreeColGameObject fcgo2)Was this session started by the given objects?static java.lang.StringmakeDiplomacySessionKey(Ownable o1, Ownable o2)Make a diplomacy session key for the given ownables.voidsetAgreement(DiplomaticTrade agreement)Set the session agreement.-
Methods inherited from class net.sf.freecol.server.model.TimedSession
cancel
-
Methods inherited from class net.sf.freecol.server.model.Session
clearAll, completeAll, findSession, getKey, lookup, lookup, lookup, makeSessionKey, makeSessionKey, register
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
agreement
private DiplomaticTrade agreement
The agreement under consideration.
-
unit
private final Unit unit
The initiating unit.
-
settlement
private final Settlement settlement
The other player's settlement.
-
otherUnit
private final Unit otherUnit
The other player's unit (only non-null in first contact cases).
-
-
Constructor Detail
-
DiplomacySession
public DiplomacySession(Unit unit, Settlement settlement, long timeout)
Start a new diplomacy session with our unit and another player settlement.- Parameters:
unit- TheUnitthat is initiating diplomacy.settlement- TheSettlementthat is contacted.timeout- The amount of time to wait for a response.
-
DiplomacySession
public DiplomacySession(Unit unit, Unit otherUnit, long timeout)
Start a new diplomacy session with our unit and another player unit.- Parameters:
unit- TheUnitthat is initiating diplomacy.otherUnit- The otherUnitthat is contacted.timeout- The amount of time to wait for a response.
-
-
Method Detail
-
makeDiplomacySessionKey
public static java.lang.String makeDiplomacySessionKey(Ownable o1, Ownable o2)
Make a diplomacy session key for the given ownables.- Parameters:
o1- The firstOwnable.o2- The secondOwnable.- Returns:
- A diplomacy session key.
-
getGame
private ServerGame getGame()
Get the game this session is in.- Returns:
- The enclosing
ServerGame.
-
getAgreement
public DiplomaticTrade getAgreement()
Get the session agreement.- Returns:
- The
DiplomaticTradeunder negotiation.
-
setAgreement
public void setAgreement(DiplomaticTrade agreement)
Set the session agreement.- Parameters:
agreement- The newDiplomaticTradeto negotiate.
-
getUnit
public Unit getUnit()
Get the initiating unit.- Returns:
- The
Unitthat started the session.
-
getSettlement
public Settlement getSettlement()
Get the settlement if any.- Returns:
- The
Settlementthat is negotiating.
-
getOtherUnit
public Unit getOtherUnit()
Get the other unit if any.- Returns:
- The other
Unitthat is negotiating.
-
getOwner
private ServerPlayer getOwner()
Get the owner of the initiating unit.- Returns:
- The
ServerPlayerthat owns the initiating unit.
-
getOtherPlayer
private ServerPlayer getOtherPlayer()
Get the owner of the other settlement or unit.- Returns:
- The
ServerPlayerthat owns the other settlement or unit.
-
getOtherPlayer
public ServerPlayer getOtherPlayer(ServerPlayer serverPlayer)
Utility to find the other player in this session from a given one.- Parameters:
serverPlayer- TheServerPlayer*not* to find.- Returns:
- The other
ServerPlayer.
-
getMessage
public DiplomacyMessage getMessage(Player destination)
Utility to create a message using the current session parameters and trade agreement, given a desired destination player.- Parameters:
destination- ThePlayerto send the message to.- Returns:
- A new
DiplomacyMessagefor the destination player.
-
isCompatible
public boolean isCompatible(FreeColGameObject fcgo1, FreeColGameObject fcgo2)
Was this session started by the given objects?- Parameters:
fcgo1- The firstFreeColGameObject.fcgo2- The secondFreeColGameObject.- Returns:
- True if the objects started this session.
-
findContactSession
public static DiplomacySession findContactSession(Unit unit, Unit other)
Find any contact session already underway between the owners of the given units.- Parameters:
unit- The firstUnit.other- The secondUnit.- Returns:
- Any
DiplomacySessionfound.
-
findContactSession
public static DiplomacySession findContactSession(Unit unit, Settlement settlement)
Find any contact session already underway between the owners of a given unit and settlement.- Parameters:
unit- TheUnit.settlement- TheSettlement.- Returns:
- Any
DiplomacySessionfound.
-
findContactSession
private static DiplomacySession findContactSession(Player p1, Player p2)
Find any contact session already underway between the given players.- Parameters:
p1- The firstPlayer.p2- The secondPlayer.- Returns:
- Any
DiplomacySessionfound.
-
completeInternal
private void completeInternal(boolean result, ChangeSet cs)Primitive level to finishing the session with the given result.- Parameters:
result- The result of the session.cs- AChangeSetto update.
-
completeFirstContact
public boolean completeFirstContact(ChangeSet cs)
Complete first contact session. Just do nothing but superclass action as we do not want the offer accept/reject messages, and the unit already has zero moves.- Parameters:
cs- AChangeSetto update.- Returns:
- Whether the session was already complete.
-
complete
public boolean complete(boolean result, ChangeSet cs)Explicit completion of the session with a given result. Called from the controller when the player returns a definite response.- Parameters:
result- Whether to accept or reject the demand.cs- AChangeSetto update.- Returns:
- Whether the session was already complete.
-
complete
protected boolean complete(boolean result)
Complete this task with the given result. By default this will be called (with value == false) when the timer expires.- Specified by:
completein classTimedSession- Parameters:
result- The result to complete the session with.- Returns:
- The result of the session.
-
complete
public boolean complete(ChangeSet cs)
All transaction types must implement a completion action. This is called by the controller at the end of turn to complete any sessions that have not yet completed, or if the controller gets the required response to complete the session.- Overrides:
completein classTimedSession- Parameters:
cs- AChangeSetto update with changes that occur when completing this session.- Returns:
- True if the session was already complete.
-
-