From 29ce3537f703da841180ae3b11ef273b69620841 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 12 Apr 2024 17:29:52 -0400 Subject: [PATCH] Work on cost overflow calculations --- src/engine/gameManager/ForgeManager.java | 56 ++++++++++++++++-------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 207de0cb..0f159c0a 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -31,25 +31,6 @@ public enum ForgeManager implements Runnable { public static final AtomicInteger wordOrderCounter = new AtomicInteger(0); public static HashMap oven = new HashMap(); - public static HashMap calcWarehouseOverflow(Warehouse warehouse, HashMap cost_map) { - - // Method returns a map of resourceType that a transaction overdrafts. - - HashMap overflowMap = new HashMap<>(); - - for (mbEnums.ResourceType resourceType : cost_map.keySet()) { - - int debit = warehouse.resources.get(resourceType) - cost_map.get(resourceType); - - // Locked resources are always unavailable - - if (debit < 0 || warehouse.locked.contains(resourceType)) - overflowMap.put(resourceType, debit); - } - - return overflowMap; - } - @Override public void run() { @@ -238,4 +219,41 @@ public enum ForgeManager implements Runnable { return production_cost; } + + public static HashMap calculateCostOverflow(WorkOrder workOrder) { + + HashMap costMap = new HashMap<>(); + Warehouse warehouse; + + // See if we can meet gold only requirements and early exit + + if (workOrder.production_cost_total.size() == 1) { + if (workOrder.vendor.building.getStrongboxValue() > workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD)) + return costMap; + } + + // Gold deficit exists so a warehouse is required + + warehouse = workOrder.vendor.building.getCity() == null ? null : workOrder.vendor.building.getCity().warehouse; + + if (warehouse == null) + return workOrder.production_cost_total; + + // Method returns a map of resourceType that a transaction overdrafts. + + HashMap overflowMap = new HashMap<>(); + + for (mbEnums.ResourceType resourceType : workOrder.production_cost_total.keySet()) { + + int debit = warehouse.resources.get(resourceType) - workOrder.production_cost_total.get(resourceType); + + // Locked resources are always unavailable + + if (debit < 0 || warehouse.locked.contains(resourceType)) + overflowMap.put(resourceType, debit); + } + + return overflowMap; + } + }