
function InitQB1Desc()
{
   quickbattle1desc.setText("Select any combination of vehicles for your gang and the enemy gang. Select either the Friendly or Enemy " @
   "button to select vehicles for that gang. Remove a vehicle by clicking on it.");   
   
   deleteVariables("$EnemyQuickVehicles*");   
   deleteVariables("$PlayerQuickVehicles*");   
}

// this will generate all the commands for the buttons for the first screen
// remember if the vehicle orders change in the GUI change them here

function GenerateQuickBattle()
{   
   
   qv1.command = "PlaceQuickVehicle(\"dunebuggy\");";           
   qv1.tooltip = GetVehicleDisplayName(dunebuggy);      
   qv2.command = "PlaceQuickVehicle(\"bike\");";           
   qv2.tooltip = GetVehicleDisplayName(bike);      
   qv3.command = "PlaceQuickVehicle(\"jeep\");";           
   qv3.tooltip = GetVehicleDisplayName(jeep);      
   qv4.command = "PlaceQuickVehicle(\"compact\");";           
   qv4.tooltip = GetVehicleDisplayName(compact);      
   qv5.command = "PlaceQuickVehicle(\"minivan\");";           
   qv5.tooltip = GetVehicleDisplayName(minivan);      
   qv6.command = "PlaceQuickVehicle(\"towtruck\");";           
   qv6.tooltip = GetVehicleDisplayName(towtruck);      
   qv7.command = "PlaceQuickVehicle(\"van\");";           
   qv7.tooltip = GetVehicleDisplayName(van);      
   qv8.command = "PlaceQuickVehicle(\"limo\");";           
   qv8.tooltip = GetVehicleDisplayName(limo);      
   qv9.command = "PlaceQuickVehicle(\"sedan\");";           
   qv9.tooltip = GetVehicleDisplayName(sedan);      
   qv10.command = "PlaceQuickVehicle(\"sportscar\");";           
   qv10.tooltip = GetVehicleDisplayName(sportscar);      
   qv11.command = "PlaceQuickVehicle(\"pickuptruck\");";           
   qv11.tooltip = GetVehicleDisplayName(pickuptruck);      
   qv12.command = "PlaceQuickVehicle(\"musclecar\");";           
   qv12.tooltip = GetVehicleDisplayName(musclecar);      
   qv13.command = "PlaceQuickVehicle(\"stationwagon\");";           
   qv13.tooltip = GetVehicleDisplayName(stationwagon);      
   qv14.command = "PlaceQuickVehicle(\"humvee\");";           
   qv14.tooltip = GetVehicleDisplayName(humvee);      
   qv15.command = "PlaceQuickVehicle(\"suv\");";           
   qv15.tooltip = GetVehicleDisplayName(suv);      
   qv17.command = "PlaceQuickVehicle(\"flatbedtruck\");";           
   qv17.tooltip = GetVehicleDisplayName(flatbedtruck);      
   qv18.command = "PlaceQuickVehicle(\"fireengine\");";           
   qv18.tooltip = GetVehicleDisplayName(fireengine);      
   qv19.command = "PlaceQuickVehicle(\"garbagetruck\");";           
   qv19.tooltip = GetVehicleDisplayName(garbagetruck);      
   qv20.command = "PlaceQuickVehicle(\"TrailerTruck\");";           
   qv20.tooltip = GetVehicleDisplayName(trailertruck);      
   qv21.command = "PlaceQuickVehicle(\"boxtruck\");";           
   qv21.tooltip = GetVehicleDisplayName(boxtruck);      
   qv22.command = "PlaceQuickVehicle(\"cargovan\");";           
   qv22.tooltip = GetVehicleDisplayName(cargovan);      
   qv23.command = "PlaceQuickVehicle(\"ambulance\");";           
   qv23.tooltip = GetVehicleDisplayName(ambulance);      
   qv24.command = "PlaceQuickVehicle(\"construction\");";           
   qv24.tooltip = GetVehicleDisplayName(construction);      
   qv25.command = "PlaceQuickVehicle(\"bus\");";           
   qv25.tooltip = GetVehicleDisplayName(bus);      
   
   for(%i=1;%i<=10;%i++)
   {
      %control = "qbslot" @ %i;
      %control.command = "DeletePlayerQuickVehicle(" @ %i @ ");";           
      %control.setBitmap(expandfilename("~/data/images/gui/grey.png"));   
      %control.vehicle = "";
   }
   for(%i=1;%i<=10;%i++)
   {
      %control = "eqbslot" @ %i;
      %control.command = "DeleteEnemyQuickVehicle(" @ %i @ ");";           
      %control.setBitmap(expandfilename("~/data/images/gui/grey.png"));   
      %control.vehicle = "";
   }
}

function PlaceQuickVehicle(%vehicle)
{
   if($QBPlacement $= "friendly")
   {

      for(%i=1;%i<=10;%i++)
      {
         %control = "qbslot" @ %i;

         if(%control.vehicle $= "")
         {
            %control.setBitmap(expandfilename("~/data/images/icons/" @ %vehicle @ ".png"));   
            $PlayerQuickVehicles[%i] = %vehicle;   
            %control.vehicle = true;
            alxPlay(goodbeep);
            return;
         }
      }
   }
   else
   {   

      for(%i=1;%i<=10;%i++)
      {
         %control = "eqbslot" @ %i;

         if(%control.vehicle $= "")
         {
            %control.setBitmap(expandfilename("~/data/images/icons/r_" @ %vehicle @ ".png"));   
            $EnemyQuickVehicles[%i] = %vehicle;   
            %control.vehicle = true;
            alxPlay(goodbeep);
            return;
         }
      }
   }
   
   // if there are no more slots left
   
   alxPlay(buzzer);
}

function DeletePlayerQuickVehicle(%slot)
{
   $PlayerquickVehicles[%slot] = "";
   %control = "qbslot" @ %slot;
   
   if(%control.vehicle $= "")
   {
      alxPlay(buzzer);
      return;
   }

   %control.setBitmap(expandfilename("~/data/images/gui/grey.png"));   
   %control.vehicle = "";
   alxPlay(goodbeep);
}

function DeleteEnemyQuickVehicle(%slot)
{
   $EnemyquickVehicles[%slot] = "";
   %control = "eqbslot" @ %slot;
   
   if(%control.vehicle $= "")
   {
      alxPlay(buzzer);
      return;
   }

   %control.setBitmap(expandfilename("~/data/images/gui/grey.png"));   
   %control.vehicle = "";
   alxPlay(goodbeep);
}

function ChangePlacing(%selection)
{
   echo("CHANGE PLACING");
   
   if(%selection $= "friendly")
   {
      qb1friendly.setProfile(GuiButton28Red);
      qb1enemy.SetProfile(GuiButton28FF);
      $QBPlacement = "friendly";
   }
   else   
   {
      qb1friendly.SetProfile(GuiButton28FF);
      qb1enemy.SetProfile(GuiButton28Red);
      $QBPlacement = "enemy";
   }
}

function ToQB2()
{
   for(%i=1;%i<=10;%i++)
   {
      %control = "qbslot" @ %i;

      if(%control.vehicle !$= "")
      {
         %player = true;
         break;
      }
   }

   for(%i=1;%i<=10;%i++)
   {
      %control = "eqbslot" @ %i;

      if(%control.vehicle !$= "")
      {
         %enemy = true;
         break;
      }
   }
   
   if(%player $= "" || %enemy $= "")
   {
      alxPlay(buzzer);
      return;
   }
   
   canvas.SetContent(quickbattle2);
}

function QuickBattle1::OnWake()
{
   GenerateQuickBattle();   
   alxStop($IntroSong);   
   qb1friendly.setProfile(Guibutton28Red);
   qb1enemy.setProfile(GuiButton28ff);
   InitQb1Desc();
   $QBPlacement = "friendly";
}
