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

Use Gillspie Algorithm to simulate NPC, faction, and monster activities when off-map. #27226

Open
kevingranade opened this issue Dec 21, 2018 · 3 comments
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world <Enhancement / Feature> New features, or enhancements on existing Map / Mapgen Overmap, Mapgen, Map extras, Map display NPC / Factions NPCs, AI, Speech, Factions, Ownership (P5 - Long-term) Long-term WIP, may stay on the list for a while.

Comments

@kevingranade
Copy link
Member

Is your feature request related to a problem? Please describe.
When the player travels into a new area, the state of that area is not modified based on the time since the cataclysm occurred. As such there is a strange player-centric effect that occurs where the world state near the player progresses differently than the state of the world elsewhere.

Describe the solution you'd like
When a new area is entered, or an area is re-entered after some amount of time has passed, run forward a very basic simulaion of the area based on populations of NPCs, animals, monsters, and resources.

This simulation can follow the Gillspie Algorithm, treating actors being modelled as particles with specified interactions and outcomes.
The key benefit of this algorithm is that when the interactions are infrequent enough, it is very efficient to calculate when the "next" interaction will occur and step time forward to that encounter. In the case of dda, the expectation is that encounters between NPCs and monsters (the primary actors) are actually fairly infrequent, and that large timespans can be processed with little computation occurring. A key part of this is that interactions that do not change the state of one of the involved actors are irrelevant and are not tracked.

Some example interactions:
NPC interacts with resources to restock their store of resources. This destroys resources and promotes the NPC to a "NPC with resources".
Over time, "NPCs with resources" decay to "NPCs without resources".
Over time, "NPCs without resources" decay to "Starving NPCs", and eventually die.
NPCs may interact with special resources to be promoted to "Well-equipped NPCs".

Membership in these various populations adjust the frequency and outcomes of subsequent interactions. NPCs with resources will tend to prioritize safety over resource acquisition and therefore interact less often with monsters. NPCs without resources gain an interaction with resources, but also have their rate of interaction with monsters increased. Well-equipped NPCs might have better rates of success in all of their interactions. Likely we will want a 2D matrix of "resources possessed" and "level of equipment/preparedness". Like with monsters, as time goes on, the survivors are the ones who have managed to survive and therefore the better equipped ones.

NPCs of all kinds can have one of several interactions with monsters:
NPC dies
Monster dies
NPC is wounded, monster dies
NPC escapes, monster is provoked (becomes a "wandering monster")

As outlined above, the rate of occurrence of these different interactions depend on the state of both interacting actors (the monster and the NPC).

Monster evolution is also modelled in that monsters can spontaneously change state.
Zombies evolve to stronger zombies, though the specific type is irrelevant.
Fungal and triffid monsters mostly multiply, though we may add other developments at some point.
Natural animals may multiply and may be harvested by NPCs or monsters. They may also be ignored.

Once this simulation has run its course, the resulting population and state data can be injected into overmap-scale generation to place actual entities representing the populations. (monster populations, resources, surviving NPCs, animal poplations)

@kevingranade kevingranade added <Enhancement / Feature> New features, or enhancements on existing NPC / Factions NPCs, AI, Speech, Factions, Ownership (P5 - Long-term) Long-term WIP, may stay on the list for a while. Map / Mapgen Overmap, Mapgen, Map extras, Map display [C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world labels Dec 22, 2018
@CoroNaut
Copy link

CoroNaut commented Dec 31, 2018

If the npc is moving around after you get a mission from them, technically there would be no way to determine where they went unless they say "I'll be here on this date..." or something similar.

Also, with the natural animals that multiply, perhaps if there is a large population of them, then a predator will wander that way and multiply there. This will help stop the exponential growth issue.

@kevingranade
Copy link
Member Author

If the npc is moving around

I don't follow you, unless you arrange something, of course you don't know where the NPC is.

@kevingranade
Copy link
Member Author

An addendum to this I want to jot down is that this technique is applicable during world generation as well. In other words when generating an overmap, we could generate HUMAN population distributions, then add various hazardous effects and entities to the mix. Then we would run forward a Gillspie algorithm to determine the occurrence of various population and map altering events. At the end of the process, a log of those events could be used to determine the initial state of the map.

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` Character / World Generation Issues and enhancements concerning stages of creating a character or a world <Enhancement / Feature> New features, or enhancements on existing Map / Mapgen Overmap, Mapgen, Map extras, Map display NPC / Factions NPCs, AI, Speech, Factions, Ownership (P5 - Long-term) Long-term WIP, may stay on the list for a while.
Projects
None yet
Development

No branches or pull requests

2 participants