Use weighted list for nested mapgen with same id #39511
Merged
+18
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: None
Purpose of change
Nested mapgen were stored in a vector and if multiple entries had the same id, they all had an equal chance of being selected--the weight attribute was being ignored.
This changes it so that nested mapgen are stored in a weighted list, and consequently behave the same way as normal mapgen: given multiple entries with the same id, those with a higher weight are more likely to be selected.
Describe the solution
Replace the std::vector used with a weighted_int_list, and then update all the usages of it accordingly.
Testing
Created some nested mapgen and tested spawning them via the debug menu, both with weights defined and omitted (which then falls back to the default weight of 1000 as documented in MAPGEN.md), and verified that the results were as expected.