From: Erik V. <ev...@us...> - 2009-01-14 20:45:23
|
Update of /cvsroot/rails/18xx/rails/game/action In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv24082/rails/game/action Modified Files: SetDividend.java Log Message: Added 1856 loan interest payment (from all possible sources). Index: SetDividend.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/SetDividend.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SetDividend.java 4 Jun 2008 19:00:29 -0000 1.4 --- SetDividend.java 14 Jan 2009 20:45:07 -0000 1.5 *************** *** 1,7 **** --- 1,11 ---- package rails.game.action; + import java.io.IOException; + import java.io.ObjectInputStream; import java.util.Arrays; import rails.game.Bank; + import rails.game.Game; + import rails.util.Util; /** *************** *** 11,17 **** * back-end; in that case, the user can only select the earnings distribution * method. ! * * @author Erik Vos ! * */ public class SetDividend extends PossibleORAction implements Cloneable { --- 15,21 ---- * back-end; in that case, the user can only select the earnings distribution * method. ! * * @author Erik Vos ! * */ public class SetDividend extends PossibleORAction implements Cloneable { *************** *** 27,35 **** new String[] { "WITHHOLD", "SPLIT", "PAYOUT" }; /** * The revenue as proposed by the back-end. Currently this is always the * previous revenue. In the future, this could be the calculated revenue. */ ! private int presetRevenue; /** --- 31,40 ---- new String[] { "WITHHOLD", "SPLIT", "PAYOUT" }; + /*--- Server-side settings ---*/ /** * The revenue as proposed by the back-end. Currently this is always the * previous revenue. In the future, this could be the calculated revenue. */ ! protected int presetRevenue; /** *************** *** 39,46 **** * in 1844, the user may opt for less that maximum revenue is some cases). */ ! private boolean mayUserSetRevenue; ! ! /** The revenue as set (or accepted, or just seen) by the user. */ ! private int actualRevenue; /** --- 44,48 ---- * in 1844, the user may opt for less that maximum revenue is some cases). */ ! protected boolean mayUserSetRevenue; /** *************** *** 49,56 **** * most games). */ ! private int[] allowedRevenueAllocations; /** The revenue destination selected by the user (if he has a choice at all). */ ! private int revenueAllocation; public static final long serialVersionUID = 1L; --- 51,70 ---- * most games). */ ! protected int[] allowedRevenueAllocations; ! ! /** Cash that should be minimally raised as revenue ! * (for instance, to pay loan interest as in 1856). ! * If actual revenue is below this value, the dividend will be zero, ! * and no dividend allocation should be requested. ! * */ ! protected int requiredCash = 0; ! ! /*--- Client-side settings ---*/ ! ! /** The revenue as set (or accepted, or just seen) by the user. */ ! protected int actualRevenue; /** The revenue destination selected by the user (if he has a choice at all). */ ! protected int revenueAllocation; public static final long serialVersionUID = 1L; *************** *** 58,65 **** public SetDividend(int presetRevenue, boolean mayUserSetRevenue, int[] allowedAllocations) { super(); this.presetRevenue = presetRevenue; this.mayUserSetRevenue = mayUserSetRevenue; ! this.allowedRevenueAllocations = (int[]) allowedAllocations.clone(); if (allowedRevenueAllocations.length == 1) { revenueAllocation = allowedRevenueAllocations[0]; --- 72,85 ---- public SetDividend(int presetRevenue, boolean mayUserSetRevenue, int[] allowedAllocations) { + this (presetRevenue, mayUserSetRevenue, allowedAllocations, 0); + } + + public SetDividend(int presetRevenue, boolean mayUserSetRevenue, + int[] allowedAllocations, int requiredCash) { super(); this.presetRevenue = presetRevenue; this.mayUserSetRevenue = mayUserSetRevenue; ! this.allowedRevenueAllocations = allowedAllocations.clone(); ! this.requiredCash = requiredCash; if (allowedRevenueAllocations.length == 1) { revenueAllocation = allowedRevenueAllocations[0]; *************** *** 70,76 **** /** Clone an instance (used by clone) */ ! private SetDividend(SetDividend action) { this(action.presetRevenue, action.mayUserSetRevenue, ! action.allowedRevenueAllocations); } --- 90,97 ---- /** Clone an instance (used by clone) */ ! protected SetDividend(SetDividend action) { this(action.presetRevenue, action.mayUserSetRevenue, ! action.allowedRevenueAllocations, ! action.requiredCash); } *************** *** 98,101 **** --- 119,126 ---- } + public int getRequiredCash() { + return requiredCash; + } + public void setRevenueAllocation(int allocation) { revenueAllocation = allocation; *************** *** 114,117 **** --- 139,143 ---- } + @Override public Object clone() { *************** *** 122,125 **** --- 148,152 ---- } + @Override public boolean equals(PossibleAction action) { if (!(action instanceof SetDividend)) return false; *************** *** 128,138 **** && a.presetRevenue == presetRevenue && a.mayUserSetRevenue == mayUserSetRevenue && Arrays.equals(a.allowedRevenueAllocations, allowedRevenueAllocations); } public String toString() { StringBuffer b = new StringBuffer(); ! b.append("SetDividend: ").append(company.getName()); if (mayUserSetRevenue) { b.append(", settable, previous=").append(Bank.format(presetRevenue)); --- 155,167 ---- && a.presetRevenue == presetRevenue && a.mayUserSetRevenue == mayUserSetRevenue + && a.requiredCash == requiredCash && Arrays.equals(a.allowedRevenueAllocations, allowedRevenueAllocations); } + @Override public String toString() { StringBuffer b = new StringBuffer(); ! b.append(getClass().getSimpleName()).append(": ").append(company.getName()); if (mayUserSetRevenue) { b.append(", settable, previous=").append(Bank.format(presetRevenue)); *************** *** 150,156 **** --- 179,207 ---- b.append(" chosen=").append(allocationNameKeys[revenueAllocation]); } + if (requiredCash > 0) { + b.append(" requiredCash="+requiredCash); + } return b.toString(); } + /** Deserialize */ + @SuppressWarnings("unchecked") + private void readObject(ObjectInputStream in) throws IOException, + ClassNotFoundException { + + // Custom deserialization for backwards compatibility + ObjectInputStream.GetField fields = in.readFields(); + presetRevenue = fields.get("presetRevenue", presetRevenue); + mayUserSetRevenue = fields.get("mayUserSetRevenue", mayUserSetRevenue); + allowedRevenueAllocations = (int[]) fields.get("allowedRevenueAllocations", allowedRevenueAllocations); + requiredCash = fields.get("requiredCash", 0); + actualRevenue = fields.get("actualRevenue", actualRevenue); + revenueAllocation = fields.get("revenueAllocation", revenueAllocation); + + if (Util.hasValue(companyName)) { + company = Game.getCompanyManager().getPublicCompany(companyName); + } + } + } |