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

Random NPC classes can define weighted chance of spawning #75384

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

RenechCDDA
Copy link
Member

@RenechCDDA RenechCDDA commented Aug 2, 2024

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
image

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

@github-actions github-actions bot added <Documentation> Design documents, internal info, guides and help. NPC / Factions NPCs, AI, Speech, Factions, Ownership [C++] Changes (can be) made in C++. Previously named `Code` [Markdown] Markdown issues and PRs Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Aug 2, 2024
@dseguin dseguin merged commit 85a3241 into CleverRaven:master Aug 2, 2024
29 of 30 checks passed
@RenechCDDA RenechCDDA deleted the weighted_NPC_classes branch August 2, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style <Documentation> Design documents, internal info, guides and help. json-styled JSON lint passed, label assigned by github actions [Markdown] Markdown issues and PRs NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants