As I develop the monster spawning will get progressively complex, so this is an iterative approach.
Spawn Point - Coordinates of spawn point
Spawn Radius - As a player moves monsters will spawn within this area
- Check if there is more than MaxMonstersNearBy, if so exit. MaxMonstersNearBy will be set by the particular segment of the map the player is on.
- Check if there any players within viewing distance of the spawn point. If so exit. We don't want monsters to "pop" on the screen, players will wonder into them, or monsters will wonder into players
- Spawners will have a maximum number of monsters they can have spawned at any point in time.
- Check if there any spawn points outside of viewing distance but within SpawnRadius of the player. For each spawn point proceed.
- Choose a random leader, whose level is within 1 level of the player.
- Leaders have a number of followers that will spawn with them.
- Place the leader and the followers on an empty spot near the spawn point.
- Monsters will have one of the follow modes specified:
- Attack - Aggressively chase any player within x distance
- Guard - Stay still and attack only when attacked
- Wander - Moves randomly in a direction
- Follow - Follow a given unit, in the event that unit can not be found, start to wander.
- Leaders will set the mode of all followers
- Followers with no leader will go into wander mode.
- Recall that AI processing (aiThinker) is only called once every few seconds.
- AI will choose 5 waypoints and move between those waypoints until the aiThinker is called again.
This is for my game Blades of War.