Finding all AIPlayers
by Mathieu · in Torque Game Engine · 06/18/2005 (8:03 am) · 8 replies
I'm trying to write small debug tools for my game. In want to draw the moveDestination of all AI running around but I'm having difficulties looping over them in C++.
console.log return :
It seems that my dynamic_cast is incorrect but I can't figure how to make it work... any idea ?
for (SimSetIterator itr(conn); *itr; ++itr) {
if ((*itr)->getType() & ShapeBaseObjectType) {
ShapeBase* shape = static_cast<ShapeBase*>(*itr);
Con::printf("--%s",shape->getShapeName());
if (shape != control && shape->getShapeName()) {
Con::printf("----%s",shape->getShapeName());
Point3F shapePos;
AIPlayer* theAI = dynamic_cast<AIPlayer*>(Sim::findObject(shape->getShapeName()));
if(theAI != NULL){
shapePos = theAI->getMoveDestination();
Con::printf("%s -- x= %f y= %f z= %f",
shape->getShapeName(),
shapePos.x,
shapePos.y,
shapePos.z
);
}
/*
Some code to draw shapePos
*/
}
}
}console.log return :
--Mathieu --(null) --(null) --(null) --(null) --(null) --(null) --Bot1 ----Bot1 --(null) --(null) --(null) --(null)
It seems that my dynamic_cast is incorrect but I can't figure how to make it work... any idea ?
About the author
Developer at frogames.com / frogames.net
#2
But what do I know?
06/22/2005 (10:26 am)
Wouldn't you be better off looking things up by ID rather than by name? I don't believe objects are required to have names, but ID's are a given.But what do I know?
#3
But now that the dynamic cast seems to work I'm having another problem. I replaced my old code with :
and here the result :
I can access the rotation value with getRotation() but I can't access the moveDestination! Seems to me that in need to get a long C++ seminar...
06/22/2005 (1:56 pm)
Hem, yes thanks, it's better with the ID.But now that the dynamic cast seems to work I'm having another problem. I replaced my old code with :
Point3F shapePos;
AIPlayer* theAI = dynamic_cast<AIPlayer*>(Sim::findObject(shape->getId()));
if(theAI != NULL){
shapePos = theAI->getMoveDestination();
Con::printf("%s -- x= %f y= %f z= %f",shape->getShapeName(), shapePos.x, shapePos.y, shapePos.z);
Point3F tempTest;
tempTest = theAI->getRotation();
Con::printf("mRot -- x= %f y= %f z= %f", tempTest.x, tempTest.y, tempTest.z);
}and here the result :
--(null) --(null) --(null) --(null) --(null) --(null) --Mathieu --(null) --(null) --(null) --(null) --Bot1 ----Bot1 Bot1 -- x= 0.000000 y= 0.000000 z= 0.000000 mRot -- x= 0.000000 y= 0.000000 z= 0.461756
I can access the rotation value with getRotation() but I can't access the moveDestination! Seems to me that in need to get a long C++ seminar...
#4
I'm trying to get the moveDestination of all AIPlayers in game.
Here the console.log :
As you can see I don't get the right moveDestination but I get the position of the Bot, after one of my tests I found that I get the initialisation value of moveDestination.
I really don't understand why I don't get the current value of moveDestination, where I'm making a mistake?
06/26/2005 (6:28 am)
Finding all AIPlayers isn't the problem now, getting moveDestination is the new one. As I don't want to spam the forums I will continue here...I'm trying to get the moveDestination of all AIPlayers in game.
GameConnection* conn = GameConnection::getServerConnection();
if (!conn) return;
ShapeBase* control = conn->getControlObject();
if (!control) return;
for (SimSetIterator itr(conn); *itr; ++itr){
if ((*itr)->getType() & PlayerObjectType){
if (AIPlayer* theAI = dynamic_cast<AIPlayer*>(*itr)){
Point3F shapePos;
shapePos = theAI->getMoveDestination();
Con::printf("%s -- x= %f y= %f z= %f", theAI->getShapeName(), shapePos.x, shapePos.y, shapePos.z);
//other printf for comparaison
Point3F tempTest;
tempTest = theAI->getPosition();
Con::printf("temp -- x= %f y= %f z= %f", tempTest.x, tempTest.y, tempTest.z);
}
}
}Here the console.log :
Bot1 -- x= 0.000000 y= 0.000000 z= 0.000000 temp -- x= 94.360565 y= -257.071655 z= 100.012329 Bot1 -- x= 0.000000 y= 0.000000 z= 0.000000 temp -- x= 93.790565 y= -256.664978 z= 100.012329 Bot1 -- x= 0.000000 y= 0.000000 z= 0.000000 temp -- x= 93.790565 y= -256.664978 z= 100.012329 Bot1 -- x= 0.000000 y= 0.000000 z= 0.000000 temp -- x= 93.220566 y= -256.258301 z= 100.012329 Bot1 -- x= 0.000000 y= 0.000000 z= 0.000000 temp -- x= 92.650566 y= -255.851639 z= 100.012329 Bot1 -- x= 0.000000 y= 0.000000 z= 0.000000 temp -- x= 92.650566 y= -255.851639 z= 100.012329
As you can see I don't get the right moveDestination but I get the position of the Bot, after one of my tests I found that I get the initialisation value of moveDestination.
AIPlayer::AIPlayer()
{
mMoveDestination.set( 0.0f, 0.0f, 0.0f );
mMoveSpeed = 1.0f;
mMoveTolerance = 0.25f;
mMoveSlowdown = true;
mAimObject = 0;
mAimLocationSet = false;
mTargetInLOS = false;
}I really don't understand why I don't get the current value of moveDestination, where I'm making a mistake?
#5
06/26/2005 (1:38 pm)
Are you working on the client or the server? The client may not have things like the move destination ghosted across.
#6
If I don't found another way to display the moveDestination to the GUI I will need to fight with Pack/Unpack. To bad for me, I was trying to keep things simple and clear! :)
06/26/2005 (2:08 pm)
Thanks Ben, that's seems to be the problem.If I don't found another way to display the moveDestination to the GUI I will need to fight with Pack/Unpack. To bad for me, I was trying to keep things simple and clear! :)
#7
06/02/2008 (4:22 am)
Any resource about that?
#8
If so, heres how I am doing that. All agents are in a global simset. Then the gui control that shows debug info uses sim::findObject to get that simset. Since the simset only really exists on the server side this only works in a single-player situation -- but maybe thats fine because its just for debugging.
Then loop through and do whatever you need.
06/02/2008 (11:34 am)
Does this "debug" information have to show up in your gui when there is a non-local server? Or if it works at least for "single-player" will that be acceptable?If so, heres how I am doing that. All agents are in a global simset. Then the gui control that shows debug info uses sim::findObject to get that simset. Since the simset only really exists on the server side this only works in a single-player situation -- but maybe thats fine because its just for debugging.
Then loop through and do whatever you need.
Torque Owner Mathieu
Maybe I'm not trying the right way to display the moveDestination of the bots?