From: Erik V. <ev...@us...> - 2011-10-30 20:24:09
|
rails/game/OperatingRound.java | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) New commits: commit 8dd8adf3e2da0056bb7b254f3a0d796288d73b1d Author: Erik Vos <eri...@xs...> Date: Sun Oct 30 21:16:37 2011 +0100 Fix: Buying Coalfields right is now refused if the company does not have enough cash. Reported by Charles Strong. This is the easy fix. In fact, the option to buy this right should not be offered at all if the company lacks cash, but fixing that is a bit more complex and omitted for now. diff --git a/rails/game/OperatingRound.java b/rails/game/OperatingRound.java index 23af287..458a6a7 100644 --- a/rails/game/OperatingRound.java +++ b/rails/game/OperatingRound.java @@ -1353,21 +1353,35 @@ public class OperatingRound extends Round implements Observer { protected boolean buyRight (UseSpecialProperty action) { String errMsg = null; + String rightName = ""; + String rightValue = ""; + int cost = 0; SpecialPropertyI sp = action.getSpecialProperty(); - if (!(sp instanceof SpecialRight)) { - errMsg = "Wrong right property class: "+sp.toString(); - } - SpecialRight right = (SpecialRight) sp; - String rightName = right.getName(); - String rightValue = right.getValue(); + while (true) { + if (!(sp instanceof SpecialRight)) { + errMsg = "Wrong right property class: "+sp.toString(); + break; + } + + SpecialRight right = (SpecialRight) sp; + rightName = right.getName(); + rightValue = right.getValue(); + cost = right.getCost(); + + if (cost > 0 && cost > operatingCompany.get().getCash()) { + errMsg = LocalText.getText("NoMoney"); + break; + } + break; + } if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CannotBuyRight", action.getCompanyName(), rightName, - Bank.format(right.getCost()), + Bank.format(cost), errMsg)); return false; @@ -1376,12 +1390,12 @@ public class OperatingRound extends Round implements Observer { moveStack.start(true); operatingCompany.get().setRight(rightName, rightValue); - new CashMove (operatingCompany.get(), bank, right.getCost()); + if (cost > 0) new CashMove (operatingCompany.get(), bank, cost); ReportBuffer.add(LocalText.getText("BuysRight", operatingCompany.get().getName(), rightName, - Bank.format(right.getCost()))); + Bank.format(cost))); sp.setExercised(); |