From: Erik V. <ev...@us...> - 2009-09-04 18:56:30
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv28727/rails/game Modified Files: Round.java StockRound.java Player.java GameManagerI.java GameManager.java Log Message: Moved player share limit from Player to GameManager Index: Player.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Player.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Player.java 3 Sep 2009 21:36:53 -0000 1.19 --- Player.java 4 Sep 2009 18:56:16 -0000 1.20 *************** *** 10,23 **** public class Player implements CashHolder, Comparable<Player> { - /** Default limit to percentage of a company a player may hold */ - private static final int DEFAULT_PLAYER_SHARE_LIMIT = 60; - public static int MAX_PLAYERS = 8; public static int MIN_PLAYERS = 2; - private static int playerShareLimit = DEFAULT_PLAYER_SHARE_LIMIT; - // May need to become an array - private String name = ""; --- 10,17 ---- *************** *** 48,77 **** } - /** - * Return the number of <i>additional</i> shares of a certain company and - * of a certain size that a player may buy, given the share "hold limit" per - * company, that is the percentage of shares of one company that a player - * 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%). - * @return The maximum number of such shares that would not let the player - * overrun the per-company share hold limit. - */ - public int maxAllowedNumberOfSharesToBuy(PublicCompanyI company, - int shareSize) { - - int limit; - if (!company.hasStarted()) { - limit = playerShareLimit; - } else { - limit = - company.getCurrentSpace().isNoHoldLimit() ? 100 - : playerShareLimit; - } - return (limit - portfolio.getShare(company)) / shareSize; - } - /** * @return Returns the player's portfolio. --- 42,45 ---- *************** *** 202,212 **** } - public static void setShareLimit(int percentage) { - playerShareLimit = percentage; - } - - public static int getShareLimit() { - return playerShareLimit; - } /** * Compare Players by their total worth, in descending order. This method --- 170,173 ---- Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** GameManager.java 4 Sep 2009 18:40:30 -0000 1.47 --- GameManager.java 4 Sep 2009 18:56:16 -0000 1.48 *************** *** 212,216 **** Tag shareLimitTag = tag.getChild("PlayerShareLimit"); if (shareLimitTag != null) { ! Player.setShareLimit(shareLimitTag.getAttributeAsInteger("percentage")); } --- 212,216 ---- Tag shareLimitTag = tag.getChild("PlayerShareLimit"); if (shareLimitTag != null) { ! playerShareLimit = shareLimitTag.getAttributeAsInteger("percentage", playerShareLimit); } *************** *** 868,872 **** } ! /* (non-Javadoc) * @see rails.game.GameManagerI#getAllPublicCompanies() */ --- 868,876 ---- } ! public int getPlayerShareLimit() { ! return playerShareLimit; ! } ! ! /* (non-Javadoc) * @see rails.game.GameManagerI#getAllPublicCompanies() */ Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GameManagerI.java 4 Sep 2009 18:40:30 -0000 1.5 --- GameManagerI.java 4 Sep 2009 18:56:16 -0000 1.6 *************** *** 151,154 **** --- 151,156 ---- public ModelObject getPlayerCertificateLimitModel (); + public int getPlayerShareLimit(); + public abstract String getHelp(); Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Round.java 3 Sep 2009 21:36:53 -0000 1.20 --- Round.java 4 Sep 2009 18:56:15 -0000 1.21 *************** *** 361,363 **** --- 361,368 ---- } + public GameManagerI getGameManager() { + return gameManager; + } + + } Index: StockRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockRound.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** StockRound.java 4 Sep 2009 18:40:30 -0000 1.40 --- StockRound.java 4 Sep 2009 18:56:15 -0000 1.41 *************** *** 160,164 **** comp = cert.getCompany(); if (isSaleRecorded(currentPlayer, comp)) continue; ! if (currentPlayer.maxAllowedNumberOfSharesToBuy(comp, cert.getShare()) < 1) continue; shares = cert.getShares(); --- 160,164 ---- comp = cert.getCompany(); if (isSaleRecorded(currentPlayer, comp)) continue; ! if (maxAllowedNumberOfSharesToBuy(currentPlayer, comp, cert.getShare()) < 1) continue; shares = cert.getShares(); *************** *** 209,213 **** comp = cert.getCompany(); if (isSaleRecorded(currentPlayer, comp)) continue; ! if (currentPlayer.maxAllowedNumberOfSharesToBuy(comp, cert.getShare()) < 1) continue; stockSpace = comp.getCurrentSpace(); --- 209,213 ---- comp = cert.getCompany(); if (isSaleRecorded(currentPlayer, comp)) continue; ! if (maxAllowedNumberOfSharesToBuy(currentPlayer, comp, cert.getShare()) < 1) continue; stockSpace = comp.getCurrentSpace(); *************** *** 253,257 **** if (isSaleRecorded(currentPlayer, company)) continue; if (!mayPlayerBuyCompanyShare(currentPlayer, company, 1)) continue; ! if (currentPlayer.maxAllowedNumberOfSharesToBuy(company, certs.get(0).getShare()) < 1) continue; stockSpace = company.getCurrentSpace(); --- 253,257 ---- if (isSaleRecorded(currentPlayer, company)) continue; if (!mayPlayerBuyCompanyShare(currentPlayer, company, 1)) continue; ! if (maxAllowedNumberOfSharesToBuy(currentPlayer, company, certs.get(0).getShare()) < 1) continue; stockSpace = company.getCurrentSpace(); *************** *** 1214,1222 **** public boolean mayPlayerBuyCompanyShare(Player player, PublicCompanyI company, int number) { // Check for per-company share limit ! if (player.getPortfolio().getShare(company) + number * company.getShareUnit() > Player.getShareLimit() && !company.getCurrentSpace().isNoHoldLimit()) return false; return true; } public static void setNoSaleInFirstSR() { --- 1214,1251 ---- public boolean mayPlayerBuyCompanyShare(Player player, PublicCompanyI company, int number) { // Check for per-company share limit ! if (player.getPortfolio().getShare(company) ! + number * company.getShareUnit() ! > gameManager.getPlayerShareLimit() && !company.getCurrentSpace().isNoHoldLimit()) return false; return true; } + /** + * Return the number of <i>additional</i> shares of a certain company and + * of a certain size that a player may buy, given the share "hold limit" per + * company, that is the percentage of shares of one company that a player + * 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%). + * @return The maximum number of such shares that would not let the player + * overrun the per-company share hold limit. + */ + public int maxAllowedNumberOfSharesToBuy(Player player, + PublicCompanyI company, + int shareSize) { + + int limit; + if (!company.hasStarted()) { + limit = gameManager.getPlayerShareLimit(); + } else { + limit = + company.getCurrentSpace().isNoHoldLimit() ? 100 + : gameManager.getPlayerShareLimit(); + } + return (limit - player.getPortfolio().getShare(company)) / shareSize; + } + public static void setNoSaleInFirstSR() { |