// update the stats bar with the latest numbers

function UpdateStatsBar(%consumption)
{
   Food.text = $food;
   Guns.text = $guns;
   Ammo.text = $ammo;
   medicine.text = $medicine;
   tires.text = $tires;   
   Fuel.text = $fuel;
   
   %num = GetSparePartsNeeded();
   
   if(%num > 0)
   {
      DisplayTutorial(spareparts);
      spareparts.text = $spareparts SPC "/" SPC %num;         
   }
   else
      spareparts.text = $spareparts;   
   
   if(GetTotalNumPeople() < GetTotalPeopleCapacity() / 2)
   {
      currentPeople.setProfile(Gui28Red);
      currentpeople.text = GetTotalNumPeople();
   }
   else
   {
      currentpeople.text = GetTotalNumPeople();
      currentPeople.setProfile(Gui28Yellow);
   }
   
   totalPeople.text = "/" SPC GetTotalPeopleCapacity();

   capacity.text = GetCurrentSupplyCount() SPC "/" SPC GetTotalSupplyCapacity();
   
   if(%consumption !$= "") 
      fuelconsumption.text = %consumption; 
   else
      fuelconsumption.text = GetTotalFuelConsumption(); 
   
   Morale.text = $morale;
   Clock.text = $clock;
   
   if($UpgradePoints == 1)
      upgradetext.text = "Upgrade Point";
   else
      upgradetext.text = "Upgrade Points";
   
   upgradepoints.text = $UpgradePoints;
   
   numvehicles.text = GetNumVehicles();
      
   if($disease $= true)
      disease.Visible = true;
   else
      disease.Visible = false;
      
   if($starving $= true)
      Starving.Visible = true;
   else
      Starving.Visible = false;     
      
   UpdatePlayerVehicle();
   
   if($food < GetTotalNumPeople())
      food.setProfile(Gui28Red);
   else
      food.setProfile(Gui28Yellow);
      
   if($fuel < GetTotalFuelConsumption())
      fuel.setProfile(Gui28Red);
   else
      fuel.setProfile(Gui28Yellow);
      
   // if the player needs to repair but no spare parts let him know it
         
   for(%i=1;%i<=10;%i++)
   {               
      if($vehicles[%i, currentarmor] < $vehicles[%i, stockarmor])     
         %repair = true;
         
      if($vehicles[%i, currentenginehp] < $vehicles[%i, stockenginehp])             
         %repair = true;

      if($vehicles[%i, currenttirearmor] < $vehicles[%i, stocktirearmor])              
         %repair = true;

      if($vehicles[%i, currentgastankarmor] < $vehicles[%i, stockgastankarmor])
         %repair = true;

      if($vehicles[%i, currentmountedweaponhp] < $vehicles[%i, stockmountedweaponhp])
         %repair = true;

      if($vehicles[%i, currentramhp] < $vehicles[%i, stockramhp])
         %repair = true;

      if($vehicles[%i, currentwindowarmor] < $vehicles[%i, stockwindowarmor])
         %repair = true;

      if($vehicles[%i, currentvehiclehp] < $vehicles[%i, stockvehiclehp])
         %repair = true;
   }
   
   if(%repair $= true && $spareparts == 0)
      spareparts.setProfile(Gui28Red);
   else
      spareparts.setProfile(Gui28Yellow);   
}

function UpdateMainBarShortcuts()
{
   // shortcuts
   
   main_capturecity.ToolTip = "Shortcut is " @ $Keys_CaptureCity;
   main_gangstats.ToolTip = "Shortcut is " @ $keys_GangStats;
   main_healgang.tooltip = "Shortcut is " @ $keys_HealGang;
   main_map.ToolTip = "Shortcut is " @ $keys_Map;
   main_options.ToolTip = "Shortcut is " @ $keys_Options;
   main_peoplesearch.ToolTip = "Shortcut is " @ $keys_PeopleSearch;
   main_supplysearch.ToolTip = "Shortcut is " @ $keys_SupplySearch;
   main_vehiclesearch.ToolTip = "Shortcut is " @ $keys_VehicleSearch;
   main_upgrades.ToolTip = "Shortcut is " @ $keys_VehicleUpgrades;
   main_vehiclestats.ToolTip = "Shortcut is " @ $keys_VehicleStats;
}

// for the player icon

function UpdatePlayerVehicle()
{
   %largestTonnage = 0;

   for(%i=1;%i<=10;%i++)
   {
      %tonnage = GetSingleVehicleTonnage($vehicles[%i, vehicle]);
      
      if(%tonnage > %largestTonnage)
      {
         %largestTonnage = %tonnage;
         %slot = %i;         
      }
   }
   
   // if the tonnage is greater or equal to 7 it has to be a truck
         
   if(player.trailer $= "" && %largestTonnage >= 7)
   {
      %obj =    new t2dStaticSprite() {
                     canSaveDynamicFields = "1";
                     layer = 1;  // the vehicle is beneath the pause text
                     scenegraph = "sg";
                  };
      
      if($vehicles[%slot, vehicle] $= "trailertruck")
         %obj.mount(player, "0 1.5", 0, true, true, true, true);        
      else
         %obj.mount(player, "0 1.4", 0, true, true, true, true);        
      
      player.trailer = %obj;
   }
   
   player.trailer.visible = false;
   
   switch$ ($vehicles[%slot, vehicle])
   {
      case "dunebuggy":
         player.SetSize(4, 9);           
      case "bike":
         player.SetSize(3, 9);           
      case "jeep":
         player.SetSize(4, 9);           
      case "compact":
         player.SetSize(4, 9);           
      case "minivan":
         player.SetSize(4, 9);           
      case "towtruck":
         player.SetSize(4, 9);           
      case "van":
         player.SetSize(4, 9);           
      case "limo":
         player.SetSize(3, 10);           
      case "sedan":
         player.SetSize(4, 9);           
      case "sportscar":
         player.SetSize(4, 9);           
      case "pickuptruck":
         player.SetSize(4, 10);           
      case "musclecar":
         player.SetSize(5, 8);           
      case "stationwagon":
         player.SetSize(4, 9);           
      case "humvee":
         player.SetSize(5, 9);           
      case "suv":
         player.SetSize(4, 10);           
      case "flatbedtruck":
         player.trailer.SetImagemap("flatbedtrailer");
         player.trailer.visible = true;
         player.trailer.SetSize(6, 13);
         player.SetSize(4, 9);           
      case "trailertruck":
         player.trailer.SetImagemap("trailertrucktrailer");
         player.trailer.visible = true;
         player.trailer.SetSize(7, 11);
         player.SetSize(5, 10);           
      case "fireengine":
         player.SetSize(7, 12);           
      case "garbagetruck":
         player.SetSize(4, 10);           
      case "bus":
         player.SetSize(4, 10);           
      case "boxtruck":
         player.SetSize(4, 9);           
      case "cargovan":
         player.SetSize(4, 10);           
      case "ambulance":
         player.SetSize(5, 10);           
      case "construction":
         player.SetSize(6, 12);           
   }
   
   player.SetImageMap($vehicles[%slot, vehicle]);   
}

function MainMap::OnWake()
{
   if($combat $= "" && $peoplebattle $= "")
      UpdateStatsBar();
}