Refactor production logic to use state amounts; update calculate_max_producible function to accept default desired amount
This commit is contained in:
+7
-1
@@ -240,7 +240,13 @@ func _set_active_page_actions() -> void:
|
||||
if !g_active_items.has(pa): continue
|
||||
|
||||
var item_id: String = g_active_items[pa].item_id
|
||||
var amount = owniverse.get_available_to_produce(item_id)
|
||||
var entity: OwniverseEntity = owniverse.entities[item_id]
|
||||
|
||||
#var amount = owniverse.get_available_to_produce(item_id)
|
||||
|
||||
#var amount = owniverse.get_available_to_produce(entity)
|
||||
var amount = owniverse.calculate_max_producible(entity)
|
||||
print(item_id, " : ", amount)
|
||||
page_actions[pa].set_actions(item_id, amount)
|
||||
|
||||
|
||||
|
||||
@@ -122,14 +122,14 @@ func produce_hs(entity_id: String, value: float) -> float:
|
||||
## @param entity - entity to produce
|
||||
## @param desired_amount - desired quantity
|
||||
## @return maximum producible amount considering all constraints
|
||||
func calculate_max_producible(entity: OwniverseEntity, desired_amount: float) -> float:
|
||||
func calculate_max_producible(entity: OwniverseEntity, desired_amount: float = 1.0E150) -> float:
|
||||
var max_producible: float = desired_amount
|
||||
|
||||
# Check cost constraints - resources consumed during production
|
||||
for cost_item in entity.cost:
|
||||
if entity.cost[cost_item] == 0:
|
||||
continue
|
||||
var available = current_amount.get(cost_item, 0.0)
|
||||
var available = state.amount.get(cost_item, 0.0)
|
||||
var max_from_cost = floorf(available / entity.cost[cost_item])
|
||||
max_producible = min(max_producible, max_from_cost)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user