Game Development Community

dev|Pro Game Development Curriculum

RTS Game Setup

by Caleb · 03/12/2008 (9:56 am) · 32 comments

Download Site

This isn't an example game similar to the starter.fps kit, instead I used the tutorial.base as a starting point. It doesn't come with content. That being said, I am planning on making a kind of starter.rts folder that will contain that sort of stuff.

Let's get started. . . .
First off, download and extract the "base" folder. Place "tutorial.rts" inside your "example" folder, and place the "editor" folder inside you "example/common" folder.

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");
Next, open the "example/main.cs" file. Change "$defaultGame" to:
$defaultGame = "tutorial.rts";
Congratulations! Now you only have to alter the engine code, and your done.

We'll start by making a tiny adjustment to the camera.
Open "Engine/game/camera.cc" file, and find the function "void Camera::processTick". In the last "if" statement before the end of this function, put:
vec.z = 0;
right after:
mObjToWorld.getColumn(2,&vec);
This will keep the camera from rising or falling as you move around.


Now, 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);
Now open your "Engine/editor/worldEditor.cc" file. Find the function "WorldEditor::on3DRightMouseDown", and put this inside of it:
Con::executef(this, 1, "onRightMouseDown");
Now copy and paste all of this at the very bottom of the same file:
//-----------------------------------------------------------
//RTS CODE START---------------------------------------------
//-----------------------------------------------------------
Point3F WorldEditor::collidePos(const Gui3DMouseEvent & event, CollisionInfo & info)
{
   Point3F startPnt = event.pos;
   Point3F endPnt = event.pos + event.vec * mProjectDistance;

   RayInfo ri;
   bool hit;
   if(mBoundingBoxCollision)
      hit = gServerContainer.collideBox(startPnt, endPnt, 0xFFFFFFFF, &ri);
   else
      hit = gServerContainer.castRay(startPnt, endPnt, 0xFFFFFFFF, &ri);

   if(hit)
   {
      info.pos = ri.point;
      info.obj = ri.object;
      info.normal = ri.normal;
      AssertFatal(info.obj, "WorldEditor::collide - client container returned non SceneObject");
   }
   return(info.pos);
}

Point3F WorldEditor::getMouse3DPos()
{
   CollisionInfo info;
   return collidePos(mLastMouseEvent, info);
}

ConsoleMethod( WorldEditor, getMouse3DPos, const char*, 2, 2, "")
{
   char *returnBuffer = Con::getReturnBuffer(256);
   const Point3F& mat = object->getMouse3DPos();
   dSprintf(returnBuffer,256,"%g %g %g",mat.x,mat.y,-1);
   return returnBuffer;
}
//-----------------------------------------------------------
//RTS CODE END-----------------------------------------------
//-----------------------------------------------------------
Congrats again! At this point your pretty much done. Go ahead and give it a try. Use the world editor to drop some bots in the game and move em around a bit.

All that's left is add building placement code, and path-finding. Since not all RTS games have the option to place buildings wherever you want, and a lot of people already have path-finding code, you can stop right here if you want. (The rest of the code isn't required)

In the same file you were just in, ("Engine/editor/worldEditor.cc"), put this at the top of "WorldEditor::on3DMouseMove":
//For building placement preview
   Con::executef(this, 1, "onMouseMove");
Now put this at the top of "WorldEditor::on3DMouseDown":
//For building placement preview
   Con::executef(this, 1, "onLeftMouseDown");
Great! Now the last thing is path-finding. (if you have your own path-finding, you can skip this part)

Open your "engine/sim/simPath.cc" file. In the function "Marker::onAdd", comment out these lines:
if(gEditingMission)
      onEditorEnable();
Add these lines right after those:
mNetFlags.set(Ghostable);
   setScopeAlways();
   addToScene();
and in the function "Marker::onRemove", comment out these lines:
if(gEditingMission)
      onEditorDisable();
Add this after those lines:
mNetFlags.clear(Ghostable);
  clearScopeAlways();
  removeFromScene();
Now find the functions "onEditorEnable" and "onEditorDisable", and comment out everything inside them. Last but not least, find the function "Marker::renderObject", and comment out the line:
wireWedge(.25, Point3F(0, 0, 0));
To use your new path finding, place path markers around objects that should be navigated. When I do the "starter.rts" file, I'll try and make a function that does this when a new building is created.

