// gets the total number of supply units the gang can have

function GetTotalSupplyCapacity()
{
   // go through each vehicle, let's assume it won't be more then 50
   
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, vehicle] !$= "")
         %capacity = $vehicles[%i, supplycapacity]+%capacity;
   }
   
   return %capacity;
}

// used to define the orignal vehicle capacity

function GetVehicleSupplyCapacity(%vehicle)
{         
   switch$ (%vehicle)
   {
      case "dunebuggy":
         %capacity = 75;           
      case "bike":
         %capacity = 50;           
      case "jeep":
         %capacity = 70;           
      case "compact":
         %capacity = 80;           
      case "minivan":
         %capacity = 120;           
      case "towtruck":
         %capacity = 140;           
      case "van":
         %capacity = 220;           
      case "limo":
         %capacity = 200;           
      case "sedan":
         %capacity = 160;           
      case "sportscar":
         %capacity = 110;           
      case "pickuptruck":
         %capacity = 195;           
      case "musclecar":
         %capacity = 145;           
      case "stationwagon":
         %capacity = 180;           
      case "humvee":
         %capacity = 210;           
      case "suv":
         %capacity = 200;           
      case "flatbedtruck":
         %capacity = 400;           
      case "trailertruck":
         %capacity = 575;           
      case "fireengine":
         %capacity = 210;           
      case "garbagetruck":
         %capacity = 240;           
      case "bus":
         %capacity = 290;           
      case "boxtruck":
         %capacity = 300;           
      case "cargovan":
         %capacity = 210;           
      case "ambulance":
         %capacity = 170;           
      case "construction":
         %capacity = 120;                 
   }
   
   return %capacity;
}

// add up all the supplies the gang has in it's posession

function GetCurrentSupplyCount()
{
   %supplies = $food + $guns + $medicine + $tires + $spareparts + $fuel;
   
   %ammo = $ammo / 20;
   
   %ammo = mCeil(%ammo);
   
   return %supplies+%ammo;
}

function GetNumVehicles()
{
   for(%i=1;%i<=50;%i++)
   {
      if($vehicles[%i, vehicle] !$= "")
         %j++;      
   }
   
   return %j;   
}

// add up the weight of all the vehicles in the gang, used to see how many and what type of vehicles they can have

function GetVehicleTonnage()
{
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, vehicle] !$= "")
      {
         switch$ ($vehicles[%i, vehicle])
         {
            // light
            
            case "dunebuggy":
               %tonnage = GetSingleVehicleTonnage("dunebuggy");           
            case "bike":
               %tonnage = GetSingleVehicleTonnage("bike");           
            case "jeep":
               %tonnage = GetSingleVehicleTonnage("jeep");           
            
            // compact
            
            case "compact":
               %tonnage = GetSingleVehicleTonnage("compact");           
            case "minivan":
               %tonnage = GetSingleVehicleTonnage("minivan");           
            case "towtruck":
               %tonnage = GetSingleVehicleTonnage("towtruck");           
            
            // full size

            case "van":
               %tonnage = GetSingleVehicleTonnage("van");           
            case "limo":
               %tonnage = GetSingleVehicleTonnage("limo");           
            case "sedan":
               %tonnage = GetSingleVehicleTonnage("sedan");           
            case "sportscar":
               %tonnage = GetSingleVehicleTonnage("sportscar");           
            case "pickuptruck":
               %tonnage = GetSingleVehicleTonnage("pickuptruck");           
            case "musclecar":
               %tonnage = GetSingleVehicleTonnage("musclecar");           
            case "stationwagon":
               %tonnage = GetSingleVehicleTonnage("stationwagon");           
            case "humvee":
               %tonnage = GetSingleVehicleTonnage("humvee");           
            case "suv":
               %tonnage = GetSingleVehicleTonnage("suv");           
            
            
            // large

            case "flatbedtruck":
               %tonnage = GetSingleVehicleTonnage("flatbedtruck");           
            case "trailertruck":
               %tonnage = GetSingleVehicleTonnage("trailertruck");           
            case "fireengine":
               %tonnage = GetSingleVehicleTonnage("fireengine");           
            case "garbagetruck":
               %tonnage = GetSingleVehicleTonnage("garbagetruck");           
            case "bus":
               %tonnage = GetSingleVehicleTonnage("bus");           
            
            // special            
            
            case "boxtruck":
               %tonnage = GetSingleVehicleTonnage("boxtruck");           
            case "cargovan":
               %tonnage = GetSingleVehicleTonnage("cargevan");           
            case "ambulance":
               %tonnage = GetSingleVehicleTonnage("ambulance");           
            case "construction":
               %tonnage = GetSingleVehicleTonnage("construction");                       
         }
         
         %totaltonnage = %totaltonnage+%tonnage;
      }
   }
   
   return %totaltonnage;
}

// gets the tonnage value for a single vehicle

function GetSingleVehicleTonnage(%vehicle)
{
   switch$ (%vehicle)
   {
      case "dunebuggy":
         %tonnage = 1;           
      case "bike":
         %tonnage = ".5";           
      case "jeep":
         %tonnage = 1;           
      case "compact":
         %tonnage = 1;           
      case "minivan":
         %tonnage = 1;           
      case "towtruck":
         %tonnage = 2;           
      case "van":
         %tonnage = 2;           
      case "limo":
         %tonnage = 2;           
      case "sedan":
         %tonnage = 2;           
      case "sportscar":
         %tonnage = 1;           
      case "pickuptruck":
         %tonnage = 2;           
      case "musclecar":
         %tonnage = 2;           
      case "stationwagon":
         %tonnage = 2;           
      case "humvee":
         %tonnage = 3;           
      case "suv":
         %tonnage = 3;           
      case "flatbedtruck":
         %tonnage = 7;           
      case "trailertruck":
         %tonnage = 10;           
      case "fireengine":
         %tonnage = 5;           
      case "garbagetruck":
         %tonnage = 3;           
      case "bus":
         %tonnage = 6;           
      case "boxtruck":
         %tonnage = 3;           
      case "cargovan":
         %tonnage = 3;           
      case "ambulance":
         %tonnage = 3;           
      case "construction":
         %tonnage = 4;                 
   }
            
   return %tonnage;
}

// there will be a default tonnage, each mechanic will increase that number
// max of 5 mechanics but that may change

function GetMaxVehicleTonnage()
{
   %default = 20;
   
   %default = %default+CheckMechanicTonnage();
   
   return %default;         
   
}

// when the player finds a vehicle from a search
// if the top speed is changed here change it in the default top speed function below

