Game Development Community

Multiple Squads

by Nicholas Bogart · in RTS Starter Kit · 07/28/2007 (3:38 am) · 17 replies

Heyas,
So I am looking at making a RTS with squads of men similar to Dawn of War and its add-ons. I was wondering if anyone else has tried this out yet and if so where can I get it to make it when I create a Unit it spawns multiple models with it and automatically groups them together.

Any knowledge on this would be helpful,
Thanks,
Nick

#1
07/28/2007 (12:18 pm)
Nicholas, the squad system its a topic that come back from time to time, but I dont remember have been read someone that finally implement such system.

Nevertheless, its a mandatory feature for almost any modern rts, so it would be a good project to think about for the community.

I will try to make some kind of solution for this in the code pack Im doing, at least from a pathfinding perspective, but again: a complete squad control and behaviour system its a must-have feature still to be developed for the kit.
#2
07/28/2007 (12:57 pm)
Rough pseudocode:

RTSUNIT

OnSelect
{
If unit in squad, add all other squad members.
}
OnDeSelect
{
If unit in squad, remove all other squad members.
}

onreachdestination
{
are all other units at their destination? if so, then squad.onreacheddestination
}

ondeath
{
were we the last squad member? if so, nuke the squad
}

SQUAD

IssueMoveOrder(%x,%y)
{
For unit with index i in squad:
unit.setmovedestination( vectoradd(%x %y, SquadFormation[i] [with rotation probably]))
squad.destination=%x %y
}

Where squadformation is a list that contains unit position offsets for the current squad formation.

}

Connection

SpawnSquad(%unittype,%quantity, %location) [might want rotation as well]
{
%newsquad = new squad ;
%newsquad.formation=$basicformation
for i 0 to %quantity:
%b=newunit ( location=%location+formation[i])
%newsquad.add(%b)
%b.squad=%newsquad
}

That's the rough overview of something i tested a while ago.
#3
07/28/2007 (10:28 pm)
Seems to be simple and clean. Sounds like a fantastic initial aproach, Benjamin.
#4
08/02/2007 (10:38 am)
Ive implemented squad based selection :)
#5
08/02/2007 (6:15 pm)
Using Benjamin scaffold? Tell us some more...
#6
08/02/2007 (7:10 pm)
No I did it a while ago. Its not particually challenging apart from changing rtstsctrl to show selection for squads instead of individual units. I just have a class named RTSOverseer which has multiple members. A good idea is to do flocking, so the units only path to the leader. Questions?
#7
08/02/2007 (7:25 pm)
Well thats great, but indeed a have some questions.
Do you implemented flocking? if yes,
do you coded it on C++ or script?
do you make the follow-leader steering behavior? How do you set up a leader, just random?
#8
08/02/2007 (7:50 pm)
I have done it all in c++. It would be quite troublesome to do in script probably.

The leader I have set as a variable as a "squad captain". If this captain is killed or doesnt exist then it just uses the first member in the array as the leader. I have it so flocking only happens if a certain distance away from the goal

Im not really sure if you need steering. The idea being that all members of the squad are moving at the same speed.

Also you really want to path into some sort of formation(I havent got to this yet). So opposed to pathing to the leaders pos, path into an offset position. I suppose you need a sort of steering here to make sure that certain members in the formation arent pathing into a tree the leaders standing next to. Well just find the nearest passable tile.
#9
08/02/2007 (8:16 pm)
Well Jonathan, flocking actually is a steering behaviour, such as leader following ;)

I was thinking about making it with flocking with leader follow, with a tendence to the target position. If I can mix that with path following and obstacle avoidance (another two steering behaviors), the result will be great.

But Im doing it in script (ill test later any performance issues). Im trying to make a system just ready to plug-in in the PathManager.
#10
08/03/2007 (11:39 am)
Would you Johnathan be willing to share what you have done?
#11
08/20/2007 (2:47 pm)
Initially, I try to manage the squads client side, but I found that the pathfinding (and the flocking) is server side, so its easier to put the squad system server side too. BTW, Im using the Benjamin ideas.
So boys, what do you think about this:

1) I create a Simset for each squad, on RTSConnection. There, I add a number of soldiers to each simset and add a variable %player.squad = %simset to track each soldiers squad.

