Skip to main content
GameDev.net gamedev.net
🔒 Locked

Basic D&D monster ai

Started by iliak Jan 12, 2010 at 2:40 PM 13 replies 9.8k views
Original Post
iliak
iliak
Hi I'm currently making a clone of Eye of the Beholder (Dungeon Eye). I'm at the point where I need to have ai for monster but I don't know where to begin... Yet I just need basic ai, nothing fancy.
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
IADaveMark
IADaveMark
You can actually start right here in this thread by answering the question, "what does a monster do?" Seriously... just tell us what a monster does in the scope of a D&D game?
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<
Xelen
Xelen
It also depends on how you build your engine. Scripting, no scripting? Is it event based if so? Events such as OnAttack, OnTick, OnPercieve, things that your engine fires when something happens. Lots of ways of doing AI, depending on what you want to happen :)
iliak
iliak
Currently the framework is in C# and OpenGL (OpenTK). Each object (monster, maze, items...) is scripted with C# (implementing interfaces). Here's the very first draft of the monster interface :


/// <summary>/// Interface for monsters/// </summary>public interface IMonster{	/// <summary>	/// Updates monster state	/// </summary>	/// <param name="monster">Monster handle</param>	void OnUpdate(Monster monster);	/// <summary>	/// Draws the monster	/// </summary>	/// <param name="monster">Monster handle</param>	void OnDraw(Monster monster);}


Here's what I want :
- In the first time is to have monster wandering the corridors.
- If the monster can see the team, then moving to it (no need to chase it, stay in a zone).
- Then if the monster is within range, attack the team.

This would be the default behaviour for a monster (hardcoded) that I would like to setup. I can rely on certain characteristics defined in the monster class (state, back row attack, melee or ranged weapon...). But on the other way, I want to be able to script monster behavior. So my first task is having the monster wandering in the maze. I can make the monster move randomly but that's not the goal.

Blocks in the maze have differents states :
- walkable
- non walkable (wall, pit...)
- special (floor plate, door, teleporter...)

- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
vaneger
vaneger
A state machine is often the most straight forward and useful thing to implement.
IADaveMark
IADaveMark
As said, a finite state machine (FSM) is what you want to use. The states (off the cuff) would be wander, approach, attack, and die. The code of what makes those states work is held in the state itself. The "AI" is in the transitions. Those are the decisions that monster makes - and you have to define them for him. For example, how does he "see" the party? Do we assume sight in all directions and even through walls but just restrict it an aggro range? That would be coded into the "wander" state and, if the conditions match, you would set the new state to the "approach" state. The transition from "approach" to "attack" would be range based as well. Is he close enough to attack? Then attack. Too far again? Back to "approach".

Hopefully you get the picture for now.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<
Promethium
Promethium
Quote:
Original post by iliak
So my first task is having the monster wandering in the maze. I can make the monster move randomly but that's not the goal.

Blocks in the maze have differents states :
- walkable
- non walkable (wall, pit...)
- special (floor plate, door, teleporter...)


The easiest way to make your monster wander is to just move it in a random direction on every update. As you have probably already found out, this is not really intelligent AI behavior. [smile]

A better solution would be to give the monster a goal: Some point in the maze where it would like to go. This can just be a random point that's a bit further away than it current position. So make a circle with radius X tiles around the monster and select some point in there to be the destination.

Next you will need to find a path from the monsters current position to its destination. This is where path finding comes in. The path finding algorithm called A* (A-star) is a popular choice, do a google search. This will give you a path to the destination. Now your simply have to follow the path and the monster will seem to wander from point to point in your maze.

Of course, don't forget that every time the monster moves a tile the players may come into view, so you need to check that (and any other conditions that you can think of) on every update.
iliak
iliak
Ok, thanks guys, I have some good starts points now :)
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
AngleWyrm
AngleWyrm
Schroedinger's Mob
Another way to cut down on individually moving monsters and checking their line-of-sight for encounters.

Monsters start without a solid location. Instead, they have a bounding box for the area where they might be at any given moment. And this bounding box can be shared by several mobs that constitute an encounter.

When the player enters the bounding box, only the player's line of sight is traced through the area. The area is divided into visible and unvisible locations. Along the edges of the player's line of sight within the box, one of the mobs is placed, with the remainder being placed in the out-of-sight locations for that moment.
--"I'm not at home right now, but" = lights on, but no ones home
electroreactive
electroreactive
Well, for D&D you need swarm AI, swarms are a nice encounter for some levels.
Individual creatures aren't used... it's managed as a 'mass' with a center.
You also need individual creature ai... generally, find and hit! Sometimes 'activate ability'. You also need a weighting function to decide which ability to use. It's better if you map all abilities, including the general thwack, as a probability of helping you survive this encounter... essentially the monsters want to live.

