From: Erik V. <ev...@us...> - 2008-11-03 15:55:07
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv17514/rails/game Modified Files: Phase.java PhaseI.java Log Message: Implemented varying flotation percentage for 1856. New generic Parameter property map in Phase. Index: Phase.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Phase.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Phase.java 4 Jun 2008 19:00:31 -0000 1.8 --- Phase.java 3 Nov 2008 15:55:00 -0000 1.9 *************** *** 42,45 **** --- 42,50 ---- /** Items to close if a phase gets activated */ protected List<Closeable> closedObjects = null; + + /** A HashMap to contain phase-dependent parameters + * by name and value. + */ + protected Map<String, String> parameters = null; // protected static boolean previousPrivateSellingAllowed = false; *************** *** 66,69 **** --- 71,80 ---- oneTrainPerTurn = defaults.oneTrainPerTurn; oneTrainPerTypePerTurn = defaults.oneTrainPerTypePerTurn; + if (defaults.parameters != null) { + this.parameters = new HashMap<String, String>(); + for (String key : defaults.parameters.keySet()) { + parameters.put(key, defaults.parameters.get(key)); + } + } } *************** *** 119,122 **** --- 130,142 ---- oneTrainPerTypePerTurn); } + + Tag parameterTag = tag.getChild("Parameters"); + if (parameterTag != null) { + if (parameters == null) parameters = new HashMap<String, String>(); + Map<String,String> attributes = parameterTag.getAttributes(); + for (String key : attributes.keySet()) { + parameters.put (key, attributes.get(key)); + } + } } *************** *** 191,194 **** --- 211,236 ---- closedObjects.add(object); } + + public String getParameterAsString (String key) { + if (parameters != null) { + return parameters.get(key); + } else { + return null; + } + } + + public int getParameterAsInteger (String key) { + String stringValue = getParameterAsString(key); + if (stringValue == null) { + return 0; + } + try { + return Integer.parseInt(stringValue); + } catch (Exception e) { + log.error ("Error while parsing parameter "+key+" in phase "+name, e); + return 0; + } + + } public String toString() { Index: PhaseI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PhaseI.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PhaseI.java 4 Jun 2008 19:00:30 -0000 1.5 --- PhaseI.java 3 Nov 2008 15:55:00 -0000 1.6 *************** *** 29,31 **** --- 29,34 ---- public int getOffBoardRevenueStep(); + + public String getParameterAsString (String key); + public int getParameterAsInteger (String key); } |