Critter behaviour and triggers

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Critter behaviour and triggers

Post by kaypy »

The backstory here is that I had a nasty hack to simulate monsters following the party through stairs and am trying to make a more natural version.

So the questions I am currently facing are:

(1) Is there a way to trigger when monsters rearrange themselves on a tile? Something sort of like "on_turn" does for the player? I need to keep things at the front of the stair tile or the graphics don't work right. Also, if the monster decides to flee then I should shunt it back to the other side of the stair.

(2) The monster far AI should possibly have some mechanism to handle targets. Currently I have a hack added to the far_ai that calls into regular AI if there are any targets set, but I'm wondering if there should be something in the base code. (When the player uses a stair, I set a target for any monster that can see the player)

(3) Even with the aforementioned hack, monsters don't seem to be particularly enthusiastic about following targets. They seem to wander off about half the time...

oh, also

(4) Is there a 'proper' way to test if a tile is passable to the player? I have a method based on the monster_ai that loops through the insts and checks the collision on each, but I'm wondering if I have missed some 'official' method...

Thanks
Friends don't let friends eat worm round
User avatar
Saumun
High Lord
Posts: 2238
Joined: Fri Feb 20, 2009 3:03 am
Location: The Ether

Re: Critter behaviour and triggers

Post by Saumun »

Unrelated, but since you’re here...
Someone was having trouble downloading your Probably Solvable RDG, here viewtopic.php?f=53&t=30666
Link seemed fine for me, so not sure what the trouble is.
“Grynix Ernum Quey Ki Skebow Rednim U Os Dey Wefna Enocarn Aquantana” - Anon
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Re: Critter behaviour and triggers

Post by kaypy »

Ah, thanks- I'd completely missed that. (Wonder why it was posted there?)

I'm actually just getting a new version ready now...
Friends don't let friends eat worm round
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Critter behaviour and triggers

Post by Sophia »

kaypy wrote:Is there a way to trigger when monsters rearrange themselves on a tile? Something sort of like "on_turn" does for the player? I need to keep things at the front of the stair tile or the graphics don't work right. Also, if the monster decides to flee then I should shunt it back to the other side of the stair.
There is no hook as such, but you can probably do the same basic thing yourself by wrapping the AI function monster_rearrange with something like this:

Code: Select all

base_monster_rearrange = monster_rearrange
function monster_rearrange(id, dir, reason)
   -- your code here
   if (monsters_shouldnt_rearrange_themselves_for_whatever_reason) then
       return false
   end

   return base_monster_rearrange(id, dir, reason)
end
This is a little bit ugly, but an on_rearrange hook would have to be defined for every monster, or it would have to be a sys_ function, and those are ugly too, so I think this is probably the best idea.
kaypy wrote:The monster far AI should possibly have some mechanism to handle targets. Currently I have a hack added to the far_ai that calls into regular AI if there are any targets set, but I'm wondering if there should be something in the base code. (When the player uses a stair, I set a target for any monster that can see the player)
In the base code, targets are used in a very limited fashion: a target is added when the party is seen, so the monster will continue to go towards that location even if you step out of sight. If you run away fast enough that it switches to the far AI, the monster will stop hunting that target, which at the time I saw as a feature, as it keeps a whole mob of monsters from chasing you all over the level. In addition, as I'll explain below, monsters who are far away probably won't do a very good job of finding their targets anyway...
kaypy wrote:Even with the aforementioned hack, monsters don't seem to be particularly enthusiastic about following targets. They seem to wander off about half the time...
In order to feel a bit more like real DM (and also because I was lazy) the pathfinding used in DSB is not very sophisticated, so if there are a lot of twists and turns on the way to the target, the monster is probably going to get lost. Probably inadequate for what you're trying to do!

A simple implementation of something more robust (probably A*-like or whatever) shouldn't be too much trouble, so I'll look into that.
kaypy wrote:Is there a 'proper' way to test if a tile is passable to the player? I have a method based on the monster_ai that loops through the insts and checks the collision on each, but I'm wondering if I have missed some 'official' method...
No, there's nothing official, because checking if a tile is passable and moving there is low level enough I didn't see the need to expose it to Lua. There is, of course, a Lua function to check if a tile is passable to a monster (canigo) so I'm not sure if that's any help.
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Re: Critter behaviour and triggers

Post by kaypy »

re monster_rearrange:
Oh. I hadn't seen that. I will need to play around with it and see what I can make it do 8-)

on targetting:
A full A* might be overkill, but I was having critters move off randomly when the target was adjacent or a few tiles away

The situation was something like:

Code: Select all

#######
##..M##
#..M..#
##M@M##
###<###
#######
(roguelike style @=player M=monster <=stairs)

and if the player retreated up the stairs and a target was set behind them, the monsters would mostly fail to find their way to the target.
(I had the use-normal-AI hack and a log dump of their location and target list). I hadn't looked too closely at the LUA as it was some hairy code and the whole system was sorta workingish: stairs were making me nervous instead of feeling exploity.

on passability:
canigo was the template I used for partyCanGo 8-)
Friends don't let friends eat worm round
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Critter behaviour and triggers

Post by Sophia »

I think that a big problem you're having with using the near AI code in this case is that the "presence" of the party is confusing them: the near AI code never actually checks that the party is on the same level as the monster, because that (normally) is one of the preconditions for even calling it. All comparisons are based on x and y coordinates only. This means that if you've moved around upstairs, the monsters will 'see' the party in an equivalent location on their own level, and try to chase this 'phantom party' down, rather than going after their target.
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Re: Critter behaviour and triggers

Post by kaypy »

Putting the stairways a big horizontal distance away does seem to help...

I guess I should see if I can reproduce the target code in the far AI rather than just calling to the base AI...

thanks
Friends don't let friends eat worm round
Post Reply