//----------------------------------------
// Team Settings Stdlib Script
// TeamSetupStdlib.cs
//
// version 1.10
//
// Author: ACrisp [oAo]
//----------------------------------------

//----------------------------------------
// This script will allow players to define maps along faction lines.  Up to Four teams can be defined.
// These factions are available: 
// Human - all human vehicles.
// Imperial - human Imperial vehicles (no Knights)
// Knight - human Knight vehicles only
// Rebel - human Rebel vehicles only (includes outrider vehicles)
// Cybrid - all Cybrid Vehicles (no Metagen)
// Metagen - Metagen Cybrid vehicles only
//
// Some special options:
// mixed tech - toggles the mixed technology option
// Tharsis Cache limited - allows limited access to Cache weapons.  Limits are equal across all teams
// Predators limited - allows mission to limit number of Predators. Limits are equal across all teams
// Platinum Guard limited - allows missions to limit numbers of Plat Guard Execs and Adjuds.  Limits are equal across all teams
//
// Functions in this script
// setFactions(%faction1, %faction2, %faction3, %faction4) - Defines factions for Yellow, Blue, Red, and Purple teams respectively)
// vehicle::onAdd(%this) - sifts vehicles being dropped on the basis of faction lines and diverts vehicles to proper teams.  
//                         Also the gatekeeper for limited vehicles and technologies.
// grabVehicleTech(%this) - used to determine the tech base of a vehicle.  Returns a faction name
// inventoryTharsisTech(%this) - used to keep track on how many Tharsis Cache items are on a map per team.  Returns a true/false value.
// restoreTharsisTech(%this) - adjusts team Tharsis Cache inventory if vehicles are destroyed so that other players can use Tharsis items
// inventorySpecialVehicles(%this) - used to keep track of Predators and Platinum Guard vehicles.  Returns a true/false value
// restoreSpecialVehicles(%this) - adjusts team vehicle inventories if special vehicles are destroyed.
//
//-----------------------------------------

function grabVehicleTech(%this)
{
   %name = getVehicleName(%this);
   
   if (%name == "Talon") %techBase = "Imperial";
   if (%name == "Minotaur") %techBase = "Imperial";
   if (%name == "Basilisk") %techBase = "Imperial";
   if (%name == "Apocalypse") %techBase = "Imperial";
   if (%name == "Gorgon") %techBase = "Imperial";
   if (%name == "Paladin") %techBase = "Imperial";
   if (%name == "Myrmidon") %techBase = "Imperial";
   if (%name == "Disrupter") %techBase = "Imperial";
   if (%name == "Knight's Talon") %techBase = "Knight";
   if (%name == "Knight's Minotaur") %techBase = "Knight";
   if (%name == "Knight's Basilisk") %techBase = "Knight";
   if (%name == "Knight's Apocalypse") %techBase = "Knight";
   if (%name == "Knight's Gorgon") %techBase = "Knight";
   if (%name == "Knight's Paladin") %techBase = "Knight";
   if (%name == "Knight's Myrmidon") %techBase = "Knight";
   if (%name == "Knight's Disrupter") %techBase = "Knight";
   if (%name == "Emancipator") %techBase = "Rebel";
   if (%name == "Outrider Emancipator") %techBase = "Rebel";
   if (%name == "Avenger") %techBase = "Rebel";
   if (%name == "Dreadlock") %techBase = "Rebel";
   if (%name == "Olympian") %techBase = "Rebel";
   if (%name == "Harabec's Predator") %techBase = "Rebel";
   if (%name == "Seeker") %techBase = "Cybrid";
   if (%name == "Goad") %techBase = "Cybrid";
   if (%name == "Shepherd") %techBase = "Cybrid";
   if (%name == "Adjudicator") %techBase = "Cybrid";
   if (%name == "Executioner") %techBase = "Cybrid";
   if (%name == "Bolo") %techBase = "Cybrid";
   if (%name == "Recluse") %techBase = "Cybrid";
   if (%name == "Platinum Guard Adjudicator") %techBase = "Cybrid";
   if (%name == "Platinum Guard Executioner") %techBase = "Cybrid";
   if (%name == "Metagen Seeker") %techBase = "Metagen";
   if (%name == "Metagen Goad") %techBase = "Metagen";
   if (%name == "Metagen Shepherd") %techBase = "Metagen";
   if (%name == "Metagen Adjudicator") %techBase = "Metagen";
   if (%name == "Metagen Executioner") %techBase = "Metagen";

   return %techBase;

}

function vehicle::onAdd(%this)
{
   %player = playerManager::vehicleIdToPlayerNum( %this );

   %tech = grabVehicleTech(%this);
   
   if (%player != 0)
   {
   if ($noFactions == FALSE)
   {
   if ($yellowtech == "Human")
    {
      if (((%tech == "Imperial") || (%tech == "Knight") || (%tech == "Rebel")) && (getTeam(%this) != *IDSTR_TEAM_YELLOW))
       {
         setTeam(%this, *IDSTR_TEAM_YELLOW);
         reDrop(%this);
       }
    }
   else if ($bluetech == "Human") 
    {
      if (((%tech == "Imperial") || (%tech == "Knight") || (%tech == "Rebel")) && (getTeam(%this) != *IDSTR_TEAM_BLUE))
       {
         setTeam(%this, *IDSTR_TEAM_BLUE);
         reDrop(%this);
       }
    }
   else if ($redtech == "Human") 
    {
      if (((%tech == "Imperial") || (%tech == "Knight") || (%tech == "Rebel")) && (getTeam(%this) != *IDSTR_TEAM_RED))
       {
         setTeam(%this, *IDSTR_TEAM_RED);
         reDrop(%this);
       }
    }
   else if ($purpletech == "Human") 
    {
      if (((%tech == "Imperial") || (%tech == "Knight") || (%tech == "Rebel")) && (getTeam(%this) != *IDSTR_TEAM_PURPLE))
       {
         setTeam(%this, *IDSTR_TEAM_PURPLE);
         reDrop(%this);
       }
    }
   else
    {
      if ((%tech == $yellowtech) && (getTeam(%this) != *IDSTR_TEAM_YELLOW))
       {
         setTeam(%this, *IDSTR_TEAM_YELLOW);
         reDrop(%this);
       }
      else if ((%tech == $bluetech) && (getTeam(%this) != *IDSTR_TEAM_BLUE))
       {
         setTeam(%this, *IDSTR_TEAM_BLUE);
         reDrop(%this);
       }
      else if ((%tech == $redtech) && (getTeam(%this) != *IDSTR_TEAM_RED))
       {
         setTeam(%this, *IDSTR_TEAM_RED);
         reDrop(%this);
       }
      else if ((%tech == $purpletech) && (getTeam(%this) != *IDSTR_TEAM_PURPLE))
       {
         setTeam(%this, *IDSTR_TEAM_PURPLE);
         reDrop(%this);
       }
      else 
       {
         
         if ((%tech != $yellowtech) && (%tech != $bluetech) && (%tech != $redtech) && (%tech != $purpletech))
          {
            say(%player, 1234, "<f5>Your vehicle does not conform to the tech parameters of this mission.  Please reread the mission rules and choose another vehicle.", "rules_violated.wav");
            damageObject(%this, 50000); // kills the offending vehicle
          }
         
       }
    }  
   }
   }

}




