Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to pet menu for removing individual items from storage (c…
…ataclysmbnteam#2868) * Add command to pet menu for removing individual items from storage * Update monexamine.cpp * refactor: use `const` where possible the value `pet_name` does not get mutated, however reader has to read through the entire function to figure it out. using [const](https://learn.microsoft.com/en-us/cpp/cpp/const-cpp?view=msvc-170#const-values) will clarify it out and prevent possible accidental modification in the future. * refactor: use alias pet_name defined earlier using alias pet_name we used earlier * refactor: use references instead of copies i suspect you used `z.inv.erase` at the end of function after experiencing that `monster_inv.erase` did not remove item from monster's inventory. this is because `monster_inv` was a **copy** of `z.inv`. so while item from `monster_inv` was erased, it monsters inventory was kept intact. if you're using `monster_inv` as alias to `z.inv`, you should use [references](https://learn.microsoft.com/en-us/cpp/cpp/references-cpp?view=msvc-170) to ensure that - it does not get copied - mutating `monster_inv` are the same as mutating `z.inv` * refactor: group related usages together 1. adding comment to clarify why we need to remove 1 from index. 2. declaring `selection` to prevent making off-by-1 error. 3. grouped related mutation ('pop' an element from vector). 4. grouped you and its usage close together. --------- Co-authored-by: scarf <[email protected]>
- Loading branch information