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
Craftsman
Posts: 113
Joined: 19-Jan-14 06:11

Critter behaviour and triggers

Post by kaypy » 9-Apr-18 01:17

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

User avatar
Saumun
Grand Master
Posts: 1695
Joined: 20-Feb-09 02:03
Location: The Ether

Re: Critter behaviour and triggers

Post by Saumun » 9-Apr-18 07:32

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.
“That which can be asserted without evidence, can be dismissed without evidence.” - Christopher Hitchens

kaypy
Craftsman
Posts: 113
Joined: 19-Jan-14 06:11

Re: Critter behaviour and triggers

Post by kaypy » 9-Apr-18 10:38

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

I'm actually just getting a new version ready now...

User avatar
Sophia
Concise and Honest
Posts: 3909
Joined: 12-Sep-02 19:50
Location: Nowhere in particular
Contact:

Re: Critter behaviour and triggers

Post by Sophia » 10-Apr-18 20:47

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
Craftsman
Posts: 113
Joined: 19-Jan-14 06:11

Re: Critter behaviour and triggers

Post by kaypy » 11-Apr-18 11:17

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-)

User avatar
Sophia
Concise and Honest
Posts: 3909
Joined: 12-Sep-02 19:50
Location: Nowhere in particular
Contact:

Re: Critter behaviour and triggers

Post by Sophia » 11-Apr-18 18:16

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
Craftsman
Posts: 113
Joined: 19-Jan-14 06:11

Re: Critter behaviour and triggers

Post by kaypy » 12-Apr-18 13:40

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

Post Reply