From: Stefan F. <ste...@us...> - 2010-05-18 21:36:20
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv11104/rails/algorithms Modified Files: NetworkTrain.java RevenueAdapter.java RevenueManager.java NetworkVertex.java Log Message: Added revenue modifier support for bonuses. Support for 1856 enabled. Index: NetworkVertex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkVertex.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** NetworkVertex.java 18 May 2010 04:12:22 -0000 1.10 --- NetworkVertex.java 18 May 2010 21:36:12 -0000 1.11 *************** *** 5,8 **** --- 5,9 ---- import java.util.Comparator; import java.util.HashSet; + import java.util.List; import java.util.Set; *************** *** 297,301 **** } } - /** --- 298,301 ---- *************** *** 320,325 **** return graph.removeVertex(oldVertex); } ! ! public static Point2D getVertexPoint2D(HexMap map, NetworkVertex vertex) { GUIHex guiHex = map.getHexByName(vertex.getHex().getName()); --- 320,339 ---- return graph.removeVertex(oldVertex); } ! ! /** ! * Returns all vertices in a specified collection of hexes ! */ ! public static Set<NetworkVertex> getVerticesByHex(Collection<NetworkVertex> vertices, Collection<MapHex> hexes) { ! log.info("hexes = " + hexes); ! Set<NetworkVertex> hexVertices = new HashSet<NetworkVertex>(); ! for (NetworkVertex vertex:vertices) { ! if (vertex.getHex() != null && hexes.contains(vertex.getHex())) { ! hexVertices.add(vertex); ! } ! } ! return hexVertices; ! } ! ! public static Point2D getVertexPoint2D(HexMap map, NetworkVertex vertex) { GUIHex guiHex = map.getHexByName(vertex.getHex().getName()); Index: RevenueManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RevenueManager.java 18 May 2010 04:12:22 -0000 1.1 --- RevenueManager.java 18 May 2010 21:36:12 -0000 1.2 *************** *** 40,63 **** List<Tag> modifierTags = tag.getChildren("StaticModifier"); ! for (Tag modifierTag:modifierTags) { ! // get classname ! String className = modifierTag.getAttributeAsString("class"); ! if (className == null) { ! throw new ConfigurationException(LocalText.getText( ! "ComponentHasNoClass", "StaticModifier")); ! } ! // create modifier ! RevenueStaticModifier modifier; ! try { ! modifier = (RevenueStaticModifier) Class.forName(className).newInstance(); ! } catch (Exception e) { ! throw new ConfigurationException(LocalText.getText( ! "ClassCannotBeInstantiated", className), e); } - // add them to the revenueManager - staticModifiers.add(modifier); - log.info("Added modifier " + className); } - } --- 40,64 ---- List<Tag> modifierTags = tag.getChildren("StaticModifier"); ! if (modifierTags != null) { ! for (Tag modifierTag:modifierTags) { ! // get classname ! String className = modifierTag.getAttributeAsString("class"); ! if (className == null) { ! throw new ConfigurationException(LocalText.getText( ! "ComponentHasNoClass", "StaticModifier")); ! } ! // create modifier ! RevenueStaticModifier modifier; ! try { ! modifier = (RevenueStaticModifier) Class.forName(className).newInstance(); ! } catch (Exception e) { ! throw new ConfigurationException(LocalText.getText( ! "ClassCannotBeInstantiated", className), e); ! } ! // add them to the revenueManager ! staticModifiers.add(modifier); ! log.info("Added modifier " + className); } } } *************** *** 71,74 **** --- 72,80 ---- } + public void addStaticModifier(RevenueStaticModifier modifier) { + staticModifiers.add(modifier); + log.info("Added modifier " + modifier); + } + void callStaticModifiers(RevenueAdapter revenueAdapter) { for (RevenueStaticModifier modifier:staticModifiers) { Index: NetworkTrain.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkTrain.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NetworkTrain.java 14 May 2010 15:19:57 -0000 1.6 --- NetworkTrain.java 18 May 2010 21:36:12 -0000 1.7 *************** *** 29,47 **** this.trainName = trainName; this.railsTrainType = trainType; } static NetworkTrain createFromRailsTrain(TrainI railsTrain){ ! int cities = railsTrain.getMajorStops(); ! int towns = railsTrain.getMinorStops(); ! boolean townsCostNothing = (railsTrain.getTownCountIndicator() == 0); ! int multiplyCities = railsTrain.getCityScoreFactor(); ! int multiplyTowns = railsTrain.getTownScoreFactor(); String trainName = railsTrain.getName(); TrainTypeI trainType = railsTrain.getType(); ! if (cities == 0 && towns == 0) { return null;// protection against pullman } else { ! return new NetworkTrain(cities, towns, townsCostNothing, multiplyCities, multiplyTowns, trainName, trainType); } --- 29,54 ---- this.trainName = trainName; this.railsTrainType = trainType; + log.info("Created NetworkTrain " + this.toString() + " / " + this.attributes()); } static NetworkTrain createFromRailsTrain(TrainI railsTrain){ ! int majors = railsTrain.getMajorStops(); ! int minors = railsTrain.getMinorStops(); ! if (railsTrain.getTownCountIndicator() == 0) { ! minors = 999; ! } ! int multiplyMajors = railsTrain.getCityScoreFactor(); ! int multiplyMinors = railsTrain.getTownScoreFactor(); ! boolean ignoreMinors = false; ! if (multiplyMinors == 0){ ! ignoreMinors = true; ! } String trainName = railsTrain.getName(); TrainTypeI trainType = railsTrain.getType(); ! if (majors == -1) { return null;// protection against pullman } else { ! return new NetworkTrain(majors, minors, ignoreMinors, multiplyMajors, multiplyMinors, trainName, trainType); } *************** *** 65,69 **** } else if (t.contains("D")) { log.info("RA: found Double Express train"); ! cities = Integer.parseInt(t.replace("D", "")); ignoreTowns = true; multiplyCities = 2; --- 72,76 ---- } else if (t.contains("D")) { log.info("RA: found Double Express train"); ! cities = Integer.parseInt(t.replace("D", "")); ignoreTowns = true; multiplyCities = 2; *************** *** 112,115 **** --- 119,132 ---- return railsTrainType; } + + public String attributes() { + StringBuffer attributes = new StringBuffer(); + attributes.append("majors = " + majors); + attributes.append(", minors = " + minors); + attributes.append(", ignoreMinors = " + ignoreMinors); + attributes.append(", mulitplyMajors = " + multiplyMajors); + attributes.append(", mulitplyMinors = " + multiplyMinors); + return attributes.toString(); + } public String toString() { Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** RevenueAdapter.java 18 May 2010 04:12:22 -0000 1.14 --- RevenueAdapter.java 18 May 2010 21:36:12 -0000 1.15 *************** *** 79,82 **** --- 79,86 ---- } + public PublicCompanyI getCompany() { + return company; + } + public PhaseI getPhase() { return phase; *************** *** 187,192 **** // add all static modifiers ! gameManager.getRevenueManager().callStaticModifiers(this); ! } private void defineVertexVisitSets() { --- 191,197 ---- // add all static modifiers ! if (gameManager.getRevenueManager() != null) { ! gameManager.getRevenueManager().callStaticModifiers(this); ! } } private void defineVertexVisitSets() { |