|
From: <wak...@us...> - 2011-06-30 18:56:06
|
Revision: 1597
http://rails.svn.sourceforge.net/rails/?rev=1597&view=rev
Author: wakko666
Date: 2011-06-30 18:56:00 +0000 (Thu, 30 Jun 2011)
Log Message:
-----------
Commit Erik's changes, try #2.
Modified Paths:
--------------
trunk/18xx/rails/game/OperatingRound.java
Modified: trunk/18xx/rails/game/OperatingRound.java
===================================================================
--- trunk/18xx/rails/game/OperatingRound.java 2011-06-30 18:27:52 UTC (rev 1596)
+++ trunk/18xx/rails/game/OperatingRound.java 2011-06-30 18:56:00 UTC (rev 1597)
@@ -33,19 +33,12 @@
protected ArrayListState<PublicCompanyI> operatingCompanies;
- //protected IntegerState operatingCompanyIndexObject;
-
protected GenericState<PublicCompanyI> operatingCompany;
// do not use a operatingCompany.getObject() as reference
- // protected PublicCompanyI operatingCompany.getObject() = null;
// Non-persistent lists (are recreated after each user action)
protected List<SpecialPropertyI> currentSpecialProperties = null;
- //protected List<LayTile> currentSpecialTileLays = new ArrayList<LayTile>();
-
- //protected List<LayTile> currentNormalTileLays = new ArrayList<LayTile>();
-
protected HashMapState<String, Integer> tileLaysPerColour =
new HashMapState<String, Integer>("tileLaysPerColour");
@@ -241,6 +234,11 @@
} else if (selectedAction instanceof ClosePrivate) {
result = executeClosePrivate((ClosePrivate)selectedAction);
+
+ } else if (selectedAction instanceof UseSpecialProperty
+ && ((UseSpecialProperty)selectedAction).getSpecialProperty() instanceof SpecialRight) {
+
+ result = buyRight ((UseSpecialProperty)selectedAction);
} else if (selectedAction instanceof NullAction) {
@@ -1207,7 +1205,7 @@
/** Take the next step after a given one (see nextStep()) */
protected void nextStep(GameDef.OrStep step) {
- PublicCompanyI company = operatingCompany.get();
+ PublicCompanyI company = operatingCompany.get();
// Cycle through the steps until we reach one where a user action is
// expected.
@@ -1257,24 +1255,24 @@
int poolShare = pool.getShare(company); // Expensive, do it once
// Can it buy?
boolean canBuy =
- ownShare < getGameParameterAsInt (GameDef.Parm.TREASURY_SHARE_LIMIT)
- && company.getCash() >= company.getCurrentSpace().getPrice()
- && poolShare > 0;
+ ownShare < getGameParameterAsInt (GameDef.Parm.TREASURY_SHARE_LIMIT)
+ && company.getCash() >= company.getCurrentSpace().getPrice()
+ && poolShare > 0;
// Can it sell?
boolean canSell =
- company.getPortfolio().getShare(company) > 0
- && poolShare < getGameParameterAsInt (GameDef.Parm.POOL_SHARE_LIMIT);
+ company.getPortfolio().getShare(company) > 0
+ && poolShare < getGameParameterAsInt (GameDef.Parm.POOL_SHARE_LIMIT);
// Above we ignore the possible existence of double shares (as in 1835).
if (!canBuy && !canSell) {
// XXX For BACKWARDS COMPATIBILITY only,
- // register a Done skip action during reloading.
- if (gameManager.isReloading()) {
- gameManager.setSkipDone(GameDef.OrStep.TRADE_SHARES);
+ // register a Done skip action during reloading.
+ if (gameManager.isReloading()) {
+ gameManager.setSkipDone(GameDef.OrStep.TRADE_SHARES);
log.debug("If the next saved action is 'Done', skip it");
- }
- log.info("Skipping Treasury share trading step");
- continue;
+ }
+ log.info("Skipping Treasury share trading step");
+ continue;
}
gameManager.startTreasuryShareTradingRound();
@@ -1613,8 +1611,8 @@
company = newOperatingCompanies.get(i);
if (company != operatingCompanies.get(i)) {
log.debug("Company "+company.getName()
- +" replaces "+operatingCompanies.get(i).getName()
- +" in operating sequence");
+ +" replaces "+operatingCompanies.get(i).getName()
+ +" in operating sequence");
operatingCompanies.move(company, i);
}
}
@@ -2305,6 +2303,44 @@
return numberOfLoans * operatingCompany.get().getValuePerLoan();
}
+ protected boolean buyRight (UseSpecialProperty action) {
+
+ String errMsg = null;
+
+ SpecialPropertyI sp = action.getSpecialProperty();
+ if (!(sp instanceof SpecialRight)) {
+ errMsg = "Wrong right property class: "+sp.toString();
+ }
+
+ SpecialRight right = (SpecialRight) sp;
+ String rightName = right.getName();
+ String rightValue = right.getValue();
+
+ if (errMsg != null) {
+ DisplayBuffer.add(LocalText.getText("CannotBuyRight",
+ action.getCompanyName(),
+ rightName,
+ Bank.format(right.getCost()),
+ errMsg));
+
+ return false;
+ }
+
+ moveStack.start(true);
+
+ operatingCompany.get().setRight(rightName, rightValue);
+ new CashMove (operatingCompany.get(), bank, right.getCost());
+
+ ReportBuffer.add(LocalText.getText("BuysRight",
+ operatingCompany.get().getName(),
+ rightName,
+ Bank.format(right.getCost())));
+
+ sp.setExercised();
+
+ return true;
+ }
+
/*----- METHODS TO BE CALLED TO SET UP THE NEXT TURN -----*/
/**
@@ -2486,10 +2522,13 @@
// Are there other step-independent special properties owned by the company?
List<SpecialPropertyI> orsps = operatingCompany.get().getPortfolio().getAllSpecialProperties();
+ List<SpecialPropertyI> compsps = operatingCompany.get().getSpecialProperties();
+ if (compsps != null) orsps.addAll(compsps);
+
if (orsps != null) {
for (SpecialPropertyI sp : orsps) {
if (!sp.isExercised() && sp.isUsableIfOwnedByCompany()
- && sp.isUsableDuringOR()) {
+ && sp.isUsableDuringOR(step)) {
if (sp instanceof SpecialTokenLay) {
if (getStep() != GameDef.OrStep.LAY_TOKEN) {
possibleActions.add(new LayBaseToken((SpecialTokenLay)sp));
@@ -2505,7 +2544,7 @@
if (orsps != null) {
for (SpecialPropertyI sp : orsps) {
if (!sp.isExercised() && sp.isUsableIfOwnedByPlayer()
- && sp.isUsableDuringOR()) {
+ && sp.isUsableDuringOR(step)) {
if (sp instanceof SpecialTokenLay) {
if (getStep() != GameDef.OrStep.LAY_TOKEN) {
possibleActions.add(new LayBaseToken((SpecialTokenLay)sp));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|