rails.game
Class OperatingRound

java.lang.Object
  extended by rails.game.Round
      extended by rails.game.OperatingRound
All Implemented Interfaces:
java.util.Observer, RoundI
Direct Known Subclasses:
OperatingRound_1825, OperatingRound_1835, OperatingRound_1856, OperatingRound_1880, OperatingRound_1889, OperatingRound_18AL, OperatingRound_18EU, OperatingRound_18TN

public class OperatingRound
extends Round
implements java.util.Observer

Implements a basic Operating Round.

A new instance must be created for each new Operating Round. At the end of a round, the current instance should be discarded.


Field Summary
protected  boolean actionPossible
           
protected  java.util.List<PublicCompanyI> companiesOperatedThisRound
           
protected  java.util.List<LayBaseToken> currentNormalTokenLays
           
protected  java.util.List<SpecialPropertyI> currentSpecialProperties
           
protected  java.util.List<LayBaseToken> currentSpecialTokenLays
           
protected  boolean doneAllowed
           
protected  java.util.Map<Player,java.util.List<PublicCompanyI>> excessTrainCompanies
          A List per player with owned companies that have excess trains
protected  java.util.Map<PublicCompanyI,java.lang.Integer> loansThisRound
           
protected  boolean noMapMode
           
protected  ArrayListState<PublicCompanyI> operatingCompanies
           
protected  GenericState<PublicCompanyI> operatingCompany
           
protected  PossibleAction savedAction
           
protected  PossibleAction selectedAction
           
static int SPLIT_ROUND_DOWN
           
protected  EnumState<GameDef.OrStep> stepObject
           
protected  GameDef.OrStep[] steps
           
protected  java.lang.String thisOrNumber
           
protected  HashMapState<java.lang.String,java.lang.Integer> tileLaysPerColour
           
protected  TrainManager trainManager
           
protected  java.util.List<TrainTypeI> trainsBoughtThisTurn
           
 
Fields inherited from class rails.game.Round
autopasses, bank, canRequestTurn, companyManager, gameManager, guiHints, hasRequestedTurn, ipo, log, mapManager, moveStack, playerManager, pool, possibleActions, scrapHeap, stockMarket, unavailable, wasInterrupted
 
Constructor Summary
OperatingRound(GameManagerI gameManager)
          Constructor with no parameters, call the super Class (Round's) Constructor with no parameters
 
Method Summary
protected  boolean areTileLaysPossible()
           
 boolean buyBonusToken(BuyBonusToken action)
           
 boolean buyPrivate(BuyPrivate action)
           
 boolean buyTrain(BuyTrain action)
           
protected  int calculateLoanAmount(int numberOfLoans)
           
protected  boolean canBuyTrainNow()
          Can the company buy a train now? Normally only calls isBelowTrainLimit() to get the result.
protected  int checkForDeductions(SetDividend action)
          Default version, to be overridden if need be
 void checkForeignSales()
           
 boolean checkForExcessTrains()
           
protected  boolean checkNormalTileLay(TileI tile, boolean update)
           
protected  java.util.Map<CashHolder,java.lang.Integer> countSharesPerRecipient()
           
 boolean discardTrain(DiscardTrain action)
           
 boolean done()
          The current Company is done operating.
 boolean equals(RoundI round)
           
protected  boolean executeClosePrivate(ClosePrivate action)
           
protected  int executeDeductions(SetDividend action)
          Default version, to be overridden if need be
protected  boolean executeOperatingCost(OperatingCost action)
           
protected  void executeRepayLoans(RepayLoans action)
           
protected  void executeSetRevenueAndDividend(SetDividend action)
           
protected  void executeTakeLoans(TakeLoans action)
           
protected  void finishOR()
           
protected  void finishTurn()
           
protected  boolean finishTurnSpecials()
          Stub, may be overridden in subclasses Return value: TRUE = normal turn end; FALSE = return immediately from finishTurn().
protected  boolean gameSpecificNextStep(GameDef.OrStep step)
          Stub, can be overridden in subclasses to check for extra steps
protected  CashHolder getBeneficiary(PublicCertificateI cert)
          Who gets the per-share revenue?
 java.lang.String getHelp()
           
protected  java.util.List<LayTile> getNormalTileLays(boolean display)
           
 java.util.List<PublicCompanyI> getOperatingCompanies()
           
 PublicCompanyI getOperatingCompany()
          Get the public company that has the turn to operate.
 int getOperatingCompanyIndex()
           
protected  int getPrivateMaximumPrice(PrivateCompanyI privComp)
           
protected  int getPrivateMinimumPrice(PrivateCompanyI privComp)
           
 java.lang.String getRoundName()
           
 java.util.List<SpecialPropertyI> getSpecialProperties()
           
protected
<T extends SpecialPropertyI>
java.util.List<T>
getSpecialProperties(java.lang.Class<T> clazz)
           
protected  java.util.List<LayTile> getSpecialTileLays(boolean display)
          Create a List of allowed special tile lays (see LayTile class).
 GameDef.OrStep getStep()
          Get the current operating round step (i.e.
protected  void initNormalTileLays()
          Create a List of allowed normal tile lays (see LayTile class).
protected  void initTurn()
           
protected  boolean isBelowTrainLimit()
          Returns whether or not the company is allowed to buy a train, considering its train limit.
protected  boolean isPrivateSellingAllowed()
           
protected  boolean isTileLayAllowed(PublicCompanyI company, MapHex hex, int orientation)
          Reports if a tile lay is allowed by a certain company on a certain hex
protected  boolean isTokenLayAllowed(PublicCompanyI company, MapHex hex, int station)
          Reports if a token lay is allowed by a certain company on a certain hex and city
 boolean layBaseToken(LayBaseToken action)
           
 boolean layBonusToken(LayBonusToken action)
           
 boolean layTile(LayTile action)
           
protected  boolean maySellPrivate(Player player)
           
protected  void newPhaseChecks()
          Stub
protected  void nextStep()
          Internal method: change the OR state to the next step.
protected  void nextStep(GameDef.OrStep step)
          Take the next step after a given one (see nextStep())
 void payLoanInterest()
           
 void payout(int amount)
          Distribute the dividend amongst the shareholders.
protected  void prepareNoMapActions()
           
protected  void prepareRevenueAndDividendAction()
           
protected  void prepareStep()
          This method is only called at the start of each step (unlike updateStatus(), which is called after each user action)
protected  void privatesPayOut()
           
 boolean process(PossibleAction action)
           
 boolean processGameSpecificAction(PossibleAction action)
          Stub, to be overridden in game-specific subclasses.
protected  void reachDestination(PublicCompanyI company)
          Stub for applying any follow-up actions when a company reaches it destinations.
 boolean reachDestinations(ReachDestinations action)
           
protected  void registerNormalTileLay(TileI tile)
           
protected  boolean repayLoans(RepayLoans action)
           
 void resume()
          Generic stub to resume an interrupted round.
protected  void setBonusTokenLays()
          TODO Should be merged with setSpecialTokenLays() in the future.
 void setBuyableTrains()
          Get a list of buyable trains for the currently operating company.
protected  void setDestinationActions()
          This is currently a stub, as it is unclear if there is a common rule for setting destination reaching options.
protected  void setGameSpecificPossibleActions()
          Stub, can be overridden by subclasses
protected  boolean setNextOperatingCompany(boolean initial)
           
protected  void setNormalTokenLays()
           
protected  void setOperatingCompany(PublicCompanyI company)
           
 boolean setPossibleActions()
          To be called after each change, to re-establish the currently allowed actions.
 boolean setRevenueAndDividend(SetDividend action)
           
protected  void setSpecialTokenLays()
          Create a List of allowed special token lays (see LayToken class).
protected  void setStep(GameDef.OrStep step)
          Bypass normal order of operations and explicitly set round step.
protected  void setTrainsToDiscard()
           
 void skip()
           
 void splitRevenue(int amount)
          Split a dividend.
 void start()
           
protected  boolean takeLoans(TakeLoans action)
           
 java.lang.String toString()
           
 void update(java.util.Observable observable, java.lang.Object object)
          Update the status if the step has changed by an Undo or Redo
protected  void updateAllowedTileColours(java.lang.String colour, int oldAllowedNumber)
           
protected  boolean validateNormalTileLay(TileI tile)
           
protected  java.lang.String validateRepayLoans(RepayLoans action)
           
protected  java.lang.String validateSetRevenueAndDividend(SetDividend action)
           
protected  java.lang.String validateTakeLoans(TakeLoans action)
           
 void withhold(int amount)
          Withhold a given amount of revenue (and store it).
 
Methods inherited from class rails.game.Round
canCompanyOperateThisRound, canRequestTurn, certCountsAsSold, checkFlotation, exchangeTokens, finishRound, floatCompany, getAutopasses, getCurrentPhase, getCurrentPlayer, getCurrentPlayerIndex, getGameManager, getGameOption, getGameParameter, getGameParameterAsBoolean, getGameParameterAsInt, getNumberOfActivePlayers, getNumberOfPlayers, getPlayers, getRoundTypeForUI, getSoldPercentage, hasAutopassed, pay, pay, requestTurn, setAutopass, setCanRequestTurn, setCurrentPlayer, setCurrentPlayerIndex, setOperatingCompanies, setOperatingCompanies, transferCertificate, transferCertificates, wasInterrupted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

stepObject

protected EnumState<GameDef.OrStep> stepObject

actionPossible

protected boolean actionPossible

noMapMode

protected boolean noMapMode

companiesOperatedThisRound

protected java.util.List<PublicCompanyI> companiesOperatedThisRound

operatingCompanies

protected ArrayListState<PublicCompanyI> operatingCompanies

operatingCompany

protected GenericState<PublicCompanyI> operatingCompany

currentSpecialProperties

protected java.util.List<SpecialPropertyI> currentSpecialProperties

tileLaysPerColour

protected HashMapState<java.lang.String,java.lang.Integer> tileLaysPerColour

currentNormalTokenLays

protected java.util.List<LayBaseToken> currentNormalTokenLays

currentSpecialTokenLays

protected java.util.List<LayBaseToken> currentSpecialTokenLays

excessTrainCompanies

protected java.util.Map<Player,java.util.List<PublicCompanyI>> excessTrainCompanies
A List per player with owned companies that have excess trains


trainsBoughtThisTurn

protected java.util.List<TrainTypeI> trainsBoughtThisTurn

loansThisRound

protected java.util.Map<PublicCompanyI,java.lang.Integer> loansThisRound

thisOrNumber

protected java.lang.String thisOrNumber

selectedAction

protected PossibleAction selectedAction

savedAction

protected PossibleAction savedAction

SPLIT_ROUND_DOWN

public static final int SPLIT_ROUND_DOWN
See Also:
Constant Field Values

steps

protected GameDef.OrStep[] steps

doneAllowed

protected boolean doneAllowed

trainManager

protected TrainManager trainManager
Constructor Detail

OperatingRound

public OperatingRound(GameManagerI gameManager)
Constructor with no parameters, call the super Class (Round's) Constructor with no parameters

Method Detail

start

public void start()

privatesPayOut

protected void privatesPayOut()

process

public boolean process(PossibleAction action)
Specified by:
process in interface RoundI
Overrides:
process in class Round

processGameSpecificAction

public boolean processGameSpecificAction(PossibleAction action)
Stub, to be overridden in game-specific subclasses.


layTile

public boolean layTile(LayTile action)

validateNormalTileLay

protected boolean validateNormalTileLay(TileI tile)

registerNormalTileLay

protected void registerNormalTileLay(TileI tile)

checkNormalTileLay

protected boolean checkNormalTileLay(TileI tile,
                                     boolean update)

updateAllowedTileColours

protected void updateAllowedTileColours(java.lang.String colour,
                                        int oldAllowedNumber)

layBaseToken

public boolean layBaseToken(LayBaseToken action)

layBonusToken

public boolean layBonusToken(LayBonusToken action)

buyBonusToken

public boolean buyBonusToken(BuyBonusToken action)

setRevenueAndDividend

public boolean setRevenueAndDividend(SetDividend action)

validateSetRevenueAndDividend

protected java.lang.String validateSetRevenueAndDividend(SetDividend action)

executeSetRevenueAndDividend

protected void executeSetRevenueAndDividend(SetDividend action)

payout

public void payout(int amount)
Distribute the dividend amongst the shareholders.

Parameters:
amount -

countSharesPerRecipient

protected java.util.Map<CashHolder,java.lang.Integer> countSharesPerRecipient()

getBeneficiary

protected CashHolder getBeneficiary(PublicCertificateI cert)
Who gets the per-share revenue?


withhold

public void withhold(int amount)
Withhold a given amount of revenue (and store it).

Parameters:
The - revenue amount.

splitRevenue

public void splitRevenue(int amount)
Split a dividend. TODO Optional rounding down the payout

Parameters:
amount -

checkForDeductions

protected int checkForDeductions(SetDividend action)
Default version, to be overridden if need be


executeDeductions

protected int executeDeductions(SetDividend action)
Default version, to be overridden if need be


executeOperatingCost

protected boolean executeOperatingCost(OperatingCost action)

executeClosePrivate

protected boolean executeClosePrivate(ClosePrivate action)

nextStep

protected void nextStep()
Internal method: change the OR state to the next step. If the currently Operating Company is done, notify this.

Parameters:
company - The current company.

nextStep

protected void nextStep(GameDef.OrStep step)
Take the next step after a given one (see nextStep())


gameSpecificNextStep

protected boolean gameSpecificNextStep(GameDef.OrStep step)
Stub, can be overridden in subclasses to check for extra steps


initTurn

protected void initTurn()

prepareStep

protected void prepareStep()
This method is only called at the start of each step (unlike updateStatus(), which is called after each user action)


getSpecialProperties

protected <T extends SpecialPropertyI> java.util.List<T> getSpecialProperties(java.lang.Class<T> clazz)

initNormalTileLays

protected void initNormalTileLays()
Create a List of allowed normal tile lays (see LayTile class). This method should be called only once per company turn in an OR: at the start of the tile laying step.


getNormalTileLays

protected java.util.List<LayTile> getNormalTileLays(boolean display)

getSpecialTileLays

protected java.util.List<LayTile> getSpecialTileLays(boolean display)
Create a List of allowed special tile lays (see LayTile class). This method should be called before each user action in the tile laying step.


areTileLaysPossible

protected boolean areTileLaysPossible()

setNormalTokenLays

protected void setNormalTokenLays()

setSpecialTokenLays

protected void setSpecialTokenLays()
Create a List of allowed special token lays (see LayToken class). This method should be called before each user action in the base token laying step. TODO: Token preparation is practically identical to Tile preparation, perhaps the two can be merged to one generic procedure.


setBonusTokenLays

protected void setBonusTokenLays()
TODO Should be merged with setSpecialTokenLays() in the future. Assumptions: 1. Bonus tokens can be laid anytime during the OR. 2. Bonus token laying is always extra. TODO This assumptions will be made configurable conditions.


setGameSpecificPossibleActions

protected void setGameSpecificPossibleActions()
Stub, can be overridden by subclasses


getSpecialProperties

public java.util.List<SpecialPropertyI> getSpecialProperties()
Overrides:
getSpecialProperties in class Round

skip

public void skip()

done

public boolean done()
The current Company is done operating.

Parameters:
company - Name of the company that finished operating.
Returns:
False if an error is found.

finishTurn

protected void finishTurn()

finishTurnSpecials

protected boolean finishTurnSpecials()
Stub, may be overridden in subclasses Return value: TRUE = normal turn end; FALSE = return immediately from finishTurn().


setNextOperatingCompany

protected boolean setNextOperatingCompany(boolean initial)

setOperatingCompany

protected void setOperatingCompany(PublicCompanyI company)

finishOR

protected void finishOR()

buyTrain

public boolean buyTrain(BuyTrain action)

checkForExcessTrains

public boolean checkForExcessTrains()

newPhaseChecks

protected void newPhaseChecks()
Stub


resume

public void resume()
Description copied from class: Round
Generic stub to resume an interrupted round. Only valid if implemented in a subclass.

Specified by:
resume in interface RoundI
Overrides:
resume in class Round

discardTrain

public boolean discardTrain(DiscardTrain action)

buyPrivate

public boolean buyPrivate(BuyPrivate action)

reachDestinations

public boolean reachDestinations(ReachDestinations action)

takeLoans

protected boolean takeLoans(TakeLoans action)

validateTakeLoans

protected java.lang.String validateTakeLoans(TakeLoans action)

executeTakeLoans

protected void executeTakeLoans(TakeLoans action)

reachDestination

protected void reachDestination(PublicCompanyI company)
Stub for applying any follow-up actions when a company reaches it destinations. Default version: no actions.

Parameters:
company -

repayLoans

protected boolean repayLoans(RepayLoans action)

validateRepayLoans

protected java.lang.String validateRepayLoans(RepayLoans action)

executeRepayLoans

protected void executeRepayLoans(RepayLoans action)

calculateLoanAmount

protected int calculateLoanAmount(int numberOfLoans)

getOperatingCompany

public PublicCompanyI getOperatingCompany()
Get the public company that has the turn to operate.

Returns:
The currently operating company object.

getOperatingCompanies

public java.util.List<PublicCompanyI> getOperatingCompanies()

getStep

public GameDef.OrStep getStep()
Get the current operating round step (i.e. the next action).

Returns:
The number that defines the next action.

setStep

protected void setStep(GameDef.OrStep step)
Bypass normal order of operations and explicitly set round step. This should only be done for specific rails.game exceptions, such as forced train purchases.

Parameters:
step -

getOperatingCompanyIndex

public int getOperatingCompanyIndex()

setPossibleActions

public boolean setPossibleActions()
To be called after each change, to re-establish the currently allowed actions. (new method, intended to absorb code from several other methods).

Specified by:
setPossibleActions in interface RoundI
Overrides:
setPossibleActions in class Round

isPrivateSellingAllowed

protected boolean isPrivateSellingAllowed()

getPrivateMinimumPrice

protected int getPrivateMinimumPrice(PrivateCompanyI privComp)

getPrivateMaximumPrice

protected int getPrivateMaximumPrice(PrivateCompanyI privComp)

maySellPrivate

protected boolean maySellPrivate(Player player)

prepareRevenueAndDividendAction

protected void prepareRevenueAndDividendAction()

prepareNoMapActions

protected void prepareNoMapActions()

setBuyableTrains

public void setBuyableTrains()
Get a list of buyable trains for the currently operating company. Omit trains that the company has no money for. If there is no cash to buy any train from the Bank, prepare for emergency train buying.


isBelowTrainLimit

protected boolean isBelowTrainLimit()
Returns whether or not the company is allowed to buy a train, considering its train limit.

Returns:

isTileLayAllowed

protected boolean isTileLayAllowed(PublicCompanyI company,
                                   MapHex hex,
                                   int orientation)
Reports if a tile lay is allowed by a certain company on a certain hex

This method can be used both in retricting possible actions and in validating submitted actions.

Currently, only a few standard checks are included. This method can be extended to perform other generic checks, such as if a route exists, and possibly in subclasses for game-specific checks.

Parameters:
company - The company laying a tile.
hex - The hex on which a tile is laid.
orientation - The orientation in which the tile is laid (-1 is any).

isTokenLayAllowed

protected boolean isTokenLayAllowed(PublicCompanyI company,
                                    MapHex hex,
                                    int station)
Reports if a token lay is allowed by a certain company on a certain hex and city

This method can be used both in retricting possible actions and in validating submitted actions.

Currently, only a few standard checks are included. This method can be extended to perform other generic checks, such as if a route exists, and possibly in subclasses for game-specific checks.

Parameters:
company - The company laying a tile.
hex - The hex on which a tile is laid.
station - The number of the station/city on which the token is to be laid (0 if any or immaterial).

canBuyTrainNow

protected boolean canBuyTrainNow()
Can the company buy a train now? Normally only calls isBelowTrainLimit() to get the result. May be overridden if other considerations apply (such as having a Pullmann in 18EU).

Returns:

setTrainsToDiscard

protected void setTrainsToDiscard()

setDestinationActions

protected void setDestinationActions()
This is currently a stub, as it is unclear if there is a common rule for setting destination reaching options. See OperatingRound_1856 for a first implementation of such rules.


payLoanInterest

public void payLoanInterest()

checkForeignSales

public void checkForeignSales()

getHelp

public java.lang.String getHelp()
Specified by:
getHelp in interface RoundI
Overrides:
getHelp in class Round

update

public void update(java.util.Observable observable,
                   java.lang.Object object)
Update the status if the step has changed by an Undo or Redo

Specified by:
update in interface java.util.Observer

toString

public java.lang.String toString()
Overrides:
toString in class Round

equals

public boolean equals(RoundI round)

getRoundName

public java.lang.String getRoundName()
Specified by:
getRoundName in interface RoundI
Overrides:
getRoundName in class Round