Game Development Community

AI think function (in engine)

by ChrisP · in Technical Issues · 09/02/2005 (4:35 pm) · 3 replies

I have a 'think' function for my bots that I would like to be called every so often. I know with the scripting approach, people seem to use the schedule function (SimConsoleEvent and postEvent) to get the function called every so often. However, I've coded my think function into the engine as opposed to scripting it in, and I was wondering how or where to call this function from. I'm still coming to grips with the client/server model, but it seems to me like the think() function should be running/called on the server side?
What sort of approach do people recommend to get the same sort of behaviour as the schedule() function so that think() can be repeatedly called in engine code on the server side?
I've already tried to hack a call to it into the players advanceTime function, but this is only called on the client side.

#1
09/02/2005 (4:37 pm)
Probably not the most efficient place but I guess you could put it in processServer()... Someone else will probably give you a better place though :)
#2
09/02/2005 (8:17 pm)
Thanks Matthew - I don't mind hacking it in a bit at the moment just to get the idea working! ;)
#3
09/05/2005 (6:42 pm)
Just to let those interested know: I ended up implementing this by setting up a 'think(%this)' function in aiplayer.cs, which did nothing but call a ConsoleFunction 'startThink()', implemented in aiPlayer.cc. startThink() in turn calls my main ai function in aiplayer.cc, which at the very end creates a new SimConsoleEvent referencing think(), passes (this) as the parameter to it and uses postEvent to fire the event in x milliseconds time. Probably not the least verbose way of doing things, but it works at least.