Skip to content

Commit

Permalink
The "transfer all items" and "wait until N" caravan actions now sort …
Browse files Browse the repository at this point in the history
…and merge both the output and input inventories after delivery. Resolves pyanodon/pybugreports#670
  • Loading branch information
notnotmelon committed Nov 9, 2024
1 parent 8e0d002 commit 7b71782
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Date: ?
- Deleted the micromine turd.
- The micromine machine now has a fixed recipe for incubated petri dishes.
- The "transfer all items" caravan action will now preserve metadata for even more items such as equipment grids, blueprint data, and upgrade planner data.
- The "transfer all items" and "wait until N" caravan actions now sort and merge both the output and input inventories after delivery. Resolves https://github.com/pyanodon/pybugreports/issues/670
---------------------------------------------------------------------------------------------------
Version: 3.0.18
Date: 2024-11-7
Expand Down
6 changes: 6 additions & 0 deletions scripts/caravan/caravan-prototypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ local function transfer_all_items(input_inventory, output_inventory)
stack.count = stack.count - inserted_count
end
end
input_inventory.sort_and_merge()
output_inventory.sort_and_merge()
end

local function transfer_filtered_items(input_inventory, output_inventory, item, goal) -- TODO: make it work with complex items. currently it wipes data on for example equipment grids
Expand All @@ -157,6 +159,8 @@ local function transfer_filtered_items(input_inventory, output_inventory, item,
elseif inventory_count > goal then
local inserted_count = output_inventory.insert {name = item, count = inventory_count - goal}
if inserted_count ~= 0 then input_inventory.remove {name = item, count = inserted_count} end
input_inventory.sort_and_merge()
output_inventory.sort_and_merge()
return inserted_count == inventory_count - goal
elseif inventory_count < goal then
local removed_count = output_inventory.remove {name = item, count = goal - inventory_count}
Expand All @@ -167,6 +171,8 @@ local function transfer_filtered_items(input_inventory, output_inventory, item,
output_inventory.insert {name = item, count = couldnt_fit}; return false
end
end
input_inventory.sort_and_merge()
output_inventory.sort_and_merge()
return removed_count == goal - inventory_count
end
end
Expand Down

1 comment on commit 7b71782

@AFranticTypist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! I will test it.

Please sign in to comment.