Page 1 of 1

Monsters and AI

Posted: Fri Mar 30, 2007 12:22 pm
by Joramun
I have several questions / suggestions concerning monsters and AI :

I notice that there are three variables that influence the monster behavior :
1-perception
2-bravery
3-attack types

3 are used in "monster.lua" so, there's no explanation needed really, except one thing : If a monster has an "open door attack" but the door chosen cannot be broken/opened, will the monster still shoot ?

For 1 :
- how does it behave exactly ? can it be "lua-modified" ?
- Do some monsters have some qualities like :
* can see better in light than in darkness (in DM some monsters where totally blind in half-darkness, so it was possible to bypass them using the darkness spell at low power)
* can see as good in darkness as in light
* can see better in darkness / is blinded by light
* can see invisible (like Lord Chaos in O DM)
etc.

Having two types of perception instead of one can also help having very complex behaviors...

For 2 : how does it behave ? can it be "lua-modified" ?

Then suggestions :
- having an "alliance system" :
* each monster has a side (an integer)
* the party is side 0
* each monster has two tabs of booleans : 'foe', 'friend'
* a monster ignores neutrals (side field equals "nil" / "false" in 'foe')
* a monster attacks foes (side field equals "true" in 'foe')
* a monster helps friends (side field equals "true" in 'friend')
If there is a way to distinguish "nil" of "false", you can do the whole thing with one tab.
* allow adding new class of "positive attacks" called by monsters on friends.
* allow adding functions that sets the alliance status in a lua module.

Re: Monsters and AI

Posted: Sat Mar 31, 2007 3:01 am
by Sophia
Joramund wrote:If a monster has an "open door attack" but the door chosen cannot be broken/opened, will the monster still shoot ?
Yes.
Joramund wrote:- how does [perception] behave exactly ? can it be "lua-modified" ?
Right now, the formula is just:
seeing_distance = perception + light_level / 20

This formula is hardcoded. If I change it so that this formula is done by Lua instead, then everything else you've suggested becomes doable, so I'll do that...
Joramund wrote:how does [bravery] behave ? can it be "lua-modified" ?
Yes.
Look in method_causefear, in base/methods.lua. This is used by war cry etc., and is where the bravery value is used.
Joramund wrote:Then suggestions :
- having an "alliance system" :
I'll have to think a bit more about this one, and how to do it without completely losing my mind. ;)

Re: Monsters and AI

Posted: Sat Mar 31, 2007 3:53 am
by Parallax
Sophia wrote:
Joramund wrote:Then suggestions :
- having an "alliance system" :
I'll have to think a bit more about this one, and how to do it without completely losing my mind. ;)
It may be an oversimplifcation that makes some of the stuff you want to do impossible, but simply having a side exvar is sufficient to establish factions. If side=0 is the party, then any monster with side=0 is allied with the party.

After that you just need to modify the monster AI so that a monster can choose the side-appropriate action. Attack (or cast attack spell or other general nastiness) if target.side!=self.side and do nothing or cast buffs/heal if target.side=self.side.

In a regular dungeon like DM all monsters would be on the same side !=0. In a half-life dungeon scientists would be in side=0, marines in side=1, aliens in side=2, for instance. Since you can change on-the-fly the side of any number of cherry-picked monsters or even all of them at once, I believe most if not all of what you have in mind could be done.

And if you want to do something more complex like have a monster who is friends with two sides at once you can always make the AI more discriminatory than "I am Blue, I kill everything that is Not Blue" whenever a monster has to decide its next action.

Posted: Sat Mar 31, 2007 8:05 am
by beowuuf
Yeah, I mean if that 'if != side kill' is implemented, there is nothign to stop the designer interrupting the side check and comparing it in an and funciton as you suggetsed (so 5 belows to side 4 and 1, so you could interrupt a side 4 monster checking a side 5 and returning 4) etc

Posted: Sat Mar 31, 2007 11:20 am
by Joramun
Par : ok, basically that's what I thought but then i added the
friend/neutral/foe specification, because I thought of more tangled situation, like a bunch of monsters just doing a melee, or an ecosystem of monsters with predators, preys etc. (speaking of "half-life"...)

Beo : yes, but it means exporting some of the AI in a lua module,
instead of adding some dsb_check_side(id,target) etc. functions.

Anyway, I suppose I'll wait for Sophia's conclusions on this one, since I have no idea of what the hardcoded AI currently does.

Posted: Sun Apr 01, 2007 9:04 pm
by Tom Hatfield
Depending on how many factions you intend to have, a bit-flag might work better. A creature hostile to all factions (including its own) would have a faction of zero (0), so the test "if (self.faction & target.faction)" would return false in all cases. This is not a replacement for your idea so much as an extension of it, for more complicated relationships.