function DropSupplies()
{
   canvas.popdialog(gangstats);
   canvas.pushdialog(DropSupplies);   
   Infowindow.Visible = false;   // in case they are coming from a supply search
}

function DropSupplies::OnWake()
{
   ShowSupplies();
   DisplayTutorial(DropSupplies);
}

function ShowSupplies()
{
   ds_ammo.setText($ammo);
   ds_fuel.setText($fuel);
   ds_guns.setText($guns);
   ds_medicine.setText($medicine);
   ds_spareparts.setText($spareparts);
   ds_tires.setText($tires);  
   ds_food.setText($food);
   ds_capacity.setText(GetCurrentSupplyCount() SPC "/" SPC GetTotalSupplyCapacity());   
   
   // clean drop ammounts
   
   dropped_spareparts.setText("0");
   dropped_ammo.setText("0");
   dropped_fuel.setText("0");
   dropped_guns.setText("0");
   dropped_medicine.setText("0");
   dropped_tires.setText("0");
   dropped_food.setText("0");
   
   // hide icons
   
   DropSupplies1.Visible = false;
   DropSupplies2.Visible = false;
   DropSupplies3.Visible = false;
}

function DropAmmo(%amount)
{
   if($ammo >= %amount)
   {
      DecreaseAmmo(%amount);
      %num = %amount;
   }
   else   
   {
      %num = $ammo;
      $ammo = 0;
   }
   
   %num = dropped_ammo.Text + %num;
   %num = SupplyFixNumber(%num);
   dropped_ammo.setText(%num);
   ShowDrop(ammo);   // so it will readjust buttons if needed
         
   UpdateSupplies();
}

function DropFuel(%amount)
{
   if($fuel >= %amount)
   {
      DecreaseFuel(%amount);
      %num = %amount;
   }
   else   
   {
      %num = $fuel;
      $fuel = 0;
   }
   
   dropped_fuel.setText(dropped_fuel.Text + %num);
      
   ShowDrop(fuel);   // so it will readjust buttons if needed
   UpdateSupplies();
}

function DropGuns(%amount)
{
   if($guns >= %amount)
   {
      DecreaseGuns(%amount);
      %num = %amount;
   }
   else   
   {
      %num = $guns;
      $guns = 0;
   }
   
   dropped_guns.setText(dropped_guns.Text + %num);
      
   ShowDrop(guns);   // so it will readjust buttons if needed
   UpdateSupplies();
}

function DropMedicine(%amount)
{
   if($medicine >= %amount)
   {
      DecreaseMedicine(%amount);
      %num = %amount;
   }
   else   
   {
      %num = $medicine;
      $medicine = 0;
   }
   
   ShowDrop(Medicine);   // so it will readjust buttons if needed
   dropped_medicine.setText(dropped_medicine.Text + %num);
      
   UpdateSupplies();
}

function DropSpareParts(%amount)
{
   if($spareparts >= %amount)
   {
      DecreaseSpareParts(%amount);
      %num = %amount;
   }
   else   
   {
      %num = $spareparts;
      $spareparts = 0;
   }
   
   ShowDrop(spareparts);   // so it will readjust buttons if needed
   dropped_spareparts.setText(dropped_spareparts.Text + %num);
      
   UpdateSupplies();
}

function DropTires(%amount)
{
   if($tires >= %amount)
   {
      DecreaseTires(%amount);
      %num = 10;
   }
   else   
   {
      %num = $tires;
      $tires = 0;
   }
   
   dropped_tires.setText(dropped_tires.Text + %num);
      
   ShowDrop(tires);   // so it will readjust buttons if needed
   UpdateSupplies();
}

function DropFood(%amount)
{
   if($food >= %amount)
   {
      DecreaseFood(%amount);
      %num = %amount;
   }
   else   
   {
      %num = $food;
      $food = 0;
   }
   
   dropped_food.setText(dropped_food.Text + %num);
   
   ShowDrop(Food);   // so it will readjust buttons if needed
   UpdateSupplies();
}

// show drop amounts

