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 DiplomaticTrade
agreement
The agreement under consideration.private static java.util.logging.Logger
logger
private Unit
otherUnit
The other player's unit (only non-null in first contact cases).private Settlement
settlement
The other player's settlement.private Unit
unit
The 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 boolean
complete(boolean result)
Complete this task with the given result.boolean
complete(boolean result, ChangeSet cs)
Explicit completion of the session with a given result.boolean
complete(ChangeSet cs)
All transaction types must implement a completion action.boolean
completeFirstContact(ChangeSet cs)
Complete first contact session.private void
completeInternal(boolean result, ChangeSet cs)
Primitive level to finishing the session with the given result.private static DiplomacySession
findContactSession(Player p1, Player p2)
Find any contact session already underway between the given players.static DiplomacySession
findContactSession(Unit unit, Settlement settlement)
Find any contact session already underway between the owners of a given unit and settlement.static DiplomacySession
findContactSession(Unit unit, Unit other)
Find any contact session already underway between the owners of the given units.DiplomaticTrade
getAgreement()
Get the session agreement.private ServerGame
getGame()
Get the game this session is in.DiplomacyMessage
getMessage(Player destination)
Utility to create a message using the current session parameters and trade agreement, given a desired destination player.private ServerPlayer
getOtherPlayer()
Get the owner of the other settlement or unit.ServerPlayer
getOtherPlayer(ServerPlayer serverPlayer)
Utility to find the other player in this session from a given one.Unit
getOtherUnit()
Get the other unit if any.private ServerPlayer
getOwner()
Get the owner of the initiating unit.Settlement
getSettlement()
Get the settlement if any.Unit
getUnit()
Get the initiating unit.boolean
isCompatible(FreeColGameObject fcgo1, FreeColGameObject fcgo2)
Was this session started by the given objects?static java.lang.String
makeDiplomacySessionKey(Ownable o1, Ownable o2)
Make a diplomacy session key for the given ownables.void
setAgreement(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
- TheUnit
that is initiating diplomacy.settlement
- TheSettlement
that 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
- TheUnit
that is initiating diplomacy.otherUnit
- The otherUnit
that 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
DiplomaticTrade
under negotiation.
-
setAgreement
public void setAgreement(DiplomaticTrade agreement)
Set the session agreement.- Parameters:
agreement
- The newDiplomaticTrade
to negotiate.
-
getUnit
public Unit getUnit()
Get the initiating unit.- Returns:
- The
Unit
that started the session.
-
getSettlement
public Settlement getSettlement()
Get the settlement if any.- Returns:
- The
Settlement
that is negotiating.
-
getOtherUnit
public Unit getOtherUnit()
Get the other unit if any.- Returns:
- The other
Unit
that is negotiating.
-
getOwner
private ServerPlayer getOwner()
Get the owner of the initiating unit.- Returns:
- The
ServerPlayer
that owns the initiating unit.
-
getOtherPlayer
private ServerPlayer getOtherPlayer()
Get the owner of the other settlement or unit.- Returns:
- The
ServerPlayer
that 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
- ThePlayer
to send the message to.- Returns:
- A new
DiplomacyMessage
for 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
DiplomacySession
found.
-
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
DiplomacySession
found.
-
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
DiplomacySession
found.
-
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
- AChangeSet
to 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
- AChangeSet
to 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
- AChangeSet
to 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:
complete
in 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:
complete
in classTimedSession
- Parameters:
cs
- AChangeSet
to update with changes that occur when completing this session.- Returns:
- True if the session was already complete.
-
-