Update of /cvsroot/rails/18xx/rails/game/specific/_18AL
In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv28571/rails/game/specific/_18AL
Modified Files:
NamedTrainRevenueModifier.java
Log Message:
Fixed 18AL bug with named trains (3017592)
Index: NamedTrainRevenueModifier.java
===================================================================
RCS file: /cvsroot/rails/18xx/rails/game/specific/_18AL/NamedTrainRevenueModifier.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** NamedTrainRevenueModifier.java 26 May 2010 19:48:57 -0000 1.2
--- NamedTrainRevenueModifier.java 17 Jun 2010 22:03:05 -0000 1.3
***************
*** 2,6 ****
--- 2,8 ----
import java.util.ArrayList;
+ import java.util.Collection;
import java.util.List;
+ import java.util.Set;
import rails.algorithms.NetworkTrain;
***************
*** 14,17 ****
--- 16,20 ----
import rails.game.ConfigurationException;
import rails.game.GameManagerI;
+ import rails.game.MapHex;
import rails.game.TrainI;
import rails.util.Tag;
***************
*** 32,35 ****
--- 35,63 ----
}
+ private RevenueBonus defineBonus(RevenueAdapter revenueAdapter, NamedTrainToken token, boolean useLongname) {
+ RevenueBonus bonus;
+ if (useLongname) {
+ bonus = new RevenueBonus(token.getValue(), token.getLongName());
+ } else {
+ bonus = new RevenueBonus(token.getValue(), token.getName());
+ }
+
+ for (MapHex hex:token.getHexesToPass()) {
+ boolean stationWasFound = false;
+ for (NetworkVertex vertex:NetworkVertex.getVerticesByHex(revenueAdapter.getVertices(), hex)) {
+ if (!vertex.isStation()) continue;
+ bonus.addVertex(vertex);
+ stationWasFound = true;
+ }
+ // if for one vertex no station is found then the bonus is set null
+ if (!stationWasFound) {
+ bonus = null;
+ break;
+ }
+ }
+ return bonus;
+ }
+
+
public void modifyCalculator(RevenueAdapter revenueAdapter) {
// static modifier
***************
*** 43,52 ****
if (token == null) continue;
// 2. define revenue bonus
! RevenueBonus bonus = new RevenueBonus(token.getValue(), token.getName());
bonus.addTrain(train);
- for (NetworkVertex vertex:NetworkVertex.getVerticesByHexes(revenueAdapter.getVertices(), token.getHexesToPass())) {
- if (!vertex.isStation()) continue;
- bonus.addVertex(vertex);
- }
revenueAdapter.addRevenueBonus(bonus);
}
--- 71,77 ----
if (token == null) continue;
// 2. define revenue bonus
! RevenueBonus bonus = defineBonus(revenueAdapter, token, false);
! if (bonus == null) continue;
bonus.addTrain(train);
revenueAdapter.addRevenueBonus(bonus);
}
***************
*** 66,75 ****
// 3. there is only one special property in 18AL, thus get tokens from it
for (NamedTrainToken token:sp.get(0).getTokens()) {
! RevenueBonus bonus = new RevenueBonus(token.getValue(), token.getLongName());
! // 4. define vertices
! for (NetworkVertex vertex:NetworkVertex.getVerticesByHexes(revenueAdapter.getVertices(), token.getHexesToPass())) {
! if (!vertex.isStation()) continue;
! bonus.addVertex(vertex);
! }
bonuses.add(bonus);
bonusMaximum += token.getValue();
--- 91,96 ----
// 3. there is only one special property in 18AL, thus get tokens from it
for (NamedTrainToken token:sp.get(0).getTokens()) {
! RevenueBonus bonus = defineBonus(revenueAdapter, token, true);
! if (bonus == null) continue;
bonuses.add(bonus);
bonusMaximum += token.getValue();
|