From: Erik V. <ev...@us...> - 2009-09-23 21:39:16
|
Update of /cvsroot/rails/18xx/rails/game/special In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/game/special Modified Files: SpecialProperty.java SpecialTokenLay.java Added Files: SellBonusToken.java LocatedBonus.java Log Message: Implemented 1856 Bridge and Tunnel tokens Index: SpecialTokenLay.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/special/SpecialTokenLay.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SpecialTokenLay.java 4 Jun 2008 19:00:38 -0000 1.9 --- SpecialTokenLay.java 23 Sep 2009 21:38:57 -0000 1.10 *************** *** 20,24 **** int numberUsed = 0; ! public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); --- 20,25 ---- int numberUsed = 0; ! @Override ! public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); *************** *** 89,101 **** } - /** @deprecated */ - public MapHex getLocation() { - if (locations != null) { - return locations.get(0); - } else { - return null; - } - } - public List<MapHex> getLocations() { return locations; --- 90,93 ---- *************** *** 118,122 **** } ! public String toString() { return "SpecialTokenLay comp=" + privateCompany.getName() + " type=" + tokenClass.getSimpleName() + ": " --- 110,115 ---- } ! @Override ! public String toString() { return "SpecialTokenLay comp=" + privateCompany.getName() + " type=" + tokenClass.getSimpleName() + ": " Index: SpecialProperty.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/special/SpecialProperty.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** SpecialProperty.java 26 Oct 2008 20:39:16 -0000 1.13 --- SpecialProperty.java 23 Sep 2009 21:38:57 -0000 1.14 *************** *** 5,10 **** import java.util.Map; ! import rails.game.*; import rails.game.move.MoveableHolderI; import rails.game.state.BooleanState; import rails.util.Tag; --- 5,12 ---- import java.util.Map; ! import rails.game.ConfigurationException; ! import rails.game.PrivateCompanyI; import rails.game.move.MoveableHolderI; + import rails.game.move.ObjectMove; import rails.game.state.BooleanState; import rails.util.Tag; *************** *** 14,17 **** --- 16,20 ---- protected PrivateCompanyI privateCompany; + protected MoveableHolderI holder = null; protected int closingValue = 0; protected BooleanState exercised; *************** *** 67,71 **** public void setCompany(PrivateCompanyI company) { ! this.privateCompany = company; exercised = new BooleanState(company.getName() + "_SP_" + uniqueId --- 70,75 ---- public void setCompany(PrivateCompanyI company) { ! privateCompany = company; ! holder = company; exercised = new BooleanState(company.getName() + "_SP_" + uniqueId *************** *** 78,82 **** public MoveableHolderI getHolder() { ! return null; } --- 82,86 ---- public MoveableHolderI getHolder() { ! return holder; } *************** *** 135,144 **** /** ! * Stub for moving the special property to another holder. Must be ! * overridden by subsclasses that actually can be moved. */ ! public void moveTo(MoveableHolderI newHolder) {} ! public String toString() { return getClass().getSimpleName() + " of private " + privateCompany.getName(); --- 139,154 ---- /** ! * Move the special property to another holder. ! * Only to be used for special properties that have the "transfer" attribute. */ ! public void moveTo(MoveableHolderI newHolder) { ! if (transferText.equals("")) return; ! //if (newHolder instanceof Portfolio) { ! new ObjectMove(this, holder, newHolder); ! //} ! } ! @Override ! public String toString() { return getClass().getSimpleName() + " of private " + privateCompany.getName(); --- NEW FILE: LocatedBonus.java --- /* $Header: /cvsroot/rails/18xx/rails/game/special/LocatedBonus.java,v 1.1 2009/09/23 21:38:57 evos Exp $ */ package rails.game.special; import java.util.ArrayList; import java.util.List; import rails.game.*; import rails.util.Tag; import rails.util.Util; /** * An object of class LocatedBonus represent extra income for the owning company, * usually connected to certain map locations. * <p>LocatedBonus objects are configured as Special Properties in CompanyManager.xml. * @author VosE * */ public class LocatedBonus extends SpecialProperty { String locationCodes = null; List<MapHex> locations = null; String name; int value; @Override public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); Tag bonusTag = tag.getChild("LocatedBonus"); if (bonusTag == null) { throw new ConfigurationException("<LocatedBonus> tag missing"); } locationCodes = bonusTag.getAttributeAsString("location"); if (!Util.hasValue(locationCodes)) throw new ConfigurationException("LocatedBonus: location missing"); parseLocations (); name = bonusTag.getAttributeAsString("name"); value = bonusTag.getAttributeAsInteger("value"); if (value <= 0) throw new ConfigurationException("Value invalid ["+value+"] or missing"); } public boolean isExecutionable() { return false; } public List<MapHex> getLocations() { return locations; } public String getLocationNameString() { return locationCodes; } public String getName() { return name; } public int getValue() { return value; } private void parseLocations () throws ConfigurationException { MapManager mmgr = MapManager.getInstance(); MapHex hex; locations = new ArrayList<MapHex>(); for (String hexName : locationCodes.split(",")) { hex = mmgr.getHex(hexName); if (hex == null) throw new ConfigurationException("Location " + hexName + " does not exist"); locations.add(hex); } } @Override public String toString() { return "LocatedBonus "+name+" comp=" + privateCompany.getName() + " hex=" + locationCodes + " value=" + value; } } --- NEW FILE: SellBonusToken.java --- /* $Header: /cvsroot/rails/18xx/rails/game/special/SellBonusToken.java,v 1.1 2009/09/23 21:38:57 evos Exp $ */ package rails.game.special; import java.util.ArrayList; import java.util.List; import rails.game.*; import rails.game.state.State; import rails.util.Tag; import rails.util.Util; public class SellBonusToken extends SpecialProperty { private String locationCodes = null; private List<MapHex> locations = null; //private PublicCompanyI seller = null; private State seller = null; private String name; private int price; private int value; private int maxNumberToSell; private int numberSold = 0; @Override public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); Tag sellBonusTokenTag = tag.getChild("SellBonusToken"); if (sellBonusTokenTag == null) { throw new ConfigurationException("<SellBonusToken> tag missing"); } locationCodes = sellBonusTokenTag.getAttributeAsString("location"); if (!Util.hasValue(locationCodes)) throw new ConfigurationException("SellBonusToken: location missing"); MapManager mmgr = MapManager.getInstance(); MapHex hex; locations = new ArrayList<MapHex>(); for (String hexName : locationCodes.split(",")) { hex = mmgr.getHex(hexName); if (hex == null) throw new ConfigurationException("Location " + hexName + " does not exist"); locations.add(hex); } name = sellBonusTokenTag.getAttributeAsString("name"); value = sellBonusTokenTag.getAttributeAsInteger("value", 0); if (value <= 0) throw new ConfigurationException("Value invalid ["+value+"] or missing"); price = sellBonusTokenTag.getAttributeAsInteger("price", 0); if (price <= 0) throw new ConfigurationException("Price invalid ["+price+"] or missing"); maxNumberToSell = sellBonusTokenTag.getAttributeAsInteger("number", 1); seller = new State ("SellerOf_"+name+"_Bonus", CashHolder.class); } @Override public void setExercised () { numberSold++; if (maxNumberToSell >= 0 && numberSold >= maxNumberToSell) { super.setExercised(); } } public boolean isExecutionable() { return true; } public List<MapHex> getLocations() { return locations; } public String getLocationNameString() { return locationCodes; } public String getName() { return name; } public int getPrice() { return price; } public int getValue() { return value; } public CashHolder getSeller() { return (CashHolder) seller.getObject(); } public void setSeller(CashHolder seller) { this.seller.set(seller); } @Override public String toString() { return "SellBonusToken comp=" + privateCompany.getName() + " hex=" + locationCodes + " value=" + value + " price=" + price; } } |