Browse Source

Work on cost overflow calculations

combat-2
MagicBot 7 months ago
parent
commit
29ce3537f7
  1. 56
      src/engine/gameManager/ForgeManager.java

56
src/engine/gameManager/ForgeManager.java

@ -31,25 +31,6 @@ public enum ForgeManager implements Runnable { @@ -31,25 +31,6 @@ public enum ForgeManager implements Runnable {
public static final AtomicInteger wordOrderCounter = new AtomicInteger(0);
public static HashMap<Item, WorkOrder> oven = new HashMap<Item, WorkOrder>();
public static HashMap<mbEnums.ResourceType, Integer> calcWarehouseOverflow(Warehouse warehouse, HashMap<mbEnums.ResourceType, Integer> cost_map) {
// Method returns a map of resourceType that a transaction overdrafts.
HashMap<mbEnums.ResourceType, Integer> 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 { @@ -238,4 +219,41 @@ public enum ForgeManager implements Runnable {
return production_cost;
}
public static HashMap<mbEnums.ResourceType, Integer> calculateCostOverflow(WorkOrder workOrder) {
HashMap<mbEnums.ResourceType, Integer> 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<mbEnums.ResourceType, Integer> 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;
}
}

Loading…
Cancel
Save