Mobs

11/08/2010 16:34 Arcо#1
So I'm gonna go about asking you higher ups how you would go about coding mob movement and mob AI altogether. I'm gonna code this for my 5017, (hybrids) and I just wanna get some tips from y'all first.

btw

[brag]
[Only registered and activated users can see links. Click Here To Register...]
[/brag]
11/08/2010 16:42 ChingChong23#2
mobs won't need to be moved when nobody is in the area (and even in conquer they don't move unless your close to them right?) when you want them to move, its usually just chasing the player isn't it, you could make it walk random directions, just make sure it cant walk through boundaries.
11/08/2010 16:44 Korvacs#3
Its quite tricky to be honest, every time a monster needs to move something needs to fire a trigger or inform the monster, its unrealistic to give every monster cpu time, because most of them wont need it, so your wasting time on them, so its better to have it so that when players move around they trigger events which cause the monsters to move.

So depending on how many players you have in a map, and how many monsters you would probably want a thread per map with players on it minimum, with the ability to expand that if the map is very busy, then have the players trigger events for monsters on that thread and have that thread perform the necessary actions, or delegate to other threads.

It is definitely not a simple task, and there are of course many ways of doing this. Other options include giving CPU time to all monsters on all maps on one thread and performing actions depending on the circumstance of the individual monster. You could have a spawn object which detects when players move into the spawn and then have that delegate actions, however you would still need a way to give the relevant spawns CPU time.

Just a few thoughts for you. Im also about to start work on spawns myself in the open source project, so im sure i'll probably experiment with a few, most likely ill be trying my first suggestion to begin with (player triggered monsters).
11/08/2010 16:55 pro4never#4
Personally I haven't done much work with AI/Spawns as I'm a bit too busy atm but my thinking has been along the same idea as Korv's.


When I move a player I assign objects in range to a player dict of local objects. My thinking is then using this to iterate through mobs actually relevant to the server in my Mob handling thread.

IE: Pull players on a map, pull mobs on their screen and perform checks/actions only on those mobs and leave all other mobs alone (not on anyone's screen, who cares what they do?... maybe very low chance to trigger random movement for them but that's about as far as I'd ever wanna go with them)


I'm sure there are more efficient ways such as korv is suggesting but imo if you're only running through objects already on screen then I don't see any huge issue with the system. Can always be improved though.
11/08/2010 19:23 |NeoX#5
A* Pathfinding algo for Mobs please + for my "bots" implementation in process...
11/08/2010 20:18 bone-you#6
Old game I worked on had global timers. Basically every about 200ms the server would run through a list of NPCs and do a check on their last attack/movement time and see if they needed to do so again (they had a target, are walking somewhere, etc). Granted for CO, the timer would be far less than 200ms, but it'd be a similar situation. For pathfinding, that wouldn't be too difficult to emulate official CO. For mobs on official, it's just a 3x3 area check around them if they can move and if that tile is closer to you than they currenly are, move, if not but is the closest possible while not moving in the opposite direction entirely, move. Some mobs in CO move quite fast though (tombbats anyone?) so the timer would probably be it's own thread running every I'd guess 50-100msish checking the NPC list.