#Const Version		"2014-02-07"
#Const ScriptName	"Mode.Script.txt"

// ---------------------------------- //
/** Return the version number of the script
 *
 *	@return		The version number of the script
 */
Text GetScriptVersion() {
	return Version;
}

// ---------------------------------- //
/** Return the name of the script
 *
 *	@return		The name of the script
 */
Text GetScriptName() {
	return ScriptName;
}

// ---------------------------------- //
/**	Do a synchronization
 *
 *	@deprecated		Use the MB_Synchro_DoBarrier() function from ModeBase.Script.txt instead
 */
Void Synchro_DoBarrier()
{
	declare Barrier = Synchro_AddBarrier();
	wait(Synchro_BarrierReached(Barrier) || ServerShutdownRequested);
}

// ---------------------------------- //
/** Balance the teams
 *
 *	@deprecated		Use the MB_AutoTeamBalance() function from ModeBase.Script.txt instead
 */
Void AutoTeamBalance() {
	This.AutoTeamBalance();
	Synchro_DoBarrier();
}

// ---------------------------------- //
/** Load the next map
 *
 *	@deprecated		Use the MB_LoadMap() function from ModeBase.Script.txt instead
 */
Void LoadMap() { 
	if (!MapLoaded) 
	{
		RequestLoadMap(); 
	} 
	wait(MapLoaded || ServerShutdownRequested); 
}

// ---------------------------------- //
/** Unload the current map
 *
 *	@deprecated		Use the MB_UnloadMap() function from ModeBase.Script.txt instead
 */
Void UnloadMap() { 
	if (MapLoaded) 
	{
		UIManager.UIAll.UISequence = CUIConfig::EUISequence::None;
		UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::Normal;
		RequestUnloadMap(); 
	} 
	wait(!MapLoaded || ServerShutdownRequested); 
} 

// ---------------------------------- //
/** Show the new record and medals dialog (and the end-race replay in TM.)
 *
 *	@deprecated		Use the MB_Solo_SetNewRecord() function from ModeBase.Script.txt instead
 */
Void Solo_SetNewRecord(CScore _NewScore, CMode::EMedal _NewMedal) { 
	This.Solo_SetNewRecord(_NewScore, _NewMedal);
	wait(!Solo_NewRecordSequenceInProgress || ServerShutdownRequested); 
} 


// ---------------------------------- //
/** Create a new match on the ladder and register all the scores
 *
 *	@deprecated		Use the MB_Ladder_OpenMatch_All() function from ModeBase.Script.txt instead
 */
Void Ladder_OpenMatch_All() {
	Ladder_CancelMatchRequest();
	wait(!Ladder_RequestInProgress); 
	
	Ladder_OpenMatch_BeginRequest(); 
	foreach(Score in Scores) { 
		Ladder_OpenMatch_AddPlayer(Score); 
	}
	Ladder_OpenMatch_EndRequest(); 
	wait(!Ladder_RequestInProgress); 
}

// ---------------------------------- //
/** Create a new match on the ladder and register a list of scores
 *
 *	@param	_Scores 	The list of scores to register on the ladder
 *
 *	@deprecated		Use the MB_Ladder_OpenMatch() function from ModeBase.Script.txt instead
 */
Void Ladder_OpenMatch(CScore[] _Scores) {
	Ladder_CancelMatchRequest();
	wait(!Ladder_RequestInProgress); 
	
	Ladder_OpenMatch_BeginRequest(); 
	foreach(Score in _Scores) { 
		Ladder_OpenMatch_AddPlayer(Score); 
	}
	Ladder_OpenMatch_EndRequest(); 
	wait(!Ladder_RequestInProgress); 
}

// ---------------------------------- //
/** Close the current match on the ladder
 *
 *	@deprecated		Use the MB_Ladder_CloseMatch() function from ModeBase.Script.txt instead
 */
Void Ladder_CloseMatch() {
	declare CScore PrevScore;
	foreach(Score in Scores) { 
		if (PrevScore == Null)
			continue;
		assert(PrevScore.LadderRankSortValue <= Score.LadderRankSortValue);
		PrevScore <=> Score;
	}
	
	Ladder_CloseMatchRequest();
	wait(!Ladder_RequestInProgress); 
}

// ---------------------------------- //
/** Cancel the current match on the ladder
 *
 *	@deprecated		Use the MB_Ladder_CancelMatch() function from ModeBase.Script.txt instead
 */
Void Ladder_CancelMatch() {
	Ladder_CancelMatchRequest();
	wait(!Ladder_RequestInProgress); 
}

// ---------------------------------- //
/** Play a sound
 *
 *	@param	_Name		The name of the sound to play
 *	@param	_Variant	The variant to use
 */
Void PlaySound(CUIConfig::EUISound _Name, Integer _Variant) {
	UIManager.UIAll.SendNotice(
		"", 
		CUIConfig::ENoticeLevel::PlayerInfo, Null, 
		CUIConfig::EAvatarVariant::Default, 
		_Name, _Variant
	);
}

// ---------------------------------- //
/** Convert an echelon to an integer
 *
 *	@param	_Echelon		The echelong= to convert
 *
 *	@return		The echelon value
 */
Integer EchelonToInteger(CUser::EEchelon _Echelon) {
	switch (_Echelon) {
		case CUser::EEchelon::Bronze1	: return 1;
		case CUser::EEchelon::Bronze2	: return 2;
		case CUser::EEchelon::Bronze3	: return 3;
		case CUser::EEchelon::Silver1	: return 4;
		case CUser::EEchelon::Silver2	: return 5;
		case CUser::EEchelon::Silver3	: return 6;
		case CUser::EEchelon::Gold1		: return 7;
		case CUser::EEchelon::Gold2		: return 8;
		case CUser::EEchelon::Gold3		: return 9;
	}
	
	return 0;
}