From 146b1c3449e855637c3adb2653e7cd3b12673558 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 31 Jul 2024 21:35:52 +0200 Subject: [PATCH] possibly fix id overlap when reinforcing from MUL, check graveyard for used IDs --- megamek/src/megamek/common/Game.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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); }