function MountPlayerFiringPoints(%id)
{   
   %size = %id.GetSize();
   %x = getWord(%size, 0);
   %y = getWord(%size, 1);

   // left
   
   %obj = new t2dSceneObject() {
      canSaveDynamicFields = "1";
      size = "1" SPC %y;
      scenegraph = "sg";
   };
   
   %obj.mount(%id, "-2 0", 0, true, true, true, true);   
   %obj.playerportal = "left";
   %obj.owner = %id;

   // right

   %obj = new t2dSceneObject() {
      canSaveDynamicFields = "1";
      size = "1" SPC %y ;
      scenegraph = "sg";
   };   
   
   %obj.mount(%id, "2 0", 0, true, true, true, true);   
   %obj.playerportal = "right";
   %obj.owner = %id;

   // back
   
   %x = %x + (%x * ".30"); // used for back and front
   
   %obj = new t2dSceneObject() {
      canSaveDynamicFields = "1";
      size = %x SPC "1";
      scenegraph = "sg";
   };
   
   %obj.mount(%id, "0 1.5", 0, true, true, true, true);   
   %obj.playerportal = "back";
   %obj.owner = %id;

   // front

   %obj = new t2dSceneObject() {
      canSaveDynamicFields = "1";
      size = %x SPC "1";
      scenegraph = "sg";
   };
   
   %obj.mount(%id, "0 -1.5", 0, true, true, true, true);   
   %obj.playerportal = "front";
   %obj.owner = %id;
}

function GetEnemyTargets(%id)
{
   // this is just a snapshot of what's around so clear the targets on every check
   
   %id.fronttargets = "";
   %id.backtargets = "";
   %id.righttargets = "";
   %id.lefttargets = "";
   
   // get enemy vehicles within range
   
   for(%i=1;%i<=10;%i++)
   {
      if($Enemyvehicles[%i, battleid] !$= "")
      {
         %dist = VectorDist(%id.GetPosition(), $Enemyvehicles[%i, battleid].GetPosition());
         
         if(%dist <= 100 && %id.donotfire !$= $Enemyvehicles[%i, battleid])
         {
            if(%targets $= "")  
               %targets = $Enemyvehicles[%i, battleid];
            else
               %targets = %targets SPC $Enemyvehicles[%i, battleid];            
         }         
      }
   }
   
   if(%targets !$= "")
   {
      %count = getWordCount(%targets);
      
      for(%i=0;%i<%count;%i++)
      {
         %enemy = getWord(%targets, %i);
         
         %line = sg.pickLine(%id.GetPosition(), %enemy.GetPosition());
         
         %linecount = getWordCount(%line);
         
         for(%j=0;%j<%linecount;%j++)
         {
            %obj = getWord(%line, %j);
            
            if(%obj.playerportal !$= "" && %obj.owner $= %id)
               %portal = %obj.playerportal;
            
            if(%obj.player $= 1)
               if(%obj !$= %id)
                  %playerblock = true;
            
            if(%obj.block $= 1)
               %block = 1;
         }
         
         if(%block $= "" && %playerblock $= "")
         {               
            switch$ (%portal)
            {                  
               case "front":
                  if(%id.fronttargets $= "")
                     %id.fronttargets = %enemy;
                  else
                     %id.fronttargets = %id.fronttargets SPC %enemy;
               case "back":
                  if(%id.backtargets $= "")
                     %id.backtargets = %enemy;
                  else
                     %id.backtargets = %id.backtargets SPC %enemy;
               case "right":
                  if(%id.righttargets $= "")
                     %id.righttargets = %enemy;
                  else
                     %id.righttargets = %id.righttargets SPC %enemy;
               case "left":                  
                  if(%id.lefttargets $= "")
                     %id.lefttargets = %enemy;
                  else
                     %id.lefttargets = %id.lefttargets SPC %enemy;
            }               
         }
      }
   }
}



/////////////////////////// enemy /////////////////////////////////////////////////////////////////

function MountEnemyFiringPoints(%id)
{   
   %size = %id.GetSize();
   %x = getWord(%size, 0);
   %y = getWord(%size, 1);

   // left
   
   %obj = new t2dSceneObject() {
      canSaveDynamicFields = "1";
      size = "1" SPC %y;
      scenegraph = "sg";
   };
   
   %obj.mount(%id, "-2 0", 0, true, true, true, true);   
   %obj.enemyportal = "left";
   %obj.owner = %id;

   // right

   %obj = new t2dSceneObject() {
      canSaveDynamicFields = "1";
      size = "1" SPC %y ;
      scenegraph = "sg";
   };   
   
   %obj.mount(%id, "2 0", 0, true, true, true, true);   
   %obj.enemyportal = "right";
   %obj.owner = %id;

   // back
   
   %x = %x + (%x * ".30"); // used for back and front
   
   %obj = new t2dSceneObject() {
      canSaveDynamicFields = "1";
      size = %x SPC "1";
      scenegraph = "sg";
   };
   
   %obj.mount(%id, "0 1.5", 0, true, true, true, true);   
   %obj.enemyportal = "back";
   %obj.owner = %id;

   // front

   %obj = new t2dSceneObject() {
      canSaveDynamicFields = "1";
      size = %x SPC "1";
      scenegraph = "sg";
   };
   
   %obj.mount(%id, "0 -1.5", 0, true, true, true, true);   
   %obj.enemyportal = "front";
   %obj.owner = %id;
}

function GetPlayerTargets(%id)
{
   // this is just a snapshot of what's around so clear the targets on every check
   
   %id.fronttargets = "";
   %id.backtargets = "";
   %id.righttargets = "";
   %id.lefttargets = "";

   // get enemy vehicles within range
   
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, battleid] !$= "")
      {
         %dist = VectorDist(%id.GetPosition(), $vehicles[%i, battleid].GetPosition());
         
         if(%dist <= 100)
         {
            if(%targets $= "")  
               %targets = $vehicles[%i, battleid];
            else
               %targets = %targets SPC $vehicles[%i, battleid];            
         }         
      }
   }
   
   if(%targets !$= "")
   {
      %count = getWordCount(%targets);
      
      for(%i=0;%i<%count;%i++)
      {
         %player = getWord(%targets, %i);
         
         %line = sg.pickLine(%id.GetPosition(), %player.GetPosition());
         
         %linecount = getWordCount(%line);
         
         for(%j=0;%j<%linecount;%j++)
         {
            %obj = getWord(%line, %j);
            
            if(%obj.enemyportal !$= ""  && %obj.owner $= %id)
            {
               switch$ (%obj.enemyportal)
               {
                  case "front":
                     if(%id.fronttargets $= "")
                        %id.fronttargets = %player;
                     else
                        %id.fronttargets = %id.fronttargets SPC %player;
                  case "back":
                     if(%id.backtargets $= "")
                        %id.backtargets = %player;
                     else
                        %id.backtargets = %id.backtargets SPC %player;
                  case "right":
                     if(%id.righttargets $= "")
                        %id.righttargets = %player;
                     else
                        %id.righttargets = %id.righttargets SPC %player;
                  case "left":                  
                     if(%id.lefttargets $= "")
                        %id.lefttargets = %player;
                     else
                        %id.lefttargets = %id.lefttargets SPC %player;
               }
               
               break;
            }
         }
      }
   }
}