From: Dr. M. B. <neu...@us...> - 2012-03-22 20:07:57
|
data/1880/CompanyManager.xml | 6 + rails/game/specific/_1880/ExchangeForCash_1880.java | 85 ++++++++++++++++++++ rails/game/specific/_1880/OperatingRound_1880.java | 25 ++++- rails/game/specific/_1880/StartCompany_1880.java | 12 ++ rails/game/specific/_1880/StockRound_1880.java | 82 +++++++++++++++++++ 5 files changed, 206 insertions(+), 4 deletions(-) New commits: commit 78a057aefc72557a3dc5c8642470c2946f157326 Author: Martin Brumm <Dr....@t-...> Date: Thu Mar 22 19:08:18 2012 +0100 Fixing the bug that certain Informations and properties of an 1880 company arent read from a saved game diff --git a/rails/game/specific/_1880/StartCompany_1880.java b/rails/game/specific/_1880/StartCompany_1880.java index 616b8bb..c877e3a 100644 --- a/rails/game/specific/_1880/StartCompany_1880.java +++ b/rails/game/specific/_1880/StartCompany_1880.java @@ -3,8 +3,11 @@ */ package rails.game.specific._1880; +import java.io.IOException; +import java.io.ObjectInputStream; import java.util.BitSet; +import rails.game.CompanyManagerI; import rails.game.PublicCompanyI; import rails.game.StockSpace; import rails.game.StockSpaceI; @@ -126,4 +129,13 @@ public class StartCompany_1880 extends StartCompany { ((StockMarket_1880) gameManager.getStockMarket()).setParSlot(startPrice); } + /** Deserialize */ + private void readObject(ObjectInputStream in) throws IOException, + ClassNotFoundException { + + in.defaultReadObject(); + + CompanyManagerI cmgr = getCompanyManager(); + + } } diff --git a/rails/game/specific/_1880/StockRound_1880.java b/rails/game/specific/_1880/StockRound_1880.java index 537f704..e878f56 100644 --- a/rails/game/specific/_1880/StockRound_1880.java +++ b/rails/game/specific/_1880/StockRound_1880.java @@ -9,13 +9,16 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import rails.common.DisplayBuffer; import rails.common.LocalText; import rails.game.*; import rails.game.action.BuyCertificate; import rails.game.action.PossibleAction; import rails.game.action.SellShares; import rails.game.action.StartCompany; +import rails.game.action.UseSpecialProperty; import rails.game.move.CashMove; +import rails.game.special.SpecialPropertyI; import rails.game.specific._1880.PublicCompany_1880; @@ -475,5 +478,84 @@ public class StockRound_1880 extends StockRound { } } + /* (non-Javadoc) + * @see rails.game.StockRound#useSpecialProperty(rails.game.action.UseSpecialProperty) + */ + @Override + public boolean useSpecialProperty(UseSpecialProperty action) { + SpecialPropertyI sp = action.getSpecialProperty(); + + // TODO This should work for all subclasses, but not all have execute() + // yet. + if (sp instanceof ExchangeForCash_1880) { + + boolean result = executeExchangeForCash((ExchangeForCash_1880) sp); + if (result) hasActed.set(true); + return result; + + } else { + return super.useSpecialProperty(action); + } + + } + + private boolean executeExchangeForCash(ExchangeForCash_1880 sp) { + CompanyI privateCompany = sp.getOriginalCompany(); + Portfolio portfolio = privateCompany.getPortfolio(); + + Player player = null; + String errMsg = null; + + while (true) { + + /* Check if the private is owned by a player */ + if (!(portfolio.getOwner() instanceof Player)) { + errMsg = + LocalText.getText("PrivateIsNotOwnedByAPlayer", + privateCompany.getName()); + break; + } + player = (Player) portfolio.getOwner(); + break; + } + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText( + "CannotSwapPrivateForCash", + player.getName(), + privateCompany.getName(), + errMsg )); + return false; + } + + moveStack.start(true); + int amount = sp.getPhaseAmount(); + if (amount >0 ) { + player.addCash(amount); + sp.setExercised(); + privateCompany.setClosed(); + return true; + } + return false; + } + + /* (non-Javadoc) + * @see rails.game.StockRound#process(rails.game.action.PossibleAction) + */ + @Override + public boolean process(PossibleAction action) { + boolean result; + String playerName = action.getPlayerName(); + + if (action instanceof StartCompany) { + + StartCompany_1880 startCompanyAction = (StartCompany_1880) action; + + result = startCompany(playerName, startCompanyAction); + + return result; + } else { + return super.process(action); + } + } } commit c0efbb3a9c4433b6afe986d130e84afcd826919d Author: Martin Brumm <Dr....@t-...> Date: Thu Mar 22 19:07:29 2012 +0100 Introducing Exchange for Cash as Special Property diff --git a/data/1880/CompanyManager.xml b/data/1880/CompanyManager.xml index b20e346..ff26af7 100644 --- a/data/1880/CompanyManager.xml +++ b/data/1880/CompanyManager.xml @@ -47,6 +47,12 @@ <Company name="WR" longname="Woosong Railway" type="Private" basePrice="5" revenue="0"> + <SpecialProperties> + <SpecialProperty condition="ifOwnedByPlayer" when="anyTurn" + class="rails.game.specific._1880.ExchangeForCash_1880"> + <ExchangeForCash/> + </SpecialProperty> + </SpecialProperties> <ClosingConditions> <SpecialProperties condition="ifExercised"/> </ClosingConditions> diff --git a/rails/game/specific/_1880/ExchangeForCash_1880.java b/rails/game/specific/_1880/ExchangeForCash_1880.java new file mode 100644 index 0000000..98c409f --- /dev/null +++ b/rails/game/specific/_1880/ExchangeForCash_1880.java @@ -0,0 +1,85 @@ +/** + * + */ +package rails.game.specific._1880; + +import rails.common.LocalText; +import rails.common.parser.ConfigurationException; +import rails.common.parser.Tag; +import rails.game.PhaseI; +import rails.game.Player; +import rails.game.special.SpecialProperty; + +/** + * @author Martin + * + */ +public class ExchangeForCash_1880 extends SpecialProperty { + + int[] phaseAmount = {40,70,100}; + + @Override + public void configureFromXML(Tag tag) throws ConfigurationException { + + super.configureFromXML(tag); + + Tag swapTag = tag.getChild("ExchangeForCash"); + if (swapTag == null) { + throw new ConfigurationException("<ExchangeForCash> tag missing"); + } + +// String amount = swapTag.getAttributeAsString("amount"); +// if (!Util.hasValue(amount)) +// throw new ConfigurationException( +// "ExchangeForCash: amounts are missing"); + + } + + /* (non-Javadoc) + * @see rails.game.special.SpecialPropertyI#isExecutionable() + */ + public boolean isExecutionable() { + + return originalCompany.getPortfolio().getOwner() instanceof Player; + } + + /* (non-Javadoc) + * @see rails.game.special.SpecialPropertyI#getName() + */ + public String getName() { + return toString(); + } + + @Override + public String toString() { + return "Swap " + originalCompany.getName() + " for " + "{40, 70, 100 }" + + "Yuan"; + } + + public int getPhaseAmount() { + String currentPhase; + + currentPhase = gameManager.getCurrentPhase().getName(); + if (currentPhase == "3") { + return phaseAmount[0]; + } else if (currentPhase == "3+3"){ + return phaseAmount[1]; + } else if (currentPhase == "4") { + return phaseAmount[2]; + }else { + return 0; + } + + } + + @Override + public String toMenu() { + return LocalText.getText("SwapPrivateForMoney", + originalCompany.getName(), + "40, 70, 100 Yuan depending on the active Train"); + } + + public String getInfo() { + return toMenu(); + } +} diff --git a/rails/game/specific/_1880/OperatingRound_1880.java b/rails/game/specific/_1880/OperatingRound_1880.java index f3c1bf9..adc4b3d 100644 --- a/rails/game/specific/_1880/OperatingRound_1880.java +++ b/rails/game/specific/_1880/OperatingRound_1880.java @@ -18,6 +18,7 @@ import rails.game.BaseToken; import rails.game.Bonus; import rails.game.CashHolder; import rails.game.GameDef; +import rails.game.GameManager; import rails.game.GameManagerI; import rails.game.MapHex; import rails.game.OperatingRound; @@ -46,6 +47,7 @@ import rails.game.special.SpecialTrainBuy; import rails.game.specific._1880.PublicCompany_1880; import rails.game.specific._1880.GameManager_1880; import rails.game.state.EnumState; +import rails.ui.swing.GameUIManager; import rails.util.SequenceUtil; /** @@ -737,10 +739,25 @@ public class OperatingRound_1880 extends OperatingRound { } private void askForPrivateRocket(PhaseI newPhase) { - TrainType actualTrainForRocket= gameManager.getTrainManager().getTypeByName(newPhase.getName()); - //ToDo: Make a Window Popup that is asking the operating Player on Behalf of the Rocket Paper Owner - //to Act, we might have to follow the path of 1835 there. - + + } + + /* (non-Javadoc) + * @see rails.game.OperatingRound#processGameSpecificAction(rails.game.action.PossibleAction) + */ + @Override + public boolean processGameSpecificAction(PossibleAction action) { + // TODO Auto-generated method stub + return super.processGameSpecificAction(action); + } + + /* (non-Javadoc) + * @see rails.game.OperatingRound#setGameSpecificPossibleActions() + */ + @Override + protected void setGameSpecificPossibleActions() { + // TODO Auto-generated method stub + super.setGameSpecificPossibleActions(); } } |