rails.game
Class StartItem

java.lang.Object
  extended by rails.game.StartItem

public class StartItem
extends java.lang.Object

Each object of this class represents a "start packet item", which consist of one or two certificates. The whole start packet must be bought before the stock rounds can start.

During XML parsing, only the certificate name and other attributes are saved. The certificate objects are linked to in the later initialisation step.


Field Summary
static int AUCTIONED
           
protected  MoneyModel basePrice
           
static int BIDDABLE
           
protected  MoneyModel[] bids
           
static int BUYABLE
           
protected  int column
           
protected  int index
           
protected  IntegerState lastBidderIndex
           
protected static org.apache.log4j.Logger log
           
protected  MoneyModel minimumBid
           
protected  java.lang.String name
           
protected  java.lang.String name2
           
static int NEEDS_SHARE_PRICE
           
protected  int numberOfPlayers
           
protected  java.util.List<Player> players
           
protected  boolean president
           
protected  boolean president2
           
protected  Certificate primary
           
protected  int row
           
protected  Certificate secondary
           
static int SELECTABLE
           
static int SOLD
           
protected static java.util.Map<java.lang.String,StartItem> startItemMap
           
protected  IntegerState status
          Status of the start item (buyable? biddable?) regardless whether the current player has the amount of (unblocked) cash to buy it or to bid on it.
static java.lang.String[] statusName
           
protected  java.lang.String type
           
protected  java.lang.String type2
           
static int UNAVAILABLE
           
 
Constructor Summary
StartItem(java.lang.String name, java.lang.String type, int basePrice, int index, boolean president)
          The constructor, taking the properties of the "primary" (often teh only) certificate.
 
Method Summary
protected  PublicCompanyI checkNeedForPriceSetting(Certificate certificate)
          If a start item component a President's certificate that needs price setting, return the name of thecompany for which the price must be set.
 boolean equals(StartItem item)
           
 int getBasePrice()
          Get the start item base price.
 ModelObject getBasePriceModel()
           
 int getBid()
          Get the currently highest bid amount.
 int getBid(Player player)
          Get the highest bid done so far by a particular player.
 Player getBidder()
          Get the highest bidder so far.
 int getBidders()
          Return the total number of players that has done bids so far on this item.
 ModelObject getBidForPlayerModel(int index)
           
static StartItem getByName(java.lang.String name)
           
 int getColumn()
          Get the column number.
 int getIndex()
           
 int getMinimumBid()
          Get the minimum allowed next bid.
 ModelObject getMinimumBidModel()
           
 java.lang.String getName()
          Get the start item name (which is the company name of the primary certificate).
 Certificate getPrimary()
          Get the primary (or only) certificate.
 int getRow()
          Get the row number.
 Certificate getSecondary()
          Get the secondary certificate.
 int getStatus()
           
 ModelObject getStatusModel()
           
 java.lang.String getStatusName()
           
 java.lang.String getText()
           
 java.lang.String getType()
           
 boolean hasBid(Player player)
          Check if a player has done any bids on this start item.
 boolean hasSecondary()
          Check if there is a secondary certificate.
 void init(GameManagerI gameManager)
          Initialisation, to be called after all XML parsing has completed, and after IPO initialisation.
 boolean isSold()
          Check if the start item has been sold.
 PublicCompanyI needsPriceSetting()
          This method indicates if there is a company for which a par price must be set when this start item is bought.
 void reduceBasePriceBy(int amount)
           
 void setBid(int amount, Player bidder)
          Register a bid.
protected  void setColumn(int column)
          Set the start packet row.
 void setMinimumBid(int value)
           
protected  void setRow(int row)
          Set the start packet row.
 void setSecondary(java.lang.String name2, java.lang.String type2, boolean president2)
          Add a secondary certificate, that "comes with" the primary certificate.
 void setSold(Player player, int buyPrice)
          Set the start item sold status.
 void setStatus(int status)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

primary

protected Certificate primary

secondary

protected Certificate secondary

basePrice

protected MoneyModel basePrice

row

protected int row

column

protected int column

index

protected int index

lastBidderIndex

protected IntegerState lastBidderIndex

players

protected java.util.List<Player> players

numberOfPlayers

protected int numberOfPlayers

bids

protected MoneyModel[] bids

minimumBid

protected MoneyModel minimumBid

status

protected IntegerState status
Status of the start item (buyable? biddable?) regardless whether the current player has the amount of (unblocked) cash to buy it or to bid on it.


UNAVAILABLE

public static final int UNAVAILABLE
See Also:
Constant Field Values

BIDDABLE

public static final int BIDDABLE
See Also:
Constant Field Values

BUYABLE

public static final int BUYABLE
See Also:
Constant Field Values

SELECTABLE

public static final int SELECTABLE
See Also:
Constant Field Values

AUCTIONED

public static final int AUCTIONED
See Also:
Constant Field Values

NEEDS_SHARE_PRICE

public static final int NEEDS_SHARE_PRICE
See Also:
Constant Field Values

SOLD

public static final int SOLD
See Also:
Constant Field Values

statusName

public static final java.lang.String[] statusName

type

protected java.lang.String type

president

protected boolean president

name2

protected java.lang.String name2

type2

protected java.lang.String type2

president2

protected boolean president2

startItemMap

protected static java.util.Map<java.lang.String,StartItem> startItemMap

log

protected static org.apache.log4j.Logger log
Constructor Detail

StartItem

public StartItem(java.lang.String name,
                 java.lang.String type,
                 int basePrice,
                 int index,
                 boolean president)
The constructor, taking the properties of the "primary" (often teh only) certificate. The parameters are only stored, real initialisation is done by the init() method.

Parameters:
name - The Company name of the primary certificate. This name will also become the name of the start item itself.
type - The CompanyType name of the primary certificate.
basePrice - The start item base selling price, i.e. the price for which the item can be bought or where bidding starts.
president - True if the primary certificate is the president's share.
Method Detail

setSecondary

public void setSecondary(java.lang.String name2,
                         java.lang.String type2,
                         boolean president2)
Add a secondary certificate, that "comes with" the primary certificate.

Parameters:
name2 - The Company name of the secondary certificate.
type2 - The CompanyType name of the secondary certificate.
president2 - True if the secondary certificate is the president's share.

init

public void init(GameManagerI gameManager)
Initialisation, to be called after all XML parsing has completed, and after IPO initialisation.


getIndex

public int getIndex()

setRow

protected void setRow(int row)
Set the start packet row.

Applies to games like 1835 where start items are organised and become available in rows.

Parameters:
row -

setColumn

protected void setColumn(int column)
Set the start packet row.

Applies to games like 1837 where start items are organised and become available in columns.

Parameters:
row -

getRow

public int getRow()
Get the row number.

Returns:
The row number. Default 0.
See Also:
setRow()

getColumn

public int getColumn()
Get the column number.

Returns:
The column number. Default 0.
See Also:
setColumn()

getPrimary

public Certificate getPrimary()
Get the primary (or only) certificate.

Returns:
The primary certificate object.

hasSecondary

public boolean hasSecondary()
Check if there is a secondary certificate.

Returns:
True if there is a secondary certificate.

getSecondary

public Certificate getSecondary()
Get the secondary certificate.

Returns:
The secondary certificate object, or null if it does not exist.

getBasePrice

public int getBasePrice()
Get the start item base price.

Returns:
The base price.

reduceBasePriceBy

public void reduceBasePriceBy(int amount)

getName

public java.lang.String getName()
Get the start item name (which is the company name of the primary certificate).

Returns:
The start item name.

setBid

public void setBid(int amount,
                   Player bidder)
Register a bid.

This method does not check off the amount of money that a player has available for bidding.

Parameters:
amount - The bid amount.
bidder - The bidding player. special amounts are 0 for 18EU as buy price, -1 as standard pass, -2 and below as pass in 18EU

getBid

public int getBid()
Get the currently highest bid amount.

Returns:
The bid amount (0 if there have been no bids yet).

getBid

public int getBid(Player player)
Get the highest bid done so far by a particular player.

Parameters:
player - The name of the player.
Returns:
The bid amount for this player (default 0).

getBidders

public int getBidders()
Return the total number of players that has done bids so far on this item.

Returns:
The number of bidders.

getBidder

public Player getBidder()
Get the highest bidder so far.

Returns:
The player object that did the highest bid.

getMinimumBid

public int getMinimumBid()
Get the minimum allowed next bid. TODO 5 should be configurable.

Returns:
Minimum bid

setMinimumBid

public void setMinimumBid(int value)

hasBid

public boolean hasBid(Player player)
Check if a player has done any bids on this start item.

Parameters:
playerName - The name of the player.
Returns:
True if this player has done any bids.

isSold

public boolean isSold()
Check if the start item has been sold.

Returns:
True if this item has been sold.

setSold

public void setSold(Player player,
                    int buyPrice)
Set the start item sold status.

Parameters:
sold - The new sold status (usually true).

needsPriceSetting

public PublicCompanyI needsPriceSetting()
This method indicates if there is a company for which a par price must be set when this start item is bought. The UI can use this to ask for the price immediately, so bypassing the extra "price asking" intermediate step.

Returns:
A public company for which a price must be set.

checkNeedForPriceSetting

protected PublicCompanyI checkNeedForPriceSetting(Certificate certificate)
If a start item component a President's certificate that needs price setting, return the name of thecompany for which the price must be set.

Parameters:
certificate -
Returns:
Name of public company, or null

getStatus

public int getStatus()

getStatusModel

public ModelObject getStatusModel()

getStatusName

public java.lang.String getStatusName()

setStatus

public void setStatus(int status)

getBasePriceModel

public ModelObject getBasePriceModel()

getBidForPlayerModel

public ModelObject getBidForPlayerModel(int index)

getMinimumBidModel

public ModelObject getMinimumBidModel()

getByName

public static StartItem getByName(java.lang.String name)

getType

public java.lang.String getType()

equals

public boolean equals(StartItem item)

toString

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

getText

public java.lang.String getText()