• 10
• 9
• 13
• 10
• 18

# Unit commands / Command Manager

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

## 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: All comments and sugestions are welcome, Thanks

##### Share on other sites
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 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 classvoid Update (){if( nextCommand ){nextCommand = false;curCommand = cmds.next;}if(curCommand != null)curCommand.Update();}//Command Classbool 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 on other sites
Well, certain objects cant do certain tasks, so you would have a command parser to double check that. I guess I just read you wrong, I'm sorry...

##### Share on other sites
That's ok. So is there another way of issuing orders to units? Is there a more commonly used method?

Thanks

##### Share on other sites
I assume this is an RTS. What is the most common way that this is done in RTS games?