#Const Version		"2013-11-18"
#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
Void Synchro_DoBarrier()
{
	declare Barrier = Synchro_AddBarrier();
	wait(Synchro_BarrierReached(Barrier) || ServerShutdownRequested);
}

// ---------------------------------- //
/// Balance the teams
Void AutoTeamBalance() {
	This.AutoTeamBalance();
	Synchro_DoBarrier();
}

// ---------------------------------- //
/// Load the next map
Void LoadMap() { 
	if (!MapLoaded) 
	{
		RequestLoadMap(); 
	} 
	wait(MapLoaded || ServerShutdownRequested); 
}

// ---------------------------------- //
/// Unload the current map
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.)
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
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
 */
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
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
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
	);
}