function InitQB3Desc()
{
   quickbattle3desc.setText("You can optionally tweak the configuration of each gang. If you select zero ammo or zero guns that gang will " @
   "have crossbows instead."); 
   
}

function GenerateQuickBattle3()
{
   // initiate values for controls
   
   // soldiers

   for(%i=1;%i<=10;%i++)
   {
      %control = "qbupgrade" @ %i;
      
      if(%control.vehicle !$= "")
      {
         %currentcapacity = GetVehiclePeopleCapacity(%control.vehicle);         
         %totalcapacity = %totalcapacity+%currentcapacity;                  
      }
   }
   
   friendly_soldiers.text = %totalcapacity;

   friendly_guns.text = %totalcapacity;
   
   friendly_ammo.text = 50;
   
   %totalcapacity = ""; // needs to be reset for next for loop
   for(%i=1;%i<=10;%i++)
   {
      %control = "eqbupgrade" @ %i;
      
      if(%control.vehicle !$= "")
      {
         %currentcapacity = GetVehiclePeopleCapacity(%control.vehicle);         
         %totalcapacity = %totalcapacity+%currentcapacity;                  
      }
   }
   
   enemy_soldiers.text = %totalcapacity;
      
   enemy_guns.text = %totalcapacity;
   
   enemy_ammo.text = 50;   
   
   // max soldier level
   
   friendly_maxsoldierlevel.text = "Mercenaries";
   enemy_maxsoldierlevel.text = "Soldiers";
   friendly_maxsoldierlevel.counter = 6;
   enemy_maxsoldierlevel.counter = 5;   
   
   friendly_formation.setText("Line");
   friendly_formation.formation = 2;
   Enemy_formation.setText("Random");
}

function DecSoldiers(%team)
{
   if(%team $= "friendly")
   {
      friendly_soldiers.text = friendly_soldiers.text-10;   

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

         if(%control.vehicle !$= "")
            %minsoldiers++;
      }
      
      if(friendly_soldiers.text < %minsoldiers)
         friendly_soldiers.text = %minsoldiers;
      
      if(friendly_guns.text > friendly_soldiers.text)
         friendly_guns.text = friendly_soldiers.text;
   }
   else
   {
      enemy_soldiers.text = enemy_soldiers.text-10;   
      
      for(%i=11;%i<=20;%i++)
      {
         %control = "qbupgrade" @ %i;

         if(%control.vehicle !$= "")
            %minsoldiers++;
      }
      
      if(enemy_soldiers.text < %minsoldiers)
         enemy_soldiers.text = %minsoldiers;

      if(enemy_guns.text > enemy_soldiers.text)
         enemy_guns.text = enemy_soldiers.text;
   }
}

function IncSoldiers(%team)
{
   if(%team $= "friendly")
   {
      friendly_soldiers.text = friendly_soldiers.text+10;   
      
      for(%i=1;%i<=10;%i++)
      {
         %control = "qbupgrade" @ %i;

         if(%control.vehicle !$= "")
         {
            %currentcapacity = GetVehiclePeopleCapacity(%control.vehicle);         
            %totalcapacity = %totalcapacity+%currentcapacity;                  
         }
      }
      
      if(friendly_soldiers.text > %totalcapacity)
         friendly_soldiers.text = %totalcapacity;
   }
   else
   {
      enemy_soldiers.text = enemy_soldiers.text+10;   

      for(%i=11;%i<=20;%i++)
      {
         %control = "qbupgrade" @ %i;

         if(%control.vehicle !$= "")
         {
            %currentcapacity = GetVehiclePeopleCapacity(%control.vehicle);         
            %totalcapacity = %totalcapacity+%currentcapacity;                  
         }
      }
      
      if(enemy_soldiers.text > %totalcapacity)
         enemy_soldiers.text = %totalcapacity;
   }
}

function IncSoldierLevel(%team)
{
   if(%team $= "friendly")
   {
      %counter = friendly_maxsoldierlevel.counter+1;

      if(%counter > 6)
         %counter = 6;

      friendly_maxsoldierlevel.counter = %counter;
      
      switch$ (%counter)
      {
         case 1:
            friendly_maxsoldierlevel.text = "Refuges";         
         case 2:
            friendly_maxsoldierlevel.text = "Brigands";                  
         case 3:
            friendly_maxsoldierlevel.text = "Militia";         
         case 4:
            friendly_maxsoldierlevel.text = "Police";         
         case 5:
            friendly_maxsoldierlevel.text = "Soldiers";         
         case 6:          
            friendly_maxsoldierlevel.text = "Mercenaries";                  
      }   
   }
   else
   {
      %counter = enemy_maxsoldierlevel.counter+1;
      
      if(%counter > 6)
         %counter = 6;

      enemy_maxsoldierlevel.counter = %counter;
         
      switch$ (%counter)
      {
         case 1:
            enemy_maxsoldierlevel.text = "Refuges";         
         case 2:
            enemy_maxsoldierlevel.text = "Brigands";                  
         case 3:
            enemy_maxsoldierlevel.text = "Militia";         
         case 4:
            enemy_maxsoldierlevel.text = "Police";         
         case 5:
            enemy_maxsoldierlevel.text = "Soldiers";         
         case 6:          
            enemy_maxsoldierlevel.text = "Mercenaries";                  
      }
   }   
}

function DecSoldierLevel(%team)
{
   if(%team $= "friendly")
   {
      %counter = friendly_maxsoldierlevel.counter-1;

      if(%counter < 1)
         %counter = 1;

      friendly_maxsoldierlevel.counter = %counter;
      
      switch$ (%counter)
      {
         case 1:
            friendly_maxsoldierlevel.text = "Refuges";         
         case 2:
            friendly_maxsoldierlevel.text = "Brigands";                  
         case 3:
            friendly_maxsoldierlevel.text = "Militia";         
         case 4:
            friendly_maxsoldierlevel.text = "Police";         
         case 5:
            friendly_maxsoldierlevel.text = "Soldiers";         
         case 6:          
            friendly_maxsoldierlevel.text = "Mercenaries";                  
      }   
   }
   else
   {
      %counter = enemy_maxsoldierlevel.counter-1;
      
      if(%counter < 1)
         %counter = 1;

      enemy_maxsoldierlevel.counter = %counter;
         
      switch$ (%counter)
      {
         case 1:
            enemy_maxsoldierlevel.text = "Refuges";         
         case 2:
            enemy_maxsoldierlevel.text = "Brigands";                  
         case 3:
            enemy_maxsoldierlevel.text = "Militia";         
         case 4:
            enemy_maxsoldierlevel.text = "Police";         
         case 5:
            enemy_maxsoldierlevel.text = "Soldiers";         
         case 6:          
            enemy_maxsoldierlevel.text = "Mercenaries";                  
      }
   }   
}

function DecGuns(%team)
{
   if(%team $= "friendly")
   {
      friendly_guns.text = friendly_guns.text-10;
      
      if(friendly_guns.text < 0)
         friendly_guns.text = 0;      
   }
   else
   {
      enemy_guns.text = enemy_guns.text-10;
      
      if(enemy_guns.text < 0)
         enemy_guns.text = 0;      
   }
}

function IncGuns(%team)
{
   if(%team $= "friendly")
   {
      friendly_guns.text = friendly_guns.text+10;
      
      if(friendly_guns.text > friendly_soldiers.text)
         friendly_guns.text = friendly_soldiers.text;      
   }
   else
   {
      enemy_guns.text = enemy_guns.text+10;
      
      if(enemy_guns.text > enemy_soldiers.text)
         enemy_guns.text = enemy_soldiers.text;      
   }
}

function DecAmmo(%team)
{
   if(%team $= "friendly")
   {
      friendly_ammo.text = friendly_ammo.text-10;
      
      if(friendly_ammo.text < 0)
         friendly_ammo.text = 0;      
   }
   else
   {
      enemy_ammo.text = enemy_ammo.text-10;
      
      if(enemy_ammo.text < 0)
         enemy_ammo.text = 0;      
   }
}

function IncAmmo(%team)
{
   if(%team $= "friendly")
   {
      friendly_ammo.text = friendly_ammo.text+10;
      
      if(friendly_ammo.text > 300)
         friendly_ammo.text = 300;      
   }
   else
   {
      enemy_ammo.text = enemy_ammo.text+10;
      
      if(enemy_ammo.text > 300)
         enemy_ammo.text = 300;      
   }
}

function IncPlayerFormation()
{
   friendly_formation.formation++;
   
   if(friendly_formation.formation > 6)
      friendly_formation.formation = 6;      

   switch$(friendly_formation.formation)
   {
      case 1:
         friendly_formation.setText("Random");      
         friendly_formation.formation = 1;   
      case 2:
         friendly_formation.setText("Line");      
         friendly_formation.formation = 2;   
      case 3:
         friendly_formation.setText("Light First");      
         friendly_formation.formation = 3;   
      case 4:
         friendly_formation.setText("Heavy First");   
         friendly_formation.formation = 4;   
      case 5:
         friendly_formation.setText("Skirmish");      
         friendly_formation.formation = 5;   
      case 6:
         friendly_formation.setText("Box");      
         friendly_formation.formation = 6;   
   }
}

function DecPlayerFormation()
{
   friendly_formation.formation--;
   
   if(friendly_formation.formation < 1)
      friendly_formation.formation = 1;      

   switch$(friendly_formation.formation)
   {
      case 1:
         friendly_formation.setText("Random");      
         friendly_formation.formation = 1;
      case 2:
         friendly_formation.setText("Line");      
         friendly_formation.formation = 2;
      case 3:
         friendly_formation.setText("Light First");      
         friendly_formation.formation = 3;
      case 4:
         friendly_formation.setText("Heavy First");      
         friendly_formation.formation = 4;
      case 5:
         friendly_formation.setText("Skirmish");      
         friendly_formation.formation = 5;
      case 6:
         friendly_formation.setText("Box");      
         friendly_formation.formation = 6;
   }
}

function IncEnemyFormation()
{
   enemy_formation.formation++;

   if(enemy_formation.formation > 6)
      enemy_formation.formation = 6;      

   switch$(enemy_formation.formation)
   {
      case 1:
         enemy_formation.setText("Random");      
      case 2:
         enemy_formation.setText("Line");      
      case 3:
         enemy_formation.setText("Light First");      
      case 4:
         enemy_formation.setText("Heavy First");      
      case 5:
         enemy_formation.setText("Skirmish");      
      case 6:
         enemy_formation.setText("Box");      
   }
}

function DecEnemyFormation()
{
   enemy_formation.formation--;
   
   if(enemy_formation.formation < 1)
      enemy_formation.formation = 1;      

   switch$(enemy_formation.formation)
   {
      case 1:
         enemy_formation.setText("Random");      
      case 2:
         enemy_formation.setText("Line");      
      case 3:
         enemy_formation.setText("Light First");      
      case 4:
         enemy_formation.setText("Heavy First");      
      case 5:
         enemy_formation.setText("Skirmish");      
      case 6:
         enemy_formation.setText("Box");      
   }
}

function QuickBattleTerrain()
{
   %text = qb3terrain.text;
   
   switch$(%text)
   {
      case "country":
         qb3terrain.text = "City";
      case "City":
         qb3terrain.text = "Highway";
      case "Highway":
         qb3terrain.text = "Country";
   }
}

function quickbattle3::OnWake()
{
   GenerateQuickBattle3();   
   InitQB3Desc();
}
