Jump to content
  • Advertisement
Sign in to follow this  
web_scripter

Unit commands / Command Manager

This topic is 4830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i'm working on a system to issue commands to units, and i was wondering how i can inprove it or is there a better way of doing this. So here it is, the Unit has a list of commands it's been given usually theres only two of them. It also has a list of actions. Commands consist of actions. So the Attack Command has two actions move and attack. When the game tells the unit to update. The unit issues the first action, which is move. It keeps on issuing this command on each update, until it reaches the specified destination. When is have reached the destination it issues the attack action. When it has killed the opponent it goes into idle. If another Command is set then it terminates it's current command, and goes to the next one. I guess the strucure would look something like this: Image Hosted by ImageShack.us All comments and sugestions are welcome, Thanks

Share this post


Link to post
Share on other sites
Advertisement
Looks fairly good, but in essence of speed I see some things. For example, user hits a mouse 1 ordering and attack on point 7,5. That input data is saved on a data pile for later use due to the earlier configuration of controls. Update comes and realizes it has fresh data and sends it to the unit. Yes, I said unit, so somehow encorporate a command parser to the correct unit. Unit should have a command object, and the command object should have an action object. When unit updates, the command list for that unit is checked. If something is there, the command object calls up the definition in action of what it should do. Action should just be full of a bunch of function on what to do for each command. After it's called, the command object should mark that command as active. So each time it comes around it can simple go instead of having to be checked for.

Share this post


Link to post
Share on other sites
What do you mean command parser? There are classes for each command that are derived from the Command Class. so there's a attackCMD class, moveCMD class, buildCMD class, etc.

By setting the command to active, how does this differ from the way i'm doing it? I have a flag in the Unit class that tells the unit to get the next command in the list. if it is true it gets the next command and sets the curCommand object with it. so i wouldn't have to go into the list to get the current command, i'll just access the curCommand object. So it's like this:


//unit class
void Update ()
{

if( nextCommand )
{
nextCommand = false;
curCommand = cmds.next;
}

if(curCommand != null)
curCommand.Update();
}


//Command Class
bool Update()
{
if( nextAction )
{
nextAction = false;
curAction = actions.next;
}

if(curAction != null)
if(curAction.Update() && actions.length == 0)
//finished
return true;
else
{
//not finished
//get next action on next update
nextAction = true;
return false;
}
else
return true;
}


Share this post


Link to post
Share on other sites
yes it is an rts. Actually it's going to be a 3d rts but i want to get the engine done first. so i'm creating a small 2d rts. So again is there a more common way of issuing orders/commands to units.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!