Congratulations for the last time! Your done. Please let me know if your having any problems. If you want to see how the engine changes you made are being used, take a look at the "tutorial.rts/client/commander.cs" file.
Page «Previous 1 2
#1
02/09/2008 (1:49 pm)
last update- 7/07/08

-I fixed a few errors and cleaned up the code a bit, so you might want to download the base.zib folder again.
-I added additional instructions near the top of the resource. If your camera was doing weird things (rising and falling) it will fix it.
-I also changed where the file is hosted. (please let me know if you have any problems with the link)
#2
03/12/2008 (6:30 pm)
Nice, so this doesnt use the rts kit at all, but creates rts like movement ?
#3
03/12/2008 (6:40 pm)
Correct.

There's no extra content in here, but it's great if you already have your own stuff.
#4
03/13/2008 (1:11 pm)
Great article, but I'd like to point out that the RTS kit gives you much more than content on top of the code here. The RTS kit has a TON of additional features...
#5
03/13/2008 (8:20 pm)
Good base starting point for an RTS. I own the RTS Starter Kit, but I see where this can be useful because:
a. It's Free
b. It's not bloated with other code, just a simple foundation to use as a starting point for your own wacky additions.
#6
03/18/2008 (2:57 pm)
it's ok, but your "editor" folder doesn't seem to be in the download file.
#7
03/19/2008 (5:40 am)
I re-uploaded the files.

All should be well now.
#8
03/20/2008 (9:52 am)
Really great resource, ive litterally just ifnished doing all this myself after being VERY disapointed by the RTS starter kit. Shame you were a week too late :P
#9
03/21/2008 (1:22 pm)
*sigh* I just keep screwing up don't I? If you have had problems compiling, it's cause I left out required code.

Just find the part about "Engine/editor/worldEditor.h", and add those two lines of code. At this point there's no telling what else I left out, so please let me know if something isn't working right.

Thanks.
#10
03/22/2008 (3:15 pm)
it's ok Caleb, and so i installed a fresh torque folder and followed the directions to Congrats again!, and i recieved the same error message.
#11
05/23/2008 (3:56 pm)
I've been trying to put this into TGEA and while it compiles fine, when I start torque it fatals out with the message GuiControlProfile:unable to find specified profile (GuiButtonProfile) and GuiDefaultProfile does not exist. If I comment out
new GuiControl(EmptyControl)
{
profile = "GuiButtonProfile";
}; in the cursors.cs file torque will start up but the console says it can't find the editor when pressing f11 or clicking on the button on the menu.

Is there something I'm missing that's different in tgea?
#12
06/13/2008 (6:25 am)
Chris, I'm sorry I didn't think of this earlier , but I've seen this problem before. For some reason or another, you need to compile release mode rather then debug. If you still have problems, try either deleting the "pref.cs" files in "tutorial.rts", or replace them with the ones from "tutorial.base".

I hope that solves your problem.
#13
08/16/2008 (12:25 pm)
im willing to make an mmorts, is this release still suported ?
#14
08/20/2008 (5:32 am)
@Ricardo, I'm not sure what you mean exactly. If your talking about using another kit alongside this resource, I'd imagine it would work fine as long as the code changes don't cross.
#15
08/21/2008 (1:12 pm)
im asking if this is still in development, or you stop developing it ?
#16
08/25/2008 (4:28 am)
Oh it's still in development. I been making pretty good progress on it so far, but don't know how much longer it's gonna take. I'll try to get some screen shots when I get a chance.
#17
09/07/2008 (3:33 pm)
Interesting, Will check it out sometime soon. (Over the next few days, I guess)

Are you currently considering future updates?

And, I guess this is updated/working for 1.5.2?

Thanks,
Daniel
#18
09/08/2008 (10:45 am)
Just started testing this out today, Awsome work so far.

Can anyone tell me how to remove the red box around the selected unit?

Thanks,
Daniel
#19
09/11/2008 (6:25 am)
@Daniel, I've already completed many updates such as unit formation, a mini map, and map shroud (still working on this one). It's coming along nicely. :)

The selection box is controlled via the commander gui. Open the gui editor, select "Commander", and scroll down till you find options about selections. You can toggle it from there.
#20
10/09/2008 (12:45 pm)
Good to hear about progress, Looking forward to seeing more!
Page «Previous 1 2