Skip to content

Commit 64e4368

Browse files
authored
Merge pull request #79 from neutronc/rails_2_maintenance
Rails 2 maintenance
2 parents 59fdde4 + 8e5a0ea commit 64e4368

25 files changed

+308
-219
lines changed

1835_20200301_2250_Hakko.rails

26.1 KB
Binary file not shown.

build.gradle

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ buildscript {
3636
// reference: https://github.com/johnrengelman/shadow
3737
plugins {
3838
id 'java' // or 'groovy' Must be explicitly applied
39-
id 'com.github.johnrengelman.shadow' version '2.0.1'
39+
id 'com.github.johnrengelman.shadow' version '5.0.0'
4040
}
4141

4242
// Addition of macAppBundle
@@ -131,124 +131,7 @@ task makeDevelopVersion(type: Copy) {
131131
into resourceFilesDir
132132
}
133133

134-
// The following implements a creation of a Webstart version
135-
// refer to http://www.apprenticeshipnotes.org/2013/01/generating-webstart-files-using-gradle.html
136-
// and http://java.dzone.com/articles/java-web-start-jnlp-hello
137134

138-
task createBuildDir << {
139-
def dir = new File("${webstartBuildDir}")
140-
if (!dir.exists()) {
141-
dir.mkdirs()
142-
}
143-
}
144-
145-
task (copyJarFiles, type:Copy, dependsOn:[jar, createBuildDir]) {
146-
// the next line is required if we have several jars
147-
from configurations.runtime
148-
from("${buildDir}/libs")
149-
into("${webstartBuildDir}")
150-
include('*.jar')
151-
}
152-
153-
task (updateManifest, dependsOn: copyJarFiles) << {
154-
def buildFiles = fileTree(dir: "${webstartBuildDir}", include:"**/*.jar")
155-
buildFiles.each {
156-
ant.jar(destfile: it, update: true) {
157-
delegate.manifest {
158-
attribute(name: "Permissions", value: "all-permissions")
159-
attribute(name: "Codebase", value: "${railsCodebase}")
160-
attribute(name: "Application-Name", value: "${name}")
161-
attribute(name: "Trusted-Only", value: "true")
162-
}
163-
}
164-
}
165-
}
166-
167-
task (signAll, dependsOn: updateManifest) << {
168-
def libFiles = fileTree(dir: "${webstartBuildDir}", include:"**/*.jar")
169-
libFiles.each {
170-
ant.signjar(
171-
alias: "${keyAlias}",
172-
jar: it,
173-
keystore: "${keystoreFile}",
174-
storepass: "rails18xx",
175-
preservelastmodified: "true",
176-
lazy: "true")
177-
}
178-
}
179-
180-
task createWebStartDir << {
181-
def dir = new File("${webstartDestDir}")
182-
if (!dir.exists()) {
183-
dir.mkdirs()
184-
}
185-
}
186-
187-
task(generateWebStartFiles, type:Copy, dependsOn: [createWebStartDir, signAll]) {
188-
from("${webstartBuildDir}")
189-
into("${webstartDestDir}")
190-
include('*.jar')
191-
}
192-
193-
task generateWebStartJnlp() << {
194-
File jnlpTemplateFile = new File("${buildFilesDir}/template.jnlp")
195-
def root = new XmlParser().parse(jnlpTemplateFile)
196-
def jnlpFileName = "${sourceforgeJnlpFileName}"
197-
198-
// Setting values in the jnlp template
199-
// Setting root values
200-
201-
// Http CodeBase
202-
root.@codebase = sourceforgeJnlpPath
203-
root.@href = jnlpFileName
204-
205-
// Setting information values
206-
def information = root.information[0]
207-
208-
def title = information.title[0]
209-
title.setValue("${project.name}")
210-
211-
def vendor = information.vendor[0]
212-
vendor.setValue("${railsVendor}")
213-
214-
def homepage = information.homepage[0]
215-
homepage.@href = "${railsHomepage}"
216-
217-
// Setting resources
218-
def resource = root.resources[0]
219-
def j2se = resource.j2se[0]
220-
j2se.@version = "1.6+"
221-
222-
def collection = fileTree(dir:"${webstartBuildDir}", include:"**/*.jar")
223-
def mainJar = 'rails.jar'
224-
225-
collection.each {
226-
def resourceValues = [href: it.name]
227-
if (mainJar == it.name) {
228-
resourceValues = [href: it.name, main: 'true']
229-
}
230-
resource.appendNode('jar', resourceValues)
231-
}
232-
233-
// Setting the main class
234-
def applicationDesc = root.'application-desc'[0]
235-
applicationDesc.'@main-class' = "$railsMainClass"
236-
237-
// Writing the jnlp file filled
238-
File jnlpFile = new File("${webstartDestDir}/" + jnlpFileName)
239-
new XmlNodePrinter(new PrintWriter(jnlpFile)).print(root)
240-
}
241-
242-
// upload via ant task
243-
task uploadWebstart() << {
244-
ant.scp(todir:"${sourceforgeUserName}:${sfpwd}@${sourceforgeUploadPath}") {
245-
fileset(dir:"${webstartDestDir}")
246-
}
247-
}
248-
249-
task cleanWebstart (type:Delete, dependsOn:clean) {
250-
delete "${webstartBuildDir}", "${webstartDestDir}"
251-
}
252135

253136
launch4j {
254137
mainClassName = "${railsMainClass}"

src/main/java/net/sf/rails/game/PlayerShareUtils.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
public class PlayerShareUtils {
1818

19-
public static SortedSet<Integer> sharesToSell (PublicCompany company, Player player) {
19+
public static SortedSet<Integer> sharesToSell (PublicCompany company, Player player) {
2020

2121
if (company.hasMultipleCertificates()) {
2222
if (player == company.getPresident()) {
@@ -88,13 +88,18 @@ private static SortedSet<Integer> presidentSellMultiple(PublicCompany company, P
8888
Player potential = company.findPlayerToDump();
8989
int potentialShareNumber = potential.getPortfolioModel().getShare(company);
9090
int shareNumberDumpDifference = presidentShareNumber - potentialShareNumber;
91+
boolean presidentShareOnly = false;
9192

92-
// ... if this is less than what the pool allows => goes back to non-president selling
93-
int poolAllows = poolAllowsShareNumbers(company);
94-
if (shareNumberDumpDifference <= poolAllows) {
95-
return otherSellMultiple(company, president);
93+
if (presidentCert.getShare() == presidentShareNumber) { // Only President Share to be sold...
94+
presidentShareOnly = true;
9695
}
9796

97+
// ... if this is less than what the pool allows => goes back to non-president selling only if non president share... (1835 or other multipe director shares...)
98+
int poolAllows = poolAllowsShareNumbers(company);
99+
if ((shareNumberDumpDifference <= poolAllows) && (!presidentShareOnly)) {
100+
return otherSellMultiple(company, president);
101+
}
102+
98103
// second: separate the portfolio into other shares and president certificate
99104
ImmutableList.Builder<PublicCertificate> otherCerts = ImmutableList.builder();
100105
for (PublicCertificate c:president.getPortfolioModel().getCertificates(company)) {
@@ -124,7 +129,7 @@ private static SortedSet<Integer> presidentSellMultiple(PublicCompany company, P
124129
// d is the amount sold in addition to standard shares, returned has the remaining part of the president share
125130
int remaining = presidentCert.getShares() - d;
126131
if (returnShareNumbers.contains(remaining)) {
127-
sharesToSell.add(s);
132+
sharesToSell.add(s+d);
128133
}
129134
} else {
130135
break; // pool is full
@@ -175,8 +180,15 @@ public static List<PublicCertificate> findCertificatesToSell(PublicCompany compa
175180
break;
176181
}
177182
}
183+
else if (cert.isPresidentShare() && cert.getShares()== shareUnits) {
184+
certsToSell.add(cert);
185+
nbCertsToSell--;
186+
if (nbCertsToSell == 0) {
187+
break;
188+
}
189+
}
178190
}
179-
191+
180192
return certsToSell.build();
181193
}
182194

src/main/java/net/sf/rails/game/ShareSellingRound.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public boolean sellShares(SellShares action) {
237237
int presSharesToSell = 0;
238238
int numberToSell = action.getNumber();
239239
int shareUnits = action.getShareUnits();
240-
240+
int presidentExchange = action.getPresidentExchange();
241241

242242
// Dummy loop to allow a quick jump out
243243
while (true) {

src/main/java/net/sf/rails/game/StockRound.java

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ public void setSellableShares() {
422422
Player potential = company.findPlayerToDump();
423423
if (potential != null) {
424424
dumpThreshold = ownedShare - potential.getPortfolioModel().getShareNumber(company) + 1;
425-
possibleSharesToSell = PlayerShareUtils.sharesToSell(company, currentPlayer);
425+
possibleSharesToSell = PlayerShareUtils.sharesToSell(company, currentPlayer);
426+
427+
426428
dumpIsPossible = true;
427429
log.debug("dumpThreshold = " + dumpThreshold);
428430
log.debug("possibleSharesToSell = " + possibleSharesToSell);
@@ -445,8 +447,8 @@ public void setSellableShares() {
445447
SortedMultiset<Integer> certCount = playerPortfolio.getCertificateTypeCounts(company);
446448

447449
// Make sure that single shares are always considered (due to possible dumping)
448-
SortedSet<Integer> certSizeElements =Sets.newTreeSet(certCount.elementSet());
449-
certSizeElements.add(1);
450+
SortedSet<Integer> certSizeElements = Sets.newTreeSet(certCount.elementSet());
451+
certSizeElements.add(1);
450452

451453
for (int shareSize:certSizeElements) {
452454
int number = certCount.count(shareSize);
@@ -489,18 +491,36 @@ public void setSellableShares() {
489491
if (number <= 0) {
490492
continue;
491493
}
494+
492495

493-
for (int i=1; i<=number; i++) {
494-
// check if selling would dump the company
495-
if (dumpIsPossible && i*shareSize >= dumpThreshold) {
496-
// dumping requires that the total is in the possibleSharesToSell list and that shareSize == 1
497-
// multiple shares have to be sold separately
498-
if (shareSize == 1 && possibleSharesToSell.contains(i*shareSize)) {
499-
possibleActions.add(new SellShares(company, shareSize, i, price, 1));
496+
for (int i=1; i<=number; i++) { //For a president certificate only the number is 2.. but it may also be 2 if the player has more than just the president certificate..
497+
if(checkIfSplitSaleOfPresidentAllowed()) {
498+
// check if selling would dump the company
499+
if (dumpIsPossible && i*shareSize >= dumpThreshold) {
500+
// dumping requires that the total is in the possibleSharesToSell list
501+
if (shareSize == 1 && possibleSharesToSell.contains(i*shareSize)) {
502+
possibleActions.add(new SellShares(company, shareSize, i, price, 1));
503+
}
504+
} else {
505+
// ... no dumping: standard sell
506+
possibleActions.add(new SellShares(company, shareSize, i, price, 0));
500507
}
501-
} else {
502-
// ... no dumping: standard sell
503-
possibleActions.add(new SellShares(company, shareSize, i, price, 0));
508+
}
509+
else {
510+
if (dumpIsPossible && i*shareSize >= dumpThreshold) {
511+
if ( certCount.isEmpty() && number == 2) {
512+
513+
possibleActions.add(new SellShares(company, 2, 1, price, 1));
514+
}
515+
else {
516+
if (((!certCount.isEmpty()) && (number ==1) ) || number >2) {
517+
possibleActions.add(new SellShares(company, shareSize, i, price, 1));
518+
}
519+
}
520+
}
521+
else {
522+
possibleActions.add(new SellShares(company, shareSize, i, price, 0));
523+
}
504524
}
505525
}
506526
}
@@ -524,6 +544,11 @@ public void setSellableShares() {
524544
}
525545
}
526546

547+
protected boolean checkIfSplitSaleOfPresidentAllowed() {
548+
// To be overwritten in Stockround Classes for games where that is not allowed e.g. 1835
549+
return true;
550+
}
551+
527552
protected void setSpecialActions() {
528553

529554
List<SpecialProperty> sps =
@@ -1053,6 +1078,17 @@ > getGameParameterAsInt(GameDef.Parm.POOL_SHARE_LIMIT)) {
10531078
numberToSell -= presidentShareNumbersToSell;
10541079
}
10551080
}
1081+
else {
1082+
if (currentPlayer == company.getPresident() && shareUnits == 2) {
1083+
dumpedPlayer = company.findPlayerToDump();
1084+
if (dumpedPlayer != null) {
1085+
presidentShareNumbersToSell = PlayerShareUtils.presidentShareNumberToSell(
1086+
company, currentPlayer, dumpedPlayer, numberToSell+1);
1087+
// reduce the numberToSell by the president (partial) sold certificate
1088+
numberToSell -= presidentShareNumbersToSell;
1089+
}
1090+
}
1091+
}
10561092

10571093
certsToSell = PlayerShareUtils.findCertificatesToSell(company, currentPlayer, numberToSell, shareUnits);
10581094

@@ -1406,7 +1442,7 @@ protected void finishTurn() {
14061442
setAutopass (currentPlayer, false);
14071443
} else {
14081444
// Process a pass for a player that has set Autopass
1409-
done (null, currentPlayer.getId(), true);
1445+
done (null, currentPlayer.getId(), true);
14101446
}
14111447
}
14121448
}
@@ -1614,14 +1650,14 @@ public String getRoundName() {
16141650
return "StockRound " + getStockRoundNumber();
16151651
}
16161652

1617-
public boolean isSellObligationLifted(PublicCompany company) {
1653+
public boolean isSellObligationLifted(PublicCompany company) {
16181654
return sellObligationLifted != null
16191655
&& sellObligationLifted.contains(company);
16201656
}
16211657

1622-
public void setSellObligationLifted (PublicCompany company) {
1658+
public void setSellObligationLifted (PublicCompany company) {
16231659
if (sellObligationLifted == null) {
1624-
sellObligationLifted = HashSetState.create(this, "sellObligationLifted");
1660+
sellObligationLifted = HashSetState.create(this, "sellObligationLifted");
16251661
}
16261662
sellObligationLifted.add(company);
16271663
}

src/main/java/net/sf/rails/game/model/CertificatesModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ ImmutableMultimap<String, PublicCertificate> getCertificatesByType(PublicCompany
104104
SortedMultiset<Integer> getCertificateTypeCounts(PublicCompany company) {
105105
ImmutableSortedMultiset.Builder<Integer> certCount = ImmutableSortedMultiset.naturalOrder();
106106
for (PublicCertificate cert : getCertificates(company)) {
107-
if (!cert.isPresidentShare()) {
107+
if (!cert.isPresidentShare()) {
108108
certCount.add(cert.getShares());
109109
}
110110
}

src/main/java/net/sf/rails/game/model/PortfolioModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public ImmutableList<PublicCertificate> getCertsOfType(String certTypeId) {
229229

230230
/**
231231
* @return a sorted Multiset<Integer> of shareNumbers of the certificates
232-
* Remark: excludes the presdident share
232+
* Remark: excludes the presdident share if not of a different size as the standard share...
233233
*/
234234
// FIXME: Integers could be replaced later by CerficateTypes
235235
public SortedMultiset<Integer> getCertificateTypeCounts(PublicCompany company) {

0 commit comments

Comments
 (0)