2) In serverCmdAddToSelection (commands.cs) I add to %client.selection all members of the squad (using the simset), update the client, and send a new MessageCallback to the client to refresh the Selection Display.

Till here it works (to say truth, I having some problems in refreshSelectionDisplay but i think its a minor issue)

Of course, its only the begining, so dont scream to me about the lacking of the rest, but I wanna know your critics before go on...




EDIT: Ok, its making me crazy.. When I try to use GuiRTSTSCtrl::refreshSelectionDisplay, (from the callback) it says:

starter.RTS/client/scripts/playGui.cs (92): Unable to find object: '' attempting to call function 'getSelectionSize'

I dont know what to send on the "%this" parameter so it work... any help?

Edit2: it does not matter, just I was tired, the correct call is GuiRTSTSCtrl::refreshSelectionDisplay(PlayGui.getId(), false)
Sadly, it didnt do what I spected to do, which is to show the actual selection (I perfectly move the squad, but only one unit shows selected). Working on it.
#12
08/22/2007 (10:00 pm)
Mhh, apparently the selection circle rendering/activation is hardcoded on the engine... Any ideas to make it show from the script?


Edit: [tired] 2:05 am... You have some time to think about it, im going to sleep now [/tired] :)


EDIT 2: Ok its done. I was making bad a bunch of things, but it finally works from script. I could say that the squad system its done, Im working on make it work with flocking. If all goes ok, the coming week Ill be working on porting pathfinding of Gavin Bunney's immersiveAI to rts.
#13
08/30/2007 (10:50 pm)
Im thinking on re-write the squad system. Even when the basic functionality its working, the actual code tide me on some other aspects of future improvements to the squads.

Im thinking on later make an unique "health" for all the squad, put some identifier simbol or flag over the units and show only one point per squad on the minimap. Those three things are near imposible with the Ben scafold, so I think Im comming back to squads... pathfinfind to the freezer for some more days.

Anyway I will save the actual work, beacuse its an effective way to create simple squads.


Edit: I dont know exactly what do to.... Im a little saturated of GG activity. Im gonna rest some days, so dont take as sure, none of what I said about squads...
.
#14
09/09/2007 (4:03 am)
All I did was move the circle rendering code into a separate function nameddrawHealthBar and then added this in GuiRTSTSCtrl::OnRender.

// Draws healthbars for every member of the selected squads
   for(S32 i=0; i<getSelectionSize(); i++)
   {
      if(mDragSelected.objInSet(mSelected[i]) || mSelected[i] == (SceneObject*)mHitObject)
         continue;
		RTSOverseer* ovs = (RTSOverseer*)((mSelected)[i]);
		for(S32 n=0; n < (ovs->mMember->size()); n++) 
		{
			drawHealthBar((RTSShape*)((*ovs->mMember)[n]));
		}
   }

	// Draws health bars for every member of the mouseover squad
   if(bool(mHitObject))
   {
		RTSOverseer* ovs = mHitObject->getOverseer();
		S32 size = ovs->mMember->size();
		for(S32 n=0; n < ovs->mMember->size(); n++)
		{
			SimObject* mem =((*ovs->mMember)[n]);
			drawHealthBar((RTSShape*)((*ovs->mMember)[n]));
		}
   }

Bearing in mind that the selection list contained the squad class instead of unit(which I called RTSOverseer)
#15
09/09/2007 (9:14 am)
Great Johnatan, Ill take a look!

Question: Its posible to call from C++ code, an object created in Torquescript? Beacuse, I just expanded the squad concept, but all on Torquescript. Sadly, I think that sooner or later Ill have to port everything I do to C++...
#16
09/15/2007 (9:10 pm)
I think a good workaround could be to make the inverse work, call a script function from the engine, that passes the squad members to a console function, that way, I maybe dont need to manage the squad overseer from C++.


To this point all its coming great from script, now its time to test that three points:

* health bars for every member on mouseover
* add a new health bar with the sum of the health of the squad units (maybe at the bottom of the recently added squad flag)
* manage to make the squad flag (an Gui3DProjectionCtrl) to not be atached to one unit, but to the center of mass of the squad
#17
07/04/2009 (6:33 pm)
Has anyone implemented squads yet?