function AddStockVehicle(%slot)
{
   // these values will be the same for all cars
   // if any is different they will be over ridden
   
   $vehicles[%slot, stockarmor] = 0;
   $vehicles[%slot, currentarmor] = 0;
   $vehicles[%slot, acceleration] = 0;
   $vehicles[%slot, brakes] = 0;
   $vehicles[%slot, steering] = 0;
   $vehicles[%slot, stocktirearmor] = 0;
   $vehicles[%slot, currenttirearmor] = 0;
   $vehicles[%slot, stockgastankarmor] = 0;
   $vehicles[%slot, currentgastankarmor] = 0;
   $vehicles[%slot, tireupgrade] = 0;
   $vehicles[%slot, badtires] = 0;
   $vehicles[%slot, currentwindowarmor] = 0;
   $vehicles[%slot, stockwindowarmor] = 0;
   $vehicles[%slot, currentramhp] = 0;
   $vehicles[%slot, stockramhp] = 0;
   $vehicles[%slot, topspeedlevel] = 0;
   $vehicles[%slot, capacitylevel] = 0;
   $vehicles[%slot, mountedweapon] = "";
   $vehicles[%slot, currentmountedweaponhp] = 0;
   $vehicles[%slot, stockmountedweaponhp] = 0;

   switch$ ($foundvehicle)
   {
      case "dunebuggy":
         $vehicles[%slot, vehicle] = "dunebuggy";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("dunebuggy");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("dunebuggy");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("dunebuggy");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("dunebuggy");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("dunebuggy");   
            
      case "bike":
         $vehicles[%slot, vehicle] = "bike";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("bike");
         $vehicles[%slot, tires] = 2;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("bike");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("bike");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("bike");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("bike");   

      case "jeep":
         $vehicles[%slot, vehicle] = "jeep";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("jeep");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("jeep");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("jeep");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("jeep");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("jeep");   
      
      case "compact":
         $vehicles[%slot, vehicle] = "compact";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("compact");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("compact");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("compact");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("compact");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("compact");   

      case "minivan":
         $vehicles[%slot, vehicle] = "minivan";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("minivan");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("minivan");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("minivan");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("minivan");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("minivan");   

      case "towtruck":
         $vehicles[%slot, vehicle] = "towtruck";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("towtruck");
         $vehicles[%slot, tires] = 6;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("towtruck");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("towtruck");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("towtruck");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("towtruck");   
     
      case "van":
         $vehicles[%slot, vehicle] = "van";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("van");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("van");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("van");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("van");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("van");   

      case "limo":
         $vehicles[%slot, vehicle] = "limo";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("limo");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("limo");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("limo");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("limo");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("limo");   

      case "sedan":
         $vehicles[%slot, vehicle] = "sedan";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("sedan");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("sedan");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("sedan");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("sedan");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("sedan");   

      case "sportscar":
         $vehicles[%slot, vehicle] = "sportscar";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("sportscar");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("sportscar");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("sportscar");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("sportscar");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("sportscar");   

      case "pickuptruck":
         $vehicles[%slot, vehicle] = "pickuptruck";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("pickuptruck");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("pickuptruck");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("pickuptruck");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("pickuptruck");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("pickuptruck");   

      case "musclecar":
         $vehicles[%slot, vehicle] = "musclecar";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("musclecar");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("musclecar");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("musclecar");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("musclecar");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("musclecar");   

      case "stationwagon":
         $vehicles[%slot, vehicle] = "stationwagon";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("stationwagon");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("stationwagon");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("stationwagon");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("stationwagon");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("stationwagon");   

      case "humvee":
         $vehicles[%slot, vehicle] = "humvee";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("humvee");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("humvee");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("humvee");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("humvee");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("humvee");   

      case "suv":
         $vehicles[%slot, vehicle] = "suv";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("suv");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("suv");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("suv");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("suv");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("suv");   
      
      case "flatbedtruck":
         $vehicles[%slot, vehicle] = "flatbedtruck";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("flatbedtruck");
         $vehicles[%slot, tires] = 14;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("flatbedtruck");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("flatbedtruck");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("flatbedtruck");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("flatbedtruck");   

      case "trailertruck":
         $vehicles[%slot, vehicle] = "trailertruck";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("trailertruck");
         $vehicles[%slot, tires] = 18;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("trailertruck");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("trailertruck");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("trailertruck");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("trailertruck");   

      case "fireengine":
         $vehicles[%slot, vehicle] = "fireengine";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("fireengine");
         $vehicles[%slot, tires] = 6;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("fireengine");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("fireengine");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("fireengine");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("fireengine");   

      case "garbagetruck":
         $vehicles[%slot, vehicle] = "garbagetruck";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("garbagetruck");
         $vehicles[%slot, tires] = 6;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("garbagetruck");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("garbagetruck");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("garbagetruck");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("garbagetruck");   

      case "bus":
         $vehicles[%slot, vehicle] = "bus";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("bus");
         $vehicles[%slot, tires] = 10;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("bus");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("bus");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("bus");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("bus");   
      
      case "boxtruck":
         $vehicles[%slot, vehicle] = "boxtruck";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("boxtruck");
         $vehicles[%slot, tires] = 6;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("boxtruck");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("boxtruck");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("boxtruck");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("boxtruck");   

      case "cargovan":
         $vehicles[%slot, vehicle] = "cargovan";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("cargovan");
         $vehicles[%slot, tires] = 6;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("cargovan");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("cargovan");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("cargovan");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("cargovan");   

      case "ambulance":
         $vehicles[%slot, vehicle] = "ambulance";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("ambulance");
         $vehicles[%slot, tires] = 4;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("ambulance");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("ambulance");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("ambulance");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("ambulance");   

      case "construction":
         $vehicles[%slot, vehicle] = "construction";
         $vehicles[%slot, topspeed] = GetVehicleTopSpeed("construction");
         $vehicles[%slot, tires] = 6;
         $vehicles[%slot, supplycapacity] = GetVehicleSupplyCapacity($vehicles[%slot, vehicle]);
         $vehicles[%slot, currentvehiclehp] = GetStockVehicleHitPoints("construction");
         $vehicles[%slot, stockvehiclehp] = GetStockVehicleHitPoints("construction");
         $vehicles[%slot, stockenginehp] = GetStockEngineHitPoints("construction");   
         $vehicles[%slot, currentenginehp] = GetStockEngineHitPoints("construction");   
   }
   
   if($DamagedVehicle $= true)
      AddDamageToStockVehicle(%slot);   
   
   UpdateStatsBar();
}

// when the gang finds a vehicle there is a small chance it will come with damage

function AddDamageToStockVehicle(%slot)
{
   %damagetires = getRandom(1, 4);
   $vehicles[%slot, badtires] = $vehicles[%slot, badtires]+%damagetires;
   
   if($vehicles[%slot, badtires] > $vehicles[%slot, tires])
      $vehicles[%slot, badtires] = $vehicles[%slot, tires];      

   %damage = getRandom(3, 20);
   
   $vehicles[%slot, currentvehiclehp] = $vehicles[%slot, currentvehiclehp]-%damage;
   
   // this will only really effect smaller vehicles, if it's a motorcycle, not a big deal
            
   if($vehicles[%slot, currentvehiclehp] <= 0)
      $vehicles[%slot, currentvehiclehp] = 5;         

   %damage = getRandom(10, 30);

   $vehicles[%slot, currentenginehp] = $vehicles[%slot, currentenginehp]-%damage;   
   
   if($vehicles[%slot, currentenginehp] <= 0)
      $vehicles[%slot, currentenginehp] = 10;         
}

// this will be used by both player and enemy

function GetStockVehicleHitPoints(%vehiclename)
{
   switch$ (%vehiclename)
   {
      case "dunebuggy":
         return 15;   
      case "bike":
         return 10;
      case "jeep":
         return 15;
      case "compact":
         return 15;
      case "minivan":
         return 20;
      case "towtruck":
         return 35;
      case "van":
         return 30;
      case "limo":
         return 40;
      case "sedan":
         return 35;
      case "sportscar":
         return 20;
      case "pickuptruck":
         return 30;
      case "musclecar":
         return 30;
      case "stationwagon":
         return 30;
      case "humvee":
         return 40;
      case "suv":
         return 40;
      case "flatbedtruck":
         return 55;
      case "trailertruck":
         return 60;
      case "fireengine":
         return 50;
      case "garbagetruck":
         return 45;
      case "bus":
         return 50;
      case "boxtruck":
         return 45;
      case "cargovan":
         return 35;
      case "ambulance":
         return 40;
      case "construction":
         return 45;         
   }
}

// the health bar is 5 units long so depending on the vehicle X amount of hitpoints lost will be needed
// to shrink the bar 1 unit

function GetHealthBarConversion(%vehiclename)
{
   switch$ (%vehiclename)
   {
      case "dunebuggy":
         return 2;   
      case "bike":
         return 1;
      case "jeep":
         return 2;
      case "compact":
         return 3;
      case "minivan":
         return 4;
      case "towtruck":
         return 6;
      case "van":
         return 7;
      case "limo":
         return 8;
      case "sedan":
         return 7;
      case "sportscar":
         return 3;
      case "pickuptruck":
         return 7;
      case "musclecar":
         return 6;
      case "stationwagon":
         return 5;
      case "humvee":
         return 11;
      case "suv":
         return 10;
      case "flatbedtruck":
         return 16;
      case "trailertruck":
         return 20;
      case "fireengine":
         return 10;
      case "garbagetruck":
         return 7;
      case "bus":
         return 10;
      case "boxtruck":
         return 8;
      case "cargovan":
         return 7;
      case "ambulance":
         return 9;
      case "construction":
         return 6;         
   }
}

