function PlayerLineFormation(%spawnid)
{
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, battleid] !$= "")
         %value = %value+50;
   }

   %value = %value / 2;
   
   switch$ (%spawnid)
   {
      case 1:
         // south
         %spawn = $Battlegrid @ "_3";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         echo("SPAWN IS " @ %x SPC %y);   
         %x = %x-%value;
      case 2:
         // west
         %spawn = $Battlegrid @ "_4";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         echo("SPAWN IS " @ %x SPC %y);   
         %y = %y-%value;
      case 3:
         // north
         %spawn = $Battlegrid @ "_1";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         echo("SPAWN IS " @ %x SPC %y);   
         %x = %x-%value;
      case 4:
         // east
         %spawn = $Battlegrid @ "_2";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         echo("SPAWN IS " @ %x SPC %y);   
         %y = %y-%value; 
   }
      
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, battleid] !$= "")
      {
         %vehicle = $vehicles[%i, battleid];

         switch$ (%spawnid)
         {
            case 1:
               // north
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y);
            case 2:
               // east
               %y = %y+50;
               %vehicle.SetPosition(%x SPC %y);
            case 3:
               // south
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y);
            case 4:
               // west
               %y = %y+50;
               %vehicle.SetPosition(%x SPC %y);
         }
         
         echo("PLACEMENT " @ %x SPC %y);
         
         // proper facing
         
         switch$ (%spawnid)
         {
            case 1:
               %vehicle.SetRotation(0);         
            case 2:
               %vehicle.SetRotation(90);                  
            case 3:
               %vehicle.SetRotation(180);                  
            case 4:
               %vehicle.SetRotation(270);                  
         }         
      }
   }
}

function PlayerHeavyFormation(%spawnid)
{
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, battleid] !$= "")
      {
         %value = %value+35;
         
         // also clasify the class
         
         %class = GetVehicleClass($vehicles[%i, vehicle]);
         
         if(%class $= "heavy")
         {
            if(%heavy $= "")
               %heavy = $vehicles[%i, battleid];
            else
               %heavy = %heavy SPC $vehicles[%i, battleid];
         }
         else
         {
            if(%light $= "")
               %light = $vehicles[%i, battleid];
            else
               %light = %light SPC $vehicles[%i, battleid];
         }
      }
   }

   %value = %value / 2;
   
   switch$ (%spawnid)
   {
      case 1:
         // south
         %spawn = $Battlegrid @ "_3";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 2:
         // west
         %spawn = $Battlegrid @ "_4";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value;
      case 3:
         // north
         %spawn = $Battlegrid @ "_1";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 4:
         // east
         %spawn = $Battlegrid @ "_2";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value; 
   }

   // heavy first
   
   %count = getWordCount(%heavy);
   
   if(%count > 0)
   {        
      for(%i=0;%i<%count;%i++)
      {
         %vehicle = getWord(%heavy, %i);
               
         switch$ (%spawnid)
         {
            case 1:
               // north
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y);
            case 2:
               // east
               %y = %y+50;
               %vehicle.SetPosition(%x SPC %y);
            case 3:
               // south
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y);
            case 4:
               // west
               %y = %y+50;
               %vehicle.SetPosition(%x SPC %y);
         }

         // proper facing
         
         switch$ (%spawnid)
         {
            case 1:
               %vehicle.SetRotation(0);         
            case 2:
               %vehicle.SetRotation(90);                  
            case 3:
               %vehicle.SetRotation(180);                  
            case 4:
               %vehicle.SetRotation(270);                  
         }         

      }
   }

   switch$ (%spawnid)
   {
      case 1:
         // south
         %spawn = $Battlegrid @ "_3";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 2:
         // west
         %spawn = $Battlegrid @ "_4";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value;
      case 3:
         // north
         %spawn = $Battlegrid @ "_1";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 4:
         // east
         %spawn = $Battlegrid @ "_2";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value; 
   }
   
   // light
   
   %count = getWordCount(%light);
   
   if(%count > 0)
   {        
      for(%i=0;%i<%count;%i++)
      {
         %vehicle = getWord(%light, %i);

         switch$ (%spawnid)
         {
            case 1:
               // north
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y-100);
            case 2:
               // east
               %y = %y+50;
               %vehicle.SetPosition(%x+100 SPC %y);
            case 3:
               // south
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y+100);
            case 4:
               // west
               %y = %y+50;
               %vehicle.SetPosition(%x-100 SPC %y);
         }

         // proper facing
         
         switch$ (%spawnid)
         {
            case 1:
               %vehicle.SetRotation(0);         
            case 2:
               %vehicle.SetRotation(90);                  
            case 3:
               %vehicle.SetRotation(180);                  
            case 4:
               %vehicle.SetRotation(270);                  
         }         
      }
   }
}

function PlayerLightFormation(%spawnid)
{
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, battleid] !$= "")
      {
         %value = %value+35;
         
         // also clasify the class
         
         %class = GetVehicleClass($vehicles[%i, vehicle]);
         
         if(%class $= "heavy")
         {
            if(%heavy $= "")
               %heavy = $vehicles[%i, battleid];
            else
               %heavy = %heavy SPC $vehicles[%i, battleid];
         }
         else
         {
            if(%light $= "")
               %light = $vehicles[%i, battleid];
            else
               %light = %light SPC $vehicles[%i, battleid];
         }
      }
   }
   
   %value = %value / 2;
   
   switch$ (%spawnid)
   {
      case 1:
         // south
         %spawn = $Battlegrid @ "_3";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 2:
         // west
         %spawn = $Battlegrid @ "_4";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value;
      case 3:
         // north
         %spawn = $Battlegrid @ "_1";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 4:
         // east
         %spawn = $Battlegrid @ "_2";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value; 
   }

   // light first
   
   %count = getWordCount(%light);
   
   if(%count > 0)
   {        
      for(%i=0;%i<%count;%i++)
      {
         %vehicle = getWord(%light, %i);
               
         switch$ (%spawnid)
         {
            case 1:
               // north
               %x = %x+25;
               %vehicle.SetPosition(%x SPC %y);
            case 2:
               // east
               %y = %y-25;
               %vehicle.SetPosition(%x SPC %y);
            case 3:
               // south
               %x = %x-25;
               %vehicle.SetPosition(%x SPC %y);
            case 4:
               // west
               %y = %y+25;
               %vehicle.SetPosition(%x SPC %y);
         }

         // proper facing
         
         switch$ (%spawnid)
         {
            case 1:
               %vehicle.SetRotation(0);         
            case 2:
               %vehicle.SetRotation(90);                  
            case 3:
               %vehicle.SetRotation(180);                  
            case 4:
               %vehicle.SetRotation(270);                  
         }         
      }
   }

   switch$ (%spawnid)
   {
      case 1:
         // south
         %spawn = $Battlegrid @ "_3";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 2:
         // west
         %spawn = $Battlegrid @ "_4";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value;
      case 3:
         // north
         %spawn = $Battlegrid @ "_1";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 4:
         // east
         %spawn = $Battlegrid @ "_2";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value; 
   }
   
   // heavy
   
   %count = getWordCount(%heavy);

   if(%count > 0)
   {        
      for(%i=0;%i<%count;%i++)
      {
         %vehicle = getWord(%heavy, %i);

         switch$ (%spawnid)
         {
            case 1:
               // north
               %x = %x+25;
               %vehicle.SetPosition(%x SPC %y-100);
            case 2:
               // east
               %y = %y-25;
               %vehicle.SetPosition(%x+100 SPC %y);
            case 3:
               // south
               %x = %x-25;
               %vehicle.SetPosition(%x SPC %y+100);
            case 4:
               // west
               %y = %y+25;
               %vehicle.SetPosition(%x-100 SPC %y);
         }

         // proper facing
         
         switch$ (%spawnid)
         {
            case 1:
               %vehicle.SetRotation(0);         
            case 2:
               %vehicle.SetRotation(90);                  
            case 3:
               %vehicle.SetRotation(180);                  
            case 4:
               %vehicle.SetRotation(270);                  
         }         
      }
   }
}

function PlayerBoxFormation(%spawnid)
{
   for(%i=1;%i<=5;%i++)
   {
      if($vehicles[%i, battleid] !$= "")
      {
         %value = %value+35;
                  
         if(%front $= "")
            %front = $vehicles[%i, battleid];
         else
            %front = %front SPC $vehicles[%i, battleid];
      }
   }

   %value = %value / 2;
   
   switch$ (%spawnid)
   {
      case 1:
         // south
         %spawn = $Battlegrid @ "_3";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 2:
         // west
         %spawn = $Battlegrid @ "_4";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value;
      case 3:
         // north
         %spawn = $Battlegrid @ "_1";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 4:
         // east
         %spawn = $Battlegrid @ "_2";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value; 
   }

   // front line
   
   %count = getWordCount(%front);
   
   if(%count > 0)
   {        
      for(%i=0;%i<%count;%i++)
      {
         %vehicle = getWord(%front, %i);
               
         switch$ (%spawnid)
         {
            case 1:
               // north
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y);
            case 2:
               // east
               %y = %y+50;
               %vehicle.SetPosition(%x SPC %y);
            case 3:
               // south
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y);
            case 4:
               // west
               %y = %y+50;
               %vehicle.SetPosition(%x SPC %y);
         }

         // proper facing
         
         switch$ (%spawnid)
         {
            case 1:
               %vehicle.SetRotation(0);         
            case 2:
               %vehicle.SetRotation(90);                  
            case 3:
               %vehicle.SetRotation(180);                  
            case 4:
               %vehicle.SetRotation(270);                  
         }         
      }
   }
   
   %value = "";
   
   for(%i=6;%i<=10;%i++)
   {
      if($vehicles[%i, battleid] !$= "")
      {
         %value = %value+35;
                  
         if(%back $= "")
            %back = $vehicles[%i, battleid];
         else
            %back = %back SPC $vehicles[%i, battleid];
      }
   }

   %value = %value / 2;

   switch$ (%spawnid)
   {
      case 1:
         // south
         %spawn = $Battlegrid @ "_3";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 2:
         // west
         %spawn = $Battlegrid @ "_4";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value;
      case 3:
         // north
         %spawn = $Battlegrid @ "_1";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 4:
         // east
         %spawn = $Battlegrid @ "_2";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value; 
   }
   
   // second line
   
   %count = getWordCount(%back);
   
   if(%count > 0)
   {        
      for(%i=0;%i<%count;%i++)
      {
         %vehicle = getWord(%back, %i);

         switch$ (%spawnid)
         {
            case 1:
               // north
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y-100);
            case 2:
               // east
               %y = %y+50;
               %vehicle.SetPosition(%x+100 SPC %y);
            case 3:
               // south
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y+100);
            case 4:
               // west
               %y = %y+50;
               %vehicle.SetPosition(%x-100 SPC %y);
         }

         // proper facing
         
         switch$ (%spawnid)
         {
            case 1:
               %vehicle.SetRotation(0);         
            case 2:
               %vehicle.SetRotation(90);                  
            case 3:
               %vehicle.SetRotation(180);                  
            case 4:
               %vehicle.SetRotation(270);                  
         }         
      }
   }
}

function PlayerSkirmishLine(%spawnid)
{
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, battleid] !$= "")
         %value = %value+50;
   }

   %value = %value / 2;
   
   switch$ (%spawnid)
   {
      case 1:
         // south
         %spawn = $Battlegrid @ "_3";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 2:
         // west
         %spawn = $Battlegrid @ "_4";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value;
      case 3:
         // north
         %spawn = $Battlegrid @ "_1";         
         %y = getWord(%spawn.GetPosition(), 1);
         %x = getWord(%spawn.GetPosition(), 0);
         %x = %x-%value;
      case 4:
         // east
         %spawn = $Battlegrid @ "_2";         
         %x = getWord(%spawn.GetPosition(), 0);
         %y = getWord(%spawn.GetPosition(), 1);
         %y = %y-%value; 
   }
      
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, battleid] !$= "")
      {
         %vehicle = $vehicles[%i, battleid];

         switch$ (%spawnid)
         {
            case 1:
               // north
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y+getRandom(-75, 50));
            case 2:
               // east
               %y = %y+50;
               %vehicle.SetPosition(%x+getRandom(-50, 75) SPC %y);
            case 3:
               // south
               %x = %x+50;
               %vehicle.SetPosition(%x SPC %y+getRandom(-50, 75));
            case 4:
               // west
               %y = %y+50;
               %vehicle.SetPosition(%x+getRandom(-75, 50) SPC %y);
         }

         // proper facing
         
         switch$ (%spawnid)
         {
            case 1:
               %vehicle.SetRotation(0);         
            case 2:
               %vehicle.SetRotation(90);                  
            case 3:
               %vehicle.SetRotation(180);                  
            case 4:
               %vehicle.SetRotation(270);                  
         }         
      }
   }
}
