Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix items spawning with fewer charges than defined in their item group entry #39620

Merged

Conversation

ralreegorganon
Copy link
Contributor

Summary

SUMMARY: Bugfixes "Fix items spawning with fewer charges than defined"

Purpose of change

An item spawn that looks like this { "item": "40x46mm_m1006", "charges": 4 } should spawn 4 charges of the item in question, but instead would spawn between 1 and 4 charges.

Per the documentation, defining charges like this should be setting the min and max charges to 4 (which it was), and then the actual spawn amount should be a random value between the min and max... which should be 4 (it wasn't).

I tracked this down to this change which effectively made it so that if the maximum charges was set (which happens both when setting the max directly or just setting the charges which sets both min and max) then the minimum number of charges would be set to 0 rather than the provided value. The system later clamps the minimum value to 1, thus resulting in a charges entry like "charges": x actually spawning between 1 and x charges.

Describe the solution

Wrote some unit tests to assert what I thought was happening here, confirmed that the particular scenario in question failed the test, then reverted the change and confirmed that all the tests passed.

Testing

The added unit tests.

@ralreegorganon ralreegorganon added Spawn Creatures, items, vehicles, locations appearing on map Code: Tests Measurement, self-control, statistics, balancing. [C++] Changes (can be) made in C++. Previously named `Code` labels Apr 17, 2020
@ralreegorganon ralreegorganon force-pushed the fix-item-group-charges branch from c931c42 to d946de7 Compare April 17, 2020 02:32
@ralreegorganon ralreegorganon force-pushed the fix-item-group-charges branch from d946de7 to ee250d0 Compare April 17, 2020 03:59
@ZhilkinSerg
Copy link
Contributor

Excel agrees:

variant max_capacity charges.first charges.second charges_min charges_max charges_min_f_pr charges_min_f_prev result_f_pr result_f_prev
1 max_capacity -1 -1 0 max_capacity 0 0 0-max_capacity 0-max_capacity
2 max_capacity -1 second 0 second 0 0 0-second 0-second
3 max_capacity first -1 first max_capacity first 0 first-max_capacity 0-max_capacity
4 max_capacity first second first second first 0 first-second 0-second

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. Spawn Creatures, items, vehicles, locations appearing on map
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants