Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dropping only two or so items when selecting to drop all of a stack.
The problem is within `convert_to_items`. It has code that converts an item pointer to a stack of items in the main inventory (e.g. 100 flyers) into multiple pointers, each to a different item within that stack. E.g. when the dropping is started, the user has selected the stack of 100 flyers and a count of 100. This is a **single** pair of information added to the activity: the pointer to the first item of the stack and the number 100. `convert_to_items` converts that into 100 `act_item` instances (each contains a pointer to a different item within that stack of flyers, a move cost, and a count of 1 for each instance). This is later given to the actual dropping code, which works fine for now, it drops the first item of that stack. But at the end of the dropping code (after dropping one item), the remaining values used to be converted back into item position and count values (two integers) in order to store them in the activity to resume this upon the next turn. This was done in `convert_to_locations` (the other overload), which used to look up the item position and merge the multiple instance that all pointed to the same item position (again: **old** code). The new code only compares the `item_location`, which compares the actual item pointers. Those don't match (one points to the first item in the stack, the next one to the second item in the stack and so on). So the pairs are not merged back into a single item position and count pair. Now the activity contains 99 instance of items to be dropped. Upon loading those the next time, they go through `convert_to_items`, which gets their item position and creates **new** `item_location` instances, but because the count for each of those items is 1, they all point to the first item in the stack (caused by the loop over the item stack in `convert_to_items` (the loop there over `p.inv.const_stack` only visits the first one, after visiting that one `obtained` is 1, as is `count`). Now the code drops the first of those items. But this invalidates all the remaining instances (remember: they all point to the same item!) and so dropping stops and no more items are stored for dropping next time.
- Loading branch information