Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant prompts and inappropriate retreat options. Bump version and fix old version processing #1621

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
65574dc
Add abstract class for MustFightBattle & NonFightingBattle to consoli…
Mar 24, 2017
e26b518
Review feedback
Mar 25, 2017
29389d5
Don't prompt for retreat when only one retreat territory is valid
Mar 31, 2017
32a6142
Fix tests
Mar 31, 2017
c6a3106
Fix bug found by test
Mar 31, 2017
87fc650
Kill undefended AA Guns too
Mar 31, 2017
e6a18a4
Code formatting
Mar 31, 2017
50e199b
Fix order for subs submerging vs air only so that retreat is not inap…
Mar 31, 2017
2ae7a18
Move on 3rd version number because this fix breaks serialisation when…
Apr 1, 2017
9ecca77
Fix NPE
Apr 1, 2017
9940148
Fix NPE
Apr 1, 2017
6c7a53f
Merge branch 'cleanup' of github.com:simon33-2/triplea into cleanup
Apr 1, 2017
73c2cb5
Merge branch 'cleanup' into RemovePrompts
Apr 1, 2017
ec35384
Encode version in jar file
simon33-2 Apr 6, 2017
e2fd46e
Don't prompt for retreat when only one retreat territory is valid
Mar 31, 2017
cb0fb84
Fix tests
Mar 31, 2017
a52246a
Fix bug found by test
Mar 31, 2017
e177df8
Kill undefended AA Guns too
Mar 31, 2017
e7c5117
Code formatting
Mar 31, 2017
13fa2d3
Fix order for subs submerging vs air only so that retreat is not inap…
Mar 31, 2017
0042627
Move on 3rd version number because this fix breaks serialisation when…
Apr 1, 2017
f251c1f
Merge commit '73c2cb56790d6006540f17cbed2d9aa3cb824b71'; commit 'ec35…
simon33-2 Apr 6, 2017
59c1aca
Auto Update game_engine.properties
simon33-2 Apr 6, 2017
36e9740
Re-simplify code
simon33-2 Apr 6, 2017
21486aa
Code formatting
simon33-2 Apr 6, 2017
b53fcde
Checkstyle changes
Apr 8, 2017
3632e10
CheckStyle
Apr 8, 2017
8da098a
Remove latest_version_new file dependency
Apr 10, 2017
313b867
Merge branch 'master' into RemovePrompts
Apr 10, 2017
36b0d62
Couldn't see a way of resolving the conflict here???
Apr 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ before_deploy:
- chmod +x ./.travis/setup && ./.travis/setup
## Add the travis build number to the game engine version
- GAME_CONFIG=game_engine.properties
- ENGINE_VERSION=$(grep "engine_version" $GAME_CONFIG | sed 's/.*= *//g')
- VERSION_SOURCE=src/main/java/games/strategy/engine/config/GameEnginePropertyFileReader.java
- ENGINE_VERSION=$(grep "public static final String GAME_ENGINE_VERSION *=" $VERSION_SOURCE | sed 's/.*="//g' | cut -d\" -f2)
- export TAGGED_VERSION="$ENGINE_VERSION.$TRAVIS_BUILD_NUMBER"
- sed -i "s/engine_version.*/engine_version = $TAGGED_VERSION/" $GAME_CONFIG
## Run the gradle release build process - creates the installers
Expand Down
2 changes: 1 addition & 1 deletion game_engine.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
engine_version = 1.9.0.0
engine_version = 1.9.1.0

## Map_List_File
# URL if the value begins with http, otherwise assumed to be a file. This file lists which maps are available
Expand Down
Binary file added old/triplea_1_9_0_0.jar
Binary file not shown.
13 changes: 9 additions & 4 deletions src/main/java/games/strategy/engine/ClientFileSystemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public static File getRootFolder() {
}

final String tripleaJarNameWithEngineVersion = getTripleaJarWithEngineVersionStringPath();
if (fileName.contains("triplea_" + tripleaJarNameWithEngineVersion + ".jar!")) {
return getRootFolderRelativeToJar(fileName, tripleaJarNameWithEngineVersion);
final int locn = fileName.indexOf("triplea_" + tripleaJarNameWithEngineVersion + ".jar!");
if (locn >= 0) {
return new File(fileName.substring(0, locn - 1));
}

return getRootRelativeToClassFile(fileName);
Expand Down Expand Up @@ -68,7 +69,8 @@ private static String getTripleaJarWithEngineVersionStringPath() {

private static File getRootFolderRelativeToJar(final String fileName, final String tripleaJarName) {
final String subString =
fileName.substring("file:/".length() - (SystemProperties.isWindows() ? 0 : 1), fileName.indexOf(tripleaJarName) - 1);
fileName.substring("file:/".length() - (SystemProperties.isWindows() ? 0 : 1),
fileName.indexOf(tripleaJarName) - 1);
final File f = new File(subString).getParentFile();
if (!f.exists()) {
throw new IllegalStateException("File not found:" + f);
Expand Down Expand Up @@ -97,7 +99,10 @@ private static File getRootRelativeToClassFile(final String fileName) {
return f;
}

private static boolean folderContainsGamePropsFile(final File folder) {
private static boolean folderContainsGamePropsFile(File folder) {
if (!folder.isDirectory()) {
folder = new File(folder.toString().substring(5));
}
final File[] files = folder.listFiles();
final List<String> fileNames =
Arrays.asList(files).stream().map(file -> file.getName()).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
public class GameEnginePropertyFileReader implements PropertyReader {

public static final String GAME_ENGINE_PROPERTY_FILE = "game_engine.properties";
public static final String GAME_ENGINE_VERSION = "1.9.1";
private final File propertyFile;

public GameEnginePropertyFileReader() {
this(new File(GAME_ENGINE_PROPERTY_FILE));
}

/** This constructor here for testing purposes, use the simple no-arg constructor instead */
/* This constructor here for testing purposes, use the simple no-arg constructor instead. */
protected GameEnginePropertyFileReader(final File propertyFile) {
this.propertyFile = propertyFile;
}

@Override
public String readProperty(final GameEngineProperty propertyKey) {
if (propertyKey == GameEngineProperty.ENGINE_VERSION) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bug? It looks like object equality is being checked instead of verifying values. ie: this if statement will only be true when propertyKey and GameEnginerProperty.ENGINE_VERSION are the same instance.

return GAME_ENGINE_VERSION;
}
try (FileInputStream inputStream = new FileInputStream(propertyFile)) {
final Properties props = new Properties();
props.load(inputStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private String getOutOfDateMessage() {
text.append("<h2>A new version of TripleA is out. Please Update TripleA!</h2>");
text.append("<br />Your current version: ").append(ClientContext.engineVersion().getFullVersion());
text.append("<br />Latest version available for download: ").append(getLatestVersionOut());
text.append("<br /><br />Click to download: <a class=\"external\" href=\"").append(getLinkToDownloadLatestVersion())
text.append("<br /><br />Click to download: <a class=\"external\" href=\"")
.append(getLinkToDownloadLatestVersion())
.append("\">").append(getLinkToDownloadLatestVersion()).append("</a>");
text.append("<br />Backup Mirror: <a class=\"external\" href=\"").append(getLinkAltToDownloadLatestVersion())
.append("\">").append(getLinkAltToDownloadLatestVersion()).append("</a>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ public void resetCanBeCapturedOnEnteringBy() {
public void setWhenCapturedChangesInto(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length < 5 || (s.length - 1) % 2 != 0) {
throw new GameParseException("whenCapturedChangesInto must have 5 or more values, "
+ "playerFrom:playerTo:keepAttributes:unitType:howMany (you may have additional unitType:howMany:unitType:howMany, etc"
throw new GameParseException("whenCapturedChangesInto must have 5 or more values, playerFrom:playerTo:"
+ "keepAttributes:unitType:howMany (you may have additional unitType:howMany:unitType:howMany, etc"
+ thisErrorMsg());
}
final PlayerID pfrom = getData().getPlayerList().getPlayerID(s[0]);
Expand Down
107 changes: 55 additions & 52 deletions src/main/java/games/strategy/triplea/delegate/MustFightBattle.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,21 @@ public List<String> determineStepStrings(final boolean showFirstRun, final IDele
}
}
}
// See if there any unescorted trns
if (m_battleSite.isWater() && isTransportCasualtiesRestricted()) {
if (Match.someMatch(m_attackingUnits, Matches.UnitIsTransport)
|| Match.someMatch(m_defendingUnits, Matches.UnitIsTransport)) {
steps.add(REMOVE_UNESCORTED_TRANSPORTS);
}
}
}
// Air only Units can't attack subs without Destroyers present
if (isAirAttackSubRestricted()) {
final Collection<Unit> units = new ArrayList<>(m_attackingUnits.size() + m_attackingWaitingToDie.size());
units.addAll(m_attackingUnits);
if (Match.someMatch(m_attackingUnits, Matches.UnitIsAir) && !canAirAttackSubs(m_defendingUnits, units)) {
steps.add(SUBMERGE_SUBS_VS_AIR_ONLY);
}
}
// Check if defending subs can submerge before battle
if (isSubRetreatBeforeBattle()) {
Expand All @@ -525,13 +540,6 @@ public List<String> determineStepStrings(final boolean showFirstRun, final IDele
steps.add(m_defender.getName() + SUBS_SUBMERGE);
}
}
// See if there any unescorted trns
if (m_battleSite.isWater() && isTransportCasualtiesRestricted()) {
if (Match.someMatch(m_attackingUnits, Matches.UnitIsTransport)
|| Match.someMatch(m_defendingUnits, Matches.UnitIsTransport)) {
steps.add(REMOVE_UNESCORTED_TRANSPORTS);
}
}
// if attacker has no sneak attack subs, then defendering sneak attack subs fire first and remove casualties
final boolean defenderSubsFireFirst = defenderSubsFireFirst();
if (defenderSubsFireFirst && Match.someMatch(m_defendingUnits, Matches.UnitIsSub)) {
Expand Down Expand Up @@ -569,16 +577,6 @@ public List<String> determineStepStrings(final boolean showFirstRun, final IDele
&& (returnFireAgainstDefendingSubs() != ReturnFire.ALL || returnFireAgainstAttackingSubs() != ReturnFire.ALL)) {
steps.add(REMOVE_SNEAK_ATTACK_CASUALTIES);
}
// Air only Units can't attack subs without Destroyers present
if (isAirAttackSubRestricted()) {
final Collection<Unit> units = new ArrayList<>(m_attackingUnits.size() + m_attackingWaitingToDie.size());
units.addAll(m_attackingUnits);
// if(!Match.someMatch(m_attackingUnits, Matches.UnitIsDestroyer) && Match.allMatch(m_attackingUnits,
// Matches.UnitIsAir))
if (Match.someMatch(m_attackingUnits, Matches.UnitIsAir) && !canAirAttackSubs(m_defendingUnits, units)) {
steps.add(SUBMERGE_SUBS_VS_AIR_ONLY);
}
}
// Air Units can't attack subs without Destroyers present
if (m_battleSite.isWater() && isAirAttackSubRestricted()) {
final Collection<Unit> units = new ArrayList<>(m_attackingUnits.size() + m_attackingWaitingToDie.size());
Expand Down Expand Up @@ -611,9 +609,6 @@ public List<String> determineStepStrings(final boolean showFirstRun, final IDele
final Collection<Unit> units = new ArrayList<>(m_defendingUnits.size() + m_defendingWaitingToDie.size());
units.addAll(m_defendingUnits);
units.addAll(m_defendingWaitingToDie);
// if(!Match.someMatch(m_defendingUnits, Matches.UnitIsDestroyer) && Match.someMatch(m_defendingUnits,
// Matches.UnitIsAir) &&
// Match.someMatch(m_attackingUnits, Matches.UnitIsSub))
if (Match.someMatch(m_defendingUnits, Matches.UnitIsAir) && !canAirAttackSubs(m_attackingUnits, units)) {
steps.add(AIR_DEFEND_NON_SUBS);
}
Expand Down Expand Up @@ -648,6 +643,13 @@ public List<String> determineStepStrings(final boolean showFirstRun, final IDele
}
}
}
// See if there any unescorted trns
if (m_battleSite.isWater() && isTransportCasualtiesRestricted()) {
if (Match.someMatch(m_attackingUnits, Matches.UnitIsTransport)
|| Match.someMatch(m_defendingUnits, Matches.UnitIsTransport)) {
steps.add(REMOVE_UNESCORTED_TRANSPORTS);
}
}
// if we are a sea zone, then we may not be able to retreat
// (ie a sub travelled under another unit to get to the battle site)
// or an enemy sub retreated to our sea zone
Expand Down Expand Up @@ -715,6 +717,22 @@ public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
});
}
if (firstRun) {
/** Remove undefended trns */
if (isTransportCasualtiesRestricted()) {
steps.add(new IExecutable() {
private static final long serialVersionUID = 99989L;

@Override
public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
checkUndefendedTransports(bridge, m_defender);
checkUndefendedTransports(bridge, m_attacker);
checkForUnitsThatCanRollLeft(bridge, true);
checkForUnitsThatCanRollLeft(bridge, false);
clearWaitingToDie(bridge);
// ?? This appears to remove both sides undefended transports twice
}
});
}
steps.add(new IExecutable() {
private static final long serialVersionUID = -2255284529092427441L;

Expand Down Expand Up @@ -815,9 +833,24 @@ List<IExecutable> getBattleExecutables(final boolean firstRun) {

@Override
public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
if (Match.someMatch(m_attackingUnits, Matches.unitHasAttackValueOfAtLeast(1))
&& Match.allMatch(m_defendingUnits, Matches.unitHasDefenseThatIsMoreThanOrEqualTo(1).invert())) {
remove(m_defendingUnits, bridge, m_battleSite, true);
}
clearWaitingToDie(bridge);
}
});
/** Submerge subs if -vs air only & air restricted from attacking subs */
if (isAirAttackSubRestricted()) {
steps.add(new IExecutable() {
private static final long serialVersionUID = 99990L;

@Override
public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
submergeSubsVsOnlyAir(bridge);
}
});
}
steps.add(new IExecutable() {
// not compatible with 0.9.0.2 saved games. this is new for 1.2.6.0
private static final long serialVersionUID = 6387198382888361848L;
Expand Down Expand Up @@ -865,15 +898,10 @@ public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
// changed to only look at units that can be destroyed in combat, and therefore not include factories, aaguns,
// and infrastructure.
else if (Match.getMatches(m_defendingUnits, Matches.UnitIsNotInfrastructure).size() == 0) {
if (isTransportCasualtiesRestricted()) {
// If there are undefended attacking transports, determine if they automatically die
checkUndefendedTransports(bridge, m_defender);
}
checkForUnitsThatCanRollLeft(bridge, false);
endBattle(bridge);
attackerWins(bridge);
} else if (shouldEndBattleDueToMaxRounds()
|| (Match.allMatch(m_attackingUnits, Matches.unitHasAttackValueOfAtLeast(1).invert())
} else if (shouldEndBattleDueToMaxRounds() ||
(Match.allMatch(m_attackingUnits, Matches.unitHasAttackValueOfAtLeast(1).invert())
&& Match.allMatch(m_defendingUnits, Matches.unitHasDefendValueOfAtLeast(1).invert()))) {
endBattle(bridge);
nobodyWins(bridge);
Expand Down Expand Up @@ -1017,31 +1045,6 @@ public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
checkSuicideUnits(bridge);
}
});
/** Remove undefended trns */
if (isTransportCasualtiesRestricted()) {
steps.add(new IExecutable() {
private static final long serialVersionUID = 99989L;

@Override
public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
checkUndefendedTransports(bridge, m_defender);
checkUndefendedTransports(bridge, m_attacker);
checkForUnitsThatCanRollLeft(bridge, true);
checkForUnitsThatCanRollLeft(bridge, false);
}
});
}
/** Submerge subs if -vs air only & air restricted from attacking subs */
if (isAirAttackSubRestricted()) {
steps.add(new IExecutable() {
private static final long serialVersionUID = 99990L;

@Override
public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
submergeSubsVsOnlyAir(bridge);
}
});
}
final ReturnFire returnFireAgainstAttackingSubs = returnFireAgainstAttackingSubs();
final ReturnFire returnFireAgainstDefendingSubs = returnFireAgainstDefendingSubs();
if (defenderSubsFireFirst()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import games.strategy.util.Util;

/**
* Battle in which no fighting occurs. <b>
* Battle in which no fighting occurs.
* Example is a naval invasion into an empty country,
* but the battle cannot be fought until a naval battle
* occurs.
Expand Down Expand Up @@ -161,6 +161,9 @@ public void unitsLostInPrecedingBattle(final IBattle battle, final Collection<Un
}
}

/*
* Add dependent units - suppress javadoc error
*/
public void addDependentUnits(final Map<Unit, Collection<Unit>> dependencies) {
for (final Unit holder : dependencies.keySet()) {
final Collection<Unit> transporting = dependencies.get(holder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Logic for placing units.
* <p>
*
* Known limitations.
* Doesnt take into account limits on number of factories that can be produced.
* The situation where one has two non original factories a,b each with production 2.
Expand Down
Loading