From: <ev...@us...> - 2010-08-08 15:20:57
|
Revision: 1373 http://rails.svn.sourceforge.net/rails/?rev=1373&view=rev Author: evos Date: 2010-08-08 15:20:50 +0000 (Sun, 08 Aug 2010) Log Message: ----------- 1835 to use "proper" (JDG) company names Modified Paths: -------------- trunk/18xx/data/1835/CompanyManager.xml trunk/18xx/rails/game/Company.java trunk/18xx/rails/game/CompanyI.java trunk/18xx/rails/game/CompanyManager.java trunk/18xx/rails/game/CompanyManagerI.java trunk/18xx/rails/game/PublicCompany.java trunk/18xx/rails/game/action/BuyCertificate.java trunk/18xx/rails/game/action/BuyTrain.java trunk/18xx/rails/game/action/SellShares.java trunk/18xx/rails/game/specific/_1835/GameManager_1835.java trunk/18xx/rails/game/specific/_1835/OperatingRound_1835.java Modified: trunk/18xx/data/1835/CompanyManager.xml =================================================================== --- trunk/18xx/data/1835/CompanyManager.xml 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/data/1835/CompanyManager.xml 2010-08-08 15:20:50 UTC (rev 1373) @@ -155,29 +155,34 @@ </SpecialProperties> </Company> - <Company name="Bay" longname="Bayerische Eisenbahn" type="Major" startspace="C3" tokens="5" fgColour="FFFFFF" bgColour="0000FF"> + <Company name="BY" longname="Bayerische Eisenbahn" type="Major" startspace="C3" tokens="5" fgColour="FFFFFF" bgColour="0000FF" + alias="Bay"> <Home hex="O15"/> <IfOption name="BYFloatsAt" value="20%"> <Float percentage="20"/> </IfOption> </Company> - <Company name="Sax" longname="Sächsische Eisenbahn" type="Major" startspace="C4" tokens="3" fgColour="FFFFFF" bgColour="FF0000"> + <Company name="SX" longname="Sächsische Eisenbahn" type="Major" startspace="C4" tokens="3" fgColour="FFFFFF" bgColour="FF0000" + alias="Sax"> <Home hex="H16"/> <FirstTrainCloses type="Private" name="LD"/> </Company> - <Company name="Bad" longname="Badische Eisenbahn" type="Major" startspace="B4" available="no" tokens="2" fgColour="FFFFFF" bgColour="808000"> + <Company name="BA" longname="Badische Eisenbahn" type="Major" startspace="B4" available="no" tokens="2" fgColour="FFFFFF" bgColour="808000" + alias="Bad"> <Home hex="L6"/> <Certificate type="President" shares="2"/> <Certificate shares="1" number="6"/> <Certificate shares="2" number="1"/> </Company> - <Company name="Wrt" longname="Württembergische Eisenbahn" type="Major" startspace="B4" available="no" tokens="2" fgColour="000000" bgColour="FFFF00"> + <Company name="WT" longname="Württembergische Eisenbahn" type="Major" startspace="B4" available="no" tokens="2" fgColour="000000" bgColour="FFFF00" + alias="Wrt"> <Home hex="M9"/> <Certificate type="President" shares="2"/> <Certificate shares="1" number="6"/> <Certificate shares="2" number="1"/> </Company> - <Company name="Hes" longname="Hessische Eisenbahn" type="Major" startspace="B4" available="no" tokens="2" fgColour="000000" bgColour="00CC00"> + <Company name="HE" longname="Hessische Eisenbahn" type="Major" startspace="B4" available="no" tokens="2" fgColour="000000" bgColour="00CC00" + alias="Hes"> <Home hex="J8"/> <Certificate type="President" shares="2"/> <Certificate shares="1" number="6"/> @@ -189,13 +194,15 @@ <Certificate shares="2" number="2"/> <Certificate shares="1" number="4"/> </Company> - <Company name="Old" longname="Oldenburgische Eisenbahn" type="Major" startspace="B5" available="no" tokens="2" fgColour="000000" bgColour="C0C0C0"> + <Company name="OL" longname="Oldenburgische Eisenbahn" type="Major" startspace="B5" available="no" tokens="2" fgColour="000000" bgColour="C0C0C0" + alias="Old"> <Home hex="D6"/> <Certificate type="President" shares="2"/> <Certificate shares="2" number="2"/> <Certificate shares="1" number="4"/> </Company> - <Company name="Pr" longname="Preußische Eisenbahn" type="Major" startspace="I4" available="no" tokens="7" fgColour="FFFFFF" bgColour="000000"> + <Company name="PR" longname="Preußische Eisenbahn" type="Major" startspace="I4" available="no" tokens="7" fgColour="FFFFFF" bgColour="000000" + alias="Pr"> <Home hex="E19"/> <ShareUnit percentage="5" sharePriceUnits="2"/> <Float percentage="10"/> Modified: trunk/18xx/rails/game/Company.java =================================================================== --- trunk/18xx/rails/game/Company.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/Company.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -17,6 +17,7 @@ protected String name; protected String longName; + protected String alias = null; // To allow reloading files with old names after name changes protected CompanyTypeI type; protected int companyNumber; // For internal use @@ -160,6 +161,10 @@ return longName; } + public String getAlias() { + return alias; + } + public String getInfoText(){ return infoText; } Modified: trunk/18xx/rails/game/CompanyI.java =================================================================== --- trunk/18xx/rails/game/CompanyI.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/CompanyI.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -53,6 +53,8 @@ public String getInfoText(); + public String getAlias(); + /** * Returns the CompanyType of the Company * Modified: trunk/18xx/rails/game/CompanyManager.java =================================================================== --- trunk/18xx/rails/game/CompanyManager.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/CompanyManager.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -40,6 +40,9 @@ private Map<String, StartPacket> startPacketMap = new HashMap<String, StartPacket>(); + /** A map to enable translating aliases to names */ + protected Map<String, String> aliases = null; + private int numberOfPublicCompanies = 0; protected static Logger log = @@ -140,10 +143,15 @@ new HashMap<String, CompanyI>()); (mCompaniesByTypeAndName.get(type)).put( name, company); + + String alias = company.getAlias(); + if (alias != null) createAlias (alias, name); + } catch (Exception e) { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", cType.getClassName()), e); } + } /* Read and configure the start packets */ @@ -182,6 +190,30 @@ } } + private void createAlias (String alias, String name) { + if (aliases == null) { + aliases = new HashMap<String, String>(); + } + aliases.put(alias, name); + } + + public String checkAlias (String alias) { + if (aliases != null && aliases.containsKey(alias)) { + return aliases.get(alias); + } else { + return alias; + } + } + + public String checkAliasInCertId (String certId) { + String[] parts = certId.split("-"); + String realName = checkAlias (parts[0]); + if (!parts[0].equals(realName)) { + return realName + "-" + parts[1]; + } else { + return certId; + } + } /** * @see rails.game.CompanyManagerI#getCompany(java.lang.String) * @@ -191,7 +223,7 @@ } public PublicCompanyI getPublicCompany(String name) { - return mPublicCompanies.get(name); + return mPublicCompanies.get(checkAlias(name)); } public List<PrivateCompanyI> getAllPrivateCompanies() { @@ -202,19 +234,6 @@ return lPublicCompanies; } - /* - public PublicCompanyI getCompanyByName(String name) { - for (int i = 0; i < lPublicCompanies.size(); i++) { - PublicCompany co = (PublicCompany) lPublicCompanies.get(i); - if (name.equalsIgnoreCase(co.getName())) { - return lPublicCompanies.get(i); - } - } - - return null; - } - */ - public List<CompanyTypeI> getCompanyTypes() { return lCompanyTypes; } @@ -222,7 +241,7 @@ public CompanyI getCompany(String type, String name) { if (mCompaniesByTypeAndName.containsKey(type)) { - return (mCompaniesByTypeAndName.get(type)).get(name); + return (mCompaniesByTypeAndName.get(type)).get(checkAlias(name)); } else { return null; } Modified: trunk/18xx/rails/game/CompanyManagerI.java =================================================================== --- trunk/18xx/rails/game/CompanyManagerI.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/CompanyManagerI.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -54,7 +54,9 @@ */ public CompanyI getCompany(String type, String name); - //public PublicCompanyI getCompanyByName(String name); + public String checkAlias (String alias); + public String checkAliasInCertId (String certId); + public List<CompanyTypeI> getCompanyTypes(); public void closeAllPrivates(); Modified: trunk/18xx/rails/game/PublicCompany.java =================================================================== --- trunk/18xx/rails/game/PublicCompany.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/PublicCompany.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -93,7 +93,7 @@ /** Company treasury, holding cash */ protected CashModel treasury = null; - + /** PresidentModel */ protected PresidentModel presidentModel = null; @@ -196,9 +196,6 @@ /** Are the certificates available from the first SR? */ boolean certsAreInitiallyAvailable = true; - /** Privates and Certificates owned by the public company */ - //protected Portfolio portfolio; - /** What percentage of ownership constitutes "one share" */ protected IntegerState shareUnit; @@ -289,13 +286,13 @@ longName = tag.getAttributeAsString("longname", name); infoText = "<html>"+longName; + alias = tag.getAttributeAsString("alias", alias); + /* Configure public company features */ fgHexColour = tag.getAttributeAsString("fgColour", fgHexColour); - //fgColour = new Color(Integer.parseInt(fgHexColour, 16)); fgColour = Util.parseColour(fgHexColour); bgHexColour = tag.getAttributeAsString("bgColour", bgHexColour); - //bgColour = new Color(Integer.parseInt(bgHexColour, 16)); bgColour = Util.parseColour(bgHexColour); floatPerc = tag.getAttributeAsInteger("floatPerc", floatPerc); @@ -1990,5 +1987,5 @@ public String getExtraShareMarks () { return ""; } - + } Modified: trunk/18xx/rails/game/action/BuyCertificate.java =================================================================== --- trunk/18xx/rails/game/action/BuyCertificate.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/action/BuyCertificate.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -143,6 +143,11 @@ GameManagerI gameManager = GameManager.getInstance(); + /* Check for aliases (old company names) */ + CompanyManagerI companyManager = gameManager.getCompanyManager(); + companyName = companyManager.checkAlias (companyName); + certUniqueId = companyManager.checkAliasInCertId(certUniqueId); + if (certUniqueId != null) { // Old style certificate = PublicCertificate.getByUniqueId(certUniqueId); Modified: trunk/18xx/rails/game/action/BuyTrain.java =================================================================== --- trunk/18xx/rails/game/action/BuyTrain.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/action/BuyTrain.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -29,17 +29,17 @@ private boolean forcedBuyIfNoRoute = false; // TODO Remove once route checking exists transient private List<TrainI> trainsForExchange = null; private String[] trainsForExchangeUniqueIds; - + /** Obsolete, but left in for backwards compatibility of saved files */ private boolean forcedExchange = false; - + private boolean presidentMustAddCash = false; private boolean presidentMayAddCash = false; private int presidentCashToAdd = 0; transient private SpecialTrainBuy specialProperty = null; private int specialPropertyId = 0; - + private String extraMessage = null; // User settings @@ -91,7 +91,7 @@ public void setForcedBuyIfNoRoute(boolean hasNoTrains) { this.forcedBuyIfNoRoute = hasNoTrains; } - + public void setExtraMessage (String message) { extraMessage = message; } @@ -119,14 +119,14 @@ return specialProperty != null; } - /** - * To be used for all usage of train, also within this class. - * After reloading the 2nd copy etc. of a train with unlimited quantity, + /** + * To be used for all usage of train, also within this class. + * After reloading the 2nd copy etc. of a train with unlimited quantity, * the train attribute will be null (because readObject() is called and the * train is initiated before the actions have been executed - the second * train is in this case only created after buying the first one). * @return - */ + */ public TrainI getTrain() { if (train == null) { train = GameManager.getInstance().getTrainManager().getTrainByUniqueId(trainUniqueId); @@ -269,11 +269,14 @@ GameManagerI gameManager = GameManager.getInstance(); TrainManager trainManager = gameManager.getTrainManager(); + CompanyManagerI companyManager = gameManager.getCompanyManager(); + fromName = companyManager.checkAlias (fromName); + train = trainManager.getTrainByUniqueId(trainUniqueId); // Note: the 2nd etc. copy of an unlimited quantity train will become null this way. // Set getTrain() for how this is fixed. - + from = gameManager.getPortfolioByName(fromName); if (trainsForExchangeUniqueIds != null && trainsForExchangeUniqueIds.length > 0) { Modified: trunk/18xx/rails/game/action/SellShares.java =================================================================== --- trunk/18xx/rails/game/action/SellShares.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/action/SellShares.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -8,8 +8,7 @@ import java.io.IOException; import java.io.ObjectInputStream; -import rails.game.Bank; -import rails.game.PublicCompanyI; +import rails.game.*; import rails.util.Util; /** @@ -115,7 +114,9 @@ in.defaultReadObject(); + CompanyManagerI companyManager = getCompanyManager(); if (Util.hasValue(companyName)) - company = getCompanyManager().getPublicCompany(companyName); + companyName = companyManager.checkAlias(companyName); + company = companyManager.getPublicCompany(companyName); } } Modified: trunk/18xx/rails/game/specific/_1835/GameManager_1835.java =================================================================== --- trunk/18xx/rails/game/specific/_1835/GameManager_1835.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/specific/_1835/GameManager_1835.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -7,16 +7,16 @@ private RoundI previousRound = null; private Player prFormStartingPlayer = null; - + public static String M2_ID = "M2"; - public static String PR_ID = "Pr"; - public static String OL_ID = "Old"; + public static String PR_ID = "PR"; + public static String OL_ID = "OL"; public static String MS_ID = "MS"; - public static String WT_ID = "Wrt"; - public static String HE_ID = "Hes"; - public static String BA_ID = "Bad"; - public static String SX_ID = "Sax"; - public static String BY_ID = "Bay"; + public static String WT_ID = "WT"; + public static String HE_ID = "HE"; + public static String BA_ID = "BA"; + public static String SX_ID = "SX"; + public static String BY_ID = "BY"; public GameManager_1835() { super(); @@ -47,7 +47,7 @@ } } - + public void startPrussianFormationRound(OperatingRound_1835 or) { interruptedRound = or; @@ -61,12 +61,13 @@ public Player getPrussianFormationStartingPlayer() { return prFormStartingPlayer; } - + + @Override public int getPlayerCertificateLimit(Player player) { int limit = playerCertificateLimit.intValue(); for (PublicCompanyI company : companyManager.getAllPublicCompanies()) { if (company.getTypeName().equalsIgnoreCase("Major") - && company.getPresident() == player + && company.getPresident() == player && player.getPortfolio().getShare(company) >= 80) limit++; } return limit; Modified: trunk/18xx/rails/game/specific/_1835/OperatingRound_1835.java =================================================================== --- trunk/18xx/rails/game/specific/_1835/OperatingRound_1835.java 2010-08-07 14:26:10 UTC (rev 1372) +++ trunk/18xx/rails/game/specific/_1835/OperatingRound_1835.java 2010-08-08 15:20:50 UTC (rev 1373) @@ -1,45 +1,24 @@ package rails.game.specific._1835; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.util.*; -import rails.game.Bank; -import rails.game.CashHolder; -import rails.game.DisplayBuffer; -import rails.game.GameDef; -import rails.game.GameManagerI; -import rails.game.GameOption; -import rails.game.OperatingRound; -import rails.game.PhaseI; -import rails.game.Player; -import rails.game.Portfolio; -import rails.game.PrivateCompanyI; -import rails.game.PublicCertificateI; -import rails.game.PublicCompanyI; -import rails.game.ReportBuffer; -import rails.game.StockSpaceI; +import rails.game.*; import rails.game.action.DiscardTrain; import rails.game.action.LayTile; import rails.game.move.CashMove; import rails.game.move.MapChange; -import rails.game.special.ExchangeForShare; -import rails.game.special.SpecialPropertyI; -import rails.game.special.SpecialTileLay; +import rails.game.special.*; import rails.game.state.BooleanState; import rails.util.LocalText; public class OperatingRound_1835 extends OperatingRound { - - private BooleanState needPrussianFormationCall + + private BooleanState needPrussianFormationCall = new BooleanState ("NeedPrussianFormationCall", false); private BooleanState hasLaidExtraOBBTile = new BooleanState ("HasLaidExtraOBBTile", false); - - /** + + /** * Registry of percentage of PR revenue to be denied per player * because of having produced revenue in the same OR. */ @@ -51,6 +30,7 @@ } /** Can a public company operate? (1835 special version) */ + @Override protected boolean canCompanyOperateThisRound (PublicCompanyI company) { if (!company.hasFloated() || company.isClosed()) { return false; @@ -66,6 +46,7 @@ return true; } + @Override protected void privatesPayOut() { int count = 0; for (PrivateCompanyI priv : companyManager.getAllPrivateCompanies()) { @@ -79,8 +60,8 @@ Bank.format(revenue), priv.getName())); new CashMove(bank, recipient, revenue); - - /* Register black private equivalent PR share value + + /* Register black private equivalent PR share value * so it can be subtracted if PR operates */ if (recipient instanceof Player && priv.getSpecialProperties() != null && priv.getSpecialProperties().size() > 0) { @@ -92,7 +73,7 @@ Player player = (Player) recipient; addIncomeDenialShare (player, share); } - + } } } @@ -103,11 +84,11 @@ } private void addIncomeDenialShare (Player player, int share) { - + if (!deniedIncomeShare.containsKey(player)) { new MapChange<Player, Integer> (deniedIncomeShare, player, share); } else { - new MapChange<Player, Integer> (deniedIncomeShare, player, + new MapChange<Player, Integer> (deniedIncomeShare, player, share + deniedIncomeShare.get(player)); } //log.debug("+++ Denied "+share+"% share of PR income to "+player.getName()); @@ -117,10 +98,11 @@ * A special rule applies to 1835 to prevent black privates and minors providing * income twice during an OR. */ + @Override protected Map<CashHolder, Integer> countSharesPerRecipient () { - + Map<CashHolder, Integer> sharesPerRecipient = super.countSharesPerRecipient(); - + if (operatingCompany.getName().equalsIgnoreCase(GameManager_1835.PR_ID)) { for (Player player : deniedIncomeShare.keySet()) { if (!sharesPerRecipient.containsKey(player)) continue; @@ -131,19 +113,20 @@ player.getName(), share, GameManager_1835.PR_ID)); - + } } - + return sharesPerRecipient; } - /** - * Register black minors as having operated + /** + * Register black minors as having operated * for the purpose of denying income after conversion to a PR share */ + @Override protected void initTurn() { - + super.initTurn(); List<SpecialPropertyI> sps = operatingCompany.getSpecialProperties(); @@ -152,32 +135,32 @@ addIncomeDenialShare (operatingCompany.getPresident(), efs.getShare()); } } - + @Override public void resume() { - + PublicCompanyI prussian = companyManager.getPublicCompany(GameManager_1835.PR_ID); - + if (prussian.hasFloated() && !prussian.hasOperated() // PR has just started. Check if it can operate this round - // That's only the case if M1 has just bought + // That's only the case if M1 has just bought // the first 4-train or 4+4-train && operatingCompany == companyManager.getPublicCompany("M1")) { log.debug("M2 has not operated: PR can operate"); - + // Insert the Prussian before the first major company // with a lower current price that hoas not yet operated // and isn't currently operating - + int index = 0; int operatingCompanyIndex = getOperatingCompanyIndex(); for (PublicCompanyI company : setOperatingCompanies()) { if (index > operatingCompanyIndex - && company.hasStockPrice() + && company.hasStockPrice() && company.hasFloated() && !company.isClosed() && company != operatingCompany - && company.getCurrentSpace().getPrice() + && company.getCurrentSpace().getPrice() < prussian.getCurrentSpace().getPrice()) { log.debug("PR will operate before "+company.getName()); break; @@ -189,15 +172,16 @@ log.debug("PR will operate at order position "+index); } else { - + log.debug("M2 has operated: PR cannot operate"); - + } - + guiHints.setCurrentRoundType(getClass()); super.resume(); } - + + @Override protected void setSpecialTileLays() { /* Special-property tile lays */ @@ -207,16 +191,17 @@ for (SpecialTileLay stl : getSpecialProperties(SpecialTileLay.class)) { if (stl.isExtra() || !currentNormalTileLays.isEmpty()) { - + // Exclude the second OBB free tile if the first was laid in this round if (stl.getLocationNameString().matches("M1(7|9)") && hasLaidExtraOBBTile.booleanValue()) continue; - + currentSpecialTileLays.add(new LayTile(stl)); } } } + @Override public boolean layTile(LayTile action) { // The extra OBB tiles may not both be laid in the same round @@ -233,17 +218,18 @@ return false; } } - + boolean result = super.layTile(action); - + if (result && action.getSpecialProperty() != null && action.getSpecialProperty().getLocationNameString().matches("M1(5|7)")) { hasLaidExtraOBBTile.set(true); } - + return result; } + @Override protected void newPhaseChecks() { PhaseI phase = getCurrentPhase(); if (phase.getName().equals("4") || phase.getName().equals("4+4") @@ -259,13 +245,14 @@ } } } - + + @Override public boolean discardTrain(DiscardTrain action) { - + boolean result = super.discardTrain(action); - if (result && getStep() == GameDef.OrStep.BUY_TRAIN + if (result && getStep() == GameDef.OrStep.BUY_TRAIN && needPrussianFormationCall.booleanValue()) { - // Do the postponed formation calls + // Do the postponed formation calls ((GameManager_1835)gameManager).startPrussianFormationRound (this); needPrussianFormationCall.set(false); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |