Jump to content
  • Advertisement
Sign in to follow this  
rmxhaha

Command system in RTS game

This topic is 2007 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

Say I have this class called Spaceship 

Now off coarse I have to give command to this Spaceship like go here and go there

I have fully implemented steering behavior like seek, flee, avoid, 

 

but I am having a hard time deciding whether I should put something like

the command system inside the class or outside the class

 

something like 

var ship = new Spaceship( param );
 
io.on('connection', function( socket ){
    socket.on('command', function( cmd ){
       if( cmd.instruction == 'move' )
           ship.moveTo( cmd.x, cmd.y );
    }
});
 

 

There are some command that need interaction with other classes not just one class something like shooting missile 

when shooting missile it have to know the location of the enemy which need a pointer to the enemy

and also it need to spawn missile class and push them to missiles array which is concealed deep inside another class

 

so should I just make this class something like Commander

to tell each unit what to do

There will be one Commander class per player 

 

What do you think ?

is there a major flaw both of these ?

Share this post


Link to post
Share on other sites
Advertisement

Your question is hard to answer without knowing how the rest of your game is structured. The short answer is, both ways might work.

 

The longer answer is encapsulation. Ideally, each object should only know about the stuff it actually needs. So an object shooting a missile doesn't necessarily need to know any of that; it just needs a function that takes a target as an argument that spawns another object (the missile). The spaceship doesn't actually have to know anything about missiles or enemies; it just needs to know how to spawn an object and give the spawned object a target.

 

If you need more information, it would help to know how your current classes are structured.

Share this post


Link to post
Share on other sites

My classes are structured something like this

I will make this brief :

 

 
var HealthModule = {  
     number : 1,
     shield : 1,
     hit : function( dmg ){ ... }
}
 
var EventListener = function(){
     call : function( eventName ){ ... },
     on : function( eventname, callback ){ ... }
}
 
var Spaceship = function( opt ){
     this.extend( opt );
}
 
// now spaceship have those module property and function
Spaceship.prototype.extend( HealthModule );
 
// so ship = new Spaceship( ...);
// ship.on('death', function(){} );
// is possible
Spaceship.prototype.extend( EventListener('death','under-attack') );
var Warhead = function(){ ... }
 
// this is I think most people call entity manager 
var Galaxy =  function(){
    var Legion = function(){
        this.units = [];
        this.heads = [];
    }
    var legions = [];
 
    this.addLegion = function(){};
    
    this.update = function(){}
}
 
var galaxy = new Galaxy;
 
setInterval( galaxy.update, 50 );
 
// socket and data transfer between client server
 
var express = ...;
var io = ...;
 
io.on('connection', function( socket ){
    var legion = ...;
    socket.on('identification', function( data ) { legion = spawnLegion( data ) } );
 
   function sendData(){
     socket.emit( galaxy.getData( legion.id ) );
   }
   
   setInterval( sendData, 100 );
});

 

I skip a lot of internal physic, health, collision system and this is just pseudocode that I type to describe the structure I am using 

 

so can you tell

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!