// this function will be used by both player and enemy so it only needs to be changed in 1 place
// NOTE - IF YOU CHANGE THE VEHICLE CAPACITY HERE CHANGE IT IN GET SEATING CAPACITY FUNCTION

function GetVehiclePeopleCapacity(%vehiclename)
{
   switch$ (%vehiclename)
   {
      case "dunebuggy":
         return 5;   
      case "bike":
         return 2;
      case "jeep":
         return 4;
      case "compact":
         return 5;
      case "minivan":
         return 6;
      case "towtruck":
         return 9;
      case "van":
         return 9;
      case "limo":
         return 12;
      case "sedan":
         return 6;
      case "sportscar":
         return 4;
      case "pickuptruck":
         return 9;
      case "musclecar":
         return 5;
      case "stationwagon":
         return 6;
      case "humvee":
         return 8;
      case "suv":
         return 8;
      case "flatbedtruck":
         return 40;
      case "trailertruck":
         return 45;
      case "fireengine":
         return 18;
      case "garbagetruck":
         return 14;
      case "bus":
         return 30;
      case "boxtruck":
         return 22;
      case "cargovan":
         return 18;
      case "ambulance":
         return 9;
      case "construction":
         return 14;         
   }
}

// bike and side car will not be listed here since they have no sides
// this will determine how many people can fire out of that side of the vehicle

function GetVehicleFiringCapacity(%vehicle, %side)
{
   switch$ (%vehicle)
   {
      case "bike":
         if(%side $= "front")
            return 1;
         if(%side $= "back")
            return 1;
         if(%side $= "right")
            return 1;
         if(%side $= "left")
            return 1;

      case "jeep":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 2;
         if(%side $= "left")
            return 2;

      case "dunebuggy":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 2;
         if(%side $= "left")
            return 2;
      
      case "compact":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 2;
         if(%side $= "left")
            return 2;

      case "minivan":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 2;
         if(%side $= "left")
            return 2;

      case "towtruck":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 3;
         if(%side $= "left")
            return 3;
      
      case "van":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 3;
         if(%side $= "left")
            return 3;

      case "limo":
         if(%side $= "front")
            return 3;
         if(%side $= "back")
            return 3;
         if(%side $= "right")
            return 3;
         if(%side $= "left")
            return 3;

      case "sedan":
         if(%side $= "front")
            return 1;
         if(%side $= "back")
            return 1;
         if(%side $= "right")
            return 2;
         if(%side $= "left")
            return 2;

      case "sportscar":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 2;
         if(%side $= "left")
            return 2;

      case "pickuptruck":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 3;
         if(%side $= "left")
            return 3;

      case "musclecar":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 2;
         if(%side $= "left")
            return 2;

      case "stationwagon":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 3;
         if(%side $= "left")
            return 3;

      case "humvee":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 2;
         if(%side $= "left")
            return 2;

      case "suv":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 3;
         if(%side $= "left")
            return 3;
      
      case "flatbedtruck":
         if(%side $= "front")
            return 5;
         if(%side $= "back")
            return 10;
         if(%side $= "right")
            return 15;
         if(%side $= "left")
            return 15;

      case "trailertruck":
         if(%side $= "front")
            return 5;
         if(%side $= "back")
            return 10;
         if(%side $= "right")
            return 15;
         if(%side $= "left")
            return 15;

      case "fireengine":
         if(%side $= "front")
            return 3;
         if(%side $= "back")
            return 3;
         if(%side $= "right")
            return 8;
         if(%side $= "left")
            return 8;

      case "garbagetruck":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 3;
         if(%side $= "right")
            return 6;
         if(%side $= "left")
            return 6;

      case "bus":
         if(%side $= "front")
            return 5;
         if(%side $= "back")
            return 5;
         if(%side $= "right")
            return 12;
         if(%side $= "left")
            return 12;
      
      case "boxtruck":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 8;
         if(%side $= "right")
            return 8;
         if(%side $= "left")
            return 2;

      case "cargovan":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 3;
         if(%side $= "right")
            return 10;
         if(%side $= "left")
            return 10;

      case "ambulance":
         if(%side $= "front")
            return 2;
         if(%side $= "back")
            return 2;
         if(%side $= "right")
            return 4;
         if(%side $= "left")
            return 4;

      case "construction":
         if(%side $= "front")
            return 1;
         if(%side $= "back")
            return 1;
         if(%side $= "right")
            return 1;
         if(%side $= "left")
            return 1;
   }
}
// total fuel consumption for the gang when traveling

function GetTotalFuelConsumption()
{
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, vehicle] !$= "")
      {
         %consumption = GetVehicleFuelConsumption($vehicles[%i, vehicle]);
         
         %totalconsumption = %totalconsumption+%consumption;
      }
   }
   
   return %totalconsumption;
}

// get fuel consumption for 1 vehicle for stats screen

function GetVehicleFuelConsumption(%vehicle)
{
   switch$ (%vehicle)
   {
      case "dunebuggy":
         %consumption = 2;
      case "bike":
         %consumption = 1;
      case "jeep":
         %consumption = 1;
      case "compact":
         %consumption = 1;
      case "minivan":
         %consumption = 2;
      case "towtruck":
         %consumption = 4;
      case "van":
         %consumption = 4;
      case "limo":
         %consumption = 5;
      case "sedan":
         %consumption = 5;
      case "sportscar":
         %consumption = 6;
      case "pickuptruck":
         %consumption = 7;
      case "musclecar":
         %consumption = 6;
      case "stationwagon":
         %consumption = 4;
      case "humvee":
         %consumption = 8;
      case "suv":
         %consumption = 8;
      case "flatbedtruck":
         %consumption = 10;
      case "trailertruck":
         %consumption = 12;
      case "fireengine":
         %consumption = 8;
      case "garbagetruck":
         %consumption = 6;
      case "bus":
         %consumption = 9;
      case "boxtruck":
         %consumption = 6;
      case "cargovan":
         %consumption = 7;
      case "ambulance":
         %consumption = 7;
      case "construction":
         %consumption = 7;
   }         
   
   %supplies = GetCurrentSupplyCount();
       
   %total = GetTotalSupplyCapacity();
   
   %half = %total / 2;
   
   if(%supplies > %half)
      %consumption++;
    
   return %consumption;
}

// used in the config code
// if top speed is changed here change it in the default vehicle function up above

function GetVehicleTopSpeed(%vehicle)
{
   switch$ (%vehicle)
   {
      case "dunebuggy":
         return 60;

      case "bike":
         return 90;

      case "jeep":
         return 50;
      
      case "compact":
         return 50;

      case "minivan":
         return 70;

      case "towtruck":
         return 50;
      
      case "van":
         return 70;

      case "limo":
         return 80;

      case "sedan":
         return 70;

      case "sportscar":
         return 100;

      case "pickuptruck":
         return 70;

      case "musclecar":
         return 100;

      case "stationwagon":
         return 60;

      case "humvee":
         return 70;

      case "suv":
         return 70;
      
      case "flatbedtruck":
         return 70;

      case "trailertruck":
         return 70;

      case "fireengine":
         return 70;

      case "garbagetruck":
         return 50;

      case "bus":
         return 60;
      
      case "boxtruck":
         return 70;

      case "cargovan":
         return 70;

      case "ambulance":
         return 80;

      case "construction":
         return 50;
   }   
}

function GetVehicleCruiseSpeed(%id)
{
   %num = %id.topspeed / 2;
   
   switch$ (%num)
   {
      case 15:
         %num = 20;      
      case 25:
         %num = 30;            
      case 35:
         %num = 40;            
      case 45:
         %num = 50;            
      case 55:
         %num = 60;            
      case 65:
         %num = 70;            
      case 75:
         %num = 80;            
      case 85:      
         %num = 90;      
   }

   return %num;   
}

// used for enemy setup

function GetGangUpgradePoints()
{
  // get points for all available upgrades
   
   for(%slot=1;%slot<=20;%slot++)
   {
      if($vehicles[%slot, vehicle] !$= "")
      {
         %points = GetPointCost($vehicles[%slot, vehicle], armor)*$vehicles[%slot, stockarmor];
         $points = $points+%points;
         
         %points = GetPointCost($vehicles[%slot, vehicle], tireupgrade)*$vehicles[%slot, tireupgrade];
         $points = $points+%points;

         %points = GetPointCost($vehicles[%slot, vehicle], brakes)*$vehicles[%slot, brakes];
         $points = $points+%points;

         %points = GetPointCost($vehicles[%slot, vehicle], acceleration)*$vehicles[%slot, acceleration];
         $points = $points+%points;

         %points = GetPointCost($vehicles[%slot, vehicle], turning)*$vehicles[%slot, steering];
         $points = $points+%points;

         %points = GetPointCost($vehicles[%slot, vehicle], tirearmor)*$vehicles[%slot, currenttirearmor];
         $points = $points+%points;

         %points = GetPointCost($vehicles[%slot, vehicle], gastankarmor)*$vehicles[%slot, gastankarmor];
         $points = $points+%points;

         %points = GetPointCost($vehicles[%slot, vehicle], $vehicles[%slot, mountedweapon])*$vehicles[%slot, mountedweapon];
         $points = $points+%points;

         %points = GetPointCost($vehicles[%slot, vehicle], ram)*$vehicles[%slot, ram];
         $points = $points+%points;

         %points = GetPointCost($vehicles[%slot, vehicle], windowarmor)*$vehicles[%slot, windowarmor];
         $points = $points+%points;
      }
   }
}

// remove a vehicle either by dropping it, combat, etc

function RemoveVehicle(%slot)
{
   $vehicles[%slot, vehicle] = "";
   $vehicles[%slot, tires] = "";
   $vehicles[%slot, topspeed] = "";
   $vehicles[%slot, stockarmor] = "";
   $vehicles[%slot, currentarmor] = "";
   $vehicles[%slot, acceleration] = "";
   $vehicles[%slot, brakes] = "";
   $vehicles[%slot, badtires] = "";
   $vehicles[%slot, steering] = "";
   $vehicles[%slot, stocktirearmor] = "";
   $vehicles[%slot, currenttirearmor] = "";
   $vehicles[%slot, stockgastankarmor] = "";
   $vehicles[%slot, currentgastankarmor] = "";
   $vehicles[%slot, tireupgrade] = "";
   $vehicles[%slot, currentwindowarmor] = "";
   $vehicles[%slot, stockwindowarmor] = "";
   $vehicles[%slot, currentramhp] = "";
   $vehicles[%slot, stockramhp] = "";
   $vehicles[%slot, currentvehiclehp] = "";
   $vehicles[%slot, stockvehiclehp] = "";
   $vehicles[%slot, supplycapacity] = "";
   $vehicles[%slot, stockenginehp] = "";
   $vehicles[%slot, currentenginehp] = "";
   
   CheckPersonnelCapacity();  
   
   CheckSupplyCapacity();
      
   UpdateStatsBar();
}

// this gets called after a vehicle is removed, if the gang has more people then capacity some have to be let go!

function CheckPersonnelCapacity()
{
   %people = GetTotalnumPeople();
   
   %capacity = GetTotalPeopleCapacity();
   
   if(%people > %capacity)
   {
      %num = %people-%capacity;
      
      // zero everthing out for the report
      
      %refuges = 0;
      %brigands = 0;
      %militia = 0;
      %police = 0;
      %soldiers = 0;
      %mercenaries = 0;
      
      while(%num !$= 0)
      {
         %rand = getRandom(1, 6);
         
         switch$ (%rand)
         {
            case 1:
               if($refuges > 0)
               {
                  $refuges--;
                  %refuges++;
                  %num--;     
               }
            case 2:
               if($Brigands > 0)
               {
                  $Brigands--;
                  %brigands++;
                  %num--;
               }               
            case 3:
               if($Militia > 0)
               {
                  $Militia--;
                  %militia++;
                  %num--;
               }
            case 4:
               if($Police > 0)
               {
                  $Police--;
                  %police++;
                  %num--;
               }
            case 5:
               if($Soldiers > 0)
               {
                  $Soldiers--;
                  %soldiers++;
                  %num--;
               }
            case 6:
               if($Mercenaries > 0)
               {
                  $Mercenaries--;
                  %mercenaries++;
                  %num--;
               }
         }
      }
   
      // display the report
      
      Infowindow.Visible = true;
      InfoYesbutton.Visible = false;
      InfoNobutton.Visible = false;
      Infocontinuebutton.Visible = true;
      Infocontinuebutton.command = "Infowindow.Visible = false;";   

      Infotext.setText("");
      Infotext.AddText("*You have more gang members than capacity! You lost - *\n\n", true);
      Infotext.AddText("Refuges - " @ %refuges @ "\n", true);
      Infotext.AddText("Brigands - " @ %brigands @ "\n", true);
      Infotext.AddText("Militia - " @ %militia @ "\n", true);
      Infotext.AddText("Police - " @ %police @ "\n", true);
      Infotext.AddText("Soldiers - " @ %soldiers @ "\n", true);
      Infotext.AddText("Mercenaries - " @ %mercenaries @ "\n", true);   
      
      UpdateStatsBar();         
   }
}

//////////////////////////////////////////////////////////////////////////////////////////////
// repair
// The gang can replace X amount of parts after a battle and X amount per hours, if they have a mechanic
// they can replace more parts
//////////////////////////////////////////////////////////////////////////////////////////////

// NOTE - 1 spare part to fix 5 points of damage, remember to change that number throughout the function
// if a system has less then 5 points of damage it stil requires 1 spare part

function Repair()
{
   // see if anything needs repairing
   
   $maxparts = 1+CheckMechanic();  // maxparts is how many can be replaced in 1 day
      
   // pick a vehicle at random and run the spare parts down to zero
   
   while($spareparts > 0 && $maxparts > 0)
   {
      %loop++;
      
      %i = getRandom(1, 10);
               
      if($vehicles[%i, vehicle] !$= "")
      {
         if($vehicles[%i, currentarmor] < $vehicles[%i, stockarmor])     
         {
            PartialRepair(%i, armor);
            %repair = true;
         }
            
         if($vehicles[%i, currentenginehp] < $vehicles[%i, stockenginehp])             
         {
            PartialRepair(%i, engine);
            %repair = true;
         }

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

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

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

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

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

         if($vehicles[%i, currentvehiclehp] < $vehicles[%i, stockvehiclehp])
         {
            PartialRepair(%i, vehicle);
            %repair = true;
         }
      }
      
      // to prevent it from going on forever      
      if(%loop == 300)
         break;
   }
   
   if(%repair $= true)
      PromoteMechanic();
         
   UpdateStatsBar();   
}

// used in repair function
// the flag is used from trading in upgrade points

function PartialRepair(%slot, %area)
{
   if(CheckMechanic() > 0)
      %points = 15;
   else
      %points = 10;
      
   switch$ (%area)
   {
      case "armor":     
         while ($spareparts > 0 && $maxparts > 0)
         {
            DecreaseSpareParts(1);
            $maxparts--;

            $vehicles[%slot, currentarmor] = $vehicles[%slot, currentarmor]+%points;
            
            if($vehicles[%slot, currentarmor] > $vehicles[%slot, stockarmor])            
            {
               $vehicles[%slot, currentarmor] = $vehicles[%slot, stockarmor];
               break;
            }               
         }
            
      case "engine":             
         while ($spareparts > 0 && $maxparts > 0)
         {
            DecreaseSpareParts(1);
            $maxparts--;

            $vehicles[%slot, currentenginehp] = $vehicles[%slot, currentenginehp]+%points;
            
            if($vehicles[%slot, currentenginehp] > $vehicles[%slot, stockenginehp])            
            {
               $vehicles[%slot, currentenginehp] = $vehicles[%slot, stockenginehp];
               break;
            }               
         }
      case "tirearmor":              
         while ($spareparts > 0 && $maxparts > 0)
         {
            DecreaseSpareParts(1);
            $maxparts--;

            $vehicles[%slot, currenttirearmor] = $vehicles[%slot, currenttirearmor]+%points;
            
            if($vehicles[%slot, currenttirearmor] > $vehicles[%slot, stocktirearmor])            
            {
               $vehicles[%slot, currenttirearmor] = $vehicles[%slot, stocktirearmor];
               break;
            }               
         }

      case "gastankarmor":
         while ($spareparts > 0 && $maxparts > 0)
         {
            DecreaseSpareParts(1);
            $maxparts--;

            $vehicles[%slot, currentgastankarmor] = $vehicles[%slot, currentgastankarmor]+%points;
            
            if($vehicles[%slot, currentgastankarmor] > $vehicles[%slot, stockgastankarmor])            
            {
               $vehicles[%slot, currentgastankarmor] = $vehicles[%slot, stockgastankarmor];
               break;
            }               
         }

      case "mountedweapon":
         while ($spareparts > 0 && $maxparts > 0)
         {
            DecreaseSpareParts(1);
            $maxparts--;

            $vehicles[%slot, currentmountedweaponhp] = $vehicles[%slot, currentmountedweaponhp]+%points;
            
            if($vehicles[%slot, currentmountedweaponhp] > $vehicles[%slot, stockmountedweaponhp])            
            {
               $vehicles[%slot, currentmountedweaponhp] = $vehicles[%slot, stockmountedweaponhp];
               break;
            }               
         }

      case "ram":
         while ($spareparts > 0 && $maxparts > 0)
         {
            DecreaseSpareParts(1);
            $maxparts--;

            $vehicles[%slot, currentramhp] = $vehicles[%slot, currentramhp]+%points;
            
            if($vehicles[%slot, currentramhp] > $vehicles[%slot, stockramhp])            
            {
               $vehicles[%slot, currentramhp] = $vehicles[%slot, stockramhp];
               break;
            }               
         }

      case "windowarmor":
         while ($spareparts > 0 && $maxparts > 0)
         {
            DecreaseSpareParts(1);
            $maxparts--;

            $vehicles[%slot, currentwindowarmor] = $vehicles[%slot, currentwindowarmor]+%points;
            
            if($vehicles[%slot, currentwindowarmor] > $vehicles[%slot, stockwindowarmor])            
            {
               $vehicles[%slot, currentwindowarmor] = $vehicles[%slot, stockwindowarmor];
               break;
            }               
         }

      case "vehicle":
         while ($spareparts > 0 && $maxparts > 0)
         {
            DecreaseSpareParts(1);
            $maxparts--;

            $vehicles[%slot, currentvehiclehp] = $vehicles[%slot, currentvehiclehp]+%points;
            
            if($vehicles[%slot, currentvehiclehp] > $vehicles[%slot, stockvehiclehp])            
            {
               $vehicles[%slot, currentvehiclehp] = $vehicles[%slot, stockvehiclehp];
               break;
            }               
         }
   }   
}

// this will tell the player how many spare parts are needed to repair damage

function GetSparePartsNeeded()
{
   if(CheckMechanic() > 0)
      %points = 15;
   else
      %points = 10;

   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, vehicle] !$= "")
      {
         if($vehicles[%i, currentarmor] < $vehicles[%i, stockarmor])     
         {
            %difference = $vehicles[%i, stockarmor] - $vehicles[%i, currentarmor];
            
            while(%difference > 0)
            {
               %difference = %difference-%points;
               %counter++;
            }
         }
            
         if($vehicles[%i, currentenginehp] < $vehicles[%i, stockenginehp])             
         {
            %difference = $vehicles[%i, stockenginehp] - $vehicles[%i, currentenginehp];
            
            while(%difference > 0)
            {
               %difference = %difference-%points;
               %counter++;
            }

         }

         if($vehicles[%i, currenttirearmor] < $vehicles[%i, stocktirearmor])              
         {
            %difference = $vehicles[%i, stocktirearmor] - $vehicles[%i, currenttirearmor];
            
            while(%difference > 0)
            {
               %difference = %difference-%points;
               %counter++;
            }

         }

         if($vehicles[%i, currentgastankarmor] < $vehicles[%i, stockgastankarmor])
         {
            %difference = $vehicles[%i, stockgastankarmor] - $vehicles[%i, currentgastankarmor];
            
            while(%difference > 0)
            {
               %difference = %difference-%points;
               %counter++;
            }

         }

         if($vehicles[%i, currentmountedweaponhp] < $vehicles[%i, stockmountedweaponhp])
         {
            %difference = $vehicles[%i, stockmountedweaponhp] - $vehicles[%i, currentmountedweaponhp];
            
            while(%difference > 0)
            {
               %difference = %difference-%points;
               %counter++;
            }

         }

         if($vehicles[%i, currentramhp] < $vehicles[%i, stockramhp])
         {
            %difference = $vehicles[%i, stockramhp] - $vehicles[%i, currentramhp];
            
            while(%difference > 0)
            {
               %difference = %difference-%points;
               %counter++;
            }

         }

         if($vehicles[%i, currentwindowarmor] < $vehicles[%i, stockwindowarmor])
         {         
            %difference = $vehicles[%i, stockwindowarmor] - $vehicles[%i, currentwindowarmor];
            
            while(%difference > 0)
            {
               %difference = %difference-%points;
               %counter++;
            }

         }

         if($vehicles[%i, currentvehiclehp] < $vehicles[%i, stockvehiclehp])
         {
            %difference = $vehicles[%i, stockvehiclehp] - $vehicles[%i, currentvehiclehp];
            
            while(%difference > 0)
            {
               %difference = %difference-%points;
               %counter++;
            }
         }
      }      
   }
   
   return %counter;   
}

// this will let the player know a damage percentage before going into battle

function GetCollectiveHitPoints()
{
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, vehicle] !$= "")
      {
         %hp = %hp+$vehicles[%i, stockarmor];     
         %hp = %hp+$vehicles[%i, stockenginehp];             
         %hp = %hp+$vehicles[%i, stocktirearmor];              
         %hp = %hp+$vehicles[%i, stockgastankarmor];
         %hp = %hp+$vehicles[%i, stockmountedweaponhp];
         %hp = %hp+$vehicles[%i, stockramhp];
         %hp = %hp+$vehicles[%i, stockwindowarmor];
         %hp = %hp+$vehicles[%i, stockvehiclehp];
      }      
   }
   
   return %hp;   
}

// used whenever a vehicle name is displayed

function GetVehicleDisplayName(%vehicle)
{
   switch$ (%vehicle)
   {
      case "dunebuggy":
         return "Dune Buggy";           
      case "bike":
         return "Bike";           
      case "jeep":
         return "Jeep";           
      case "compact":
         return "Compact";           
      case "minivan":
         return "Mini-Van";           
      case "towtruck":
         return "Tow Truck";           
      case "van":
         return "Van";           
      case "limo":
         return "Limo";           
      case "sedan":
         return "Sedan";           
      case "sportscar":
         return "Sports Car";           
      case "pickuptruck":
         return "Pickup Truck";           
      case "musclecar":
         return "Muscle Car";           
      case "stationwagon":
         return "Station Wagon";           
      case "humvee":
         return "Humvee";           
      case "suv":
         return "SUV";           
      case "flatbedtruck":
         return "Flatbed Truck";           
      case "trailertruck":
         return "Trailer Truck";           
      case "fireengine":
         return "Fire Engine";           
      case "garbagetruck":
         return "Garbage Truck";           
      case "bus":
         return "Bus";           
      case "boxtruck":
         return "Box Truck";           
      case "cargovan":
         return "Cargo Van";           
      case "ambulance":
         return "Ambulance";           
      case "construction":
         return "Construction Vehicle";           
   }
}

function ReplaceTires()
{
   for(%i=1;%i<=10;%i++)
   {
      if($vehicles[%i, vehicle] !$= "")
      {
         while($vehicles[%i, badtires] > 0 && $tires > 0)         
         {
            $vehicles[%i, badtires]--;
            DecreaseTires(1);
         }
      }
   }
}

function GetUpgradeSpecialWeaponHitPoints(%weapon)
{
   switch$ (%weapon)
   {
      case "crossbow":
         return 5;
      case "flamethrower":
         return 6;
      case "machinegun":
         return 7;      
      case "rpg":   
         return 9;   
   }   
}

function GetStockEngineHitPoints(%vehiclename)
{
   switch$ (%vehiclename)
   {
      // vehicles
      
      case "dunebuggy":
         return 15;
      case "bike":
         return 10;
      case "jeep":
         return 15;
      case "compact":
         return 20;
      case "minivan":
         return 20;
      case "towtruck":
         return 30;
      case "van":
         return 25;
      case "limo":
         return 25;
      case "sedan":
         return 25;
      case "sportscar":
         return 20;
      case "pickuptruck":
         return 30;
      case "musclecar":
         return 30;
      case "stationwagon":
         return 25;
      case "humvee":
         return 30;
      case "suv":
         return 30;
      case "flatbedtruck":
         return 40;
      case "trailertruck":
         return 40;
      case "fireengine":
         return 35;
      case "garbagetruck":
         return 30;
      case "bus":
         return 35;
      case "boxtruck":
         return 25;
      case "cargovan":
         return 25;
      case "ambulance":
         return 30;
      case "construction":
         return 40;
   }
}


// return the size of the vehicle for icon size

function GetSize(%vehicle)
{
   switch$ (%vehicle)
   {
      case "ambulance":
         return "4 7";

      case "boxtruck":
         return "4.5 8.5";

      case "bike":
         return "1.5 4.5";

      case "dunebuggy":
         return "3 5";

      case "fireengine":
         return "6 16";

      case "flatbedtruck":
         return "3.5 5.5";

      case "flatbedtrailer":
         return "5 12.5";

      case "garbagetruck":
         return "4 8.5";

      case "humvee":
         return "3.5 6.5";

      case "limo":
         return "3.5 11.5";

      case "minivan":
         return "3.5 6";

      case "musclecar":
         return "4 6";

      case "sedan":
         return "4 7";

      case "jeep":
         return "3.5 5";

      case "compact":
         return "3.5 5.5";

      case "sportscar":
         return "3 5";

      case "stationwagon":
         return "3.5 6.5";

      case "suv":
         return "3.5 8.5";

      case "cargovan":
         return "4 8.5";

      case "construction":
         return "6.5 12.5";

      case "trailertruck":
         return "4 5.5";

      case "trailertrucktrailer":
         return "4.5 12.5";

      case "towtruck":
         return "4 8";

      case "van":
         return "4 6.5";

      case "pickuptruck":
         return "3.5 8.5";

      case "bus":
         return "5 16";

      case "trailertrucktrailer":
         return "5 12.5";

      case "flatbedtrailer":
         return "5 12.5";

   }
}

// return the size of the vehicle for icon size

function GetVehicleSizeForPeopleBattle(%vehicle)
{
   switch$ (%vehicle)
   {
      case "ambulance":
         return "12 21";

      case "boxtruck":
         return "14 26";

      case "bike":
         return "5 14";

      case "dunebuggy":
         return "9 15";

      case "fireengine":
         return "14 48";

      case "flatbedtruck":
         return "10.5 15.5";

      case "flatbedtrailer":
         return "15 36.5";

      case "garbagetruck":
         return "12 24.5";

      case "humvee":
         return "9.5 18.5";

      case "limo":
         return "9.5 33.5";

      case "minivan":
         return "9.5 18";

      case "musclecar":
         return "12.5 15";

      case "sedan":
         return "9.5 15.5";

      case "jeep":
         return "9.5 15";

      case "compact":
         return "9 15.5";

      case "sportscar":
         return "9 15";

      case "stationwagon":
         return "9.5 18.5";

      case "suv":
         return "9.5 24.5";

      case "cargovan":
         return "12 24.5";

      case "construction":
         return "18.5 36.5";

      case "trailertruck":
         return "12 15.5";

      case "trailertrucktrailer":
         return "12.5 36.5";

      case "towtruck":
         return "12 24.5";

      case "van":
         return "12 18.5";

      case "pickuptruck":
         return "9.5 24.5";

      case "bus":
         return "15 48";

      case "trailertrucktrailer":
         return "15 36.5";

      case "flatbedtrailer":
         return "15 36.5";

   }
}

// when uprading a vehicle's armor get the armor points per upgrade
// a vehicle can only go up 5 levels, max wil be 100

function GetUpgradeArmorPoints(%vehicle)
{
   switch$ (%vehicle)
   {
      case "jeep":
         return 1;
      case "compact":
         return 1;
      case "minivan":
         return 2;
      case "towtruck":
         return 3;
      case "van":
         return 3;
      case "limo":
         return 4;
      case "sedan":
         return 3;
      case "sportscar":
         return 2;
      case "pickuptruck":
         return 3;
      case "musclecar":
         return 3;
      case "stationwagon":
         return 3;
      case "humvee":
         return 4;
      case "suv":
         return 4;
      case "flatbedtruck":
         return 7;
      case "trailertruck":
         return 8;
      case "fireengine":
         return 6;
      case "garbagetruck":
         return 5;
      case "bus":
         return 6;
      case "boxtruck":
         return 5;
      case "cargovan":
         return 4;
      case "ambulance":
         return 5;
      case "construction":
         return 5;
   }
}

function GetUpgradewindowArmorPoints(%vehicle)
{
   switch$ (%vehicle)
   {
      case "jeep":
         return 3;
      case "compact":
         return 3;
      case "minivan":
         return 6;
      case "towtruck":
         return 7;
      case "van":
         return 6;
      case "limo":
         return 8;
      case "sedan":
         return 5;
      case "sportscar":
         return 3;
      case "pickuptruck":
         return 7;
      case "musclecar":
         return 6;
      case "stationwagon":
         return 6;
      case "humvee":
         return 10;
      case "suv":
         return 9;
      case "flatbedtruck":
         return 13;
      case "trailertruck":
         return 15;
      case "fireengine":
         return 12;
      case "garbagetruck":
         return 10;
      case "bus":
         return 9;
      case "boxtruck":
         return 8;
      case "cargovan":
         return 6;
      case "ambulance":
         return 7;
      case "construction":
         return 6;
   }
}

function GetUpgradeTireArmorPoints(%vehicle)
{
   switch$ (%vehicle)
   {
      case "jeep":
         return 2;
      case "compact":
         return 2;
      case "minivan":
         return 2;
      case "towtruck":
         return 5;
      case "van":
         return 5;
      case "limo":
         return 5;
      case "sedan":
         return 4;
      case "sportscar":
         return 2;
      case "pickuptruck":
         return 6;
      case "musclecar":
         return 5;
      case "stationwagon":
         return 5;
      case "humvee":
         return 7;
      case "suv":
         return 6;
      case "flatbedtruck":
         return 8;
      case "trailertruck":
         return 10;
      case "fireengine":
         return 7;
      case "garbagetruck":
         return 5;
      case "bus":
         return 7;
      case "boxtruck":
         return 6;
      case "cargovan":
         return 4;
      case "ambulance":
         return 5;
      case "construction":
         return 5;
   }
}

