From: Erik V. <ev...@us...> - 2010-02-28 21:38:13
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv7856/rails/game Modified Files: Company.java PublicCompany.java StockRound.java PublicCompanyI.java OperatingRound.java CompanyI.java PrivateCompanyI.java PrivateCompany.java Log Message: 1835 Prussian start & side effects Index: CompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyI.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CompanyI.java 4 Feb 2010 21:27:58 -0000 1.7 --- CompanyI.java 28 Feb 2010 21:38:05 -0000 1.8 *************** *** 2,9 **** package rails.game; /** * To be implemented by any Company object. */ ! public interface CompanyI extends ConfigurableComponentI { /** The name of the XML tag used to configure a company. */ --- 2,14 ---- package rails.game; + import java.util.List; + + import rails.game.move.MoveableHolder; + import rails.game.special.SpecialPropertyI; + /** * To be implemented by any Company object. */ ! public interface CompanyI extends ConfigurableComponentI, MoveableHolder { /** The name of the XML tag used to configure a company. */ *************** *** 18,22 **** void init(String name, CompanyTypeI type); ! // void configureFromXML (Element element) throws ConfigurationException; /** --- 23,45 ---- void init(String name, CompanyTypeI type); ! /** ! * @return ArrayList of all special properties we have. ! */ ! public List<SpecialPropertyI> getSpecialProperties(); ! ! /** ! * Do we have any special properties? ! * ! * @return Boolean ! */ ! public boolean hasSpecialProperties(); ! ! /** ! * Get the Portfolio of this company, containing all privates and ! * certificates owned.. ! * ! * @return The Portfolio of this company. ! */ ! public Portfolio getPortfolio(); /** Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** PublicCompany.java 20 Feb 2010 12:34:50 -0000 1.87 --- PublicCompany.java 28 Feb 2010 21:38:04 -0000 1.88 *************** *** 187,191 **** /** Privates and Certificates owned by the public company */ ! protected Portfolio portfolio; /** What percentage of ownership constitutes "one share" */ --- 187,191 ---- /** Privates and Certificates owned by the public company */ ! //protected Portfolio portfolio; /** What percentage of ownership constitutes "one share" */ *************** *** 270,273 **** --- 270,275 ---- public void configureFromXML(Tag tag) throws ConfigurationException { + super.configureFromXML(tag); + longName = tag.getAttributeAsString("longname", name); infoText = "<html>"+longName; *************** *** 1172,1185 **** /** - * Get the Portfolio of this company, containing all privates and - * certificates owned.. - * - * @return The Portfolio of this company. - */ - public Portfolio getPortfolio() { - return portfolio; - } - - /** * Get the percentage of shares that must be sold to float the company. * --- 1174,1177 ---- Index: PrivateCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PrivateCompany.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** PrivateCompany.java 17 Feb 2010 22:02:52 -0000 1.36 --- PrivateCompany.java 28 Feb 2010 21:38:05 -0000 1.37 *************** *** 11,15 **** public class PrivateCompany extends Company implements PrivateCompanyI { ! protected static int numberOfPrivateCompanies = 0; protected int privateNumber; // For internal use --- 11,15 ---- public class PrivateCompany extends Company implements PrivateCompanyI { ! protected static int numberOfPrivateCompanies = 0; protected int privateNumber; // For internal use *************** *** 18,22 **** // list of revenue sfy 1889 protected int[] revenue; - protected List<SpecialPropertyI> specialProperties = null; protected String auctionType; --- 18,21 ---- *************** *** 44,47 **** --- 43,50 ---- /* Configure private company features */ try { + + // For special properties (now included in Company). + super.configureFromXML(tag); + longName= tag.getAttributeAsString("longname", name); infoText = "<html>"+longName; *************** *** 60,83 **** // Special properties - Tag spsTag = tag.getChild("SpecialProperties"); - if (spsTag != null) { - - List<Tag> spTags = spsTag.getChildren("SpecialProperty"); - String className; - for (Tag spTag : spTags) { - className = spTag.getAttributeAsString("class"); - if (!Util.hasValue(className)) - throw new ConfigurationException( - "Missing class in private special property"); - - SpecialPropertyI sp = - (SpecialPropertyI) Class.forName(className).newInstance(); - sp.setCompany(this); - specialProperties.add(sp); - sp.configureFromXML(spTag); - infoText += "<br>" + sp.getInfo(); - } - } - // Extra info text(usually related to extra-share special properties) Tag infoTag = tag.getChild("Info"); --- 63,66 ---- *************** *** 334,353 **** } - /** - * @return ArrayList of all special properties we have. - */ - public List<SpecialPropertyI> getSpecialProperties() { - return specialProperties; - } - - /** - * Do we have any special properties? - * - * @return Boolean - */ - public boolean hasSpecialProperties() { - return specialProperties != null && !specialProperties.isEmpty(); - } - public List<MapHex> getBlockedHexes() { return blockedHexes; --- 317,320 ---- Index: Company.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Company.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Company.java 4 Feb 2010 21:27:58 -0000 1.13 --- Company.java 28 Feb 2010 21:38:04 -0000 1.14 *************** *** 2,9 **** --- 2,15 ---- package rails.game; + import java.util.ArrayList; + import java.util.List; + import org.apache.log4j.Logger; import rails.game.move.MoveableHolder; + import rails.game.special.SpecialPropertyI; import rails.game.state.BooleanState; + import rails.util.Tag; + import rails.util.Util; public abstract class Company implements CompanyI, ConfigurableComponentI, *************** *** 29,33 **** protected BooleanState closedObject; ! protected static Logger log = Logger.getLogger(Company.class.getPackage().getName()); --- 35,42 ---- protected BooleanState closedObject; ! ! // Moved here from PrivayeCOmpany on behalf of 1835 ! protected List<SpecialPropertyI> specialProperties = null; ! protected static Logger log = Logger.getLogger(Company.class.getPackage().getName()); *************** *** 42,45 **** --- 51,110 ---- } + /** Only to be called from subclasses */ + public void configureFromXML(Tag tag) throws ConfigurationException { + + // Special properties + Tag spsTag = tag.getChild("SpecialProperties"); + if (spsTag != null) { + + List<Tag> spTags = spsTag.getChildren("SpecialProperty"); + String className; + for (Tag spTag : spTags) { + className = spTag.getAttributeAsString("class"); + if (!Util.hasValue(className)) + throw new ConfigurationException( + "Missing class in private special property"); + SpecialPropertyI sp = null; + try { + sp = (SpecialPropertyI) Class.forName(className).newInstance(); + } catch (Exception e) { + log.fatal ("Cannot instantiate "+className, e); + System.exit(-1); + } + sp.setCompany(this); + if (specialProperties == null) specialProperties = new ArrayList<SpecialPropertyI>(2); + specialProperties.add(sp); + sp.configureFromXML(spTag); + infoText += "<br>" + sp.getInfo(); + } + } + } + + /** + * @return ArrayList of all special properties we have. + */ + public List<SpecialPropertyI> getSpecialProperties() { + return specialProperties; + } + + /** + * Do we have any special properties? + * + * @return Boolean + */ + public boolean hasSpecialProperties() { + return specialProperties != null && !specialProperties.isEmpty(); + } + + /** + * Get the Portfolio of this company, containing all privates and + * certificates owned.. + * + * @return The Portfolio of this company. + */ + public Portfolio getPortfolio() { + return portfolio; + } + /** * @return This company's number *************** *** 160,162 **** --- 225,237 ---- } + public static String joinNamesWithDelimiter (List<CompanyI> companies, String delimiter) { + StringBuilder b = new StringBuilder(""); + if (companies != null) { + for (CompanyI company : companies) { + if (b.length() > 0) b.append(delimiter); + b.append(company.getName()); + } + } + return b.toString(); + } } Index: PublicCompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompanyI.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** PublicCompanyI.java 20 Feb 2010 12:34:46 -0000 1.48 --- PublicCompanyI.java 28 Feb 2010 21:38:05 -0000 1.49 *************** *** 216,220 **** public int getFloatPercentage(); ! public Portfolio getPortfolio(); public void payout(int amount); --- 216,220 ---- public int getFloatPercentage(); ! //public Portfolio getPortfolio(); public void payout(int amount); Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.109 retrieving revision 1.110 diff -C2 -d -r1.109 -r1.110 *** OperatingRound.java 26 Feb 2010 08:51:08 -0000 1.109 --- OperatingRound.java 28 Feb 2010 21:38:05 -0000 1.110 *************** *** 1641,1645 **** oldHolder.getName(), Bank.format(price), ! stb.getCompany().getName() )); } --- 1641,1645 ---- oldHolder.getName(), Bank.format(price), ! stb.getOriginalCompany().getName() )); } Index: StockRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockRound.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** StockRound.java 24 Feb 2010 18:08:36 -0000 1.64 --- StockRound.java 28 Feb 2010 21:38:05 -0000 1.65 *************** *** 1097,1101 **** PublicCompanyI publicCompany = companyManager.getPublicCompany(sp.getPublicCompanyName()); ! PrivateCompanyI privateCompany = sp.getCompany(); Portfolio portfolio = privateCompany.getPortfolio(); Player player = null; --- 1097,1101 ---- PublicCompanyI publicCompany = companyManager.getPublicCompany(sp.getPublicCompanyName()); ! CompanyI privateCompany = sp.getOriginalCompany(); Portfolio portfolio = privateCompany.getPortfolio(); Player player = null; Index: PrivateCompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PrivateCompanyI.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PrivateCompanyI.java 3 Feb 2010 05:37:54 -0000 1.9 --- PrivateCompanyI.java 28 Feb 2010 21:38:05 -0000 1.10 *************** *** 5,9 **** import rails.game.move.MoveableHolder; - import rails.game.special.SpecialPropertyI; public interface PrivateCompanyI extends CompanyI, Certificate, MoveableHolder { --- 5,8 ---- *************** *** 29,37 **** public int getRevenueByPhase(PhaseI phase); - /** - * @return ArrayList of all special properties we have. - */ - public List<SpecialPropertyI> getSpecialProperties(); - public List<MapHex> getBlockedHexes(); --- 28,31 ---- |