function ShowDrop(%item, %value)
{
   dropsupplies1.Visible = false;
   dropsupplies2.Visible = false;
   dropsupplies3.Visible = false;
   
   // value lets us know the player is actually clicking the button to call this. A second click will hide the drop buttons
      
   if(%value $= true)
   {
      if($ShowDrop $= %item)
      {
         $ShowDrop = "";
         return;         
      }
      else
         $ShowDrop = %item;
   }
   
   switch$ (%item)
   {
      case "ammo":            
         if($ammo == 0)
            return;

         %y = getWord(ds_ammo.getPosition(), 1);
            
         dropsupplies1.Visible = true;
         dropsupplies1.Command = "DropAmmo(50);";
         dropsupplies1.setPosition(getWord(dropsupplies1.getPosition(), 0), %y);
         dropsupplies1.ToolTip = "Drop 50 Ammo";
      
         if($ammo >= 100)
         {
            dropsupplies2.Visible = true;
            dropsupplies2.Command = "DropAmmo(100);";
            dropsupplies2.setPosition(getWord(dropsupplies2.getPosition(), 0), %y);
            dropsupplies2.ToolTip = "Drop 100 Ammo";
         }
         if($ammo >= 500)
         {
            dropsupplies3.Visible = true;
            dropsupplies3.Command = "DropAmmo(500);";
            dropsupplies3.setPosition(getWord(dropsupplies3.getPosition(), 0), %y);
            dropsupplies3.ToolTip = "Drop 500 Ammo";
         }         
                           
      case "food":
         if($food == 0)
            return;

         %y = getWord(ds_food.getPosition(), 1);
            
         dropsupplies1.Visible = true;
         dropsupplies1.Command = "DropFood(50);";
         dropsupplies1.setPosition(getWord(dropsupplies1.getPosition(), 0), %y);
         dropsupplies1.ToolTip = "Drop 50 Food";
      
         if($food >= 100)
         {
            dropsupplies2.Visible = true;
            dropsupplies2.Command = "DropFood(100);";
            dropsupplies2.setPosition(getWord(dropsupplies2.getPosition(), 0), %y);
            dropsupplies2.ToolTip = "Drop 100 Food";
         }
         if($food >= 500)
         {
            dropsupplies3.Visible = true;
            dropsupplies3.Command = "DropFood(200);";
            dropsupplies3.setPosition(getWord(dropsupplies3.getPosition(), 0), %y);
            dropsupplies3.ToolTip = "Drop 200 Food";
         }         
      
      case "fuel":
         if($fuel == 0)
            return;

         %y = getWord(ds_fuel.getPosition(), 1);
            
         dropsupplies1.Visible = true;
         dropsupplies1.Command = "DropFuel(50);";
         dropsupplies1.setPosition(getWord(dropsupplies1.getPosition(), 0), %y);
         dropsupplies1.ToolTip = "Drop 50 Fuel";
      
         if($fuel >= 100)
         {
            dropsupplies2.Visible = true;
            dropsupplies2.Command = "DropFuel(100);";
            dropsupplies2.setPosition(getWord(dropsupplies2.getPosition(), 0), %y);
            dropsupplies2.ToolTip = "Drop 100 Fuel";
         }
         if($fuel >= 500)
         {
            dropsupplies3.Visible = true;
            dropsupplies3.Command = "DropFuel(200);";
            dropsupplies3.setPosition(getWord(dropsupplies3.getPosition(), 0), %y);
            dropsupplies3.ToolTip = "Drop 200 Fuel";
         }         
      
      case "guns":
         if($guns == 0)
            return;

         %y = getWord(ds_guns.getPosition(), 1);
            
         dropsupplies1.Visible = true;
         dropsupplies1.Command = "DropGuns(10);";
         dropsupplies1.setPosition(getWord(dropsupplies1.getPosition(), 0), %y);
         dropsupplies1.ToolTip = "Drop 10 Guns";
      
         if($Guns >= 100)
         {
            dropsupplies2.Visible = true;
            dropsupplies2.Command = "DropGuns(30);";
            dropsupplies2.setPosition(getWord(dropsupplies2.getPosition(), 0), %y);
            dropsupplies2.ToolTip = "Drop 30 Guns";
         }
         if($Guns >= 500)
         {
            dropsupplies3.Visible = true;
            dropsupplies3.Command = "DropGuns(50);";
            dropsupplies3.setPosition(getWord(dropsupplies3.getPosition(), 0), %y);
            dropsupplies3.ToolTip = "Drop 50 Guns";
         }         
      
      case "medicine":
         if($medicine == 0)
            return;

         %y = getWord(ds_medicine.getPosition(), 1);
            
         dropsupplies1.Visible = true;
         dropsupplies1.Command = "DropMedicine(10);";
         dropsupplies1.setPosition(getWord(dropsupplies1.getPosition(), 0), %y);
         dropsupplies1.ToolTip = "Drop 10 Medicine";
      
         if($medicine >= 100)
         {
            dropsupplies2.Visible = true;
            dropsupplies2.Command = "DropMedicine(20);";
            dropsupplies2.setPosition(getWord(dropsupplies2.getPosition(), 0), %y);
            dropsupplies2.ToolTip = "Drop 20 Medicine";
         }
         if($medicine >= 500)
         {
            dropsupplies3.Visible = true;
            dropsupplies3.Command = "DropMedicine(30);";
            dropsupplies3.setPosition(getWord(dropsupplies3.getPosition(), 0), %y);
            dropsupplies3.ToolTip = "Drop 30 Medicine";
         }         
      
      case "spareparts":
         if($spareparts == 0)
            return;

         %y = getWord(ds_spareparts.getPosition(), 1);
            
         dropsupplies1.Visible = true;
         dropsupplies1.Command = "DropSpareParts(10);";
         dropsupplies1.setPosition(getWord(dropsupplies1.getPosition(), 0), %y);
         dropsupplies1.ToolTip = "Drop 10 Spare Parts";
      
         if($spareparts >= 100)
         {
            dropsupplies2.Visible = true;
            dropsupplies2.Command = "DropSpareParts(20);";
            dropsupplies2.setPosition(getWord(dropsupplies2.getPosition(), 0), %y);
            dropsupplies2.ToolTip = "Drop 20 Spare Parts";
         }
         if($spareparts >= 500)
         {
            dropsupplies3.Visible = true;
            dropsupplies3.Command = "DropSpareParts(50);";
            dropsupplies3.setPosition(getWord(dropsupplies3.getPosition(), 0), %y);
            dropsupplies3.ToolTip = "Drop 50 Spare Parts";
         }         
      
      case "tires":
         if($tires == 0)
            return;

         %y = getWord(ds_tires.getPosition(), 1);
            
         dropsupplies1.Visible = true;
         dropsupplies1.Command = "DropTires(10);";
         dropsupplies1.setPosition(getWord(dropsupplies1.getPosition(), 0), %y);
         dropsupplies1.ToolTip = "Drop 10 Tires";
      
         if($tires >= 100)
         {
            dropsupplies2.Visible = true;
            dropsupplies2.Command = "DropTires(20);";
            dropsupplies2.setPosition(getWord(dropsupplies2.getPosition(), 0), %y);
            dropsupplies2.ToolTip = "Drop 20 Tires";
         }
         if($Tires >= 500)
         {
            dropsupplies3.Visible = true;
            dropsupplies3.Command = "DropTires(50);";
            dropsupplies3.setPosition(getWord(dropsupplies3.getPosition(), 0), %y);
            dropsupplies3.ToolTip = "Drop 50 Tires";
         }         
   }
}

