rails.game
Class PublicCompany

java.lang.Object
  extended by rails.game.Company
      extended by rails.game.PublicCompany
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Company>, CashHolder, CompanyI, ConfigurableComponentI, MoveableHolder, PublicCompanyI, TokenHolder
Direct Known Subclasses:
Investor_1880, PublicCompany_1825, PublicCompany_1856, PublicCompany_1880, PublicCompany_CGR

public class PublicCompany
extends Company
implements PublicCompanyI

This class provides an implementation of a (perhaps only basic) public company. Public companies encompass all 18xx company-like entities that lay tracks and run trains.

Ownership of companies will always be performed by holding certificates. Some minor company types may have only one certificate, but this will still be the form in which ownership is expressed.

Company shares may or may not have a price on the stock market.


Field Summary
protected  java.util.List<TokenI> allBaseTokens
           
protected  Bank bank
           
static java.lang.String BASE_COST_DISTANCE
           
static java.lang.String BASE_COST_SEQUENCE
           
protected  int[] baseTokenLayCost
          An array of base token laying costs, per successive token
protected  java.lang.String baseTokenLayCostMethod
           
protected  int baseTokensBuyCost
           
protected  BaseTokensModel baseTokensModel
           
protected  java.awt.Color bgColour
          Background colour of the company tokens
protected  java.lang.String bgHexColour
          Hexadecimal representation (RRGGBB) of the background colour.
protected  java.util.List<Bonus> bonuses
          Acquires Bonus objects
protected  BonusModel bonusValue
          Total bonus tokens amount
