Game Development Community

Needing Clarification on AI Model swapping.

by Jason Gossiaux · in Torque Game Engine · 03/29/2008 (6:27 pm) · 4 replies

Howdy folks. So right now I am using some of the standard AIPlayer structure, heavily modified to handle pathfinding and decision making.

The problem I wanted to solve was how to not lose my function callbacks when spawning multiple nots that use different models. Now I read about declaring one datablock per AI, and then assigning the shapeFile in there. That works well enough - but it prevents me from having a common handler for AI callbacks.

For example:

By default AIPlayers use the DemoPlayer data block which copies over the PlayerBody datablock. The Demoplayer datablock has several functions that are tied into the engine, such as OnDestinationReached() and EndofSequence().

So if I rename Demoplayer to something like Ogre, Troll, Cow... I break the Demoplayer:: functions. I'd end up having to make a whole bunch of these functions to duplicate the functionality for each AI datablock. Does a better way exist?

I'd also read that the only way to change a model in game dynamically was to re-assign a new datablock and copy over all the old values. Is that still the case or has anyone found a better method?

Thanks for any help you can give me with this.

#1
03/29/2008 (6:39 pm)
Change all your Demoplayer calls to PlayerData calls. When Torque calls a function, it searches for the specific name first, then goes down the class hierarchy looking for it.

Hope that helps.
#2
03/29/2008 (6:43 pm)
Yes, Jason. It does, this goes along the lines of what i was talking about in a previous post where i got shot down. To create multiple aiplayers you have to replicate alot of functionality. you mentioned you had you own ai functions so this might have some issues with the demoplayer in the first place. But yes, in most cases trying to create new aiplayer datablocks ei, ogre, troll, cows are a pain to do. For now you have to duplicate the aiplayer functions, as a later case you could even create a aiplayer2 .cc and .h to change some of the behaviours, but simply creating 2 different ai from the same datablock can ba a hassle.
#3
03/29/2008 (7:45 pm)
@ Edward - Duplicating code is never the right option. If you feel it is the only way to solve a problem, you are probably doing something wrong.

@Jason - Another option for AI (which we are using in our game) is creating a new object to handle your AI calls. For example:

new ScriptObject(AI_BaseMonster)
{
     class = "aiObject";
};

new Player()
{
     ...
     AiClass = AI_BaseMonster;
     ...
};



AI_BaseMonster::think(%ai, %this)
{
     ..
     ..
}

Then you can assign all your logic to that single object, accessing it with %this.AiClass. Since torque supports inheriting for script objects, you can even create a hierarchy of AI calls.
#4
03/29/2008 (7:59 pm)
I never said it was the right thing, it is the easiest option, without going into the hundred "could do this and could do that". I personally go the playerdata route and script similar to above. WIth the addition of new .cc and .h to dicatate new ai behaviour classes and such. The above solution should work as well. Depending on what your doing. Still it would be nice to have a way standard for folks to select different models and place them as a standard, assign a path and let them go, as a default. I mentioned this in my other ai post. Its not a huge ai boost, but it would be nice to see being able to simply select datablocks(orc,troll, cow) and place them per mission as a standard. Has almost nothing to do with ai, and more to do with more control of editor and placement really. It would save alot of these kinds of questions. Simple define your "ai" object, select aiplayer in the editor under mission, select your datablock and path number. Poof, problem solved. rather then the above issues. And i dont see how that is game specific the object can be anything, and it doesnt depict a behaviour, but it does allow folks to place ai, alla aiguard ect.