AIPlayer mod
by Matthew W · in Torque Game Engine · 02/25/2008 (3:23 pm) · 28 replies
We want to setup an AIPlayer bot for our player character so that left-clicking on the screen moves the player character to the clicked spot on the field. It should be an AIPlayer bot so that we can call
We found that method on this resource.
We don't understand what to do - like what code could we change or where should we insert our own code?
AIPlayer::setMoveDestination("x y z");We found that method on this resource.
We don't understand what to do - like what code could we change or where should we insert our own code?
#2
This is our Failure attempt to make an AI bot move to where you click on the Terrain. We want $pos to =onMouseDown(x,y,z) coords and the AI bot to run to that location. But we cannot figure out how to make it work.
----
We thought that the GuiMouseEventCtrl::onMouseDown(const GuiEvent & event) function from/engine/gui/utility/guiMouseEventCtrl.cc would be the place to get the mouse x,y,z coordinates from.
02/27/2008 (2:57 pm)
new AIPlayer(Bob) {
datablock = "PlayerBody";
position = LocalClientConnection.camera.getPosition();
};
Bob.setMoveDestination($pos);
$pos = getWords(%scanTarg, 1, 3);
%client.player.setMoveDestination($pos);This is our Failure attempt to make an AI bot move to where you click on the Terrain. We want $pos to =onMouseDown(x,y,z) coords and the AI bot to run to that location. But we cannot figure out how to make it work.
----
We thought that the GuiMouseEventCtrl::onMouseDown(const GuiEvent & event) function from/engine/gui/utility/guiMouseEventCtrl.cc would be the place to get the mouse x,y,z coordinates from.
Quote:Do you already have a way to select the point on "the field" you mention?no, i dont think so.
#3
I'm sure it's been done though.
In fact...I know it has. Check out the terrain editor code!
02/27/2008 (5:31 pm)
I suspect that is your problem. I don't know how to do it, unfortunately. Probably you would need the mouse cursor to be represented by, say, a square of the terrain being selected. Once you have that, you would have the 3d coords.I'm sure it's been done though.
In fact...I know it has. Check out the terrain editor code!
#4
see it converts a Point2I object, described in engine\math\mPoint.h, into something with the three x, y, and z point! Well, i tried to change it to transfer a Point2I object into a Point3I.
03/17/2008 (12:39 am)
Ok, while looking through the terrain editor code this function, in \engine\terrain\terrRender.cc, this caught my eye:ChunkCornerPoint *TerrainRender::allocPoint(Point2I pos)
{
ChunkCornerPoint *ret = (ChunkCornerPoint *) FrameAllocator::alloc(sizeof(ChunkCornerPoint));
ret->x = pos.x * mSquareSize + mBlockPos.x;
ret->y = pos.y * mSquareSize + mBlockPos.y;
ret->z = fixedToFloat(mCurrentBlock->getHeight(pos.x, pos.y));
ret->distance = (*ret - mCamPos).len();
gClientSceneGraph->getFogCoordPair(ret->distance, ret->z, ret->fogRed, ret->fogGreen);
ret->xfIndex = 0;
return ret;
}see it converts a Point2I object, described in engine\math\mPoint.h, into something with the three x, y, and z point! Well, i tried to change it to transfer a Point2I object into a Point3I.
Point3I *TerrainRender::make3dPoint(Point2I pos)
{
Point3I *xyz;
ChunkCornerPoint *ret = (ChunkCornerPoint *) FrameAllocator::alloc(sizeof(ChunkCornerPoint));
ret->x = pos.x * mSquareSize + mBlockPos.x;
ret->y = pos.y * mSquareSize + mBlockPos.y;
ret->z = fixedToFloat(mCurrentBlock->getHeight(pos.x, pos.y));
xyz->x = ret->x;
xyz->y = ret->y;
xyz->z = ret->z;
return xyz;
}
#5
03/17/2008 (1:39 am)
Sooo...did it work? If not, what happens?
#6
edit: setTransform could help after figuring out how to test it - when the xy point has been changed into an xyz point, using something like %player.setTransform(x SPC y SPC z SPC "0 0 1 0"); might move my player character to the xyz point instantly.
03/17/2008 (2:02 am)
Well, honestly, i'm not sure how to test it, but i was able to build a Torque Demo exe. It's not TorqueScript so i cant test it with the console.. right? Wow.. can you think of a way to test it?edit: setTransform could help after figuring out how to test it - when the xy point has been changed into an xyz point, using something like %player.setTransform(x SPC y SPC z SPC "0 0 1 0"); might move my player character to the xyz point instantly.
#7
Can't test with the console? Why not? What would you have to do to make it testable via the console?
Can you think of any way at all to display the results of your mouse clicks when run through your code? I dunno...like trying to do what you want to do?
Sorry man, it seems to me you have all the tools, I'm not sure what I can tell you otherwise, sorry if I'm misunderstanding, because I certainly don't have any ideas.
03/17/2008 (4:26 am)
You're going to have to solve a lot of problems like this.Can't test with the console? Why not? What would you have to do to make it testable via the console?
Can you think of any way at all to display the results of your mouse clicks when run through your code? I dunno...like trying to do what you want to do?
Sorry man, it seems to me you have all the tools, I'm not sure what I can tell you otherwise, sorry if I'm misunderstanding, because I certainly don't have any ideas.
#8
03/17/2008 (3:59 pm)
It's ok. Im sorry. and im working on it. :)
#9
I basically used the built-in world editor for object selection. After that the only thing left was getting the 3D position of the mouse. Even if you don't use the resource, you should take a look at the code in the post, and the "tutorial.rts/client/commander.cs" file in the download.
I hope it helps you some.
EDIT- If you use the resource, you might want to change something in "tutorial.rts/client/commander.cs". In the function "Commander::onRightMouseDown", you should probably change:
03/17/2008 (4:35 pm)
Hmm, I normally don't like recommending my own resources, but this does pretty much exactly what you trying to do.I basically used the built-in world editor for object selection. After that the only thing left was getting the 3D position of the mouse. Even if you don't use the resource, you should take a look at the code in the post, and the "tutorial.rts/client/commander.cs" file in the download.
I hope it helps you some.
EDIT- If you use the resource, you might want to change something in "tutorial.rts/client/commander.cs". In the function "Commander::onRightMouseDown", you should probably change:
. . .
if (%this.getSelectedObject(%i).getClassName() $= "AIPlayer")
%this.getSelectedObject(%i).moveTo(%pos);
. . .to. . .
if (%this.getSelectedObject(%i).getClassName() $= "AIPlayer")
%this.getSelectedObject(%i).setMoveDestination(%pos);
. . .This takes out the pathfinding function.
#10
I fixed the link. If you already followed the resource, you should only have to put the "Editor" folder inside your "Common" folder. If all goes well, you should be able to call "Commander.getMouse3DPos()" to get the 3D coordinates of the mouse.
03/19/2008 (5:44 am)
OK then, sorry about that.I fixed the link. If you already followed the resource, you should only have to put the "Editor" folder inside your "Common" folder. If all goes well, you should be able to call "Commander.getMouse3DPos()" to get the 3D coordinates of the mouse.
#11
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2952) : error C2039: 'collidePos' : is not a member of 'WorldEditor'
13> i:\torque_new\tge_1_5_2\engine\editor\worldeditor.h(21) : see declaration of 'WorldEditor'
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2952) : error C2061: syntax error : identifier 'CollisionInfo'
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2955) : error C2065: 'mProjectDistance' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2959) : error C2065: 'mBoundingBoxCollision' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2966) : error C2065: 'info' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2966) : error C2228: left of '.pos' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2967) : error C2228: left of '.obj' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2968) : error C2228: left of '.normal' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2969) : error C2228: left of '.obj' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2971) : error C2228: left of '.pos' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2974) : error C2039: 'getMouse3DPos' : is not a member of 'WorldEditor'
13> i:\torque_new\tge_1_5_2\engine\editor\worldeditor.h(21) : see declaration of 'WorldEditor'
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2976) : error C2065: 'CollisionInfo' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2976) : error C2146: syntax error : missing ';' before identifier 'info'
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2977) : error C2065: 'mLastMouseEvent' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2983) : error C2039: 'getMouse3DPos' : is not a member of 'WorldEditor'
13> i:\torque_new\tge_1_5_2\engine\editor\worldeditor.h(21) : see declaration of 'WorldEditor'
Well, i think that the real problem might be in worldeditor.h on line 21. But i never changed that code. Plus, line 16 of worldEditor.h is displayed as grey text!? Google somehow mentioned that the grey text in Microsoft Visual C++ 2005 may be for an "Inactive Code Block". So i guess that grey code isnt being executed? i'm so confused.
03/21/2008 (12:46 pm)
All has not gone well. Currently, after adding the block of code to the end of worldEditor.cc, i try to build it and it gives me many errors from that sectioin of code like13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2952) : error C2039: 'collidePos' : is not a member of 'WorldEditor'
13> i:\torque_new\tge_1_5_2\engine\editor\worldeditor.h(21) : see declaration of 'WorldEditor'
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2952) : error C2061: syntax error : identifier 'CollisionInfo'
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2955) : error C2065: 'mProjectDistance' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2959) : error C2065: 'mBoundingBoxCollision' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2966) : error C2065: 'info' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2966) : error C2228: left of '.pos' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2967) : error C2228: left of '.obj' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2968) : error C2228: left of '.normal' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2969) : error C2228: left of '.obj' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2971) : error C2228: left of '.pos' must have class/struct/union
13> type is ''unknown-type''
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2974) : error C2039: 'getMouse3DPos' : is not a member of 'WorldEditor'
13> i:\torque_new\tge_1_5_2\engine\editor\worldeditor.h(21) : see declaration of 'WorldEditor'
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2976) : error C2065: 'CollisionInfo' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2976) : error C2146: syntax error : missing ';' before identifier 'info'
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2977) : error C2065: 'mLastMouseEvent' : undeclared identifier
13>i:\torque_new\tge_1_5_2\engine\editor\worldeditor.cc(2983) : error C2039: 'getMouse3DPos' : is not a member of 'WorldEditor'
13> i:\torque_new\tge_1_5_2\engine\editor\worldeditor.h(21) : see declaration of 'WorldEditor'
Well, i think that the real problem might be in worldeditor.h on line 21. But i never changed that code. Plus, line 16 of worldEditor.h is displayed as grey text!? Google somehow mentioned that the grey text in Microsoft Visual C++ 2005 may be for an "Inactive Code Block". So i guess that grey code isnt being executed? i'm so confused.
#12
Open your "Engine/editor/worldEditor.h" file. Find "class WorldEditor : public EditTSCtrl" and add this right after "public:"
In my defense, I never had to reopen the worldEditor.h file after adding those lines. I forgot about them when I got around to posting it as a resource.
Sorry again.
EDIT- I've gone over everything just to be sure. It should work now.
03/21/2008 (1:28 pm)
Matthew, I'm an idiot. By looking at those errors, it's pretty clear that I forgot to mention the .h file in the resource. I updated the resource, but this should fix it up (I hope).Open your "Engine/editor/worldEditor.h" file. Find "class WorldEditor : public EditTSCtrl" and add this right after "public:"
Point3F getMouse3DPos();Now scroll down and add this after "bool collide(const Gui3DMouseEvent & event, CollisionInfo & info);"
Point3F collidePos(const Gui3DMouseEvent & event, CollisionInfo & info);Hopefully that will be the last of the problems.
In my defense, I never had to reopen the worldEditor.h file after adding those lines. I forgot about them when I got around to posting it as a resource.
Sorry again.
EDIT- I've gone over everything just to be sure. It should work now.
#13
GuiControlProfile: unable to find specified profile (GuiButtonProfile)
and GuiDefaultProfile does not exist!
This is probably my fault, but i applied your resource to a backup copy of torque and it gave me the same error. Sorry for all these errors.
03/21/2008 (3:51 pm)
Ok thanks, it builds, but now when i run the demo_DEBUG.exe it gives me this error:GuiControlProfile: unable to find specified profile (GuiButtonProfile)
and GuiDefaultProfile does not exist!
This is probably my fault, but i applied your resource to a backup copy of torque and it gave me the same error. Sorry for all these errors.
#14
Sounds like neither GuiButtonProfile or GuiDefaultProfile exist. :-)
Either create them, or nuke the references to them.
They are present in a default TGE install, however. Maybe the script they are in is not included or something.
03/21/2008 (5:16 pm)
That should be a script error, If I'm not mistaken.Sounds like neither GuiButtonProfile or GuiDefaultProfile exist. :-)
Either create them, or nuke the references to them.
They are present in a default TGE install, however. Maybe the script they are in is not included or something.
#15
Fatal: (i:\torquefour\tge_1_5_2\engine\gui\core\guitypes.cc @ 363
GuiControlProfile: unable to find specified profile (GuiButtonProfile)
and GuiDefaultProfile does not exist!
Caleb,
So i guess there is a problem with your code?
03/22/2008 (3:12 pm)
Ok so i installed a fresh torque folder and followed the directions to Congrats again!, and i recieved the same error message.Fatal: (i:\torquefour\tge_1_5_2\engine\gui\core\guitypes.cc @ 363
GuiControlProfile: unable to find specified profile (GuiButtonProfile)
and GuiDefaultProfile does not exist!
Caleb,
So i guess there is a problem with your code?
#16
It is exempt from the GuiButtonProfile all together. I've never even opened guitypes.cc since I got Torque. If your GuiDefaultProfile is somehow missing, I have no idea how this would of happened. I'm fairly confident in saying that trouble is totally separate from my code. However, since my code did cause you a lot of problems before, I'll see if I can't help you out.
First off, install a fresh version of Torque like you did last time, but try building before you go through the resource again. See if you get a clean build.
03/22/2008 (5:33 pm)
After all the problems I had to correct in the resource, I don't doubt it. However, I don't think that's your problem here.It is exempt from the GuiButtonProfile all together. I've never even opened guitypes.cc since I got Torque. If your GuiDefaultProfile is somehow missing, I have no idea how this would of happened. I'm fairly confident in saying that trouble is totally separate from my code. However, since my code did cause you a lot of problems before, I'll see if I can't help you out.
First off, install a fresh version of Torque like you did last time, but try building before you go through the resource again. See if you get a clean build.
#17
edit: right now im redownloading that base.zip file and then im going to go slowly through the resource - just do one step and then build and see if the problem occurs.
03/22/2008 (6:18 pm)
Ok, thank you. Yes, just installed a fresh version of Torque, built the engine right away, and it just ran fine.edit: right now im redownloading that base.zip file and then im going to go slowly through the resource - just do one step and then build and see if the problem occurs.
#18
1)Now while your still in the "common" folder, open up "main.cs". Find the function "initBaseClient" (second function from the top), and put this at the bottom of it.
causes that GuiControlProfile error to appear.
After undoing step 1 and adding the second step
2)Next, open the "example/main.cs" file. Change "$defaultGame" to:
it has a different error: "Hardware failed to switch to the specified mode." and then "Could not find a compatible display device"
im sorry, and tired. goodnight.
03/22/2008 (7:55 pm)
Without changing the engine that ran fine i found out that your first step 1)Now while your still in the "common" folder, open up "main.cs". Find the function "initBaseClient" (second function from the top), and put this at the bottom of it.
exec("./editor/cursors.cs");causes that GuiControlProfile error to appear.
After undoing step 1 and adding the second step
2)Next, open the "example/main.cs" file. Change "$defaultGame" to:
$defaultGame = "tutorial.rts";
it has a different error: "Hardware failed to switch to the specified mode." and then "Could not find a compatible display device"
im sorry, and tired. goodnight.
#19
First of all, the only thing in cursors.cs is a bunch of cursors for the RTS Commander.
Second, changing "$defaultGame" shouldn't cause an error. If there's a problem with it, either it loads the new mod, or torque fails to run all together.
This problem is very confusing for me, so I need you to help me understand some things. . .
How are these errors coming to you? Is it when you compile Torque, open your console, it does it open a pop-up window?
Also, are you running debug mode?
As much information as possible will be greatly appreciated.
03/23/2008 (8:16 am)
Very interesting.First of all, the only thing in cursors.cs is a bunch of cursors for the RTS Commander.
Second, changing "$defaultGame" shouldn't cause an error. If there's a problem with it, either it loads the new mod, or torque fails to run all together.
This problem is very confusing for me, so I need you to help me understand some things. . .
How are these errors coming to you? Is it when you compile Torque, open your console, it does it open a pop-up window?
Also, are you running debug mode?
As much information as possible will be greatly appreciated.
#20
In your compiler, you need to change your output to release instead of debug. Hopefully that will clear it up.
03/23/2008 (9:25 am)
Alrighty then. I finally managed to duplicate your problem by switching back to debug mode. although I'm still not sure why this problem occurs, you should now be able to fix it.In your compiler, you need to change your output to release instead of debug. Hopefully that will clear it up.
Torque Owner Lee Latham
Default Studio Name
Do you already have a way to select the point on "the field" you mention?