Page 1 of 1

[RESOLVED] tmwserv Bizzar Mob Movement Trend

Posted: 20 Feb 2008, 00:32
by leeor_net
Well, I've been running the Game Server with few problems (minus the problem if it periodically crashing but that's a different issue). I've begun to notice a bizzar trend: All of the mobs seem to want to migrate toward the top left corner of the map.

Now, the game server has been running overnight and most of the day without anybody signing on and killing mobs so they've been free to roam wherever they please... yet, they still all seem to be moving over to that one section of the map.

Any thoughts on what is causing this phenomena (and perhaps suggestions on how to change it)?

Re: tmwserv Bizzar Mob Movement Trend

Posted: 20 Feb 2008, 09:22
by ElvenProgrammer
Did you notice this behaviour on all the maps and for all monsters?

My guess is that they can't go too far from their spawning point (but I don't really remember how it works), and maggot spawning point should be located NW.

Re: tmwserv Bizzar Mob Movement Trend

Posted: 20 Feb 2008, 13:22
by Crush
No, Elven, you are wrong. A monster which has nothing to do searches for a new location to go to using the following lines of code (game-server/monster.cpp lines 246 and 247)

Code: Select all

Point randomPos(rand() % (range * 2) - range + getPosition().x,
                rand() % (range * 2) - range + getPosition().y);
where "range" is the stroll range of the monster in pixels and getPosition() is the current position of the monster. The spawn location doesn't matter for a monster (it doesn't even know it). This code might indeed favor negative over positive values. I'll check that.

Thanks for reporting, leeor_net

Re: tmwserv Bizzar Mob Movement Trend

Posted: 20 Feb 2008, 13:42
by Crush
Yes, leeor, you were right. The code above does indeed favor negative directions over positive.

rand()%X does not return a number between 0 and X but between 0 and X-1. So rand()%6 - 3 would not return numbers between -3 and +3 but between -3 and +2. I committed a bugfix which should and seems to fix the problem. But it's hard to say without a real long-time test.

Re: tmwserv Bizzar Mob Movement Trend

Posted: 21 Feb 2008, 00:11
by leeor_net
I'm just glad I'm not crazy! :)

Thanks for the update, Crush. I was actually considering completely replacing the 'rand' function with a truelly random number generator. But that's something to toss into a TODO.

I'll keep the gameserver running for awhile and see if the problem is corrected.

Re: tmwserv Bizzar Mob Movement Trend

Posted: 21 Feb 2008, 00:22
by Crush
Replacing rand() would be quite unnecessary. The rand implementation of the average C standard library is already random enough for games. Better random number generators are only needed for scientific or cryptographical purposes.

Re: tmwserv Bizzar Mob Movement Trend

Posted: 22 Feb 2008, 00:55
by leeor_net
I suppose you're right. I never really thought of it that way.