function StartNewGame()
{
   canvas.SetContent(LoadingScreen);
   canvas.cursoroff();
   ResetLoadingBar();
   ChangeLoadingBar(100);      
   schedule(500, 0, "StartNewGamePhaseOne");
}

function StartNewGamePhaseOne()
{
   alxStop($IntroSong);
   Screen2D.loadLevel(expandFilename("~/data/levels/main.t2d"));
   fow.Visible = true;   
   Screen2D.mount(player);
   UpdateMainBarShortcuts();
   ChangeLoadingBar(200);
   schedule(500, 0, "StartnewGamePhaseTwo");
}

function StartNewGamePhaseTwo()
{
   GenerateRandomLocations();
   
   Canvas.SetContent(MainMap);
   
   $wind = alxPlay(wind);
   
   $saveid = getRandom(100, 1000000);
      
   // starter values //

   $RoadCombatChance = 3;
   $CountryCombatChance = 1;
      
   // supplies
   
   $food = 10;
   $guns = 1;
   $ammo = 20;
   $medicine = 0;
   $tires = 0;
   $spareparts = 0;   
   $fuel = 20;

   // people
      
   $refuges = 5;
   $Brigands = 0;
   $Militia = 0;
   $Police = 0;
   $Soldiers = 0;
   $Mercenaries = 0;
   $scientists = 0;
   
   // vehicle
   
   $vehicles[1, vehicle] = "compact";
   $vehicles[1, tires] = 4;
   $vehicles[1, topspeed] = 50;
   $vehicles[1, stockarmor] = 0;
   $vehicles[1, currentarmor] = 0;
   $vehicles[1, acceleration] = 0;
   $vehicles[1, brakes] = 0;
   $vehicles[1, badtires] = 0;
   $vehicles[1, steering] = 0;
   $vehicles[1, tireupgrade] = 0;
   $vehicles[1, stocktirearmor] = 0;
   $vehicles[1, currenttirearmor] = 0;
   $vehicles[1, stockgastankarmor] = 0;
   $vehicles[1, currentgastankarmor] = 0;
   $vehicles[1, tireupgade] = 0;
   $vehicles[1, currentwindowarmor] = 0;
   $vehicles[1, stockwindowarmor] = 0;
   $vehicles[1, currentramhp] = 0;
   $vehicles[1, stockramhp] = 0;
   $vehicles[1, currentvehiclehp] = GetStockVehicleHitPoints("compact");
   $vehicles[1, stockvehiclehp] = GetStockVehicleHitPoints("compact");
   $vehicles[1, supplycapacity] = GetVehicleSupplyCapacity($vehicles[1, vehicle]);
   $vehicles[1, stockenginehp] = GetStockEngineHitPoints("compact");
   $vehicles[1, currentenginehp] = GetStockEngineHitPoints("compact");
   
   // stats
   
   $morale = 10;
   $reputation = 0;
   $UpgradePoints = 0;
   $CapturedCities = 0;
   $savename = "Game";
   $scoutingParty = 0;
   
   // get time started
   
   $clock = "Day   1    Hour   100";   
   clock.text = $clock;   
   $mastertime = 1;
   
   $diseasecheck = 24;
   
   // get difficulty level 
   
   $Difficulty = trim(Difficulty.text);
   
   // reset vehicles
   
   for(%i=2;%i<=10;%i++)
   {
      RemoveVehicle(%i);            
   }
   
   switch$ ($Difficulty)
   {
      case "easy":
         %maxsilos = 10;            
      case "normal":
         %maxsilos = 15;      
      case "hard":      
         %maxsilos = 20;      
   }

   deleteVariables("$SpecialistLocations*");

   UpdateStatsBar();
   
   BuildCityPopulation();
   
   echo("FIRST");
   
   PlaceSpecialPeople();

   echo("SECOND");
   
   CreateSilos(%maxsilos);

   echo("THIRD");
   
   SeedScientists(%maxsilos);

   echo("FOURTH");
         
   $remainingsilos = %maxsilos;
   
   // food contamination chance
   
   $checkFoodConTime = getRandom(48, 72);
      
   // hide search window   

   Infowindow.Visible = false;      

   // position player piece
   
   %rand = getRandom(1, 10);
   
   %spawn = "spawn" @ %rand;
   
   %pos = %spawn.GetPosition();
   
   player.SetPosition(%pos);
   
   InitFow(player.GetPosition());
   
   $GameStarted = true;
   $EndGame = ""; // in case they quit the game and went back to main menu
   
   battlewindow.Visible = false;
   mainbar.Visible = true;
   PeopleBattle.Visible = false;
   
   IntroTutorial(1);
   setAcceptableScreenRatio();
}

function DisplayIntroDialog()
{
   // check here to see if they have an open game slot, if they don't make them delete one
   
   for(%file = findFirstFile("~/save*.sav"); %file !$= ""; %file = findNextFile("~/save*.sav"))  
   {
      %fo = new fileobject();
      
      %fo.OpenForRead(%file);
      
      for(%line = %fo.ReadLine();%line !$= "";%line = %fo.ReadLine())
      {
         %word = GetWord(%line, 0);
         
         switch$ (%word)
         {         

            case "Saveid":
               %saveid = getWord(%line, 1);
               
               if(%saveid !$= "")
                 %counter++;            
         }
      }
      
      if(%counter $= 10)
      {
         alxPlay(buzzer);
         introtutorial1.Visible = false;
         introtutorial2.Visible = false;
         tutorialbutton.text = "Close";
         tutorialbutton.command = "CloseTutorial();";      
         canvas.pushdialog(tutorial);                           
         tutorialdesc.setText("You have no saved game slots available, please delete a saved game to start a new one.");
         return;
      }      
   }

   alxPlay(click);
   canvas.SetContent(black);
   canvas.pushdialog(introdialog);   
   intropic.SetBitmap(expandfilename("~/data/images/gui/introscreen1.png"));
   
   introbutton.command = "DisplayIntroDialog1();";
   introbutton.setText("Next");
   introdialogtext.setText("In the not too distant future a radical cult called The Children of Tomorrow decided " @
   "that American society was too sick to continue. In the following years they developed a super germ designed " @
   "for one purpose, to wipe out every human on the entire North American continent. Cult members, armed with " @ 
   "barrels of the lethal poison, tainted the water supply of every major city in the United States and waited " @
   "for the end. \n\nThey succeeded and within days the country's population was decimated. What The Children " @
   "of Tomorrow didn't count on was a very small percentage of people had a natural immunity to their super germ. " @
   "What was left of society quickly descended into darkness and despair, people had to fight every day for basic " @
   "survival and for their very lives. Food and water became scarce, disease was rampant, and gangs took over the " @
   "highways and cities.");

}

function DisplayIntroDialog1()
{
   ChangeIntroButton();
   
   intropic.SetBitmap(expandfilename("~/data/images/gui/introscreen2.png"));

   introdialogtext.setText("The Children of Tomorrow quickly realized there was still going to be a tomorrow and " @
   "decided to end not just what was left of the United States but the entire human race once and for all. With the " @
   "government almost non-existent and the remainder of society in chaos, cult members set out to capture nuclear " @
   "silos so they can launch one last attack to wipe out every last human on the planet.\n\nThe last remnants of the " @
   "Federal government have given you some meager resources and tasked you to stop The Children of Tomorrow. Your " @
   "goal is to gather vehicles, new recruits and supplies and find nuclear scientists scattered in cities around the " @
   "country. With the help of the scientists you need to find the hostile nuclear silos and disarm them. Once you " @
   "have defeated The Children of Tomorrow and disabled all of the silos within 150 days time, only then will the human race be given a " @
   "chance to continue.");

   introbutton.setText("Start Game");
   introbutton.command = "StartNewGame();";
}

