/**
 *	Ladder library
 */
#Const	Version			"2016-05-30"
#Const	ScriptName	"Libs/Nadeo/Ladder.Script.txt"

// ---------------------------------- //
// Libraries
// ---------------------------------- //
#Include "Libs/Nadeo/Log.Script.txt" as Log

// ---------------------------------- //
// Functions
// ---------------------------------- //
// ---------------------------------- //
// Public
// ---------------------------------- //
// ---------------------------------- //
/**	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;
}

// ---------------------------------- //
/** Check if a ladder request is already
 *	in progress 
 *	Always use this before and after any
 *	request to the ladder
 *	Functions making a request are prefixed
 *	with "Request_"
 */
Boolean RequestInProgress() {
	return Ladder_RequestInProgress;
}

// ---------------------------------- //
/** Create a new match and register
 *	the given scores
 *	Remember to close any open match
 *	before
 *
 *	@param	_Scores										The scores to register in the match
 */
Void Request_OpenMatch(CScore[] _Scores) {
	Log::Log("""[Ladder] Ladder_OpenMatch_Request()""");
	Ladder_OpenMatch_Request();
	foreach (Score in _Scores) {
		if (Score != Null) Log::Log("""[Ladder] Ladder_AddPlayer({{{Score.User.Login}}})""");
		else Log::Log("""[Ladder] Ladder_AddPlayer(Null)""");
		Ladder_AddPlayer(Score);
	}
}

// ---------------------------------- //
/** Create a new match and register
 *	all available scores
 *	Remember to close any open match
 *	before
 */
Void Request_OpenMatch() {
	Log::Log("""[Ladder] Ladder_OpenMatch_Request()""");
	Ladder_OpenMatch_Request();
	foreach (Score in Scores) {
		if (Score != Null) Log::Log("""[Ladder] Ladder_AddPlayer({{{Score.User.Login}}})""");
		else Log::Log("""[Ladder] Ladder_AddPlayer(Null)""");
		Ladder_AddPlayer(Score);
	}
}

// ---------------------------------- //
/** Create a new match and register
 *	all available scores
 *	Remember to close any open match
 *	before
 */
Void Request_OpenEmptyMatch() {
	Log::Log("""[Ladder] Ladder_OpenMatch_Request()""");
	Ladder_OpenMatch_Request();
}

// ---------------------------------- //
/** Close the currently opened match
 *	Closing a match will award
 *	ladder points to the players
 *	registered in the match
 */
Void Request_CloseMatch() {
	Log::Log("""[Ladder] Ladder_CloseMatchRequest()""");
	Ladder_CloseMatchRequest();
}

// ---------------------------------- //
/** Cancel the currently opened match
 *	Canceling a match close a match
 *	without awarding ladder points
 *	to the players
 */
Void Request_CancelMatch() {
	Log::Log("""[Ladder] Ladder_CancelMatchRequest()""");
	Ladder_CancelMatchRequest();
}

// ---------------------------------- //
/** Add a player to the currently
 *	opened match
 *
 *	@param	_Score										The score of the player to add
 */
Void AddPlayer(CScore _Score) {
	if (_Score != Null) Log::Log("""[Ladder] Ladder_AddPlayer({{{_Score.User.Login}}})""");
	else Log::Log("""[Ladder] Ladder_AddPlayer(Null)""");
	Ladder_AddPlayer(_Score);
}

// ---------------------------------- //
/** Select the version used to
 *	calculate the ladder points reward
 *	of the currently opened match
 *
 *	@param	_Version									The version to use
 */
Void SetResultsVersion(Integer _Version) {
	Log::Log("""[Ladder] Ladder_SetResultsVersion({{{_Version}}})""");
	Ladder_SetResultsVersion(_Version);
}

// ---------------------------------- //
/** Associate a matchmaking match id
 *	to the currently opened match
 *
 *	@param	_MatchId									The match id
 */
Void SetMatchmakingMatchId(Integer _MatchId) {
	Log::Log("""[Ladder] Ladder_SetMatchMakingMatchId({{{_MatchId}}})""");
	Ladder_SetMatchMakingMatchId(_MatchId);
}

// ---------------------------------- //
/** Enable of disable the challenge
 *	mode for the currently opened
 *	match
 *
 *	@param	_Enable										True to enable the challenge mode, False to disable it
 */
Void EnableChallengeMode(Boolean _Enable) {
	Log::Log("""[Ladder] Ladder_EnableChallengeMode({{{_Enable}}})""");
	Ladder_EnableChallengeMode(_Enable);
}

// ---------------------------------- //
/// Unload the library
Void Unload() {
	
}

// ---------------------------------- //
/// Load the library
Void Load() {
	Unload();
}