function GetUpgradeGasTankArmorPoints(%vehicle)
{
   switch$ (%vehicle)
   {
      case "jeep":
         return 1;
      case "compact":
         return 1;
      case "minivan":
         return 1;
      case "towtruck":
         return 3;
      case "van":
         return 3;
      case "limo":
         return 4;
      case "sedan":
         return 3;
      case "sportscar":
         return 1;
      case "pickuptruck":
         return 4;
      case "musclecar":
         return 3;
      case "stationwagon":
         return 3;
      case "humvee":
         return 5;
      case "suv":
         return 5;
      case "flatbedtruck":
         return 6;
      case "trailertruck":
         return 7;
      case "fireengine":
         return 6;
      case "garbagetruck":
         return 4;
      case "bus":
         return 5;
      case "boxtruck":
         return 4;
      case "cargovan":
         return 3;
      case "ambulance":
         return 4;
      case "construction":
         return 4;
   }
}

function GetUpgradeRamPoints(%vehicle)
{
   switch$ (%vehicle)
   {
      case "jeep":
         return 2;
      case "compact":
         return 2;
      case "minivan":
         return 2;
      case "towtruck":
         return 4;
      case "van":
         return 3;
      case "limo":
         return 4;
      case "sedan":
         return 3;
      case "sportscar":
         return 2;
      case "pickuptruck":
         return 3;
      case "musclecar":
         return 3;
      case "stationwagon":
         return 3;
      case "humvee":
         return 5;
      case "suv":
         return 4;
      case "flatbedtruck":
         return 6;
      case "trailertruck":
         return 6;
      case "fireengine":
         return 6;
      case "garbagetruck":
         return 5;
      case "bus":
         return 6;
      case "boxtruck":
         return 5;
      case "cargovan":
         return 3;
      case "ambulance":
         return 5;
      case "construction":
         return 5;
   }
}

function GetVehicleNorthIconSize(%vehicle)
{
   switch$ (%vehicle)
   {
      case "bike":
         return "16 26.5";
      case "dunebuggy":
         return "29.5 42";
      case "jeep":
         return "29 46.5";
      case "compact":
         return "32 48";
      case "minivan":
         return "29.5 43";
      case "towtruck":
         return "28.5 69";
      case "van":
         return "33.5 45";
      case "limo":
         return "27.5 81.5";
      case "sedan":
         return "26.5 48";
      case "sportscar":
         return "26 36.5";
      case "pickuptruck":
         return "32.5 55.5";
      case "musclecar":
         return "33 42.5";
      case "stationwagon":
         return "30.5 48";
      case "humvee":
         return "29.5 46";
      case "suv":
         return "29 62";
      case "flatbedtruck":
         return "28 48.5";
      case "trailertruck":
         return "32 48.5";
      case "fireengine":
         return "29 75.5";
      case "garbagetruck":
         return "29.5 62.5";
      case "bus":
         return "34 78";
      case "boxtruck":
         return "31 60.5";
      case "cargovan":
         return "31 69";
      case "ambulance":
         return "29 48.5";
      case "construction":
         return "46 81";
   }
}

// create the vehicle icon in game which will have correct bounds for mounting

function GetVehiclePolyList(%vehicle)
{
   switch$ (%vehicle)
   {
      case "construction":
            return "-0.805 -0.334 0.727 -0.329 0.737 0.815 -0.894 0.820";      
      case "trailertruck":
            return "-0.851 -0.830 0.818 -0.825 1.000 0.830 -0.971 0.830";                  
      case "trailertruck_trailer":
            return "-0.822 -0.869 0.754 -0.869 0.754 0.884 -0.822 0.889";         
      case "flatbedtruck":
            return "-0.733 -0.688 0.746 -0.692 0.707 0.697 -0.707 0.697";      
      case "flatbed_trailer":
            return "-0.713 -0.688 0.742 -0.707 0.713 0.702 -0.698 0.697";         
      case "cargovan":      
            return "-0.838 -0.859 0.838 -0.869 0.838 0.859 -0.838 0.859";
      case "musclecar":
            return "-0.681 -0.982 0.755 -0.992 0.746 1.000 -0.709 1.000";            
      case "jeep":
            return "-1.000 -0.928 1.000 -0.913 0.923 0.835 -0.972 0.845";            
      case "bus":
            return "-0.770 -0.992 0.784 -0.997 0.784 0.977 -0.770 0.977";
      case "towtruck":            
            return "-1.000 -0.845 0.950 -0.840 0.950 0.756 -0.950 0.751";            
      case "compact":
            return "-0.835 -0.869 0.835 -0.874 0.786 0.766 -0.864 0.746";
      case "pickuptruck":
            return "-0.990 -0.746 0.962 -0.746 0.947 0.859 -0.947 0.859";
      case "van":
            return "-0.756 -0.992 0.786 -0.987 0.766 0.982 -0.756 0.987";
      case "suv":
            return "-0.966 -0.761 1.000 -0.766 1.000 0.756 -0.993 0.761";
      case "stationwagon":
            return "-0.754 -0.845 0.740 -0.850 0.833 0.874 -0.806 0.874";
      case "sportscar":
            return "-0.678 -0.997 0.805 -0.992 1.000 1.000 -1.000 1.000";
      case "sedan":
            return "-0.796 -0.761 0.809 -0.771 0.809 0.776 -0.822 0.776";
      case "minivan":
            return "-0.733 -0.904 0.761 -0.904 0.771 0.884 -0.790 0.879";
      case "limo":
            return "-0.943 -0.791 0.962 -0.796 0.962 0.717 -0.923 0.717";
      case "humvee":
            return "-0.864 -0.987 0.815 -0.992 0.845 0.948 -0.854 0.948";
      case "garbagetruck":
            return "-0.903 -0.820 1.000 -0.825 0.985 0.869 -0.985 0.884";
      case "fireengine":
            return "-1.000 -1.000 1.000 -1.000 0.908 0.962 -0.933 0.972";
      case "dunebuggy":
            return "-0.746 -0.879 1.000 -0.879 0.923 0.859 -0.923 0.859";      
      case "bike":
            return "-0.688 -0.746 0.825 -0.746 0.884 0.746 -0.786 0.761";
      case "ambulance":
            return "-0.796 -0.958 0.943 -0.953 0.913 0.987 -0.786 1.000";
   }
}

function PlayVehicleSound(%vehicle)
{
   switch$ (%vehicle)
   {
      case "dunebuggy":
         $vehicleSound = alxPlay(cars);
      case "bike":
         $vehicleSound = alxPlay(cars);
      case "jeep":
         $vehicleSound = alxPlay(cars);
      case "compact":
         $vehicleSound = alxPlay(cars);
      case "minivan":
         $vehicleSound = alxPlay(cars);
      case "towtruck":
         $vehicleSound = alxPlay(cars);
      case "van":
         $vehicleSound = alxPlay(cars);
      case "limo":
         $vehicleSound = alxPlay(cars);
      case "sedan":
         $vehicleSound = alxPlay(cars);
      case "sportscar":
         $vehicleSound = alxPlay(cars);
      case "pickuptruck":
         $vehicleSound = alxPlay(cars);
      case "musclecar":
         $vehicleSound = alxPlay(cars);
      case "stationwagon":
         $vehicleSound = alxPlay(cars);
      case "humvee":
         $vehicleSound = alxPlay(trucks);
      case "suv":
         $vehicleSound = alxPlay(cars);
      case "flatbedtruck":
         $vehicleSound = alxPlay(trucks);
      case "trailertruck":
         $vehicleSound = alxPlay(trucks);
      case "fireengine":
         $vehicleSound = alxPlay(trucks);
      case "garbagetruck":
         $vehicleSound = alxPlay(trucks);
      case "bus":
         $vehicleSound = alxPlay(trucks);
      case "boxtruck":
         $vehicleSound = alxPlay(trucks);
      case "cargovan":
         $vehicleSound = alxPlay(trucks);
      case "ambulance":
         $vehicleSound = alxPlay(trucks);
      case "construction":
         $vehicleSound = alxPlay(trucks);
   }
      
}

function GetTires(%vehicle)
{
   switch$ (%vehicle)
   {
      case "dunebuggy":
         return 4;           
      case "bike":
         return 2;           
      case "jeep":
         return 4;           
      case "compact":
         return 4;           
      case "minivan":
         return 4;           
      case "towtruck":
         return 6;           
      case "van":
         return 4;           
      case "limo":
         return 4;           
      case "sedan":
         return 4;           
      case "sportscar":
         return 4;           
      case "pickuptruck":
         return 4;           
      case "musclecar":
         return 4;           
      case "stationwagon":
         return 4;           
      case "humvee":
         return 4;           
      case "suv":
         return 4;           
      case "flatbedtruck":
         return 14;           
      case "trailertruck":
         return 18;           
      case "fireengine":
         return 6;           
      case "garbagetruck":
         return 6;           
      case "bus":
         return 10;           
      case "boxtruck":
         return 6;           
      case "cargovan":
         return 6;           
      case "ambulance":
         return 4;           
      case "construction":
         return 6;                 
   }
}

function TradeInUpgradePoints()
{
   if($UpgradePoints == 0)
   {
      alxPlay(buzzer);
      return;            
   }
   
   Infowindow.Visible = true;
   
   if($TradeIn > $mastertime)
   {      
      Infotext.setText("You can trade in Upgrade Points in " @ $TradeIn-$mastertime @ " turns.");

      InfoYesbutton.Visible = false;
      InfoNobutton.Visible = false;
      Infocontinuebutton.Visible = true;
               
      Infocontinuebutton.command = "Infowindow.Visible = false;";   
   }
   else
   {
      if($UpgradePoints >= 15)
         %points = 15;
      else
         %points = $UpgradePoints;   
      
      if(%points == 1)
         %word = "point";
      else
         %word = "points";
         
      if(CheckMechanic() > 0)
         %factor = 15;
      else
         %factor = 10;
         
      Infotext.setText("Do you want to use " @ %points @ " upgrade " @ %word @ " to repair " @ %points*%factor @ " points worth of damage?");

      InfoYesbutton.Visible = true;
      InfoNobutton.Visible = true;
      Infocontinuebutton.Visible = false;
               
      InfoNobutton.command = "Infowindow.Visible = false;";   
      InfoYesbutton.Command = "RepairDamageWithUpgradePoints();";
   }
}

// this checks the value, if they can trade in than change the button

function CheckTradeInTime()
{
   if($TradeIn >= $mastertime)
      upgradetext.Setbitmap(expandFilename("~/data/images/gui/transparent.png"));
   else
      upgradetext.Setbitmap(expandFilename("~/data/images/gui/btn_big.png"));
}

function RepairDamageWithUpgradePoints()
{
   if(Infowindow.Visible $= false)
      return;
      
   %partsneeded = GetSparePartsNeeded();
   
   if(%partsneeded > 15)
      %counter = 15;
   else
      %counter = %partsneeded;
   
   while(%counter > 0 && $UpgradePoints > 0)   
   {
      %i = getRandom(1, 10);
               
      if($vehicles[%i, vehicle] !$= "")
      {
         if($vehicles[%i, currentarmor] < $vehicles[%i, stockarmor] && $UpgradePoints > 0 && %counter > 0)     
         {
            TradeInRepair(%i, armor, true);
            %counter--;
            $UpgradePoints--;
         }
            
         if($vehicles[%i, currentenginehp] < $vehicles[%i, stockenginehp]  && $UpgradePoints > 0 && %counter > 0)             
         {
            TradeInRepair(%i, engine, true);
            %counter--;
            $UpgradePoints--;
         }

         if($vehicles[%i, currenttirearmor] < $vehicles[%i, stocktirearmor] && $UpgradePoints > 0 && %counter > 0)              
         {
            TradeInRepair(%i, tirearmor, true);
            %counter--;
            $UpgradePoints--;
         }

         if($vehicles[%i, currentgastankarmor] < $vehicles[%i, stockgastankarmor] && $UpgradePoints > 0 && %counter > 0)
         {
            TradeInRepair(%i, gastankarmor, true);
            %counter--;
            $UpgradePoints--;
         }

         if($vehicles[%i, currentmountedweaponhp] < $vehicles[%i, stockmountedweaponhp] && $UpgradePoints > 0 && %counter > 0)
         {
            TradeInRepair(%i, mountedweapon, true);
            %counter--;
            $UpgradePoints--;
         }

         if($vehicles[%i, currentramhp] < $vehicles[%i, stockramhp] && $UpgradePoints > 0 && %counter > 0)
         {
            TradeInRepair(%i, ram, true);
            %counter--;
            $UpgradePoints--;
         }

         if($vehicles[%i, currentwindowarmor] < $vehicles[%i, stockwindowarmor] && $UpgradePoints > 0 && %counter > 0)
         {         
            TradeInRepair(%i, windowarmor, true);
            %counter--;
            $UpgradePoints--;
         }

         if($vehicles[%i, currentvehiclehp] < $vehicles[%i, stockvehiclehp] && $UpgradePoints > 0 && %counter > 0)
         {
            TradeInRepair(%i, vehicle, true);
            %counter--;
            $UpgradePoints--;
         }
      }   
   }   
   
   UpdateStatsBar();
   
   $TradeIn = $mastertime+24;
   
   Infowindow.Visible = false;

   CheckTradeInTime();
}

function TradeInRepair(%slot, %area)
{
   if(CheckMechanic() > 0)
      %points = 15;
   else
      %points = 10;
      
   switch$ (%area)
   {
      case "armor":     
         $vehicles[%slot, currentarmor] = $vehicles[%slot, currentarmor]+%points;
         
         if($vehicles[%slot, currentarmor] > $vehicles[%slot, stockarmor])            
            $vehicles[%slot, currentarmor] = $vehicles[%slot, stockarmor];
         
      case "engine":             
         $vehicles[%slot, currentenginehp] = $vehicles[%slot, currentenginehp]+%points;
         
         if($vehicles[%slot, currentenginehp] > $vehicles[%slot, stockenginehp])            
            $vehicles[%slot, currentenginehp] = $vehicles[%slot, stockenginehp];

      case "tirearmor":              
         $vehicles[%slot, currenttirearmor] = $vehicles[%slot, currenttirearmor]+%points;
         
         if($vehicles[%slot, currenttirearmor] > $vehicles[%slot, stocktirearmor])            
            $vehicles[%slot, currenttirearmor] = $vehicles[%slot, stocktirearmor];

      case "gastankarmor":
         $vehicles[%slot, currentgastankarmor] = $vehicles[%slot, currentgastankarmor]+%points;
         
         if($vehicles[%slot, currentgastankarmor] > $vehicles[%slot, stockgastankarmor])            
            $vehicles[%slot, currentgastankarmor] = $vehicles[%slot, stockgastankarmor];

      case "mountedweapon":
         $vehicles[%slot, currentmountedweaponhp] = $vehicles[%slot, currentmountedweaponhp]+%points;
         
         if($vehicles[%slot, currentmountedweaponhp] > $vehicles[%slot, stockmountedweaponhp])            
            $vehicles[%slot, currentmountedweaponhp] = $vehicles[%slot, stockmountedweaponhp];

      case "ram":
         $vehicles[%slot, currentramhp] = $vehicles[%slot, currentramhp]+%points;
         
         if($vehicles[%slot, currentramhp] > $vehicles[%slot, stockramhp])            
            $vehicles[%slot, currentramhp] = $vehicles[%slot, stockramhp];

      case "windowarmor":
         $vehicles[%slot, currentwindowarmor] = $vehicles[%slot, currentwindowarmor]+%points;
         
         if($vehicles[%slot, currentwindowarmor] > $vehicles[%slot, stockwindowarmor])            
            $vehicles[%slot, currentwindowarmor] = $vehicles[%slot, stockwindowarmor];

      case "vehicle":
         $vehicles[%slot, currentvehiclehp] = $vehicles[%slot, currentvehiclehp]+%points;
         
         if($vehicles[%slot, currentvehiclehp] > $vehicles[%slot, stockvehiclehp])            
            $vehicles[%slot, currentvehiclehp] = $vehicles[%slot, stockvehiclehp];
   }   
}


