Skip to content

Commit

Permalink
Merge pull request #6292 from Sleet01/mm_6259_error_spam_and_deployme…
Browse files Browse the repository at this point in the history
…nt_hang_with_combined_arms_forces

Fix #6259 error spam and deployment hang with combined arms forces
  • Loading branch information
Sleet01 authored Dec 19, 2024
2 parents 37aee40 + 5bcc422 commit 953fc5b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
8 changes: 5 additions & 3 deletions megamek/src/megamek/client/bot/BotClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ public void gameTurnChange(GameTurnChangeEvent e) {
public void gamePhaseChange(GamePhaseChangeEvent e) {
calculatedTurnThisPhase = false;
if (e.getOldPhase().isSimultaneous(getGame())) {
logger.info("%s: Calculated %d / %d turns for phase %s",
logger.info(
String.format("%s: Calculated %d / %d turns for phase %s",
getName(), calculatedTurnsThisPhase,
getGame().getEntitiesOwnedBy(getLocalPlayer()), e.getOldPhase());
getGame().getEntitiesOwnedBy(getLocalPlayer()), e.getOldPhase()
)
);
}
calculatedTurnsThisPhase = 0;
}
Expand Down Expand Up @@ -654,7 +657,6 @@ public double getMassOfAllInBuilding(final Game game, final Coords coords) {
return dest;
}

logger.error("Returning no deployment position; THIS IS BAD!");
// If NONE of them are acceptable, then just return null.
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,11 @@ protected Coords rankDeploymentCoords(Entity deployedUnit, List<Coords> possible
logger.debug(sb.toString());
}
// Fall back on old method
return super.getFirstValidCoords(deployedUnit, possibleDeployCoords);
Coords bestCandidate = super.getFirstValidCoords(deployedUnit, possibleDeployCoords);
if (bestCandidate == null) {
logger.error("Returning no deployment position; THIS IS BAD!");
}
return bestCandidate;
}

@Override
Expand Down
8 changes: 5 additions & 3 deletions megamek/src/megamek/common/EquipmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,11 @@ public boolean hasModeType(String modeType) {
}

// Avoid Concurrent Modification exception with this one simple trick!
for (Iterator<EquipmentMode> iterator = modes.iterator(); iterator.hasNext();) {
if (iterator.next().getName().equals(modeType)) {
return true;
synchronized (modes) {
for (Iterator<EquipmentMode> iterator = modes.iterator(); iterator.hasNext(); ) {
if (iterator.next().getName().equals(modeType)) {
return true;
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions megamek/src/megamek/common/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,9 @@ public synchronized List<Entity> getEntitiesVector(Coords c, boolean ignore) {
if (entityPosLookup.isEmpty() && !inGameTWEntities().isEmpty()) {
resetEntityPositionLookup();
}
// For sanity check
GamePhase phase = getPhase();

Set<Integer> posEntities = entityPosLookup.get(c);
List<Entity> vector = new ArrayList<>();
if (posEntities != null) {
Expand All @@ -1492,9 +1495,9 @@ public synchronized List<Entity> getEntitiesVector(Coords c, boolean ignore) {
if (e.isTargetable() || ignore) {
vector.add(e);

// Sanity check
// Sanity check: report out-of-place entities if it's not the deployment phase
HashSet<Coords> positions = e.getOccupiedCoords();
if (!positions.contains(c)) {
if (!phase.isDeployment() && !positions.contains(c)) {
logger.error(e.getDisplayName() + " is not in " + c + "!");
}
}
Expand Down
4 changes: 3 additions & 1 deletion megamek/src/megamek/common/weapons/lasers/LaserWeapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public int getModesCount(Mounted<?> mounted) {
}

//Only works if laser pulse module's "Pulse" modes are added last.
return (int) modes.stream().filter(mode -> !mode.getName().startsWith("Pulse")).count();
synchronized (modes) {
return (int) modes.stream().filter(mode -> !mode.getName().startsWith("Pulse")).count();
}
}

@Override
Expand Down

0 comments on commit 953fc5b

Please sign in to comment.