You might also need AI for extremely slow monsters that will try to intercept and/or set traps.
You might also need AI for monsters that will try to flank (Basically, pin you inbetween two monsters... it makes the game harder.

And the AI should have a difficulty level... which can be managed both by the difficulty of the overall encounter and disabling certain advantageous abilities.

Also flanking... every rogue should know how to flank... and enemies against rogues should try to use concealment. These are basically squares... it's easier if you have the creatures themselves set the flanking squares and have this in a function run for each creature. "You can flank me from here." That should make things a bit easier. One function for medium, another for large, and another for the size categories of dragons. WHEE!!! Make sure to make notes of how you do it, best kept in the source.

Also, make sure the characters will ready crossbows or throw daggers when they can't reach the enemies.

[Edited by - electroreactive on January 17, 2010 3:55:12 PM]
iliak
iliak
Quote:
Original post by electroreactive
Well, for D&D you need swarm AI, swarms are a nice encounter for some levels.
Individual creatures aren't used... it's managed as a 'mass' with a center.
You also need individual creature ai... generally, find and hit! Sometimes 'activate ability'. You also need a weighting function to decide which ability to use. It's better if you map all abilities, including the general thwack, as a probability of helping you survive this encounter... essentially the monsters want to live.


Yes you are right, it's a fact I didn't noticed. I think I can make it possible with a kind of hierarchy. One monster is the "boss" telling others monsters what to do (I can use messages in the FSM). If the boss is killed each servant is working alone. Would be a nice idea :)

Quote:

You might also need AI for extremely slow monsters that will try to intercept and/or set traps.
You might also need AI for monsters that will try to flank (Basically, pin you inbetween two monsters... it makes the game harder.

And the AI should have a difficulty level... which can be managed both by the difficulty of the overall encounter and disabling certain advantageous abilities.

Also flanking... every rogue should know how to flank... and enemies against rogues should try to use concealment. These are basically squares... it's easier if you have the creatures themselves set the flanking squares and have this in a function run for each creature. "You can flank me from here." That should make things a bit easier. One function for medium, another for large, and another for the size categories of dragons. WHEE!!! Make sure to make notes of how you do it, best kept in the source.

Also, make sure the characters will ready crossbows or throw daggers when they can't reach the enemies.



I have a variable telling the way the monster should behaviour : front melee attack, ranged attack, attack from back or side...

- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
simesf
simesf
Sorry to come in on your post with nothing but a question Iliak, but for a long time I've been itching to try doing an EoB type game. But I've found almost no information about how to go about doing such a thing on the web. Maybe I'm googling with the wrong keywords. The only thing I found was here: http://eob.wikispaces.com/eob.vmp Did you come across any information about how to program any aspect of this kind of game on the web or in books? Any information would be much appreciated.
iliak
iliak
Quote:
Original post by simesf
Sorry to come in on your post with nothing but a question Iliak, but for a long time I've been itching to try doing an EoB type game. But I've found almost no information about how to go about doing such a thing on the web. Maybe I'm googling with the wrong keywords. The only thing I found was here: http://eob.wikispaces.com/eob.vmp Did you come across any information about how to program any aspect of this kind of game on the web or in books? Any information would be much appreciated.


You can have a look at the mantis of the project. When I find a good source of information, I report it their. The trickiest part (I think) is the way to render the maze, but with a little bit of logic everything is simple. The only assets I "stolen" are the graphics (if any graphician read this and want to help...). I made my clone from scratch. You can have a look at the source for more information, or better ask question in the mantis bug report and *if* I have enough time, I'll post some wiki pages about this...

Anyway, if you have question just ask ;)
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
Dragonsoulj
Dragonsoulj
If it is a monster and not an NPC (I've never played Eye of the Beholder but I do play D&D), then you should check to see if the player is in the line of sight. If it is and the monster is aggressive, then have it attack. For a party, have it attack the closest, the one dealing lots of damage, or the one that just killed another monster ally. Each attack can be random if you want, weighted towards the ones that the monster "thinks" need to be hit first.
simesf
simesf
Quote:
Original post by iliak


You can have a look at the mantis of the project. When I find a good source of information, I report it their. The trickiest part (I think) is the way to render the maze, but with a little bit of logic everything is simple. The only assets I "stolen" are the graphics (if any graphician read this and want to help...). I made my clone from scratch. You can have a look at the source for more information, or better ask question in the mantis bug report and *if* I have enough time, I'll post some wiki pages about this...

Anyway, if you have question just ask ;)


Well thanks very much iliak. That's very generous of you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.