|
From: Erik V. <ev...@us...> - 2011-11-19 09:35:56
|
rails/game/model/ShareModel.java | 4 -
rails/game/model/ViewUpdate.java | 2
rails/game/specific/_1835/StockRound_1835.java | 92 +++++++++++++++----------
rails/ui/swing/GameStatus.java | 2
rails/ui/swing/elements/Field.java | 9 +-
5 files changed, 65 insertions(+), 44 deletions(-)
New commits:
commit 605008e5a969b1f3fe46a584a5ab86a32176e639
Author: Erik Vos <eri...@xs...>
Date: Sat Nov 19 10:35:35 2011 +0100
Fixes for 1835: Nationalisation rewritten to handle mixed shares.
Rewrote nationalisation to make it able to handle both 10% and 20% shares.
The nationalisation code has also been refactored into setBuyableCerts().
Suppressed empty share field tooltips.
Moved the SHARES update key from ShareModel to ViewUpdate, where the other keys are.
diff --git a/rails/game/model/ShareModel.java b/rails/game/model/ShareModel.java
index 2dd9993..2c7f913 100644
--- a/rails/game/model/ShareModel.java
+++ b/rails/game/model/ShareModel.java
@@ -11,8 +11,6 @@ public class ShareModel extends ModelObject {
private Portfolio portfolio;
private PublicCompanyI company;
- public static final String SHARES = "SHARES";
-
public ShareModel(Portfolio portfolio, PublicCompanyI company) {
this.portfolio = portfolio;
this.company = company;
@@ -55,7 +53,7 @@ public class ShareModel extends ModelObject {
if (b.length() > 0) b.append(",");
b.append(type).append(":").append(numberPerCertType.get(type));
}
- u.addObject(SHARES, b.toString());
+ u.addObject(ViewUpdate.SHARES, b.toString());
}
return u;
}
diff --git a/rails/game/model/ViewUpdate.java b/rails/game/model/ViewUpdate.java
index 3a99661..bc1b57d 100644
--- a/rails/game/model/ViewUpdate.java
+++ b/rails/game/model/ViewUpdate.java
@@ -9,7 +9,6 @@ import java.util.*;
* <p> The current version has text, background colour and foreground colour.
* Receiving view objects must be prepared to handle extensions.
* @author VosE
- *
*/
public class ViewUpdate implements Serializable {
@@ -18,6 +17,7 @@ public class ViewUpdate implements Serializable {
public static final String TEXT = "TEXT";
public static final String BGCOLOUR = "BGCOLOUR";
+ public static final String SHARES = "SHARES";
public static final long serialVersionUID = 1L;
diff --git a/rails/game/specific/_1835/StockRound_1835.java b/rails/game/specific/_1835/StockRound_1835.java
index 8d27f76..ff8eea3 100644
--- a/rails/game/specific/_1835/StockRound_1835.java
+++ b/rails/game/specific/_1835/StockRound_1835.java
@@ -4,7 +4,6 @@
*/
package rails.game.specific._1835;
-import java.util.ArrayList;
import java.util.List;
import rails.common.LocalText;
@@ -25,45 +24,68 @@ public class StockRound_1835 extends StockRound {
/** Add nationalisations */
@Override
- protected void setGameSpecificActions() {
- if (!mayCurrentPlayerBuyAnything()) return;
+ public void setBuyableCerts() {
+
+ super.setBuyableCerts();
if (companyBoughtThisTurnWrapper.get() != null) return;
- List<Player> otherPlayers = new ArrayList<Player>();
- Portfolio holder;
- CashHolder owner;
- Player otherPlayer;
int price;
int cash = currentPlayer.getCash();
+ List<PublicCertificateI> certs;
+ StockSpaceI stockSpace;
+ Portfolio from;
+ int unitsForPrice;
- // Nationalization
+ // Nationalisation
for (PublicCompanyI company : companyManager.getAllPublicCompanies()) {
if (!company.getTypeName().equalsIgnoreCase("Major")) continue;
if (!company.hasFloated()) continue;
if (company.getPresident() != currentPlayer) continue;
- if (currentPlayer.getPortfolio().getShare(company) >= 55) {
- otherPlayers.clear();
- for (PublicCertificateI cert : company.getCertificates()) {
- holder = (Portfolio)cert.getHolder();
- owner = holder.getOwner();
+ if (currentPlayer.getPortfolio().getShare(company) < 55) continue;
+ if (isSaleRecorded(currentPlayer, company)) continue;
+
+ for (Player otherPlayer : this.getPlayers()) {
+ if (otherPlayer == currentPlayer) continue;
+
+ /* Get the unique player certificates and check which ones can be bought */
+ from = otherPlayer.getPortfolio();
+ certs = from.getCertificatesPerCompany(company.getName());
+ if (certs == null || certs.isEmpty()) continue;
+
+ /* Allow for multiple share unit certificates (e.g. 1835) */
+ PublicCertificateI[] uniqueCerts;
+ int shares;
+
+ stockSpace = company.getCurrentSpace();
+ unitsForPrice = company.getShareUnitsForSharePrice();
+ price = (int)(1.5 * stockSpace.getPrice() / unitsForPrice);
+
+ /* Check what share multiples are available
+ * Normally only 1, but 1 and 2 in 1835. Allow up to 4.
+ */
+ uniqueCerts = new PublicCertificateI[5];
+ for (PublicCertificateI cert2 : certs) {
+ shares = cert2.getShares();
+ if (uniqueCerts[shares] != null) continue;
+ uniqueCerts[shares] = cert2;
+ }
+
+ /* Create a BuyCertificate action per share size */
+ for (shares = 1; shares < 5; shares++) {
+ if (uniqueCerts[shares] == null) continue;
+
/* Would the player exceed the total certificate limit? */
- StockSpaceI stockSpace = company.getCurrentSpace();
- if ((stockSpace == null || !stockSpace.isNoCertLimit()) && !mayPlayerBuyCertificate(
- currentPlayer, company, cert.getCertificateCount())) continue;
- // only nationalize other players
- if (owner instanceof Player && owner != currentPlayer) {
- otherPlayer = (Player) owner;
- if (!otherPlayers.contains(otherPlayer)) {
- price = (int)(1.5 * company.getCurrentPriceModel().getPrice().getPrice());
- if (price <= cash) {
- possibleActions.add(new BuyCertificate (company, cert.getShare(),
- holder,
- (int)(1.5 * company.getCurrentPriceModel().getPrice().getPrice()),
- 1));
- }
- otherPlayers.add(otherPlayer);
- }
- }
+ if (!stockSpace.isNoCertLimit()
+ && !mayPlayerBuyCertificate(currentPlayer, company,
+ uniqueCerts[shares].getCertificateCount()))
+ continue;
+
+ // Does the player have enough cash?
+ if (cash < price * shares) continue;
+
+ possibleActions.add(new BuyCertificate(company,
+ uniqueCerts[shares].getShare(),
+ from, price, 1));
}
}
}
@@ -97,7 +119,7 @@ public class StockRound_1835 extends StockRound {
}
// stored price is the previous unadjusted price
price = price / company.getShareUnitsForSharePrice();
- return price;
+ return price;
}
@@ -133,9 +155,9 @@ public class StockRound_1835 extends StockRound {
// Check for group releases
if (sharesInIPO == 0) {
if (name.equals(GameManager_1835.SX_ID) &&
- ipo.getShare(companyManager.getPublicCompany(GameManager_1835.BY_ID)) == 0
- || name.equals(GameManager_1835.BY_ID) &&
- ipo.getShare(companyManager.getPublicCompany(GameManager_1835.SX_ID)) == 0) {
+ ipo.getShare(companyManager.getPublicCompany(GameManager_1835.BY_ID)) == 0
+ || name.equals(GameManager_1835.BY_ID) &&
+ ipo.getShare(companyManager.getPublicCompany(GameManager_1835.SX_ID)) == 0) {
// Group 1 sold out: release Badische
releaseCompanyShares (companyManager.getPublicCompany(GameManager_1835.BA_ID));
ReportBuffer.add (LocalText.getText("SharesReleased",
@@ -163,7 +185,7 @@ public class StockRound_1835 extends StockRound {
"All", GameManager_1835.WT_ID));
} else if (sharesInIPO == 80) {
// President sold: release four 10% Prussian shares
- gameManager.getCompanyManager().getPublicCompany(GameManager_1835.PR_ID).setBuyable(true);
+ gameManager.getCompanyManager().getPublicCompany(GameManager_1835.PR_ID).setBuyable(true);
for (int i=0; i<4; i++) {
unavailable.getCertOfType(GameManager_1835.PR_ID+"_10%").moveTo(ipo);
}
diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java
index 29f55ea..a41d730 100644
--- a/rails/ui/swing/GameStatus.java
+++ b/rails/ui/swing/GameStatus.java
@@ -1066,7 +1066,7 @@ public class GameStatus extends GridPanel implements ActionListener {
protected void syncToolTipText (Field field, ClickField clickField) {
String baseText = field.getToolTipText();
- clickField.setToolTipText(Util.hasValue(baseText) ? baseText : "");
+ clickField.setToolTipText(Util.hasValue(baseText) ? baseText : null);
}
protected void addToolTipText (ClickField clickField, String addText) {
diff --git a/rails/ui/swing/elements/Field.java b/rails/ui/swing/elements/Field.java
index 1c7816f..eee384b 100644
--- a/rails/ui/swing/elements/Field.java
+++ b/rails/ui/swing/elements/Field.java
@@ -8,7 +8,8 @@ import java.util.*;
import javax.swing.*;
import javax.swing.border.Border;
-import rails.game.model.*;
+import rails.game.model.ModelObject;
+import rails.game.model.ViewUpdate;
import rails.util.Util;
public class Field extends JLabel implements ViewObject {
@@ -122,13 +123,13 @@ public class Field extends JLabel implements ViewObject {
setBackground((Color)vu.getValue(key));
normalBgColour = getBackground();
setForeground (Util.isDark(normalBgColour) ? Color.WHITE : Color.BLACK);
- } else if (ShareModel.SHARES.equalsIgnoreCase(key)) {
+ } else if (ViewUpdate.SHARES.equalsIgnoreCase(key)) {
int count;
String type;
String[] items;
StringBuilder b = new StringBuilder();
for (String typeAndCount : ((String)vu.getValue(key)).split(",")) {
- Util.getLogger().debug(">>> "+typeAndCount+" <<<");
+ //Util.getLogger().debug(">>> "+typeAndCount+" <<<");
if (!Util.hasValue(typeAndCount)) continue;
items = typeAndCount.split(":");
count = Integer.parseInt(items[1]);
@@ -138,7 +139,7 @@ public class Field extends JLabel implements ViewObject {
b.append(count).append(" x ").append(type);
}
baseToolTipInfo = b.toString();
- setToolTipText ("<html>" + baseToolTipInfo);
+ setToolTipText (b.length()>0 ? "<html>" + baseToolTipInfo : null);
}
}
}
|