TGB Strategy Unit game game cs

From TDN

// --------------------------------------------------------------------
// initGame()
//
// This is a simple init function that
// --------------------------------------------------------------------
function initGame()
{
   // these are values we will use to offset our moving of units
   $posOffset[0] = "0 0";
   $posOffset[1] = "0 -5";
   $posOffset[2] = "0 5";
   $posOffset[3] = "0 -10";
   $posOffset[4] = "0 10";
   $posOffset[5] = "0 -15";
   $posOffset[6] = "0 15";
   $posOffset[7] = "0 -20";
   $posOffset[8] = "0 20";
}

// --------------------------------------------------------------------
// processAction()
//
// This will basically process the right click action of a single set
// or group of objects with the option to pass a "mode,"  this mode is
// used when you click the move action button and then click on a space 
// in the world.  This will prevent you from attacking while in that "mode,"
// though it seemed redundant to set up a whole seperate set of of functions
// when the actions are the right click actions, so this just forces the right
// click action down a path
// --------------------------------------------------------------------
function processAction(%worldPos, %mode)
{
   // get the count of objects selected
   %count = Selections.getCount();
   
   // if we have more than one object selected then we store that we have
   // multiple selections
   if(%count > 1)
   {   
      %multiple = true;
   } else
   {
      %multiple = false;
   }
   
   // here we loop through all of our selections
   for(%i=0;%i<%count;%i++)
   {
      // if we have a multiple selection we want to generate some offset points
      // so when we move a group of units they won't go to the same spot...
      // formation integration would go in here, but right now a simple
      // offset works for testing purposes
      if(%multiple)
      {
         // grab and divide the world positions as well as the offsets so we
         // can generate some -very- simple position offsets
         %worldX = getWord(%worldPos, 0);
         %worldY = getWord(%worldPos, 1);
         %offsetX = getWord($posOffset[%i], 0) + getRandom(0,2);
         %offsetY = getWord($posOffset[%i], 1) + getRandom(0,2);
         
         // lets peice together the new position
         %pos = (%worldX += %offsetX) SPC (%worldY += %offsetY);
      } else
      {
         // if this is a single selection we want the object to go
         // where we clicked
         %pos = %worldPos;
      }
      
      // lets grab a list of all objects at the area clicked so we can pass this
      // to the object for its own use
      %objList = $strategyScene.pickPoint(%worldPos);
      
      // we store the object we're currently looping through and pass it
      // information the object might need
      %obj = Selections.getObject(%i);
      %obj.OnRightClick(%pos, %mode, %objList);
   }
}