From: Brett L. <wak...@us...> - 2010-02-03 05:38:02
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv24614/rails/game Modified Files: Phase.java PhaseI.java Bank.java PrivateCompanyI.java OperatingRound.java PrivateCompany.java Log Message: Apply patches from Stefan Frey <ste...@we...> to implement 1889. Index: PrivateCompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PrivateCompanyI.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PrivateCompanyI.java 8 Jan 2010 21:30:46 -0000 1.8 --- PrivateCompanyI.java 3 Feb 2010 05:37:54 -0000 1.9 *************** *** 25,29 **** * @return */ ! public int getRevenue(); /** --- 25,31 ---- * @return */ ! // sfy 1889: changed to IntegerArray ! public int[] getRevenue(); ! public int getRevenueByPhase(PhaseI phase); /** *************** *** 36,39 **** --- 38,45 ---- public void setHolder(Portfolio portfolio); + // sfy 1889: check if closeable + public boolean isCloseable(); + public List<String> getPreventClosingConditions(); + // Methods related to closure when special properties are exercised. public boolean closesIfAllExercised(); Index: PrivateCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PrivateCompany.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** PrivateCompany.java 31 Jan 2010 22:22:28 -0000 1.31 --- PrivateCompany.java 3 Feb 2010 05:37:54 -0000 1.32 *************** *** 16,20 **** protected int basePrice = 0; ! protected int revenue = 0; protected List<SpecialPropertyI> specialProperties = null; protected String auctionType; --- 16,21 ---- protected int basePrice = 0; ! // list of revenue sfy 1889 ! protected int[] revenue; protected List<SpecialPropertyI> specialProperties = null; protected String auctionType; *************** *** 26,29 **** --- 27,32 ---- protected boolean closeIfAnyExercised = false; protected boolean closeAtEndOfTurn = false; // E.g. 1856 W&SR + // Prevent closing conditions sfy 1889 + protected List<String> preventClosingConditions = null; protected String blockedHexesString = null; *************** *** 43,47 **** longName= tag.getAttributeAsString("longName", ""); basePrice = tag.getAttributeAsInteger("basePrice", 0); ! revenue = tag.getAttributeAsInteger("revenue", 0); // Blocked hexes (until bought by a company) --- 46,52 ---- longName= tag.getAttributeAsString("longName", ""); basePrice = tag.getAttributeAsInteger("basePrice", 0); ! ! // sfy 1889 changed to IntegerArray ! revenue = tag.getAttributeAsIntegerArray("revenue", new int[0]); // Blocked hexes (until bought by a company) *************** *** 103,109 **** } } } - - } catch (Exception e) { throw new ConfigurationException("Configuration error for Private " --- 108,123 ---- } } + /* start sfy 1889 */ + List<Tag> preventTags = closureTag.getChildren("PreventClosing"); + if (preventTags != null) { + for (Tag preventTag: preventTags) { + String conditionText = preventTag.getAttributeAsString("condition"); + if (conditionText != null) { + preventClosingConditions.add(conditionText); + } + } + } + /* end sfy 1889 */ } } catch (Exception e) { throw new ConfigurationException("Configuration error for Private " *************** *** 137,141 **** specialProperties = new ArrayList<SpecialPropertyI>(); ! } --- 151,157 ---- specialProperties = new ArrayList<SpecialPropertyI>(); ! ! /* start sfy 1889 */ ! preventClosingConditions = new ArrayList<String>(); } *************** *** 161,168 **** * @return Revenue */ ! public int getRevenue() { return revenue; } ! /** * @return Phase this Private closes --- 177,196 ---- * @return Revenue */ ! public int[] getRevenue() { return revenue; } ! ! // start: sfy 1889: new method ! public int getRevenueByPhase(PhaseI phase){ ! if (phase != null) { ! return revenue[Math.min( ! revenue.length, ! phase.getPrivatesRevenueStep()) - 1]; ! } else { ! return 0; ! } ! } ! // end: sfy 1889 ! /** * @return Phase this Private closes *************** *** 185,191 **** public void setClosed() { ! if (isClosed()) return; ! ! super.setClosed(); unblockHexes(); moveTo(GameManager.getInstance().getBank().getScrapHeap()); --- 213,220 ---- public void setClosed() { ! if (isClosed()) return; ! if (!isCloseable()) return; /* sfy 1889 */ ! ! super.setClosed(); unblockHexes(); moveTo(GameManager.getInstance().getBank().getScrapHeap()); *************** *** 207,211 **** } } ! /** * @param i --- 236,261 ---- } } ! ! /* start sfy 1889 */ ! public boolean isCloseable() { ! ! if (preventClosingConditions.isEmpty()) return true; ! ! if (preventClosingConditions.contains("doesNotClose")) { ! log.debug("Private Company "+getName()+" does not close (unconditional)."); ! return false; ! } ! if (preventClosingConditions.contains("ifOwnedByPlayer") ! && portfolio.getOwner() instanceof Player) { ! log.debug("Private Company "+getName()+" does not close, as it is owned by a player."); ! return false; ! } ! return true; ! } ! public List<String> getPreventClosingConditions() { ! return preventClosingConditions; ! } ! /* end sfy 1889 */ ! /** * @param i Index: Bank.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Bank.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Bank.java 31 Jan 2010 22:22:27 -0000 1.19 --- Bank.java 3 Feb 2010 05:37:54 -0000 1.20 *************** *** 200,203 **** return result; } ! } --- 200,212 ---- return result; } ! // start sfy 1889 for integerarrays ! public static String formatIntegerArray(int[] amountList) { ! StringBuilder result = new StringBuilder(); ! for (int i = 0; i < amountList.length;++i) { ! if (!(i == 0)) result.append(","); ! result.append(format(amountList[i])); ! } ! return result.toString(); ! } ! // end sfy 1889 } Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** OperatingRound.java 31 Jan 2010 22:22:28 -0000 1.94 --- OperatingRound.java 3 Feb 2010 05:37:54 -0000 1.95 *************** *** 124,128 **** if (((Portfolio)priv.getHolder()).getOwner().getClass() != Bank.class) { CashHolder recipient = ((Portfolio)priv.getHolder()).getOwner(); ! int revenue = priv.getRevenue(); if (count++ == 0) ReportBuffer.add(""); ReportBuffer.add(LocalText.getText("ReceivesFor", --- 124,128 ---- if (((Portfolio)priv.getHolder()).getOwner().getClass() != Bank.class) { CashHolder recipient = ((Portfolio)priv.getHolder()).getOwner(); ! int revenue = priv.getRevenueByPhase(getCurrentPhase()); // sfy 1889: revenue by phase if (count++ == 0) ReportBuffer.add(""); ReportBuffer.add(LocalText.getText("ReceivesFor", Index: PhaseI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PhaseI.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PhaseI.java 28 Aug 2009 20:49:20 -0000 1.7 --- PhaseI.java 3 Feb 2010 05:37:54 -0000 1.8 *************** *** 19,22 **** --- 19,24 ---- public boolean isPrivateSellingAllowed(); + + public int getPrivatesRevenueStep(); // sfy 1889 public boolean isTrainTradingAllowed(); Index: Phase.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Phase.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Phase.java 31 Jan 2010 22:22:28 -0000 1.17 --- Phase.java 3 Feb 2010 05:37:54 -0000 1.18 *************** *** 25,28 **** --- 25,30 ---- protected int offBoardRevenueStep = 1; + + protected int privatesRevenueStep = 1; // sfy 1889 protected boolean trainTradingAllowed = false; *************** *** 63,66 **** --- 65,69 ---- numberOfOperatingRounds = defaults.numberOfOperatingRounds; offBoardRevenueStep = defaults.offBoardRevenueStep; + privatesRevenueStep = defaults.privatesRevenueStep; trainTradingAllowed = defaults.trainTradingAllowed; oneTrainPerTurn = defaults.oneTrainPerTurn; *************** *** 96,99 **** --- 99,103 ---- privateSellingAllowed); privatesClose = privatesTag.getAttributeAsBoolean("close", false); + privatesRevenueStep = privatesTag.getAttributeAsInteger("revenueStep", privatesRevenueStep); // sfy 1889 } *************** *** 189,193 **** return privateSellingAllowed; } ! public boolean isTrainTradingAllowed() { return trainTradingAllowed; --- 193,200 ---- return privateSellingAllowed; } ! // sfy 1889 ! public int getPrivatesRevenueStep() { ! return privatesRevenueStep; ! } public boolean isTrainTradingAllowed() { return trainTradingAllowed; |