// add supplies ////////////////////////////////

function ds_AddAmmo()
{
   IncreaseAmmo(dropped_ammo.Text);
   dropped_ammo.setText(0);
         
   UpdateSupplies();
   ShowDrop(ammo);
}

function ds_AddFuel()
{
   IncreaseFuel(dropped_fuel.text);
   dropped_fuel.setText(0);
         
   UpdateSupplies();
   ShowDrop(fuel);
}

function ds_AddGuns()
{
   IncreaseGuns(dropped_guns.text);
   
   dropped_guns.setText(0);
         
   UpdateSupplies();
   ShowDrop(guns);
}

function ds_AddMedicine()
{
   IncreaseMedicine(dropped_medicine.text);
   
   dropped_medicine.setText(0);
         
   UpdateSupplies();
   ShowDrop(Medicine);
}

function ds_AddSpareParts()
{
   IncreaseSpareParts(dropped_spareparts.text);

   dropped_spareparts.setText(0);
         
   UpdateSupplies();
   ShowDrop(spareparts);
}

function ds_AddTires()
{
   IncreaseTires(dropped_tires.text);
   
   dropped_tires.setText(0);
         
   UpdateSupplies();
   ShowDrop(tires);
}

function ds_AddFood()
{
   IncreaseFood(dropped_food.text);
   
   dropped_food.setText(0);
         
   UpdateSupplies();
   ShowDrop(food);
}

// fixes the string length for display

function SupplyFixNumber(%num)
{
   if(%num <= 99)
      %string = "     " @ %num;      

   if(%num >= 100)
      %string = "    " @ %num;      
   
   return %string;   
}

function UpdateSupplies()
{
   ds_ammo.setText($ammo);
   ds_fuel.setText($fuel);
   ds_guns.setText($guns);
   ds_medicine.setText($medicine);
   ds_spareparts.setText($spareparts);
   ds_tires.setText($tires);  
   ds_food.setText($food);
   ds_capacity.setText(GetCurrentSupplyCount() SPC "/" SPC GetTotalSupplyCapacity());   
}

function dropsupplies::OnSleep()
{
   UpdateStatsBar();   
   $ShowDrop = "";
}