Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv14080/rails/game Modified Files: Portfolio.java Tile.java StockRound.java StockMarket.java PublicCertificate.java MapHex.java StartRound_1830.java PublicCompany.java TreasuryShareRound.java Player.java GameManager.java StartRound.java StartRound_1835.java ShareSellingRound.java OperatingRound.java CompanyManager.java CompanyType.java ComponentManager.java Round.java PrivateCompany.java PrivateCompanyI.java GameOption.java Log Message: Fixed code to remove compiler warnings Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** PublicCompany.java 11 Jan 2009 17:24:46 -0000 1.46 --- PublicCompany.java 15 Jan 2009 20:53:28 -0000 1.47 *************** *** 1309,1313 **** buyer.getPortfolio()); ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", ! new String[] { buyer.getName(), name })); } } --- 1309,1314 ---- buyer.getPortfolio()); ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", ! buyer.getName(), ! name )); } } *************** *** 1334,1338 **** player.getPortfolio()); ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", ! new String[] { player.getName(), name })); } } --- 1335,1340 ---- player.getPortfolio()); ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", ! player.getName(), ! name )); } } Index: StartRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartRound.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** StartRound.java 8 Jan 2009 19:59:39 -0000 1.23 --- StartRound.java 15 Jan 2009 20:53:28 -0000 1.24 *************** *** 209,214 **** errMsg = LocalText.getText("InvalidStartPrice", ! new String[] { Bank.format(sharePrice), ! shareCompName }); break; } --- 209,214 ---- errMsg = LocalText.getText("InvalidStartPrice", ! Bank.format(sharePrice), ! shareCompName ); break; } *************** *** 218,223 **** if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("CantBuyItem", new String[] { ! playerName, item.getName(), errMsg })); return false; } --- 218,225 ---- if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("CantBuyItem", ! playerName, ! item.getName(), ! errMsg )); return false; } *************** *** 248,261 **** int sharePrice) { Certificate primary = item.getPrimary(); ! ReportBuffer.add(LocalText.getText("BuysItemFor", new String[] { ! player.getName(), primary.getName(), Bank.format(price) })); ! //player.buy(primary, price); executeTradeCertificate (primary, player.getPortfolio(), price); checksOnBuying(primary, sharePrice); if (item.hasSecondary()) { Certificate extra = item.getSecondary(); ! ReportBuffer.add(LocalText.getText("ALSO_GETS", new String[] { ! player.getName(), extra.getName() })); ! //player.buy(extra, 0); executeTradeCertificate (extra, player.getPortfolio(), 0); checksOnBuying(extra, sharePrice); --- 250,264 ---- int sharePrice) { Certificate primary = item.getPrimary(); ! ReportBuffer.add(LocalText.getText("BuysItemFor", ! player.getName(), ! primary.getName(), ! Bank.format(price) )); executeTradeCertificate (primary, player.getPortfolio(), price); checksOnBuying(primary, sharePrice); if (item.hasSecondary()) { Certificate extra = item.getSecondary(); ! ReportBuffer.add(LocalText.getText("ALSO_GETS", ! player.getName(), ! extra.getName() )); executeTradeCertificate (extra, player.getPortfolio(), 0); checksOnBuying(extra, sharePrice); Index: Player.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Player.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Player.java 20 Nov 2008 21:49:38 -0000 1.15 --- Player.java 15 Jan 2009 20:53:28 -0000 1.16 *************** *** 55,59 **** * Initialises each Player's parameters which depend on the number of * players. To be called when all Players have been added. ! * */ public static void initPlayers(List<Player> players) { --- 55,59 ---- * Initialises each Player's parameters which depend on the number of * players. To be called when all Players have been added. ! * */ public static void initPlayers(List<Player> players) { *************** *** 66,71 **** player.index = index++; Bank.transferCash(null, player, startCash); ! ReportBuffer.add(LocalText.getText("PlayerIs", new String[] { ! String.valueOf(index), player.getName() })); } ReportBuffer.add(LocalText.getText("PlayerCash", Bank.format(startCash))); --- 66,72 ---- player.index = index++; Bank.transferCash(null, player, startCash); ! ReportBuffer.add(LocalText.getText("PlayerIs", ! index, ! player.getName() )); } ReportBuffer.add(LocalText.getText("PlayerCash", Bank.format(startCash))); *************** *** 120,124 **** /** * Check if a player may buy the given number of certificates. ! * * @param number Number of certificates to buy (usually 1 but not always * so). --- 121,125 ---- /** * Check if a player may buy the given number of certificates. ! * * @param number Number of certificates to buy (usually 1 but not always * so). *************** *** 137,141 **** * company, given the "hold limit" per company, that is the percentage of * shares of one company that a player may hold (typically 60%). ! * * @param company The company from which to buy * @param number The number of shares (usually 1 but not always so). --- 138,142 ---- * company, given the "hold limit" per company, that is the percentage of * shares of one company that a player may hold (typically 60%). ! * * @param company The company from which to buy * @param number The number of shares (usually 1 but not always so). *************** *** 155,159 **** * may hold (typically 60%). <p>If no hold limit applies, it is taken to be * 100%. ! * * @param company The company from which to buy * @param number The share unit (typically 10%). --- 156,160 ---- * may hold (typically 60%). <p>If no hold limit applies, it is taken to be * 100%. ! * * @param company The company from which to buy * @param number The share unit (typically 10%). *************** *** 211,215 **** /** * Get the player's total worth. ! * * @return Total worth */ --- 212,216 ---- /** * Get the player's total worth. ! * * @return Total worth */ *************** *** 256,260 **** /** * Block cash allocated by a bid. ! * * @param amount Amount of cash to be blocked. * @return false if the amount was not available. --- 257,261 ---- /** * Block cash allocated by a bid. ! * * @param amount Amount of cash to be blocked. * @return false if the amount was not available. *************** *** 272,276 **** /** * Unblock cash. ! * * @param amount Amount to be unblocked. * @return false if the given amount was not blocked. --- 273,277 ---- /** * Unblock cash. ! * * @param amount Amount to be unblocked. * @return false if the given amount was not blocked. *************** *** 288,292 **** /** * Return the unblocked cash (available for bidding) ! * * @return */ --- 289,293 ---- /** * Return the unblocked cash (available for bidding) ! * * @return */ Index: CompanyType.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyType.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CompanyType.java 4 Jun 2008 19:00:30 -0000 1.6 --- CompanyType.java 15 Jan 2009 20:53:28 -0000 1.7 *************** *** 26,30 **** /** * The constructor. ! * * @param name Company type name ("Private", "Public", "Minor" etc.). * @param className Name of the class that will instantiate this type of --- 26,30 ---- /** * The constructor. ! * * @param name Company type name ("Private", "Public", "Minor" etc.). * @param className Name of the class that will instantiate this type of *************** *** 73,77 **** } catch (CloneNotSupportedException e) { DisplayBuffer.add(LocalText.getText("CantCloneCompany", ! new String[] { name, this.name })); } return newCompany; --- 73,77 ---- } catch (CloneNotSupportedException e) { DisplayBuffer.add(LocalText.getText("CantCloneCompany", ! name, this.name )); } return newCompany; *************** *** 81,85 **** /** * Get the company type name ! * * @return The name of this company type. */ --- 81,85 ---- /** * Get the company type name ! * * @return The name of this company type. */ *************** *** 90,94 **** /** * Get the name of the class that will implement this type of company. ! * * @return The full class name. */ --- 90,94 ---- /** * Get the name of the class that will implement this type of company. ! * * @return The full class name. */ Index: GameOption.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameOption.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GameOption.java 4 Jun 2008 19:00:31 -0000 1.6 --- GameOption.java 15 Jan 2009 20:53:28 -0000 1.7 *************** *** 2,9 **** package rails.game; ! import java.util.ArrayList; ! import java.util.HashMap; ! import java.util.List; ! import java.util.Map; import rails.util.LocalText; --- 2,6 ---- package rails.game; ! import java.util.*; import rails.util.LocalText; *************** *** 43,47 **** public String getLocalisedName() { ! return LocalText.getText(name, parm); } --- 40,44 ---- public String getLocalisedName() { ! return LocalText.getText(name, (Object[]) parm); } Index: StockMarket.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockMarket.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** StockMarket.java 2 Nov 2008 20:04:26 -0000 1.13 --- StockMarket.java 15 Jan 2009 20:53:28 -0000 1.14 *************** *** 2,11 **** package rails.game; ! import java.util.ArrayList; ! import java.util.HashMap; ! import java.util.List; import rails.game.move.PriceTokenMove; ! import rails.util.*; public class StockMarket implements StockMarketI, ConfigurableComponentI { --- 2,10 ---- package rails.game; ! import java.util.*; import rails.game.move.PriceTokenMove; ! import rails.util.LocalText; ! import rails.util.Tag; public class StockMarket implements StockMarketI, ConfigurableComponentI { *************** *** 105,109 **** spaceTag.getAttributeAsString(StockSpaceI.TYPE_TAG); if (typeName != null ! && (type = (StockSpaceTypeI) stockSpaceTypes.get(typeName)) == null) { throw new ConfigurationException(LocalText.getText( "StockSpaceTypeUndefined", type)); --- 104,108 ---- spaceTag.getAttributeAsString(StockSpaceI.TYPE_TAG); if (typeName != null ! && (type = stockSpaceTypes.get(typeName)) == null) { throw new ConfigurationException(LocalText.getText( "StockSpaceTypeUndefined", type)); *************** *** 120,124 **** row = Integer.parseInt(name.substring(1)); ! col = (int) (name.toUpperCase().charAt(0) - '@'); if (row > numRows) numRows = row; if (col > numCols) numCols = col; --- 119,123 ---- row = Integer.parseInt(name.substring(1)); ! col = (name.toUpperCase().charAt(0) - '@'); if (row > numRows) numRows = row; if (col > numCols) numCols = col; *************** *** 138,142 **** startPrices = new int[startSpaces.size()]; for (int i = 0; i < startPrices.length; i++) { ! startPrices[i] = ((StockSpaceI) startSpaces.get(i)).getPrice(); } --- 137,141 ---- startPrices = new int[startSpaces.size()]; for (int i = 0; i < startPrices.length; i++) { ! startPrices[i] = (startSpaces.get(i)).getPrice(); } *************** *** 290,302 **** // To be written to a log file in the future. if (from != null && from == to) { ! ReportBuffer.add(LocalText.getText("PRICE_STAYS_LOG", new String[] { ! company.getName(), Bank.format(from.getPrice()), ! from.getName() })); return; } else if (from == null && to != null) {} else if (from != null && to != null) { ! ReportBuffer.add(LocalText.getText("PRICE_MOVES_LOG", new String[] { ! company.getName(), Bank.format(from.getPrice()), ! from.getName(), Bank.format(to.getPrice()), to.getName() })); /* Check for rails.game closure */ --- 289,305 ---- // To be written to a log file in the future. if (from != null && from == to) { ! ReportBuffer.add(LocalText.getText("PRICE_STAYS_LOG", ! company.getName(), ! Bank.format(from.getPrice()), ! from.getName() )); return; } else if (from == null && to != null) {} else if (from != null && to != null) { ! ReportBuffer.add(LocalText.getText("PRICE_MOVES_LOG", ! company.getName(), ! Bank.format(from.getPrice()), ! from.getName(), ! Bank.format(to.getPrice()), ! to.getName() )); /* Check for rails.game closure */ *************** *** 328,332 **** /** * Return start prices as an int array. Note: this array is NOT sorted. ! * * @return */ --- 331,335 ---- /** * Return start prices as an int array. Note: this array is NOT sorted. ! * * @return */ Index: StartRound_1830.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartRound_1830.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** StartRound_1830.java 8 Jan 2009 19:59:39 -0000 1.17 --- StartRound_1830.java 15 Jan 2009 20:53:28 -0000 1.18 *************** *** 188,193 **** } if (!validItem) { ! errMsg = ! LocalText.getText("ActionNotAllowed", bidItem.toString()); break; --- 188,192 ---- } if (!validItem) { ! errMsg = LocalText.getText("ActionNotAllowed", bidItem.toString()); break; *************** *** 203,208 **** // Bid must be at least 5 above last bid if (bidAmount < item.getMinimumBid()) { ! errMsg = ! LocalText.getText("BidTooLow", "" + item.getMinimumBid()); break; --- 202,206 ---- // Bid must be at least 5 above last bid if (bidAmount < item.getMinimumBid()) { ! errMsg = LocalText.getText("BidTooLow", "" + item.getMinimumBid()); break; *************** *** 211,220 **** // Bid must be a multiple of the modulus if (bidAmount % startPacket.getModulus() != 0) { ! errMsg = ! LocalText.getText( ! "BidMustBeMultipleOf", ! new String[] { ! String.valueOf(bidAmount), ! String.valueOf(startPacket.getMinimumIncrement()) }); break; } --- 209,215 ---- // Bid must be a multiple of the modulus if (bidAmount % startPacket.getModulus() != 0) { ! errMsg = LocalText.getText("BidMustBeMultipleOf", ! bidAmount, ! startPacket.getMinimumIncrement()); break; } *************** *** 224,229 **** int available = player.getFreeCash() + previousBid; if (bidAmount > available) { ! errMsg = ! LocalText.getText("BidTooHigh", Bank.format(available)); break; } --- 219,223 ---- int available = player.getFreeCash() + previousBid; if (bidAmount > available) { ! errMsg = LocalText.getText("BidTooHigh", Bank.format(available)); break; } *************** *** 233,238 **** if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("InvalidBid", new String[] { ! playerName, item.getName(), errMsg })); return false; } --- 227,234 ---- if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("InvalidBid", ! playerName, ! item.getName(), ! errMsg )); return false; } *************** *** 243,249 **** if (previousBid > 0) player.unblockCash(previousBid); player.blockCash(bidAmount); ! ReportBuffer.add(LocalText.getText("BID_ITEM_LOG", new String[] { ! playerName, Bank.format(bidAmount), item.getName(), ! Bank.format(player.getFreeCash()) })); if (bidItem.getStatus() != StartItem.AUCTIONED) { --- 239,247 ---- if (previousBid > 0) player.unblockCash(previousBid); player.blockCash(bidAmount); ! ReportBuffer.add(LocalText.getText("BID_ITEM_LOG", ! playerName, ! Bank.format(bidAmount), ! item.getName(), ! Bank.format(player.getFreeCash()) )); if (bidItem.getStatus() != StartItem.AUCTIONED) { *************** *** 282,287 **** if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("InvalidPass", new String[] { ! playerName, errMsg })); return false; } --- 280,286 ---- if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("InvalidPass", ! playerName, ! errMsg )); return false; } *************** *** 325,331 **** ReportBuffer.add(LocalText.getText( "ITEM_PRICE_REDUCED", - new String[] { startPacket.getFirstItem().getName(), ! Bank.format(startPacket.getFirstItem().getBasePrice()) })); numPasses.set(0); if (startPacket.getFirstItem().getBasePrice() == 0) { --- 324,329 ---- ReportBuffer.add(LocalText.getText( "ITEM_PRICE_REDUCED", startPacket.getFirstItem().getName(), ! Bank.format(startPacket.getFirstItem().getBasePrice()) )); numPasses.set(0); if (startPacket.getFirstItem().getBasePrice() == 0) { Index: ComponentManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/ComponentManager.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ComponentManager.java 4 Jun 2008 19:00:31 -0000 1.11 --- ComponentManager.java 15 Jan 2009 20:53:28 -0000 1.12 *************** *** 142,147 **** // Add it to the map of known components. instance.mComponentMap.put(name, component); ! log.debug(LocalText.getText("ComponentInitAs", new String[] { name, ! clazz })); } --- 142,146 ---- // Add it to the map of known components. instance.mComponentMap.put(name, component); ! log.debug(LocalText.getText("ComponentInitAs", name, clazz )); } *************** *** 149,153 **** /** * Returns the configured parameter with the given name. ! * * @param componentName the of the component sought. * @return the component sought, or null if it has not been configured. --- 148,152 ---- /** * Returns the configured parameter with the given name. ! * * @param componentName the of the component sought. * @return the component sought, or null if it has not been configured. Index: CompanyManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyManager.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** CompanyManager.java 3 Dec 2008 20:15:15 -0000 1.12 --- CompanyManager.java 15 Jan 2009 20:53:28 -0000 1.13 *************** *** 1 **** ! /* $Header$ */ package rails.game; import java.util.*; import org.apache.log4j.Logger; import rails.util.LocalText; import rails.util.Tag; public class CompanyManager implements CompanyManagerI, ConfigurableComponentI { /** A List with all private companies */ private List<PrivateCompanyI> lPrivateCompanies = new ArrayList<PrivateCompanyI>(); /** A List with all public companies */ private List<PublicCompanyI> lPublicCompanies = new ArrayList<PublicCompanyI>(); /** A map with all private companies by name */ private Map<String, PrivateCompanyI> mPrivateCompanies = new HashMap<String, PrivateCompanyI>(); /** A map with all public (i.e. non-private) companies by name */ private Map<String, PublicCompanyI> mPublicCompanies = new HashMap<String, PublicCompanyI>(); /** A map of all type names to maps of companies of that type by name */ // TODO Redundant, current usage can be replaced. private Map<String, HashMap<String, CompanyI>> mCompaniesByTypeAndName = new HashMap<String, HashMap<String, CompanyI>>(); /** A list of all start packets (usually one) */ // TODO Currently not used (but some newer games have more than one) private List<StartPacket> startPackets = new ArrayList<StartPacket>(); private int numberOfPublicCompanies = 0; protected static Logger log = Logger.getLogger(CompanyManager.class.getPackage().getName()); /* * NOTES: 1. we don't have a map over all companies, because some games have * duplicate names, e.g. B&O in 1830. 2. we have both a map and a list of * private/public companies to preserve configuration sequence while * allowing direct access. */ /** * No-args constructor. */ public CompanyManager() { // Nothing to do here, everything happens when configured. } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { /** A map with all company types, by type name */ // Localised here as it has no permanent use Map<String, CompanyTypeI> mCompanyTypes = new HashMap<String, CompanyTypeI>(); for (Tag compTypeTag : tag.getChildren(CompanyTypeI.ELEMENT_ID)) { // Extract the attributes of the Component String name = compTypeTag.getAttributeAsString(CompanyTypeI.NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompanyType")); } String className = compTypeTag.getAttributeAsString(CompanyTypeI.CLASS_TAG); if (className == null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeHasNoClass", name)); } if (mCompanyTypes.get(name) != null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeConfiguredTwice", name)); } CompanyTypeI companyType = new CompanyType(name, className); mCompanyTypes.put(name, companyType); // Further parsing is done within CompanyType companyType.configureFromXML(compTypeTag); } /* Read and configure the companies */ for (Tag companyTag : tag.getChildren(CompanyI.COMPANY_ELEMENT_ID)) { // Extract the attributes of the Component String name = companyTag.getAttributeAsString(CompanyI.COMPANY_NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompany")); } String type = companyTag.getAttributeAsString(CompanyI.COMPANY_TYPE_TAG); if (type == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasNoType", name)); } CompanyTypeI cType = mCompanyTypes.get(type); if (cType == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasUnknownType", new String[] { name, type })); } try { CompanyI company = cType.createCompany(name, companyTag); /* Private or public */ if (company instanceof PrivateCompanyI) { mPrivateCompanies.put(name, (PrivateCompanyI) company); lPrivateCompanies.add((PrivateCompanyI) company); } else if (company instanceof PublicCompanyI) { ((PublicCompanyI)company).setIndex (numberOfPublicCompanies++); mPublicCompanies.put(name, (PublicCompanyI) company); lPublicCompanies.add((PublicCompanyI) company); } /* By type and name */ if (!mCompaniesByTypeAndName.containsKey(type)) mCompaniesByTypeAndName.put(type, new HashMap<String, CompanyI>()); ((Map<String, CompanyI>) mCompaniesByTypeAndName.get(type)).put( name, company); } catch (Exception e) { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", cType.getClassName()), e); } } /* Read and configure the start packets */ List<Tag> packetTags = tag.getChildren("StartPacket"); if (packetTags != null) { for (Tag packetTag : tag.getChildren("StartPacket")) { // Extract the attributes of the Component String name = packetTag.getAttributeAsString("name"); if (name == null) name = "Initial"; String roundClass = packetTag.getAttributeAsString("roundClass"); if (roundClass == null) { throw new ConfigurationException(LocalText.getText( "StartPacketHasNoClass", name)); } StartPacket sp = new StartPacket(name, roundClass); startPackets.add(sp); sp.configureFromXML(packetTag); } } /* Read and configure additional rules */ /* This part may move later to a GameRules or GameManager XML */ Tag rulesTag = tag.getChild("StockRoundRules"); if (rulesTag != null) { for (String ruleTagName : rulesTag.getChildren().keySet()) { if (ruleTagName.equals("NoSaleInFirstSR")) { StockRound.setNoSaleInFirstSR(); } else if (ruleTagName.equals("NoSaleIfNotOperated")) { StockRound.setNoSaleIfNotOperated(); } } } } // Post XML parsing initialisations public void initCompanies() throws ConfigurationException { for (PublicCompanyI comp : lPublicCompanies) { comp.init2(); } } /** * @see rails.game.CompanyManagerI#getCompany(java.lang.String) * */ public PrivateCompanyI getPrivateCompany(String name) { return mPrivateCompanies.get(name); } public PublicCompanyI getPublicCompany(String name) { return mPublicCompanies.get(name); } public List<PrivateCompanyI> getAllPrivateCompanies() { return lPrivateCompanies; } public List<PublicCompanyI> getAllPublicCompanies() { return lPublicCompanies; } public PublicCompanyI getCompanyByName(String name) { for (int i = 0; i < lPublicCompanies.size(); i++) { PublicCompany co = (PublicCompany) lPublicCompanies.get(i); if (name.equalsIgnoreCase(co.getName())) { return lPublicCompanies.get(i); } } return null; } public CompanyI getCompany(String type, String name) { if (mCompaniesByTypeAndName.containsKey(type)) { return (mCompaniesByTypeAndName.get(type)).get(name); } else { return null; } } public void closeAllPrivates() { if (lPrivateCompanies == null) return; for (PrivateCompanyI priv : lPrivateCompanies) { priv.setClosed(); } } public List<PrivateCompanyI> getPrivatesOwnedByPlayers() { List<PrivateCompanyI> privatesOwnedByPlayers = new ArrayList<PrivateCompanyI>(); for (PrivateCompanyI priv : getAllPrivateCompanies()) { if (priv.getPortfolio().getOwner() instanceof Player) { privatesOwnedByPlayers.add(priv); } } return privatesOwnedByPlayers; } } \ No newline at end of file --- 1 ---- ! /* $Header$ */ package rails.game; import java.util.*; import org.apache.log4j.Logger; import rails.util.LocalText; import rails.util.Tag; public class CompanyManager implements CompanyManagerI, ConfigurableComponentI { /** A List with all private companies */ private List<PrivateCompanyI> lPrivateCompanies = new ArrayList<PrivateCompanyI>(); /** A List with all public companies */ private List<PublicCompanyI> lPublicCompanies = new ArrayList<PublicCompanyI>(); /** A map with all private companies by name */ private Map<String, PrivateCompanyI> mPrivateCompanies = new HashMap<String, PrivateCompanyI>(); /** A map with all public (i.e. non-private) companies by name */ private Map<String, PublicCompanyI> mPublicCompanies = new HashMap<String, PublicCompanyI>(); /** A map of all type names to maps of companies of that type by name */ // TODO Redundant, current usage can be replaced. private Map<String, HashMap<String, CompanyI>> mCompaniesByTypeAndName = new HashMap<String, HashMap<String, CompanyI>>(); /** A list of all start packets (usually one) */ // TODO Currently not used (but some newer games have more than one) private List<StartPacket> startPackets = new ArrayList<StartPacket>(); private int numberOfPublicCompanies = 0; protected static Logger log = Logger.getLogger(CompanyManager.class.getPackage().getName()); /* * NOTES: 1. we don't have a map over all companies, because some games have * duplicate names, e.g. B&O in 1830. 2. we have both a map and a list of * private/public companies to preserve configuration sequence while * allowing direct access. */ /** * No-args constructor. */ public CompanyManager() { // Nothing to do here, everything happens when configured. } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { /** A map with all company types, by type name */ // Localised here as it has no permanent use Map<String, CompanyTypeI> mCompanyTypes = new HashMap<String, CompanyTypeI>(); for (Tag compTypeTag : tag.getChildren(CompanyTypeI.ELEMENT_ID)) { // Extract the attributes of the Component String name = compTypeTag.getAttributeAsString(CompanyTypeI.NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompanyType")); } String className = compTypeTag.getAttributeAsString(CompanyTypeI.CLASS_TAG); if (className == null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeHasNoClass", name)); } if (mCompanyTypes.get(name) != null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeConfiguredTwice", name)); } CompanyTypeI companyType = new CompanyType(name, className); mCompanyTypes.put(name, companyType); // Further parsing is done within CompanyType companyType.configureFromXML(compTypeTag); } /* Read and configure the companies */ for (Tag companyTag : tag.getChildren(CompanyI.COMPANY_ELEMENT_ID)) { // Extract the attributes of the Component String name = companyTag.getAttributeAsString(CompanyI.COMPANY_NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompany")); } String type = companyTag.getAttributeAsString(CompanyI.COMPANY_TYPE_TAG); if (type == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasNoType", name)); } CompanyTypeI cType = mCompanyTypes.get(type); if (cType == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasUnknownType", name, type )); } try { CompanyI company = cType.createCompany(name, companyTag); /* Private or public */ if (company instanceof PrivateCompanyI) { mPrivateCompanies.put(name, (PrivateCompanyI) company); lPrivateCompanies.add((PrivateCompanyI) company); } else if (company instanceof PublicCompanyI) { ((PublicCompanyI)company).setIndex (numberOfPublicCompanies++); mPublicCompanies.put(name, (PublicCompanyI) company); lPublicCompanies.add((PublicCompanyI) company); } /* By type and name */ if (!mCompaniesByTypeAndName.containsKey(type)) mCompaniesByTypeAndName.put(type, new HashMap<String, CompanyI>()); ((Map<String, CompanyI>) mCompaniesByTypeAndName.get(type)).put( name, company); } catch (Exception e) { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", cType.getClassName()), e); } } /* Read and configure the start packets */ List<Tag> packetTags = tag.getChildren("StartPacket"); if (packetTags != null) { for (Tag packetTag : tag.getChildren("StartPacket")) { // Extract the attributes of the Component String name = packetTag.getAttributeAsString("name"); if (name == null) name = "Initial"; String roundClass = packetTag.getAttributeAsString("roundClass"); if (roundClass == null) { throw new ConfigurationException(LocalText.getText( "StartPacketHasNoClass", name)); } StartPacket sp = new StartPacket(name, roundClass); startPackets.add(sp); sp.configureFromXML(packetTag); } } /* Read and configure additional rules */ /* This part may move later to a GameRules or GameManager XML */ Tag rulesTag = tag.getChild("StockRoundRules"); if (rulesTag != null) { for (String ruleTagName : rulesTag.getChildren().keySet()) { if (ruleTagName.equals("NoSaleInFirstSR")) { StockRound.setNoSaleInFirstSR(); } else if (ruleTagName.equals("NoSaleIfNotOperated")) { StockRound.setNoSaleIfNotOperated(); } } } } // Post XML parsing initialisations public void initCompanies() throws ConfigurationException { for (PublicCompanyI comp : lPublicCompanies) { comp.init2(); } } /** * @see rails.game.CompanyManagerI#getCompany(java.lang.String) * */ public PrivateCompanyI getPrivateCompany(String name) { return mPrivateCompanies.get(name); } public PublicCompanyI getPublicCompany(String name) { return mPublicCompanies.get(name); } public List<PrivateCompanyI> getAllPrivateCompanies() { return lPrivateCompanies; } public List<PublicCompanyI> getAllPublicCompanies() { return lPublicCompanies; } public PublicCompanyI getCompanyByName(String name) { for (int i = 0; i < lPublicCompanies.size(); i++) { PublicCompany co = (PublicCompany) lPublicCompanies.get(i); if (name.equalsIgnoreCase(co.getName())) { return lPublicCompanies.get(i); } } return null; } public CompanyI getCompany(String type, String name) { if (mCompaniesByTypeAndName.containsKey(type)) { return (mCompaniesByTypeAndName.get(type)).get(name); } else { return null; } } public void closeAllPrivates() { if (lPrivateCompanies == null) return; for (PrivateCompanyI priv : lPrivateCompanies) { priv.setClosed(); } } public List<PrivateCompanyI> getPrivatesOwnedByPlayers() { List<PrivateCompanyI> privatesOwnedByPlayers = new ArrayList<PrivateCompanyI>(); for (PrivateCompanyI priv : getAllPrivateCompanies()) { if (priv.getPortfolio().getOwner() instanceof Player) { privatesOwnedByPlayers.add(priv); } } return privatesOwnedByPlayers; } } \ No newline at end of file Index: PrivateCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PrivateCompany.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** PrivateCompany.java 20 Nov 2008 21:49:38 -0000 1.19 --- PrivateCompany.java 15 Jan 2009 20:53:28 -0000 1.20 *************** *** 2,15 **** package rails.game; ! import java.util.*; ! import rails.game.move.CashMove; ! import rails.game.move.Moveable; ! import rails.game.move.MoveableHolderI; ! import rails.game.move.ObjectMove; import rails.game.special.SpecialPropertyI; ! import rails.util.LocalText; ! import rails.util.Tag; ! import rails.util.Util; public class PrivateCompany extends Company implements PrivateCompanyI { --- 2,11 ---- package rails.game; ! import java.util.ArrayList; ! import java.util.List; ! import rails.game.move.*; import rails.game.special.SpecialPropertyI; ! import rails.util.*; public class PrivateCompany extends Company implements PrivateCompanyI { *************** *** 22,26 **** protected List<SpecialPropertyI> specialProperties = null; protected String auctionType; ! // Closing conditions protected int closingPhase; --- 18,22 ---- protected List<SpecialPropertyI> specialProperties = null; protected String auctionType; ! // Closing conditions protected int closingPhase; *************** *** 80,84 **** } } ! // Closing conditions // Currently only used to handle closure following laying --- 76,80 ---- } } ! // Closing conditions // Currently only used to handle closure following laying *************** *** 86,96 **** // Other cases are currently handled elsewhere. Tag closureTag = tag.getChild("ClosingConditions"); ! if (closureTag != null) { Tag spTag = closureTag.getChild("SpecialProperties"); ! if (spTag != null) { ! String ifAttribute = spTag.getAttributeAsString("condition"); if (ifAttribute != null) { --- 82,92 ---- // Other cases are currently handled elsewhere. Tag closureTag = tag.getChild("ClosingConditions"); ! if (closureTag != null) { Tag spTag = closureTag.getChild("SpecialProperties"); ! if (spTag != null) { ! String ifAttribute = spTag.getAttributeAsString("condition"); if (ifAttribute != null) { *************** *** 105,109 **** } } ! } catch (Exception e) { --- 101,105 ---- } } ! } catch (Exception e) { *************** *** 115,123 **** /** Initialisation, to be called directly after instantiation (cloning) */ public void init(String name, CompanyTypeI type) { super.init(name, type); specialProperties = new ArrayList<SpecialPropertyI>(); ! } --- 111,120 ---- /** Initialisation, to be called directly after instantiation (cloning) */ + @Override public void init(String name, CompanyTypeI type) { super.init(name, type); specialProperties = new ArrayList<SpecialPropertyI>(); ! } *************** *** 164,167 **** --- 161,165 ---- * @param b */ + @Override public void setClosed() { if (!isClosed()) { *************** *** 205,221 **** } ! public void payOut() { ! if (portfolio.getOwner() != Bank.getInstance()) { ! ReportBuffer.add(LocalText.getText("ReceivesFor", ! new String[] { portfolio.getOwner().getName(), ! Bank.format(revenue), name })); ! new CashMove(null, portfolio.getOwner(), revenue); ! } ! } ! public String toString() { return "Private: " + name; } public Object clone() { --- 203,212 ---- } ! @Override public String toString() { return "Private: " + name; } + @Override public Object clone() { *************** *** 227,231 **** return null; } ! return clone; } --- 218,222 ---- return null; } ! return clone; } *************** *** 242,246 **** * Remove a special property. Only used to transfer a persistent special * property to a Portfolio, where it becomes independent of the private. ! * * @param token The special property object to remove. * @return True if successful. --- 233,237 ---- * Remove a special property. Only used to transfer a persistent special * property to a Portfolio, where it becomes independent of the private. ! * * @param token The special property object to remove. * @return True if successful. *************** *** 248,252 **** public boolean removeObject(Moveable object) { if (object instanceof SpecialPropertyI) { ! return specialProperties.remove((SpecialPropertyI) object); } else { return false; --- 239,243 ---- public boolean removeObject(Moveable object) { if (object instanceof SpecialPropertyI) { ! return specialProperties.remove(object); } else { return false; *************** *** 263,267 **** /** * Do we have any special properties? ! * * @return Boolean */ --- 254,258 ---- /** * Do we have any special properties? ! * * @return Boolean */ *************** *** 285,293 **** return closeAtEndOfTurn; } ! public void checkClosingIfExercised (boolean endOfOR) { ! if (isClosed() || endOfOR != closeAtEndOfTurn) return; ! if (closeIfAllExercised) { for (SpecialPropertyI sp : specialProperties) { --- 276,284 ---- return closeAtEndOfTurn; } ! public void checkClosingIfExercised (boolean endOfOR) { ! if (isClosed() || endOfOR != closeAtEndOfTurn) return; ! if (closeIfAllExercised) { for (SpecialPropertyI sp : specialProperties) { *************** *** 296,300 **** log.debug("CloseIfAll: closing "+name); setClosed(); ! } else if (closeIfAnyExercised) { for (SpecialPropertyI sp : specialProperties) { --- 287,291 ---- log.debug("CloseIfAll: closing "+name); setClosed(); ! } else if (closeIfAnyExercised) { for (SpecialPropertyI sp : specialProperties) { Index: ShareSellingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/ShareSellingRound.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** ShareSellingRound.java 14 Jan 2009 20:45:07 -0000 1.19 --- ShareSellingRound.java 15 Jan 2009 20:53:28 -0000 1.20 *************** *** 306,311 **** if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CantSell", ! new String[] { playerName, String.valueOf(numberSold), ! companyName, errMsg })); return false; } --- 306,313 ---- if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CantSell", ! playerName, ! numberSold, ! companyName, ! errMsg )); return false; } *************** *** 336,341 **** // Check if the presidency has changed if (presCert != null && dumpedPlayer != null && presSharesToSell > 0) { ! ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", new String[] { ! dumpedPlayer.getName(), companyName})); // First swap the certificates Portfolio dumpedPortfolio = dumpedPlayer.getPortfolio(); --- 338,344 ---- // Check if the presidency has changed if (presCert != null && dumpedPlayer != null && presSharesToSell > 0) { ! ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", ! dumpedPlayer.getName(), ! companyName)); // First swap the certificates Portfolio dumpedPortfolio = dumpedPlayer.getPortfolio(); *************** *** 364,370 **** otherPlayer.getPortfolio()); ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", ! new String[] { otherPlayer.getName(), ! company.getName() ! })); break; } --- 367,372 ---- otherPlayer.getPortfolio()); ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", ! otherPlayer.getName(), ! company.getName())); break; } Index: TreasuryShareRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TreasuryShareRound.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TreasuryShareRound.java 23 Dec 2008 19:57:26 -0000 1.11 --- TreasuryShareRound.java 15 Jan 2009 20:53:28 -0000 1.12 *************** *** 270,275 **** if (company != operatingCompany) { errMsg = ! LocalText.getText("WrongCompany", new String[] { ! companyName, operatingCompany.getName() }); } --- 270,276 ---- if (company != operatingCompany) { errMsg = ! LocalText.getText("WrongCompany", ! companyName, ! operatingCompany.getName() ); } *************** *** 295,300 **** if (shares > from.getShare(company)) { errMsg = ! LocalText.getText("NotAvailable", new String[] { ! companyName, from.getName() }); break; } --- 296,302 ---- if (shares > from.getShare(company)) { errMsg = ! LocalText.getText("NotAvailable", ! companyName, ! from.getName() ); break; } *************** *** 322,328 **** if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("CantBuy", new String[] { ! companyName, String.valueOf(shares), companyName, ! from.getName(), errMsg })); return false; } --- 324,333 ---- if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("CantBuy", ! companyName, ! shares, ! companyName, ! from.getName(), ! errMsg )); return false; } *************** *** 330,342 **** // All seems OK, now buy the shares. if (number == 1) { ! ReportBuffer.add(LocalText.getText("BUY_SHARE_LOG", new String[] { ! companyName, String.valueOf(shareUnit), companyName, ! from.getName(), Bank.format(shares * price) })); } else { ! ReportBuffer.add(LocalText.getText("BUY_SHARES_LOG", new String[] { ! companyName, String.valueOf(number), ! String.valueOf(shareUnit), ! String.valueOf(number * shareUnit), companyName, ! from.getName(), Bank.format(shares * price) })); } --- 335,353 ---- // All seems OK, now buy the shares. if (number == 1) { ! ReportBuffer.add(LocalText.getText("BUY_SHARE_LOG", ! companyName, ! shareUnit, ! companyName, ! from.getName(), ! Bank.format(shares * price) )); } else { ! ReportBuffer.add(LocalText.getText("BUY_SHARES_LOG", ! companyName, ! number, ! shareUnit, ! number * shareUnit, ! companyName, ! from.getName(), ! Bank.format(shares * price) )); } *************** *** 381,386 **** if (company != operatingCompany) { errMsg = ! LocalText.getText("WrongCompany", new String[] { ! companyName, operatingCompany.getName() }); break; } --- 392,398 ---- if (company != operatingCompany) { errMsg = ! LocalText.getText("WrongCompany", ! companyName, ! operatingCompany.getName() ); break; } *************** *** 440,446 **** int numberSold = action.getNumberSold(); if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("CantSell", new String[] { ! companyName, String.valueOf(numberSold), companyName, ! errMsg })); return false; } --- 452,460 ---- int numberSold = action.getNumberSold(); if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("CantSell", ! companyName, ! numberSold, ! companyName, ! errMsg )); return false; } *************** *** 461,468 **** MoveSet.start(true); ! ReportBuffer.add(LocalText.getText("SELL_SHARES_LOG", new String[] { ! companyName, String.valueOf(numberSold), ! String.valueOf((numberSold * company.getShareUnit())), ! companyName, Bank.format(numberSold * price) })); // Transfer the sold certificates --- 475,484 ---- MoveSet.start(true); ! ReportBuffer.add(LocalText.getText("SELL_SHARES_LOG", ! companyName, ! numberSold, ! (numberSold * company.getShareUnit()), ! companyName, ! Bank.format(numberSold * price) )); // Transfer the sold certificates Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Round.java 23 Dec 2008 19:55:29 -0000 1.14 --- Round.java 15 Jan 2009 20:53:28 -0000 1.15 *************** *** 201,206 **** if (cash > 0) { new CashMove(Bank.getInstance(), company, cash); ! ReportBuffer.add(LocalText.getText("FloatsWithCash", new String[] { ! company.getName(), Bank.format(cash) })); } else { ReportBuffer.add(LocalText.getText("Floats", --- 201,207 ---- if (cash > 0) { new CashMove(Bank.getInstance(), company, cash); ! ReportBuffer.add(LocalText.getText("FloatsWithCash", ! company.getName(), ! Bank.format(cash) )); } else { ReportBuffer.add(LocalText.getText("Floats", Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** OperatingRound.java 14 Jan 2009 20:45:07 -0000 1.51 --- OperatingRound.java 15 Jan 2009 20:53:28 -0000 1.52 *************** *** 128,132 **** for (PrivateCompanyI priv : companyManager.getAllPrivateCompanies()) { ! if (!priv.isClosed()) priv.payOut(); } --- 128,144 ---- for (PrivateCompanyI priv : companyManager.getAllPrivateCompanies()) { ! if (!priv.isClosed()) { ! //priv.payOut(); ! if (((Portfolio)priv.getHolder()).getOwner().getClass() != Bank.class) { ! CashHolder recipient = ((Portfolio)priv.getHolder()).getOwner(); ! int revenue = priv.getRevenue(); ! ReportBuffer.add(LocalText.getText("ReceivesFor", ! recipient.getName(), ! Bank.format(revenue), ! priv.getName())); ! new CashMove(null, recipient, revenue); ! } ! ! } } *************** *** 169,174 **** if (company != operatingCompany) { DisplayBuffer.add(LocalText.getText("WrongCompany", ! new String[] { company.getName(), ! operatingCompany.getName() })); return false; } --- 181,186 ---- if (company != operatingCompany) { DisplayBuffer.add(LocalText.getText("WrongCompany", ! company.getName(), ! operatingCompany.getName() )); return false; } *************** *** 265,270 **** if (!companyName.equals(operatingCompany.getName())) { errMsg = ! LocalText.getText("WrongCompany", new String[] { ! companyName, operatingCompany.getName() }); break; } --- 277,283 ---- if (!companyName.equals(operatingCompany.getName())) { errMsg = ! LocalText.getText("WrongCompany", ! companyName, ! operatingCompany.getName() ); break; } *************** *** 301,307 **** LocalText.getText( "TileMayNotBeLaidInHex", ! new String[] { ! String.valueOf(tile.getExternalId()), ! hex.getName() }); break; } --- 314,319 ---- LocalText.getText( "TileMayNotBeLaidInHex", ! tile.getExternalId(), ! hex.get... [truncated message content] |