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

Fix #6259 error spam and deployment hang with combined arms forces #6292

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading