// this will be the main plot of the game

function CreateSilos(%maxsilos)
{
   %i=1;
   
   while(%i<= %maxsilos)
   {
      %rand = getRandom(1, 30);
      
      %silo = "silo" @ %rand;
      
      if(%silo.ingame !$= true)
      {
         %i++;
         %silolist[%silo] = true;
         %silo.ingame = true;    
         
         // for the save game file
         
         $silos[%silo] = true;     
      }
   }
   
   for(%i=1;%i<=30;%i++)
   {
      %silo = "silo" @ %i;
      
      if(%silolist[%silo] !$= true)
         %silo.visible = false;             
   }
}

// by default all the silos are visible, once the active list is loaded on a load game
// this will hide the ones that are not in play

function HideSilos()
{   
   for(%i=1;%i<=30;%i++)
   {
      %silo = "silo" @ %i;
      
      if($silos[%silo] !$= true)
         %silo.visible = false;             
   }
}

// there must be 1 scientist for each silo to be captured and a scientist may not be 
// placed in a city with a specialist

function SeedScientists(%maxsilos)
{
   %j = 1;
   
   while(%j <= %maxsilos)
   {
      %rand = getRandom(1, 56);
      %specialist = "";      
      %scientist = "";
      %city = GetCityName(%rand);
      
      // check for specialist
      
      for(%i=1;%i<=10;%i++)
         if(getWord($SpecialistLocations[%i], 0) $= %city)            
            %specialist = true;                        
      
      for(%i=1;%i<=%maxsilos;%i++)
         if($ScientistLocations[%i] $= %city)
            %scientist = true;
      
      if(%specialist $= "" && %scientist $= "")                  
      {
         $ScientistLocations[%j] = %city;
         %j++;
      }
   }
}

// when a player moves their gang to a nuclear silo see if it's been captured already. If not see if they have a scientist
// to make an attempt to capture it

function CheckNukeSite(%captured)
{
   // if they haven't captured it yet and don't have a scientist display a message saying they don't have a scientist
   // to make the attempt
   
   if(%captured $= "" && $scientists == 0)
   {
      InfoWindow.Visible = true;
      InfoYesbutton.Visible = false;
      InfoNobutton.Visible = false; 
      Infocontinuebutton.Visible = true;
      InfoContinuebutton.command = "Infowindow.Visible = false;";
      
      InfoText.setText("You need at least 1 scientist to capture this silo!");     
   }
   
   if(%captured $= "" && $scientists > 0)
   {
      InfoWindow.Visible = true;
      InfoYesbutton.Visible = true;
      InfoNobutton.Visible = true; 
      Infocontinuebutton.Visible = false;
      InfoNobutton.command = "Infowindow.Visible = false;";
      InfoYesbutton.command = "CaptureSilo();";
            
      InfoText.setText("Do you want to attempt to capture this silo?");     
   }
   
   DisplayTutorial(silo);
}

// capture silo will start vehicle combat

function CaptureSilo()
{
   if(Infowindow.Visible $= false)
      return;

   $SiloCapture = true;
   Infowindow.Visible = false;
   
   StartCombat();      
}

// if this battle was part of a silo capture

function CheckSiloCapture()
{
   if($SiloCapture $= true)
   {
      // deduct a scientist
      
      $scientists--;
      
      $remainingsilos--;
      $UpgradePoints++;
      
      %objects = sg.pickPoint(player.getPosition());   
      
      %count = getWordCount(%objects);
      
      for(%i=0;%i<%count;%i++)
      {
         %obj = getWord(%objects, %i);
         
         if(%obj.silo !$= "")
         {
            %obj.captured = true;
            %obj.SetBlendColor("0 202 41 255");            
         }
      }
            
      $SiloCapture = "";
      
      if($remainingsilos == 0)
      {
         echo("End Game");
         GoodEndGame(); 
      }
   }
}