Random NPC classes can define weighted chance of spawning #75384
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
Infrastructure "Random NPC classes can define weighted chance of spawning, relative to other random NPC classes"
Purpose of change
Multiple contributors requested this feature on the development discord. It makes sense - not every randomly spawnable class should be just as common as each other.
Describe the solution
Add a weighting variable, put the classes in a weighted list, pick from the list. Uses existing RNG functions - nothing new or fancy here. Existing classes without this variable defined will all have the same weight - 1.0, and will work exactly the same as before. If no weights are added, then the weight of each is 1.0, and the chances for a particular NPC class to roll is exactly the same as before.
Describe alternatives you've considered
Full support for conditions and math, so that the chance could be dynamic based on post-cataclysm time or other variables 😈
...That's a lot more effort though.
Testing
Game correctly errors when weighting is defined but class cannot spawn
Locally set the "Operator" class to 500 weight. Spawned about 10 NPCs after starting a new game. Got one doctor, the rest were operators. Quite the difference.
Additional context