protected  BooleanState buyable
          Are company shares buyable (i.e.
protected  boolean canBeRestarted
          Can a company be restarted once it is closed?
protected  boolean canBuyPrivates
           
protected  boolean canBuyStock
           
protected  boolean canClose
          Can the company price token go down to a "Close" square? 1856 CGR cannot.
protected  boolean canHoldOwnShares
           
protected  BooleanState canSharePriceVary
           
protected  boolean canUseSpecialProperties
           
protected  int capitalisation
           
protected  java.util.ArrayList<PublicCertificateI> certificates
          The certificates of this company (minimum 1)
(package private)  boolean certsAreInitiallyAvailable
          Are the certificates available from the first SR?
protected  MoneyModel currentLoanValue
           
protected  IntegerState currentNumberOfLoans
           
protected  PriceModel currentPrice
          Current share price, represented by a stock market location object
protected static int DEFAULT_SHARE_UNIT
           
protected  MapHex destinationHex
           
protected  java.lang.String destinationHexName
          Destination hex *
protected  java.util.Map<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Integer>> extraTileLays
          A map per tile colour.
protected  IntegerState extraTiles
          Number of tiles laid.
protected  java.awt.Color fgColour
          Foreground (i.e.
protected  java.lang.String fgHexColour
          Hexadecimal representation (RRGGBB) of the foreground colour.
protected  int fixedPrice
          Fixed price (for a 1835-style minor)
protected  int floatPerc
          At what percentage sold does the company float
protected  java.util.List<TokenI> freeBaseTokens
           
protected  GameManagerI gameManager
           
protected  BooleanState hasFloated
          Is the company operational ("has it floated")?
protected  BooleanState hasOperated
          Has the company already operated?
protected  boolean hasParPrice
          Does the company have a par price?
protected  BooleanState hasReachedDestination
           
protected  BooleanState hasStarted
          Has the company started?
protected  boolean hasStockPrice
          Does the company have a stock price (minors often don't)
protected  boolean homeAllCitiesBlocked
           
protected  int homeBaseTokensLayTime
           
protected  int homeCityNumber
           
protected  java.util.List<MapHex> homeHexes
           
protected  java.lang.String homeHexNames
          Home hex & city * Two home hexes is supported, but only if:
1.
protected  BooleanState inGameState
          In-game state.
protected  int initialTrainCost
           
protected  boolean initialTrainTradeable
           
protected  java.lang.String initialTrainType
          Initial train at floating time
protected  boolean ipoPaysOut
           
protected  java.util.List<TokenI> laidBaseTokens
           
protected  MoneyModel lastRevenue
          Most recent revenue earned.
protected  StringState lastRevenueAllocation
          Most recent payout decision.
protected  int loanInterestPct
           
protected  float lowerPrivatePriceFactor
          Minimum price for buying privates, to be multiplied by the original price
protected  MapManager mapManager
           
protected  int maxLoansPerRound
           
protected  int maxNumberOfLoans
           
protected  int maxPercOfOwnShares
           
protected  boolean mayTradeShares
           
protected  boolean mustHaveOperatedToTradeShares
           
protected  boolean mustOwnATrain
          Must the company own a train
protected  boolean mustTradeTrainsAtFixedPrice
           
protected  int numberOfBaseTokens
           
protected static int numberOfPublicCompanies
           
protected  PriceModel parPrice
          Initial (par) share price, represented by a stock market location object
protected  boolean payoutMustExceedPriceToMove
          Must payout exceed stock price to move token right?
protected  boolean poolPaysOut
           
protected  PresidentModel presidentModel
          PresidentModel
protected  MoneyModel privatesCostThisTurn
           
protected  PrivateCompanyI privateToCloseOnFirstTrain
           
protected  java.lang.String privateToCloseOnFirstTrainName
          Private to close if first train is bought
protected  int publicNumber
          Sequence number in the array of public companies - may not be useful
protected  boolean sharePriceUpOnFloating
          Share price movement on floating (1851: up)
protected  IntegerState shareUnit
          What percentage of ownership constitutes "one share"
protected  int shareUnitsForSharePrice
          What number of share units relates to the share price (normally 1, but 2 for 1835 Prussian)
protected  boolean splitAllowed
           
protected  boolean splitAlways
          Is the revenue always split (typical for non-share minors)
protected static int START_OF_FIRST_OR
           
protected  java.lang.String startSpace
           
protected  StockMarketI stockMarket
           
protected  MoneyModel tilesCostThisTurn
           
protected  StringState tilesLaidThisTurn
           
protected static java.lang.String[] tokenLayTimeNames
           
protected  MoneyModel tokensCostThisTurn
           
protected  StringState tokensLaidThisTurn
           
protected  int[] trainLimit
          Train limit per phase (index)
protected  MoneyModel trainsCostThisTurn
           
protected  CashModel treasury
          Company treasury, holding cash
protected  boolean treasuryPaysOut
           
protected  java.util.Map<java.lang.String,IntegerState> turnsWithExtraTileLays
          Copy of turnsWithExtraTileLaysInit, per company
protected  java.util.Map<java.lang.String,java.lang.Integer> turnsWithExtraTileLaysInit
          A map per tile colour, holding the number of turns that the tile lay number applies.
protected  float upperPrivatePriceFactor
          Maximum price for buying privates, to be multiplied by the original price
protected  int valuePerLoan
           
protected static int WHEN_FLOATED
           
protected static int WHEN_STARTED
           
 
Fields inherited from class rails.game.Company
alias, certLimitCount, closedObject, companyNumber, infoText, log, longName, name, parentInfoText, portfolio, specialProperties, type, value
 
Fields inherited from interface rails.game.PublicCompanyI
CAPITALISE_FULL, CAPITALISE_INCREMENTAL, CAPITALISE_WHEN_BOUGHT
 
Fields inherited from interface rails.game.CompanyI
COMPANY_ELEMENT_ID, COMPANY_NAME_TAG, COMPANY_TYPE_TAG
 
Constructor Summary
PublicCompany()
          The constructor.
 
Method Summary
 boolean addBonus(Bonus bonus)
           
 void addCash(int amount)
          Add a given amount to the company treasury.
 void addCertificate(PublicCertificateI certificate)
          Add a certificate to the end of this company's list of certificates.
 void addLoans(int number)
           
 boolean addObject(Moveable object, int[] position)
          Add an object to its list at a certain position.
 boolean addToken(TokenI token, int position)
          Add a base token to the company charter.
 void buyPrivate(PrivateCompanyI privateCompany, Portfolio from, int price)
           
 void buyTrain(TrainI train, int price)
          Must be called in stead of Portfolio.buyTrain if side-effects can occur.
 boolean canBuyPrivates()
           
 boolean canBuyStock()
           
 boolean canClose()
           
 boolean canHoldOwnShares()
           
 boolean canLoan()
           
 boolean canRunTrains()
           
 boolean canSharePriceVary()
           
 boolean canUseSpecialProperties()
           
 void checkPresidency()
          A generic presidency check.
 void checkPresidencyOnBuy(Player buyer)
          Check if the presidency has changed for a buying player.
 void checkPresidencyOnSale(Player seller)
          Check if the presidency has changed for a selling player.
 java.lang.Object clone()
           
 void configureFromXML(Tag tag)
          To configure all public companies from the <PublicCompany> XML element
 void finishConfiguration(GameManagerI gameManager)
          Final initialisation, after all XML has been processed.
 int getBaseTokenLayCost(MapHex hex)
          Calculate the cost of laying a token, given the hex where the token is laid.
 int[] getBaseTokenLayCosts()
          Return all possible token lay costs to be incurred for the company's next token lay.
 int getBaseTokensBuyCost()
           
 BaseTokensModel getBaseTokensModel()
           
 java.awt.Color getBgColour()
          Return the company token background colour.
 java.util.List<Bonus> getBonuses()
           
 BonusModel getBonusTokensModel()
           
 int getCapitalisation()
           
 int getCash()
          Get the current company treasury.
 ModelObject getCashModel()
           
 java.util.List<PublicCertificateI> getCertificates()
          Get a list of this company's certificates.
 int getCurrentLoanValue()
           
 int getCurrentNumberOfLoans()
           
 PriceModel getCurrentPriceModel()
           
 StockSpaceI getCurrentSpace()
          Get the current company share price.
 int getCurrentTrainLimit()
           
 MapHex getDestinationHex()
           
 java.lang.String getExtraShareMarks()
          Extra codes to be added to the president's indicator in the Game Status window.
 java.awt.Color getFgColour()
          Return the company token foreground colour.
 int getFixedPrice()
           
 int getFloatPercentage()
          Get the percentage of shares that must be sold to float the company.
 java.lang.String getFormattedCash()
           
 BaseToken getFreeToken()
           
 int getGameEndPrice()
          Return the price per share at game end.
 java.lang.String getHexBgColour()
          Return the company token background colour.
 java.lang.String getHexFgColour()
          Return the company token foreground colour.
 int getHomeCityNumber()
           
 java.util.List<MapHex> getHomeHexes()
          Return the company's Home hexes (usually one).
 ModelObject getInGameModel()
           
 int getIPOPrice()
           
 ModelObject getIsClosedModel()
           
 int getLastRevenue()
          Get the last revenue earned by this company.
 ModelObject getLastRevenueAllocationModel()
           
 java.lang.String getlastRevenueAllocationText()
           
 ModelObject getLastRevenueModel()
           
 int[] getListIndex(Moveable object)
           
 int getLoanInterestPct()
           
 MoneyModel getLoanValueModel()
           
 int getMarketPrice()
           
 int getMaxLoansPerRound()
           
 int getMaxNumberOfLoans()
           
 int getNumberOfBaseTokens()
           
 int getNumberOfFreeBaseTokens()
           
 int getNumberOfLaidBaseTokens()
           
 int getNumberOfShares()
           
 int getNumberOfTileLays(java.lang.String tileColour)
           
 int getNumberOfTrains()
           
 PriceModel getParPriceModel()
           
 Player getPresident()
          Get the company President.
 PresidentModel getPresidentModel()
           
 PublicCertificateI getPresidentsShare()
           
 ModelObject getPrivatesSpentThisTurnModel()
           
 int getPublicNumber()
           
 int getShareUnit()
          Get the unit of share.
 int getShareUnitsForSharePrice()
           
 StockSpaceI getStartSpace()
          Get the company par (initial) price.
 ModelObject getTilesCostThisTurnModel()
           
 ModelObject getTilesLaidThisTurnModel()
           
 java.util.List<TokenI> getTokens()
           
 ModelObject getTokensCostThisTurnModel()
           
 ModelObject getTokensLaidThisTurnModel()
           
 int getTrainLimit(int phaseIndex)
           
 ModelObject getTrainsSpentThisTurnModel()
           
 int getValuePerLoan()
           
 boolean hasDestination()
           
 boolean hasFloated()
          Has the company already floated?
 boolean hasLaidHomeBaseTokens()
           
 boolean hasOperated()
          Has the company already operated?
 boolean hasParPrice()
           
 boolean hasReachedDestination()
           
 boolean hasStarted()
           
 boolean hasStockPrice()
          Is company present on the Stock Market?
 boolean hasTokens()
          Do we have any tokens?
 void init(java.lang.String name, CompanyTypeI type)
          Initialisation, to be called directly after instantiation (cloning)
 void initTurn()
          Reset turn objects
 boolean isAvailable()
           
 boolean isBuyable()
           
 boolean isHomeBlockedForAllCities()
           
 boolean isSoldOut()
          Is the company completely sold out? This method should return true only if the share price should move up at the end of a stock round.
 boolean isSplitAllowed()
           
 boolean isSplitAlways()
           
 void layBaseToken(MapHex hex, int cost)
           
 void layBaseTokenInNoMapMode(int cost)
           
 boolean layHomeBaseTokens()
           
 void layTile(MapHex hex, TileI tile, int orientation, int cost)
           
 void layTileInNoMapMode(int cost)
           
 boolean mayBuyTrainType(TrainI train)
          Stub that allows exclusions such as that 1856 CGR may not buy a 4
 boolean mayTradeShares()
           
 boolean mustHaveOperatedToTradeShares()
           
 boolean mustOwnATrain()
           
 boolean mustTradeTrainsAtFixedPrice()
           
 void nameCertificates()
          Backlink the certificates to this company, and give each one a type name.
 void payout(int amount)
          Determine if the price token must be moved after a dividend payout.
 boolean paysOutToTreasury(PublicCertificateI cert)
           
protected  void reinitialise()
          Reinitialise a company, i.e.
 boolean removeBonus(Bonus bonus)
           
 boolean removeBonus(java.lang.String name)
           
 boolean removeObject(Moveable object)
           
 boolean removeToken(TokenI token)
          Remove a base token from the company charter.
 void setBuyable(boolean buyable)
          Make company shares buyable.
 void setCapitalisation(int capitalisation)
           
 void setCertificates(java.util.List<PublicCertificateI> list)
          Assign a predefined list of certificates to this company.
 void setClosed()
          Close this company.
 void setCurrentSpace(StockSpaceI price)
          Set a new company price.
 void setFloated()
          Float the company, put its initial cash in the treasury.
 void setHomeCityNumber(int number)
           
 void setHomeHex(MapHex homeHex)
          Set a non-fixed company home hex.
 void setIndex(int index)
           
 void setLastRevenue(int i)
          Store the last revenue earned by this company.
 void setLastRevenueAllocation(int allocation)
          Last revenue allocation (payout, split, withhold)
 void setOperated()
           
 void setParSpace(StockSpaceI space)
          Set the company par price.
 void setReachedDestination(boolean value)
           
 int sharesOwnedByPlayers()
           
 void start()
          Start a company.
 void start(int price)
           
 void start(StockSpaceI startSpace)
          Start the company.
 java.lang.String toString()
           
 void transferAssetsFrom(PublicCompanyI otherCompany)
           
 void updatePlayersWorth()
           
 void withhold(int amount)
          Determine if the price token must be moved after a withheld dividend.
 
Methods inherited from class rails.game.Company
addToken, compareTo, equals, getAlias, getCertLimitCount, getCompanyNumber, getHolder, getInfoText, getLongName, getName, getNumber, getPortfolio, getSpecialProperties, getType, getTypeName, getValue, hasSpecialProperties, isClosed, joinNamesWithDelimiter, setCertLimitCount, setValue
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface rails.game.CompanyI
equals, getAlias, getCertLimitCount, getCompanyNumber, getInfoText, getLongName, getName, getPortfolio, getSpecialProperties, getType, getTypeName, getValue, hasSpecialProperties, isClosed, setCertLimitCount, setValue
 
Methods inherited from interface rails.game.CashHolder
getName
 
Methods inherited from interface rails.game.TokenHolder
getName
 

Field Detail

DEFAULT_SHARE_UNIT

protected static final int DEFAULT_SHARE_UNIT
See Also:
Constant Field Values

numberOfPublicCompanies

protected static int numberOfPublicCompanies

WHEN_STARTED

protected static final int WHEN_STARTED
See Also:
Constant Field Values

WHEN_FLOATED

protected static final int WHEN_FLOATED
See Also:
Constant Field Values

START_OF_FIRST_OR

protected static final int START_OF_FIRST_OR
See Also:
Constant Field Values

BASE_COST_SEQUENCE

public static final java.lang.String BASE_COST_SEQUENCE
See Also:
Constant Field Values

BASE_COST_DISTANCE

public static final java.lang.String BASE_COST_DISTANCE
See Also:
Constant Field Values

tokenLayTimeNames

protected static final java.lang.String[] tokenLayTimeNames

homeBaseTokensLayTime

protected int homeBaseTokensLayTime

fgColour

protected java.awt.Color fgColour
Foreground (i.e. text) colour of the company tokens (if pictures are not used)


fgHexColour

protected java.lang.String fgHexColour
Hexadecimal representation (RRGGBB) of the foreground colour.


bgColour

protected java.awt.Color bgColour
Background colour of the company tokens


bgHexColour

protected java.lang.String bgHexColour
Hexadecimal representation (RRGGBB) of the background colour.


homeHexNames

protected java.lang.String homeHexNames
Home hex & city * Two home hexes is supported, but only if:
1. The locations are fixed (i.e. configured by XML), and
2. Any station (city) numbers are equal for the two home stations. There is no provision yet for two home hexes having different tile station numbers.


homeHexes

protected java.util.List<MapHex> homeHexes

homeCityNumber

protected int homeCityNumber

homeAllCitiesBlocked

protected boolean homeAllCitiesBlocked

destinationHexName

protected java.lang.String destinationHexName
Destination hex *


destinationHex

protected MapHex destinationHex

hasReachedDestination

protected BooleanState hasReachedDestination

publicNumber

protected int publicNumber
Sequence number in the array of public companies - may not be useful


allBaseTokens

protected java.util.List<TokenI> allBaseTokens

freeBaseTokens

protected java.util.List<TokenI> freeBaseTokens

laidBaseTokens

protected java.util.List<TokenI> laidBaseTokens

numberOfBaseTokens

protected int numberOfBaseTokens

baseTokensBuyCost

protected int baseTokensBuyCost

baseTokenLayCost

protected int[] baseTokenLayCost
An array of base token laying costs, per successive token


baseTokenLayCostMethod

protected java.lang.String baseTokenLayCostMethod

baseTokensModel

protected BaseTokensModel baseTokensModel

parPrice

protected PriceModel parPrice
Initial (par) share price, represented by a stock market location object


currentPrice

protected PriceModel currentPrice
Current share price, represented by a stock market location object


treasury

protected CashModel treasury
Company treasury, holding cash


presidentModel

protected PresidentModel presidentModel
PresidentModel


hasStarted

protected BooleanState hasStarted
Has the company started?


bonusValue

protected BonusModel bonusValue
Total bonus tokens amount


bonuses

protected java.util.List<Bonus> bonuses
Acquires Bonus objects


lastRevenue

protected MoneyModel lastRevenue
Most recent revenue earned.


lastRevenueAllocation

protected StringState lastRevenueAllocation
Most recent payout decision.


hasFloated

protected BooleanState hasFloated
Is the company operational ("has it floated")?


hasOperated

protected BooleanState hasOperated
Has the company already operated?


buyable

protected BooleanState buyable
Are company shares buyable (i.e. before started)?


inGameState

protected BooleanState inGameState
In-game state.

Will only be set false if the company is closed and cannot ever be reopened. By default it will be set false if a company is closed.


extraTileLays

protected java.util.Map<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Integer>> extraTileLays
A map per tile colour. Each entry contains a map per phase, of which each value is an Integer defining the number of allowed tile lays. Only numbers deviating from 1 need be specified, the default is always 1.


turnsWithExtraTileLaysInit

protected java.util.Map<java.lang.String,java.lang.Integer> turnsWithExtraTileLaysInit
A map per tile colour, holding the number of turns that the tile lay number applies. The default number is always 1.


turnsWithExtraTileLays

protected java.util.Map<java.lang.String,IntegerState> turnsWithExtraTileLays
Copy of turnsWithExtraTileLaysInit, per company


extraTiles

protected IntegerState extraTiles
Number of tiles laid. Only used where more tiles can be laid in the company's first OR turn.


privatesCostThisTurn

protected MoneyModel privatesCostThisTurn

tilesLaidThisTurn

protected StringState tilesLaidThisTurn

tilesCostThisTurn

protected MoneyModel tilesCostThisTurn

tokensLaidThisTurn

protected StringState tokensLaidThisTurn

tokensCostThisTurn

protected MoneyModel tokensCostThisTurn

trainsCostThisTurn

protected MoneyModel trainsCostThisTurn

canBuyStock

protected boolean canBuyStock

canBuyPrivates

protected boolean canBuyPrivates

canUseSpecialProperties

protected boolean canUseSpecialProperties

canBeRestarted

protected boolean canBeRestarted
Can a company be restarted once it is closed?


lowerPrivatePriceFactor

protected float lowerPrivatePriceFactor
Minimum price for buying privates, to be multiplied by the original price


upperPrivatePriceFactor

protected float upperPrivatePriceFactor
Maximum price for buying privates, to be multiplied by the original price


ipoPaysOut

protected boolean ipoPaysOut

poolPaysOut

protected boolean poolPaysOut

treasuryPaysOut

protected boolean treasuryPaysOut

canHoldOwnShares

protected boolean canHoldOwnShares

maxPercOfOwnShares

protected int maxPercOfOwnShares

mayTradeShares

protected boolean mayTradeShares

mustHaveOperatedToTradeShares

protected boolean mustHaveOperatedToTradeShares

certificates

protected java.util.ArrayList<PublicCertificateI> certificates
The certificates of this company (minimum 1)


certsAreInitiallyAvailable

boolean certsAreInitiallyAvailable
Are the certificates available from the first SR?


shareUnit

protected IntegerState shareUnit
What percentage of ownership constitutes "one share"


shareUnitsForSharePrice

protected int shareUnitsForSharePrice
What number of share units relates to the share price (normally 1, but 2 for 1835 Prussian)


floatPerc

protected int floatPerc
At what percentage sold does the company float


sharePriceUpOnFloating

protected boolean sharePriceUpOnFloating
Share price movement on floating (1851: up)


hasStockPrice

protected boolean hasStockPrice
Does the company have a stock price (minors often don't)


hasParPrice

protected boolean hasParPrice
Does the company have a par price?


splitAllowed

protected boolean splitAllowed

splitAlways

protected boolean splitAlways
Is the revenue always split (typical for non-share minors)


payoutMustExceedPriceToMove

protected boolean payoutMustExceedPriceToMove
Must payout exceed stock price to move token right?


startSpace

protected java.lang.String startSpace

capitalisation

protected int capitalisation

fixedPrice

protected int fixedPrice
Fixed price (for a 1835-style minor)


trainLimit

protected int[] trainLimit
Train limit per phase (index)


privateToCloseOnFirstTrainName

protected java.lang.String privateToCloseOnFirstTrainName
Private to close if first train is bought


privateToCloseOnFirstTrain

protected PrivateCompanyI privateToCloseOnFirstTrain

mustOwnATrain

protected boolean mustOwnATrain
Must the company own a train


mustTradeTrainsAtFixedPrice

protected boolean mustTradeTrainsAtFixedPrice

canClose

protected boolean canClose
Can the company price token go down to a "Close" square? 1856 CGR cannot.


initialTrainType

protected java.lang.String initialTrainType
Initial train at floating time


initialTrainCost

protected int initialTrainCost

initialTrainTradeable

protected boolean initialTrainTradeable

maxNumberOfLoans

protected int maxNumberOfLoans

valuePerLoan

protected int valuePerLoan

currentNumberOfLoans

protected IntegerState currentNumberOfLoans

loanInterestPct

protected int loanInterestPct

maxLoansPerRound

protected int maxLoansPerRound

currentLoanValue

protected MoneyModel currentLoanValue

canSharePriceVary

protected BooleanState canSharePriceVary

gameManager

protected GameManagerI gameManager

bank

protected Bank bank

stockMarket

protected StockMarketI stockMarket

mapManager

protected MapManager mapManager
Constructor Detail

PublicCompany

public PublicCompany()
The constructor. The way this class is instantiated does not allow arguments.

Method Detail

configureFromXML

public void configureFromXML(Tag tag)
                      throws ConfigurationException
To configure all public companies from the <PublicCompany> XML element

Specified by:
configureFromXML in interface ConfigurableComponentI
Overrides:
configureFromXML in class Company
Throws:
ConfigurationException

init

public void init(java.lang.String name,
                 CompanyTypeI type)
Initialisation, to be called directly after instantiation (cloning)

Specified by:
init in interface CompanyI
Overrides:
init in class Company

setIndex

public void setIndex(int index)
Specified by:
setIndex in interface PublicCompanyI

finishConfiguration

public void finishConfiguration(GameManagerI gameManager)
                         throws ConfigurationException
Final initialisation, after all XML has been processed.

Specified by:
finishConfiguration in interface ConfigurableComponentI
Parameters:
gameManager - The 'parent' configurable component is passed to allow the 'child' to access any other object without the need to resort to static calls where possible.
Throws:
ConfigurationException

initTurn

public void initTurn()
Reset turn objects

Specified by:
initTurn in interface PublicCompanyI

getBgColour

public java.awt.Color getBgColour()
Return the company token background colour.

Specified by:
getBgColour in interface PublicCompanyI
Returns:
Color object

getHexBgColour

public java.lang.String getHexBgColour()
Return the company token background colour.

Specified by:
getHexBgColour in interface PublicCompanyI
Returns:
Hexadecimal string RRGGBB.

getFgColour

public java.awt.Color getFgColour()
Return the company token foreground colour.

Specified by:
getFgColour in interface PublicCompanyI
Returns:
Color object.

getHexFgColour

public java.lang.String getHexFgColour()
Return the company token foreground colour.

Specified by:
getHexFgColour in interface PublicCompanyI
Returns:
Hexadecimal string RRGGBB.

getHomeHexes

public java.util.List<MapHex> getHomeHexes()
Return the company's Home hexes (usually one).

Specified by:
getHomeHexes in interface PublicCompanyI
Returns:
Returns the homeHex.

setHomeHex

public void setHomeHex(MapHex homeHex)
Set a non-fixed company home hex. Only covers setting one home hex. Having two home hexes is currently only supported if the locations are preconfigured.

Specified by:
setHomeHex in interface PublicCompanyI
Parameters:
homeHex - The homeHex to set.

getHomeCityNumber

public int getHomeCityNumber()
Specified by:
getHomeCityNumber in interface PublicCompanyI
Returns:
Returns the homeStation.

setHomeCityNumber

public void setHomeCityNumber(int number)
Specified by:
setHomeCityNumber in interface PublicCompanyI
Parameters:
homeStation - The homeStation to set.

isHomeBlockedForAllCities

public boolean isHomeBlockedForAllCities()
Specified by:
isHomeBlockedForAllCities in interface PublicCompanyI
Returns:
true -> requires an open slot in each city of the hex, false -> one slot on the hex

getDestinationHex

public MapHex getDestinationHex()
Specified by:
getDestinationHex in interface PublicCompanyI
Returns:
Returns the destinationHex.

hasDestination

public boolean hasDestination()
Specified by:
hasDestination in interface PublicCompanyI

hasReachedDestination

public boolean hasReachedDestination()
Specified by:
hasReachedDestination in interface PublicCompanyI

setReachedDestination

public void setReachedDestination(boolean value)
Specified by:
setReachedDestination in interface PublicCompanyI

canBuyStock

public boolean canBuyStock()
Specified by:
canBuyStock in interface PublicCompanyI
Returns:

mayTradeShares

public boolean mayTradeShares()
Specified by:
mayTradeShares in interface PublicCompanyI

mayBuyTrainType

public boolean mayBuyTrainType(TrainI train)
Stub that allows exclusions such as that 1856 CGR may not buy a 4

Specified by:
mayBuyTrainType in interface PublicCompanyI

mustHaveOperatedToTradeShares

public boolean mustHaveOperatedToTradeShares()
Specified by:
mustHaveOperatedToTradeShares in interface PublicCompanyI

start

public void start(StockSpaceI startSpace)
Description copied from interface: PublicCompanyI
Start the company.

Specified by:
start in interface PublicCompanyI

start

public void start(int price)
Specified by:
start in interface PublicCompanyI

start

public void start()
Start a company.

Specified by:
start in interface PublicCompanyI

transferAssetsFrom

public void transferAssetsFrom(PublicCompanyI otherCompany)
Specified by:
transferAssetsFrom in interface PublicCompanyI

hasStarted

public boolean hasStarted()
Specified by:
hasStarted in interface PublicCompanyI
Returns:
Returns true is the company has started.

setBuyable

public void setBuyable(boolean buyable)
Make company shares buyable. Only useful where shares become buyable before the company has started (e.g. 1835 Prussian).

Specified by:
setBuyable in interface PublicCompanyI

isBuyable

public boolean isBuyable()
Specified by:
isBuyable in interface PublicCompanyI

setFloated

public void setFloated()
Float the company, put its initial cash in the treasury.

Specified by:
setFloated in interface PublicCompanyI

hasFloated

public boolean hasFloated()
Has the company already floated?

Specified by:
hasFloated in interface PublicCompanyI
Returns:
true if the company has floated.

hasOperated

public boolean hasOperated()
Has the company already operated?

Specified by:
hasOperated in interface PublicCompanyI
Returns:
true if the company has operated.

setOperated

public void setOperated()
Specified by:
setOperated in interface PublicCompanyI

setClosed

public void setClosed()
Description copied from class: Company
Close this company.

Specified by:
setClosed in interface CompanyI
Overrides:
setClosed in class Company

reinitialise

protected void reinitialise()
Reinitialise a company, i.e. close it and make the shares available for a new company start. IMplemented rules are now as in 18EU. TODO Will see later if this is generic enough.


getInGameModel

public ModelObject getInGameModel()
Specified by:
getInGameModel in interface PublicCompanyI

getIsClosedModel

public ModelObject getIsClosedModel()
Specified by:
getIsClosedModel in interface PublicCompanyI

setParSpace

public void setParSpace(StockSpaceI space)
Set the company par price.

Note: this method should not be used to start a company! Use start() in stead.

Specified by:
setParSpace in interface PublicCompanyI
Parameters:
spaceI -

getStartSpace

public StockSpaceI getStartSpace()
Get the company par (initial) price.

Specified by:
getStartSpace in interface PublicCompanyI
Returns:
StockSpace object, which defines the company start position on the stock chart.

getIPOPrice

public int getIPOPrice()
Specified by:
getIPOPrice in interface PublicCompanyI

getMarketPrice

public int getMarketPrice()
Specified by:
getMarketPrice in interface PublicCompanyI

getGameEndPrice

public int getGameEndPrice()
Return the price per share at game end. Normally, it is equal to the market price, but in some games (e.g. 1856) deductions may apply.

Specified by:
getGameEndPrice in interface PublicCompanyI
Returns:

setCurrentSpace

public void setCurrentSpace(StockSpaceI price)
Set a new company price.

Specified by:
setCurrentSpace in interface PublicCompanyI
Parameters:
price - The StockSpace object that defines the new location on the stock market.

getCurrentPriceModel

public PriceModel getCurrentPriceModel()
Specified by:
getCurrentPriceModel in interface PublicCompanyI

getParPriceModel

public PriceModel getParPriceModel()
Specified by:
getParPriceModel in interface PublicCompanyI

getCurrentSpace

public StockSpaceI getCurrentSpace()
Get the current company share price.

Specified by:
getCurrentSpace in interface PublicCompanyI
Returns:
The StockSpace object that defines the current location on the stock market.

updatePlayersWorth

public void updatePlayersWorth()
Specified by:
updatePlayersWorth in interface PublicCompanyI

addCash

public void addCash(int amount)
Add a given amount to the company treasury.

Specified by:
addCash in interface CashHolder
Parameters:
amount - The amount to add (may be negative).

getCash

public int getCash()
Get the current company treasury.

Specified by:
getCash in interface CashHolder
Specified by:
getCash in interface PublicCompanyI
Returns:
The current cash amount.

getFormattedCash

public java.lang.String getFormattedCash()
Specified by:
getFormattedCash in interface PublicCompanyI

getCashModel

public ModelObject getCashModel()
Specified by:
getCashModel in interface CashHolder

getPublicNumber

public int getPublicNumber()
Specified by:
getPublicNumber in interface PublicCompanyI
Returns:

getCertificates

public java.util.List<PublicCertificateI> getCertificates()
Get a list of this company's certificates.

Specified by:
getCertificates in interface PublicCompanyI
Returns:
ArrayList containing the certificates (item 0 is the President's share).

setCertificates

public void setCertificates(java.util.List<PublicCertificateI> list)
Assign a predefined list of certificates to this company. The list is deep cloned.

Specified by:
setCertificates in interface PublicCompanyI
Parameters:
list - ArrayList containing the certificates.

nameCertificates

public void nameCertificates()
Backlink the certificates to this company, and give each one a type name.


addCertificate

public void addCertificate(PublicCertificateI certificate)
Add a certificate to the end of this company's list of certificates.

Specified by:
addCertificate in interface PublicCompanyI
Parameters:
certificate - The certificate to add.

getFloatPercentage

public int getFloatPercentage()
Get the percentage of shares that must be sold to float the company.

Specified by:
getFloatPercentage in interface PublicCompanyI
Returns:
The float percentage.

getPresident

public Player getPresident()
Get the company President.

Specified by:
getPresident in interface PublicCompanyI

getPresidentModel

public PresidentModel getPresidentModel()
Specified by:
getPresidentModel in interface PublicCompanyI

getPresidentsShare

public PublicCertificateI getPresidentsShare()
Specified by:
getPresidentsShare in interface PublicCompanyI

isAvailable

public boolean isAvailable()

setLastRevenue

public void setLastRevenue(int i)
Store the last revenue earned by this company.

Specified by:
setLastRevenue in interface PublicCompanyI
Parameters:
i - The last revenue amount.

getLastRevenue

public int getLastRevenue()
Get the last revenue earned by this company.

Specified by:
getLastRevenue in interface PublicCompanyI
Returns:
The last revenue amount.

getLastRevenueModel

public ModelObject getLastRevenueModel()
Specified by:
getLastRevenueModel in interface PublicCompanyI

setLastRevenueAllocation

public void setLastRevenueAllocation(int allocation)
Last revenue allocation (payout, split, withhold)

Specified by:
setLastRevenueAllocation in interface PublicCompanyI

getlastRevenueAllocationText

public java.lang.String getlastRevenueAllocationText()
Specified by:
getlastRevenueAllocationText in interface PublicCompanyI

getLastRevenueAllocationModel

public ModelObject getLastRevenueAllocationModel()
Specified by:
getLastRevenueAllocationModel in interface PublicCompanyI

payout

public void payout(int amount)
Determine if the price token must be moved after a dividend payout.

Specified by:
payout in interface PublicCompanyI
Parameters:
amount -

paysOutToTreasury

public boolean paysOutToTreasury(PublicCertificateI cert)
Specified by:
paysOutToTreasury in interface PublicCompanyI

withhold

public void withhold(int amount)
Determine if the price token must be moved after a withheld dividend.

Specified by:
withhold in interface PublicCompanyI
Parameters:
The - revenue amount.

isSoldOut

public boolean isSoldOut()
Is the company completely sold out? This method should return true only if the share price should move up at the end of a stock round. Since 1851 (jan 2008) interpreted as: no share is owned either by the Bank or by the company's own Treasury.

Specified by:
isSoldOut in interface PublicCompanyI
Returns:
true if the share price can move up.

canBuyPrivates

public boolean canBuyPrivates()
Specified by:
canBuyPrivates in interface PublicCompanyI
Returns:

canUseSpecialProperties

public boolean canUseSpecialProperties()
Specified by:
canUseSpecialProperties in interface PublicCompanyI

getShareUnit

public int getShareUnit()
Get the unit of share.

Specified by:
getShareUnit in interface PublicCompanyI
Returns:
The percentage of ownership that is called "one share".

getShareUnitsForSharePrice

public int getShareUnitsForSharePrice()
Specified by:
getShareUnitsForSharePrice in interface PublicCompanyI

toString

public java.lang.String toString()
Specified by:
toString in interface CompanyI
Overrides:
toString in class Company

hasStockPrice

public boolean hasStockPrice()
Description copied from interface: PublicCompanyI
Is company present on the Stock Market?

Specified by:
hasStockPrice in interface PublicCompanyI
Returns:
True if the company has a stock price.

hasParPrice

public boolean hasParPrice()
Specified by:
hasParPrice in interface PublicCompanyI

canSharePriceVary

public boolean canSharePriceVary()
Specified by:
canSharePriceVary in interface PublicCompanyI

getFixedPrice

public int getFixedPrice()
Specified by:
getFixedPrice in interface PublicCompanyI

getBaseTokensBuyCost

public int getBaseTokensBuyCost()
Specified by:
getBaseTokensBuyCost in interface PublicCompanyI

sharesOwnedByPlayers

public int sharesOwnedByPlayers()
Specified by:
sharesOwnedByPlayers in interface PublicCompanyI

canHoldOwnShares

public boolean canHoldOwnShares()
Specified by:
canHoldOwnShares in interface PublicCompanyI

isSplitAllowed

public boolean isSplitAllowed()
Specified by:
isSplitAllowed in interface PublicCompanyI
Returns:
Returns the splitAllowed.

isSplitAlways

public boolean isSplitAlways()
Specified by:
isSplitAlways in interface PublicCompanyI
Returns:
Returns the splitAlways.

checkPresidencyOnBuy

public void checkPresidencyOnBuy(Player buyer)
Check if the presidency has changed for a buying player.

Specified by:
checkPresidencyOnBuy in interface PublicCompanyI
Parameters:
buyer - Player who has just bought a certificate.

checkPresidencyOnSale

public void checkPresidencyOnSale(Player seller)
Check if the presidency has changed for a selling player.

Specified by:
checkPresidencyOnSale in interface PublicCompanyI

checkPresidency

public void checkPresidency()
A generic presidency check. Perhaps it can replace the above two methods.

Specified by:
checkPresidency in interface PublicCompanyI

getCapitalisation

public int getCapitalisation()
Specified by:
getCapitalisation in interface PublicCompanyI
Returns:
Returns the capitalisation.

setCapitalisation

public void setCapitalisation(int capitalisation)
Specified by:
setCapitalisation in interface PublicCompanyI
Parameters:
capitalisation - The capitalisation to set.

getNumberOfShares

public int getNumberOfShares()
Specified by:
getNumberOfShares in interface PublicCompanyI

getTrainLimit

public int getTrainLimit(int phaseIndex)
Specified by:
getTrainLimit in interface PublicCompanyI

getCurrentTrainLimit

public int getCurrentTrainLimit()
Specified by:
getCurrentTrainLimit in interface PublicCompanyI

getNumberOfTrains

public int getNumberOfTrains()
Specified by:
getNumberOfTrains in interface PublicCompanyI

canRunTrains

public boolean canRunTrains()
Specified by:
canRunTrains in interface PublicCompanyI

buyTrain

public void buyTrain(TrainI train,
                     int price)
Must be called in stead of Portfolio.buyTrain if side-effects can occur.

Specified by:
buyTrain in interface PublicCompanyI

getTrainsSpentThisTurnModel

public ModelObject getTrainsSpentThisTurnModel()
Specified by:
getTrainsSpentThisTurnModel in interface PublicCompanyI

buyPrivate

public void buyPrivate(PrivateCompanyI privateCompany,
                       Portfolio from,
                       int price)
Specified by:
buyPrivate in interface PublicCompanyI

getPrivatesSpentThisTurnModel

public ModelObject getPrivatesSpentThisTurnModel()
Specified by:
getPrivatesSpentThisTurnModel in interface PublicCompanyI

layTile

public void layTile(MapHex hex,
                    TileI tile,
                    int orientation,
                    int cost)
Specified by:
layTile in interface PublicCompanyI

layTileInNoMapMode

public void layTileInNoMapMode(int cost)
Specified by:
layTileInNoMapMode in interface PublicCompanyI

getTilesLaidThisTurnModel

public ModelObject getTilesLaidThisTurnModel()
Specified by:
getTilesLaidThisTurnModel in interface PublicCompanyI

getTilesCostThisTurnModel

public ModelObject getTilesCostThisTurnModel()
Specified by:
getTilesCostThisTurnModel in interface PublicCompanyI

layBaseToken

public void layBaseToken(MapHex hex,
                         int cost)
Specified by:
layBaseToken in interface PublicCompanyI

layBaseTokenInNoMapMode

public void layBaseTokenInNoMapMode(int cost)
Specified by:
layBaseTokenInNoMapMode in interface PublicCompanyI

getBaseTokenLayCost

public int getBaseTokenLayCost(MapHex hex)
Calculate the cost of laying a token, given the hex where the token is laid. This only makes a difference for de "distance" method.

Specified by:
getBaseTokenLayCost in interface PublicCompanyI
Parameters:
hex - The hex where the token is to be laid.
Returns:
The cost of laying that token.

getBaseTokenLayCosts

public int[] getBaseTokenLayCosts()
Return all possible token lay costs to be incurred for the company's next token lay. In the "distance" method, this will be an array.

Specified by:
getBaseTokenLayCosts in interface PublicCompanyI
Returns:

getTokensLaidThisTurnModel

public ModelObject getTokensLaidThisTurnModel()
Specified by:
getTokensLaidThisTurnModel in interface PublicCompanyI

getTokensCostThisTurnModel

public ModelObject getTokensCostThisTurnModel()
Specified by:
getTokensCostThisTurnModel in interface PublicCompanyI

getBaseTokensModel

public BaseTokensModel getBaseTokensModel()
Specified by:
getBaseTokensModel in interface PublicCompanyI

addBonus

public boolean addBonus(Bonus bonus)
Specified by:
addBonus in interface PublicCompanyI

removeBonus

public boolean removeBonus(Bonus bonus)
Specified by:
removeBonus in interface PublicCompanyI

removeBonus

public boolean removeBonus(java.lang.String name)
Specified by:
removeBonus in interface PublicCompanyI

getBonuses

public java.util.List<Bonus> getBonuses()
Specified by:
getBonuses in interface PublicCompanyI

getBonusTokensModel

public BonusModel getBonusTokensModel()
Specified by:
getBonusTokensModel in interface PublicCompanyI

hasLaidHomeBaseTokens

public boolean hasLaidHomeBaseTokens()
Specified by:
hasLaidHomeBaseTokens in interface PublicCompanyI

layHomeBaseTokens

public boolean layHomeBaseTokens()
Specified by:
layHomeBaseTokens in interface PublicCompanyI

getFreeToken

public BaseToken getFreeToken()
Specified by:
getFreeToken in interface PublicCompanyI

addToken

public boolean addToken(TokenI token,
                        int position)
Add a base token to the company charter. This method is called when a base token is removed from a map hex. This may happen because of an Undo action. In some games tokens can be taken back for more "regular" reasons as well. The token is removed from the company laid token list and added to the free token list.

Specified by:
addToken in interface TokenHolder

getTokens

public java.util.List<TokenI> getTokens()
Specified by:
getTokens in interface TokenHolder
Returns:
ArrayList of all tokens we have.

getNumberOfBaseTokens

public int getNumberOfBaseTokens()
Specified by:
getNumberOfBaseTokens in interface PublicCompanyI

getNumberOfFreeBaseTokens

public int getNumberOfFreeBaseTokens()
Specified by:
getNumberOfFreeBaseTokens in interface PublicCompanyI

getNumberOfLaidBaseTokens

public int getNumberOfLaidBaseTokens()
Specified by:
getNumberOfLaidBaseTokens in interface PublicCompanyI

hasTokens

public boolean hasTokens()
Description copied from interface: TokenHolder
Do we have any tokens?

Specified by:
hasTokens in interface TokenHolder
Returns:
Boolean

removeToken

public boolean removeToken(TokenI token)
Remove a base token from the company charter. This method is called when a base token is laid on a map hex. The token is removed from the company free token list and added to the laid token list. In other words: lay a base token

Specified by:
removeToken in interface TokenHolder
Parameters:
token - The token object to remove.
Returns:
True if successful.

addObject

public boolean addObject(Moveable object,
                         int[] position)
Description copied from interface: MoveableHolder
Add an object to its list at a certain position.

Specified by:
addObject in interface MoveableHolder
Parameters:
object - The Moveable object to be added.
position - Position to insert object at. O: at front, -1, at end, >0: at that position.
Returns:
True if successful.

removeObject

public boolean removeObject(Moveable object)
Specified by:
removeObject in interface MoveableHolder

getListIndex

public int[] getListIndex(Moveable object)
Specified by:
getListIndex in interface MoveableHolder

getNumberOfTileLays

public int getNumberOfTileLays(java.lang.String tileColour)
Specified by:
getNumberOfTileLays in interface PublicCompanyI

mustOwnATrain

public boolean mustOwnATrain()
Specified by:
mustOwnATrain in interface PublicCompanyI

mustTradeTrainsAtFixedPrice

public boolean mustTradeTrainsAtFixedPrice()
Specified by:
mustTradeTrainsAtFixedPrice in interface PublicCompanyI

getCurrentNumberOfLoans

public int getCurrentNumberOfLoans()
Specified by:
getCurrentNumberOfLoans in interface PublicCompanyI

getCurrentLoanValue

public int getCurrentLoanValue()
Specified by:
getCurrentLoanValue in interface PublicCompanyI

addLoans

public void addLoans(int number)
Specified by:
addLoans in interface PublicCompanyI

getLoanInterestPct

public int getLoanInterestPct()
Specified by:
getLoanInterestPct in interface PublicCompanyI

getMaxNumberOfLoans

public int getMaxNumberOfLoans()
Specified by:
getMaxNumberOfLoans in interface PublicCompanyI

canLoan

public boolean canLoan()
Specified by:
canLoan in interface PublicCompanyI

getMaxLoansPerRound

public int getMaxLoansPerRound()
Specified by:
getMaxLoansPerRound in interface PublicCompanyI

getValuePerLoan

public int getValuePerLoan()
Specified by:
getValuePerLoan in interface PublicCompanyI

getLoanValueModel

public MoneyModel getLoanValueModel()
Specified by:
getLoanValueModel in interface PublicCompanyI

canClose

public boolean canClose()
Specified by:
canClose in interface PublicCompanyI

clone

public java.lang.Object clone()
Specified by:
clone in interface CompanyI
Overrides:
clone in class Company

getExtraShareMarks

public java.lang.String getExtraShareMarks()
Extra codes to be added to the president's indicator in the Game Status window. Normally nothing (see 1856 CGR for an exception).

Specified by:
getExtraShareMarks in interface PublicCompanyI