
// speed control //////////////////////////////////////////////////////////////////////////////////////

function IncreasePlayerSpeed()
{
   if($combat $= "")
      return;

   DisplayTutorial(Acceleration);

   %id = $vehicles[$CombatCamera, battleid];
   
   // if setspeed is blank then this is the first time the player is adjusting the speed for this vehicle
     
   if(%id.setspeed $= "")
   {
      %id.setspeed = %id.currentspeed;
      %id.setspeed = %id.setspeed+10;
   }
   else
      %id.setspeed = %id.setspeed+10;
   
   // should play a beep or modify icon to let the player know vehicle can't be set for any faster
   
   if(%id.setspeed > %id.topspeed)
   {
      alxPlay(buzzer);
      echo("SET TO MAX SPEED");
      %id.setspeed = %id.setspeed-10;
   }
   else
      alxPlay(goodbeep);
}

function DecreasePlayerSpeed()
{
   if($combat $= "")
      return;
      
   %id = $vehicles[$CombatCamera, battleid];
   
   // if setspeed is blank then this is the first time the player is adjusting the speed for this vehicle
     
   if(%id.setspeed $= "")
   {
      %id.setspeed = %id.currentspeed;
      %id.setspeed = %id.setspeed-10;
   }
   else
      %id.setspeed = %id.setspeed-10;
   
   // should play a beep or modify icon to let the player know vehicle can't be set for any faster
   
   if(%id.setspeed < 0)
   {
      alxPlay(buzzer);
      echo("Vehicle is stopped");
      %id.setspeed = 0;
   }
   else
      alxPlay(goodbeep);
}

function CustomAttackOrder(%attack)
{
   if($combat $= "")
      return;
   
   if(%attack $= "DoNotFire")
      DisplayTutorial("DoNotFire");
      
   if(attackcrew.bitmap $= "game/data/images/gui/red.png")
      %previous = "attackcrew";        
   if(attackengine.bitmap $= "game/data/images/gui/red.png")
      %previous = "attackengine";        
   if(attackgastank.bitmap $= "game/data/images/gui/red.png")
      %previous = "attackgastank";        
   if(attackmountedweapon.bitmap $= "game/data/images/gui/red.png")
      %previous = "attackmountedweapon";        
   if(attacktires.bitmap $= "game/data/images/gui/red.png")
      %previous = "attacktires";        
   if(ramvehicle.bitmap $= "game/data/images/gui/red.png")
      %previous = "ramvehicle";        
   if(BoardVehicle.bitmap $= "game/data/images/gui/red.png")
      %previous = "boardvehicle";        
   if(donotfire.bitmap $= "game/data/images/gui/red.png")
      %previous = "donotfire";        
   
   // deselecting attack orders
      
   if(%previous $= %attack)
   {   
      %previous.SetBitmap(expandfilename("~/data/images/gui/sq_border.png"));      
      canvas.SetCursor(GameCursor);         
      $vehicles[$CombatCamera, battleid].attackorder = "";
      
      // do not fire is a bit special
      
      if(%attack $= "donotfire")
      {      
         for(%i=1;%i<=10;%i++)
         {
            if($vehicles[%i, battleid] !$= "")
               $vehicles[%i, battleid].donotfire = "";         
         }
         
         $DoNotFire = "";
         $TargetOrder = "";
      }
   }
   
   // new order that what is currently selected
   
   if(%previous !$= "" && %previous !$= %attack)
   {   
      %previous.SetBitmap(expandfilename("~/data/images/gui/sq_border.png"));      
      canvas.SetCursor(GameCursor);         
      $vehicles[$CombatCamera, battleid].attackorder = "";
      %previous = "";
      $TargetOrder = "";
   }
   
   // new order
      
   if(%previous $= "")
   {
      %attack.SetBitmap(expandfilename("~/data/images/gui/red.png"));      
      canvas.SetCursor(TargetCursor);         
      
      if(%attack !$= "donotfire")
         $vehicles[$CombatCamera, battleid].attackorder = %attack;
      else
         $DoNotFire = true;
         
      // so the enemy intel doesn't display
      
      $TargetOrder =  true;
   }
   
   $vehicles[$CombatCamera, battleid].firelocation = "";
   $vehicles[$CombatCamera, battleid].BoardVehicle = "";
   $vehicles[$CombatCamera, battleid].RamVehicle = "";
}

// play a beep if the player can't attack that particular section on an enemy vehicle

function TargetEnemyVehicle(%slot)
{
   // mark the target and the location on the player vehicle
   
   %id = $vehicles[$CombatCamera, battleid];

   // for a manual target, the attack order will be blank so it will return
   
   switch$ ($vehicles[$CombatCamera, battleid].attackorder)
   {
      case "attackcrew":
         %id.firelocation = "crew";      
         %id.donotfire = "";   
         alxPlay(goodbeep);
      case "attacktires":
         if($Enemyvehicles[%slot, badtires] $= GetMaxVehicleTires($Enemyvehicles[%slot, vehicle]))
         {
            alxPlay(buzzer);
            return;            
         }
         %id.donotfire = "";   
         alxPlay(goodbeep);
         %id.firelocation = "tires";            
      case "attackengine":
         if($Enemyvehicles[%slot, currentenginehp] == 0)
         {
            alxPlay(buzzer);
            return;            
         }
         %id.donotfire = "";   
         alxPlay(goodbeep);
         %id.firelocation = "engine";            
      case "attackmountedweapon":
         if($Enemyvehicles[%slot, mountedweapon] $= "")
         {
            alxPlay(buzzer);
            return;            
         }
         %id.donotfire = "";   
         alxPlay(goodbeep);
         %id.firelocation = "mountedweapon";            
      case "attackgastank":      
         %id.firelocation = "gastank";      
         %id.donotfire = "";   
         alxPlay(goodbeep);
      case "boardvehicle":
         %count = getWordCount(%id.crew);      

         if(%count <= 2)
         {
            %id.boardvehicle = "";
            DisplayTutorial("MayNotBoard");
            alxPlay(buzzer);
            return;      
         }

         %id.boardvehicle = true;
         alxPlay(goodbeep);
      case "ramvehicle":
         %id.ramvehicle = true;
         alxPlay(goodbeep);
   }

   canvas.SetCursor(GameCursor);
   $TargetOrder = "";
   
   if($DoNotFire $= true)
   {
      for(%i=1;%i<=10;%i++)
      {
         if($vehicles[%i, battleid] !$= "")
            $vehicles[%i, battleid].donotfire = $Enemyvehicles[%slot, battleid];
      }

      alxPlay(goodbeep);
      
      $DoNotFire = "";
   }
   else
   {
      // make this the new target for the vehicle to drive around
      
      %id.target = $Enemyvehicles[%slot, battleid];
      %id.coords = "";  // if they have coords assigned, clear them   
      greenflag.visible = false;

      UpdateEnemyGroup();
   }
}

// When the player makes a selection during combat

function CombatSelection(%coords)
{
   echo("COMBAT SELECTION");
   
   %objects = sg.pickPoint(%coords);   
   
   %count = getWordCount(%objects);
   
   for(%i=0;%i<%count;%i++)
   {
      %obj = getWord(%objects, %i);
      
      // custom attack order
      
      if(%obj.enemy $= 1 && $vehicles[$CombatCamera, battleid].attackorder !$= "")
      {
         echo("TARGET ENEMY VEHICLE");
         TargetEnemyVehicle(%obj.slot);        
         return;
      }
      
      // do not fire
      
      if(%obj.enemy $= 1 && $DoNotFire $= true)
      {
         echo("DO NOT FIRE ENEMY VEHICLE");
         TargetEnemyVehicle(%obj.slot);        
         return;
      }
      
      // select target
      
      if(%obj.enemy $= 1 && $vehicles[$CombatCamera, battleid].targetorder $= true)
      {
         SelectVehicleTarget(%obj);
         return;
      }
      
      // friendly selection
      
      if(%obj.player $= 1)
         SetVehicleCamera(%obj.slot);
   }
   
   // they are selecting the ground but it will check to see if there is a building there
   
   if($vehicles[$CombatCamera, battleid].targetorder $= true)
      SelectGround(%coords);
}

// this is to either target a vehicle for a general attack or target the ground for the vehicle to rotate around

function TargetOrder()
{   
   DisplayTutorial(selecttarget);
   
   if(TargetOrder.bitmap $= "game/data/images/gui/red.png")
   {
      $vehicles[$CombatCamera, battleid].targetorder = "";       
      canvas.SetCursor(GameCursor);
      TargetOrder.SetBitmap(expandfilename("game/data/images/gui/sq_border.png"));    
      greenflag.visible = false;   
      $TargetOrder = "";
   }
   else
   {
      $vehicles[$CombatCamera, battleid].targetorder = true;       
      canvas.SetCursor(TargetCursor);
      TargetOrder.SetBitmap(expandfilename("game/data/images/gui/red.png"));      
      $TargetOrder = true;
   }
}

// will be either an enemy vehicle or coords on the map
// if they select a target clear the coords so the nav function knows to follow the target

function SelectVehicleTarget(%obj)
{   
   canvas.SetCursor(GameCursor);
   
   $vehicles[$CombatCamera, battleid].target = %obj;
   $vehicles[$CombatCamera, battleid].coords = "";   
   greenflag.visible = false;
   
   $TargetOrder = "";
}

function SelectGround(%coords)
{
   %objects = sg.pickPoint(%coords);   
   
   %count = getWordCount(%objects);
   
   for(%i=0;%i<%count;%i++)
   {
      %obj = getWord(%objects, %i);
      
      if(%obj.block $= 1)
      {
         $LastBlockedPick = %obj;   // this is to make sure the player can't keep selecting the same building over and over again
         alxPlay(buzzer);
         return;            
      }
            
      if(%obj.GetName() $= $Battlegrid)
         %grid = true;
   }
   
   // check for a border
   
   %line = sg.pickLine(%coords, $vehicles[$CombatCamera, battleid].GetPosition());
   
   %linecount = getWordCount(%line);
   
   for(%j=0;%j<%linecount;%j++)
   {
      %obj = getWord(%line, %j);
      
      if(%obj.border $= 1)
      {
         alxPlay(buzzer);
         return;            
      }
   }
   
   // will rotate arond these coordinates
   if(%grid $= true)
   {
      $vehicles[$CombatCamera, battleid].coords = %coords;  
      greenflag.SetPosition($vehicles[$CombatCamera, battleid].coords);
      greenflag.visible = true;
      $vehicles[$CombatCamera, battleid].targetorder = "";
      canvas.SetCursor(GameCursor);
      TargetOrder.SetBitmap(expandfilename("game/data/images/gui/sq_border.png"));    
      $TargetOrder = "";
   }
   else
      alxPlay(buzzer);
}

function UpdateCustomOrders()
{
   attackcrew.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   targetOrder.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   attackengine.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   attackmountedweapon.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   attackgastank.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   attacktires.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   boardvehicle.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   ramvehicle.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   
   switch$ ($vehicles[$CombatCamera, battleid].firelocation)
   {
      case "crew":
         attackcrew.SetBitMap(expandfilename("~/data/images/gui/red.png"));         
      case "tires":
         attacktires.SetBitMap(expandfilename("~/data/images/gui/red.png"));         
      case "engine":
         attackengine.SetBitMap(expandfilename("~/data/images/gui/red.png"));         
      case "mountedweapon":
         attackmountedweapon.SetBitMap(expandfilename("~/data/images/gui/red.png"));         
      case "gastank":      
         attackgastank.SetBitMap(expandfilename("~/data/images/gui/red.png"));         
   }
   
   if($vehicles[$CombatCamera, battleid].boardvehicle $= true)
      boardvehicle.SetBitMap(expandfilename("~/data/images/gui/red.png"));         
   if($vehicles[$CombatCamera, battleid].ramvehicle $= true)
      ramvehicle.SetBitMap(expandfilename("~/data/images/gui/red.png"));         
   if($vehicles[$CombatCamera, battleid].donotfire !$= "")
      donotfire.SetBitMap(expandfilename("~/data/images/gui/red.png"));         
   
   canvas.SetCursor(GameCursor);
   $TargetOrder = "";
}

function ClearCustomOrders(%slot)
{
   attackcrew.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   targetOrder.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   attackengine.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   attackmountedweapon.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   attackgastank.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   attacktires.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   boardvehicle.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   ramvehicle.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   donotfire.SetBitMap(expandfilename("~/data/images/gui/sq_border.png"));         
   
   $vehicles[%slot, battleid].firelocation = "";
   $vehicles[%slot, battleid].boardvehicle = "";
   $vehicles[%slot, battleid].ramvehicle = "";   
   $vehicles[%slot, battleid].coords = "";
   greenflag.visible = false;

   canvas.SetCursor(GameCursor);
   
   $TargetOrder = "";
}


//////////// display enemy text and enemy seletion //////////////////////////////////////////////////////

function DisplayEnemyVehicle(%this, %mod, %coords, %click)
{      
   if($TargetOrder $= true)
      return;
      
   %objects = sg.pickPoint(%coords);   
   
   %count = getWordCount(%objects);
   
   for(%i=0;%i<%count;%i++)
   {
      %obj = getWord(%objects, %i);
      
      if(%obj.enemy $= 1 && $EnemyIntel $= "")
      {      
         CreateEnemyIntelDisplay(%obj);
         %vehicle = %obj;
         echo("DISPLAY INFO");
         break;
      }      
      
      if(%obj.enemy $= 1 && $EnemyIntel !$= "")
         %vehicle = %obj;
   }
   
   if($EnemyIntel !$= %vehicle)
   {
      $EnemyIntel.DetachGui();      
      $EnemyIntel.control.delete();
      $EnemyIntel = "";
      echo("DELETE INFO");
   }
}

function CreateEnemyIntelDisplay(%obj)
{
   %x = getWord(%obj.GetPosition(), 0);
   %y = getWord(%obj.GetPosition(), 1);

   switch$ ($Enemyvehicles[%obj.slot, vehicle])
   {
      case "dunebuggy":
         %text = "Dune Buggy";           
      case "bike":
         %text = "Bike";           
      case "jeep":
         %text = "Jeep";           
      case "compact":
         %text = "Compact";           
      case "minivan":
         %text = "Mini Van";           
      case "towtruck":
         %text = "Tow Truck";           
      case "van":
         %text = "Van";           
      case "limo":
         %text = "Limo";           
      case "sedan":
         %text = "Sedan";           
      case "sportscar":
         %text = "Sports Car";           
      case "pickuptruck":
         %text = "Pickup Truck";           
      case "musclecar":
         %text = "Muscle Car";           
      case "stationwagon":
         %text = "Station Wagon";           
      case "humvee":
         %text = "Humvee";           
      case "suv":
         %text = "SUV";           
      case "flatbedtruck":
         %text = "Flatbed Truck";           
      case "trailertruck":
         %text = "Trailer Truck";           
      case "fireengine":
         %text = "Fire Engine";           
      case "garbagetruck":
         %text = "Garbage Truck";           
      case "bus":
         %text = "Bus";           
      case "boxtruck":
         %text = "Box Truck";           
      case "cargovan":
         %text = "Cargo Van";           
      case "ambulance":
         %text = "Ambulance";           
      case "construction":
         %text = "Construction Vehicle";                 
   }
   
      %control = new GuiBitmapCtrl() {
         canSaveDynamicFields = "0";
         isContainer = "1";
         Profile = "GuiDefaultProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         Position = "2000 2000";
         Extent = "282 237";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         hovertime = "1000";
         bitmap = "~/data/images/gui/med_brdr.png";
         wrap = "0";

         new GuiTextCtrl(enemyintel_name) {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui28WhiteCenter";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "40 19";
            Extent = "200 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Vehicle Condition:";
            maxLength = "1024";
         };
         new GuiTextCtrl() {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "10 49";
            Extent = "149 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Vehicle Condition:";
            maxLength = "1024";
         };
         new GuiTextCtrl() {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "10 79";
            Extent = "64 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Crew:";
            maxLength = "1024";
         };
         new GuiTextCtrl() {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "10 109";
            Extent = "64 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Tires:";
            maxLength = "1024";
         };
         new GuiTextCtrl() {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "10 139";
            Extent = "64 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Engine:";
            maxLength = "1024";
         };
         new GuiTextCtrl() {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "10 169";
            Extent = "133 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Mounted Weapon:";
            maxLength = "1024";
         };

         new GuiTextCtrl() {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "10 199";
            Extent = "149 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Speed:";
            maxLength = "1024";
         };
         new GuiTextCtrl(enemyintel_vehicle) {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "160 49";
            Extent = "117 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Vehicle Condition";
            maxLength = "1024";
         };
         new GuiTextCtrl(enemyintel_crew) {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "160 79";
            Extent = "108 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Crew";
            maxLength = "1024";
         };
         new GuiTextCtrl(enemyintel_tires) {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "160 109";
            Extent = "115 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Tires";
            maxLength = "1024";
         };
         new GuiTextCtrl(enemyintel_engine) {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "160 139";
            Extent = "111 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Engine";
            maxLength = "1024";
         };
         new GuiTextCtrl(enemyintel_weapon) {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "160 169";
            Extent = "117 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Mounted Weapon";
            maxLength = "1024";
         };
         new GuiTextCtrl(enemyintel_Speed) {
            canSaveDynamicFields = "0";
            isContainer = "0";
            Profile = "Gui24White";
            HorizSizing = "right";
            VertSizing = "bottom";
            Position = "160 199";
            Extent = "215 19";
            MinExtent = "8 2";
            canSave = "1";
            Visible = "1";
            hovertime = "1000";
            text = "Name";
            maxLength = "1024";
         };
      };
   
   // fill in the info
   
   // name
   
   enemyintel_name.setText(%text);
   
   // vehicle
   
   %third = $Enemyvehicles[%obj.slot, stockvehiclehp] / 3;
   %third = mCeil(%third);
             
   if($Enemyvehicles[%obj.slot, currentvehiclehp] < %third)
      enemyintel_vehicle.setText("Poor");
   if($Enemyvehicles[%obj.slot, currentvehiclehp] >= %third)
      enemyintel_vehicle.setText("Average");
   if($Enemyvehicles[%obj.slot, currentvehiclehp] >= (%third * 2))
      enemyintel_vehicle.setText("Excellent");
            
   // crew
   
   %capacity = GetVehiclePeopleCapacity(%obj.vehiclename);
   %crew = getWordCount(%obj.crew);
   %third = %capacity / 3;
   %third = mCeil(%third);
            
   if(%capacity $= %crew)
      enemyintel_crew.setText("Full");
   else
   {
      if(%crew < %third)
         enemyintel_crew.setText("Low");
      if(%crew >= %third)
         enemyintel_crew.setText("About 1/3 Left");
      if(%crew >= (%third *2))
         enemyintel_crew.setText("About 2/3 Left");
   }
   
   // tires
   
   %tires = $Enemyvehicles[%obj.slot, tires]-$Enemyvehicles[%obj.slot, badtires];
   enemyintel_tires.setText(%tires @ " Tires left");
   
   // engine

   %engine = GetStockEngineHitPoints(%obj.vehiclename);
   %third = %engine / 3;
   %third = mCeil(%third);
            
   if($Enemyvehicles[%obj.slot, currentenginehp] < %third)
      enemyintel_engine.setText("Low");
   if($Enemyvehicles[%obj.slot, currentenginehp] >= %third)
      enemyintel_engine.setText("Average");
   if($Enemyvehicles[%obj.slot, currentenginehp] >= (%third *2))
      enemyintel_engine.setText("Excellent");
      
   // speed
   
   enemyintel_speed.setText(%obj.currentspeed);
      
   // mounted weapon
   
   %third = $Enemyvehicles[%obj.slot, stockmountedweaponhp] / 3;
   %third = mCeil(%third);
   
   if($Enemyvehicles[%obj.slot, stockmountedweaponhp] $= "")
      enemyintel_weapon.setText("None");
   else
   {                           
      if($Enemyvehicles[%obj.slot, currentmountedweaponhp] < %third)
         enemyintel_weapon.setText("Low");
      if($Enemyvehicles[%obj.slot, currentmountedweaponhp] >= %third)
         enemyintel_weapon.setText("Average");
      if($Enemyvehicles[%obj.slot, currentmountedweaponhp] >= (%third * 2))
         enemyintel_weapon.setText("Excellent");
   }
                        
   %obj.AttachGui(%control, Screen2D, false);
   %obj.control = %control;
   $EnemyIntel = %obj;      
   $enemyIntelControl = %control;   // used in after combat for deleting
}

// if a player just leaves a mouse cursor over the enemy it will continue to display the name
// this will keep checking and once the enemy vehicle is not under the cursor hide the text

function CheckEnemyIntel(%coords)
{
   %objects = sg.pickPoint(%coords);   
   
   %count = getWordCount(%objects);
   
   for(%i=0;%i<%count;%i++)
   {
      %obj = getWord(%objects, %i);
      
      if(%obj.enemy $= 1)
      {
         %enemy = true;
         schedule(200, 0, "CheckEnemyIntel", %coords);          
      }
   }
   
   if(%enemy $= "")
   {
      $EnemyIntel.DetachGui();      
      $EnemyIntel.control.delete();
      $EnemyIntel = "";
   }
}
