From: <ste...@us...> - 2010-08-15 19:40:54
|
Revision: 1389 http://rails.svn.sourceforge.net/rails/?rev=1389&view=rev Author: stefanfrey Date: 2010-08-15 19:40:47 +0000 (Sun, 15 Aug 2010) Log Message: ----------- Added display of revenue bonus in non-detailed revenue results Some refactoring of the dynamic revenue modifier Modified Paths: -------------- trunk/18xx/LocalisedText.properties trunk/18xx/rails/algorithms/RevenueAdapter.java trunk/18xx/rails/algorithms/RevenueDynamicModifier.java trunk/18xx/rails/game/specific/_18AL/NamedTrainRevenueModifier.java trunk/18xx/rails/game/specific/_18EU/PullmanRevenueModifier.java Modified: trunk/18xx/LocalisedText.properties =================================================================== --- trunk/18xx/LocalisedText.properties 2010-08-15 12:09:08 UTC (rev 1388) +++ trunk/18xx/LocalisedText.properties 2010-08-15 19:40:47 UTC (rev 1389) @@ -492,7 +492,9 @@ REPORT_COMMENT_TITLE=Add Comment REPORT_COMMENT_ASK=Add a comment to the previous action REVENUE=Revenue +RevenueBonus=Bonus(es) = {0} RevenueCalculation=support for revenue calculation +RevenueNoRun=No Optimal Run RevenueStations=, Cities = {0}, Towns = {1} RevenueStationsIgnoreMinors=, Cities = {0} ReceivesFor={0} receives {1} for {2}. Modified: trunk/18xx/rails/algorithms/RevenueAdapter.java =================================================================== --- trunk/18xx/rails/algorithms/RevenueAdapter.java 2010-08-15 12:09:08 UTC (rev 1388) +++ trunk/18xx/rails/algorithms/RevenueAdapter.java 2010-08-15 19:40:47 UTC (rev 1389) @@ -19,12 +19,12 @@ import rails.game.GameManagerI; import rails.game.MapHex; -import rails.game.MapManager; import rails.game.PhaseI; import rails.game.PublicCompanyI; import rails.game.TrainI; import rails.game.TrainTypeI; import rails.ui.swing.hexmap.HexMap; +import rails.util.LocalText; public final class RevenueAdapter implements Runnable { @@ -587,7 +587,7 @@ int dynamicEvaluation() { int value = 0; for (RevenueDynamicModifier modifier:dynamicModifiers) { - value += modifier.evaluationValue(this); + value += modifier.evaluationValue(this.getCurrentRun()); } return value; } @@ -598,7 +598,7 @@ int dynamicPrediction() { int value = 0; for (RevenueDynamicModifier modifier:dynamicModifiers) { - value += modifier.predictionValue(this); + value += modifier.predictionValue(); } return value; } @@ -630,7 +630,7 @@ public String getOptimalRunPrettyPrint(boolean includeDetails) { List<RevenueTrainRun> listRuns = getOptimalRun(); - if (listRuns== null) return "No Optimal Run"; + if (listRuns== null) return LocalText.getText("RevenueNoRun"); StringBuffer runPrettyPrint = new StringBuffer(); for (RevenueTrainRun run:listRuns) { @@ -641,12 +641,19 @@ runPrettyPrint.append("; "); } if (includeDetails) { - // add dynamic Modifier for (RevenueDynamicModifier modifier:dynamicModifiers) { runPrettyPrint.append(modifier.prettyPrint(this)); } + } else { + int dynamicBonuses = 0; + for (RevenueDynamicModifier modifier:dynamicModifiers) { + dynamicBonuses += modifier.evaluationValue(this.getOptimalRun()); + } + if (dynamicBonuses != 0) { + runPrettyPrint.append("; " + + LocalText.getText("RevenueBonus", dynamicBonuses)); + } } - return runPrettyPrint.toString(); } Modified: trunk/18xx/rails/algorithms/RevenueDynamicModifier.java =================================================================== --- trunk/18xx/rails/algorithms/RevenueDynamicModifier.java 2010-08-15 12:09:08 UTC (rev 1388) +++ trunk/18xx/rails/algorithms/RevenueDynamicModifier.java 2010-08-15 19:40:47 UTC (rev 1389) @@ -1,4 +1,7 @@ package rails.algorithms; + +import java.util.List; + /** * Classes that change properties of the revenue calculation * after the actual calculation started implement the dynamic modifier. @@ -15,12 +18,12 @@ public boolean prepareModifier(RevenueAdapter revenueAdapter); /** returns the value used for prediction */ - public int predictionValue(RevenueAdapter revenueAdapter); + public int predictionValue(); - /** returns the value used for evaluation */ - public int evaluationValue(RevenueAdapter revenueAdapter); + /** returns the value used for evaluation (at the run supplied) */ + public int evaluationValue(List<RevenueTrainRun> runs); - /** returns the prettyPrintName */ - public String prettyPrint(RevenueAdapter revenueAdapter); + /** returns the results as pretty prints */ + public String prettyPrint(RevenueAdapter adapter); } Modified: trunk/18xx/rails/game/specific/_18AL/NamedTrainRevenueModifier.java =================================================================== --- trunk/18xx/rails/game/specific/_18AL/NamedTrainRevenueModifier.java 2010-08-15 12:09:08 UTC (rev 1388) +++ trunk/18xx/rails/game/specific/_18AL/NamedTrainRevenueModifier.java 2010-08-15 19:40:47 UTC (rev 1389) @@ -98,14 +98,13 @@ return true; } - public int predictionValue(RevenueAdapter revenueAdapter) { + public int predictionValue() { return bonusMaximum; } - public int evaluationValue(RevenueAdapter revenueAdapter) { - List<RevenueTrainRun> runs = revenueAdapter.getCurrentRun(); + public int evaluationValue(List<RevenueTrainRun> runs) { int bonusValue = 0; - // due to the geography each train can only score one bonus + // due to the geography (off-map areas!) each train can only score one bonus for (RevenueBonus bonus:bonuses) { for (RevenueTrainRun run:runs) { if (run.getUniqueVertices().containsAll(bonus.getVertices())) { @@ -123,7 +122,7 @@ for (RevenueBonus bonus:bonuses) { for (RevenueTrainRun run:runs) { if (run.getUniqueVertices().containsAll(bonus.getVertices())) { - prettyPrint.append(bonus.getName() + ": " + bonus.getValue() + "\n"); + prettyPrint.append(bonus.getName() + " = " + bonus.getValue() + "\n"); continue; // each bonus can only be scored once } } Modified: trunk/18xx/rails/game/specific/_18EU/PullmanRevenueModifier.java =================================================================== --- trunk/18xx/rails/game/specific/_18EU/PullmanRevenueModifier.java 2010-08-15 12:09:08 UTC (rev 1388) +++ trunk/18xx/rails/game/specific/_18EU/PullmanRevenueModifier.java 2010-08-15 19:40:47 UTC (rev 1389) @@ -32,8 +32,8 @@ return true; } - public int evaluationValue(RevenueAdapter revenueAdapter) { - return pullmanValue(revenueAdapter.getCurrentRun()); + public int evaluationValue(List<RevenueTrainRun> runs) { + return pullmanValue(runs); } private int pullmanValue(List<RevenueTrainRun> trainRuns) { @@ -45,12 +45,12 @@ return maximum; } - public int predictionValue(RevenueAdapter revenueAdapter) { + public int predictionValue() { return maxValue; } public String prettyPrint(RevenueAdapter revenueAdapter) { - return LocalText.getText("Pullman") + ": " + pullmanValue(revenueAdapter.getOptimalRun()); + return LocalText.getText("Pullman") + " = " + pullmanValue(revenueAdapter.getOptimalRun()); } private int maximumMajorValue(Collection<NetworkVertex> vertices) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |