From dce3822d437c3d70ad2623758deba58aaf10e8ea Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 4 Feb 2024 13:18:52 -0500 Subject: [PATCH] Update to list based lookup --- src/engine/gameManager/BuildingManager.java | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index f1c5bb83..eea9540b 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -56,15 +56,11 @@ public enum BuildingManager { if (building.hirelings.isEmpty()) return 0; - for (int i = 0; i < numOfSlots; i++) { + if (building.hirelings.size() == numOfSlots) + return -1; - if (i > building.hirelings.size()) - return i; + return building.hirelings.size() + 1; - if (building.hirelings.get(i) == null) - return i; - } - return -1; } public static int getLastAvailableSlot(Building building) { @@ -82,15 +78,10 @@ public enum BuildingManager { if (building.hirelings.isEmpty()) return numOfSlots - 1; - for (int i = numOfSlots - 1; i >= 0; i--) { - - if (i > building.hirelings.size()) - return i; + if (building.hirelings.size() == numOfSlots) + return -1; - if (building.hirelings.get(i) == null) - return i; - } - return -1; + return numOfSlots - 1; } public static BuildingLocation getSlotLocation(Building building, int slot) {