Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/WCSumpton/triplea
Browse files Browse the repository at this point in the history
  • Loading branch information
WCSumpton committed Sep 18, 2023
2 parents 1924237 + 49f4fc6 commit f072c15
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-bot-update-maps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: Ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run Ansible to Deploy
run: |
pip install ansible==2.9.13
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: Ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Load SSH private key into ssh-agent
uses: webfactory/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload-game-installers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: Ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Fetch depth of 0 is needed so we checkout the full revision history
# The current revision count will be used as our build-number
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'com.github.ben-manes.versions' version '0.47.0'
id 'com.github.ben-manes.versions' version '0.48.0'
id 'io.franzbecker.gradle-lombok' version '5.0.0' apply false
id 'com.diffplug.spotless' version '6.21.0' apply false
}
Expand Down Expand Up @@ -55,7 +55,7 @@ subprojects {
commonsIoVersion = '2.13.0'
commonsMathVersion = '3.6.1'
commonsTextVersion = '1.10.0'
databaseRiderVersion = '1.40.0'
databaseRiderVersion = '1.41.0'
dropwizardVersion = '2.1.0'
dropwizardWebsocketsVersion = '1.3.14'
equalsVerifierVersion = '3.15.1'
Expand All @@ -74,7 +74,7 @@ subprojects {
jaxbApiVersion = '2.3.1'
jaxbCoreVersion = '4.0.3'
jaxbImplVersion = '4.0.3'
jdbiVersion = '3.41.0'
jdbiVersion = '3.41.1'
jetbrainsAnnotationsVersion = '24.0.1'
jlayerVersion = '1.0.1.4'
junitJupiterVersion = '5.10.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ protected void perform(final GameState data) {
newTotalDamage.forEach(
(unitId, damage) -> {
final Unit unit = data.getUnits().get(UUID.fromString(unitId));
unit.setHits(damage);
if (unit != null) {
unit.setHits(damage);
}
});
// invoke territory change listeners
for (final String territory : territoriesToNotify) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ private void findUnitsThatCantMove(

Map<Territory, ProTerritory> moveMap = territoryManager.getDefendOptions().getTerritoryMap();
Map<Unit, Set<Territory>> unitMoveMap = territoryManager.getDefendOptions().getUnitMoveMap();
List<ProTransport> transportMapList = territoryManager.getDefendOptions().getTransportList();

// Add all units that can't move (to be consumed, allied units, 0 move units, etc)
for (final Territory t : moveMap.keySet()) {
Expand All @@ -252,26 +251,13 @@ private void findUnitsThatCantMove(
// Add all units that only have 1 move option and can't be transported
for (final Iterator<Unit> it = unitMoveMap.keySet().iterator(); it.hasNext(); ) {
final Unit u = it.next();
if (unitMoveMap.get(u).size() == 1) {
final Territory onlyTerritory = CollectionUtils.getAny(unitMoveMap.get(u));
if (onlyTerritory.equals(unitTerritoryMap.get(u))) {
boolean canBeTransported = false;
for (final ProTransport pad : transportMapList) {
for (final Territory t : pad.getTransportMap().keySet()) {
if (pad.getTransportMap().get(t).contains(onlyTerritory)) {
canBeTransported = true;
}
}
for (final Territory t : pad.getSeaTransportMap().keySet()) {
if (pad.getSeaTransportMap().get(t).contains(onlyTerritory)) {
canBeTransported = true;
}
}
}
if (!canBeTransported) {
moveMap.get(onlyTerritory).addCantMoveUnit(u);
it.remove();
}
final Set<Territory> territories = unitMoveMap.get(u);
if (territories.size() == 1) {
final Territory onlyTerritory = CollectionUtils.getAny(territories);
if (onlyTerritory.equals(unitTerritoryMap.get(u))
&& !canPotentiallyBeTransported(onlyTerritory)) {
moveMap.get(onlyTerritory).addCantMoveUnit(u);
it.remove();
}
}
}
Expand Down Expand Up @@ -325,6 +311,24 @@ private Map<Unit, Set<Territory>> findInfraUnitsThatCanMove() {
return infraUnitMoveMap;
}

private boolean canPotentiallyBeTransported(Territory unitTerritory) {
final List<ProTransport> transportMapList =
territoryManager.getDefendOptions().getTransportList();
for (final ProTransport pad : transportMapList) {
for (final Territory t : pad.getTransportMap().keySet()) {
if (pad.getTransportMap().get(t).contains(unitTerritory)) {
return true;
}
}
for (final Territory t : pad.getSeaTransportMap().keySet()) {
if (pad.getSeaTransportMap().get(t).contains(unitTerritory)) {
return true;
}
}
}
return false;
}

private List<Territory> moveOneDefenderToLandTerritoriesBorderingEnemy() {

ProLogger.info("Determine which territories to defend with one land unit");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ProTerritory {
private ProBattleResult battleResult;

// Non-combat move variables
private final List<Unit> cantMoveUnits;
private final Set<Unit> cantMoveUnits;
private List<Unit> maxEnemyUnits;
private Set<Unit> maxEnemyBombardUnits;
private ProBattleResult minBattleResult;
Expand Down Expand Up @@ -89,7 +89,7 @@ public ProTerritory(final Territory territory, final ProData proData) {
currentlyWins = false;
battleResult = null;

cantMoveUnits = new ArrayList<>();
cantMoveUnits = new HashSet<>();
maxEnemyUnits = new ArrayList<>();
maxEnemyBombardUnits = new HashSet<>();
minBattleResult = new ProBattleResult();
Expand Down Expand Up @@ -126,7 +126,7 @@ public ProTerritory(final Territory territory, final ProData proData) {
currentlyWins = patd.isCurrentlyWins();
battleResult = patd.getBattleResult();

cantMoveUnits = new ArrayList<>(patd.getCantMoveUnits());
cantMoveUnits = new HashSet<>(patd.getCantMoveUnits());
maxEnemyUnits = new ArrayList<>(patd.getMaxEnemyUnits());
maxEnemyBombardUnits = new HashSet<>(patd.getMaxEnemyBombardUnits());
minBattleResult = patd.getMinBattleResult();
Expand Down Expand Up @@ -332,8 +332,8 @@ public String getResultString() {
return sb.toString();
}

public List<Unit> getCantMoveUnits() {
return Collections.unmodifiableList(cantMoveUnits);
public Collection<Unit> getCantMoveUnits() {
return Collections.unmodifiableCollection(cantMoveUnits);
}

public void addCantMoveUnit(final Unit unit) {
Expand Down
Loading

0 comments on commit f072c15

Please sign in to comment.