From: <ev...@us...> - 2010-07-23 20:05:41
|
Revision: 1354 http://rails.svn.sourceforge.net/rails/?rev=1354&view=rev Author: evos Date: 2010-07-23 20:05:34 +0000 (Fri, 23 Jul 2010) Log Message: ----------- Changed BuyCertificate to pass on share size per certificate rather that the certificate ID. This is to make BuyCertificate consistent will SellShares and help preventing saved file loading problems. Various minor fixes have als been applied for issues detected during testing. Modified Paths: -------------- trunk/18xx/rails/game/GameManager.java trunk/18xx/rails/game/GameManagerI.java trunk/18xx/rails/game/Portfolio.java trunk/18xx/rails/game/ReportBuffer.java trunk/18xx/rails/game/StockRound.java trunk/18xx/rails/game/TreasuryShareRound.java trunk/18xx/rails/game/action/BuyCertificate.java trunk/18xx/rails/game/action/StartCompany.java trunk/18xx/rails/game/move/ObjectMove.java trunk/18xx/rails/game/specific/_1835/StockRound_1835.java trunk/18xx/rails/game/specific/_1856/StockRound_1856.java trunk/18xx/rails/game/specific/_18EU/StartCompany_18EU.java trunk/18xx/rails/game/specific/_18EU/StockRound_18EU.java trunk/18xx/rails/ui/swing/GameStatus.java trunk/18xx/rails/ui/swing/GameUIManager.java trunk/18xx/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java trunk/18xx/rails/util/Util.java Modified: trunk/18xx/rails/game/GameManager.java =================================================================== --- trunk/18xx/rails/game/GameManager.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/GameManager.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -68,12 +68,16 @@ protected State currentPlayer = new State("CurrentPlayer", Player.class); protected State priorityPlayer = new State("PriorityPlayer", Player.class); - /** Map relating portfolio names and objects, to enable deserialization */ + /** Map relating portfolio names and objects, to enable deserialization. + * OBSOLETE since Rails 1.3.1, but still required to enable reading old saved files */ protected Map<String, Portfolio> portfolioMap = new HashMap<String, Portfolio> (); + /** Map relating portfolio unique names and objects, to enable deserialization */ + protected Map<String, Portfolio> portfolioUniqueNameMap = + new HashMap<String, Portfolio> (); protected IntegerState playerCertificateLimit - = new IntegerState ("PlayerCertificateLimit", 0); + = new IntegerState ("PlayerCertificateLimit", 0); protected int currentNumberOfOperatingRounds = 1; protected boolean skipFirstStockRound = false; protected boolean showCompositeORNumber = true; @@ -83,7 +87,7 @@ protected boolean gameEndsAfterSetOfORs = true; protected EnumMap<GameDef.Parm, Object> gameParameters - = new EnumMap<GameDef.Parm, Object>(GameDef.Parm.class); + = new EnumMap<GameDef.Parm, Object>(GameDef.Parm.class); // protected EnumSet<CorrectionType> activeCorrections // = EnumSet.noneOf(CorrectionType.class); @@ -893,11 +897,15 @@ DisplayBuffer.clear(); // TEMPORARY FIX TO ALLOW OLD 1856 SAVED FILES TO BE PROCESSED - if (!possibleActions.contains(action.getClass()) - && possibleActions.contains(RepayLoans.class)) { + if (gameName.equals("1856") + && possibleActions.contains(RepayLoans.class) + && (!possibleActions.contains(action.getClass()) + || (action.getClass() == NullAction.class + && ((NullAction)action).getMode() != NullAction.DONE))) { // Insert "Done" log.debug("Action DONE inserted"); getCurrentRound().process(new NullAction (NullAction.DONE)); + possibleActions.clear(); getCurrentRound().setPossibleActions(); if (!isGameOver()) setCorrectionActions(); } @@ -913,11 +921,16 @@ if (moveStack.isOpen()) moveStack.finish(); return false; } + possibleActions.clear(); getCurrentRound().setPossibleActions(); - //String playerName = getCurrentPlayer().getName(); - //for (PossibleAction a : possibleActions.getList()) { - // log.debug(playerName+" may: "+a.toString()); - //} + + // Log possible actions (normally this is outcommented) + String playerName = getCurrentPlayer().getName(); + for (PossibleAction a : possibleActions.getList()) { + log.debug(playerName+" may: "+a.toString()); + } + + if (!isGameOver()) setCorrectionActions(); } catch (Exception e) { @@ -1352,12 +1365,18 @@ public void addPortfolio (Portfolio portfolio) { portfolioMap.put(portfolio.getName(), portfolio); + portfolioUniqueNameMap.put(portfolio.getUniqueName(), portfolio); } + /* since Rails 1.3.1, but still required to enable loading old saved files */ public Portfolio getPortfolioByName (String name) { return portfolioMap.get(name); } + public Portfolio getPortfolioByUniqueName (String name) { + return portfolioUniqueNameMap.get(name); + } + /* (non-Javadoc) * @see rails.game.GameManagerI#getStartPacket() */ Modified: trunk/18xx/rails/game/GameManagerI.java =================================================================== --- trunk/18xx/rails/game/GameManagerI.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/GameManagerI.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -146,6 +146,7 @@ public void addPortfolio (Portfolio portfolio); public Portfolio getPortfolioByName (String name); + public Portfolio getPortfolioByUniqueName (String name); /** * @return the StartPacket Modified: trunk/18xx/rails/game/Portfolio.java =================================================================== --- trunk/18xx/rails/game/Portfolio.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/Portfolio.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -71,6 +71,8 @@ /** Name of portfolio */ protected String name; + /** Unique name (including owner class name) */ + protected String uniqueName; /** Specific portfolio names */ public static final String IPO_NAME = "IPO"; @@ -84,7 +86,8 @@ public Portfolio(String name, CashHolder holder) { this.name = name; this.owner = holder; - //portfolioMap.put(name, this); + this.uniqueName = holder.getClass().getSimpleName() + "_" + name; + GameManager.getInstance().addPortfolio(this); if (owner instanceof PublicCompanyI) { @@ -303,6 +306,14 @@ return name; } + /** Get unique name (prefixed by the owners class type, to avoid Bank, Player and Company + * namespace clashes). + * @return + */ + public String getUniqueName () { + return uniqueName; + } + /** * Returns percentage that a portfolio contains of one company. * Modified: trunk/18xx/rails/game/ReportBuffer.java =================================================================== --- trunk/18xx/rails/game/ReportBuffer.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/ReportBuffer.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -14,12 +14,12 @@ /** * Class to write a log, and also to maintain a log message stack for writing to * the UI. - * + * * Each gameManager has one unique ReportBuffer, which is used by the public static methods. * Messages before the creation of that buffer are kept in an internal initial queue. - * + * * Also used for regression testing comparing the output of the report buffer. - * + * */ public final class ReportBuffer { /** @@ -28,7 +28,7 @@ * rails.game report. */ private List<String> reportQueue = new ArrayList<String>(); - + /** Another stack for messages that must "wait" for other messages */ private List<String> waitQueue = new ArrayList<String> (); @@ -44,7 +44,7 @@ private static final String DEFAULT_REPORT_EXTENSION = "txt"; static { - reportDirectory = Config.get("report.directory"); + reportDirectory = Config.get("report.directory").trim(); wantReport = Util.hasValue(reportDirectory); } @@ -69,7 +69,7 @@ private void clearReportQueue() { reportQueue.clear(); } - + private void addMessage (String message) { if (message != null) { if (message.equals("")) @@ -81,11 +81,11 @@ if (wantReport) writeToReport(message); } } - + private void writeToReport(String message) { /* Get out if we don't want a report */ - if (!Util.hasValue(reportDirectory) || !wantReport) return; + if (!wantReport) return; if (report == null) openReportFile(); @@ -97,6 +97,9 @@ private void openReportFile() { + /* Get out if we don't want a report */ + if (!wantReport) return; + /* Get any configured date/time pattern, or else set the default */ String reportFilenamePattern = Config.get("report.filename.date_time_pattern"); @@ -132,15 +135,15 @@ /** Get the current log buffer, and clear it */ public static String get() { ReportBuffer instance = getInstance(); - + // convert to String StringBuffer result = new StringBuffer(); - for (String msg:instance.getReportQueue()) + for (String msg:instance.getReportQueue()) result.append(msg).append("\n"); // clear current queue instance.clearReportQueue(); - + return result.toString(); } @@ -160,23 +163,23 @@ /** return the current buffer as list */ public static List<String> getAsList() { ReportBuffer instance = getInstance(); - - if (instance == null) + + if (instance == null) return initialQueue; else return instance.getReportQueue(); } - + /** clear the current buffer */ public static void clear() { ReportBuffer instance = getInstance(); - - if (instance == null) + + if (instance == null) initialQueue.clear(); else instance.clearReportQueue(); } - + private static ReportBuffer getInstance() { return GameManager.getInstance().getReportBuffer(); } Modified: trunk/18xx/rails/game/StockRound.java =================================================================== --- trunk/18xx/rails/game/StockRound.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/StockRound.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -196,14 +196,14 @@ if (!cert.isPresidentShare()) { price = comp.getIPOPrice() / unitsForPrice; if (price <= playerCash) { - possibleActions.add(new BuyCertificate(cert, from, - price)); + possibleActions.add(new BuyCertificate(comp, cert.getShare(), + from, price)); } } else if (!comp.hasStarted()) { if (comp.getIPOPrice() != 0) { price = comp.getIPOPrice() * cert.getShares() / unitsForPrice; if (price <= playerCash) { - possibleActions.add(new StartCompany(cert, price)); + possibleActions.add(new StartCompany(comp, price)); } } else { List<Integer> startPrices = new ArrayList<Integer>(); @@ -218,7 +218,7 @@ for (int i = 0; i < prices.length; i++) { prices[i] = startPrices.get(i); } - possibleActions.add(new StartCompany(cert, prices)); + possibleActions.add(new StartCompany(comp, prices)); } } } @@ -247,7 +247,7 @@ price = stockSpace.getPrice() / unitsForPrice; shareUnit = comp.getShareUnit(); maxNumberOfSharesToBuy - = maxAllowedNumberOfSharesToBuy(currentPlayer, comp, shareUnit); + = maxAllowedNumberOfSharesToBuy(currentPlayer, comp, shareUnit); /* Checks if the player can buy any shares of this company */ if (maxNumberOfSharesToBuy < 1) continue; @@ -296,7 +296,8 @@ } if (number > 0) { - possibleActions.add(new BuyCertificate(uniqueCerts[shares], + possibleActions.add(new BuyCertificate(comp, + uniqueCerts[shares].getShare(), from, price, number)); } @@ -320,7 +321,7 @@ if (!stockSpace.isNoCertLimit() && !mayPlayerBuyCertificate(currentPlayer, company, 1)) continue; if (company.getMarketPrice() <= playerCash) { - possibleActions.add(new BuyCertificate(cert, + possibleActions.add(new BuyCertificate(company, cert.getShare(), company.getPortfolio(), company.getMarketPrice())); } } @@ -524,7 +525,7 @@ * @return True if the company could be started. False indicates an error. */ public boolean startCompany(String playerName, StartCompany action) { - PublicCompanyI company = action.getCertificate().getCompany(); + PublicCompanyI company = action.getCompany(); int price = action.getPrice(); int shares = action.getNumberBought(); @@ -618,7 +619,7 @@ // All is OK, now start the company company.start(startSpace); - CashHolder priceRecipient = getSharePriceRecipient (cert, price); + CashHolder priceRecipient = getSharePriceRecipient (company, ipo, price); // Transfer the President's certificate cert.moveTo(currentPlayer.getPortfolio()); @@ -668,17 +669,18 @@ */ public boolean buyShares(String playerName, BuyCertificate action) { - PublicCertificateI cert = action.getCertificate(); - Portfolio from = cert.getPortfolio(); - String companyName = cert.getCompany().getName(); + PublicCompanyI company = action.getCompany(); + Portfolio from = action.getFromPortfolio(); + String companyName = company.getName(); int number = action.getNumberBought(); - int shares = number * cert.getShares(); - int shareUnit = cert.getShare(); + int shareUnit = company.getShareUnit(); + int sharePerCert = action.getSharePerCertificate(); + int share = number * sharePerCert; + int shares = share / shareUnit; String errMsg = null; int price = 0; int cost = 0; - PublicCompanyI company = null; currentPlayer = getCurrentPlayer(); @@ -748,6 +750,10 @@ // Check if player would not exceed the certificate limit. // (shortcut: assume 1 cert == 1 certificate) + PublicCertificateI cert = from.findCertificate(company, sharePerCert/shareUnit, false); + if (cert == null) { + log.fatal("Cannot find "+sharePerCert+"% of "+company.getName()+" in "+from.getName()); + } if (!currentSpace.isNoCertLimit() && !mayPlayerBuyCertificate(currentPlayer, company, number * cert.getCertificateCount())) { errMsg = @@ -791,7 +797,7 @@ // All seems OK, now buy the shares. moveStack.start(true); - CashHolder priceRecipient = getSharePriceRecipient (cert, cost); + CashHolder priceRecipient = getSharePriceRecipient (company, from, cost); if (number == 1) { ReportBuffer.add(LocalText.getText("BUY_SHARE_LOG", @@ -814,9 +820,9 @@ PublicCertificateI cert2; for (int i = 0; i < number; i++) { - cert2 = from.findCertificate(company, cert.getShares(), false); + cert2 = from.findCertificate(company, sharePerCert/shareUnit, false); if (cert2 == null) { - log.error("Cannot find " + companyName + " " + shareUnit + log.error("Cannot find " + companyName + " " + shareUnit*sharePerCert + "% share in " + from.getName()); } cert2.moveTo(currentPlayer.getPortfolio()); @@ -864,17 +870,16 @@ * @param cert * @return */ - protected CashHolder getSharePriceRecipient (PublicCertificateI cert, int price) { + protected CashHolder getSharePriceRecipient (PublicCompanyI comp, + Portfolio from, int price) { - Portfolio oldHolder = (Portfolio) cert.getHolder(); - PublicCompanyI comp; CashHolder recipient; - if ((comp = (cert).getCompany()).hasFloated() - && oldHolder == ipo + if (comp.hasFloated() + && from == ipo && comp.getCapitalisation() == PublicCompanyI.CAPITALISE_INCREMENTAL) { recipient = comp; } else { - recipient = oldHolder.getOwner(); + recipient = from.getOwner(); } return recipient; } Modified: trunk/18xx/rails/game/TreasuryShareRound.java =================================================================== --- trunk/18xx/rails/game/TreasuryShareRound.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/TreasuryShareRound.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -141,7 +141,7 @@ number--; if (number > 0) { - possibleActions.add(new BuyCertificate(cert, from, price, + possibleActions.add(new BuyCertificate(comp, cert.getShare(), from, price, number)); } } @@ -240,16 +240,16 @@ @Override public boolean buyShares(String playerName, BuyCertificate action) { - PublicCertificateI cert = action.getCertificate(); - Portfolio from = cert.getPortfolio(); - String companyName = cert.getCompany().getName(); + PublicCompanyI company = action.getCompany(); + Portfolio from = action.getFromPortfolio(); + String companyName = company.getName(); int number = action.getNumberBought(); - int shares = number * cert.getShares(); - int shareUnit = cert.getShare(); + int shareUnit = company.getShareUnit(); + int sharePerCert = action.getSharePerCertificate(); + int shares = number * sharePerCert; String errMsg = null; int price = 0; - PublicCompanyI company = null; Portfolio portfolio = null; currentPlayer = getCurrentPlayer(); @@ -359,7 +359,7 @@ moveStack.start(true); PublicCertificateI cert2; for (int i = 0; i < number; i++) { - cert2 = from.findCertificate(company, cert.getShares(), false); + cert2 = from.findCertificate(company, sharePerCert, false); executeTradeCertificate(cert2, portfolio, cert2.getShares() * price); } Modified: trunk/18xx/rails/game/action/BuyCertificate.java =================================================================== --- trunk/18xx/rails/game/action/BuyCertificate.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/action/BuyCertificate.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -16,10 +16,22 @@ public class BuyCertificate extends PossibleAction { // Server-side settings - transient protected PublicCertificateI certificate; - protected String certUniqueId; + + /* Some obsolete properties, which are only retained for backwards compatibility + * (i.e. to remain able to load older saved files). + * The certificate was in fact only used to find the below replacement + * attributes. It was NOT actually used to select the bought certificate! + */ + transient protected PublicCertificateI certificate = null; + protected String certUniqueId = null; + + /* Replacement for the above.*/ + transient protected PublicCompanyI company; + protected String companyName; + protected int sharePerCert; // Share % per buyable certificate. + transient protected Portfolio from; - protected String fromName; + protected String fromName; // Old: portfolio name. New: portfolio unique name. protected int price; protected int maximumNumber; @@ -28,30 +40,24 @@ public static final long serialVersionUID = 1L; - /** - * Common constructor. - */ - public BuyCertificate(PublicCertificateI certificate, Portfolio from, + public BuyCertificate(PublicCompanyI company, int sharePerCert, + Portfolio from, int price, int maximumNumber) { - this.certificate = certificate; - this.certUniqueId = certificate.getUniqueId(); // TODO: Must be - // replaced by a unique - // Id! + this.company = company; + this.sharePerCert = sharePerCert; this.from = from; - this.fromName = from.getName(); + this.fromName = from.getUniqueName(); this.price = price; this.maximumNumber = maximumNumber; + + companyName = company.getName(); } - /** Buy a certificate from some portfolio at the current price */ - //public BuyCertificate(PublicCertificateI certificate, Portfolio from) { - // this(certificate, from, certificate.getCertificatePrice(), 1); - //} - /** Buy a certificate from some portfolio at a given price */ - public BuyCertificate(PublicCertificateI certificate, Portfolio from, + public BuyCertificate(PublicCompanyI company, int sharePerCert, + Portfolio from, int price) { - this(certificate, from, price, 1); + this(company, sharePerCert, from, price, 1); } /** Required for deserialization */ @@ -61,10 +67,6 @@ return from; } - public String getFromName() { - return fromName; - } - /** * @return Returns the maximumNumber. */ @@ -79,13 +81,22 @@ return price; } - /** - * @return Returns the certificate. - */ - public PublicCertificateI getCertificate() { - return certificate; + public PublicCompanyI getCompany() { + return company; } + public String getCompanyName() { + return companyName; + } + + public int getSharePerCertificate() { + return sharePerCert; + } + + public int getSharesPerCertificate() { + return sharePerCert / company.getShareUnit(); + } + public int getNumberBought() { return numberBought; } @@ -106,26 +117,46 @@ public String toString() { StringBuffer text = new StringBuffer(); text.append("BuyCertificate: "); - if (numberBought > 1) { - text.append(numberBought).append(" of "); - } else if (numberBought == 0 && maximumNumber > 1) { - text.append("up to ").append(maximumNumber).append(" of "); - } - text.append(certificate.getName()).append(" from ").append( - from.getName()).append(" price=").append( - Bank.format(certificate.getShares() * price)); + if (acted) text.append("Bought "+numberBought +" of "); + if (maximumNumber > 1) text.append ("max."+maximumNumber+" of "); + text.append(sharePerCert).append("% ").append(companyName) + .append(" from ").append(from.getName()) + .append(" price=").append(Bank.format((sharePerCert/company.getShareUnit()) * price)); return text.toString(); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); + //in.defaultReadObject(); + // Custom reading for backwards compatibility + ObjectInputStream.GetField fields = in.readFields(); + certUniqueId = (String) fields.get("certUniqueId", null); + companyName = (String) fields.get("companyName", null); + fromName = (String) fields.get("fromName", fromName); + price = fields.get("price", price); + maximumNumber = fields.get("maximumNumber", maximumNumber); + sharePerCert = fields.get("sharePerCert", -1); + + numberBought = fields.get("numberBought", numberBought); + GameManagerI gameManager = GameManager.getInstance(); - certificate = PublicCertificate.getByUniqueId(certUniqueId); - from = gameManager.getPortfolioByName(fromName); + if (certUniqueId != null) { + // Old style + certificate = PublicCertificate.getByUniqueId(certUniqueId); + from = gameManager.getPortfolioByName(fromName); + company = certificate.getCompany(); + companyName = company.getName(); + sharePerCert = certificate.getShare(); + } else if (companyName != null) { + // New style (since Rails.1.3.1) + company = gameManager.getCompanyManager().getPublicCompany(companyName); + from = gameManager.getPortfolioByUniqueName(fromName); + // We don't need the certificate anymore. + } + } } Modified: trunk/18xx/rails/game/action/StartCompany.java =================================================================== --- trunk/18xx/rails/game/action/StartCompany.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/action/StartCompany.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -9,24 +9,28 @@ public static final long serialVersionUID = 1L; - public StartCompany(PublicCertificateI certificate, int[] prices, + public StartCompany(PublicCompanyI company, int[] prices, int maximumNumber) { - super(certificate, GameManager.getInstance().getBank().getIpo(), 0, maximumNumber); + super(company, company.getPresidentsShare().getShare(), + GameManager.getInstance().getBank().getIpo(), + 0, maximumNumber); this.startPrices = prices.clone(); } - public StartCompany(PublicCertificateI certificate, int[] startPrice) { - this(certificate, startPrice, 1); + public StartCompany(PublicCompanyI company, int[] startPrice) { + this(company, startPrice, 1); } - public StartCompany(PublicCertificateI certificate, int price, + public StartCompany(PublicCompanyI company, int price, int maximumNumber) { - super(certificate, GameManager.getInstance().getBank().getIpo(), 0, maximumNumber); + super(company, company.getPresidentsShare().getShare(), + GameManager.getInstance().getBank().getIpo(), + 0, maximumNumber); this.price = price; } - public StartCompany(PublicCertificateI certificate, int price) { - this(certificate, price, 1); + public StartCompany(PublicCompanyI company, int price) { + this(company, price, 1); } public int[] getStartPrices() { @@ -44,7 +48,7 @@ @Override public String toString() { StringBuffer text = new StringBuffer(); - text.append("StartCompany: ").append(certificate.getName()); + text.append("StartCompany: ").append(company.getName()); if (price > 0) { text.append(" price=").append(Bank.format(price)); if (numberBought > 1) { Modified: trunk/18xx/rails/game/move/ObjectMove.java =================================================================== --- trunk/18xx/rails/game/move/ObjectMove.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/move/ObjectMove.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -5,6 +5,8 @@ */ package rails.game.move; +import rails.util.Util; + /** * @author Erik Vos */ @@ -77,9 +79,18 @@ if (moveableObject == null) log.error("Token is null"); if (from == null) log.warn("From is null"); if (to == null) log.error("To is null"); - return "Move " + objectClassName + ": " + moveableObject.getName() - + " from " + (from == null ? from : from.getName()) + "["+fromPosition - + "] to " + to.getName() + "["+toPosition+"]"; + StringBuilder buf = new StringBuilder(); + + buf.append("Move ").append(objectClassName).append(": ").append(moveableObject.getName()) + .append(" from ").append(from == null ? from : from.getName()); + if (fromPosition != null) { + buf.append("[").append(Util.joinWithDelimiter(fromPosition, ",")).append("]"); + } + buf.append(" to ").append(to == null ? to : to.getName()); + if (toPosition != null) { + buf.append("[").append(Util.joinWithDelimiter(toPosition, ",")).append("]"); + } + return buf.toString(); } } Modified: trunk/18xx/rails/game/specific/_1835/StockRound_1835.java =================================================================== --- trunk/18xx/rails/game/specific/_1835/StockRound_1835.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/specific/_1835/StockRound_1835.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -12,7 +12,7 @@ import rails.util.LocalText; public class StockRound_1835 extends StockRound { - + /** * Constructor with the GameManager, will call super class (StockRound's) Constructor to initialize * @@ -22,19 +22,21 @@ public StockRound_1835 (GameManagerI aGameManager) { super (aGameManager); } - + /** Add nationalisations */ + @Override protected void setGameSpecificActions() { if (!mayCurrentPlayerBuyAnything()) return; if (companyBoughtThisTurnWrapper.getObject() != null) return; - + List<Player> otherPlayers = new ArrayList<Player>(); Portfolio holder; CashHolder owner; Player otherPlayer; int price; int cash = currentPlayer.getCash(); - + + // Nationalization for (PublicCompanyI company : companyManager.getAllPublicCompanies()) { if (!company.getTypeName().equalsIgnoreCase("Major")) continue; if (!company.hasFloated()) continue; @@ -49,7 +51,8 @@ if (!otherPlayers.contains(otherPlayer)) { price = (int)(1.5 * company.getCurrentPriceModel().getPrice().getPrice()); if (price <= cash) { - possibleActions.add(new BuyCertificate (cert, holder, + possibleActions.add(new BuyCertificate (company, cert.getShare(), + holder, (int)(1.5 * company.getCurrentPriceModel().getPrice().getPrice()), 1)); } @@ -61,10 +64,12 @@ } } + @Override public boolean checkAgainstHoldLimit(Player player, PublicCompanyI company, int number) { return true; } + @Override protected int getBuyPrice (BuyCertificate action, StockSpaceI currentSpace) { int price = currentSpace.getPrice(); if (action.getFromPortfolio().getOwner() instanceof Player) { @@ -72,9 +77,10 @@ } return price; } - + /** Share price goes down 1 space for any number of shares sold. */ + @Override protected void adjustSharePrice (PublicCompanyI company, int numberSold, boolean soldBefore) { // No more changes if it has already dropped if (!soldBefore) { Modified: trunk/18xx/rails/game/specific/_1856/StockRound_1856.java =================================================================== --- trunk/18xx/rails/game/specific/_1856/StockRound_1856.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/specific/_1856/StockRound_1856.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -85,16 +85,15 @@ } @Override - protected CashHolder getSharePriceRecipient(PublicCertificateI cert, int cost) { + protected CashHolder getSharePriceRecipient(PublicCompanyI company, Portfolio from, int price) { CashHolder recipient; - Portfolio oldHolder = (Portfolio) cert.getHolder(); - if (cost != 0 - && !cert.getCompany().getName().equalsIgnoreCase(PublicCompany_CGR.NAME) - && oldHolder == ipo) { + if (price != 0 + && !company.getName().equalsIgnoreCase(PublicCompany_CGR.NAME) + && from == ipo) { - PublicCompany_1856 comp = (PublicCompany_1856)(cert).getCompany(); + PublicCompany_1856 comp = (PublicCompany_1856)company; switch (comp.getTrainNumberAvailableAtStart()) { case 2: @@ -104,9 +103,9 @@ if (getSoldPercentage(comp) >= 50 && !comp.hasReachedDestination()) { recipient = bank; - comp.addMoneyInEscrow(cost); + comp.addMoneyInEscrow(price); ReportBuffer.addWaiting(LocalText.getText("HoldMoneyInEscrow", - Bank.format(cost), + Bank.format(price), Bank.format(comp.getMoneyInEscrow()), comp.getName() )); break; @@ -120,7 +119,7 @@ recipient = bank; } } else { - recipient = oldHolder.getOwner(); + recipient = from.getOwner(); } return recipient; } @@ -183,10 +182,10 @@ } else { // Player has enough cash if (cert1 != null && price1 <= cash) { - possibleActions.add(new BuyCertificate(cert1, ipo, price1)); + possibleActions.add(new BuyCertificate(cgr, 1, ipo, price1)); } if (cert2 != null && price2 <= cash) { - possibleActions.add(new BuyCertificate(cert2, pool, price2)); + possibleActions.add(new BuyCertificate(cgr, 1, pool, price2)); } } Modified: trunk/18xx/rails/game/specific/_18EU/StartCompany_18EU.java =================================================================== --- trunk/18xx/rails/game/specific/_18EU/StartCompany_18EU.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/specific/_18EU/StartCompany_18EU.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -29,8 +29,8 @@ public static final long serialVersionUID = 1L; - public StartCompany_18EU(PublicCertificateI certificate, int[] prices) { - super(certificate, prices, 1); + public StartCompany_18EU(PublicCompanyI company, int[] prices) { + super(company, prices, 1); } public void setMinorsToMerge(List<PublicCompanyI> minors) { Modified: trunk/18xx/rails/game/specific/_18EU/StockRound_18EU.java =================================================================== --- trunk/18xx/rails/game/specific/_18EU/StockRound_18EU.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/game/specific/_18EU/StockRound_18EU.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -149,7 +149,7 @@ prices[i] = startPrices.get(i); } StartCompany_18EU action = - new StartCompany_18EU(cert, prices); + new StartCompany_18EU(comp, prices); if (mustMergeMinor) { action.setMinorsToMerge(minors); } else { @@ -158,7 +158,8 @@ possibleActions.add(action); } } else if (comp.getMarketPrice() <= playerCash) { - possibleActions.add(new BuyCertificate(cert, from, + possibleActions.add(new BuyCertificate(comp, cert.getShare(), + from, comp.getMarketPrice())); } @@ -187,7 +188,7 @@ // Does the player have enough cash? if (playerCash < price) continue; - possibleActions.add(new BuyCertificate(cert, from, price, 1)); + possibleActions.add(new BuyCertificate(comp, cert.getShare(), from, price, 1)); } // Get any shares in company treasuries that can be bought @@ -207,7 +208,7 @@ if (!stockSpace.isNoCertLimit() && !mayPlayerBuyCertificate(currentPlayer, company, 1)) continue; if (company.getMarketPrice() <= playerCash) { - possibleActions.add(new BuyCertificate(cert, + possibleActions.add(new BuyCertificate(company, cert.getShare(), company.getPortfolio(), company.getMarketPrice())); } @@ -271,7 +272,7 @@ */ @Override public boolean startCompany(String playerName, StartCompany action) { - PublicCompanyI company = action.getCertificate().getCompany(); + PublicCompanyI company = action.getCompany(); int price = action.getPrice(); int shares = action.getNumberBought(); Modified: trunk/18xx/rails/ui/swing/GameStatus.java =================================================================== --- trunk/18xx/rails/ui/swing/GameStatus.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/ui/swing/GameStatus.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -509,14 +509,14 @@ addField(futureTrains, futureTrainsXOffset, futureTrainsYOffset, futureTrainsWidth, 1, 0, true); - // Train cost overview + // Train cost overview String text = gameUIManager.getGameManager().getTrainManager().getTrainCostOverview(); addField (new Caption(text), poolTrainsXOffset, newTrainsYOffset + 1, futureTrainsWidth + 2, 1, 0, true); dummyButton = new ClickField("", "", "", this, buySellGroup); } - + public void actionPerformed(ActionEvent actor) { JComponent source = (JComponent) actor.getSource(); List<PossibleAction> actions; @@ -589,13 +589,19 @@ PublicCertificateI cert; String companyName = ""; String playerName = ""; + int sharePerCert; + int sharesPerCert; + int shareUnit; for (PossibleAction action : actions) { buy = (BuyCertificate) action; - cert = buy.getCertificate(); + //cert = buy.getCertificate(); playerName = buy.getPlayerName (); - PublicCompanyI company = cert.getCompany(); + PublicCompanyI company = buy.getCompany(); companyName = company.getName(); + sharePerCert = buy.getSharePerCertificate(); + shareUnit = company.getShareUnit(); + sharesPerCert = sharePerCert / shareUnit; if (buy instanceof StartCompany) { @@ -608,9 +614,8 @@ for (int i = 0; i < startPrices.length; i++) { options.add(LocalText.getText("StartCompany", Bank.format(startPrices[i]), - cert.getShare(), - Bank.format(cert.getShares() - * startPrices[i]) )); + sharePerCert, + Bank.format(sharesPerCert * startPrices[i]) )); buyActions.add(buy); buyAmounts.add(startPrices[i]); } @@ -618,7 +623,7 @@ startPrices = new int[] {((StartCompany) buy).getPrice()}; options.add(LocalText.getText("StartCompanyFixed", companyName, - cert.getShare(), + sharePerCert, Bank.format(startPrices[0]) )); buyActions.add(buy); buyAmounts.add(startPrices[0]); @@ -627,20 +632,19 @@ } else { options.add(LocalText.getText("BuyCertificate", - cert.getShare(), - cert.getCompany().getName(), - cert.getPortfolio().getName(), - Bank.format(cert.getShares() - * buy.getPrice()) )); + sharePerCert, + companyName, + buy.getFromPortfolio().getName(), + Bank.format(sharesPerCert * buy.getPrice()) )); buyActions.add(buy); buyAmounts.add(1); for (int i = 2; i <= buy.getMaximumNumber(); i++) { options.add(LocalText.getText("BuyCertificates", i, - cert.getShare(), - cert.getCompany().getName(), - cert.getPortfolio().getName(), - Bank.format(i * cert.getShares() + sharePerCert, + companyName, + buy.getFromPortfolio().getName(), + Bank.format(i * sharesPerCert * buy.getPrice()) )); buyActions.add(buy); buyAmounts.add(i); @@ -683,7 +687,7 @@ } else if (startCompany) { chosenAction = buyActions.get(index); ((StartCompany) chosenAction).setStartPrice(buyAmounts.get(index)); - ((StartCompany) chosenAction).setNumberBought(((StartCompany) chosenAction).getCertificate().getShares()); + ((StartCompany) chosenAction).setNumberBought(((StartCompany) chosenAction).getSharesPerCertificate()); } else { chosenAction = buyActions.get(index); ((BuyCertificate) chosenAction).setNumberBought(buyAmounts.get(index)); @@ -767,7 +771,7 @@ treasurySharesCaption.setHighlight(true); } - PublicCertificateI cert; + PublicCompanyI company; Portfolio holder; int index; CashHolder owner; @@ -776,8 +780,8 @@ possibleActions.getType(BuyCertificate.class); if (buyableCerts != null) { for (BuyCertificate bCert : buyableCerts) { - cert = bCert.getCertificate(); - index = cert.getCompany().getPublicNumber(); + company = bCert.getCompany(); + index = company.getPublicNumber(); holder = bCert.getFromPortfolio(); owner = holder.getOwner(); if (holder == ipo) { @@ -792,7 +796,6 @@ } } - PublicCompanyI company; List<SellShares> sellableShares = possibleActions.getType(SellShares.class); if (sellableShares != null) { @@ -831,7 +834,7 @@ * Initializes the CashCorrectionActions */ public boolean initCashCorrectionActions() { - + // Clear all buttons for (int i = 0; i < nc; i++) { setCompanyCashButton(i, false, null); @@ -839,7 +842,7 @@ for (int j = 0; j < np; j++) { setPlayerCashButton(j, false, null); } - + List<CashCorrectionAction> actions = possibleActions.getType(CashCorrectionAction.class); @@ -860,9 +863,9 @@ } return (actions != null && !actions.isEmpty()); - + } - + public void setPriorityPlayer(int index) { for (int j = 0; j < np; j++) { @@ -990,7 +993,7 @@ } playerCash[i].setVisible(!clickable); playerCashButton[i].setVisible(clickable); - + if (action != null) playerCashButton[i].addPossibleAction(action); } Modified: trunk/18xx/rails/ui/swing/GameUIManager.java =================================================================== --- trunk/18xx/rails/ui/swing/GameUIManager.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/ui/swing/GameUIManager.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -130,7 +130,7 @@ } if (font != null) log.debug("Change text fonts globally to " + font.getName() + " / " + (boldStyle ? "Bold" : "Plain")); } - + String fontScale = Config.getGameSpecific("font.ui.scale"); if (Util.hasValue(fontScale)) { try { @@ -143,13 +143,13 @@ } public void gameUIInit() { - + imageLoader = new ImageLoader(); stockChart = new StockChart(this); reportWindow = new ReportWindow(gameManager); orWindow = new ORWindow(this); orUIManager = orWindow.getORUIManager(); - + String statusWindowClassName = getClassName(GuiDef.ClassName.STATUS_WINDOW); try { Class<? extends StatusWindow> statusWindowClass = @@ -230,7 +230,7 @@ // // return true; // -// } +// } // else if (gameManager.getBank().isJustBroken()) { // // statusWindow.reportBankBroken(); @@ -252,7 +252,7 @@ return true; } } - + // display the end of game report if (gameManager.isGameOver()) statusWindow.endOfGameReport(); @@ -412,8 +412,8 @@ orWindow.setVisible(true); orWindow.toFront(); } - - + + // Update the currently visible round window // "Switchable" rounds will be handled from subclasses of this class. if (StartRoundWindow.class.isAssignableFrom(activeWindow.getClass())) { @@ -554,7 +554,7 @@ public void dialogActionPerformed (boolean ready) { if (!ready) { - + if (checkGameSpecificDialogAction()) { ; } else if (currentDialog instanceof RadioButtonDialog @@ -567,7 +567,7 @@ if (index >= 0) { int price = action.getStartPrices()[index]; action.setStartPrice(price); - action.setNumberBought(action.getCertificate().getShares()); + action.setNumberBought(action.getSharesPerCertificate()); } else { // No selection done - no action return; @@ -669,12 +669,12 @@ if(font != null) { float newSize = font.getSize2D() * (float)scale; UIManager.put(key, new FontUIResource(font.deriveFont(newSize))); - } - } - } + } + } + } } - - + + public void exportGame(GameAction exportAction) { JFileChooser jfc = new JFileChooser(); String filename; @@ -699,8 +699,8 @@ processOnServer(exportAction); } } - - + + public void saveGame(GameAction saveAction) { JFileChooser jfc = new JFileChooser(); Modified: trunk/18xx/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java =================================================================== --- trunk/18xx/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -76,7 +76,7 @@ LocalText.getText("PleaseSelect"), LocalText.getText( "SelectMinorToMerge", - action.getCertificate().getCompany().getName()), + action.getCompanyName()), options, -1); setCurrentDialog(dialog, action); return; @@ -93,7 +93,7 @@ LocalText.getText("PleaseSelect"), LocalText.getText( "SelectHomeStation", - action.getCertificate().getCompany().getName()), + action.getCompanyName()), options, -1); setCurrentDialog(dialog, action); return; Modified: trunk/18xx/rails/util/Util.java =================================================================== --- trunk/18xx/rails/util/Util.java 2010-07-21 18:45:07 UTC (rev 1353) +++ trunk/18xx/rails/util/Util.java 2010-07-23 20:05:34 UTC (rev 1354) @@ -42,6 +42,15 @@ return b.toString(); } + public static String joinWithDelimiter (int[] sa, String delimiter) { + StringBuilder b = new StringBuilder(); + for (int s : sa) { + if (b.length() > 0) b.append(delimiter); + b.append(s); + } + return b.toString(); + } + public static int parseInt(String value) throws ConfigurationException { if (!hasValue(value)) return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |