Update of /cvsroot/rails/18xx/rails/game/specific/_18Kaas
In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19864/rails/game/specific/_18Kaas
Added Files:
RuhrRevenueModifier.java
Log Message:
Various updates to revenue calculation, especially RevenueStaticModifier and support for 18Kaas
--- NEW FILE: RuhrRevenueModifier.java ---
package rails.game.specific._18Kaas;
import java.util.HashSet;
import java.util.Set;
import org.apache.log4j.Logger;
import rails.algorithms.NetworkVertex;
import rails.algorithms.RevenueAdapter;
import rails.algorithms.RevenueBonus;
import rails.algorithms.RevenueStaticModifier;
import rails.game.ConfigurableComponentI;
import rails.game.ConfigurationException;
import rails.game.GameManagerI;
import rails.util.Tag;
public class RuhrRevenueModifier implements RevenueStaticModifier, ConfigurableComponentI {
protected static Logger log =
Logger.getLogger(RuhrRevenueModifier.class.getPackage().getName());
private boolean doublesOnlyMajors;
public void configureFromXML(Tag tag) throws ConfigurationException {
// does nothing
}
public void finishConfiguration(GameManagerI parent)
throws ConfigurationException {
doublesOnlyMajors = parent.getGameOption("RuhrgebiedDoublesOnlyMajors").equalsIgnoreCase("yes");
log.debug("Finish configuration of RuhrRevenueModifier, doublesOnlyMajors = " + doublesOnlyMajors);
}
// creates revenueBonuses that double the value of each station/value vertex
public void modifyCalculator(RevenueAdapter revenueAdapter) {
Set<NetworkVertex> ruhrGebied = new HashSet<NetworkVertex>();
for (NetworkVertex vertex:revenueAdapter.getVertices()) {
// 1. get all vertices that point to Ruhrgebied
if (vertex.getCityName() != null && vertex.getCityName().equals("Ruhrgebied")){
ruhrGebied.add(vertex);
}
}
// 2. add revenue bonuses for stations
for (NetworkVertex vertex:revenueAdapter.getVertices()) {
if (!ruhrGebied.contains(vertex) && vertex.isStation() && (vertex.isMajor() || !doublesOnlyMajors)) {
for (NetworkVertex ruhrVertex:ruhrGebied) {
RevenueBonus bonus = new RevenueBonus(vertex.getValue(), "Ruhr/" + vertex.toString());
bonus.addVertex(vertex);
bonus.addVertex(ruhrVertex);
revenueAdapter.addRevenueBonus(bonus);
}
}
}
}
}
|