The AIPlayer Class
by Rodrigo Furlan · in Torque Game Engine · 12/02/2001 (7:08 pm) · 17 replies
Does anyone knows the purpose of the AIPlayer class? It seems to be removed from the program flow and I am failing to figure out how this class should be used.
To make things a little more spookier, this class can't be instantiated from the scripting subsystem, in despite of being correctly declared as CONOBJECT. Any ideas?
[]'s
Cyq
To make things a little more spookier, this class can't be instantiated from the scripting subsystem, in despite of being correctly declared as CONOBJECT. Any ideas?
[]'s
Cyq
About the author
#2
I just want to know the correct way to declare the AIPlayer as a console class, this way I should be able to instantiate it and use it as base for my own AI code.
In the code, the AIPlayer class is declared and implemented as a CONOBJECT and its initialize method is already prepared to expose most of its funcionality to the scripting subsystem. I already inserted a call to its initialize method into the program flow but something else is missing as I am still unable to instantiate it from scripting. What more should I do (in fact, this question goes beyond the scope of this class, what should I do when I wanto to expose a new class to the scripting subsystem?)?
I was just imagining that as it derives from AIConnection and GameConnection, would be pretty easy to develop some interesting things on top of it.
I know it is still work in progress, but working with this class is better than starting from the void as in the future it will probabily be Torque's default object for AI.
[]'s
Cyq
12/03/2001 (10:20 am)
I would love to play around with this class. I managed to compile it, inserted a call to its initialize method into the program flow, commented a line or two and voila! I just want to know the correct way to declare the AIPlayer as a console class, this way I should be able to instantiate it and use it as base for my own AI code.
In the code, the AIPlayer class is declared and implemented as a CONOBJECT and its initialize method is already prepared to expose most of its funcionality to the scripting subsystem. I already inserted a call to its initialize method into the program flow but something else is missing as I am still unable to instantiate it from scripting. What more should I do (in fact, this question goes beyond the scope of this class, what should I do when I wanto to expose a new class to the scripting subsystem?)?
I was just imagining that as it derives from AIConnection and GameConnection, would be pretty easy to develop some interesting things on top of it.
I know it is still work in progress, but working with this class is better than starting from the void as in the future it will probabily be Torque's default object for AI.
[]'s
Cyq
#3
12/03/2001 (10:24 am)
Argh, Tim is absolutly right. This is a result of me slacking off and being buisy. I haven't programed anything in a normal language for a long time. I've been buisy with LISP, PROLOG and other cruel impliments of torture that the professors can dredge up from the CS past.
#4
Hei, do you mind giving me some directions? What more do I need to do to enable this class to be instantiated by the scripting subsystem? I don't care if it is not working yet, I just want something to begin with :)
-EDITED---------------------
I just did it! Thank you anyway!
For those who are curious about how to do it, first create this console function (in the source code):
ConsoleFunction(aiPlayerConnect, S32 , 2, 20, "aiConnect(val 0...n);")
{
AIPlayer *aiPlayer = new AIPlayer();
aiPlayer->registerObject();
SimGroup *g = Sim::getClientGroup();
g->addObject( aiPlayer );
const char* args[21];
args[0] = "onConnect";
for (S32 i = 1; i < argc; i++)
args[i + 1] = argv[i];
Con::execute(aiPlayer, argc + 1, args);
return aiPlayer->getId();
}
Then use aiPlayerConnect instead of aiConnect and develop your own AI code over it :)
Is this really ok, Pat?
-----------------------------
[]'s
Cyq
12/03/2001 (11:40 am)
Ohhh man, poor of you, I hope you can survive PROLOG :)Hei, do you mind giving me some directions? What more do I need to do to enable this class to be instantiated by the scripting subsystem? I don't care if it is not working yet, I just want something to begin with :)
-EDITED---------------------
I just did it! Thank you anyway!
For those who are curious about how to do it, first create this console function (in the source code):
ConsoleFunction(aiPlayerConnect, S32 , 2, 20, "aiConnect(val 0...n);")
{
AIPlayer *aiPlayer = new AIPlayer();
aiPlayer->registerObject();
SimGroup *g = Sim::getClientGroup();
g->addObject( aiPlayer );
const char* args[21];
args[0] = "onConnect";
for (S32 i = 1; i < argc; i++)
args[i + 1] = argv[i];
Con::execute(aiPlayer, argc + 1, args);
return aiPlayer->getId();
}
Then use aiPlayerConnect instead of aiConnect and develop your own AI code over it :)
Is this really ok, Pat?
-----------------------------
[]'s
Cyq
#5
12/05/2001 (5:12 pm)
Well that I know of, you don't really need AIplayer anyway. Most of what you need for bots is already in AIConnection. What I did was to take the getmovelist function (something like that) and move it to aiConnection, modify it some, and voila, ai bots.
#6
12/06/2001 (10:47 am)
J Brown speaks the truth. AIPlayer was supposed to be an inteligent extension to AIConnection. Some stuff like basic pathfinding and such.
#7
Thank you anyway!
Cyq
12/06/2001 (12:00 pm)
Yes, I know I can do all I want using AIConnection, in fact, I have got some very evil bots running after me without using AIPlayer class, but if I need to develop something, why not begin from AIPlayer class instead of the void? Relax people, I am ok now, I have some nice AIPlayers running around, they are a little stupid right now but they will get smartter with time ;)Thank you anyway!
Cyq
#8
thanks
12/06/2001 (7:30 pm)
J Brown could you be more specific in what you had to do to get the AI working. I looked but getmovelist seems to already be in aiConnect.thanks
#9
%client.setMove ("direction", speed)
Where %client is an AIConnection object. Some example follows:
%client.setMove("x", 1) // side stepping
or
%client.setMove("x", 1) // for a diagonal move
%client.setMove("y", 1)
The valid values for "direction" are: x,y,z,yaw,pitch and roll.
This will move your bot but will not make it any smarter than a old LOGO turtle, to build some inteligent behavior all will need is to schedule a call to your "think" method when you first create the bot. In this method you put any decision taking code you want and re-schedule it to be called again. Just remember, this is not an optimal method, just something to begin with.
It's kinda hard make your bot move gracefully just using setMove, so be prepared to build a higher-level layer over it.
About the getMovelist method, I am still studying it, as soon I know more about it, I will share it with you :) Anyway, the entire AIPlayer class seens to be a layer for creating setMove "streams" based in higher level methods.
Have fun!
Cyq
12/07/2001 (3:43 am)
Hi James, you just need to use the AIConnection's setMove method like this%client.setMove ("direction", speed)
Where %client is an AIConnection object. Some example follows:
%client.setMove("x", 1) // side stepping
or
%client.setMove("x", 1) // for a diagonal move
%client.setMove("y", 1)
The valid values for "direction" are: x,y,z,yaw,pitch and roll.
This will move your bot but will not make it any smarter than a old LOGO turtle, to build some inteligent behavior all will need is to schedule a call to your "think" method when you first create the bot. In this method you put any decision taking code you want and re-schedule it to be called again. Just remember, this is not an optimal method, just something to begin with.
It's kinda hard make your bot move gracefully just using setMove, so be prepared to build a higher-level layer over it.
About the getMovelist method, I am still studying it, as soon I know more about it, I will share it with you :) Anyway, the entire AIPlayer class seens to be a layer for creating setMove "streams" based in higher level methods.
Have fun!
Cyq
#10
%client = %this.GetControllingClient();
%client.setMove("x", 0.5);
in my think function, but i get an error "unable to find object '' attempting to call function setMove"
i think i'm calling SetControlObject wrong or in the wrong place or something.. any ideas?
12/09/2001 (1:36 pm)
i call %client = %this.GetControllingClient();
%client.setMove("x", 0.5);
in my think function, but i get an error "unable to find object '' attempting to call function setMove"
i think i'm calling SetControlObject wrong or in the wrong place or something.. any ideas?
#11
%bot = createdummy(pickSpawnPoint(1));
%client.SetControlObject(%bot);
Does it work for you?
Good luck!
Cyq
12/09/2001 (1:58 pm)
How are you calling the SetControlObject method? This is the why I call it on my AIConnection::onConnect function:%bot = createdummy(pickSpawnPoint(1));
%client.SetControlObject(%bot);
Does it work for you?
Good luck!
Cyq
#12
is it like:
%ai = new aiConnection() { };
Then that would be your client?
Dark
12/09/2001 (4:01 pm)
How do you make a new aiConnection? And how do you use it?is it like:
%ai = new aiConnection() { };
Then that would be your client?
Dark
#13
function serverCmdAddBot()
{
$ServerGroup = new SimGroup (ServerGroup);
aiConnect("Cyq", -1, 0.5, false, "CyqBot1", 1.0);
}
Be happy!
Cyq
12/09/2001 (4:15 pm)
You should use the aiConnect console function, like this:function serverCmdAddBot()
{
$ServerGroup = new SimGroup (ServerGroup);
aiConnect("Cyq", -1, 0.5, false, "CyqBot1", 1.0);
}
Be happy!
Cyq
#14
The look like they get passed directly to AIConnection::onConnect(), do they?
And does the game call aiConnection::onDrop() when the ai drops? Kind of a stupid question, the ai shouldn't drop on it's own. Just wondering what I need to know.
Dark
12/09/2001 (4:21 pm)
What are those arguments?The look like they get passed directly to AIConnection::onConnect(), do they?
And does the game call aiConnection::onDrop() when the ai drops? Kind of a stupid question, the ai shouldn't drop on it's own. Just wondering what I need to know.
Dark
#15
%client = %this.GetControllingClient();
%client.setMove("x", 0.5);
like that.. or does it need to be something else.
I use
%bot = createdummy(pickSpawnPoint(1));
%client.SetControlObject(%bot);
in the onConnect, but now it's saying "unable to find object '0' attempting to call setMove"
i also tried
%client = %this.getControlObject();
but %client still = 0
any ideas
thanks for the help
12/09/2001 (5:38 pm)
Still not working. Do you call %client = %this.GetControllingClient();
%client.setMove("x", 0.5);
like that.. or does it need to be something else.
I use
%bot = createdummy(pickSpawnPoint(1));
%client.SetControlObject(%bot);
in the onConnect, but now it's saying "unable to find object '0' attempting to call setMove"
i also tried
%client = %this.getControlObject();
but %client still = 0
any ideas
thanks for the help
#16
Try this:
make a file called ai.cs, inside it put:
Execute it in game.cs, or wherever.
To add a bot you would do:
aiConnect();
But if you do it that way you'll lose it, so assign a global variable to it (for testing only):
$BotConn = aiConnect(); // type this in the console
To make it do stuff do $BotConn.setMove()
12/09/2001 (8:01 pm)
When you create an ai, you're creating a client in a way. Then you set the client to control an object.Try this:
make a file called ai.cs, inside it put:
function AIConnection::onConnect(%aiClient)
{
%spawnPoint = pickSpawnPoint();
if (%aiClient.player > 0)
error( "Attempting to create an angus ghost!" );
%player = new Player()
{
dataBlock = LightMaleHumanArmor;
client = %aiClient;
};
MissionCleanup.add(%player);
%player.setTransform(%spawnPoint);
%player.setEnergyLevel(60);
%player.setShapeName("AI Dude");
%aiClient.player = %player;
%aiClient.setControlObject(%player);
}Execute it in game.cs, or wherever.
To add a bot you would do:
aiConnect();
But if you do it that way you'll lose it, so assign a global variable to it (for testing only):
$BotConn = aiConnect(); // type this in the console
To make it do stuff do $BotConn.setMove()
#17
Any help is appreciated.
Dark
12/09/2001 (8:06 pm)
Anyone have any documents or pointers on the math functions? I've never really done 3d math before, so I'm a little lost :) I need them to get the bots to look at a location.Any help is appreciated.
Dark
Torque Owner Tim Gift