diff --git a/megamek/src/megamek/common/Game.java b/megamek/src/megamek/common/Game.java index d66beae0f20..bbbcc8821de 100644 --- a/megamek/src/megamek/common/Game.java +++ b/megamek/src/megamek/common/Game.java @@ -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); } @@ -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); }