//--------------


//$altPort = true;

//$altServer = true;
//$localServer = true;
//$officeServer = true;
//$binServer = true;
//$mangoServer = true;

//$disableScores = true;


$listDblClickTime = 200;


$adminMode = false;




$preReleaseTesting = true;

//$disablePhaseImages = true;


//$disableSP = true;

////////////

function localGrandServer()
{
   exec("./grandServer/grandServer.cs");
   startGrandServer();
}

$tileID = 3;
function initializeProject()
{
	
   
   setGlobalRandomSeed();
   
   $manager = new PsychoffManager();
   
   if (fileExists("psychoff/noshaders.txt"))
		$manager.simpleRendering = true;
   
   exec("./doubled/doubled.cs");
   
   exec("~/gui/mainScreen.gui");
   
   if (!$grandServerDedicated && !$aiProcess)
   {
		exec("./gameScripts/steam.cs");
   }
  
   
   // jamesu - tinyirc
   exec("~/tinyirc/init.cs");
   $PSIRCServer = "irc.maxgaming.net";
   $authServer = "62.197.39.230:82";
   // jamesu - social
   exec("~/gameScripts/social.cs");
   exec("./gui/TwitterPIN.gui");
   
   
   
    //exec("~/gui/drag.gui");
   exec("~/gui/MessageBoxTextEntryDlg.gui");
   exec("~/gui/MessageBoxListEntryDlg.gui");
   
   if (!$grandServerDedicated)
	{
   
		exec("./gui/preTurnGui.gui");
		exec("./gui/endConfGui.gui");
		exec("./gui/startGameGui.gui");
		exec("./gui/offline.gui");
		  exec("./gui/oldGSBrowserGui.gui");
		exec("./gui/gsBrowserGui.gui");
	 
		//exec("./gui/postGameGui.gui");
		exec("./gui/submitEPOptionsGui.gui");
		exec("./gui/progressionGui.gui");
		exec("./gui/scoresGui.gui");
		exec("./gui/scoreSheetGui.gui");
		exec("./gui/askChooseMTDialog.gui");
		exec("./gui/messageGui.gui");
		exec("./gui/quadMenuDlg.gui");
		exec("./gui/GameCityCompGui.gui");
	   
		//exec("./gui/baseViewGui.gui");
		//exec("./gui/unitBuyGui.gui");
	   
		exec("./gui/splashScreen.gui");
	
	
		exec("./gui/questGui.gui");
		exec("./gui/infModeInGameMenu.gui");
		exec("./gui/cupScoresGui.gui");
		exec("./gui/cupGui.gui");
		exec("./gui/GMInstGui.gui");
		
		exec("./gui/newAccountGui.gui");
	   
		exec("./gui/createGameGui.gui");
		exec("./gui/loginGui.gui");
		
		exec("./gui/Messageupdate.gui");
   }
   
   exec("./gameScripts/defaults.cs");
   
   exec("./gui/MessageNewChallenge.gui");
   
   exec("./gui/youtubeGui.gui");
   
   exec("./gui/WarnNoWriteGui.gui");
   
   exec("./gui/messageRateGame.gui");
   exec("./gui/messagePreGame.gui");
   exec("./gui/messagePostGame.gui");
   //exec("./gui/massageSearch.gui");
   exec("./gui/commentWindow.gui");
   
   exec("./gui/GuiMapsScreen.gui");
   exec("./gui/mapScreenIM.gui");
   exec("./gui/MessageInst.gui");
   
   exec("./gui/MessageSkirmish.gui");
   
   exec("./gui/MessageUnlockables.gui");
   
   exec("./gui/CupEndScreen.gui");
   exec("./gui/CupFailScreen.gui");
   
   exec("./gui/SkirmishEndScreen.gui");
   exec("./gui/SkirmishFailScreen.gui");
   
   exec("./gui/MessageLoading.gui");
   
   exec("./gui/MessageAltServers.gui");
   
   exec("./gui/AILoadingGui.gui");
   
   // jamesu - IRC GUI's
   exec("./gui/IRCBox.gui");
   exec("./gameScripts/ircBox.cs");

   // jamesu - music manager
   exec("./gameScripts/music.cs");

   // jamesu - Rick Roll
   exec("./gameScripts/youtube.cs");
   //exec("./gui/YTLogin.gui");
   //exec("./gui/YTEdit.gui");
   
   
   // Exec game scripts.
   exec("./gameScripts/game.cs");
   
   
   
   exec("./gameScripts/player.cs");
   exec("./gameScripts/tacticsManager.cs");
   exec("./gameScripts/tileTypes.cs");
   exec("./gameScripts/rightClickMenu.cs");
   exec("./gameScripts/plan.cs");
   
   exec("./gameScripts/time.cs");
   exec("./gameScripts/playMode.cs");
   exec("./gameScripts/editor.cs");
   exec("./gameScripts/splits.cs");
   exec("./gameScripts/unit.cs");
   exec("./gameScripts/triggers.cs");
   //exec("./gameScripts/anim.cs");
   exec("./gameScripts/comm.cs");
   exec("./gameScripts/progressionModeClient.cs");
   exec("./gameScripts/postSubmit.cs");
   
   exec("./gameScripts/friendsClient.cs");
   
   //exec("./gameScripts/fileSend.cs");
   //exec("./gameScripts/fileReceive.cs");
   
   exec("./gameScripts/multiplayer.cs");
   
   exec("./gameScripts/server.cs");
   exec("./gameScripts/client.cs");
   
   exec("./gameScripts/camera.cs");
   
   exec("./gameScripts/sqlite.cs");
   
   exec("./gameScripts/clientDb.cs");
   
   if ($grandServerDedicated)
      exec("./grandServer/grandServer.cs");
   
   exec("./gameScripts/gsClient.cs");
   exec("./gameScripts/gsInGame.cs");
   exec("./gameScripts/mtInGame.cs");
   exec("./gameScripts/execMT.cs");
   
   exec("./gameScripts/endPlay.cs");
   
   exec("./gameScripts/gameMode.cs");
   exec("./gameScripts/noHuddleClient.cs");
   
   exec("./gameScripts/gameEnd.cs");
   
   exec("./gameScripts/singlePlayer.cs");
   exec("./gameScripts/prog.cs");
   
   exec("./gameScripts/levelGenerator.cs");
   
   exec("./gameScripts/messagesClient.cs");
   
   exec("./gameScripts/multiturn.cs");
   exec("./gameScripts/quickMatch.cs");
   exec("./gameScripts/biddingClient.cs");
   
   exec("./gameScripts/dialogTree.cs");
   
   exec("./gameScripts/tutorial.cs");
   
   exec("./gameScripts/trayNotify.cs");
   
   exec("./gameScripts/nottingham.cs");
   
   exec("./gameScripts/gamePageClient.cs");
   exec("./gameScripts/playerPageClient.cs");
   exec("./gameScripts/feedClient.cs");
   
   exec("./gameScripts/tournament.cs");
   
   //exec("./gameScripts/campaign/baseClient.cs");
   //exec("./gameScripts/campaign/baseViewEditor.cs");
   //exec("./gameScripts/campaign/baseSquareClient.cs");
   
   exec("./gameScripts/campaign/campaignClient.cs");
   
   exec("./gameScripts/toolbox.cs");
   
   exec("./gameScripts/sports.cs");
   exec("./gameScripts/infiniteMode.cs");
   exec("./gameScripts/sideQuest.cs");
   exec("./gameScripts/cup.cs");
   exec("./gameScripts/cupSaving.cs");
   exec("./gameScripts/cupEndCons.cs");
   
   
 
   if (!$aiProcess && !$grandServerDedicated)
   {
		exec("./gameScripts/mapScreen.cs");
		exec("./gameScripts/cupProfiles.cs");
		exec("./gameScripts/cupEndMission.cs");
	   
		exec("./gameScripts/cupIMs.cs");
		exec("./quests/imSource.cs");
	}
   
   // ORDER IS IMPORTANT HERE
   
   exec("./gameScripts/snapCam.cs");
   
   if (!$aiProcess && !$grandServerDedicated)
   {
		exec("./gameScripts/background.cs");
   
		exec("./gameScripts/unlockables.cs");
   }
   
   exec("./gameScripts/AI.cs");
   
   exec("./gameScripts/advancedImport.cs");
   exec("./gameScripts/activeGames.cs");
   exec("./gameScripts/skirmish.cs");
   
   if ($titan)
   {
		exec("./gameScripts/titan.cs");
   }
   
   exec("psychoff/grandServer/serverStats.cs");
   
   ///////////////////
   //
   /////////////
   // game modes
   //////////////
   //
   //////////////////
   
   $nGMs = 0;
   $nUseGMS = 0;
   
   exec("./gameModes/thirdDown.cs");
   //exec("./gameModes/thirdDownNoHuddle.cs");
   exec("./gameModes/extermination.cs");
   exec("./gameModes/squadVSquad.cs");
   //exec("./gameModes/survival.cs");
   //exec("./gameModes/insertion.cs");
   //exec("./gameModes/control.cs");
   exec("./gameModes/hostage.cs");
	//exec("./gameModes/secure.cs");
	exec("./gameModes/secure2.cs");
	
	exec("./gameModes/progMode1.cs");
	exec("./gameModes/progElim.cs");
	exec("./gameModes/progEscape.cs");
	
	exec("./gameModes/killOrEscape.cs");
	
	exec("./gameModes/disputed.cs");
	exec("./gameModes/disputedDark.cs");
	
	exec("./gameModes/getBoxes.cs");
	
	exec("./gameModes/disputedCamp.cs");
	exec("./gameModes/disputedCampBaseAttack.cs");
	exec("./gameModes/exterminationCamp.cs");
	exec("./gameModes/hostageCamp.cs");
	exec("./gameModes/secureCamp.cs");
	
	exec("./gameModes/charge.cs");
	exec("./gameModes/gambit.cs");
	
   for (%i = 0; %i < $nGMs; %i ++)
   {
      new ScriptObject($gameMode[%i]);
      $gameMode[%i].init();
   }
   
   ////////
   // execing of inGameStartConfig.cs must happen after game modes have been sorted
   
   exec("./gameScripts/inGameStartConfig.cs");
   
   if (!$grandServerDedicated && !$aiProcess)
   {
		exec("./gameScripts/cutscenes.cs"); // order matters
		exec("./gui/cutsceneGui.gui");
   }
   
   ///////////////
   
   ResolutionMenu.init(GraphicsDriverMenu.getText(), FullscreenToggle.getValue());
   
   
   //////////////////
   // VERSIONING
   //////////////////
   
   // first we exec devVersion.cs.  If it isn't there $devVersion will not be set, and we need to exec releaseVersion
   // THIS SHOULD HAPPEN AFTER EVERYTHING ELSE HAS BEEN EXECED
   
   exec("./gameScripts/devVersion.cs");
   if (!$devVersion)
      exec("./gameScripts/releaseVersion.cs");
   
   
   ////////////
   
   // Remove the following four lines if you would like to start the game without running the
   // level builder.
   if ($runWithEditors && $fsRunEditor)
   {
      toggleLevelEditor();
      return;
   }
   
   if (!$grandServerDedicated && !$aiProcess)
   {
		// we don't do this at startup, we do it when we start a single player game
		// tryAIProcess();
   }
   
   initZoneColors();
   
   if ($useSteam)
   {
      initSteam();
   }
   
   initLevelGen(); // must always be done
   initTinyIRC();
   SocialInit();
   YTInit();
   if (!$grandServerDedicated) startClientDB();
   if (!$grandServerDedicated) cupInit();
   
   if (!$grandServerDedicated && !$aiProcess)
		initMusic();
		
	p1TokenColour.setSpecialBitmapMode(1);
	p2TokenColour.setSpecialBitmapMode(2);
	p1PreMatchColour.setSpecialBitmapMode(1);
	p2PreMatchColour.setSpecialBitmapMode(2);

	transitionOnLoad();

	ircBoxStartup();

	if (!$aiProcess && !$grandServerDedicated)
	{
		secondServerOnStartup();
	}
	
	
   startGame();
}

//---------------------------------------------------------------------------------------------
// 
// Clean up your game objects here.
// jamesu - NOTE: this is called from shutdownCommon() in turn called from onExit()
//---------------------------------------------------------------------------------------------
function shutdownProject()
{
   SocialShutdown();
   YTShutdown();
   freeTinyIRC();
   stopDB();

   if ($useSteam)
   {
      shutdownSteam();
   }
   
   endGame();
}

//---------------------------------------------------------------------------------------------
// setupKeybinds
// Bind keys to actions here..
//---------------------------------------------------------------------------------------------
function setupKeybinds()
{
   
}
