From: Stefan F. <ste...@us...> - 2010-02-14 20:48:23
|
Update of /cvsroot/rails/18xx/rails/game/correct In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv21890/rails/game/correct Added Files: CorrectionAction.java OperatingCost.java CorrectCash.java CorrectCashI.java Log Message: Added NoMapMode as GameOption. This mode skips LayTile and LayTrack actions and replaces those by more generic OperatingCosts actions. Currently only a non-strict mode is supported, thus "illegal" actions are possible. Option only tested and active for 1889 and 1835. Others to follow. --- NEW FILE: CorrectionAction.java --- package rails.game.correct; import rails.game.*; /** * Interface to implement for all non-correction action. * * * @author freystef * */ interface CorrectionAction { public boolean isInCorrectionMenu(); } --- NEW FILE: OperatingCost.java --- package rails.game.correct; import rails.game.*; import rails.game.action.PossibleAction; import rails.util.Util; import java.io.IOException; import java.io.ObjectInputStream; /** * Correction action that changes the cash position of a cashholder. * * @author Stefan Frey */ public class OperatingCost extends PossibleAction implements CorrectCashI, CorrectionAction { public enum OCType {LAY_TILE, LAY_BASE_TOKEN}; /** The Constant serialVersionUID. */ public static final long serialVersionUID = 1L; /* Preconditions */ /** shows in correction menu */ private boolean inCorrectionMenu; /** operating Company */ transient private PublicCompanyI operatingCompany; /** converted to name */ private String operatingCompanyName; /** operating cost type (as tile lay, token lay etc.) */ private OCType operatingCostType; /** suggested costs */ private int suggestedCost; /** maximum costs */ private int maximumCost; /* Postconditions */ /** selected cash amount */ private int operatingCost; /** * Instantiates an operating costs action * * @param pc Public Company */ public OperatingCost(PublicCompanyI pc, OCType ot, int ocCosts) { operatingCompany = pc; operatingCompanyName = pc.getName(); operatingCostType = ot; suggestedCost = ocCosts; maximumCost = pc.getCash(); } @Override public boolean isInCorrectionMenu(){ return inCorrectionMenu; } public void setCorrectionMenu(boolean menu){ inCorrectionMenu = menu; } @Override public CashHolder getCashHolder() { return operatingCompany; } @Override public String getCashHolderName() { return operatingCompanyName; } @Override public int getAmount() { if (acted) return -operatingCost; else return suggestedCost; } @Override public void setAmount(int amount) { acted=true; operatingCost = amount; } public OCType getOCType(){ return operatingCostType; } @Override public boolean equals(PossibleAction action) { if (!(action instanceof OperatingCost)) return false; OperatingCost a = (OperatingCost) action; return (a.operatingCompany == this.operatingCompany && a.operatingCostType == this.operatingCostType && a.suggestedCost == this.suggestedCost && a.maximumCost == this.maximumCost && a.inCorrectionMenu == this.inCorrectionMenu ); } @Override public String toString() { StringBuffer b = new StringBuffer("OperatingCost"); if (!acted) { b.append(" (not acted)"); if (operatingCompany != null) b.append(", operatingCompany="+operatingCompany); b.append(", operatingCostType="+operatingCostType); b.append(", suggestedCost="+suggestedCost); b.append(", maximumCost="+maximumCost); b.append(", inCorrectionMenu="+inCorrectionMenu); } else { b.append(" (acted)"); if (operatingCompany != null) b.append(", operatingCompany="+operatingCompany); b.append(", operatingCostType="+operatingCostType); b.append(", operatingCost="+operatingCost); } return b.toString(); } /** Deserialize */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); if (Util.hasValue(operatingCompanyName)) operatingCompany = getCompanyManager().getCompanyByName(operatingCompanyName); } } --- NEW FILE: CorrectCash.java --- package rails.game.correct; import rails.game.*; import rails.game.action.PossibleAction; import rails.util.Util; import java.io.IOException; import java.io.ObjectInputStream; import java.util.*; /** * Correction action that changes the cash position of a cashholder. * * @author Stefan Frey */ public class CorrectCash extends PossibleAction implements CorrectCashI, CorrectionAction { /** The Constant serialVersionUID. */ public static final long serialVersionUID = 1L; /* Preconditions */ /** shows in correction menu */ private boolean inCorrectionMenu; /** cash holder */ transient private CashHolder correctCashHolder; /** converted to name */ private String cashHolderName; private String cashHolderType; /** maximum Amount to deduct */ private int maximumNegative; /* Postconditions */ /** selected cash amount */ private int correctAmount; /** * Instantiates a new correct cash * * @param pl Player */ public CorrectCash(Player pl) { correctCashHolder = pl; cashHolderName = pl.getName(); cashHolderType = "Player"; maximumNegative = pl.getCash(); } /** * Instantiates a new correct cash * * @param pc Public Company */ public CorrectCash(PublicCompanyI pc) { correctCashHolder = pc; cashHolderName = pc.getName(); cashHolderType = "PublicCompany"; maximumNegative = pc.getCash(); } @Override public boolean isInCorrectionMenu(){ return inCorrectionMenu; } public void setCorrectionMenu(boolean menu){ inCorrectionMenu = menu; } @Override public CashHolder getCashHolder() { return correctCashHolder; } @Override public String getCashHolderName() { return cashHolderName; } @Override public int getAmount() { return correctAmount; } @Override public void setAmount(int amount) { correctAmount = amount; } @Override public boolean equals(PossibleAction action) { if (!(action instanceof CorrectCash)) return false; CorrectCash a = (CorrectCash) action; return (a.correctCashHolder == this.correctCashHolder && a.maximumNegative == this.maximumNegative && a.inCorrectionMenu == this.inCorrectionMenu ); } @Override public String toString() { StringBuffer b = new StringBuffer("CorrectCash"); if (acted) { b.append("Not Acted"); if (correctCashHolder != null) b.append("correctCashHolder="+correctCashHolder); b.append("maximumNegative="+maximumNegative); b.append("inCorrectionMenu="+inCorrectionMenu); } else { b.append("Acted"); if (correctCashHolder != null) b.append("correctCashHolder="+correctCashHolder); b.append("correctAmount="+correctAmount); } return b.toString(); } /** Deserialize */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); if (Util.hasValue(cashHolderName) && Util.hasValue(cashHolderType)) { if (cashHolderType == "Player") correctCashHolder = getGameManager().getPlayerManager().getPlayerByName(cashHolderName); else if (cashHolderType == "PublicCompany") correctCashHolder = getCompanyManager().getCompanyByName(cashHolderName); } } } --- NEW FILE: CorrectCashI.java --- package rails.game.correct; import rails.game.*; /** * Interface to action that changes the cash position of a cashholder. * * @author Stefan Frey */ public interface CorrectCashI { /** * Gets preconditions. */ public CashHolder getCashHolder(); public String getCashHolderName(); /** * Gets and sets postconditions. */ public int getAmount(); public void setAmount(int amount); } |