Thursday, June 12, 2014

Reasonable Random Hostile NPC Encounters

Here's the question I was asking myself -- how do I create random encounters with enemies, but limit the seemingly random nature of them? Here are the requirements I wanted to fulfill:


  1. The NPCs should make sense with the surrounding terrain. For example ... I shouldn't encounter beach creatures in the forest.

    Creatures following me with hostile intent should not follow me out of their normal habitat without special coercion. It shouldn't be normally allowed to lure a crab so far out of the beach that it ends up in the forest with me (unless thralled or something)
  2. I shouldn't be continuously mobbed by creatures -- the "tempo" of encounters should be somewhat regulated and related to the geography.
To this effect, there has to be something "sampling" the terrain around the player as they walk through the world. 

  1. Each tile self identifies itself as belonging to a terrain type.
  2. The sampler samples a 4x4 area around the player, and tallies the number of tiles per terrain.
  3. The area around the player is declared a terrain type if the terrain bucket exceeds 30% of the total sampled tiles.
The random encounter orchestrator piece should then decide whether or not to spawn an npc within the vicinity (but not in view) of the player, based on this information:
  1. Are there too many hostiles within the area already -- have we reached the maximum number of hostiles that should be accosting the player at any given moment, based on his level, attributes, etc.?
  2. Are there too many of the type of NPC that can be normally spawned in the terrain type already?
If the answer is "no", then we should spawn the NPC.

I plan to try to implement these algorithms into the game.

No comments:

Post a Comment