Skip to content

Commit

Permalink
Merge pull request #5834 from SJuliez/5769-id-overlap
Browse files Browse the repository at this point in the history
#5769: Possibly fix ID overlap when reinforcing from MUL
  • Loading branch information
HammerGS authored Aug 1, 2024
2 parents f21a917 + 146b1c3 commit c325ae1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion megamek/src/megamek/common/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ public synchronized void addEntity(Entity entity, boolean genEvent) {
}
// Add this Entity, ensuring that its id is unique
int id = entity.getId();
if (inGameObjects.containsKey(id)) {
if (isIdUsed(id)) {
id = getNextEntityId();
entity.setId(id);
}
Expand All @@ -1216,6 +1216,13 @@ && getOptions().booleanOption(OptionsConstants.RPG_CONDITIONAL_EJECTION)) {
}
}

/**
* @return true if the given ID is in use among active and dead units
*/
private boolean isIdUsed(int id) {
return inGameObjects.containsKey(id) || isOutOfGame(id);
}

public void setEntity(int id, Entity entity) {
setEntity(id, entity, null);
}
Expand Down

0 comments on commit c325ae1

Please sign in to comment.