Update of /cvsroot/rails/18xx/rails/game
In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv11104/rails/game
Modified Files:
Bonus.java
Log Message:
Added revenue modifier support for bonuses. Support for 1856 enabled.
Index: Bonus.java
===================================================================
RCS file: /cvsroot/rails/18xx/rails/game/Bonus.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Bonus.java 21 Mar 2010 17:43:50 -0000 1.8
--- Bonus.java 18 May 2010 21:36:12 -0000 1.9
***************
*** 3,6 ****
--- 3,14 ----
import java.util.List;
+ 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;
/**
***************
*** 16,20 ****
*
*/
! public class Bonus implements Closeable {
private PublicCompanyI owner;
--- 24,28 ----
*
*/
! public class Bonus implements Closeable, RevenueStaticModifier {
private PublicCompanyI owner;
***************
*** 31,34 ****
--- 39,45 ----
this.value = value;
this.locations = locations;
+
+ // add them to the call list of the RevenueManager
+ GameManager.getInstance().getRevenueManager().addStaticModifier(this);
}
***************
*** 113,115 ****
--- 124,143 ----
return toString();
}
+
+ /**
+ * Add bonus value to revenue calculator
+ */
+ public void modifyCalculator(RevenueAdapter revenueAdapter) {
+ // 1. check operating company
+ if (owner != revenueAdapter.getCompany()) return;
+
+ // 2. find vertices to hex
+ Set<NetworkVertex> bonusVertices = NetworkVertex.getVerticesByHex(revenueAdapter.getVertices(), locations);
+ for (NetworkVertex bonusVertex:bonusVertices) {
+ if (!bonusVertex.isStation()) continue;
+ RevenueBonus bonus = new RevenueBonus(value, name);
+ bonus.addVertex(bonusVertex);
+ revenueAdapter.addRevenueBonus(bonus);
+ }
+ }
}
|